食谱计划生成修改,根据客户ID重新生成,暂停记录不需要加订单ID
This commit is contained in:
		| @@ -232,7 +232,7 @@ public class SysOrder extends BaseEntity { | ||||
|     /** | ||||
|      * 订单暂停记录 非持久化字段 | ||||
|      * */ | ||||
|     private List<SysOrderPause> orderPauseList; | ||||
|     //private List<SysOrderPause> orderPauseList; | ||||
|  | ||||
|     //查询参数 | ||||
|     private Integer amountFlag; | ||||
|   | ||||
| @@ -100,4 +100,10 @@ public interface SysOrderMapper | ||||
|      * @return | ||||
|      */ | ||||
|     int selectSimpleOrderMessageCount(SysCommision sysCommision); | ||||
|  | ||||
|     /** | ||||
|      * 根据客户ID查询对应所有订单 | ||||
|      * @return | ||||
|      */ | ||||
|     List<SysOrder> getAllOrderByCusId(@Param("cusId") Long cusId); | ||||
| } | ||||
| @@ -82,4 +82,11 @@ public interface SysOrderPauseMapper | ||||
|      * @return | ||||
|      */ | ||||
|     List<SysOrderPause> getPauseListByOrderId(@Param("orderId")Long orderId); | ||||
|  | ||||
|     /** | ||||
|      * 根据客户ID、订单ID查询暂停记录 | ||||
|      * @param sysOrderPause | ||||
|      * @return | ||||
|      */ | ||||
|     List<SysOrderPause> getPauseListByCusIdAndOrderId(SysOrderPause sysOrderPause); | ||||
| } | ||||
| @@ -87,7 +87,7 @@ public interface SysRecipesPlanMapper | ||||
|      * @param customerId | ||||
|      * @return | ||||
|      */ | ||||
|     SysRecipesPlan getLastDayRecipesPlan(@Param("customerId")Long customerId); | ||||
|     SysRecipesPlan getLastDayRecipesPlan(@Param("customerId")Long customerId, @Param("orderId")Long orderId); | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID查询食谱计划 | ||||
|   | ||||
| @@ -81,4 +81,6 @@ public interface ISysOrderPauseService | ||||
|     List<SysOrderPause> getPauseListByOrderId(Long orderId); | ||||
|  | ||||
|     long selectNearMainOrderIdByCusId(Long cusId); | ||||
|  | ||||
|     List<SysOrderPause> getPauseListByCusIdAndOrderId(SysOrderPause sysOrderPause); | ||||
| } | ||||
| @@ -1,6 +1,7 @@ | ||||
| package com.stdiet.custom.service; | ||||
|  | ||||
| import java.math.BigDecimal; | ||||
| import java.time.LocalDate; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| @@ -9,6 +10,7 @@ import com.stdiet.custom.domain.SysCommision; | ||||
| import com.stdiet.custom.domain.SysCustomer; | ||||
| import com.stdiet.custom.domain.SysOrder; | ||||
| import com.stdiet.custom.dto.response.EveryMonthTotalAmount; | ||||
| import org.apache.ibatis.annotations.Param; | ||||
|  | ||||
| /** | ||||
|  * 销售订单Service接口 | ||||
| @@ -74,12 +76,11 @@ public interface ISysOrderService | ||||
|     public BigDecimal selectAllOrderAmount(SysOrder sysOrder); | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID更新该订单的服务到期时间,异步更新食谱计划 | ||||
|      * @param orderId  订单ID | ||||
|      * @param updatePlan 是否更新食谱 | ||||
|      * 暂停记录发生变更的时候需要更新该用户对应所有订单的开始时间、结束时间 | ||||
|      * @param cusId | ||||
|      * @return | ||||
|      */ | ||||
|     int updateOrderServerEndDate(Long orderId, boolean updatePlan); | ||||
|     int updateOrderServerStartEndDate(Long cusId); | ||||
|  | ||||
|     /** | ||||
|      * 查询客户订单数量 | ||||
| @@ -100,4 +101,17 @@ public interface ISysOrderService | ||||
|      * @return | ||||
|      */ | ||||
|     int selectSimpleOrderMessageCount(SysCommision sysCommision); | ||||
|  | ||||
|     /** | ||||
|      * 更新订单的开始时间以及提成计算开始时间 | ||||
|      * @param sysOrder | ||||
|      * @param date | ||||
|      */ | ||||
|     void updateOrderStartTime(SysOrder sysOrder, LocalDate date); | ||||
|  | ||||
|     /** | ||||
|      * 根据客户ID查询对应所有订单 | ||||
|      * @return | ||||
|      */ | ||||
|     List<SysOrder> getAllOrderByCusId(Long cusId); | ||||
| } | ||||
| @@ -2,10 +2,8 @@ package com.stdiet.custom.service; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import com.stdiet.custom.domain.SysOrder; | ||||
| import com.stdiet.custom.domain.SysRecipesPlan; | ||||
| import com.stdiet.custom.domain.SysRecipesPlanListInfo; | ||||
| import org.springframework.core.annotation.Order; | ||||
|  | ||||
| /** | ||||
|  * 食谱计划Service接口 | ||||
| @@ -65,10 +63,10 @@ public interface ISysRecipesPlanService | ||||
|  | ||||
|     /** | ||||
|      * 订单发生更新时(开始时间、服务时长、赠送时长),重新生成食谱计划 | ||||
|      * @param orderId 订单ID | ||||
|      * @param cusId 客户ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public void regenerateRecipesPlan(Long orderId); | ||||
|     public void regenerateRecipesPlan(Long cusId); | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID删除所有食谱安排计划 | ||||
| @@ -104,7 +102,7 @@ public interface ISysRecipesPlanService | ||||
|      * @param customerId | ||||
|      * @return | ||||
|      */ | ||||
|     SysRecipesPlan getLastDayRecipesPlan(Long customerId); | ||||
|     SysRecipesPlan getLastDayRecipesPlan(Long customerId, Long orderId); | ||||
|  | ||||
|     /** | ||||
|      * 通过outId查询食谱计划简要 | ||||
|   | ||||
| @@ -87,15 +87,12 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService { | ||||
|             int giveDay = sysOrder.getGiveServeDay() != null ? sysOrder.getGiveServeDay().intValue() : 0; | ||||
|             //服务到期时间(加赠送时间,不加暂停时间) | ||||
|             serverEndDate = serverStartDate.plusMonths(serverMonth).plusDays(giveDay+serverSmallDay); | ||||
|             List<SysOrderPause> pausesList = sysOrder.getOrderPauseList(); | ||||
|             if(pausesList == null){ | ||||
|                 if(sysOrder.getOrderId() != null){ | ||||
|                     SysOrderPause sysOrderPause = new SysOrderPause(); | ||||
|                     sysOrderPause.setOrderId(sysOrder.getOrderId()); | ||||
|                     pausesList = sysOrderPauseMapper.selectSysOrderPauseList(sysOrderPause); | ||||
|                 }else{ | ||||
|                     pausesList = new ArrayList<>(); | ||||
|                 } | ||||
|             List<SysOrderPause> pausesList = new ArrayList<>(); | ||||
|             if(sysOrder.getOrderId() != null){ | ||||
|                 SysOrderPause sysOrderPause = new SysOrderPause(); | ||||
|                 sysOrderPause.setOrderId(sysOrder.getOrderId()); | ||||
|                 sysOrderPause.setCusId(sysOrder.getCusId()); | ||||
|                 pausesList = sysOrderPauseMapper.getPauseListByCusIdAndOrderId(sysOrderPause); | ||||
|             } | ||||
|             //每年每月暂停天数,key为年份加月份,如:2021年1月=20211 | ||||
|             Map<String, Integer> everyYearMonthPauseDay = getEveryYearMonthPauseDay(pausesList, serverStartDate, serverEndDate); | ||||
| @@ -408,8 +405,13 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService { | ||||
|         LocalDate serverEndDate = serverStartDate.plusMonths(serverMonth).plusDays(giveDay+serverSmallDay); | ||||
|         //订单金额 | ||||
|         BigDecimal orderAmount = sysOrder.getAmount(); | ||||
|         //查询暂停列表 | ||||
|         SysOrderPause pauseParam = new SysOrderPause(); | ||||
|         pauseParam.setOrderId(sysOrder.getOrderId()); | ||||
|         pauseParam.setCusId(sysOrder.getCusId()); | ||||
|         List<SysOrderPause> pauseList = sysOrderPauseMapper.getPauseListByCusIdAndOrderId(pauseParam); | ||||
|         //每年每月暂停天数,key为年份加月份,如:2021年1月=20211 | ||||
|         Map<String, Integer> everyYearMonthPauseDay = getEveryYearMonthPauseDay(sysOrder.getOrderPauseList(), serverStartDate, serverEndDate); | ||||
|         Map<String, Integer> everyYearMonthPauseDay = getEveryYearMonthPauseDay(pauseList, serverStartDate, serverEndDate); | ||||
|         //该笔订单暂停总天数 | ||||
|         int pauseTotalDay = getTotalByMap(everyYearMonthPauseDay); | ||||
|         //服务到期时间加上暂停时间 | ||||
| @@ -443,7 +445,7 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService { | ||||
|             LocalDate realStartTime = DateUtils.stringToLocalDate(serverScopeStartTime, "yyyy-MM-dd"); | ||||
|             LocalDate realEndTime = DateUtils.stringToLocalDate(serverScopeEndTime, "yyyy-MM-dd"); | ||||
|             //计算该时间范围内的暂停时间 | ||||
|             Map<String, Integer> realEveryYearMonthPauseDay = getRealEveryYearMonthPauseDay(sysOrder.getOrderPauseList(), serverStartDate, serverEndDate, realStartTime, realEndTime); | ||||
|             Map<String, Integer> realEveryYearMonthPauseDay = getRealEveryYearMonthPauseDay(pauseList, serverStartDate, serverEndDate, realStartTime, realEndTime); | ||||
|             //暂停总天数 | ||||
|             int realPauseTotalDay = getTotalByMap(realEveryYearMonthPauseDay); | ||||
|             //计算每年每月服务天数 | ||||
|   | ||||
| @@ -67,7 +67,7 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService | ||||
|         sysOrderPause.setCreateTime(DateUtils.getNowDate()); | ||||
|         if(sysOrderPauseMapper.insertSysOrderPause(sysOrderPause) > 0){ | ||||
|             //修改订单服务到期时间 | ||||
|             return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId(), true); | ||||
|             return sysOrderService.updateOrderServerStartEndDate(sysOrderPause.getCusId()); | ||||
|         } | ||||
|         return 0; | ||||
|     } | ||||
| @@ -83,7 +83,7 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService | ||||
|     { | ||||
|         sysOrderPause.setUpdateTime(DateUtils.getNowDate()); | ||||
|         if(sysOrderPauseMapper.updateSysOrderPause(sysOrderPause) > 0){ | ||||
|             return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId(), true); | ||||
|             return sysOrderService.updateOrderServerStartEndDate(sysOrderPause.getCusId()); | ||||
|         } | ||||
|         return 0; | ||||
|     } | ||||
| @@ -98,8 +98,8 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService | ||||
|     public int deleteSysOrderPauseByIds(Long[] ids) | ||||
|     { | ||||
|         SysOrderPause sysOrderPause = selectSysOrderPauseById(ids[0]); | ||||
|         if(sysOrderPause != null && sysOrderPauseMapper.deleteSysOrderPauseByIds(ids) > 0){ | ||||
|             return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId(), true); | ||||
|         if(sysOrderPauseMapper.deleteSysOrderPauseByIds(ids) > 0){ | ||||
|             return sysOrderService.updateOrderServerStartEndDate(sysOrderPause.getCusId()); | ||||
|         } | ||||
|         return 0; | ||||
|     } | ||||
| @@ -115,7 +115,7 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService | ||||
|     { | ||||
|         SysOrderPause sysOrderPause = selectSysOrderPauseById(id); | ||||
|         if(sysOrderPause != null && sysOrderPauseMapper.deleteSysOrderPauseById(id) > 0){ | ||||
|             return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId(), true); | ||||
|             return sysOrderService.updateOrderServerStartEndDate(sysOrderPause.getCusId()); | ||||
|         } | ||||
|         return 0; | ||||
|     } | ||||
| @@ -154,4 +154,9 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService | ||||
|     public long selectNearMainOrderIdByCusId(Long cusId) { | ||||
|         return sysOrderPauseMapper.selectNearMainOrderIdByCusId(cusId); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<SysOrderPause> getPauseListByCusIdAndOrderId(SysOrderPause sysOrderPauses){ | ||||
|         return sysOrderPauseMapper.getPauseListByCusIdAndOrderId(sysOrderPauses); | ||||
|     } | ||||
| } | ||||
| @@ -190,8 +190,6 @@ public class SysOrderServiceImpl implements ISysOrderService { | ||||
|     public int updateSysOrder(SysOrder sysOrder) { | ||||
|         //获取旧订单对象 | ||||
|         SysOrder oldSysOrder = sysOrderMapper.selectSysOrderById(sysOrder.getOrderId()); | ||||
|         //计算服务到期时间 | ||||
|         setOrderServerEndDate(sysOrder); | ||||
|         sysOrder.setUpdateBy(SecurityUtils.getUsername()); | ||||
|         sysOrder.setUpdateTime(DateUtils.getNowDate()); | ||||
|         //体验单 | ||||
| @@ -210,25 +208,12 @@ public class SysOrderServiceImpl implements ISysOrderService { | ||||
|             sysOrder.setOperatorId(null); | ||||
|             sysOrder.setOperatorAssisId(null); | ||||
|         } | ||||
|         LocalDate oldStartDate = oldSysOrder.getStartTime() != null ? DateUtils.dateToLocalDate(oldSysOrder.getStartTime()) : null; | ||||
|         LocalDate nowStartDate = sysOrder.getStartTime() != null ? DateUtils.dateToLocalDate(sysOrder.getStartTime()) : null; | ||||
|         //判断修改的开始时间是否为上个月时间,为上个月时间则不修改提成开始时间 | ||||
|         if (oldStartDate != null && nowStartDate != null | ||||
|                 && ChronoUnit.DAYS.between(oldStartDate, nowStartDate) != 0) { | ||||
|             //本月第一天 | ||||
|             LocalDate monthStart = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()); | ||||
|             //System.out.println(monthStart.toString()); | ||||
|             //旧的开始时间和新的开始时间都要需要大于本月第一天 | ||||
|             if(ChronoUnit.DAYS.between(monthStart, oldStartDate) >= 0 && ChronoUnit.DAYS.between(monthStart, nowStartDate) >= 0){ | ||||
|                 sysOrder.setCommissStartTime(sysOrder.getStartTime()); | ||||
|             } | ||||
|         } | ||||
|         //更新订单 | ||||
|         int row = sysOrderMapper.updateSysOrder(sysOrder); | ||||
|         // 审核后的订单才生成食谱 | ||||
|         if (row > 0 && isNeedRegenerateRecipesPlan(oldSysOrder, sysOrder)) { | ||||
|             //异步更新食谱计划 | ||||
|             sysRecipesPlanService.regenerateRecipesPlan(sysOrder.getOrderId()); | ||||
|             //异步更新客户所有订单的服务时间范围以及生成食谱计划 | ||||
|             updateOrderServerStartEndDate(sysOrder.getCusId()); | ||||
|         } | ||||
|         return row; | ||||
|     } | ||||
| @@ -301,26 +286,43 @@ public class SysOrderServiceImpl implements ISysOrderService { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID更新该订单的服务到期时间,异步更新食谱计划 | ||||
|      * | ||||
|      * @param orderId    订单ID | ||||
|      * @param updatePlan 是否更新食谱 | ||||
|      * 客户增加、修改、删除暂停记录、新增订单、修改订单订单的相关时间,需要更新该用户对应所有订单的开始时间、结束时间 | ||||
|      * @param cusId | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public int updateOrderServerEndDate(Long orderId, boolean updatePlan) { | ||||
|     public int updateOrderServerStartEndDate(Long cusId){ | ||||
|         int row = 0; | ||||
|         //更新订单服务到期时间 | ||||
|         SysOrder sysOrder = selectSysOrderById(orderId); | ||||
|         if (sysOrder != null) { | ||||
|             //设置服务到期时间 | ||||
|             setOrderServerEndDate(sysOrder); | ||||
|             sysOrder.setUpdateTime(new Date()); | ||||
|             row = updateSysOrder(sysOrder); | ||||
|             if (row > 0) { | ||||
|                 //异步更新食谱计划 | ||||
|                 sysRecipesPlanService.regenerateRecipesPlan(sysOrder.getOrderId()); | ||||
|         //查询该用户的所有订单 | ||||
|         List<SysOrder> orderList = getAllOrderByCusId(cusId); | ||||
|         if(orderList != null && orderList.size() > 0){ | ||||
|             LocalDate lastServerEndTime = null; | ||||
|             for (SysOrder sysOrder : orderList) { | ||||
|                 LocalDate newStartTime = null; | ||||
|                 //判断是否提成单,拆分单中的副单,体验单,定金单 | ||||
|                 if(sysOrder.getAfterSaleCommissOrder().intValue() == 1 || ("1".equals(sysOrder.getOrderType()) && sysOrder.getMainOrderId().intValue() != 0) || | ||||
|                         "2".equals(sysOrder.getOrderType()) || "1".equals(sysOrder.getOrderMoneyType())){ | ||||
|                     continue; | ||||
|                 } | ||||
|                 //判断前一个订单的结束时间是否大于第二个订单的 | ||||
|                 if(lastServerEndTime != null && ChronoUnit.DAYS.between(DateUtils.dateToLocalDate(sysOrder.getStartTime()), lastServerEndTime) >= 0){ | ||||
|                     newStartTime = lastServerEndTime.plusDays(1); | ||||
|                     //本月第一天 | ||||
|                     LocalDate monthStart = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()); | ||||
|                     //旧的开始时间和新的开始时间都要需要大于本月第一天 | ||||
|                     if(ChronoUnit.DAYS.between(monthStart, DateUtils.dateToLocalDate(sysOrder.getStartTime())) >= 0 && ChronoUnit.DAYS.between(monthStart, newStartTime) >= 0){ | ||||
|                         sysOrder.setCommissStartTime(DateUtils.localDateToDate(newStartTime)); | ||||
|                     } | ||||
|                     sysOrder.setStartTime(DateUtils.localDateToDate(newStartTime)); | ||||
|                 } | ||||
|                 //设置服务到期时间 | ||||
|                 setOrderServerEndDate(sysOrder); | ||||
|                 sysOrder.setUpdateTime(new Date()); | ||||
|                 row = updateSysOrder(sysOrder); | ||||
|                 lastServerEndTime = DateUtils.dateToLocalDate(sysOrder.getServerEndTime()); | ||||
|             } | ||||
|             //异步更新食谱计划 | ||||
|             sysRecipesPlanService.regenerateRecipesPlan(cusId); | ||||
|         } | ||||
|         return row; | ||||
|     } | ||||
| @@ -374,4 +376,34 @@ public class SysOrderServiceImpl implements ISysOrderService { | ||||
|     public int selectSimpleOrderMessageCount(SysCommision sysCommision){ | ||||
|         return sysOrderMapper.selectSimpleOrderMessageCount(sysCommision); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public void updateOrderStartTime(SysOrder sysOrder, LocalDate nowStartDate){ | ||||
|         LocalDate oldStartDate = sysOrder.getStartTime() != null ? DateUtils.dateToLocalDate(sysOrder.getStartTime()) : null; | ||||
|         if (oldStartDate != null && nowStartDate != null | ||||
|                 && ChronoUnit.DAYS.between(oldStartDate, nowStartDate) != 0) { | ||||
|             SysOrder newOrder = new SysOrder(); | ||||
|             newOrder.setStartTime(DateUtils.localDateToDate(nowStartDate)); | ||||
|             newOrder.setOrderId(sysOrder.getOrderId()); | ||||
|             newOrder.setUpdateTime(new Date()); | ||||
|             //本月第一天 | ||||
|             LocalDate monthStart = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()); | ||||
|             //旧的开始时间和新的开始时间都要需要大于本月第一天 | ||||
|             if(ChronoUnit.DAYS.between(monthStart, oldStartDate) >= 0 && ChronoUnit.DAYS.between(monthStart, nowStartDate) >= 0){ | ||||
|                 sysOrder.setCommissStartTime(sysOrder.getStartTime()); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据客户ID查询对应所有订单 | ||||
|      * @return | ||||
|      */ | ||||
|     public List<SysOrder> getAllOrderByCusId(Long cusId){ | ||||
|         return sysOrderMapper.getAllOrderByCusId(cusId); | ||||
|     } | ||||
| } | ||||
| @@ -112,51 +112,58 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * 异步方法,根据订单ID生成对应的食谱计划,退款订单不生成食谱计划 | ||||
|      * 异步方法,根据客户ID生成对应的食谱计划,退款订单不生成食谱计划 | ||||
|      * | ||||
|      * @param orderId 订单ID | ||||
|      * @param cusId 客户ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     @Async | ||||
|     public void regenerateRecipesPlan(Long orderId) { | ||||
|     public void regenerateRecipesPlan(Long cusId) { | ||||
|         try{ | ||||
|             Thread.sleep(5000); | ||||
|         }catch (Exception e){ | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         if (orderId == null || orderId <= 0) { | ||||
|             return; | ||||
|         } | ||||
|         SysOrder sysOrder = sysOrderService.selectSysOrderById(orderId); | ||||
|         //订单为空、金额小于0、订单未审核不进行食谱生成、更新,只对2021年开始的订单进行食谱计划生成,判断订单金额、开始时间、结束时间,为空则直接返回,不重新生成食谱计划 | ||||
|         if (sysOrder == null || !sysOrder.getReviewStatus().equals("yes") /*|| DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear() < 2021*/ | ||||
|                 || sysOrder.getAmount().floatValue() <= 0 || sysOrder.getStartTime() == null || sysOrder.getServerEndTime() == null) { | ||||
|             return; | ||||
|         } | ||||
|         //判断是否提成单,拆分单中的副单,体验单,定金单 | ||||
|         if(sysOrder.getAfterSaleCommissOrder().intValue() == 1 || ("1".equals(sysOrder.getOrderType()) && sysOrder.getMainOrderId().intValue() != 0) || | ||||
|             "2".equals(sysOrder.getOrderType()) || "1".equals(sysOrder.getOrderMoneyType())){ | ||||
|             System.out.println("---------------------不生成食谱------------------------"); | ||||
|         if (cusId == null || cusId <= 0) { | ||||
|             return; | ||||
|         } | ||||
|         try { | ||||
|             //获取redis中该订单对应的锁 | ||||
|             if (synchrolockUtil.lock(String.format(generateRecipesPlanLockKey, orderId))) { | ||||
|                 //判断是否已存在食谱计划 | ||||
|                 SysRecipesPlan queryParam = new SysRecipesPlan(); | ||||
|                 queryParam.setOrderId(orderId); | ||||
|                 List<SysRecipesPlan> oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam); | ||||
|                 //暂停记录列表,按暂停开始时间顺序 | ||||
|                 List<SysOrderPause> pauseList = sysOrderPauseService.getPauseListByOrderId(sysOrder.getOrderId()); | ||||
|                 List<SysRecipesPlan> planList = generatePlan(sysOrder, oldRecipesPlanList, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList); | ||||
|                 if(oldRecipesPlanList != null && oldRecipesPlanList.size() > 0){ | ||||
|                     updateOrAddRecipesPlan(oldRecipesPlanList, planList); | ||||
|                 }else{ | ||||
|                     if (planList != null && planList.size() > 0) { | ||||
|                         sysRecipesPlanMapper.insertBatch(planList); | ||||
|             if (synchrolockUtil.lock(String.format(generateRecipesPlanLockKey, cusId))) { | ||||
|                 List<SysOrder> customerOrderList = sysOrderService.getAllOrderByCusId(cusId); | ||||
|                 if(customerOrderList != null && customerOrderList.size() > 0){ | ||||
|  | ||||
|                     for(SysOrder sysOrder : customerOrderList){ | ||||
|                         //订单为空、金额小于0、订单未审核不进行食谱生成、更新,只对2021年开始的订单进行食谱计划生成,判断订单金额、开始时间、结束时间,为空则直接返回,不重新生成食谱计划 | ||||
|                         if (sysOrder == null || !sysOrder.getReviewStatus().equals("yes") || sysOrder.getAmount().floatValue() <= 0 || sysOrder.getStartTime() == null || sysOrder.getServerEndTime() == null) { | ||||
|                             return; | ||||
|                         } | ||||
|                         //判断是否提成单,拆分单中的副单,体验单,定金单 | ||||
|                         if(sysOrder.getAfterSaleCommissOrder().intValue() == 1 || ("1".equals(sysOrder.getOrderType()) && sysOrder.getMainOrderId().intValue() != 0) || | ||||
|                                 "2".equals(sysOrder.getOrderType()) || "1".equals(sysOrder.getOrderMoneyType())){ | ||||
|                             System.out.println("---------------------"+sysOrder.getOrderId()+"不生成食谱------------------------"); | ||||
|                             return; | ||||
|                         } | ||||
|                         //判断是否已存在食谱计划 | ||||
|                         SysRecipesPlan queryParam = new SysRecipesPlan(); | ||||
|                         queryParam.setOrderId(sysOrder.getOrderId()); | ||||
|                         List<SysRecipesPlan> oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam); | ||||
|  | ||||
|                         //根据客户ID、订单ID查询该客户对应的暂停记录列表,按暂停开始时间顺序 | ||||
|                         SysOrderPause pauseParam = new SysOrderPause(); | ||||
|                         pauseParam.setOrderId(sysOrder.getOrderId()); | ||||
|                         pauseParam.setCusId(sysOrder.getCusId()); | ||||
|                         List<SysOrderPause> pauseList = sysOrderPauseService.getPauseListByCusIdAndOrderId(pauseParam); | ||||
|  | ||||
|                         List<SysRecipesPlan> planList = generatePlan(sysOrder, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList); | ||||
|                         if(oldRecipesPlanList != null && oldRecipesPlanList.size() > 0){ | ||||
|                             updateOrAddRecipesPlan(oldRecipesPlanList, planList); | ||||
|                         }else{ | ||||
|                             if (planList != null && planList.size() > 0) { | ||||
|                                 sysRecipesPlanMapper.insertBatch(planList); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| @@ -164,7 +171,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { | ||||
|             e.printStackTrace(); | ||||
|         } finally { | ||||
|             // 一定要释放锁 | ||||
|             synchrolockUtil.unlock(String.format(generateRecipesPlanLockKey, orderId)); | ||||
|             synchrolockUtil.unlock(String.format(generateRecipesPlanLockKey, cusId)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -184,8 +191,8 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { | ||||
|                 plan.setStartDate(newRecipesPlanList.get(index).getStartDate()); | ||||
|                 plan.setEndDate(newRecipesPlanList.get(index).getEndDate()); | ||||
|                 plan.setPauseDate(newRecipesPlanList.get(index).getPauseDate()); | ||||
|                 plan.setStartNumDay(plan.getStartNumDay()); | ||||
|                 plan.setEndNumDay(plan.getEndNumDay()); | ||||
|                 plan.setStartNumDay(newRecipesPlanList.get(index).getStartNumDay()); | ||||
|                 plan.setEndNumDay(newRecipesPlanList.get(index).getEndNumDay()); | ||||
|                 updateList.add(plan); | ||||
|             }else{ | ||||
|                 delList.add(plan.getId()); | ||||
| @@ -220,14 +227,32 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { | ||||
|      * @param pauseList          暂停列表 | ||||
|      * @return | ||||
|      */ | ||||
|     private List<SysRecipesPlan> generatePlan(SysOrder sysOrder, List<SysRecipesPlan> oldRecipesPlanList, LocalDate serverStartDate, LocalDate serverEndDate, List<SysOrderPause> pauseList) { | ||||
|         //查询该客户最后一次食谱计划对应天数 | ||||
|         int oldStartNumDay = 0; | ||||
|         if(oldRecipesPlanList.size() == 0){ | ||||
|             SysRecipesPlan lastSysRecipesPlan = getLastDayRecipesPlan(sysOrder.getCusId()); | ||||
|             oldStartNumDay = lastSysRecipesPlan == null || lastSysRecipesPlan.getEndNumDay() == null ? 0 : lastSysRecipesPlan.getEndNumDay().intValue(); | ||||
|         }else{ | ||||
|             oldStartNumDay =  oldRecipesPlanList.get(0).getStartNumDay() - 1; | ||||
|     private List<SysRecipesPlan> generatePlan(SysOrder sysOrder, LocalDate serverStartDate, LocalDate serverEndDate, List<SysOrderPause> pauseList) { | ||||
|         //查询在上一个订单最后一条食谱计划 | ||||
|         SysRecipesPlan beforeOrderLastPlan = getLastDayRecipesPlan(sysOrder.getCusId(), sysOrder.getOrderId()); | ||||
|         int startNumDay = 0; | ||||
|         //之前是否存在食谱 | ||||
|         if(beforeOrderLastPlan != null){ | ||||
|             long differDay = ChronoUnit.DAYS.between(DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()), serverStartDate); | ||||
|             //检查之前食谱的结束时间和目前该订单的开始时间是否连续 | ||||
|             if(differDay <= 1){ | ||||
|                 /*if(differDay <= 0){ | ||||
|                     serverStartDate = DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(1); | ||||
|                     //更新该订单的开始时间 | ||||
|                     sysOrderService.updateOrderStartTime(sysOrder, serverStartDate);1 7   1  3  2 | ||||
|                 }*/ | ||||
|                 //判断前一个订单食谱是否满七天,不满则需要接上 | ||||
|                 int differNum = beforeOrderLastPlan.getEndNumDay() - beforeOrderLastPlan.getStartNumDay(); | ||||
|  | ||||
|                 if(differNum < 6){ | ||||
|                     //更新该食谱计划 | ||||
|                     beforeOrderLastPlan.setEndNumDay(beforeOrderLastPlan.getStartNumDay()+6); | ||||
|                     beforeOrderLastPlan.setEndDate(DateUtils.localDateToDate(DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(6-differNum))); | ||||
|                     sysRecipesPlanMapper.updateSysRecipesPlan(beforeOrderLastPlan); | ||||
|                     serverStartDate = DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(1); | ||||
|                 } | ||||
|             } | ||||
|             startNumDay = beforeOrderLastPlan.getEndNumDay(); | ||||
|         } | ||||
|         List<SysRecipesPlan> planList = new ArrayList<>(); | ||||
|         LocalDate planStartDate = null; | ||||
| @@ -250,6 +275,10 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { | ||||
|                 planEndDate = serverEndDate; | ||||
|                 breakFlag = false; | ||||
|             } | ||||
|             if (ChronoUnit.DAYS.between(planStartDate, serverEndDate) <= 0) { | ||||
|                 planStartDate = serverEndDate; | ||||
|                 breakFlag = false; | ||||
|             } | ||||
|             //暂停日期 | ||||
|             sysRecipesPlan.setPauseDate(pauseResult[3]); | ||||
|             sysRecipesPlan.setStartDate(DateUtils.localDateToDate(planStartDate)); | ||||
| @@ -257,13 +286,14 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { | ||||
|             sysRecipesPlan.setOrderId(sysOrder.getOrderId()); | ||||
|             sysRecipesPlan.setCusId(sysOrder.getCusId()); | ||||
|             sysRecipesPlan.setOutId(Md5Utils.hash(String.valueOf(sysOrder.getCusId()))); | ||||
|             oldStartNumDay += 1; | ||||
|             sysRecipesPlan.setStartNumDay(oldStartNumDay); | ||||
|             startNumDay += 1; | ||||
|             sysRecipesPlan.setStartNumDay(startNumDay); | ||||
|             long dayNumber = ChronoUnit.DAYS.between(planStartDate, planEndDate); | ||||
|             oldStartNumDay +=  dayNumber > 6 ? 6 : dayNumber; | ||||
|             sysRecipesPlan.setEndNumDay(oldStartNumDay); | ||||
|             startNumDay +=  dayNumber > 6 ? 6 : dayNumber; | ||||
|             sysRecipesPlan.setEndNumDay(startNumDay); | ||||
|             //添加暂停范围内的日期 | ||||
|             planList.add(sysRecipesPlan); | ||||
|             //System.out.println(DateUtils.dateTime(sysRecipesPlan.getStartDate()) + "-----" + DateUtils.dateTime(sysRecipesPlan.getEndDate())); | ||||
|         }while (breakFlag); | ||||
|         return planList; | ||||
|     } | ||||
| @@ -378,11 +408,12 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { | ||||
|  | ||||
|     /** | ||||
|      * 根据客户ID查询最后一天食谱计划 | ||||
|      * @param customerId | ||||
|      * @param customerId 客户ID | ||||
|      * @param orderId 不属于该订单ID的食谱 | ||||
|      * @return | ||||
|      */ | ||||
|     public SysRecipesPlan getLastDayRecipesPlan(Long customerId){ | ||||
|         return sysRecipesPlanMapper.getLastDayRecipesPlan(customerId); | ||||
|     public SysRecipesPlan getLastDayRecipesPlan(Long customerId, Long orderId){ | ||||
|         return sysRecipesPlanMapper.getLastDayRecipesPlan(customerId, orderId); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -372,7 +372,7 @@ | ||||
|         <!-- 非持久化字段 --> | ||||
|         <result property="afterSale" column="afterSale_name"></result><!-- 售后名称  --> | ||||
|         <result property="nutritionist" column="nutritionist_name"></result><!-- 营养师名称 --> | ||||
|         <association property="orderPauseList" column="order_id" select="getOrderPauseByOrderId"/> | ||||
|         <!--<association property="orderPauseList" column="order_id" select="getOrderPauseByOrderId"/>--> | ||||
|     </resultMap> | ||||
|  | ||||
|     <resultMap type="SysOrderPause" id="SysOrderPauseResult"> | ||||
| @@ -476,4 +476,9 @@ | ||||
|         </if> | ||||
|     </select> | ||||
|  | ||||
|     <!-- 根据客户ID查询该客户下所有订单 --> | ||||
|     <select id="getAllOrderByCusId" parameterType="Long" resultMap="SysOrderResult"> | ||||
|         select * from sys_order where del_flag = 0 and cus_id = #{cusId} order by order_id asc | ||||
|     </select> | ||||
|  | ||||
| </mapper> | ||||
| @@ -144,4 +144,18 @@ | ||||
|         where sop.del_flag = 0 and sop.order_id = #{orderId} order by sop.pause_start_date asc | ||||
|     </select> | ||||
|  | ||||
|     <!-- 根据客户ID或订单ID获取暂停记录,客户ID、订单ID不能都为空 --> | ||||
|     <select id="getPauseListByCusIdAndOrderId" parameterType="SysOrderPause" resultMap="SysOrderPauseResult"> | ||||
|         <include refid="selectSysOrderPauseVo"></include> | ||||
|         where sop.del_flag = 0 | ||||
|         <if test="cusId != null and orderId == null"> | ||||
|             and sop.cus_id = #{cusId} | ||||
|         </if> | ||||
|         <if test="cusId == null and orderId != null"> | ||||
|             and sop.order_id = #{orderId} | ||||
|         </if> | ||||
|         <if test="cusId != null and orderId != null"> | ||||
|             and (sop.cus_id = #{cusId} or sop.order_id = #{orderId}) | ||||
|         </if> | ||||
|     </select> | ||||
| </mapper> | ||||
| @@ -62,10 +62,10 @@ | ||||
|         where id = #{id} and del_flag = 0 | ||||
|     </select> | ||||
|  | ||||
|     <!-- 根据用户ID查询是否存在该用户最后一天食谱 --> | ||||
|     <!-- 根据用户ID查询是否存在该用户该订单之前的最后一条食谱 --> | ||||
|     <select id="getLastDayRecipesPlan"  resultMap="SysRecipesPlanResult" parameterType="Long"> | ||||
|         <include refid="selectSysRecipesPlanVo"/> | ||||
|         where cus_id = #{customerId} and del_flag = 0 order by end_num_day DESC limit 1 | ||||
|         where cus_id = #{customerId} and del_flag = 0 and #{orderId} > order_id order by end_num_day DESC limit 1 | ||||
|     </select> | ||||
|  | ||||
|     <insert id="insertSysRecipesPlan" parameterType="SysRecipesPlan" useGeneratedKeys="true" keyProperty="id"> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user