| | |
| | | package com.zy.crm.manager.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | |
| | | 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.Item; |
| | | import com.zy.crm.manager.entity.Plan; |
| | | import com.zy.crm.manager.entity.PriQuote; |
| | | import com.zy.crm.manager.entity.PriQuoteBudget; |
| | | 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.entity.*; |
| | | 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; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private PlanService planService; |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @Autowired |
| | | private PriQuoteBudgetService priQuoteBudgetService; |
| | | |
| | | @Autowired |
| | | private ProcessPermissionsService processPermissionsService; |
| | | |
| | | @Autowired |
| | | private PlanTypeService planTypeService; |
| | | |
| | | @RequestMapping(value = "/priQuote/{id}/auth") |
| | | @ManagerAuth |
| | | public R get(@PathVariable("id") String id) { |
| | | return R.ok(priQuoteService.selectById(String.valueOf(id))); |
| | | PriQuote priQuote = priQuoteService.selectById(String.valueOf(id)); |
| | | assert priQuote != null; |
| | | JSONObject resultObj = JSON.parseObject(JSON.toJSONString(priQuote)); |
| | | if (!Cools.isEmpty(priQuote.getForm())) { |
| | | JSONObject formObj = JSON.parseObject(priQuote.getForm()); |
| | | formObj.forEach(resultObj::putIfAbsent); |
| | | } |
| | | |
| | | // 步骤条相关 |
| | | resultObj.put("step", priQuote.getSettle() == 5 ? 0 : priQuote.getSettle() + 1); |
| | | |
| | | return R.ok().add(resultObj); |
| | | // return R.ok(priQuoteService.selectById(String.valueOf(id))); |
| | | } |
| | | |
| | | @RequestMapping(value = "/priQuote/list/auth") |
| | |
| | | @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.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"); |
| | | wrapper.in("member_id", getUserRoleBelongsToUserId()); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | |
| | | } |
| | | |
| | | @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())); |
| | | |
| | |
| | | priQuote.setUserId(getUserId()); |
| | | //更新人员 |
| | | priQuote.setUpdateUserId(getUserId()); |
| | | //所属部门 |
| | | priQuote.setDeptId(getDeptId()); |
| | | //更新时间 |
| | | priQuote.setUpdateTime(new Date()); |
| | | |
| | |
| | | |
| | | //设置项目流程 |
| | | plan.setStep(5); |
| | | |
| | | priQuote.setForm(JSON.toJSONString(map)); // 自定义表单内容 |
| | | priQuote.setSettle(1); // 1.开始 |
| | | User manager = userService.getDeptManager(getHostId(), getUser().getDeptId()); // 获取部门领导 |
| | | 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); |
| | | |
| | | priQuoteService.insert(priQuote); |
| | |
| | | } |
| | | |
| | | @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(); |
| | |
| | | } |
| | | } |
| | | |
| | | @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 = userService.getDeptManager(getHostId(), user.getDeptId()); |
| | | 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); |
| | | dto.setMsg("部门经理" + manager.getNickname() + "审批通过"); |
| | | dto.setTime(DateUtils.convert(new Date())); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | priQuote.setSettleMsg(JSON.toJSONString(list)); |
| | | |
| | | // 修改规划单状态 |
| | | priQuote.setSettle(2); // 总裁办待审 |
| | | 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); |
| | | dto.setMsg("总裁办" + planLeader.getNickname() + "审批通过"); |
| | | dto.setTime(DateUtils.convert(new Date())); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | priQuote.setSettleMsg(JSON.toJSONString(list)); |
| | | // 修改规划单状态 |
| | | priQuote.setSettle(3); // 规划员待审 |
| | | priQuote.setUpdateUserId(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); |
| | | dto.setMsg("业务员" + 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); |
| | | // assert priQuote != null; |
| | | // |
| | | // switch (priQuote.getSettle()) { |
| | | // case 1: |
| | | // // 本部门经理审核 |
| | | // User user = userService.selectById(priQuote.getUserId()); |
| | | // User manager = userService.getDeptManager(getHostId(), user.getDeptId()); |
| | | // 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); |
| | | // dto.setMsg("部门经理" + manager.getNickname() + "审批通过"); |
| | | // dto.setTime(DateUtils.convert(new Date())); |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // } |
| | | // } |
| | | // priQuote.setSettleMsg(JSON.toJSONString(list)); |
| | | // |
| | | // // 修改规划单状态 |
| | | // priQuote.setSettle(2); // 总裁办待审 |
| | | // 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); |
| | | // dto.setMsg("总裁办" + planLeader.getNickname() + "审批通过"); |
| | | // dto.setTime(DateUtils.convert(new Date())); |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // } |
| | | // } |
| | | // priQuote.setSettleMsg(JSON.toJSONString(list)); |
| | | // // 修改规划单状态 |
| | | // priQuote.setSettle(3); // 规划员待审 |
| | | // priQuote.setUpdateUserId(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); |
| | | // dto.setMsg("业务员" + 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("审批成功"); |
| | | } |
| | | |
| | | } |