package com.sifang.modules.smallprogram;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.order.dao.OrdeCallbackDao;
import com.sifang.modules.order.service.OrdeCallbackService;
import com.sifang.modules.platform.service.AddressService;
import com.sifang.modules.sunshine.SystemSetting.dao.CompanyInformationDao;
import com.sifang.modules.sunshine.SystemSetting.entity.CrmPlantForm;
import com.sifang.modules.sunshine.SystemSetting.service.CrmOrderCustomerSettlementTemplateService;
import com.sifang.modules.sunshine.SystemSetting.utils.Result;
import com.sifang.modules.sunshine.SystemSetting.utils.StringUtil;
import com.sifang.modules.sunshine.fittingManager.service.CrmSiteFittingService;
import com.sifang.modules.platform.service.RecevierAddressService;
import com.sifang.modules.platform.utils.AddressUtils;
import com.sifang.modules.order.dao.OrderDao;
import com.sifang.modules.order.dao.OrderFeedbackDao;
import com.sifang.modules.order.entity.CrmOrder;
import com.sifang.modules.order.service.OrderService;
import com.sifang.modules.order.utils.OrderUtils;
import com.sifang.modules.order.utils.Target;
import com.sifang.modules.site.fittingManager.service.SiteFittingApplyService;
import com.sifang.modules.smallprogram.service.SmallProgramOrderService;
import com.sifang.modules.supply.order.constant.ApplyOrderConstants;
import com.sifang.modules.sys.common.entity.User;
import com.sifang.modules.sys.common.utils.DateUtils;
import com.sifang.modules.sys.util.CrmUtils;
import com.sifang.modules.sys.util.LayuiPage;
import com.sifang.modules.sys.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value="${adminPath}/main/order")
public class SmallProgramOrderController extends BaseController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private CrmOrderCustomerSettlementTemplateService customerSettlementTemplateService;
    @Autowired
    private SiteFittingApplyService sitFittingApplyService;
    @Autowired
    private SmallProgramOrderService smallProgramOrderService;
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private OrdeCallbackDao ordeCallbackDao;
    @Autowired
    private RecevierAddressService recevierAddressService;

    @Autowired
    private CrmSiteFittingService siteFittingService;
    @Autowired
    private OrdeCallbackService ordeCallbackService;
    @Autowired
    private OrderFeedbackDao orderFeedbackDao;

    @Autowired
    private CompanyInformationDao plantDao;

    @Autowired
    AddressService addressService;

    //首页详情   里面的数据
    @ResponseBody
    @RequestMapping(value = "getSiteOrderCount")
    public Object getSiteOrderCount(HttpServletRequest request) {
        String factor = request.getParameter("factor");//周 月 日
        String siteId = request.getParameter("siteId");
        String employeId="";

            String userId=request.getParameter("userId");
            Record employe=CrmUtils.getEmployeId(userId);
            if(employe !=null){
                employeId=employe.getStr("id");
            }
        Map<String, Object> map = Maps.newHashMap();
        map.put("order", orderService.getPageOrderCount(factor, siteId,employeId));
        map.put("fitting", smallProgramOrderService.getSiteFittingApplyCount(siteId,employeId));
        return map;
    }

    // 服务商端  工单中  全部工单
    @ResponseBody
    @RequestMapping(value = "getServiceFormList")
    public Object getServiceFormList(HttpServletRequest request) {
        Map<String, String> map = getParams(request);
        String siteId = request.getParameter("siteId");
            String userId=request.getParameter("userId");
            Record employe=CrmUtils.getEmployeId(userId);
        LayuiPage page = new LayuiPage(request);
        List<Record> list= null;
        if(employe !=null){
                map.put("employeId",employe.getStr("id"));
            list = orderDao.getSiteOrdersList(page,map,siteId);
        }

        return list;
    }

    /**
     * 获取服务商工程师待接单数据
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getWaitReceiveData")
    public Object getWaitReceiveData(HttpServletRequest request) {
        Map<String, String> map = getParams(request);
        String siteId = request.getParameter("siteId");
        String userId=request.getParameter("userId");
        Record employe=CrmUtils.getEmployeId(userId);
        LayuiPage page = new LayuiPage(request);
        List<Record> list =null;
        if(employe !=null){
            map.put("employeId",employe.getStr("id"));
            list =  orderDao.getWaitingForOrders(page,map,siteId);
        }
        return list;
    }

    /**
     * 获取服务商待派工
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getWaitWorkData")
    public Object getWaitWorkData(HttpServletRequest request) {
        Map<String, String> map = getParams(request);
        String siteId = request.getParameter("siteId");
        LayuiPage page = new LayuiPage(request);
        String userId=request.getParameter("userId");
        Record employe=CrmUtils.getEmployeId(userId);
        List<Record> list =null;
        if(employe !=null){
            map.put("employeId",employe.getStr("id"));
            list =  orderDao.getWaitWorkData(page,map,siteId);
        }
        return list;
    }

    /***
     * 服务中工单
     */
    @ResponseBody
    @RequestMapping(value = "getServiceingOrderList")
    public Object getServiceingOrderList(HttpServletRequest request) {
        Map<String, String> map = getParams(request);
        String siteId = request.getParameter("siteId");
        LayuiPage page = new LayuiPage(request);
        List<Record> list = null;
            String userId=request.getParameter("userId");
            Record employe=CrmUtils.getEmployeId(userId);
            if(employe !=null){
                map.put("employeId",employe.getStr("id"));
                list = orderDao.getInServiceOrderBySiteId(page,map,siteId,"1");
            }
        return list;
    }

    /**
     * 获取工程师已完工数据
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getWorkFinishData")
    public Object getWorkFinishData(HttpServletRequest request) {
        Map<String, String> map = getParams(request);
        String siteId = request.getParameter("siteId");
        String pages = request.getParameter("page");
        System.out.println("page:"+pages);
        LayuiPage page = new LayuiPage(request);
        List<Record> list = null;
            String userId=request.getParameter("userId");
            Record employe=CrmUtils.getEmployeId(userId);
            if(employe !=null){
                map.put("employeId",employe.getStr("id"));
                list = orderDao.getEmpCompleted(page,map,siteId);
            }
        return list;
    }

    /**
     * 获取服务商已结算数据
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getWorkSettlementData")
    public Object getWorkSettlementData(HttpServletRequest request) {
        Map<String, String> map = getParams(request);
        String siteId = request.getParameter("siteId");
        String userType=request.getParameter("userType");
        LayuiPage page = new LayuiPage(request);
        List<Record> list = null;
            String userId=request.getParameter("userId");
            Record employe=CrmUtils.getEmployeId(userId);
            if(employe !=null){
                map.put("employeId",employe.getStr("id"));
                list = orderDao.getWorkSettlementData(page,map,siteId);
            }
        return list;
    }


    /***
     * 服务商工程师接单
     */
    @ResponseBody
    @RequestMapping(value = "receiveOrder")
    public Object toReceiveOrder(HttpServletRequest request) {
        String orderId = request.getParameter("orderId");
        String userId = request.getParameter("userId");
        Result result = new Result();
        if (StringUtil.isBlank(orderId)) {
            result.setCode("407");
            return result;
        }
        return orderService.employeReceiveOrder(orderId, userId);
    }

    /***
     * 服务商工程师拒单
     */
    @ResponseBody
    @RequestMapping(value = "refuseOrder")
    public Object toRefuseOrder(HttpServletRequest request) {
        String orderId = request.getParameter("orderId");
        String userId = request.getParameter("userId");
        String siteId = request.getParameter("siteId");
        Result result = null;
        try {
            result = orderService.employeRefuseOrder(orderId,siteId, userId);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode("505");
        }
        return result;
    }

    /***
     * 获得派工的工程师信息
     */
    @ResponseBody
    @RequestMapping(value = "dispatchOrderForm")
    public Object toDispatchOrderForm(HttpServletRequest request) {
        String siteId = request.getParameter("siteId");
        List<Record> records = orderService.getEngineerList(siteId);
        return records;
    }


    /***
     * 保存预约时间
     */
    @ResponseBody
    @RequestMapping(value = "saveAppointment")
    public Object toSaveAppointment(HttpServletRequest request) {
        Map<String, Object> mapss = Maps.newHashMap();
        Map<String, String> map = getParams(request);
        if(StringUtil.isBlank(map.get("orderId"))|| StringUtil.isBlank(map.get("promiseTime"))|| StringUtil.isBlank(map.get("promiseLimit"))){
            mapss.put("code", "500");
            return mapss;
        }
        try {
            orderService.sitePromiseTimeOrder(map.get("orderId"), map.get("promiseTime"), map.get("promiseLimit"));
            mapss.put("code", "200");
        } catch (Exception e) {
            e.printStackTrace();
            mapss.put("code", "505");
        }
        return mapss;
    }
    /**
     * 查看工单基本信息
     */
    @RequestMapping(value = "getOrderDetail")
    @ResponseBody
    public Object getOrderDetail(HttpServletRequest request) {
        String orderId = request.getParameter("orderId");
        Record rd =smallProgramOrderService.getOrderDetail(orderId);
        //获取里程费
        CrmOrder or = orderService.getOrderById(orderId);
        BigDecimal mile = or.getMileage();
        if(mile.compareTo(BigDecimal.ZERO) < 1){
            double addre=  ordeCallbackDao.getCusaddress(or.getCustomerLnglat(),or.getSiteId());
            or.setMileage(new BigDecimal(addre));
            orderService.saveOrder(or);
        }
        //查询是否有备件
        BigDecimal fittingPrice = new BigDecimal("0");
        if( ApplyOrderConstants.SERVICE_TYPE_WX.equals(or.getServiceType()) && ApplyOrderConstants.WARRANTY_TYPE_TWO.equals(or.getWarrantyType())){
            fittingPrice= sitFittingApplyService.getEmpFittingByOrderId(orderId);
        }
        rd.set("fittingPrice",fittingPrice);
        if(!ApplyOrderConstants.ORDER_STATUS_CANCEL.equals(or.getStatus())){
            BigDecimal mileCost = StringUtil.isBlank(or.getWarrantyType())?new BigDecimal("0.00"):ordeCallbackService.getNewMileage(or.getMileage(),or.getWarrantyType(),"1");//type =1 为用户
            rd.set("mileCost",mileCost);
        }else{
            rd.set("mileCost",or.getMileCost());
        }
        return rd;
    }

    /**选择保修类型查询相关费用
    */
    @ResponseBody
    @RequestMapping(value = "getOrderMileCost")
    public Object getOrderMileCost(HttpServletRequest request){
        String orderId = request.getParameter("orderId");
        CrmOrder or = orderService.getOrderById(orderId);
        String warrantyType = request.getParameter("warrantyType");
        if(StringUtil.isBlank(warrantyType)){
            return 0;
        }
        Map map = Maps.newHashMap();
        String servicrStep = request.getParameter("serviceStep");
        if(StringUtil.isNotBlank(orderId) && StringUtil.isNotBlank(servicrStep)){
            Record rd =  customerSettlementTemplateService.getSetTemplateByServiceStep(servicrStep,warrantyType,or.getServiceType());
            if(rd!= null){
                map.put("step",rd);
            }
        }else{
            Record rd = new Record();
            rd.set("charge_amount",0);
            rd.set("service_step","");
            rd.set("service_type","");
            rd.set("service_content","");

            map.put("step",rd);
        }
        BigDecimal fittingPrice = new BigDecimal("0");
        if( ApplyOrderConstants.SERVICE_TYPE_WX.equals(or.getServiceType()) && ApplyOrderConstants.WARRANTY_TYPE_TWO.equals(warrantyType)){
            fittingPrice = sitFittingApplyService.getEmpFittingByOrderId(orderId);

        }
        map.put("fittingPrice",fittingPrice);
        BigDecimal mileCost = ordeCallbackService.getNewMileage(or.getMileage(),warrantyType,"1");//type =1 为用户
        map.put("mileCost",mileCost);
        return map;
    }

    /**
     * 查看工单过程信息
     * 只使用于工程师小程序
     */
    @RequestMapping(value = "getOrderProcess")
    @ResponseBody
    public Object getOrderProcess(HttpServletRequest request) {
        String orderId = request.getParameter("orderId");
        System.out.println(orderId);
        if(StringUtil.isBlank(orderId)){
            return null;
        }
        List<Target> list = orderService.getOrderDetail(orderId);
        CrmOrder or = orderService.getOrderById(orderId);
        String sitedis = DateUtils.formatDateTime(or.getSiteDispatchTime());
        if(StringUtil.isBlank(sitedis)){
            return list;
        }
        List<Target> rds = Lists.newArrayList();
        for(Target ts:list){
            String date = ts.getD();
            Integer i= date.compareTo(sitedis);
            if(i >=0){
                rds.add(ts);
            }
        }
        return rds;
    }
    @ResponseBody
    @RequestMapping(value = "checkFeedBack")
    public Object checkFeedBack(HttpServletRequest request){
        Map<String, String> map = getParams(request);
        String deviceMachineCode = map.get("deviceMachineCode");//
        String orderId = map.get("orderId");
        if(StringUtil.isBlank(deviceMachineCode) ){
            return Result.fail("201","机身条码为空");
        }
        long count= Db.queryLong("SELECT COUNT(id) FROM crm_order_feedback WHERE order_id=? AND device_machine_code=? ",orderId,deviceMachineCode);
        if(count > 0){
            return Result.fail("405","机身条码重复");
        }
        return Result.ok();
    }



    /***
     * 保存过程反馈 和  服务完成
     */
    @ResponseBody
    @RequestMapping(value = "saveFeedBack")
    public Object toSaveFeedBack(HttpServletRequest request) {
        Map<String, String> map = getParams(request);
        Result result=new Result();
        String userId=request.getParameter("userId");

            Record employe=CrmUtils.getEmployeId(userId); //获取工程师信息
            if(employe !=null){
                map.put("feedback_id", employe.getStr("id"));
                map.put("feedback_name", employe.getStr("name"));
                map.put("user_type", User.USER_TYPE_FWS);  //工程师
            }

        result = smallProgramOrderService.SitefeedbackOrder(map);
        return result;
    }


    /**
     * 工单详情查看备件信息
     */
    @ResponseBody
    @RequestMapping(value = "getOrderFittingByorderId")
    public Object getOrderFittingByorderId(HttpServletRequest request, HttpServletResponse response) {
        String orderId = request.getParameter("orderId");
        List<Record> rds = sitFittingApplyService.getOrderFitting(orderId);
        return rds;
    }

    /**
     * 工单详情查看反馈记录
     */
    @ResponseBody
    @RequestMapping(value = "getOrderFeedbackByorderId")
    public Object getOrderFeedbackByorderId(HttpServletRequest request, HttpServletResponse response) {
        String orderId = request.getParameter("orderId");
        String siteId = request.getParameter("siteId");
        List<Record> rds = orderFeedbackDao.getServiceOrderFeedbackRecords(orderId,siteId);
        return rds;
    }

    /**
     * 根据备件物料号
    */
    @ResponseBody
    @RequestMapping(value = "getSiteFitting")
    public Object getSiteFitting(HttpServletRequest request){
        String code = request.getParameter("code");
        if(StringUtil.isEmpty(code)){
            return null;
        }
        String siteId = request.getParameter("siteId");
        Record rd = siteFittingService.getSiteittingByCode(siteId,code);
        return rd;
    }



    /***
     * 保存工程师添加的备件
     */
    @ResponseBody
    @RequestMapping(value = "saveApplyFitting")
    public Object toSaveApplyFitting(HttpServletRequest request) {
        Map<String, String> map = getParams(request);
        String userId=request.getParameter("userId");
        Result result;

        Record employe=CrmUtils.getEmployeId(userId); //获取工程师信息
        if(employe !=null){
            map.put("applicantName", employe.getStr("name"));
            map.put("creator", employe.getStr("name"));
            map.put("applicantId", employe.getStr("id"));
            map.put("applicant_type", "1");   //工程师
        }else{
            return null;
        }

       result = sitFittingApplyService.siteApplyFitting(map);
        return result;
    }



    /***
     * 获取服务商结算信息
     */
    @ResponseBody
    @RequestMapping(value = "getSettleMessage")
    public Object getSettleMessage(HttpServletRequest request) {
        String orderId = request.getParameter("orderId");
        Record record = smallProgramOrderService.getSettleMessage(orderId);
        List<Record> settles = orderService.getUpDateOrderSiteSettlementByOrderId(orderId);
        if (settles.size()>0) {
            Double milefee = 0.0;
            Double servicrfee = 0.0;
            Double otherfee = 0.0;
            Double rewordfee = 0.0;
            Double questfee = 0.0;
            StringBuilder sb = new StringBuilder("");
            StringBuilder mark = new StringBuilder("");
            for (Record mass : settles) {
                milefee += (Double) (mass.get("mileage_cost"));
                servicrfee += (Double) (mass.get("service_costs"));
                otherfee += (Double) (mass.get("other_cost"));
                rewordfee += (Double) (mass.get("reward_costs"));
                questfee += (Double) (mass.get("exigency_costs"));
                mark.append(mass.getStr("remarks"));
            }
            //"服务费用:"+servicrfee+"元，里程费用:"+milefee+"元，其它费用:"+otherfee+"元";
            if (servicrfee > 0) {
                sb.append("服务费用:");
                sb.append(servicrfee);
                sb.append("元,");
            }
            if (milefee > 0) {
                sb.append("里程费用:");
                sb.append(milefee);
                sb.append("元,");
            }
            if (rewordfee > 0) {
                sb.append("奖励费用:");
                sb.append(rewordfee);
                sb.append("元,");
            }
            if (questfee > 0) {
                sb.append("加急费用:");
                sb.append(questfee);
                sb.append("元,");
            }
            if (otherfee > 0) {
                sb.append("其它费用:");
                sb.append(otherfee);
                sb.append("元,");
            }
            record.set("fee", sb.toString());
            record.set("mark", mark.toString());
        }
        return  record;
    }

    /**
     * 工程师上门
     */
    @ResponseBody
    @RequestMapping(value = "toVisit")
    public Result toVisit(HttpServletRequest request){
     String orderId=request.getParameter("orderId");
     String userId=request.getParameter("userId");
     Result result=smallProgramOrderService.toVisit(orderId,userId);
     return  result;
    }
    /**
     * 备件申请时获取网点地址
     */
    @ResponseBody
    @RequestMapping(value="getSiteAddress")
    public Object getSiteAddress(HttpServletRequest request){
        String orderId=request.getParameter("orderId");
        CrmOrder order = orderService.getOrderById(orderId);
        List<Record> list =recevierAddressService.getSiteRecevierAddress(order.getSiteId());
        return list;
    }

    /**
     * 备件申请时获取用户地址
     */
    @ResponseBody
    @RequestMapping(value="getCustomerAddress")
    public Object getCustomerAddress(HttpServletRequest request){
        String orderId=request.getParameter("orderId");
        CrmOrder order = orderService.getOrderById(orderId);
        return order;
    }

    /***
     * 分别统计各种状态下的工单数量
     */
    @ResponseBody
    @RequestMapping(value="differentOrderCount")
    public Record differentOrderCount(HttpServletRequest request){
        String siteId=request.getParameter("siteId");
        String employeId="";

            String userId=request.getParameter("userId");
            Record employe=CrmUtils.getEmployeId(userId);
            if(employe !=null){
                employeId=employe.getStr("id");
            }

        Record record=smallProgramOrderService.getDifferentOrderCount(siteId,employeId);
        return record;
    }
    /**
     * 根据工单的服务类型获取服务措施
     */
    @ResponseBody
    @RequestMapping(value="getServiceMeasure")
    public Object getServiceMeasure(HttpServletRequest request){
        String orderId =request.getParameter("orderId");
        CrmOrder order = orderService.getOrderById(orderId);
        List<Record> list = OrderUtils.getOrderServiceMeasures(order.getServiceType());
        return  list;
    }
   /**
     * 工单收款
     */
    @ResponseBody
    @RequestMapping(value="receivables")
    public Object receivables(HttpServletRequest request){
        Map<String,String> map = getParams(request);
        Result result = orderService.employeReceivables(map);

        return  result;
    }

   /**
     * 删除工单收款记录
     */
    @ResponseBody
    @RequestMapping(value="deleteOrderCollectionsById")
    public Object deleteOrderCollectionsById(HttpServletRequest request){
        String id = request.getParameter("id");
        String orderId = request.getParameter("orderId");
        Result result = orderService.deleteOrderCollectionsById(id,orderId);
        return  result;
    }


    /**
     * 获取工单收款记录
    */
    @ResponseBody
    @RequestMapping(value = "orderReceivablesList")
    public Object orderReceivablesList(HttpServletRequest request){
        String orderId = request.getParameter("orderId");
        if(StringUtil.isEmpty(orderId)){
            return null;
        }
        Map<String,Object> maps = Maps.newHashMap();
        CrmPlantForm plant = plantDao.getPlantForm();
        maps.put("plant",plant);
        List<Record> list = orderService.getOrderCollectionList(orderId);
        maps.put("list",list);
        return  maps;
    }


    /**
     * 获取工单的服务反馈内容
     */
    @ResponseBody
    @RequestMapping(value="getFeedBackInfo")
    public Object getFeedBackInfo(HttpServletRequest request){
        String orderId =request.getParameter("orderId");
        CrmOrder order = orderService.getOrderById(orderId);
        String siteId=order.getSiteId();
        //获取服务反馈信息
        List<Record> list=orderFeedbackDao.getOrderFeedbackDetail(orderId,siteId);
        return  list;
    }


    @ResponseBody
    @RequestMapping(value = "getComplaintFlagCount")
    public Object getComplaintFlagCount(HttpServletRequest request,HttpServletResponse response){
        Map<String,String> map = getParams(request);
       long count = orderService.getComplaintOrderCount(map);
       map.put("count",String.valueOf(count));
        return map;
    }
    /**
     * 获取服务商收货地址
    */
    @ResponseBody
    @RequestMapping(value = "recevierAddress")
    public Object baseInformation(HttpServletRequest request, Model model){
        List<Record> province = addressService.getProvinces();//获取所有的省
        model.addAttribute("province",province);
        Map<String,Object> map = Maps.newHashMap();
        String siteId = request.getParameter("siteId");
        List<Record> data =  recevierAddressService.getSiteRecevierAddress(siteId);//获取收货地址数据
        map.put("address",data != null? data : "");
        map.put("province",data);
        return map;
    }

    /**
     * 新增保存
     * @param request
     * @return
     */
    @RequestMapping(value = "addressSave")
    @ResponseBody
    public Object addSave(HttpServletRequest request){
        Map<String,String> map = getParams(request);
        return recevierAddressService.addSave(map);
    }

    /**
     * 获取修改地址的信息
     * @param request
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping(value="updateBtnFrom")
    public Object updateBtnFrom(HttpServletRequest request){
        String id = request.getParameter("id");
        Map<String,Object> map = Maps.newHashMap();
        Record rd = recevierAddressService.getDataList(id);//获取当前选中的数据
        map.put("address",rd);
        return map;
    }

    /**
     * 修改
    */
    @RequestMapping(value="updateAddressBtn")
    @ResponseBody
    public Object updateAddressBtn(HttpServletRequest request){
        Map<String,String> map = getParams(request);
        return recevierAddressService.saveBtn(map);
    }

    /**
     * 根据服务措施获取用户收费
    */
    @ResponseBody
    @RequestMapping(value = "getSetTemplateByServiceStep")
    public Object getSetTemplateByServiceStep(HttpServletRequest request){
        String orderId = request.getParameter("orderId");
        String servicrStep = request.getParameter("serviceStep");
        String warrantyType = request.getParameter("warrantyType");

        if(StringUtil.isNotBlank(orderId) && StringUtil.isNotBlank(servicrStep)){
            CrmOrder or = orderService.getOrderById(orderId);
            Record rd =  customerSettlementTemplateService.getSetTemplateByServiceStep(servicrStep,warrantyType,or.getServiceType());
            if(rd!= null){
                return rd;
            }
        }
        return null;
    }


    @ResponseBody
    @RequestMapping(value = "checkEmployeQrcode")
    public Object checkEmployeQrcode(HttpServletRequest request){
        String userId = request.getParameter("userId");
        if(StringUtil.isBlank(userId)){
            return Result.fail("202","数据有误");
        }
        Record rd = CrmUtils.getEmployeId(userId);
        if(rd == null){
            return Result.fail("202","数据有误");
        }
        if("0".equals(rd.getStr("qrcode"))){
            return Result.ok();
        }
        return Result.fail("201","暂无开通");
    }

    @ResponseBody
    @RequestMapping(value = "getSysApk")
    public Object getSysApk(HttpServletRequest request){
        Map<String,Object> map = Maps.newHashMap();
        String id = request.getParameter("id");
        if(StringUtil.isBlank(id)){
            map.put("code","205");
            map.put("data","");
            map.put("msg","ID为空");
        }else{
            Record rd = smallProgramOrderService.getSysApk(id);
            map.put("code","200");
            map.put("data",rd != null?rd.getColumns():"");
            map.put("msg","");
        }
        return map;
    }

    /**
     * 获取省码---省电力公司
     */
    @ResponseBody
    @RequestMapping(value = "/getProviceCodeList")
    public Result getProviceCodeList(HttpServletRequest request){
        //地址信息
        List<Record> list = addressService.getProviceCodeList();
        Result result=new Result();
        result.setOk();
        result.data(list);
        return result;
    }


}