package com.palmnest.webapp.controller.backstage;

import cn.jiguang.common.utils.StringUtils;
import cn.superdesk.libs.common.util.BeanUtils;

import com.palmnest.application.AppConstants;
import com.palmnest.application.CodeConstants;
import com.palmnest.application.Constants;
import com.palmnest.application.bean.AppResultDto;
import com.palmnest.application.bean.Page;
import com.palmnest.application.core.util.AppResultUtil;
import com.palmnest.application.core.util.StringUtil;
import com.palmnest.application.dto.OrgDto;
import com.palmnest.application.dto.WebPageResultDto;
import com.palmnest.application.dto.input.RepairBillInputDto;
import com.palmnest.application.dto.output.ElementDto;
import com.palmnest.application.dto.output.RepairSumIndexDto;
import com.palmnest.model.Element;
import com.palmnest.model.User;
import com.palmnest.model.estateserve.WxUser;
import com.palmnest.model.repair.RepairBill;
import com.palmnest.model.repair.RepairConfig;
import com.palmnest.model.repair.RepairOperateRecord;
import com.palmnest.model.repair.RepairReturnVisit;
import com.palmnest.service.AppUserService;
import com.palmnest.service.ElementGroupManager;
import com.palmnest.service.UserManager;
import com.palmnest.service.repair.*;
import com.palmnest.webapp.controller.BaseFormController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ExtendedModelMap;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.*;

@Controller
@RequestMapping(value = "/repairBill")
public class RepairBillController extends BaseFormController {

    @Autowired
    private ElementGroupManager elementGroupManager;
    @Autowired
    private RepairBillService repairBillService;
    @Autowired
    private UserRepairTypeManager userRepairTypeManager;
    @Autowired
    private RepairBillManager repairBillManager;
    @Autowired
    private RepairOperateRecordManager repairOperateRecordManager;
    @Autowired
    private RepairBillMaterialManager repairBillMaterialManager;
    @Autowired
    private UserManager userManager;
    @Autowired
    private RepairReturnVisitManager repairReturnVisitManager;
    @Autowired
    private AppUserService appUserService;
    //dz add
    @Autowired
    private RepairConfigManager repairConfigManager;

    /**
     * 发起维修首页
     *
     * @return
     */
    @RequestMapping(value = "/index")
    public ModelAndView index(HttpServletRequest request) {
        //报修方式 区域 类型 小类型
        Model model = new ExtendedModelMap();
        User user = (User) request.getSession().getAttribute("UserCache");
        List<OrgDto> dtos = appUserService.getUserOrgs(user.getId());
        List<Element> repairWayGroup = elementGroupManager.getElementsByGroupName("repairWayGroup");
        Element element = elementGroupManager.getByItemCode("wechatRepair");
        repairWayGroup.remove(element);
        List<Element> repairAreaGroup = elementGroupManager.getElementsByGroupName("repairAreaGroup");
        model.addAttribute("repairWayGroup", elementGroupManager.convert(repairWayGroup));
        model.addAttribute("repairAreaGroup", elementGroupManager.convert(repairAreaGroup));
//        String orgId="";
//        if(null!=dtos&&dtos.size()==1){
//        	if(null!=dtos.get(0)){
//        		orgId=dtos.get(0).getId()+"";
//        	}
//        }
//        List<Element> repairTypeGroup = elementGroupManager.getElementsByGroupName("repairTypeGroup",orgId);
//        List<ElementDto> list=elementGroupManager.convert(repairTypeGroup);
//        model.addAttribute("repairTypeGroup",list);
        List<Element> repairTypeGroup = new ArrayList<>();
        if (null != dtos && dtos.size() > 0) {
            for (OrgDto orgDto :
                    dtos) {
                //大类
                List<ElementDto> elementDtos = elementGroupManager.getOrgElementGroupInfoV2(String.valueOf(orgDto.getId()), "repairTypeGroup");
                if (null != elementDtos && elementDtos.size() > 0) {
                    List<Element> repairTypeGroups = BeanUtils.copy(elementDtos, Element.class);
                    repairTypeGroup.addAll(repairTypeGroups);
                }
            }

        } else {
            repairTypeGroup = elementGroupManager.getElementsByGroupName("repairTypeGroup");
        }
        
        model.addAttribute("repairTypeGroup", elementGroupManager.convert(repairTypeGroup));
        if (repairTypeGroup.size() > 0) {
            List<Element> repairTypeaDetailGroup = elementGroupManager.getElementsByGroupName(repairTypeGroup.get(0).getItemcode());
            model.addAttribute("repairTypeaDetailGroup", elementGroupManager.convert(repairTypeaDetailGroup));
        }
        
        model.addAttribute("orgs", dtos);
        if(null != user){
            model.addAttribute("userType", user.getUserType());
        }
        model.addAttribute("username", user.getFullName());
        model.addAttribute("telephone", user.getTelephone());
        return new ModelAndView("/admin/engineeringRepair/launchRepair", model.asMap());
    }

