| | |
| | | package com.zy.crm.manager.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | 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.common.entity.PhoneCodeTypeParam; |
| | | import com.zy.crm.common.model.SettleDto; |
| | | import com.zy.crm.manager.entity.*; |
| | | 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.zy.crm.manager.service.*; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | |
| | | import com.core.domain.KeyValueVo; |
| | | import com.zy.crm.common.web.BaseController; |
| | | import com.zy.crm.manager.utils.TimeCalculatorUtils; |
| | | import com.zy.crm.system.entity.User; |
| | | import com.zy.crm.system.service.UserService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private WeeklyService weeklyService; |
| | | @Autowired |
| | | private WeeklyDailyPlanService weeklyDailyPlanService; |
| | | @Autowired |
| | | private WeeklyDailyRealityService weeklyDailyRealityService; |
| | | @Autowired |
| | | private UserService userService; |
| | | @Autowired |
| | | private WeeklyFollService weeklyFollService; |
| | | @Autowired |
| | | private SmsCodeService smsCodeService; |
| | | @Autowired |
| | | private CstmrService cstmrService; |
| | | |
| | | String PZH = " ————————————————— "; |
| | | Integer PBN = 3; |
| | | |
| | | @RequestMapping(value = "/weekly/{id}/auth") |
| | | @ManagerAuth |
| | | public R get(@PathVariable("id") String id) { |
| | | return R.ok(weeklyService.selectById(String.valueOf(id))); |
| | | Weekly weekly = weeklyService.selectById(String.valueOf(id)); |
| | | assert weekly != null; |
| | | JSONObject resultObj = JSON.parseObject(JSON.toJSONString(weekly)); |
| | | if (!Cools.isEmpty(weekly.getForm())) { |
| | | JSONObject formObj = JSON.parseObject(weekly.getForm()); |
| | | formObj.forEach(resultObj::putIfAbsent); |
| | | } |
| | | |
| | | // 步骤条相关 |
| | | resultObj.put("step", weekly.getSettle().equals(weekly.getSettleSize()) ? 0 : weekly.getSettle() + 1); |
| | | |
| | | return R.ok().add(resultObj); |
| | | // return R.ok(weeklyService.selectById(String.valueOf(id))); |
| | | } |
| | | |
| | | @RequestMapping(value = "/weekly/list/auth") |
| | |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | @RequestMapping(value = "/weekly/delete/auth") |
| | | @ManagerAuth |
| | | public R delete(@RequestParam(value="ids[]") Long[] ids){ |
| | | for (Long id : ids){ |
| | | weeklyService.deleteById(id); |
| | | } |
| | | return R.ok(); |
| | | public R delete(@RequestParam() Long[] ids){ |
| | | try{ |
| | | for (Long id : ids){ |
| | | List<WeeklyDailyReality> weeklyDailyRealities = weeklyDailyRealityService.selectList(new EntityWrapper<WeeklyDailyReality>().eq("weekly_id", id)); |
| | | for (WeeklyDailyReality weeklyDailyReality:weeklyDailyRealities){ |
| | | weeklyDailyRealityService.deleteById(weeklyDailyReality); |
| | | } |
| | | List<WeeklyDailyPlan> weeklyDailyPlans = weeklyDailyPlanService.selectList(new EntityWrapper<WeeklyDailyPlan>().eq("weekly_id", id)); |
| | | for (WeeklyDailyPlan weeklyDailyPlan:weeklyDailyPlans){ |
| | | weeklyDailyPlanService.deleteById(weeklyDailyPlan); |
| | | } |
| | | List<WeeklyFoll> weeklyFolls = weeklyFollService.selectList(new EntityWrapper<WeeklyFoll>().eq("weekly_id", id)); |
| | | for (WeeklyFoll weeklyFoll:weeklyFolls){ |
| | | weeklyFollService.deleteById(weeklyFoll); |
| | | } |
| | | weeklyService.deleteById(id); |
| | | } |
| | | }catch (Exception e){ |
| | | throw new CoolException("删除失败,异常信息:"+e); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/weekly/export/auth") |
| | |
| | | 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()+"周"); |
| | | |
| | | User manager = new User(); |
| | | try { |
| | | manager = userService.getDeptManager(getHostId(), getUser().getDeptId()); // 获取部门领导 |
| | | } catch (Exception e) { |
| | | manager = getUser(); |
| | | } |
| | | // 获取业务员 |
| | | List<String> initNames = new ArrayList<>(); |
| | | initNames.add("创建了审批"); |
| | | initNames.add("业务员提交"); |
| | | initNames.add("部门领导审核"); |
| | | List<User> users = new ArrayList<>(); |
| | | users.add(getUser()); |
| | | users.add(getUser()); |
| | | users.add(manager); |
| | | // users.add(getUser()); |
| | | weekly.setSettleMsg(JSON.toJSONString(SettleDto.InItFlowPathTwo(users, initNames, users.size()))); |
| | | weekly.setSettleSize(users.size()); |
| | | weekly.setSettleCurrent(1); |
| | | if (users.size() > 1) { |
| | | weekly.setDirector(users.get(1).getId()); |
| | | } else { |
| | | weekly.setDirector(getUserId()); |
| | | } |
| | | |
| | | |
| | | weekly.setSettleSize(users.size()); |
| | | |
| | | 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(manager.getId()); // 所属人员 |
| | | |
| | | 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); |
| | | WeeklyDailyReality weeklyDailyReality = new WeeklyDailyReality(); |
| | | weeklyDailyReality.sync(weeklyDailyPlan); |
| | | weeklyDailyReality.setWorkContent(""); |
| | | weeklyDailyRealityService.insert(weeklyDailyReality); |
| | | |
| | | } catch (Exception e){ |
| | | log.error("新增日计划失败"+e); |
| | | throw new CoolException("新增日计划失败"); |
| | | } |
| | | } |
| | | |
| | | try{ |
| | | insertWeeklyFoll(users,weekly.getId()); // 自动添加跟进人 |
| | | }catch (Exception e){ |
| | | log.error("周报添加跟进人异常,异常信息1:"+e); |
| | | } |
| | | |
| | | } catch (Exception e){ |
| | | log.error("创建周计划异常,异常信息:"+e); |
| | | return R.error("创建周计划失败==>"+e); |
| | | // throw new CoolException("创建周计划失败==>"+e); |
| | | } |
| | | |
| | | return R.ok("创建成功"); |
| | | } |
| | | |
| | | public void insertWeeklyFoll(List<User> userList,Long weeklyId){ |
| | | for (User user:userList){ |
| | | try{ |
| | | // 自动添加跟进人 |
| | | List<WeeklyFoll> weeklyFolls = weeklyFollService.selectList(new EntityWrapper<WeeklyFoll>().eq("weekly_id", weeklyId).eq("user_id", user.getId())); |
| | | if (weeklyFolls.size()==0){ |
| | | WeeklyFoll weeklyFoll = new WeeklyFoll(); |
| | | weeklyFoll.setUserId(user.getId()); |
| | | weeklyFoll.setWeeklyId(weeklyId); |
| | | weeklyFollService.insert(weeklyFoll); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("周报添加跟进人异常,异常信息2:"+e); |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "/weekly/from/add/auth2") |
| | | @ManagerAuth(memo = "周计划/日计划/日实际") |
| | | @Transactional |
| | | public R formAdd2(@RequestBody WeeklyDomainParam param){ |
| | | try{ |
| | | if (Cools.isEmpty(param)){ |
| | | throw new CoolException("参数为空:WeeklyDomainParam"); |
| | | } else if (Cools.isEmpty(param.getWeeklyDailyRealityList()) || param.getWeeklyDailyRealityList().size()==0){ |
| | | throw new CoolException("参数为空:WeeklyDailyRealityList"); |
| | | } 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.setCreateBy(getUserId()); |
| | | weekly.setCreateTime(now); |
| | | weekly.setUpdateBy(getUserId()); |
| | | weekly.setUpdateTime(now); |
| | | |
| | | User manager = new User(); |
| | | try { |
| | | manager = userService.getDeptManager(getHostId(), getUser().getDeptId()); // 获取部门领导 |
| | | } catch (Exception e) { |
| | | manager = getUser(); |
| | | } |
| | | weekly.setDirector(manager.getId()); |
| | | |
| | | // 获取业务员 |
| | | List<String> initNames = new ArrayList<>(); |
| | | initNames.add("创建了审批"); |
| | | initNames.add("业务员提交"); |
| | | initNames.add("部门领导审核"); |
| | | List<User> users = new ArrayList<>(); |
| | | users.add(getUser()); |
| | | users.add(getUser()); |
| | | users.add(manager); |
| | | // users.add(getUser()); |
| | | weekly.setSettleMsg(JSON.toJSONString(SettleDto.InItFlowPathTwo(users, initNames, users.size()))); |
| | | weekly.setSettleSize(users.size()); |
| | | weekly.setSettleCurrent(1); |
| | | if (users.size() > 1) { |
| | | weekly.setDirector(users.get(1).getId()); |
| | | } else { |
| | | weekly.setDirector(getUserId()); |
| | | } |
| | | |
| | | |
| | | List<Date> dateList = new ArrayList<>();//获取周一与周日日期 |
| | |
| | | weeklyService.insert(weekly); |
| | | } catch (Exception e) { |
| | | log.error("新增周计划主表失败,异常信息:"+e); |
| | | throw new CoolException("新增周计划主表失败"); |
| | | return R.error("新增周计划主表失败"); |
| | | // throw new CoolException("新增周计划主表失败"); |
| | | } |
| | | |
| | | List<CstmrUtilsParam> cstmrUtilsParamList = new ArrayList<>(); |
| | | for (WeeklyDailyPlan weeklyDailyPlan : param.getWeeklyDailyPlanList()){ |
| | | for (WeeklyDailyReality weeklyDailyReality : param.getWeeklyDailyRealityList()){ |
| | | |
| | | weeklyDailyPlan.setHostId(getHostId()); |
| | | weeklyDailyPlan.setDeptId(getDeptId()); // 所属部门 |
| | | weeklyDailyPlan.setUserId(getUserId()); // 所属人员 |
| | | weeklyDailyReality.setHostId(getHostId()); |
| | | weeklyDailyReality.setDeptId(getDeptId()); // 所属部门 |
| | | weeklyDailyReality.setUserId(getUserId()); // 所属人员 |
| | | |
| | | weeklyDailyPlan.setDirector(getUserId()); // 所属人员 |
| | | weeklyDailyReality.setDirector(manager.getId()); // 所属人员 |
| | | |
| | | weeklyDailyPlan.setCreateBy(getUserId()); |
| | | weeklyDailyPlan.setCreateTime(now); |
| | | weeklyDailyPlan.setUpdateBy(getUserId()); |
| | | weeklyDailyPlan.setUpdateTime(now); |
| | | weeklyDailyReality.setCreateBy(getUserId()); |
| | | weeklyDailyReality.setCreateTime(now); |
| | | weeklyDailyReality.setUpdateBy(getUserId()); |
| | | weeklyDailyReality.setUpdateTime(now); |
| | | |
| | | weeklyDailyPlan.setStatus(weekly.getStatus()); |
| | | weeklyDailyReality.setStatus(weekly.getStatus()); |
| | | |
| | | weeklyDailyPlan.setDailyTime(dates.get(weeklyDailyPlan.getWeeklyDay()-1)); |
| | | weeklyDailyPlan.setWeeklyId(weekly.getId()); |
| | | weeklyDailyReality.setDailyTime(dates.get(weeklyDailyReality.getWeeklyDay()-1)); |
| | | weeklyDailyReality.setWeeklyId(weekly.getId()); |
| | | |
| | | try{ |
| | | weeklyDailyPlanService.insert(weeklyDailyPlan); |
| | | weeklyDailyRealityService.insert(weeklyDailyReality); |
| | | } catch (Exception e){ |
| | | log.error("新增日计划失败"+e); |
| | | throw new CoolException("新增日计划失败"); |
| | | // throw new CoolException("新增日计划失败"); |
| | | return R.error("新增日计划失败"); |
| | | } |
| | | } |
| | | |
| | | try{ |
| | | insertWeeklyFoll(users,weekly.getId()); // 自动添加跟进人 |
| | | }catch (Exception e){ |
| | | log.error("周报添加跟进人异常,异常信息1:"+e); |
| | | } |
| | | |
| | | } catch (Exception e){ |
| | | log.error("创建周计划异常,异常信息:"+e); |
| | | throw new CoolException("创建周计划失败==>"+e); |
| | | // throw new CoolException("创建周计划失败==>"+e); |
| | | return R.error("创建周计划失败==>"+e); |
| | | } |
| | | |
| | | return R.ok("创建成功"); |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/weekly/from/modify/auth") |
| | | @ManagerAuth(memo = "周计划/日计划/日实际") |
| | | @Transactional |
| | | public R formAddModify(@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.getWeeklyId())){ |
| | | throw new CoolException("参数为空:WeeklyId"); |
| | | } else if (Cools.isEmpty(param.getType())){ |
| | | throw new CoolException("参数为空:Type"); |
| | | } |
| | | // if (Cools.isEmpty(param.getWeeklyType())){ |
| | | // throw new CoolException("参数为空:Weekly"); |
| | | // } |
| | | Date now = new Date(); |
| | | Weekly weekly = weeklyService.selectById(param.getWeeklyId()); |
| | | weekly.setUpdateBy(getUserId()); |
| | | weekly.setUpdateTime(now); |
| | | |
| | | |
| | | List<Date> dateList = new ArrayList<>();//获取周一与周日日期 |
| | | dateList = TimeCalculatorUtils.WeeklyMondayAndSundayNow(weekly.getStartTime()); |
| | | |
| | | // List<CstmrUtilsParam> cstmrUtilsParamList = JSON.parseArray(weekly.getCstmrIdsPlan(), CstmrUtilsParam.class); |
| | | |
| | | List<Date> dates = TimeCalculatorUtils.WeeklyListDays(dateList);//获取周一到周日日期 |
| | | |
| | | try{ |
| | | weeklyService.updateById(weekly); |
| | | } catch (Exception e) { |
| | | log.error("更新周计划主表失败,异常信息:"+e); |
| | | throw new CoolException("更新周计划主表失败"); |
| | | } |
| | | |
| | | 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(weeklyDailyPlan1)){ |
| | | throw new CoolException("更新失败:id:"+weeklyDailyPlanId); |
| | | } |
| | | 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(weeklyDailyPlan.getCstmrId()); |
| | | } |
| | | weeklyDailyPlanService.updateById(weeklyDailyPlan1); |
| | | |
| | | }else { |
| | | 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/from/modify/auth2") |
| | | @ManagerAuth(memo = "周计划/日计划/日实际") |
| | | @Transactional |
| | | public R formAddModify2(@RequestBody WeeklyDomainParam param){ |
| | | try{ |
| | | if (Cools.isEmpty(param)){ |
| | | throw new CoolException("参数为空:WeeklyDomainParam"); |
| | | } else if (Cools.isEmpty(param.getWeeklyDailyRealityList()) || param.getWeeklyDailyRealityList().size()==0){ |
| | | throw new CoolException("参数为空:WeeklyDailyRealityList"); |
| | | } else if (Cools.isEmpty(param.getWeeklyId())){ |
| | | throw new CoolException("参数为空:WeeklyId"); |
| | | } 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 = weeklyService.selectById(param.getWeeklyId()); |
| | | weekly.setUpdateBy(getUserId()); |
| | | weekly.setUpdateTime(now); |
| | | |
| | | |
| | | List<Date> dateList = new ArrayList<>();//获取周一与周日日期 |
| | | dateList = TimeCalculatorUtils.WeeklyMondayAndSundayNow(weekly.getStartTime()); |
| | | |
| | | // List<CstmrUtilsParam> cstmrUtilsParamList = JSON.parseArray(weekly.getCstmrIdsPlan(), CstmrUtilsParam.class); |
| | | |
| | | List<Date> dates = TimeCalculatorUtils.WeeklyListDays(dateList);//获取周一到周日日期 |
| | | |
| | | try{ |
| | | weeklyService.updateById(weekly); |
| | | } catch (Exception e) { |
| | | log.error("更新周计划主表失败,异常信息:"+e); |
| | | throw new CoolException("更新周计划主表失败"); |
| | | } |
| | | |
| | | 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 weeklyDailyRealityId = weeklyDailyReality.getId(); |
| | | weeklyDailyReality1 = weeklyDailyRealityService.selectById(weeklyDailyReality.getId()); |
| | | if (Cools.isEmpty(weeklyDailyReality1)){ |
| | | throw new CoolException("更新失败:id:"+weeklyDailyRealityId); |
| | | } |
| | | 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); |
| | | if (!Cools.isEmpty(weeklyDailyReality.getCstmrId())){ |
| | | weeklyDailyReality1.setCstmrId(weeklyDailyReality.getCstmrId()); |
| | | } |
| | | weeklyDailyRealityService.updateById(weeklyDailyReality1); |
| | | |
| | | }else { |
| | | weeklyDailyReality.setHostId(getHostId()); |
| | | weeklyDailyReality.setDeptId(getDeptId()); // 所属部门 |
| | | weeklyDailyReality.setUserId(getUserId()); // 所属人员 |
| | | |
| | | weeklyDailyReality.setDirector(getUserId()); // 所属人员 |
| | | |
| | | weeklyDailyReality.setCreateBy(getUserId()); |
| | | weeklyDailyReality.setCreateTime(now); |
| | | weeklyDailyReality.setUpdateBy(getUserId()); |
| | | weeklyDailyReality.setUpdateTime(now); |
| | | |
| | | weeklyDailyReality.setStatus(weekly.getStatus()); |
| | | |
| | | weeklyDailyReality.setDailyTime(dates.get(weeklyDailyReality.getWeeklyDay()-1)); |
| | | weeklyDailyReality.setWeeklyId(weekly.getId()); |
| | | |
| | | try{ |
| | | weeklyDailyRealityService.insert(weeklyDailyReality); |
| | | } 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") |
| | |
| | | List<WeeklyDailyPlan> weeklyDailyPlans = weeklyDailyPlanService.selectList(new EntityWrapper<WeeklyDailyPlan>().eq("weekly_id", weeklyId)); |
| | | return R.ok().add(weeklyDailyPlans); |
| | | } |
| | | |
| | | @RequestMapping(value = "/weekly/detl/all/auth2") |
| | | @Transactional |
| | | public R head2(@RequestParam Integer weeklyId){ |
| | | List<WeeklyDailyReality> weeklyDailyRealities = weeklyDailyRealityService.selectList(new EntityWrapper<WeeklyDailyReality>().eq("weekly_id", weeklyId)); |
| | | return R.ok().add(weeklyDailyRealities); |
| | | } |
| | | |
| | | @PostMapping(value = "/weekly/approval/auth") |
| | | @ManagerAuth(memo = "审批申请单") |
| | | public R approval(@RequestParam Long weeklyId, |
| | | @RequestParam(required = false) Long plannerId) { |
| | | Weekly weekly = weeklyService.selectById(weeklyId); |
| | | assert weekly != null; |
| | | Long nextUserId = getUserId(); |
| | | User director = userService.selectById(weekly.getDirector()); |
| | | |
| | | if (Cools.isEmpty(getUser()) || Cools.isEmpty(director)) { |
| | | return R.error("抱歉,您无需确认!!!"); |
| | | } |
| | | |
| | | if (!getUserId().equals(director.getId())) { |
| | | return R.error("抱歉,您无需确认!!!"); |
| | | } |
| | | |
| | | // 修改 settle 步骤数据 |
| | | List<SettleDto> list = JSON.parseArray(weekly.getSettleMsg(), SettleDto.class); |
| | | // 修改 settle 步骤数据 |
| | | for (SettleDto dto : list) { |
| | | if (dto.getStep().equals(weekly.getSettle())) { |
| | | dto.setCurr(Boolean.TRUE); |
| | | } else if (dto.getStep().equals(weekly.getSettle() + 1)) { |
| | | dto.setCurr(Boolean.TRUE); |
| | | if (Cools.isEmpty(dto.getMsg())) { |
| | | dto.setMsg(director.getNickname() + "审批通过"); |
| | | } else { |
| | | dto.setMsg(dto.getMsg() + PZH + DateUtils.convert(new Date()) + " " + director.getNickname() + "审批通过"); |
| | | } |
| | | dto.setTime(DateUtils.convert(new Date())); |
| | | } else if (dto.getStep().equals(weekly.getSettle() + 2)) { |
| | | nextUserId = dto.getUserId(); |
| | | } |
| | | } |
| | | weekly.setSettleMsg(JSON.toJSONString(list)); |
| | | // 修改规划单状态 |
| | | weekly.setSettle(weekly.getSettle() + 1); // 审批通过 |
| | | |
| | | weekly.setUpdateBy(getUserId()); |
| | | weekly.setUpdateTime(new Date()); |
| | | weekly.setDirector(nextUserId); |
| | | |
| | | if (!weeklyService.updateById(weekly)) { |
| | | throw new CoolException("审核失败,请联系管理员"); |
| | | } |
| | | if (!weekly.getSettle().equals(weekly.getSettleSize())) { |
| | | User phoneUser = userService.selectById(nextUserId); |
| | | if (!smsCodeService.sendSmsCodeText(phoneUser.getMobile(), PhoneCodeTypeParam.ALIYUN_M1ABAC630E, getUserId())) { |
| | | return R.ok("审核成功但短信发送失败!"); |
| | | } |
| | | } |
| | | |
| | | return R.ok("审批成功"); |
| | | } |
| | | |
| | | @PostMapping(value = "/weekly/approvalEnd/auth") |
| | | @ManagerAuth(memo = "拒绝申请单") |
| | | public R approvalEnd(@RequestParam Long weeklyId, |
| | | @RequestParam(required = false) Long plannerId) { |
| | | Weekly weekly = weeklyService.selectById(weeklyId); |
| | | Date now = new Date(); |
| | | Long nextUserId = getUserId(); |
| | | Long directorId = weekly.getDirector(); |
| | | User director = userService.selectById(directorId); |
| | | if (!director.getId().equals(getUserId())) { |
| | | return R.error("抱歉,您没有审核的权限"); |
| | | } |
| | | List<SettleDto> planDtos = JSON.parseArray(weekly.getSettleMsg(), SettleDto.class); |
| | | List<SettleDto> planDtoList = new ArrayList<>(); |
| | | boolean sign = true; |
| | | for (SettleDto dto : planDtos) { |
| | | if (dto.getStep().equals(2)) { |
| | | nextUserId = dto.getUserId(); |
| | | weekly.setDirector(dto.getUserId()); |
| | | } |
| | | if (sign && dto.getUserId().equals(directorId) && weekly.getSettle() + 1 == dto.getStep()) { |
| | | if (Cools.isEmpty(dto.getMsg())) { |
| | | dto.setMsg(DateUtils.convert(now) + " " + director.getNickname() + "回退审批"); |
| | | } else { |
| | | dto.setMsg(dto.getMsg() + PZH + DateUtils.convert(now) + " " + director.getNickname() + "回退审批"); |
| | | } |
| | | sign = false; |
| | | } |
| | | if (sign) { |
| | | dto.setMsg(dto.getMsg() + PZH + DateUtils.convert(now) + " " + director.getNickname() + "回退审批"); |
| | | } |
| | | |
| | | planDtoList.add(dto); |
| | | } |
| | | weekly.setStatus(0); |
| | | weekly.setSettle(1); |
| | | weekly.setSettleMsg(JSON.toJSONString(planDtoList)); |
| | | weekly.setUpdateBy(getUserId()); |
| | | weekly.setUpdateTime(now); |
| | | weeklyService.updateById(weekly); |
| | | if (!weekly.getSettle().equals(weekly.getSettleSize())) { |
| | | User phoneUser = userService.selectById(nextUserId); |
| | | if (!smsCodeService.sendSmsCodeText(phoneUser.getMobile(), PhoneCodeTypeParam.ALIYUN_M1ABAC630E, getUserId())) { |
| | | return R.ok("审核成功但短信发送失败!"); |
| | | } |
| | | } |
| | | return R.ok("回退成功"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/weekly/from/add/phone/auth") |
| | | @ManagerAuth(memo = "周计划/日计划/日实际") |
| | | @Transactional |
| | | public R formAddModifyPhone(@RequestBody WeeklyDomainParam param){ |
| | | try{ |
| | | if (Cools.isEmpty(param)){ |
| | | throw new CoolException("参数为空:WeeklyDomainParam"); |
| | | } else if (Cools.isEmpty(param.getWeeklyDailyRealityList()) || param.getWeeklyDailyRealityList().size()==0){ |
| | | throw new CoolException("参数为空:WeeklyDailyRealityList"); |
| | | } else if (Cools.isEmpty(param.getWeeklyId())){ |
| | | throw new CoolException("参数为空:WeeklyId"); |
| | | // } 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 = weeklyService.selectById(param.getWeeklyId()); |
| | | weekly.setUpdateBy(getUserId()); |
| | | weekly.setUpdateTime(now); |
| | | |
| | | |
| | | List<Date> dateList = new ArrayList<>();//获取周一与周日日期 |
| | | dateList = TimeCalculatorUtils.WeeklyMondayAndSundayNow(weekly.getStartTime()); |
| | | |
| | | List<Date> dates = TimeCalculatorUtils.WeeklyListDays(dateList);//获取周一到周日日期 |
| | | |
| | | try{ |
| | | weeklyService.updateById(weekly); |
| | | } catch (Exception e) { |
| | | log.error("更新周计划主表失败,异常信息:"+e); |
| | | throw new CoolException("更新周计划主表失败"); |
| | | } |
| | | |
| | | List<CstmrUtilsParam> cstmrUtilsParamList = new ArrayList<>(); |
| | | for (WeeklyDailyReality weeklyDailyReality: param.getWeeklyDailyRealityList()){ |
| | | Cstmr cstmr = null; |
| | | if (!Cools.isEmpty(weeklyDailyReality.getCstmrName())){ |
| | | cstmr = cstmrService.selectByName(getHostId(), weeklyDailyReality.getCstmrName()); |
| | | if(Cools.isEmpty(cstmr)){ |
| | | throw new CoolException("未查询到甲方单位!"); |
| | | }else { |
| | | weeklyDailyReality.setCstmrId(cstmr.getId()); |
| | | } |
| | | } |
| | | weeklyDailyReality.setHostId(getHostId()); |
| | | weeklyDailyReality.setDeptId(getDeptId()); // 所属部门 |
| | | weeklyDailyReality.setUserId(getUserId()); // 所属人员 |
| | | |
| | | weeklyDailyReality.setDirector(getUserId()); // 所属人员 |
| | | |
| | | weeklyDailyReality.setCreateBy(getUserId()); |
| | | weeklyDailyReality.setCreateTime(now); |
| | | weeklyDailyReality.setUpdateBy(getUserId()); |
| | | weeklyDailyReality.setUpdateTime(now); |
| | | |
| | | weeklyDailyReality.setStatus(weekly.getStatus()); |
| | | |
| | | weeklyDailyReality.setDailyTime(dates.get(weeklyDailyReality.getWeeklyDay()-1)); |
| | | weeklyDailyReality.setWeeklyId(weekly.getId()); |
| | | |
| | | try{ |
| | | weeklyDailyRealityService.insert(weeklyDailyReality); |
| | | } catch (Exception e){ |
| | | log.error("新增日计划失败"+e); |
| | | throw new CoolException("新增日计划失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | } catch (Exception e){ |
| | | log.error("更新周计划异常,异常信息:"+e); |
| | | throw new CoolException("更新周计划失败==>"+e); |
| | | } |
| | | |
| | | return R.ok("更新成功"); |
| | | } |
| | | } |