订单新增时选择收款账号默认选择策划运营;添加修改订单时更新服务到期时间
This commit is contained in:
		| @@ -0,0 +1,143 @@ | ||||
| package com.stdiet.custom.domain; | ||||
|  | ||||
| import java.util.Date; | ||||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||||
| import com.stdiet.common.annotation.Excel; | ||||
| import com.stdiet.common.core.domain.BaseEntity; | ||||
|  | ||||
| /** | ||||
|  * 食谱计划对象 sys_recipes_plan | ||||
|  * | ||||
|  * @author xzj | ||||
|  * @date 2021-01-15 | ||||
|  */ | ||||
| public class SysRecipesPlan extends BaseEntity | ||||
| { | ||||
|     private static final long serialVersionUID = 1L; | ||||
|  | ||||
|     /** $column.columnComment */ | ||||
|     private Long id; | ||||
|  | ||||
|     /** 订单ID */ | ||||
|     @Excel(name = "订单ID") | ||||
|     private Long orderId; | ||||
|  | ||||
|     /** 食谱开始日期 */ | ||||
|     @JsonFormat(pattern = "yyyy-MM-dd") | ||||
|     @Excel(name = "食谱开始日期", width = 30, dateFormat = "yyyy-MM-dd") | ||||
|     private Date startDate; | ||||
|  | ||||
|     /** 食谱结束日期 */ | ||||
|     @JsonFormat(pattern = "yyyy-MM-dd") | ||||
|     @Excel(name = "食谱结束日期", width = 30, dateFormat = "yyyy-MM-dd") | ||||
|     private Date endDate; | ||||
|  | ||||
|     /** 食谱ID */ | ||||
|     @Excel(name = "食谱ID") | ||||
|     private Long recipesId; | ||||
|  | ||||
|     /** 食谱是否发送,0未发送 1已发送 */ | ||||
|     @Excel(name = "食谱是否发送,0未发送 1已发送") | ||||
|     private Integer sendFlag; | ||||
|  | ||||
|     /** 食谱发送时间 */ | ||||
|     @JsonFormat(pattern = "yyyy-MM-dd") | ||||
|     @Excel(name = "食谱发送时间", width = 30, dateFormat = "yyyy-MM-dd") | ||||
|     private Date sendTime; | ||||
|  | ||||
|     /** 删除标识 0未删除 1已删除 默认0 */ | ||||
|     private Integer delFlag; | ||||
|  | ||||
|     public void setId(Long id) | ||||
|     { | ||||
|         this.id = id; | ||||
|     } | ||||
|  | ||||
|     public Long getId() | ||||
|     { | ||||
|         return id; | ||||
|     } | ||||
|     public void setOrderId(Long orderId) | ||||
|     { | ||||
|         this.orderId = orderId; | ||||
|     } | ||||
|  | ||||
|     public Long getOrderId() | ||||
|     { | ||||
|         return orderId; | ||||
|     } | ||||
|     public void setStartDate(Date startDate) | ||||
|     { | ||||
|         this.startDate = startDate; | ||||
|     } | ||||
|  | ||||
|     public Date getStartDate() | ||||
|     { | ||||
|         return startDate; | ||||
|     } | ||||
|     public void setEndDate(Date endDate) | ||||
|     { | ||||
|         this.endDate = endDate; | ||||
|     } | ||||
|  | ||||
|     public Date getEndDate() | ||||
|     { | ||||
|         return endDate; | ||||
|     } | ||||
|     public void setRecipesId(Long recipesId) | ||||
|     { | ||||
|         this.recipesId = recipesId; | ||||
|     } | ||||
|  | ||||
|     public Long getRecipesId() | ||||
|     { | ||||
|         return recipesId; | ||||
|     } | ||||
|     public void setSendFlag(Integer sendFlag) | ||||
|     { | ||||
|         this.sendFlag = sendFlag; | ||||
|     } | ||||
|  | ||||
|     public Integer getSendFlag() | ||||
|     { | ||||
|         return sendFlag; | ||||
|     } | ||||
|     public void setSendTime(Date sendTime) | ||||
|     { | ||||
|         this.sendTime = sendTime; | ||||
|     } | ||||
|  | ||||
|     public Date getSendTime() | ||||
|     { | ||||
|         return sendTime; | ||||
|     } | ||||
|     public void setDelFlag(Integer delFlag) | ||||
|     { | ||||
|         this.delFlag = delFlag; | ||||
|     } | ||||
|  | ||||
|     public Integer getDelFlag() | ||||
|     { | ||||
|         return delFlag; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | ||||
|                 .append("id", getId()) | ||||
|                 .append("orderId", getOrderId()) | ||||
|                 .append("startDate", getStartDate()) | ||||
|                 .append("endDate", getEndDate()) | ||||
|                 .append("recipesId", getRecipesId()) | ||||
|                 .append("sendFlag", getSendFlag()) | ||||
|                 .append("sendTime", getSendTime()) | ||||
|                 .append("createTime", getCreateTime()) | ||||
|                 .append("createBy", getCreateBy()) | ||||
|                 .append("updateTime", getUpdateTime()) | ||||
|                 .append("updateBy", getUpdateBy()) | ||||
|                 .append("delFlag", getDelFlag()) | ||||
|                 .toString(); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,75 @@ | ||||
| package com.stdiet.custom.mapper; | ||||
|  | ||||
| import java.util.List; | ||||
| import com.stdiet.custom.domain.SysRecipesPlan; | ||||
|  | ||||
| /** | ||||
|  * 食谱计划Mapper接口 | ||||
|  * | ||||
|  * @author xzj | ||||
|  * @date 2021-01-15 | ||||
|  */ | ||||
| public interface SysRecipesPlanMapper | ||||
| { | ||||
|     /** | ||||
|      * 查询食谱计划 | ||||
|      * | ||||
|      * @param id 食谱计划ID | ||||
|      * @return 食谱计划 | ||||
|      */ | ||||
|     public SysRecipesPlan selectSysRecipesPlanById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询食谱计划列表 | ||||
|      * | ||||
|      * @param sysRecipesPlan 食谱计划 | ||||
|      * @return 食谱计划集合 | ||||
|      */ | ||||
|     public List<SysRecipesPlan> selectSysRecipesPlanList(SysRecipesPlan sysRecipesPlan); | ||||
|  | ||||
|     /** | ||||
|      * 新增食谱计划 | ||||
|      * | ||||
|      * @param sysRecipesPlan 食谱计划 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int insertSysRecipesPlan(SysRecipesPlan sysRecipesPlan); | ||||
|  | ||||
|     /** | ||||
|      * 修改食谱计划 | ||||
|      * | ||||
|      * @param sysRecipesPlan 食谱计划 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int updateSysRecipesPlan(SysRecipesPlan sysRecipesPlan); | ||||
|  | ||||
|     /** | ||||
|      * 删除食谱计划 | ||||
|      * | ||||
|      * @param id 食谱计划ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteSysRecipesPlanById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 批量删除食谱计划 | ||||
|      * | ||||
|      * @param ids 需要删除的数据ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteSysRecipesPlanByIds(Long[] ids); | ||||
|  | ||||
|     /** | ||||
|      * 批量添加食谱计划 | ||||
|      * | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     int insertBatch(List<SysRecipesPlan> sysRecipesPlanList); | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID删除对应食谱计划 | ||||
|      * @param orderId | ||||
|      * @return | ||||
|      */ | ||||
|     int delRecipesPlanByOrderId(Long orderId); | ||||
| } | ||||
| @@ -26,10 +26,10 @@ public interface ISysCommissionDayService { | ||||
|     List<SysCommissionDayDetail> calculateCommissionByDay(SysCommision sysCommision); | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID计算该笔订单的服务到期时间 | ||||
|      * @param orderId | ||||
|      * 根据订单计算该笔订单的服务到期时间 | ||||
|      * @param sysOrder 订单对象 | ||||
|      * @return | ||||
|      */ | ||||
|     LocalDate getServerEndDate(Long orderId); | ||||
|     LocalDate getServerEndDate(SysOrder sysOrder); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package com.stdiet.custom.service; | ||||
|  | ||||
| import java.math.BigDecimal; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import com.stdiet.custom.domain.SysOrder; | ||||
|  | ||||
| @@ -66,4 +67,11 @@ public interface ISysOrderService | ||||
|      * @return | ||||
|      */ | ||||
|     public BigDecimal selectAllOrderAmount(SysOrder sysOrder); | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID更新该订单的服务到期时间 | ||||
|      * @param orderId | ||||
|      * @return | ||||
|      */ | ||||
|     int updateOrderServerEndDate(Long orderId); | ||||
| } | ||||
| @@ -0,0 +1,70 @@ | ||||
| package com.stdiet.custom.service; | ||||
|  | ||||
| import java.util.List; | ||||
| import com.stdiet.custom.domain.SysRecipesPlan; | ||||
| import org.springframework.core.annotation.Order; | ||||
|  | ||||
| /** | ||||
|  * 食谱计划Service接口 | ||||
|  * | ||||
|  * @author xzj | ||||
|  * @date 2021-01-15 | ||||
|  */ | ||||
| public interface ISysRecipesPlanService | ||||
| { | ||||
|     /** | ||||
|      * 查询食谱计划 | ||||
|      * | ||||
|      * @param id 食谱计划ID | ||||
|      * @return 食谱计划 | ||||
|      */ | ||||
|     public SysRecipesPlan selectSysRecipesPlanById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询食谱计划列表 | ||||
|      * | ||||
|      * @param sysRecipesPlan 食谱计划 | ||||
|      * @return 食谱计划集合 | ||||
|      */ | ||||
|     public List<SysRecipesPlan> selectSysRecipesPlanList(SysRecipesPlan sysRecipesPlan); | ||||
|  | ||||
|     /** | ||||
|      * 新增食谱计划 | ||||
|      * | ||||
|      * @param sysRecipesPlan 食谱计划 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int insertSysRecipesPlan(SysRecipesPlan sysRecipesPlan); | ||||
|  | ||||
|     /** | ||||
|      * 修改食谱计划 | ||||
|      * | ||||
|      * @param sysRecipesPlan 食谱计划 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int updateSysRecipesPlan(SysRecipesPlan sysRecipesPlan); | ||||
|  | ||||
|     /** | ||||
|      * 批量删除食谱计划 | ||||
|      * | ||||
|      * @param ids 需要删除的食谱计划ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteSysRecipesPlanByIds(Long[] ids); | ||||
|  | ||||
|     /** | ||||
|      * 删除食谱计划信息 | ||||
|      * | ||||
|      * @param id 食谱计划ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteSysRecipesPlanById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID生成对应的食谱计划 | ||||
|      * | ||||
|      * @param orderId 订单ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public void autoGenerateRecipesPlanByOrderId(Long orderId); | ||||
| } | ||||
| @@ -60,18 +60,43 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService { | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据订单计算该笔订单的服务到期时间 | ||||
|      * @param sysOrder 订单对象 | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public LocalDate getServerEndDate(Long orderId){ | ||||
|         SysOrder sysOrder = sysOrderMapper.selectSysOrderById(orderId); | ||||
|         if(sysOrder != null){ | ||||
|             SysOrderPause sysOrderPause = new SysOrderPause(); | ||||
|             sysOrderPause.setOrderId(orderId); | ||||
|             List<SysOrderPause> pausesList = sysOrderPauseMapper.selectSysOrderPauseList(sysOrderPause); | ||||
|             sysOrder.setOrderPauseList(pausesList); | ||||
|             SysOrderCommisionDayDetail sysOrderCommisionDayDetail = statisticsOrderMessage(sysOrder); | ||||
|             return sysOrderCommisionDayDetail.getServerEndDate(); | ||||
|     public LocalDate getServerEndDate(SysOrder sysOrder){ | ||||
|         LocalDate serverEndDate = null; | ||||
|         if(sysOrder != null && sysOrder.getStartTime() != null){ | ||||
|             //服务开始时间(客户建档时间) | ||||
|             LocalDate serverStartDate = DateUtils.dateToLocalDate(sysOrder.getStartTime()); | ||||
|             //订单总服务月数 | ||||
|             int serverMonth = sysOrder.getServeTimeId() != null ? sysOrder.getServeTimeId().intValue()/30 : 0; | ||||
|             //赠送时长 | ||||
|             int giveDay = sysOrder.getGiveServeDay() != null ? sysOrder.getGiveServeDay().intValue() : 0; | ||||
|             //服务到期时间(加赠送时间,不加暂停时间) | ||||
|             serverEndDate = serverStartDate.plusMonths(serverMonth).plusDays(giveDay); | ||||
|             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<>(); | ||||
|                 } | ||||
|             } | ||||
|             //System.out.println("结束时间:"+serverEndDate); | ||||
|             //每年每月暂停天数,key为年份加月份,如:2021年1月=20211 | ||||
|             Map<String, Integer> everyYearMonthPauseDay = getEveryYearMonthPauseDay(pausesList, serverStartDate, serverEndDate); | ||||
|             //该笔订单暂停总天数 | ||||
|             int pauseTotalDay = getTotalByMap(everyYearMonthPauseDay); | ||||
|             //System.out.println("暂停天数:"+pauseTotalDay); | ||||
|             //服务到期时间加上暂停时间 | ||||
|             serverEndDate = serverEndDate.plusDays(pauseTotalDay); | ||||
|         } | ||||
|         return null; | ||||
|         return serverEndDate; | ||||
|     } | ||||
|  | ||||
|  | ||||
| @@ -381,7 +406,7 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService { | ||||
|         boolean breakFlag = false; | ||||
|         //写100防止死循环 | ||||
|         for(int i = 0; i < 100; i++){ | ||||
|             if(ChronoUnit.DAYS.between(everyMonthLastDate, endDate) >= 0){ | ||||
|             if(ChronoUnit.DAYS.between(everyMonthLastDate, endDate) > 0){ | ||||
|                 day = Period.between(everyMonthFirstDate, everyMonthLastDate).getDays() + 1; | ||||
|             }else{ | ||||
|                 day = Period.between(everyMonthFirstDate, endDate).getDays() + 1; | ||||
|   | ||||
| @@ -4,12 +4,15 @@ import java.time.LocalDate; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import com.stdiet.common.utils.DateUtils; | ||||
| import com.stdiet.custom.domain.SysOrder; | ||||
| import com.stdiet.custom.service.ISysCommissionDayService; | ||||
| import com.stdiet.custom.service.ISysOrderService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
| import com.stdiet.custom.mapper.SysOrderPauseMapper; | ||||
| import com.stdiet.custom.domain.SysOrderPause; | ||||
| import com.stdiet.custom.service.ISysOrderPauseService; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
|  | ||||
| /** | ||||
|  * 订单服务暂停Service业务层处理 | ||||
| @@ -18,6 +21,7 @@ import com.stdiet.custom.service.ISysOrderPauseService; | ||||
|  * @date 2021-01-07 | ||||
|  */ | ||||
| @Service | ||||
| @Transactional | ||||
| public class SysOrderPauseServiceImpl implements ISysOrderPauseService | ||||
| { | ||||
|     @Autowired | ||||
| @@ -26,6 +30,9 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService | ||||
|     @Autowired | ||||
|     private ISysCommissionDayService sysCommissionDayService; | ||||
|  | ||||
|     @Autowired | ||||
|     private ISysOrderService sysOrderService; | ||||
|  | ||||
|     /** | ||||
|      * 查询订单服务暂停 | ||||
|      * | ||||
| @@ -60,7 +67,11 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService | ||||
|     public int insertSysOrderPause(SysOrderPause sysOrderPause) | ||||
|     { | ||||
|         sysOrderPause.setCreateTime(DateUtils.getNowDate()); | ||||
|         return sysOrderPauseMapper.insertSysOrderPause(sysOrderPause); | ||||
|         if(sysOrderPauseMapper.insertSysOrderPause(sysOrderPause) > 0){ | ||||
|             //修改订单服务到期时间 | ||||
|             return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId()); | ||||
|         } | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -73,7 +84,10 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService | ||||
|     public int updateSysOrderPause(SysOrderPause sysOrderPause) | ||||
|     { | ||||
|         sysOrderPause.setUpdateTime(DateUtils.getNowDate()); | ||||
|         return sysOrderPauseMapper.updateSysOrderPause(sysOrderPause); | ||||
|         if(sysOrderPauseMapper.updateSysOrderPause(sysOrderPause) > 0){ | ||||
|             return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId()); | ||||
|         } | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -85,7 +99,11 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService | ||||
|     @Override | ||||
|     public int deleteSysOrderPauseByIds(Long[] ids) | ||||
|     { | ||||
|         return sysOrderPauseMapper.deleteSysOrderPauseByIds(ids); | ||||
|         SysOrderPause sysOrderPause = selectSysOrderPauseById(ids[0]); | ||||
|         if(sysOrderPause != null && sysOrderPauseMapper.deleteSysOrderPauseByIds(ids) > 0){ | ||||
|             return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId()); | ||||
|         } | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -97,7 +115,11 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService | ||||
|     @Override | ||||
|     public int deleteSysOrderPauseById(Long id) | ||||
|     { | ||||
|         return sysOrderPauseMapper.deleteSysOrderPauseById(id); | ||||
|         SysOrderPause sysOrderPause = selectSysOrderPauseById(id); | ||||
|         if(sysOrderPause != null && sysOrderPauseMapper.deleteSysOrderPauseById(id) > 0){ | ||||
|             return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId()); | ||||
|         } | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -1,15 +1,22 @@ | ||||
| package com.stdiet.custom.service.impl; | ||||
|  | ||||
| import java.math.BigDecimal; | ||||
| import java.time.LocalDate; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
|  | ||||
| import com.stdiet.common.utils.DateUtils; | ||||
| import com.stdiet.custom.domain.SysOrderCommisionDayDetail; | ||||
| import com.stdiet.custom.domain.SysOrderPause; | ||||
| import com.stdiet.custom.service.ISysCommissionDayService; | ||||
| import com.stdiet.custom.service.ISysOrderPauseService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
| import com.stdiet.custom.mapper.SysOrderMapper; | ||||
| import com.stdiet.custom.domain.SysOrder; | ||||
| import com.stdiet.custom.service.ISysOrderService; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
|  | ||||
| /** | ||||
|  * 销售订单Service业务层处理 | ||||
| @@ -18,10 +25,14 @@ import com.stdiet.custom.service.ISysOrderService; | ||||
|  * @date 2020-09-24 | ||||
|  */ | ||||
| @Service | ||||
| @Transactional | ||||
| public class SysOrderServiceImpl implements ISysOrderService { | ||||
|     @Autowired | ||||
|     private SysOrderMapper sysOrderMapper; | ||||
|  | ||||
|     @Autowired | ||||
|     private ISysCommissionDayService sysCommissionDayService; | ||||
|  | ||||
|     /** | ||||
|      * 查询销售订单 | ||||
|      * | ||||
| @@ -55,6 +66,8 @@ public class SysOrderServiceImpl implements ISysOrderService { | ||||
|         Date orderTime = DateUtils.getNowDate(); | ||||
|         sysOrder.setCreateTime(orderTime); | ||||
| //        sysOrder.setOrderTime(orderTime); | ||||
|         //计算服务到期时间 | ||||
|         setOrderServerEndDate(sysOrder); | ||||
|         sysOrder.setOrderId(Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, orderTime))); | ||||
|         return sysOrderMapper.insertSysOrder(sysOrder); | ||||
|     } | ||||
| @@ -68,6 +81,8 @@ public class SysOrderServiceImpl implements ISysOrderService { | ||||
|     @Override | ||||
|     public int updateSysOrder(SysOrder sysOrder) { | ||||
|         sysOrder.setUpdateTime(DateUtils.getNowDate()); | ||||
|         //计算服务到期时间 | ||||
|         setOrderServerEndDate(sysOrder); | ||||
|         return sysOrderMapper.updateSysOrder(sysOrder); | ||||
|     } | ||||
|  | ||||
| @@ -102,4 +117,30 @@ public class SysOrderServiceImpl implements ISysOrderService { | ||||
|     public BigDecimal selectAllOrderAmount(SysOrder sysOrder) { | ||||
|         return sysOrderMapper.selectAllOrderAmount(sysOrder); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID更新该订单的服务到期时间 | ||||
|      * @param orderId | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public int updateOrderServerEndDate(Long orderId){ | ||||
|         //更新订单服务到期时间 | ||||
|         SysOrder sysOrder = selectSysOrderById(orderId); | ||||
|         if(sysOrder != null){ | ||||
|             //设置服务到期时间 | ||||
|             setOrderServerEndDate(sysOrder); | ||||
|             sysOrder.setUpdateTime(new Date()); | ||||
|             return updateSysOrder(sysOrder); | ||||
|         } | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 给对象SysOrder对象设置服务到期时间 | ||||
|      * @param sysOrder | ||||
|      */ | ||||
|     private void setOrderServerEndDate(SysOrder sysOrder){ | ||||
|         sysOrder.setServerEndTime(DateUtils.localDateToDate(sysCommissionDayService.getServerEndDate(sysOrder))); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,243 @@ | ||||
| package com.stdiet.custom.service.impl; | ||||
|  | ||||
| import java.time.LocalDate; | ||||
| import java.time.temporal.ChronoUnit; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import com.stdiet.common.utils.DateUtils; | ||||
| import com.stdiet.common.utils.SynchrolockUtil; | ||||
| import com.stdiet.custom.domain.SysOrder; | ||||
| import com.stdiet.custom.domain.SysOrderPause; | ||||
| import com.stdiet.custom.service.ISysOrderPauseService; | ||||
| import com.stdiet.custom.service.ISysOrderService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.data.annotation.QueryAnnotation; | ||||
| import org.springframework.scheduling.annotation.Async; | ||||
| import org.springframework.stereotype.Service; | ||||
| import com.stdiet.custom.mapper.SysRecipesPlanMapper; | ||||
| import com.stdiet.custom.domain.SysRecipesPlan; | ||||
| import com.stdiet.custom.service.ISysRecipesPlanService; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
|  | ||||
| /** | ||||
|  * 食谱计划Service业务层处理 | ||||
|  * | ||||
|  * @author xzj | ||||
|  * @date 2021-01-15 | ||||
|  */ | ||||
| @Service | ||||
| @Transactional | ||||
| public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
| { | ||||
|     @Autowired | ||||
|     private SysRecipesPlanMapper sysRecipesPlanMapper; | ||||
|  | ||||
|     @Autowired | ||||
|     private ISysOrderService sysOrderService; | ||||
|  | ||||
|     @Autowired | ||||
|     private ISysOrderPauseService sysOrderPauseService; | ||||
|  | ||||
|     @Autowired | ||||
|     private SynchrolockUtil synchrolockUtil; | ||||
|  | ||||
|     public static final String generateRecipesPlanLockKey = "generateRecipesPlanLock::%s"; | ||||
|  | ||||
|     /** | ||||
|      * 查询食谱计划 | ||||
|      * | ||||
|      * @param id 食谱计划ID | ||||
|      * @return 食谱计划 | ||||
|      */ | ||||
|     @Override | ||||
|     public SysRecipesPlan selectSysRecipesPlanById(Long id) | ||||
|     { | ||||
|         return sysRecipesPlanMapper.selectSysRecipesPlanById(id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询食谱计划列表 | ||||
|      * | ||||
|      * @param sysRecipesPlan 食谱计划 | ||||
|      * @return 食谱计划 | ||||
|      */ | ||||
|     @Override | ||||
|     public List<SysRecipesPlan> selectSysRecipesPlanList(SysRecipesPlan sysRecipesPlan) | ||||
|     { | ||||
|         return sysRecipesPlanMapper.selectSysRecipesPlanList(sysRecipesPlan); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 新增食谱计划 | ||||
|      * | ||||
|      * @param sysRecipesPlan 食谱计划 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int insertSysRecipesPlan(SysRecipesPlan sysRecipesPlan) | ||||
|     { | ||||
|         sysRecipesPlan.setCreateTime(DateUtils.getNowDate()); | ||||
|         return sysRecipesPlanMapper.insertSysRecipesPlan(sysRecipesPlan); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改食谱计划 | ||||
|      * | ||||
|      * @param sysRecipesPlan 食谱计划 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int updateSysRecipesPlan(SysRecipesPlan sysRecipesPlan) | ||||
|     { | ||||
|         sysRecipesPlan.setUpdateTime(DateUtils.getNowDate()); | ||||
|         return sysRecipesPlanMapper.updateSysRecipesPlan(sysRecipesPlan); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 批量删除食谱计划 | ||||
|      * | ||||
|      * @param ids 需要删除的食谱计划ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteSysRecipesPlanByIds(Long[] ids) | ||||
|     { | ||||
|         return sysRecipesPlanMapper.deleteSysRecipesPlanByIds(ids); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除食谱计划信息 | ||||
|      * | ||||
|      * @param id 食谱计划ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteSysRecipesPlanById(Long id) | ||||
|     { | ||||
|         return sysRecipesPlanMapper.deleteSysRecipesPlanById(id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID生成对应的食谱计划 | ||||
|      * | ||||
|      * @param orderId 订单ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     @Async("generateRecipesPlan") | ||||
|     public void autoGenerateRecipesPlanByOrderId(Long orderId){ | ||||
|         if(orderId == null || orderId <= 0){ | ||||
|             return; | ||||
|         } | ||||
|         SysOrder sysOrder = sysOrderService.selectSysOrderById(orderId); | ||||
|         if(sysOrder == null){ | ||||
|             return; | ||||
|         } | ||||
|         try{ | ||||
|             //获取redis中该订单对应的锁 | ||||
|             if(synchrolockUtil.lock(String.format(generateRecipesPlanLockKey, orderId))){ | ||||
|                 //删除该订单对于食谱 | ||||
|                 sysRecipesPlanMapper.delRecipesPlanByOrderId(orderId); | ||||
|                 //订单服务开始时间、结束时间不能为空 | ||||
|                 if(sysOrder.getStartTime() != null && sysOrder.getServerEndTime() != null){ | ||||
|                     SysOrderPause pauseParam = new SysOrderPause(); | ||||
|                     pauseParam.setOrderId(sysOrder.getOrderId()); | ||||
|                     //暂停记录列表 | ||||
|                     List<SysOrderPause> pauseList = sysOrderPauseService.selectSysOrderPauseList(pauseParam); | ||||
|                     List<SysRecipesPlan> planList = generatePlan(orderId, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList); | ||||
|                     if(planList != null && planList.size() > 0){ | ||||
|                         sysRecipesPlanMapper.insertBatch(planList); | ||||
|                     } | ||||
|                     for (SysRecipesPlan sysRecipesPlan : planList) { | ||||
|                         getTestDate(sysRecipesPlan.getStartDate(), sysRecipesPlan.getEndDate()); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|         } finally { | ||||
|             // 一定要释放锁 | ||||
|             synchrolockUtil.unlock(String.format(generateRecipesPlanLockKey, orderId)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void getTestDate(Date date, Date date2){ | ||||
|         LocalDate d = DateUtils.dateToLocalDate(date); | ||||
|         LocalDate d2 =  DateUtils.dateToLocalDate(date2); | ||||
|         String s1 = d.getYear() +"-" + d.getMonthValue() + "-" + d.getDayOfMonth(); | ||||
|         String s2 = d2.getYear() +"-" + d2.getMonthValue() + "-" + d2.getDayOfMonth(); | ||||
|         System.out.println(s1 + "   " + s2); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID、订单开始服务时间、结束时间、暂停列表生成食谱计划列表 | ||||
|      * @param orderId 订单ID | ||||
|      * @param serverStartDate 服务开始时间 | ||||
|      * @param serverEndDate 服务结束时间 | ||||
|      * @param pauseList 暂停列表 | ||||
|      * @return | ||||
|      */ | ||||
|     public List<SysRecipesPlan> generatePlan(Long orderId, LocalDate serverStartDate, LocalDate serverEndDate, List<SysOrderPause> pauseList){ | ||||
|         List<SysRecipesPlan> planList = new ArrayList<>(); | ||||
|         boolean breakFlag = false; | ||||
|         LocalDate planStartDate = serverStartDate; | ||||
|         LocalDate planEndDate = planStartDate.plusDays(6); | ||||
|         while (true){ | ||||
|  | ||||
|             SysRecipesPlan sysRecipesPlan = new SysRecipesPlan(); | ||||
|             //判断是否大于服务到期时间 | ||||
|             if(ChronoUnit.DAYS.between(planEndDate, serverEndDate) > 0){ | ||||
|  | ||||
|             }else{ | ||||
|                 planEndDate = serverEndDate; | ||||
|                 breakFlag = true; | ||||
|             } | ||||
|             long pauseDay = getPauseDayeCount(planStartDate, planEndDate, pauseList); | ||||
|             //加上暂停时间 | ||||
|             planEndDate = planEndDate.plusDays(pauseDay); | ||||
|             sysRecipesPlan.setStartDate(DateUtils.localDateToDate(planStartDate)); | ||||
|             sysRecipesPlan.setEndDate(DateUtils.localDateToDate(planEndDate)); | ||||
|             sysRecipesPlan.setOrderId(orderId); | ||||
|             planList.add(sysRecipesPlan); | ||||
|  | ||||
|             planStartDate = planEndDate.plusDays(1); | ||||
|             planEndDate = planStartDate.plusDays(6); | ||||
|  | ||||
|             if(breakFlag){ | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|         return planList; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据食谱开始时间、结束时间、暂停列表获取在食谱计划范围内的暂停天数 | ||||
|      * @param planStartDate 计划开始时间 | ||||
|      * @param planEndDate 计划结束时间 | ||||
|      * @param pauseList  暂停列表 | ||||
|      * @return | ||||
|      */ | ||||
|     public long getPauseDayeCount(LocalDate planStartDate, LocalDate planEndDate, List<SysOrderPause> pauseList){ | ||||
|         long pauseDay = 0; | ||||
|         //判断这个时间内是否存在暂停 | ||||
|         if(pauseList != null && pauseList.size() > 0){ | ||||
|             for(SysOrderPause sysOrderPause : pauseList){ | ||||
|                 LocalDate pauseStartDate = DateUtils.dateToLocalDate(sysOrderPause.getPauseStartDate()); | ||||
|                 LocalDate pauseEndDate = DateUtils.dateToLocalDate(sysOrderPause.getPauseEndDate()); | ||||
|                 if(ChronoUnit.DAYS.between(pauseEndDate, planStartDate) > 0 || ChronoUnit.DAYS.between(planEndDate, pauseStartDate) > 0){ | ||||
|                     continue; | ||||
|                 } | ||||
|                 if(ChronoUnit.DAYS.between(pauseStartDate, planStartDate) > 0){ | ||||
|                     pauseStartDate = planStartDate; | ||||
|                 } | ||||
|                 if(ChronoUnit.DAYS.between(planEndDate, pauseEndDate) > 0){ | ||||
|                     pauseEndDate = planEndDate; | ||||
|                 } | ||||
|                 pauseDay += ChronoUnit.DAYS.between(pauseStartDate, pauseEndDate); | ||||
|             } | ||||
|         } | ||||
|         return pauseDay; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,115 @@ | ||||
| <?xml version="1.0" encoding="UTF-8" ?> | ||||
| <!DOCTYPE mapper | ||||
|         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||||
|         "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
| <mapper namespace="com.stdiet.custom.mapper.SysRecipesPlanMapper"> | ||||
|  | ||||
|     <resultMap type="SysRecipesPlan" id="SysRecipesPlanResult"> | ||||
|         <result property="id"    column="id"    /> | ||||
|         <result property="orderId"    column="order_id"    /> | ||||
|         <result property="startDate"    column="start_date"    /> | ||||
|         <result property="endDate"    column="end_date"    /> | ||||
|         <result property="recipesId"    column="recipes_id"    /> | ||||
|         <result property="sendFlag"    column="send_flag"    /> | ||||
|         <result property="sendTime"    column="send_time"    /> | ||||
|         <result property="createTime"    column="create_time"    /> | ||||
|         <result property="createBy"    column="create_by"    /> | ||||
|         <result property="updateTime"    column="update_time"    /> | ||||
|         <result property="updateBy"    column="update_by"    /> | ||||
|         <result property="delFlag"    column="del_flag"    /> | ||||
|     </resultMap> | ||||
|  | ||||
|     <sql id="selectSysRecipesPlanVo"> | ||||
|         select id, order_id, start_date, end_date, recipes_id, send_flag, send_time, create_time, create_by, update_time, update_by, del_flag from sys_recipes_plan | ||||
|     </sql> | ||||
|  | ||||
|     <select id="selectSysRecipesPlanList" parameterType="SysRecipesPlan" resultMap="SysRecipesPlanResult"> | ||||
|         <include refid="selectSysRecipesPlanVo"/> where del_flag = 0 | ||||
|         <if test="orderId != null "> and order_id = #{orderId}</if> | ||||
|         <if test="startDate != null "> and start_date = #{startDate}</if> | ||||
|         <if test="endDate != null "> and end_date = #{endDate}</if> | ||||
|         <if test="recipesId != null "> and recipes_id = #{recipesId}</if> | ||||
|         <if test="sendFlag != null "> and send_flag = #{sendFlag}</if> | ||||
|         <if test="sendTime != null "> and send_time = #{sendTime}</if> | ||||
|     </select> | ||||
|  | ||||
|     <select id="selectSysRecipesPlanById" parameterType="Long" resultMap="SysRecipesPlanResult"> | ||||
|         <include refid="selectSysRecipesPlanVo"/> | ||||
|         where id = #{id} and del_flag = 0 | ||||
|     </select> | ||||
|  | ||||
|     <insert id="insertSysRecipesPlan" parameterType="SysRecipesPlan" useGeneratedKeys="true" keyProperty="id"> | ||||
|         insert into sys_recipes_plan | ||||
|         <trim prefix="(" suffix=")" suffixOverrides=","> | ||||
|             <if test="orderId != null">order_id,</if> | ||||
|             <if test="startDate != null">start_date,</if> | ||||
|             <if test="endDate != null">end_date,</if> | ||||
|             <if test="recipesId != null">recipes_id,</if> | ||||
|             <if test="sendFlag != null">send_flag,</if> | ||||
|             <if test="sendTime != null">send_time,</if> | ||||
|             <if test="createTime != null">create_time,</if> | ||||
|             <if test="createBy != null">create_by,</if> | ||||
|             <if test="updateTime != null">update_time,</if> | ||||
|             <if test="updateBy != null">update_by,</if> | ||||
|             <if test="delFlag != null">del_flag,</if> | ||||
|         </trim> | ||||
|         <trim prefix="values (" suffix=")" suffixOverrides=","> | ||||
|             <if test="orderId != null">#{orderId},</if> | ||||
|             <if test="startDate != null">#{startDate},</if> | ||||
|             <if test="endDate != null">#{endDate},</if> | ||||
|             <if test="recipesId != null">#{recipesId},</if> | ||||
|             <if test="sendFlag != null">#{sendFlag},</if> | ||||
|             <if test="sendTime != null">#{sendTime},</if> | ||||
|             <if test="createTime != null">#{createTime},</if> | ||||
|             <if test="createBy != null">#{createBy},</if> | ||||
|             <if test="updateTime != null">#{updateTime},</if> | ||||
|             <if test="updateBy != null">#{updateBy},</if> | ||||
|             <if test="delFlag != null">#{delFlag},</if> | ||||
|         </trim> | ||||
|     </insert> | ||||
|  | ||||
|     <update id="updateSysRecipesPlan" parameterType="SysRecipesPlan"> | ||||
|         update sys_recipes_plan | ||||
|         <trim prefix="SET" suffixOverrides=","> | ||||
|             <if test="orderId != null">order_id = #{orderId},</if> | ||||
|             <if test="startDate != null">start_date = #{startDate},</if> | ||||
|             <if test="endDate != null">end_date = #{endDate},</if> | ||||
|             <if test="recipesId != null">recipes_id = #{recipesId},</if> | ||||
|             <if test="sendFlag != null">send_flag = #{sendFlag},</if> | ||||
|             <if test="sendTime != null">send_time = #{sendTime},</if> | ||||
|             <if test="createTime != null">create_time = #{createTime},</if> | ||||
|             <if test="createBy != null">create_by = #{createBy},</if> | ||||
|             <if test="updateTime != null">update_time = #{updateTime},</if> | ||||
|             <if test="updateBy != null">update_by = #{updateBy},</if> | ||||
|             <if test="delFlag != null">del_flag = #{delFlag},</if> | ||||
|         </trim> | ||||
|         where id = #{id} and del_flag = 0 | ||||
|     </update> | ||||
|  | ||||
|     <delete id="deleteSysRecipesPlanById" parameterType="Long"> | ||||
|         update sys_recipes_plan set del_flag = 0 where id = #{id} | ||||
|     </delete> | ||||
|  | ||||
|     <delete id="deleteSysRecipesPlanByIds" parameterType="String"> | ||||
|         update sys_recipes_plan set del_flag = 0 where id in | ||||
|         <foreach item="id" collection="array" open="(" separator="," close=")"> | ||||
|             #{id} | ||||
|         </foreach> | ||||
|     </delete> | ||||
|  | ||||
|     <!-- 批量插入食谱计划 --> | ||||
|     <insert id="insertBatch"> | ||||
|         INSERT INTO sys_recipes_plan | ||||
|         (order_id, start_date, end_date) | ||||
|         VALUES | ||||
|         <foreach collection ="list" item="plan" separator =","> | ||||
|             (#{plan.orderId}, #{plan.startDate}, #{plan.end_date}) | ||||
|         </foreach > | ||||
|     </insert> | ||||
|  | ||||
|     <!-- 根据订单ID删除对应食谱计划 --> | ||||
|     <update id="delRecipesPlanByOrderId" parameterType="Long"> | ||||
|       update sys_recipes_plan set del_flag = 0 and order_id = #{orderId} | ||||
|     </update> | ||||
|  | ||||
| </mapper> | ||||
		Reference in New Issue
	
	Block a user