    /**
     * 评价管理
     *
     * @return
     */
    @RequestMapping(value = "/evaluationManagement")
    public ModelAndView manage(HttpServletRequest request) {
        Model model = new ExtendedModelMap();
        User user = (User) request.getSession().getAttribute("UserCache");
        List<OrgDto> dtos = appUserService.getUserOrgs(user.getId());
        List<Element> repairWayGroup = elementGroupManager.getElementsByGroupName("repairWayGroup");
        List<Element> repairAreaGroup = elementGroupManager.getElementsByGroupName("repairAreaGroup");
        model.addAttribute("repairWayGroup", elementGroupManager.convert(repairWayGroup));
        model.addAttribute("repairAreaGroup", elementGroupManager.convert(repairAreaGroup));
        List<Element> repairTypeGroup = new ArrayList<>();
        if (null != dtos && dtos.size() > 0) {
            for (OrgDto orgDto :
                    dtos) {
                //大类
                List<ElementDto> elementDtos = elementGroupManager.getOrgElementGroupInfoV2(String.valueOf(orgDto.getId()), "repairTypeGroup");
                if (null != elementDtos && elementDtos.size() > 0) {
                    List<Element> repairTypeGroups = BeanUtils.copy(elementDtos, Element.class);
                    repairTypeGroup.addAll(repairTypeGroups);
                }
            }

        } else {
            repairTypeGroup = elementGroupManager.getElementsByGroupName("repairTypeGroup");
        }
        
        model.addAttribute("repairTypeGroup", elementGroupManager.convert(repairTypeGroup));

        if (repairTypeGroup.size() > 0) {
            List<Element> repairTypeaDetailGroup = elementGroupManager.getElementsByGroupName(repairTypeGroup.get(0).getItemcode());
            model.addAttribute("repairTypeaDetailGroup", elementGroupManager.convert(repairTypeaDetailGroup));
        }
        
        model.addAttribute("orgs", dtos);
        if(null != user){
            model.addAttribute("userType", user.getUserType());
        }
        return new ModelAndView("/admin/engineeringRepair/evaluationManagement", model.asMap());
    }

    /**
     * 订单列表
     *
     * @return
     */
    @RequestMapping(value = "/repairDetail")
    public ModelAndView repairDetail(HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("UserCache");
        //报修方式 区域 类型 小类型
        Model model = new ExtendedModelMap();
        List<Element> repairWayGroup = elementGroupManager.getElementsByGroupName("repairWayGroup");
        List<Element> repairAreaGroup = elementGroupManager.getElementsByGroupName("repairAreaGroup");
        //List<Element> repairTypeGroup = elementGroupManager.getElementsByGroupName("repairTypeGroup");

        List<Element> repairTypeGroup = new ArrayList<>();

        // 获取当前项目
        List<OrgDto> dtos = appUserService.getUserOrgs(user.getId());
        if (null != dtos && dtos.size() > 0) {
            for (OrgDto orgDto :
                    dtos) {
                //大类
                List<ElementDto> elementDtos = elementGroupManager.getOrgElementGroupInfoV2(String.valueOf(orgDto.getId()), "repairTypeGroup");
                if (null != elementDtos && elementDtos.size() > 0) {
                    List<Element> repairTypeGroups = BeanUtils.copy(elementDtos, Element.class);
                    repairTypeGroup.addAll(repairTypeGroups);
                }
            }

        } else {
            repairTypeGroup = elementGroupManager.getElementsByGroupName("repairTypeGroup");
        }


        model.addAttribute("repairWayGroup", elementGroupManager.convert(repairWayGroup));
        model.addAttribute("repairAreaGroup", elementGroupManager.convert(repairAreaGroup));
        model.addAttribute("repairTypeGroup", elementGroupManager.convert(repairTypeGroup));

        if (repairTypeGroup.size() > 0) {
            List<Element> repairTypeaDetailGroup = elementGroupManager.getElementsByGroupName(repairTypeGroup.get(0).getItemcode());
            model.addAttribute("repairTypeaDetailGroup", elementGroupManager.convert(repairTypeaDetailGroup));
        }

        model.addAttribute("orgs", dtos);
        if(null != user){
            model.addAttribute("userType", user.getUserType());
        }
        return new ModelAndView("/admin/engineeringRepair/repairDetail", model.asMap());
    }

