|  |  |  | 
|---|
|  |  |  | import com.core.common.DateUtils; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.core.domain.KeyValueVo; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.crm.common.model.SettleDto; | 
|---|
|  |  |  | import com.zy.crm.common.web.BaseController; | 
|---|
|  |  |  | import com.zy.crm.manager.entity.*; | 
|---|
|  |  |  | import com.zy.crm.manager.service.ItemService; | 
|---|
|  |  |  | import com.zy.crm.manager.service.PlanService; | 
|---|
|  |  |  | import com.zy.crm.manager.service.PriQuoteBudgetService; | 
|---|
|  |  |  | import com.zy.crm.manager.service.PriQuoteService; | 
|---|
|  |  |  | import com.zy.crm.manager.service.*; | 
|---|
|  |  |  | import com.zy.crm.system.entity.User; | 
|---|
|  |  |  | import com.zy.crm.system.service.UserService; | 
|---|
|  |  |  | import org.apache.poi.xssf.usermodel.XSSFSheet; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PriQuoteBudgetService priQuoteBudgetService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PriOnline2Service priOnline2Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ProcessPermissionsService processPermissionsService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PlanTypeService planTypeService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String PZH=" ———————————————————————————————————————————————————————————————————————————————— "; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/priQuote/{id}/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R get(@PathVariable("id") String id) { | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestParam(required = false)String condition, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param){ | 
|---|
|  |  |  | EntityWrapper<PriQuote> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.setSqlSelect("id,title,create_time as createTime,filepath,item_id as itemId,order_num as orderNum,template_name as templateName,user_id as userId,update_user_id as updateUserId,update_time as updateTime,in_order_num as inOrderNum,member_id as memberId"); | 
|---|
|  |  |  | wrapper.in("member_id", getUserRoleBelongsToUserId()); | 
|---|
|  |  |  | wrapper.setSqlSelect("id,title,create_time as createTime,filepath,item_id as itemId,order_num as orderNum,template_name as templateName,sheet_data as sheetData,user_id as userId,dept_id as deptId,settle,settle_msg as settleMsg,form,update_user_id as updateUserId,update_time as updateTime,in_order_num as inOrderNum,member_id as memberId,template"); | 
|---|
|  |  |  | //        wrapper.in("member_id", getUserRoleBelongsToUserId()); | 
|---|
|  |  |  | excludeTrash(param); | 
|---|
|  |  |  | convert(param, wrapper); | 
|---|
|  |  |  | allLike(PriQuote.class, param.keySet(), wrapper, condition); | 
|---|
|  |  |  | wrapper.or().eq("member_id",getUserId()); | 
|---|
|  |  |  | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} | 
|---|
|  |  |  | return R.ok(priQuoteService.selectPage(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ | 
|---|
|  |  |  | Long deptId = getDeptId(); | 
|---|
|  |  |  | boolean signUserId = false; | 
|---|
|  |  |  | boolean signDeptId = false; | 
|---|
|  |  |  | boolean signHostId = false; | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()){ | 
|---|
|  |  |  | if (entry.getKey().equals("dept_id")){ | 
|---|
|  |  |  | signDeptId = true; | 
|---|
|  |  |  | if (String.valueOf(entry.getValue()).equals("19")){ | 
|---|
|  |  |  | signHostId = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()){ | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!signUserId && !signDeptId){ | 
|---|
|  |  |  | wrapper.eq("user_id", getUserId()); | 
|---|
|  |  |  | if (getRole().getId()==1){ | 
|---|
|  |  |  | wrapper.or().eq("host_id",1); | 
|---|
|  |  |  | }else if (getRole().getId()==2){ | 
|---|
|  |  |  | wrapper.eq("dept_id",getDeptId()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | wrapper.eq("user_id", getUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (signHostId){ | 
|---|
|  |  |  | wrapper.or().eq("host_id",1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/priQuote/add/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | @ManagerAuth(memo = "添加报价单") | 
|---|
|  |  |  | public R add(@RequestBody Map<String,Object> map) { | 
|---|
|  |  |  | PriQuoteBudget priQuoteBudget = priQuoteBudgetService.selectById(Long.parseLong(map.get("priQuoteBudgetId").toString())); | 
|---|
|  |  |  | //        PriQuoteBudget priQuoteBudget = priQuoteBudgetService.selectById(Long.parseLong(map.get("priQuoteBudgetId").toString())); | 
|---|
|  |  |  | PriOnline2 priOnline2 = priOnline2Service.selectById(Long.parseLong(map.get("priQuoteBudgetId").toString())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PriQuote priQuote = new PriQuote(); | 
|---|
|  |  |  | priQuote.setCreateTime(new Date()); | 
|---|
|  |  |  | priQuote.setTitle(map.get("title").toString()); | 
|---|
|  |  |  | priQuote.setTemplateName(priQuoteBudget.getTemplateName()); | 
|---|
|  |  |  | priQuote.setTemplateName(priOnline2.getTemplateName()); | 
|---|
|  |  |  | priQuote.setSheetData(map.get("sheetData").toString()); | 
|---|
|  |  |  | priQuote.setItemId(priQuoteBudget.getItemId()); | 
|---|
|  |  |  | priQuote.setOrderNum(priQuoteBudget.getInOrderNum()); | 
|---|
|  |  |  | priQuote.setPriOnlineId(Long.parseLong(map.get("priQuoteBudgetId").toString())); | 
|---|
|  |  |  | priQuote.setItemId(priOnline2.getItemId()); | 
|---|
|  |  |  | priQuote.setOrderNum(priOnline2.getOrderNum()); | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); | 
|---|
|  |  |  | priQuote.setInOrderNum(format.format(new Date())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //创建人员 | 
|---|
|  |  |  | priQuote.setUserId(getUserId()); | 
|---|
|  |  |  | //更新人员 | 
|---|
|  |  |  | priQuote.setUpdateUserId(getUserId()); | 
|---|
|  |  |  | //更新时间 | 
|---|
|  |  |  | priQuote.setUpdateTime(new Date()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //业务员 | 
|---|
|  |  |  | Plan plan = planService.selectById(priQuote.getItemId()); | 
|---|
|  |  |  | priQuote.setMemberId(plan.getUserId()); | 
|---|
|  |  |  | User userUp = userService.selectById(plan.getUserId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //业务员 | 
|---|
|  |  |  | priQuote.setUserId(userUp.getId()); | 
|---|
|  |  |  | //更新人员 | 
|---|
|  |  |  | priQuote.setUpdateUserId(getUserId()); | 
|---|
|  |  |  | //所属部门 | 
|---|
|  |  |  | priQuote.setDeptId(userUp.getDeptId()); | 
|---|
|  |  |  | //更新时间 | 
|---|
|  |  |  | priQuote.setUpdateTime(new Date()); | 
|---|
|  |  |  | //模板 | 
|---|
|  |  |  | priQuote.setTemplate(map.get("template").toString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //设置项目流程 | 
|---|
|  |  |  | plan.setStep(5); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | priQuote.setForm(JSON.toJSONString(map));     // 自定义表单内容 | 
|---|
|  |  |  | priQuote.setSettle(1);  // 1.开始 | 
|---|
|  |  |  | User manager = userService.getDeptManager(getHostId(), getUser().getDeptId());        // 获取部门领导 | 
|---|
|  |  |  | priQuote.setSettleMsg(JSON.toJSONString(SettleDto.init(plan, manager))); | 
|---|
|  |  |  | User manager = new User(); | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | manager = userService.getDeptManager(getHostId(), userUp.getDeptId());        // 获取部门领导 | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | manager = userUp; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | priQuote.setMemberId(manager.getId()); | 
|---|
|  |  |  | ProcessPermissions processPermissions = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 2).eq("process", "3-1"));//2:报价流程 | 
|---|
|  |  |  | User president = userService.selectById(processPermissions.getUserId());       // 获取报价流程节点3-1确认人 | 
|---|
|  |  |  | priQuote.setSettleMsg(JSON.toJSONString(SettleDto.initPriQuote(plan, manager,president,getUser()))); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | planService.updateById(plan); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/priQuote/addOther/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | @ManagerAuth(memo = "另存报价单") | 
|---|
|  |  |  | public R addOther(@RequestBody Map<String,Object> map) { | 
|---|
|  |  |  | PriQuote quote = priQuoteService.selectById(Long.parseLong(map.get("id").toString())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/priQuote/update/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | @ManagerAuth(memo = "更新报价单") | 
|---|
|  |  |  | public R update(@RequestBody Map<String,Object> map){ | 
|---|
|  |  |  | PriQuote priQuote = priQuoteService.selectById(Long.parseLong(map.get("id").toString())); | 
|---|
|  |  |  | priQuote.setTitle(map.get("title").toString()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/priQuote/updateForm/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | @ManagerAuth(memo = "更新报价单") | 
|---|
|  |  |  | public R updateForm(Long id,String templateName,String title){ | 
|---|
|  |  |  | PriQuote priQuote = priQuoteService.selectById(id); | 
|---|
|  |  |  | priQuote.setTemplateName(templateName); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/priQuote/delete/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | @ManagerAuth(memo = "删除报价单") | 
|---|
|  |  |  | public R delete(Long[] ids){ | 
|---|
|  |  |  | if (Cools.isEmpty(ids)){ | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | 
|---|
|  |  |  | public R query(String condition) { | 
|---|
|  |  |  | EntityWrapper<PriQuote> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.like("id", condition); | 
|---|
|  |  |  | wrapper.in("member_id", getUserRoleBelongsToUserId()); | 
|---|
|  |  |  | wrapper.in("user_id", getUserRoleBelongsToUserId()); | 
|---|
|  |  |  | Page<PriQuote> page = priQuoteService.selectPage(new Page<>(0, 10), wrapper); | 
|---|
|  |  |  | List<Map<String, Object>> result = new ArrayList<>(); | 
|---|
|  |  |  | for (PriQuote priQuote : page.getRecords()){ | 
|---|
|  |  |  | 
|---|
|  |  |  | String path =  ClassUtils.getDefaultClassLoader().getResource("excel").getPath(); | 
|---|
|  |  |  | String filename = format.format(new Date()) + ".xlsx"; | 
|---|
|  |  |  | String filepath = path + "/" + filename; | 
|---|
|  |  |  | exportLuckySheetXlsx(path,"/" + filename,map.get("exceldata").toString()); | 
|---|
|  |  |  | exportLuckySheetXlsx(path, "/" + filename, map.get("exceldata").toString(), map.get("template").toString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok("/priQuote/excel/" + filename); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void exportLuckySheetXlsx(String newFileDir,String newFileName, String excelData) { | 
|---|
|  |  |  | public void exportLuckySheetXlsx(String newFileDir, String newFileName, String excelData, String template) { | 
|---|
|  |  |  | //解析对象,可以参照官方文档:https://mengshukeji.github.io/LuckysheetDocs/zh/guide/#%E6%95%B4%E4%BD%93%E7%BB%93%E6%9E%84 | 
|---|
|  |  |  | JSONArray jsonArray = (JSONArray) JSONObject.parse(excelData); | 
|---|
|  |  |  | //如果只有一个sheet那就是get(0),有多个那就对应取下标 | 
|---|
|  |  |  | JSONObject jsonObject = (JSONObject) jsonArray.get(0); | 
|---|
|  |  |  | JSONArray jsonObjectList = jsonObject.getJSONArray("celldata"); | 
|---|
|  |  |  | //excel模板路径 | 
|---|
|  |  |  | String filePath =  ClassUtils.getDefaultClassLoader().getResource("excel").getPath() + "/priQuoteTemplate.xlsx"; | 
|---|
|  |  |  | String filePath = ClassUtils.getDefaultClassLoader().getResource("excel").getPath() + "/priQuoteTemplate/data" + template +".xlsx"; | 
|---|
|  |  |  | //        String filePath = "/Users/ouyang/Downloads/uploadTestProductFile/生产日报表.xlsx"; | 
|---|
|  |  |  | File file = new File(filePath); | 
|---|
|  |  |  | FileInputStream in = null; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String value = ""; | 
|---|
|  |  |  | if (jsonObjectValue != null && jsonObjectValue.get("v") != null){ | 
|---|
|  |  |  | if (jsonObjectValue != null && jsonObjectValue.get("v") != null) { | 
|---|
|  |  |  | //获取单元格值 | 
|---|
|  |  |  | value = jsonObjectValue.get("v").toString(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Integer.parseInt(object.get("r").toString()) >= 4 && Integer.parseInt(object.get("r").toString()) <= 9) { | 
|---|
|  |  |  | if (Integer.parseInt(object.get("c").toString()) == 2 || Integer.parseInt(object.get("c").toString()) == 6) { | 
|---|
|  |  |  | //填充第二列数据 | 
|---|
|  |  |  | if (sheet.getRow((int) object.get("r")) !=null && sheet.getRow((int) object.get("r")).getCell((int) object.get("c")) != null){ | 
|---|
|  |  |  | if (sheet.getRow((int) object.get("r")) != null && sheet.getRow((int) object.get("r")).getCell((int) object.get("c")) != null) { | 
|---|
|  |  |  | if (!value.equals("")) { | 
|---|
|  |  |  | sheet.getRow((int) object.get("r")).getCell((int) object.get("c")).setCellValue(value); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | System.out.println("错误的=" + index + ">>>" + str_); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | case 4: | 
|---|
|  |  |  | case 5: | 
|---|
|  |  |  | if (sheet.getRow((int) object.get("r")) !=null && sheet.getRow((int) object.get("r")).getCell((int) object.get("c")) != null){ | 
|---|
|  |  |  | if (sheet.getRow((int) object.get("r")) != null && sheet.getRow((int) object.get("r")).getCell((int) object.get("c")) != null) { | 
|---|
|  |  |  | if (!value.equals("")) { | 
|---|
|  |  |  | sheet.getRow((int) object.get("r")).getCell((int) object.get("c")).setCellValue(value); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | System.out.println("错误的=" + index + ">>>" + str_); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping(value = "/priQuote/approval/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R approvalPriQuote(@RequestParam Long planId, | 
|---|
|  |  |  | @RequestParam(required = false) Long plannerId){ | 
|---|
|  |  |  | PriQuote priQuote = priQuoteService.selectById(planId); | 
|---|
|  |  |  | assert priQuote != null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | switch (priQuote.getSettle()) { | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | // 本部门经理审核 | 
|---|
|  |  |  | User user = userService.selectById(priQuote.getUserId()); | 
|---|
|  |  |  | User manager = new User(); | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | manager = userService.getDeptManager(getHostId(), user.getDeptId());        // 获取部门领导 | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | manager = user; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (manager.getId().equals(getUserId())) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改 settle 步骤数据 | 
|---|
|  |  |  | List<SettleDto> list = JSON.parseArray(priQuote.getSettleMsg(), SettleDto.class); | 
|---|
|  |  |  | for (SettleDto dto : list) { | 
|---|
|  |  |  | switch (dto.getStep()) { | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | dto.setCurr(Boolean.FALSE); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | dto.setCurr(Boolean.TRUE); | 
|---|
|  |  |  | if (Cools.isEmpty(dto.getMsg())){ | 
|---|
|  |  |  | dto.setMsg("部门经理" + manager.getNickname() + "审批通过"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | dto.setMsg(dto.getMsg()+PZH+DateUtils.convert(new Date())+" "+"部门经理" + manager.getNickname() + "审批通过"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | dto.setTime(DateUtils.convert(new Date())); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | priQuote.setSettleMsg(JSON.toJSONString(list)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改规划单状态 | 
|---|
|  |  |  | ProcessPermissions processPermissions = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 2).eq("process", "3-1"));//2:报价流程 | 
|---|
|  |  |  | User planLeader = userService.selectById(processPermissions.getUserId());       // 获取报价流程节点3确认人 | 
|---|
|  |  |  | priQuote.setSettle(2);  // 总裁办待审 | 
|---|
|  |  |  | priQuote.setMemberId(planLeader.getId()); | 
|---|
|  |  |  | priQuote.setUpdateUserId(getUserId()); | 
|---|
|  |  |  | priQuote.setUpdateTime(new Date()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!priQuoteService.updateById(priQuote)) { | 
|---|
|  |  |  | throw new CoolException("审核失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return R.error("抱歉,您没有审核的权限"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | ProcessPermissions processPermissions = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 2).eq("process", "3-1"));//2:报价流程 | 
|---|
|  |  |  | User planLeader = userService.selectById(processPermissions.getUserId());       // 获取报价流程节点3确认人 | 
|---|
|  |  |  | if (Cools.isEmpty(planLeader)) { | 
|---|
|  |  |  | throw new CoolException("未查找到报价流程节点3-1确认人,请联系在审批权限添加确认人!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!getUserId().equals(planLeader.getId())) { | 
|---|
|  |  |  | return R.error("抱歉,您没有审核的权限"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | User planner = userService.selectById(plannerId); | 
|---|
|  |  |  | // 修改 settle 步骤数据 | 
|---|
|  |  |  | List<SettleDto> list = JSON.parseArray(priQuote.getSettleMsg(), SettleDto.class); | 
|---|
|  |  |  | for (SettleDto dto : list) { | 
|---|
|  |  |  | switch (dto.getStep()) { | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | dto.setCurr(Boolean.FALSE); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | dto.setCurr(Boolean.TRUE); | 
|---|
|  |  |  | if (Cools.isEmpty(dto.getMsg())){ | 
|---|
|  |  |  | dto.setMsg("总裁办" + planLeader.getNickname() + "审批通过"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | dto.setMsg(dto.getMsg()+PZH+DateUtils.convert(new Date())+" "+"总经办" + planLeader.getNickname() + "审批通过"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | dto.setTime(DateUtils.convert(new Date())); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | priQuote.setSettleMsg(JSON.toJSONString(list)); | 
|---|
|  |  |  | // 修改规划单状态 | 
|---|
|  |  |  | priQuote.setSettle(3);  // 规划员待审 | 
|---|
|  |  |  | priQuote.setUpdateUserId(getUserId()); | 
|---|
|  |  |  | priQuote.setMemberId(priQuote.getUserId()); | 
|---|
|  |  |  | priQuote.setUpdateTime(new Date()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!priQuoteService.updateById(priQuote)) { | 
|---|
|  |  |  | throw new CoolException("审核失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | // 业务员 | 
|---|
|  |  |  | User salesman0 = userService.selectById(priQuote.getUserId()); | 
|---|
|  |  |  | if (!getUserId().equals(salesman0.getId())) { | 
|---|
|  |  |  | return R.error("抱歉,您没有审核的权限"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改 settle 步骤数据 | 
|---|
|  |  |  | List<SettleDto> list1 = JSON.parseArray(priQuote.getSettleMsg(), SettleDto.class); | 
|---|
|  |  |  | for (SettleDto dto : list1) { | 
|---|
|  |  |  | switch (dto.getStep()) { | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | dto.setCurr(Boolean.TRUE); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 4: | 
|---|
|  |  |  | dto.setCurr(Boolean.TRUE); | 
|---|
|  |  |  | if (Cools.isEmpty(dto.getMsg())){ | 
|---|
|  |  |  | dto.setMsg("业务员" + salesman0.getNickname() + "审批通过"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | dto.setMsg(dto.getMsg()+PZH+DateUtils.convert(new Date())+" "+"业务员" + salesman0.getNickname() + "审批通过"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | dto.setTime(DateUtils.convert(new Date())); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | priQuote.setSettleMsg(JSON.toJSONString(list1)); | 
|---|
|  |  |  | // 修改规划单状态 | 
|---|
|  |  |  | priQuote.setSettle(4);  // 审批通过 | 
|---|
|  |  |  | priQuote.setUpdateUserId(getUserId()); | 
|---|
|  |  |  | priQuote.setUpdateTime(new Date()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!priQuoteService.updateById(priQuote)) { | 
|---|
|  |  |  | throw new CoolException("审核失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("审批成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping(value = "/priQuote/refuse/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R refusePriQuote(@RequestParam Long planId, | 
|---|
|  |  |  | @RequestParam(required = false) Long plannerId){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PriQuote priQuote = priQuoteService.selectById(planId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | Long memberId = priQuote.getMemberId(); | 
|---|
|  |  |  | User member = userService.selectById(memberId); | 
|---|
|  |  |  | if (!member.getId().equals(getUserId())){ | 
|---|
|  |  |  | return R.error("抱歉,您没有审核的权限"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<SettleDto> planDtos = JSON.parseArray(priQuote.getSettleMsg(), SettleDto.class); | 
|---|
|  |  |  | List<SettleDto> planDtoList = new ArrayList<>(); | 
|---|
|  |  |  | boolean sign = true; | 
|---|
|  |  |  | for (SettleDto dto : planDtos) { | 
|---|
|  |  |  | if (dto.getStep().equals(2)){ | 
|---|
|  |  |  | priQuote.setMemberId(dto.getUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (sign && dto.getUserId().equals(memberId) && priQuote.getSettle()+1==dto.getStep()){ | 
|---|
|  |  |  | if (Cools.isEmpty(dto.getMsg())){ | 
|---|
|  |  |  | dto.setMsg(DateUtils.convert(now)+" "+member.getNickname()+"回退审批"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | dto.setMsg(dto.getMsg()+PZH+DateUtils.convert(now)+" "+member.getNickname()+"回退审批"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | sign = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (sign){ | 
|---|
|  |  |  | dto.setMsg(dto.getMsg()+PZH+DateUtils.convert(now)+" "+member.getNickname()+"回退审批"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | planDtoList.add(dto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | priQuote.setSettle(1); | 
|---|
|  |  |  | priQuote.setUpdateUserId(getUserId()); | 
|---|
|  |  |  | priQuote.setUpdateTime(now); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | priQuote.setSettleMsg(JSON.toJSONString(planDtoList)); | 
|---|
|  |  |  | priQuoteService.updateById(priQuote); | 
|---|
|  |  |  | return R.ok("回退成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|