From 6a70e2f5c45e376d14177e1fdb605a346701faa7 Mon Sep 17 00:00:00 2001 From: LSH Date: 星期四, 28 三月 2024 14:32:26 +0800 Subject: [PATCH] #周计划 --- src/main/java/com/zy/crm/manager/controller/WeeklyController.java | 128 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 127 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/zy/crm/manager/controller/WeeklyController.java b/src/main/java/com/zy/crm/manager/controller/WeeklyController.java index 7200aca..2e66b58 100644 --- a/src/main/java/com/zy/crm/manager/controller/WeeklyController.java +++ b/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("鍙傛暟涓虹┖锛歐eeklyDomainParam"); + } else if (Cools.isEmpty(param.getWeeklyDailyPlanList()) || param.getWeeklyDailyPlanList().size()==0){ + throw new CoolException("鍙傛暟涓虹┖锛歐eeklyDailyPlanList"); + } else if (Cools.isEmpty(param.getWeeklyType())){ + throw new CoolException("鍙傛暟涓虹┖锛歐eeklyDailyPlanList"); + } else if (Cools.isEmpty(param.getType())){ + throw new CoolException("鍙傛暟涓虹┖锛歍ype"); + } else if (Cools.isEmpty(param.getWeeklyType())){ + throw new CoolException("鍙傛暟涓虹┖锛歐eekly"); + } + 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.getWeeklyType()); + throw new CoolException("璇烽�夋嫨鏃ユ湡"); + } + + 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); + } } -- Gitblit v1.9.1