    @RequestMapping(value = "/test")
    public ModelAndView testview(HttpServletRequest request, HttpServletResponse response) {
        Model model = new ExtendedModelMap();
        return new ModelAndView("/admin/engineeringRepair/test");
    }

    /**
     * 根据维修类型查找维修类型详情
     *
     * @param repairTypeId
     * @return
     */
    @RequestMapping(value = "/getRepairTypeaDetail")
    @ResponseBody
    public AppResultDto getRepairTypeaDetail(@RequestParam("repairTypeId") Long repairTypeId) {
        Element element = elementGroupManager.getElementId(repairTypeId);
        List<Element> repairTypeaDetailGroup = elementGroupManager.getElementsByGroupName(element.getItemcode());
        return AppResultUtil.createSuccesDto(repairTypeaDetailGroup);
    }

    /**
     * 发起维修
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/repair")
    @ResponseBody
    public AppResultDto repair(@ModelAttribute("repairBillInputDto") RepairBillInputDto dto, MultipartHttpServletRequest request) {
        try {
            RepairBill bill = repairBillService.repair(dto, request);
            repairBillService.push(bill);
            return AppResultUtil.createSuccesDto(repairBillService.convert(bill));
        } catch (Exception e) {
            e.printStackTrace();
            return AppResultUtil.createErrorDto(AppConstants.REPAIR_BILL_ERROR, "保存维修单失败");
        }
    }

    /**
     * 查找维修单详情
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/getDetail")
    @ResponseBody
    public AppResultDto getDetail(@RequestParam("id") Long id) {
        return AppResultUtil.createSuccesDto(repairBillService.findById(id));
    }

    /**
     * 修改维修单分类 并重新派单
     * @param id 维修单id
     * @param repairTypeId 维修大类id
     * @param repairTypeDetailId 维修小类id
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateBillType")
    @ResponseBody
    public AppResultDto updateBillType(@RequestParam("id") Long id,
                                       @RequestParam("repairTypeId") Long repairTypeId,
                                       @RequestParam("repairTypeDetailId") Long repairTypeDetailId,
                                       HttpServletRequest request) {

        User user = (User) request.getSession().getAttribute("UserCache");
        if(null == repairTypeId || (null != repairTypeId && 0 == repairTypeId.intValue())){
            return AppResultUtil.createErrorDto(AppConstants.ERROR_CODE, "维修大类不能为空");
        }
        if(null == repairTypeDetailId || (null != repairTypeDetailId && 0 == repairTypeDetailId.intValue())){
            return AppResultUtil.createErrorDto(AppConstants.ERROR_CODE, "维修小类不能为空");
        }
        try {
            RepairBill bill = repairBillManager.get(id);
            //状态 TODO
            if (bill.getStatus().equals(CodeConstants.COMPLETED) ||
                    bill.getStatus().equals(CodeConstants.UNAUDIT) ||
                    bill.getStatus().equals(CodeConstants.CANCEL)) {
                return AppResultUtil.createErrorDto(AppConstants.SEND_BILL_ERROR, "修改失败，该单已取消或已完成");
            }
            bill.setRepairType(repairTypeId);
            bill.setRepairTypeDetail(repairTypeDetailId);
            repairBillManager.updateModel(bill);

            RepairOperateRecord operateRecord = new RepairOperateRecord(bill.getId(), user.getUsername(), new Date());
            operateRecord.setUserId(user.getId());
            operateRecord.setOperateType(CodeConstants.REPAIR);
            operateRecord.setDetail(user.getFullName() + "修改维修单类型");
            repairOperateRecordManager.saveModel(operateRecord);

//                String title = "有维修单已派给你，请查看";
//                String content = repairBillService.getPushContent(bill);
//                repairBillService.pushMessage(bill.getId(), CodeConstants.COMMON_PUSH_CODE, title, content, Arrays.asList(user));

            return AppResultUtil.createSuccesDto();
        } catch (Exception e) {
            e.printStackTrace();
            return AppResultUtil.createErrorDto(AppConstants.SEND_ERROR, "改单失败");
        }
    }


    /**
     * @param request
     * @return 查找对应维修类型下的人员
     */
    @RequestMapping(value = "/getRepairTypeUser")
    @ResponseBody
    public AppResultDto getRepairTypeUser(@RequestParam("repairTypeId") Long repairTypeId, HttpServletRequest request) {
        //PC端根据订单的项目Id，来传
        String orgIds = request.getParameter("orgId");
        Integer orgId = null;
        if (StringUtil.isNotEmpty(orgIds)) {
            orgId = Integer.parseInt(orgIds);
        }
        if (null == orgId) {
            return AppResultUtil.createSuccesDto(repairBillService.findByTypeId(repairTypeId));
        }
        return AppResultUtil.createSuccesDto(repairBillService.findByTypeId(repairTypeId, orgId));
    }

