| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/plan/assistantPlan/add/auth") |
| | | @ManagerAuth(memo = "添加副规划申请单") |
| | | @Transactional |
| | | public R assistantPlanAdd(@RequestParam Long hostPlanId) { |
| | | Plan hostPlan = planService.selectById(hostPlanId); |
| | | if (!Cools.isEmpty(hostPlan.getAssistantPlanId()) && hostPlan.getAssistantPlanId()!=0){ |
| | | return R.error("此规划单已存在副规划单,id为"+hostPlan.getAssistantPlanId()); |
| | | } |
| | | // pre |
| | | Plan plan = new Plan(hostPlan); |
| | | // begin |
| | | Long hostId = getHostId(); |
| | | if (planService.selectByUuid(hostId, plan.getUuid()) != null) { |
| | | throw new CoolException("规划单已存在"); |
| | | } |
| | | |
| | | Order order = orderService.selectById(plan.getOrderId()); |
| | | if (Cools.isEmpty(order)) { |
| | | throw new CoolException("跟踪项目不存在"); |
| | | } |
| | | |
| | | if (!order.getDirector().equals(getUserId())){ |
| | | throw new CoolException("只允许跟踪项目负责人添加所选项目规划申请单"); |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | plan.setHostId(hostId); |
| | | plan.setUuid(planService.getUuid(hostId)); // 规划单代号 |
| | | plan.setDeptId(getDeptId()); // 所属部门 |
| | | plan.setUserId(getUserId()); // 所属人员 |
| | | |
| | | plan.setAppleTime(now); |
| | | plan.setCreateBy(getUserId()); |
| | | plan.setCreateTime(now); |
| | | plan.setUpdateBy(getUserId()); |
| | | plan.setUpdateTime(now); |
| | | plan.setStatus(0); |
| | | plan.setStatus2(0); |
| | | plan.setStep(1); |
| | | plan.setSettle(1); // 1.开始 |
| | | plan.setAssistantHostSign(1);//副规划单 |
| | | |
| | | User manager = new User(); |
| | | try{ |
| | | manager = userService.getDeptManager(getHostId(), getUser().getDeptId()); // 获取部门领导 |
| | | }catch (Exception e){ |
| | | manager = getUser(); |
| | | } |
| | | PlanType planType = new PlanType(hostPlan.getHostId(),1);//1:货架 |
| | | User planLeader = planTypeService.findPlanLeader(planType); |
| | | plan.setSettleMsg(JSON.toJSONString(SettleDto.init(plan, manager, planLeader))); |
| | | |
| | | plan.setDirector(planLeader.getId()); |
| | | |
| | | if (!planService.insert(plan)) { |
| | | throw new CoolException("保存失败,请重试"); |
| | | } |
| | | plan.setAssistantPlanId(plan.getId()); |
| | | plan.setHostPlanId(hostPlanId); |
| | | if (!planService.updateById(plan)) { |
| | | throw new CoolException("更新失败,请重试"); |
| | | } |
| | | // 自动添加跟进人 |
| | | PlanFoll planFoll = new PlanFoll(); |
| | | planFoll.setPlanId(plan.getId()); |
| | | planFoll.setUserId(planLeader.getId()); |
| | | if (!planFollService.insert(planFoll)) { |
| | | throw new CoolException("保存失败,请重试"); |
| | | } |
| | | |
| | | hostPlan.setAssistantPlanId(plan.getId()); |
| | | hostPlan.setHostPlanId(hostPlanId); |
| | | if (!planService.updateById(hostPlan)) { |
| | | throw new CoolException("更新失败,请重试"); |
| | | } |
| | | return R.ok("保存成功"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/plan/update/auth") |
| | | @ManagerAuth(memo = "更新规划申请单") |
| | | @Transactional |
| | |
| | | if (priOnline2!=0){ |
| | | return R.error("存在关联的核价单,禁止删除!!!"); |
| | | } |
| | | Plan planA = planService.selectById(id); |
| | | if (planA.getAssistantHostSign()==1){ |
| | | Plan planB = planService.selectById(planA.getHostPlanId()); |
| | | planB.setAssistantPlanId(0L); |
| | | planB.setHostPlanId(0L); |
| | | planService.updateById(planB); |
| | | }else { |
| | | if (!Cools.isEmpty(planA.getAssistantPlanId()) && planA.getAssistantPlanId()!=0){ |
| | | Plan planB = planService.selectById(planA.getAssistantPlanId()); |
| | | if (!Cools.isEmpty(planB)){ |
| | | return R.error("存在关联的副规划单,禁止删除!!! 副规划单ID:"+planB.getId()); |
| | | } |
| | | } |
| | | } |
| | | planService.deleteById(id); |
| | | } |
| | | return R.ok(); |