中扬CRM客户关系管理系统
LSH
2024-03-28 e3a94fff7f518b2c84296ec4427c985676354096
src/main/java/com/zy/crm/manager/controller/WeeklyController.java
@@ -1,12 +1,16 @@
package com.zy.crm.manager.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.crm.manager.entity.Weekly;
import com.zy.crm.manager.entity.WeeklyDailyPlan;
import com.zy.crm.manager.entity.param.CstmrUtilsParam;
import com.zy.crm.manager.entity.param.WeeklyDomainParam;
import com.zy.crm.manager.service.WeeklyDailyPlanService;
import com.zy.crm.manager.service.WeeklyService;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
@@ -14,16 +18,22 @@
import com.core.common.R;
import com.core.domain.KeyValueVo;
import com.zy.crm.common.web.BaseController;
import com.zy.crm.manager.utils.TimeCalculatorUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@Slf4j
@RestController
public class WeeklyController extends BaseController {
    @Autowired
    private WeeklyService weeklyService;
    @Autowired
    private WeeklyDailyPlanService weeklyDailyPlanService;
    @RequestMapping(value = "/weekly/{id}/auth")
    @ManagerAuth
@@ -132,4 +142,120 @@
        return R.ok().add(vos);
    }
    @RequestMapping(value = "/weekly/from/add/auth")
    @ManagerAuth(memo = "周计划/日计划/日实际")
    @Transactional
    public R formAdd(@RequestBody WeeklyDomainParam param){
        try{
            if (Cools.isEmpty(param)){
                throw new CoolException("参数为空:WeeklyDomainParam");
            } else if (Cools.isEmpty(param.getWeeklyDailyPlanList()) || param.getWeeklyDailyPlanList().size()==0){
                throw new CoolException("参数为空:WeeklyDailyPlanList");
            } else if (Cools.isEmpty(param.getWeeklyType())){
                throw new CoolException("参数为空:WeeklyDailyPlanList");
            } else if (Cools.isEmpty(param.getType())){
                throw new CoolException("参数为空:Type");
            } else if (Cools.isEmpty(param.getWeeklyType())){
                throw new CoolException("参数为空:Weekly");
            }
            Date now = new Date();
            Weekly weekly = new Weekly();
            weekly.setHostId(getHostId());
            weekly.setDeptId(getDeptId());               // 所属部门
            weekly.setUserId(getUserId());               // 所属人员
            weekly.setDirector(getUserId());               // 所属人员
            weekly.setCreateBy(getUserId());
            weekly.setCreateTime(now);
            weekly.setUpdateBy(getUserId());
            weekly.setUpdateTime(now);
            List<Date> dateList = new ArrayList<>();//获取周一与周日日期
            switch (param.getWeeklyType()) {
                case 1:
                    dateList = TimeCalculatorUtils.WeeklyMondayAndSundayFront(now);
                    weekly.setStatus(2);
                    break;
                case 2:
                    dateList = TimeCalculatorUtils.WeeklyMondayAndSundayNow(now);
                    weekly.setStatus(1);
                    break;
                case 3:
                    dateList = TimeCalculatorUtils.WeeklyMondayAndSundayAfter(now);
                    weekly.setStatus(0);
                    break;
                default:
                    log.error("参数异常:Weekly="+param.getType());
                    throw new CoolException("参数异常:Weekly="+param.getType());
            }
            Integer weeklyRepeatCount = weeklyService.selectUserStartAndEnd(dateList, getUserId());
            if (Cools.isEmpty(weeklyRepeatCount) && weeklyRepeatCount!=0){
                log.error("周计划已存在==》开始日期:"+dateList.get(0)+"结束日期:"+dateList.get(1)+"员工:"+getUser().getNickname());
                throw new CoolException("周计划已存在==》开始日期:"+dateList.get(0)+"结束日期:"+dateList.get(1)+"员工:"+getUser().getNickname());
            }
//            List<CstmrUtilsParam> cstmrUtilsParamList = JSON.parseArray(weekly.getCstmrIdsPlan(), CstmrUtilsParam.class);
            weekly.setStartTime(dateList.get(0));
            weekly.setEndTime(dateList.get(1));
            weekly.setWeeklyYear(TimeCalculatorUtils.timeYest(weekly.getStartTime()));
            weekly.setWeeklyMonth(TimeCalculatorUtils.timeMonth(weekly.getStartTime()));
            weekly.setWeeklyDay(TimeCalculatorUtils.timeDay(weekly.getStartTime()));
            weekly.setWeeklyNowMonth(TimeCalculatorUtils.WeeklyNowMonthDay(weekly.getStartTime()));
            weekly.setWeeklyDayMonth(weekly.getWeeklyMonth()+"月第"+weekly.getWeeklyNowMonth()+"周");
            List<Date> dates = TimeCalculatorUtils.WeeklyListDays(dateList);//获取周一到周日日期
            try{
                weeklyService.insert(weekly);
            } catch (Exception e) {
                log.error("新增周计划主表失败,异常信息:"+e);
                throw new CoolException("新增周计划主表失败");
            }
            List<CstmrUtilsParam> cstmrUtilsParamList = new ArrayList<>();
            for (WeeklyDailyPlan weeklyDailyPlan : param.getWeeklyDailyPlanList()){
                weeklyDailyPlan.setHostId(getHostId());
                weeklyDailyPlan.setDeptId(getDeptId());               // 所属部门
                weeklyDailyPlan.setUserId(getUserId());               // 所属人员
                weeklyDailyPlan.setDirector(getUserId());               // 所属人员
                weeklyDailyPlan.setCreateBy(getUserId());
                weeklyDailyPlan.setCreateTime(now);
                weeklyDailyPlan.setUpdateBy(getUserId());
                weeklyDailyPlan.setUpdateTime(now);
                weeklyDailyPlan.setStatus(weekly.getStatus());
                weeklyDailyPlan.setDailyTime(dates.get(weeklyDailyPlan.getWeeklyDay()-1));
                weeklyDailyPlan.setWeeklyId(weekly.getId());
                try{
                    weeklyDailyPlanService.insert(weeklyDailyPlan);
                } catch (Exception e){
                    log.error("新增日计划失败"+e);
                    throw new CoolException("新增日计划失败");
                }
            }
        } catch (Exception e){
            log.error("创建周计划异常,异常信息:"+e);
            throw new CoolException("创建周计划失败==>"+e);
        }
        return R.ok("创建成功");
    }
    @RequestMapping(value = "/weekly/detl/all/auth")
    @Transactional
    public R head(@RequestParam Integer weeklyId){
        List<WeeklyDailyPlan> weeklyDailyPlans = weeklyDailyPlanService.selectList(new EntityWrapper<WeeklyDailyPlan>().eq("weekly_id", weeklyId));
        return R.ok().add(weeklyDailyPlans);
    }
}