    /**
     * 查找所有维修类型
     *
     * @return
     */
    @RequestMapping(value = "/getRepairType")
    @ResponseBody
    public AppResultDto getRepairType() {
        List<Element> repairTypeGroup = elementGroupManager.getElementsByGroupName(Constants.REPAIR_TYPE_CODE);
        return AppResultUtil.createSuccesDto(elementGroupManager.convert(repairTypeGroup));
    }

    /**
     * @param request
     * @return 查找维修单列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public WebPageResultDto list(HttpServletRequest request) {
        try {
            int pageSize = Integer.parseInt(request.getParameter("limit"));
            int pageNo = Integer.parseInt(request.getParameter("page"));
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("startTime", request.getParameter("startTime"));
            params.put("endTime", request.getParameter("endTime"));
            params.put("repairWay", request.getParameter("repairWay"));
            params.put("repairArea", request.getParameter("repairArea"));
            params.put("repairType", request.getParameter("repairType"));
            params.put("status", request.getParameter("status"));
            params.put("confirmStatus", request.getParameter("confirmStatus"));//确认状态 1-待确认 2-已确认
            params.put("code", request.getParameter("code"));
            params.put("star", request.getParameter("star"));
            params.put("hasComment", request.getParameter("hasComment"));//1,2
            params.put("hasReturnVisit", request.getParameter("hasReturnVisit"));//1,2
            params.put("serviceUsers", request.getParameter("serviceUsers"));//工程人员
            params.put("managerName", request.getParameter("managerName"));//派单人名称 模糊搜索
            String repairTypeIds = "";
            User user = (User) request.getSession().getAttribute("UserCache");
            List<Element> types = userRepairTypeManager.findByUser(user.getId());
            for (Element e : types) {
                repairTypeIds += "," + e.getId();
            }
            if (repairTypeIds.length() > 1) {
                repairTypeIds = repairTypeIds.substring(1);
            }
            params.put("repairTypeIds", repairTypeIds);
            String orgIds = getUserManageOrgIds(user);//例如:1,25,2
            if (StringUtil.isNotEmpty(request.getParameter("orgId"))) {
                params.put("orgIds", request.getParameter("orgId"));
            } else {
                params.put("orgIds", orgIds);
            }
            Page page = repairBillService.findPageBy(params, pageSize, pageNo);
            WebPageResultDto dto = new WebPageResultDto(AppConstants.SUCCESS_CODE, "成功", page.getItems());
            dto.setCount(page.getTotalCount());
            return dto;
        } catch (Exception e) {
            e.printStackTrace();
            return new WebPageResultDto(AppConstants.REPAIR_BILL_LIST_ERROR, "查询列表失败", null);
        }
    }

    /**
     * @param request
     * @return 查找维修单对应维修类型下的人员
     */
    @RequestMapping(value = "/getRepairUser")
    @ResponseBody
    public AppResultDto getRepairUser(@RequestParam("id") Long id, HttpServletRequest request) {
        RepairBill bill = repairBillManager.get(id);
        return AppResultUtil.createSuccesDto(repairBillService.getRepairUsers(bill.getRepairType(), bill.getOrgId()));
    }

    /**
     * 审核
     */
    @RequestMapping(value = "/auditBill")
    @ResponseBody
    public AppResultDto auditBill(@RequestParam("id") Long id, Integer operateType, HttpServletRequest request) {
        try {
            RepairBill bill = repairBillManager.get(id);
            //状态 TODO
            if (!bill.getStatus().equals(CodeConstants.TO_AUDIT)) {
                return AppResultUtil.createErrorDto(AppConstants.AUDIT_BILL_ERROR, "审核失败，该单不是可审核状态");
            }
            User user = (User) request.getSession().getAttribute("UserCache");
            repairBillService.audit(id, operateType, user);
            repairBillService.auditPush(operateType, bill);
            return AppResultUtil.createSuccesDto();
        } catch (Exception e) {
            e.printStackTrace();
            return AppResultUtil.createErrorDto(AppConstants.AUDIT_BILL_ERROR, "审核失败");
        }
    }


