中扬CRM客户关系管理系统
LSH
2023-11-09 e85439da9f2fb1be90509a72e637613a5c0bbc11
src/main/java/com/zy/crm/manager/controller/PlanController.java
@@ -59,6 +59,7 @@
    private ProcessPermissionsService processPermissionsService;
    String PZH=" ————————————————— ";
    Integer PBN = 6;
    @GetMapping(value = "/plan/{id}/auth")
@@ -89,10 +90,22 @@
                  @RequestParam(required = false) String condition,
                  @RequestParam(required = false, value = "dept_id") Long deptId,
                  @RequestParam(required = false, value = "user_id") Long userId) {
        Long director = null;
        if (deptId==null && userId == null){
            if (getRole().getId()==3){
                userId = getUserId();
            }else if (getRole().getId()==2){
                deptId = getDeptId();
                userId = null;
            }
            director = getUserId();
        }
        return R.ok(planService.getPage(new Page<>(curr, limit)
                , getHostId()
                , deptId == null ? (userId == null? getDeptId().toString(): null) : String.valueOf(deptId)
                , deptId == null ? null : String.valueOf(deptId)
                , userId
                , director
                , condition)
        );
    }
@@ -176,6 +189,84 @@
        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
@@ -237,6 +328,20 @@
             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();
@@ -244,31 +349,23 @@
    @RequestMapping(value = "/plan/insert/file/auth")
//    @ManagerAuth
    public R insertFile(@RequestParam("planId") String planId,@RequestParam MultipartFile file){
        try{
            InputStream inputStream = file.getInputStream();
            // 获取文件的内容类型
            String contentType = file.getContentType();
            String suffix = getFileSuffix(file.getOriginalFilename());
            String url = ossService.upload(inputStream, suffix,contentType);
//            String url = "http://tjdt.oss-cn-hangzhou.aliyuncs.com/"+file.getOriginalFilename();
            String[] names = url.split("com/");
            String name= names[1];
    public R insertFile(@RequestParam("planId") String planId, @RequestParam("filename") String filename, @RequestParam("filesize") Long filesize) {
        try {
//            InputStream inputStream = file.getInputStream();
//            // 获取文件的内容类型
//            String contentType = file.getContentType();
//            String url = ossService.upload(inputStream, file.getOriginalFilename(), contentType);
////            String url = "http://tjdt.oss-cn-hangzhou.aliyuncs.com/"+file.getOriginalFilename();
//            String[] names = url.split("com/");
//            String name= names[1];
            String[] split = planId.split("-");
            int id = Integer.parseInt(split[1]);
            planService.increasePlanUrl(id,url,name,file.getSize());
            /*String[] split = planId.split("-");
            int id = Integer.parseInt(split[1]);
            System.out.println("---开始---");
            String savePath = "D:/crm/plan/file/"+id+"/"; // 指定保存文件的路径
            try{
                FileSaveExampleUtil.saveFile(file, savePath);
            }catch (Exception e){
                return R.error();
            }*/
            String url = "http://zhongyang-ftpserver.oss-cn-hangzhou.aliyuncs.com/" + filename;
            planService.increasePlanUrl(id, url, filename, filesize);
            return R.ok();
        }catch (Exception e){
        } catch (Exception e) {
            System.out.println(e);
            return R.error();
        }
@@ -301,11 +398,14 @@
    @RequestMapping(value = "/plan/view/file/auth")
//    @ManagerAuth
    public R viewFile(@RequestParam("planId") String planId){
        List<FileSaveExampleUtil.FileDTO> fileDTOS = new ArrayList<>();
        if (Cools.isEmpty(planId)){
            return R.ok(fileDTOS);
        }
        int id = Integer.parseInt(planId);
//        String savePath = "D:/crm/plan/file/"+id+"/"; // 指定保存文件的路径
        try{
            List<Integer> ids = planService.selectPlanUrlId(id);
            List<FileSaveExampleUtil.FileDTO> fileDTOS = new ArrayList<>();
            for (int id2 : ids){
                String url = planService.selectPlanUrlPlanIdUrl(id2);
                String name = planService.selectPlanUrlPlanIdName(id2);
@@ -628,6 +728,11 @@
        List<User> users = userService.selectList(new EntityWrapper<User>().eq("dept_id", planLeader.getDeptId()));
        List<KeyValueVo> vos = new ArrayList<>();
        users.forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getNickname()), item.getId())));
        if (planType.getType().equals(2)){
            ProcessPermissions processPermissions= processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 101).eq("process", "1-1"));//2:核价流程
            User manager = userService.selectById(processPermissions.getUserId());       // 获取核价流程节点1确认人
            vos.add(new KeyValueVo(String.valueOf(manager.getNickname()), manager.getId()));
        }
        return R.ok().add(vos);
    }
@@ -679,25 +784,23 @@
        wrapper.like("name", condition);
        wrapper.eq("status",1);
        ProcessPermissions processPermissions1 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 5).eq("process", "1-1"));//2:核价流程
        User manager1 = userService.selectById(processPermissions1.getUserId());       // 获取核价流程节点1确认人
        ProcessPermissions processPermissions2 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 5).eq("process", "1-2"));//2:核价流程
        User manager2 = userService.selectById(processPermissions2.getUserId());       // 获取核价流程节点1确认人
        List<ProcessPermissions> processPermissionsList = processPermissionsService.selectList(new EntityWrapper<ProcessPermissions>().eq("process_memo", 4).or().eq("process_memo", 5));//2:核价流程
        int type =0;
        if (getUserId().equals(manager1.getId())){
            type=1;//(货架)
        }else if (getUserId().equals(manager2.getId())){
            type = 2;//(集成)
        }else {
        for (ProcessPermissions processPermissions:processPermissionsList){
            if (getUserId().equals(processPermissions.getUserId())){
                type=PBN-processPermissions.getProcessMemo();
                break;
            }
        }
        if (type==0){
            return R.error("你不是核价员,无权接任务");
        }
            List<Long> typeList = new ArrayList<>();
        List<Long> typeList = new ArrayList<>();
        List<PlanType> planTypes = planTypeService.selectList(new EntityWrapper<PlanType>().eq("type", type));
        if (Cools.isEmpty(planTypes) || planTypes.size()==0){
            return R.ok();
        }
        for (PlanType planType : planTypes){
            typeList.add(planType.getId());
        }