中扬CRM客户关系管理系统
#
lsh
2024-04-19 f614347a41aa29d5050e3da3a921cdc204c23dde
src/main/java/com/zy/crm/manager/controller/WeeklyController.java
@@ -85,16 +85,76 @@
        return R.ok(weeklyService.selectPage(new Page<>(curr, limit), wrapper));
    }
//    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
//        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 {
//                wrapper.like(entry.getKey(), val);
//            }
//        }
//    }
    @RequestMapping(value = "/weekly/list/auth2")
    @ManagerAuth
    public R list2(@RequestParam(defaultValue = "1")Integer curr,
                  @RequestParam(defaultValue = "10")Integer limit,
                  @RequestParam(required = false)String orderByField,
                  @RequestParam(required = false)String orderByType,
                  @RequestParam(required = false)String condition,
                  @RequestParam Map<String, Object> param) {
        EntityWrapper<Weekly> wrapper = new EntityWrapper<>();
        excludeTrash(param);
        convert(param, wrapper);
        allLike(Weekly.class, param.keySet(), wrapper, condition);
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        return R.ok(weeklyService.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()){
            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){
            if (getRole().getId()==1){
                wrapper.or().eq("host_id",getHostId());
            }else if (getRole().getId()==2){
                wrapper.eq("dept_id",getDeptId());
            }else {
                wrapper.eq("user_id", getUserId());
            }
        }
        if (signHostId){
            wrapper.or().eq("host_id",getHostId());
        }
    }
@@ -308,6 +368,11 @@
                try{
                    weeklyDailyPlanService.insert(weeklyDailyPlan);
                    WeeklyDailyReality weeklyDailyReality = new WeeklyDailyReality();
                    weeklyDailyReality.sync(weeklyDailyPlan);
                    weeklyDailyReality.setWorkContent("");
                    weeklyDailyRealityService.insert(weeklyDailyReality);
                } catch (Exception e){
                    log.error("新增日计划失败"+e);
                    throw new CoolException("新增日计划失败");
@@ -322,7 +387,8 @@
        } catch (Exception e){
            log.error("创建周计划异常,异常信息:"+e);
            throw new CoolException("创建周计划失败==>"+e);
            return R.error("创建周计划失败==>"+e);
//            throw new CoolException("创建周计划失败==>"+e);
        }
        return R.ok("创建成功");
@@ -443,7 +509,8 @@
                weeklyService.insert(weekly);
            } catch (Exception e) {
                log.error("新增周计划主表失败,异常信息:"+e);
                throw new CoolException("新增周计划主表失败");
                return R.error("新增周计划主表失败");
//                throw new CoolException("新增周计划主表失败");
            }
            List<CstmrUtilsParam> cstmrUtilsParamList = new ArrayList<>();
@@ -469,7 +536,8 @@
                    weeklyDailyRealityService.insert(weeklyDailyReality);
                } catch (Exception e){
                    log.error("新增日计划失败"+e);
                    throw new CoolException("新增日计划失败");
//                    throw new CoolException("新增日计划失败");
                    return R.error("新增日计划失败");
                }
            }
@@ -481,7 +549,8 @@
        } catch (Exception e){
            log.error("创建周计划异常,异常信息:"+e);
            throw new CoolException("创建周计划失败==>"+e);
//            throw new CoolException("创建周计划失败==>"+e);
            return R.error("创建周计划失败==>"+e);
        }
        return R.ok("创建成功");
@@ -501,9 +570,10 @@
                throw new CoolException("参数为空:WeeklyId");
            } else if (Cools.isEmpty(param.getType())){
                throw new CoolException("参数为空:Type");
            } else if (Cools.isEmpty(param.getWeeklyType())){
                throw new CoolException("参数为空:Weekly");
            }
//            if (Cools.isEmpty(param.getWeeklyType())){
//                throw new CoolException("参数为空:Weekly");
//            }
            Date now = new Date();
            Weekly weekly = weeklyService.selectById(param.getWeeklyId());
            weekly.setUpdateBy(getUserId());