    /**
     * 派单  dz change 1029
     */
    @RequestMapping(value = "/sendBill")
    @ResponseBody
    public AppResultDto sendBill(@RequestParam("id") Long id, @RequestParam("receiverId") String receiverId, HttpServletRequest request) {
        try {
            RepairBill bill = repairBillManager.get(id);
            //状态 TODO
            if (!bill.getStatus().equals(CodeConstants.IN_PROGRESS) && !bill.getStatus().equals(CodeConstants.IS_SINGLE)
                    && !bill.getStatus().equals(CodeConstants.IN) && !bill.getStatus().equals(CodeConstants.TO_SEND)) {
                return AppResultUtil.createErrorDto(AppConstants.SEND_BILL_ERROR, "派单失败，该单不是可派单状态");
            }

            String[] users = receiverId.split(",");
            if (users.length == 0) {
                return AppResultUtil.createErrorDto(AppConstants.SEND_ERROR, "请选择维修工程师！");
            }
            RepairConfig s_con = repairConfigManager.getByOrgId(bill.getOrgId());
            if (users.length > 1) {
                //一单多人判断
                if (s_con.getIspersons() == 2) {
                    return AppResultUtil.createErrorDto(AppConstants.SEND_ERROR, "本项目不可派给多个工程师！");
                }
            }
            //判断是否超过接单数量
            for (int i = 0; i < users.length; i++) {
                Integer c = repairBillManager.findCountBy(CodeConstants.IN_PROGRESS, null, Long.parseLong(users[i]), null);
                int max_bills = 3;
                if (s_con != null) {
                    max_bills = s_con.getMax_bills();
                }
                if (c > max_bills) {
                    User user = userManager.get(Long.parseLong(users[i]));
                    return AppResultUtil.createErrorDto(AppConstants.SEND_ERROR, user.getFullName() + " 进行中的工单数量超过 " + max_bills + " ，请重新选择工程师！");
                }
            }

            User user1 = (User) request.getSession().getAttribute("UserCache");
            bill.setStatus(CodeConstants.IN_PROGRESS);//派单成功设置状态为进行中
            bill.setConfirmStatus(1);
            bill.setServiceUser(receiverId);
            if(null == bill.getSingleTime()){
                bill.setSingleTime(new Date());
            }
            repairBillManager.updateModel(bill);
            for (int i = 0; i < users.length; i++) {
                User user = userManager.get(Long.parseLong(users[i]));
                RepairOperateRecord operateRecord = new RepairOperateRecord(id, user1.getId(), user1.getFullName(), new Date());
                operateRecord.setOperateType(CodeConstants.SEND);
                operateRecord.setIsConfirm(0);
                operateRecord.setDetail(user1.getFullName() + "派单给" + user.getFullName());
                repairOperateRecordManager.saveModel(operateRecord);

                String title = "有维修单已派给你，请查看";
                String content = repairBillService.getPushContent(bill);
                repairBillService.pushMessage(bill.getId(), CodeConstants.COMMON_PUSH_CODE, title, content, Arrays.asList(user));
            }


            return AppResultUtil.createSuccesDto();
        } catch (Exception e) {
            e.printStackTrace();
            return AppResultUtil.createErrorDto(AppConstants.SEND_ERROR, "派单失败");
        }
    }

    @RequestMapping(value = "/addOrUpdateVisit")
    @ResponseBody
    public AppResultDto addOrUpdateVisit(@RequestParam("billId") Long billId, @RequestParam(required = false) Long id, Integer star, String description) {
        try {
            RepairReturnVisit visit = null;
            if (id == null) {
                visit = new RepairReturnVisit(billId, star, description);
                repairReturnVisitManager.saveModel(visit);
            } else {
                visit = repairReturnVisitManager.get(id);
                if (visit != null) {
                    visit.setDescription(description);
                    visit.setStar(star);
                    repairReturnVisitManager.updateModel(visit);
                }
            }
            RepairBill bill = repairBillManager.get(billId);
            bill.setHasReturnVisit(Integer.parseInt("2"));
            repairBillManager.updateModel(bill);
            return AppResultUtil.createSuccesDto();
        } catch (Exception e) {
            e.printStackTrace();
            return AppResultUtil.createErrorDto(AppConstants.ADD_RETURN_VISIT_ERROR, "添加回访记录失败");
        }
    }

