中扬CRM客户关系管理系统
LSH
2024-03-28 e3a94fff7f518b2c84296ec4427c985676354096
src/main/java/com/zy/crm/manager/controller/WeeklyController.java
@@ -5,9 +5,10 @@
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.common.DateUtils;
import com.zy.crm.manager.entity.ReimburseOnlineDetl;
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;
@@ -18,12 +19,14 @@
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 {
@@ -145,21 +148,23 @@
    public R formAdd(@RequestBody WeeklyDomainParam param){
        try{
            if (Cools.isEmpty(param)){
                return R.error("参数为空:WeeklyDomainParam");
                throw new CoolException("参数为空:WeeklyDomainParam");
            } else if (Cools.isEmpty(param.getWeeklyDailyPlanList()) || param.getWeeklyDailyPlanList().size()==0){
                return R.error("参数为空:WeeklyDailyPlanList");
                throw new CoolException("参数为空:WeeklyDailyPlanList");
            } else if (Cools.isEmpty(param.getWeeklyType())){
                return R.error("参数为空:WeeklyDailyPlanList");
                throw new CoolException("参数为空:WeeklyDailyPlanList");
            } else if (Cools.isEmpty(param.getType())){
                return R.error("参数为空:Type");
                throw new CoolException("参数为空:Type");
            } else if (Cools.isEmpty(param.getWeeklyType())){
                return R.error("参数为空:Weekly");
                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);
@@ -168,7 +173,7 @@
            List<Date> dateList = new ArrayList<>();//获取周一与周日日期
            switch (param.getType()){
            switch (param.getWeeklyType()) {
                case 1:
                    dateList = TimeCalculatorUtils.WeeklyMondayAndSundayFront(now);
                    weekly.setStatus(2);
@@ -182,15 +187,69 @@
                    weekly.setStatus(0);
                    break;
                default:
                    return R.error("参数异常:Weekly="+param.getType());
                    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);//获取周一到周日日期
            System.out.println(dates.toString());
            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){
            return R.error("异常:"+e);
            log.error("创建周计划异常,异常信息:"+e);
            throw new CoolException("创建周计划失败==>"+e);
        }
        return R.ok();
        return R.ok("创建成功");
    }
    @RequestMapping(value = "/weekly/detl/all/auth")