@@ -524,28 +594,40 @@
                throw new CoolException("更新周计划主表失败");
            }
            List<CstmrUtilsParam> cstmrUtilsParamList = new ArrayList<>();
            List<WeeklyDailyPlan> weeklyDailyPlanList = weeklyDailyPlanService.selectList(new EntityWrapper<WeeklyDailyPlan>().eq("weekly_id", weekly.getId()));
            List<Long> ids = new ArrayList<>();
            for (WeeklyDailyPlan  weeklyDailyPlan: param.getWeeklyDailyPlanList()) {
                if (!Cools.isEmpty(weeklyDailyPlan.getId())) {
                    ids.add(weeklyDailyPlan.getId());
                }
            }
            try{
                for (WeeklyDailyPlan weeklyDailyPlan2:weeklyDailyPlanList){
                    if (!ids.contains(weeklyDailyPlan2.getId())){
                        weeklyDailyPlanService.deleteById(weeklyDailyPlan2.getId());
                    }
                }
            }catch (Exception e){
            }
            for (WeeklyDailyPlan  weeklyDailyPlan: param.getWeeklyDailyPlanList()){
                WeeklyDailyPlan weeklyDailyPlan1 = new WeeklyDailyPlan();
                if (!Cools.isEmpty(weeklyDailyPlan.getId())){
                    Long weeklyDailyPlanId = weeklyDailyPlan.getId();
                    weeklyDailyPlan1 = weeklyDailyPlanService.selectById(weeklyDailyPlan.getId());
                    if (Cools.isEmpty(weeklyDailyPlan)){
                    if (Cools.isEmpty(weeklyDailyPlan1)){
                        throw new CoolException("更新失败:id:"+weeklyDailyPlanId);
                    }
                    if (!Cools.isEmpty(weeklyDailyPlan1.getComment())){
//                        weeklyDailyPlan1.setComment(weeklyDailyPlan1.getComment()+";"+weeklyDailyPlan.getComment());
                        weeklyDailyPlan1.setComment(weeklyDailyPlan.getComment());
                    }else {
                        weeklyDailyPlan1.setComment(weeklyDailyPlan.getComment());
                    }
                    weeklyDailyPlan1.setComment(weeklyDailyPlan.getComment());
                    weeklyDailyPlan1.setWorkContent(weeklyDailyPlan.getWorkContent());
                    weeklyDailyPlan1.setWorkPurpose(weeklyDailyPlan.getWorkPurpose());
                    weeklyDailyPlan1.setWeeklyMatter(weeklyDailyPlan.getWeeklyMatter());
                    weeklyDailyPlan1.setAddr(weeklyDailyPlan.getAddr());
                    weeklyDailyPlan1.setMemo(weeklyDailyPlan.getMemo());
                    weeklyDailyPlan1.setUpdateBy(getUserId());
                    weeklyDailyPlan1.setUpdateTime(now);
                    if (!Cools.isEmpty(weeklyDailyPlan.getCstmrId())){
                        weeklyDailyPlan1.setCstmrId(weeklyDailyPlan1.getCstmrId());
                        weeklyDailyPlan1.setCstmrId(weeklyDailyPlan.getCstmrId());
                    }
                    weeklyDailyPlanService.updateById(weeklyDailyPlan1);
@@ -597,9 +679,10 @@
                throw new CoolException("参数为空:WeeklyId");
            } else if (Cools.isEmpty(param.getType())){
                throw new CoolException("参数为空:Type");
            } else if (Cools.isEmpty(param.getWeeklyType())){
                throw new CoolException("参数为空:Weekly");
            }
//            else if (Cools.isEmpty(param.getWeeklyType())){
//                throw new CoolException("参数为空:Weekly");
//            }
            Date now = new Date();
            Weekly weekly = weeklyService.selectById(param.getWeeklyId());
            weekly.setUpdateBy(getUserId());
@@ -620,23 +703,35 @@
                throw new CoolException("更新周计划主表失败");
            }
            List<CstmrUtilsParam> cstmrUtilsParamList = new ArrayList<>();
            List<WeeklyDailyReality> weeklyDailyRealitieList = weeklyDailyRealityService.selectList(new EntityWrapper<WeeklyDailyReality>().eq("weekly_id", weekly.getId()));
            List<Long> ids = new ArrayList<>();
            for (WeeklyDailyReality weeklyDailyReality: param.getWeeklyDailyRealityList()) {
                if (!Cools.isEmpty(weeklyDailyReality.getId())) {
                    ids.add(weeklyDailyReality.getId());
                }
            }
            try{
                for (WeeklyDailyReality weeklyDailyReality2:weeklyDailyRealitieList){
                    if (!ids.contains(weeklyDailyReality2.getId())){
                        weeklyDailyRealityService.deleteById(weeklyDailyReality2.getId());
                    }
                }
            }catch (Exception e){
            }
            for (WeeklyDailyReality  weeklyDailyReality: param.getWeeklyDailyRealityList()){
                WeeklyDailyReality weeklyDailyReality1 = new WeeklyDailyReality();
                if (!Cools.isEmpty(weeklyDailyReality.getId())){
                    Long weeklyDailyPlanId = weeklyDailyReality.getId();
                    Long weeklyDailyRealityId = weeklyDailyReality.getId();
                    weeklyDailyReality1 = weeklyDailyRealityService.selectById(weeklyDailyReality.getId());
                    if (Cools.isEmpty(weeklyDailyReality)){
                        throw new CoolException("更新失败:id:"+weeklyDailyPlanId);
                    if (Cools.isEmpty(weeklyDailyReality1)){
                        throw new CoolException("更新失败:id:"+weeklyDailyRealityId);
                    }
                    if (!Cools.isEmpty(weeklyDailyReality1.getComment())){
//                        weeklyDailyReality1.setComment(weeklyDailyReality1.getComment()+";"+weeklyDailyReality.getComment());
                        weeklyDailyReality1.setComment(weeklyDailyReality.getComment());
                    }else {
                        weeklyDailyReality1.setComment(weeklyDailyReality.getComment());
                    }
                    weeklyDailyReality1.setComment(weeklyDailyReality.getComment());
                    weeklyDailyReality1.setWorkContent(weeklyDailyReality.getWorkContent());
                    weeklyDailyReality1.setWorkPurpose(weeklyDailyReality.getWorkPurpose());
                    weeklyDailyReality1.setWeeklyMatter(weeklyDailyReality.getWeeklyMatter());
                    weeklyDailyReality1.setAddr(weeklyDailyReality.getAddr());
                    weeklyDailyReality1.setMemo(weeklyDailyReality.getMemo());
                    weeklyDailyReality1.setUpdateBy(getUserId());
                    weeklyDailyReality1.setUpdateTime(now);
@@ -812,8 +907,8 @@
                throw new CoolException("参数为空:WeeklyId");
//            } else if (Cools.isEmpty(param.getType())){
//                throw new CoolException("参数为空:Type");
            } else if (Cools.isEmpty(param.getWeeklyType())){
                throw new CoolException("参数为空:Weekly");
//            } else if (Cools.isEmpty(param.getWeeklyType())){
//                throw new CoolException("参数为空:Weekly");
            }
            Date now = new Date();
            Weekly weekly = weeklyService.selectById(param.getWeeklyId());