    //add dz 1029

    /**
     * @param request
     * @return 查找维修单对应维修类型下的人员
     */
    @RequestMapping(value = "/getconfigbyorg")
    @ResponseBody
    public AppResultDto getconfigbyorg(@RequestParam("org_id") Integer org_id, HttpServletRequest request) {
        RepairConfig s_con = repairConfigManager.getByOrgId(org_id);
        return AppResultUtil.createSuccesDto(s_con);
    }

    /**
     * 功能配置-确认
     */
    @RequestMapping(value = "/configsave")
    @ResponseBody
    public AppResultDto configsave(HttpServletRequest request) {
        try {
            User user = (User) request.getSession().getAttribute("UserCache");
            Integer org_id = Integer.parseInt(request.getParameter("org_id"));
            RepairConfig s_con = repairConfigManager.getByOrgId(org_id);
            RepairConfig con = new RepairConfig();
            if (s_con == null) {
                con.setCreate_time(new Date());
                con.setCreate_user_id(user.getId());
                con.setUpdate_time(new Date());
                con.setUpdate_user_id(user.getId());
            } else {
                con.setId(s_con.getId());
                con.setUpdate_time(new Date());
                con.setUpdate_user_id(user.getId());
            }
            Byte ispay = Byte.valueOf(request.getParameter("ispay"));
            con.setIspay(ispay);
            Byte ispersons = Byte.valueOf(request.getParameter("ispersons"));
            con.setIspersons(ispersons);
            Integer max_bills = Integer.parseInt(request.getParameter("max_bills"));
            con.setMax_bills(max_bills);

            con.setOrg_id(org_id);
            Integer repair_type = Integer.parseInt(request.getParameter("repair_type"));
            con.setRepair_type(repair_type);
            Integer checkFloor = Integer.parseInt(request.getParameter("checkFloor"));
            con.setCheckFloor(checkFloor);


            Integer isCompleteDesc = Integer.parseInt(request.getParameter("isCompleteDesc"));
            con.setIsCompleteDesc(isCompleteDesc);

            Integer isCompletePhoto = Integer.parseInt(request.getParameter("isCompletePhoto"));
            con.setIsCompletePhoto(isCompletePhoto);

            Integer isDeliveryConfirm = Integer.parseInt(request.getParameter("isDeliveryConfirm"));
            con.setIsDeliveryConfirm(isDeliveryConfirm);

            String supportReport=request.getParameter("supportReport");
            if(StringUtils.isNotEmpty(supportReport)){
            	con.setSupportReport(Integer.parseInt(supportReport));
            }else{
            	con.setSupportReport(0);
            }
            if (con.getId() == null) {
                repairConfigManager.saveModel(con);
            } else {
                repairConfigManager.updateModel(con);
            }

            return AppResultUtil.createSuccesDto();
        } catch (Exception e) {
            e.printStackTrace();
            return AppResultUtil.createErrorDto("400", "配置错误！");
        }
    }


    /**
     * test
     *
     * @param request
     * @return
     */
    @RequestMapping("/msgtest")
    @ResponseBody
    public AppResultDto test(HttpServletRequest request) {
        String username = request.getParameter("username");
        RepairSumIndexDto repairSum = repairBillService.findBy(username);

        return AppResultUtil.createSuccesDto("查询成功", repairSum);
    }

    @RequestMapping(value = "/cancelOrder")
    @ResponseBody
    public AppResultDto cancelOrder(HttpServletRequest request) {
        try {
            String                 id    = request.getParameter("id");
            User user = (User) request.getSession().getAttribute("UserCache");

            repairBillService.cancelOrder(id,user);
            return AppResultUtil.createSuccesDto();
        } catch (Exception e) {
            e.printStackTrace();
            return AppResultUtil.createErrorDto("400", "取消失败！");
        }
    }

    /**
     * test
     *
     * @param request
     * @return
     */
    @RequestMapping("/automaticHighPraise")
    @ResponseBody
    public AppResultDto automaticHighPraise(HttpServletRequest request) throws Exception {

        repairBillService.automaticHighPraise();

        return AppResultUtil.createSuccesDto("查询成功");
    }



}
