| | |
| | | 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.PriQuote; |
| | | import com.zy.crm.manager.entity.PriQuoteBudget; |
| | | import com.zy.crm.manager.service.ItemService; |
| | | 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 PriQuoteService priQuoteService; |
| | | |
| | | @Autowired |
| | | private ItemService itemService; |
| | | private PlanService planService; |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @Autowired |
| | | private PriQuoteBudgetService priQuoteBudgetService; |
| | | |
| | | @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") |
| | |
| | | } |
| | | |
| | | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ |
| | | Long deptId = getDeptId(); |
| | | boolean signUserId = false; |
| | | boolean signDeptId = false; |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | | if (entry.getKey().equals("dept_id")){ |
| | | signDeptId = true; |
| | | } |
| | | } |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | | String val = String.valueOf(entry.getValue()); |
| | | if (val.contains(RANGE_TIME_LINK)){ |
| | | String[] dates = val.split(RANGE_TIME_LINK); |
| | | wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); |
| | | wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); |
| | | } else if (entry.getKey().equals("dept_id")){ |
| | | if (!val.equals("19")){ |
| | | wrapper.eq(entry.getKey(), val); |
| | | } |
| | | } else if (entry.getKey().equals("user_id") && !signDeptId){ |
| | | signUserId = true; |
| | | wrapper.eq(entry.getKey(), val); |
| | | } else { |
| | | wrapper.like(entry.getKey(), val); |
| | | } |
| | | } |
| | | if (!signUserId && !signDeptId){ |
| | | wrapper.eq("user_id", getUserId()); |
| | | } |
| | | } |
| | | |
| | |
| | | priQuote.setUpdateTime(new Date()); |
| | | |
| | | //业务员 |
| | | Item item = itemService.selectById(priQuote.getItemId()); |
| | | priQuote.setMemberId(item.getMember()); |
| | | Plan plan = planService.selectById(priQuote.getItemId()); |
| | | priQuote.setMemberId(plan.getUserId()); |
| | | |
| | | //设置项目流程 |
| | | item.setStep(5); |
| | | itemService.updateById(item); |
| | | plan.setStep(5); |
| | | |
| | | priQuote.setForm(JSON.toJSONString(map)); // 自定义表单内容 |
| | | priQuote.setSettle(1); // 1.开始 |
| | | User manager = userService.getDeptManager(getHostId(), getUser().getDeptId()); // 获取部门领导 |
| | | priQuote.setSettleMsg(JSON.toJSONString(SettleDto.initPriQuote(plan, manager))); |
| | | |
| | | planService.updateById(plan); |
| | | |
| | | priQuoteService.insert(priQuote); |
| | | return R.ok(); |
| | |
| | | priQuote.setUpdateTime(new Date()); |
| | | |
| | | //业务员 |
| | | Item item = itemService.selectById(priQuote.getItemId()); |
| | | priQuote.setMemberId(item.getMember()); |
| | | Plan plan = planService.selectById(priQuote.getItemId()); |
| | | priQuote.setMemberId(plan.getUserId()); |
| | | |
| | | priQuoteService.insert(priQuote); |
| | | return R.ok(); |
| | |
| | | } |
| | | } |
| | | |
| | | @PostMapping(value = "/priQuote/approval/auth") |
| | | @ManagerAuth |
| | | public R approvalPriQuote(@RequestParam Long planId, |
| | | @RequestParam(required = false) Long plannerId){return null;} |
| | | // 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())) { |
| | | // |
| | | // |
| | | // // 查找总裁办 |
| | | // PlanType planType = planTypeService.selectById(priQuote.getPlanType()); |
| | | // User planLeader = planTypeService.findPlanLeader(planType); |
| | | // if (Cools.isEmpty(planLeader)) { |
| | | // throw new CoolException("未查找到总裁办,请联系管理员"); |
| | | // } |
| | | // |
| | | // // 修改 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; |
| | | // case 3: |
| | | // dto.setUserId(planLeader.getId()); |
| | | // dto.setUsername(planLeader.getNickname()); |
| | | // 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("审核失败,请联系管理员"); |
| | | // } |
| | | // |
| | | // // 添加规划组长跟进人 |
| | | // PlanFoll planFoll = new PlanFoll(); |
| | | // planFoll.setPlanId(priQuote.getId()); |
| | | // planFoll.setUserId(planLeader.getId()); |
| | | // if (!planFollService.insert(planFoll)) { |
| | | // throw new CoolException("审核失败,请联系管理员"); |
| | | // } |
| | | // |
| | | // } else { |
| | | // return R.error("抱歉,您没有审核的权限"); |
| | | // } |
| | | // break; |
| | | // case 2: |
| | | // // 查找规划组长 |
| | | // PlanType planType = planTypeService.selectById(priQuote.getPlanType()); |
| | | // User planLeader = planTypeService.findPlanLeader(planType); |
| | | // if (Cools.isEmpty(planLeader)) { |
| | | // throw new CoolException("未查找到规划组长,请联系管理员"); |
| | | // } |
| | | // if (Cools.isEmpty(planLeader)) { |
| | | // throw new CoolException("未查找到规划组长,请联系管理员"); |
| | | // } |
| | | // if (!getUserId().equals(planLeader.getId())) { |
| | | // return R.error("抱歉,您没有审核的权限"); |
| | | // } |
| | | // if (Cools.isEmpty(plannerId)) { |
| | | // 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; |
| | | // case 4: |
| | | // dto.setUserId(planner.getId()); |
| | | // dto.setUsername(planner.getNickname()); |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // } |
| | | // } |
| | | // priQuote.setSettleMsg(JSON.toJSONString(list)); |
| | | // // 修改规划单状态 |
| | | // priQuote.setSettle(3); // 规划员待审 |
| | | // priQuote.setPlanner(planner.getId()); |
| | | // priQuote.setUpdateUserId(getUserId()); |
| | | // priQuote.setUpdateTime(new Date()); |
| | | // |
| | | // if (!priQuoteService.updateById(priQuote)) { |
| | | // throw new CoolException("审核失败,请联系管理员"); |
| | | // } |
| | | // |
| | | // // 添加规划员跟进人 |
| | | // PlanFoll planFoll = new PlanFoll(); |
| | | // planFoll.setPlanId(priQuote.getId()); |
| | | // planFoll.setUserId(planner.getId()); |
| | | // if (!planFollService.insert(planFoll)) { |
| | | // throw new CoolException("审核失败,请联系管理员"); |
| | | // } |
| | | // break; |
| | | // case 3: |
| | | // User plannerUser = userService.selectById(priQuote.getPlanner()); |
| | | // if (Cools.isEmpty(plannerUser)) { |
| | | // return R.error("未找到规划员"); |
| | | // } |
| | | // if (!getUserId().equals(plannerUser.getId())) { |
| | | // return R.error("抱歉,您没有审核的权限"); |
| | | // } |
| | | // // 业务员 |
| | | // User salesman = userService.selectById(priQuote.getUserId()); |
| | | // // 修改 settle 步骤数据 |
| | | // List<SettleDto> list0 = JSON.parseArray(priQuote.getSettleMsg(), SettleDto.class); |
| | | // for (SettleDto dto : list0) { |
| | | // switch (dto.getStep()) { |
| | | // case 3: |
| | | // dto.setCurr(Boolean.FALSE); |
| | | // break; |
| | | // case 4: |
| | | // dto.setCurr(Boolean.TRUE); |
| | | // dto.setMsg("规划员" + plannerUser.getNickname() + "审批通过"); |
| | | // dto.setTime(DateUtils.convert(new Date())); |
| | | // break; |
| | | // case 5: |
| | | // dto.setUserId(salesman.getId()); |
| | | // dto.setUsername(salesman.getNickname()); |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // } |
| | | // } |
| | | // priQuote.setSettleMsg(JSON.toJSONString(list0)); |
| | | // // 修改规划单状态 |
| | | // priQuote.setSettle(4); // 审批通过 |
| | | // priQuote.setUpdateUserId(getUserId()); |
| | | // priQuote.setUpdateTime(new Date()); |
| | | // |
| | | // if (!planService.updateById(priQuote)) { |
| | | // throw new CoolException("审核失败,请联系管理员"); |
| | | // } |
| | | // break; |
| | | // case 4: |
| | | // // 业务员 |
| | | // 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 4: |
| | | // dto.setCurr(Boolean.TRUE); |
| | | // break; |
| | | // case 5: |
| | | // dto.setCurr(Boolean.TRUE); |
| | | // dto.setMsg("业务员" + salesman0.getNickname() + "审批通过"); |
| | | // dto.setTime(DateUtils.convert(new Date())); |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // } |
| | | // } |
| | | // priQuote.setSettleMsg(JSON.toJSONString(list1)); |
| | | // // 修改规划单状态 |
| | | // priQuote.setSettle(5); // 审批通过 |
| | | // priQuote.setUpdateUserId(getUserId()); |
| | | // priQuote.setUpdateTime(new Date()); |
| | | // |
| | | // if (!planService.updateById(priQuote)) { |
| | | // throw new CoolException("审核失败,请联系管理员"); |
| | | // } |
| | | // break; |
| | | // default: |
| | | // return R.error(); |
| | | // } |
| | | // return R.ok("审批成功"); |
| | | // } |
| | | |
| | | } |