package com.zhongdao.jlr.business.action;

import com.util.RequestUtil;
import com.util.UtilTools;
import com.util.Vo;
import com.zhongdao.jlr.business.service.OrderCheckService;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


/****
 * 服务结算控制器
 */

@Controller
@RequestMapping("/orderCheck")
public class OrderCheckAction {

    @Resource(name = "orderCheckServiceImpl")
    OrderCheckService serviceImpl;

    /**
     * 跳转到中道服务核对界面
     */
    @RequestMapping(value = "/list.do", produces = "text/html;chrset=UTF-8", method = {RequestMethod.GET, RequestMethod.POST})
    public String list(HttpServletRequest request, HttpServletResponse response) {
        String state = request.getParameter("state");
            return "/page/orderCheck";
    }

    /**
     * 跳转到中道服务结算界面
     */
    @RequestMapping(value = "/settle.do", produces = "text/html;chrset=UTF-8", method = {RequestMethod.GET, RequestMethod.POST})
    public String settle(HttpServletRequest request, HttpServletResponse response) {
        //获取参数
        String state = request.getParameter("state");
        //共享数据
        request.setAttribute("state",state);
        return "/page/orderCheckAll";
    }

    /**
     * 查询服务费用核对信息
     */
    @RequestMapping(value = "/query.do", produces = "text/html;chrset=UTF-8", method = {RequestMethod.GET, RequestMethod.POST})
    public void query(HttpServletRequest request, HttpServletResponse response) {
        //获取参数
        String orderCode = request.getParameter("orderCode");
        String queryDate1 = request.getParameter("queryDate1");
        String queryDate2 = request.getParameter("queryDate2");
        String rescueCompanyName = request.getParameter("rescueCompanyName");
        String checkState = request.getParameter("checkState");
        //获取工单服务费用信息
        Vo vo = serviceImpl.list(request, UtilTools.getPage(request), UtilTools.getRows(request),orderCode, queryDate1, rescueCompanyName, queryDate2, checkState);
        //RequestUtil.responseResult4Json(response, "1");
        RequestUtil.responseResult4Json(response, RequestUtil.ObjecttoJsonString(vo));
    }

    /**
     * 查询工单费用信息
     */
    @RequestMapping(value = "/querys.do", produces = "text/html;chrset=UTF-8", method = {RequestMethod.GET, RequestMethod.POST})
    public void querys(HttpServletRequest request, HttpServletResponse response) {
        //获取参数
        String code = request.getParameter("code");
        String orderCode = request.getParameter("orderCode");
        String queryDate1 = request.getParameter("queryDate1");
        String queryDate2 = request.getParameter("queryDate2");
        String rescueCompanyName = request.getParameter("rescueCompanyName");
        String checkState = request.getParameter("checkState");
        String state = request.getParameter("state");
        //获取工单服务费用信息
        Vo vo = serviceImpl.lists(request, UtilTools.getPage(request), UtilTools.getRows(request), code, orderCode, queryDate1, rescueCompanyName, queryDate2, checkState,state);
        //RequestUtil.responseResult4Json(response, "1");
        RequestUtil.responseResult4Json(response, RequestUtil.ObjecttoJsonString(vo));
    }

    /***
     * 导出
     * @param request
     * @param response
     */
    @RequestMapping(value = "/exportData.do", produces = "text/html;chrset=UTF-8", method = {RequestMethod.POST})
    public void exportData(HttpServletRequest request, HttpServletResponse response) {
        //获取参数
        String code = request.getParameter("code");
        String orderCode = request.getParameter("orderCode");
        String queryDate1 = request.getParameter("queryDate1");
        String queryDate2 = request.getParameter("queryDate2");
        String rescueCompanyName = request.getParameter("rescueCompanyName");
        String checkState = request.getParameter("checkState");
        JSONObject jsonObject = serviceImpl.exportData(request, code, orderCode, queryDate1, rescueCompanyName, queryDate2, checkState);
        RequestUtil.responseResult4Json(response, jsonObject.toString());
    }

    /***
     * 保存核对后信息
     * @param request
     * @param response
     */
    @RequestMapping(value = "/save.do", produces = "text/html;chrset=UTF-8", method = {RequestMethod.GET, RequestMethod.POST})
    public void save(HttpServletRequest request, HttpServletResponse response) {
        //获取参数
        String uid = request.getParameter("uid");
        String totalFee = request.getParameter("totalFee");
        Map result = new HashMap();
        result.put("flag", "0");
        if (StringUtils.isNotBlank(totalFee) && StringUtils.isNotBlank(uid)) {
            boolean state=serviceImpl.updateInfo(uid,totalFee);
            if(state){
                result.put("flag","1");
            }
        }else{
                result.put("msg","参数为空");
        }
        RequestUtil.responseResult4Json(response,RequestUtil.ObjecttoJsonString(result));
    }

}
