食谱计划页面、逻辑优化
This commit is contained in:
		@@ -21,9 +21,16 @@ public class SysRecipesPlan extends BaseEntity
 | 
			
		||||
    private Long id;
 | 
			
		||||
 | 
			
		||||
    /** 订单ID */
 | 
			
		||||
    @Excel(name = "订单ID")
 | 
			
		||||
    //@Excel(name = "订单ID")
 | 
			
		||||
    private Long orderId;
 | 
			
		||||
 | 
			
		||||
    //非持久化字段,客户姓名
 | 
			
		||||
    @Excel(name = "客户姓名")
 | 
			
		||||
    private String customer;
 | 
			
		||||
 | 
			
		||||
    //非持久化字段,客户手机号
 | 
			
		||||
    private String phone;
 | 
			
		||||
 | 
			
		||||
    /** 食谱开始日期 */
 | 
			
		||||
    @JsonFormat(pattern = "yyyy-MM-dd")
 | 
			
		||||
    @Excel(name = "食谱开始日期", width = 30, dateFormat = "yyyy-MM-dd")
 | 
			
		||||
@@ -34,12 +41,34 @@ public class SysRecipesPlan extends BaseEntity
 | 
			
		||||
    @Excel(name = "食谱结束日期", width = 30, dateFormat = "yyyy-MM-dd")
 | 
			
		||||
    private Date endDate;
 | 
			
		||||
 | 
			
		||||
    //非持久化字段,服务开始时间
 | 
			
		||||
    //@Excel(name = "服务开始时间", dateFormat = "yyyy-MM-dd")
 | 
			
		||||
    private Date orderStartDate;
 | 
			
		||||
 | 
			
		||||
    //非持久化字段,服务结束时间
 | 
			
		||||
    //@Excel(name = "服务结束时间", dateFormat = "yyyy-MM-dd")
 | 
			
		||||
    private Date orderEndDate;
 | 
			
		||||
 | 
			
		||||
    //非持久化字段,营养师ID
 | 
			
		||||
    private Long nutritionistId;
 | 
			
		||||
 | 
			
		||||
    //非持久化字段,营养师姓名
 | 
			
		||||
    @Excel(name = "营养师")
 | 
			
		||||
    private String nutritionist;
 | 
			
		||||
 | 
			
		||||
    //非持久化字段,营养师助理ID
 | 
			
		||||
    private Long nutritionistAssisId;
 | 
			
		||||
 | 
			
		||||
    //非持久化字段,营养师助理姓名
 | 
			
		||||
    @Excel(name = "营养师助理")
 | 
			
		||||
    private String nutritionistAssis;
 | 
			
		||||
 | 
			
		||||
    /** 食谱ID */
 | 
			
		||||
    @Excel(name = "食谱ID")
 | 
			
		||||
    //@Excel(name = "食谱ID")
 | 
			
		||||
    private Long recipesId;
 | 
			
		||||
 | 
			
		||||
    /** 食谱是否发送,0未发送 1已发送 */
 | 
			
		||||
    @Excel(name = "食谱是否发送,0未发送 1已发送")
 | 
			
		||||
    @Excel(name = "食谱是否发送", readConverterExp="0=未发送,1=已发送")
 | 
			
		||||
    private Integer sendFlag;
 | 
			
		||||
 | 
			
		||||
    /** 食谱发送时间 */
 | 
			
		||||
@@ -123,6 +152,70 @@ public class SysRecipesPlan extends BaseEntity
 | 
			
		||||
        return delFlag;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getCustomer() {
 | 
			
		||||
        return customer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCustomer(String customer) {
 | 
			
		||||
        this.customer = customer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Long getNutritionistId() {
 | 
			
		||||
        return nutritionistId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNutritionistId(Long nutritionistId) {
 | 
			
		||||
        this.nutritionistId = nutritionistId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getNutritionist() {
 | 
			
		||||
        return nutritionist;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNutritionist(String nutritionist) {
 | 
			
		||||
        this.nutritionist = nutritionist;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Long getNutritionistAssisId() {
 | 
			
		||||
        return nutritionistAssisId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNutritionistAssisId(Long nutritionistAssisId) {
 | 
			
		||||
        this.nutritionistAssisId = nutritionistAssisId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getNutritionistAssis() {
 | 
			
		||||
        return nutritionistAssis;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNutritionistAssis(String nutritionistAssis) {
 | 
			
		||||
        this.nutritionistAssis = nutritionistAssis;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date getOrderStartDate() {
 | 
			
		||||
        return orderStartDate;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setOrderStartDate(Date orderStartDate) {
 | 
			
		||||
        this.orderStartDate = orderStartDate;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date getOrderEndDate() {
 | 
			
		||||
        return orderEndDate;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setOrderEndDate(Date orderEndDate) {
 | 
			
		||||
        this.orderEndDate = orderEndDate;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getPhone() {
 | 
			
		||||
        return phone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPhone(String phone) {
 | 
			
		||||
        this.phone = phone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
 | 
			
		||||
 
 | 
			
		||||
@@ -70,4 +70,11 @@ public interface SysCustomerMapper
 | 
			
		||||
 | 
			
		||||
    //查询客户基础信息以及体征信息
 | 
			
		||||
    List<SysCustomer> selectSysCustomerAndSignList(SysCustomer sysCustomer);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据手机号查询客户以及体征
 | 
			
		||||
     * @param phone
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    SysCustomer selectSysCustomerAndSignByPhone(String phone);
 | 
			
		||||
}
 | 
			
		||||
@@ -66,4 +66,11 @@ public interface SysOrderPauseMapper
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    int getCountByOrderIdAndPauseDate(SysOrderPause sysOrderPause);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据订单ID删除暂停记录
 | 
			
		||||
     * @param orderIds
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    int deletePauseByOrderId(Long[] orderIds);
 | 
			
		||||
}
 | 
			
		||||
@@ -68,8 +68,15 @@ public interface SysRecipesPlanMapper
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据订单ID删除对应食谱计划
 | 
			
		||||
     * @param orderId
 | 
			
		||||
     * @param orderIds
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    int delRecipesPlanByOrderId(Long orderId);
 | 
			
		||||
    int delRecipesPlanByOrderId(Long[] orderIds);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 多条件查询食谱计划列表
 | 
			
		||||
     * @param sysRecipesPlan
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    List<SysRecipesPlan> selectPlanListByCondition(SysRecipesPlan sysRecipesPlan);
 | 
			
		||||
}
 | 
			
		||||
@@ -93,4 +93,11 @@ public interface ISysCustomerService
 | 
			
		||||
    SysCustomer getCustomerAndSignById(Long id);
 | 
			
		||||
 | 
			
		||||
    int delCustomerAndSignById(Long[] ids);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据手机号查询客户以及体征
 | 
			
		||||
     * @param phone
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    SysCustomer selectSysCustomerAndSignByPhone(String phone);
 | 
			
		||||
}
 | 
			
		||||
@@ -65,4 +65,11 @@ public interface ISysOrderPauseService
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    int getCountByOrderIdAndPauseDate(SysOrderPause sysOrderPause);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据订单ID删除暂停记录
 | 
			
		||||
     * @param orderIds
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    int deletePauseByOrderId(Long[] orderIds);
 | 
			
		||||
}
 | 
			
		||||
@@ -69,9 +69,10 @@ public interface ISysOrderService
 | 
			
		||||
    public BigDecimal selectAllOrderAmount(SysOrder sysOrder);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据订单ID更新该订单的服务到期时间
 | 
			
		||||
     * @param orderId
 | 
			
		||||
     * 根据订单ID更新该订单的服务到期时间,异步更新食谱计划
 | 
			
		||||
     * @param orderId  订单ID
 | 
			
		||||
     * @param updatePlan 是否更新食谱
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    int updateOrderServerEndDate(Long orderId);
 | 
			
		||||
    int updateOrderServerEndDate(Long orderId, boolean updatePlan);
 | 
			
		||||
}
 | 
			
		||||
@@ -61,10 +61,23 @@ public interface ISysRecipesPlanService
 | 
			
		||||
    public int deleteSysRecipesPlanById(Long id);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据订单ID生成对应的食谱计划
 | 
			
		||||
     *
 | 
			
		||||
     * 订单发生更新时(开始时间、服务时长、赠送时长),重新生成食谱计划
 | 
			
		||||
     * @param orderId 订单ID
 | 
			
		||||
     * @return 结果
 | 
			
		||||
     */
 | 
			
		||||
    public void autoGenerateRecipesPlanByOrderId(Long orderId);
 | 
			
		||||
    public void regenerateRecipesPlan(Long orderId);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据订单ID删除所有食谱安排计划
 | 
			
		||||
     * @param orderIds 订单ID
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    int delRecipesPlanByOrderId(Long[] orderIds);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 多条件查询食谱计划列表
 | 
			
		||||
     * @param sysRecipesPlan
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    List<SysRecipesPlan> selectPlanListByCondition(SysRecipesPlan sysRecipesPlan);
 | 
			
		||||
}
 | 
			
		||||
@@ -178,4 +178,14 @@ public class SysCustomerServiceImpl implements ISysCustomerService
 | 
			
		||||
        }
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据手机号查询客户以及体征
 | 
			
		||||
     * @param phone
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public SysCustomer selectSysCustomerAndSignByPhone(String phone){
 | 
			
		||||
        return sysCustomerMapper.selectSysCustomerAndSignByPhone(phone);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -7,6 +7,7 @@ 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 com.stdiet.custom.service.ISysRecipesPlanService;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import com.stdiet.custom.mapper.SysOrderPauseMapper;
 | 
			
		||||
@@ -27,9 +28,6 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private SysOrderPauseMapper sysOrderPauseMapper;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private ISysCommissionDayService sysCommissionDayService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private ISysOrderService sysOrderService;
 | 
			
		||||
 | 
			
		||||
@@ -69,7 +67,7 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService
 | 
			
		||||
        sysOrderPause.setCreateTime(DateUtils.getNowDate());
 | 
			
		||||
        if(sysOrderPauseMapper.insertSysOrderPause(sysOrderPause) > 0){
 | 
			
		||||
            //修改订单服务到期时间
 | 
			
		||||
            return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId());
 | 
			
		||||
            return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId(), true);
 | 
			
		||||
        }
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
@@ -85,7 +83,7 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService
 | 
			
		||||
    {
 | 
			
		||||
        sysOrderPause.setUpdateTime(DateUtils.getNowDate());
 | 
			
		||||
        if(sysOrderPauseMapper.updateSysOrderPause(sysOrderPause) > 0){
 | 
			
		||||
            return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId());
 | 
			
		||||
            return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId(), true);
 | 
			
		||||
        }
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
@@ -101,7 +99,7 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService
 | 
			
		||||
    {
 | 
			
		||||
        SysOrderPause sysOrderPause = selectSysOrderPauseById(ids[0]);
 | 
			
		||||
        if(sysOrderPause != null && sysOrderPauseMapper.deleteSysOrderPauseByIds(ids) > 0){
 | 
			
		||||
            return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId());
 | 
			
		||||
            return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId(), true);
 | 
			
		||||
        }
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
@@ -117,7 +115,7 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService
 | 
			
		||||
    {
 | 
			
		||||
        SysOrderPause sysOrderPause = selectSysOrderPauseById(id);
 | 
			
		||||
        if(sysOrderPause != null && sysOrderPauseMapper.deleteSysOrderPauseById(id) > 0){
 | 
			
		||||
            return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId());
 | 
			
		||||
            return sysOrderService.updateOrderServerEndDate(sysOrderPause.getOrderId(), true);
 | 
			
		||||
        }
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
@@ -127,7 +125,18 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService
 | 
			
		||||
     * @param sysOrderPause
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getCountByOrderIdAndPauseDate(SysOrderPause sysOrderPause){
 | 
			
		||||
        return sysOrderPauseMapper.getCountByOrderIdAndPauseDate(sysOrderPause);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据订单ID删除暂停记录
 | 
			
		||||
     * @param orderIds
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public int deletePauseByOrderId(Long[] orderIds){
 | 
			
		||||
        return sysOrderPauseMapper.deletePauseByOrderId(orderIds);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,16 +1,14 @@
 | 
			
		||||
package com.stdiet.custom.service.impl;
 | 
			
		||||
 | 
			
		||||
import java.math.BigDecimal;
 | 
			
		||||
import java.time.LocalDate;
 | 
			
		||||
import java.time.temporal.ChronoUnit;
 | 
			
		||||
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 com.stdiet.custom.service.ISysRecipesPlanService;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import com.stdiet.custom.mapper.SysOrderMapper;
 | 
			
		||||
@@ -33,6 +31,12 @@ public class SysOrderServiceImpl implements ISysOrderService {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private ISysCommissionDayService sysCommissionDayService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private ISysRecipesPlanService sysRecipesPlanService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private ISysOrderPauseService sysOrderPauseService;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 查询销售订单
 | 
			
		||||
     *
 | 
			
		||||
@@ -65,11 +69,16 @@ public class SysOrderServiceImpl implements ISysOrderService {
 | 
			
		||||
    public int insertSysOrder(SysOrder sysOrder) {
 | 
			
		||||
        Date orderTime = DateUtils.getNowDate();
 | 
			
		||||
        sysOrder.setCreateTime(orderTime);
 | 
			
		||||
//        sysOrder.setOrderTime(orderTime);
 | 
			
		||||
        //sysOrder.setOrderTime(orderTime);
 | 
			
		||||
        //计算服务到期时间
 | 
			
		||||
        setOrderServerEndDate(sysOrder);
 | 
			
		||||
        sysOrder.setOrderId(Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, orderTime)));
 | 
			
		||||
        return sysOrderMapper.insertSysOrder(sysOrder);
 | 
			
		||||
        int row = sysOrderMapper.insertSysOrder(sysOrder);
 | 
			
		||||
        if(row > 0){
 | 
			
		||||
            //异步生成食谱计划
 | 
			
		||||
            sysRecipesPlanService.regenerateRecipesPlan(sysOrder.getOrderId());
 | 
			
		||||
        }
 | 
			
		||||
        return row;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -80,10 +89,40 @@ public class SysOrderServiceImpl implements ISysOrderService {
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public int updateSysOrder(SysOrder sysOrder) {
 | 
			
		||||
        sysOrder.setUpdateTime(DateUtils.getNowDate());
 | 
			
		||||
        //获取旧订单对象
 | 
			
		||||
        SysOrder oldSysOrder = sysOrderMapper.selectSysOrderById(sysOrder.getOrderId());
 | 
			
		||||
        //计算服务到期时间
 | 
			
		||||
        setOrderServerEndDate(sysOrder);
 | 
			
		||||
        return sysOrderMapper.updateSysOrder(sysOrder);
 | 
			
		||||
        sysOrder.setUpdateTime(DateUtils.getNowDate());
 | 
			
		||||
        //更新订单
 | 
			
		||||
        int row = sysOrderMapper.updateSysOrder(sysOrder);
 | 
			
		||||
        if(row > 0){
 | 
			
		||||
            //异步更新食谱计划
 | 
			
		||||
            if(isNeedRegenerateRecipesPlan(oldSysOrder, sysOrder)){
 | 
			
		||||
                sysRecipesPlanService.regenerateRecipesPlan(sysOrder.getOrderId());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return row;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 判断是否需要重新生成食谱计划
 | 
			
		||||
     * @param oldSysOrder
 | 
			
		||||
     * @param newSysOrder
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    private boolean isNeedRegenerateRecipesPlan(SysOrder oldSysOrder, SysOrder newSysOrder){
 | 
			
		||||
        if(oldSysOrder.getServeTimeId() != null && newSysOrder.getServeTimeId() != null && oldSysOrder.getServeTimeId().intValue() != newSysOrder.getServeTimeId().intValue()){
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if(newSysOrder.getGiveServeDay() != null && oldSysOrder.getGiveServeDay() != null && oldSysOrder.getGiveServeDay().intValue() != newSysOrder.getGiveServeDay().intValue()){
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if(oldSysOrder.getStartTime() != null && newSysOrder.getStartTime() != null
 | 
			
		||||
                && ChronoUnit.DAYS.between(DateUtils.dateToLocalDate(oldSysOrder.getStartTime()), DateUtils.dateToLocalDate(newSysOrder.getStartTime())) != 0){
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -94,7 +133,11 @@ public class SysOrderServiceImpl implements ISysOrderService {
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public int deleteSysOrderByIds(Long[] orderIds) {
 | 
			
		||||
        return sysOrderMapper.deleteSysOrderByIds(orderIds);
 | 
			
		||||
        int row = sysOrderMapper.deleteSysOrderByIds(orderIds);
 | 
			
		||||
        if(row > 0){
 | 
			
		||||
            deletePauseAndPlan(orderIds);
 | 
			
		||||
        }
 | 
			
		||||
        return row;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -105,7 +148,13 @@ public class SysOrderServiceImpl implements ISysOrderService {
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public int deleteSysOrderById(Long orderId) {
 | 
			
		||||
        return sysOrderMapper.deleteSysOrderById(orderId);
 | 
			
		||||
        int row = sysOrderMapper.deleteSysOrderById(orderId);
 | 
			
		||||
        if(row > 0){
 | 
			
		||||
            Long[] orderIdArray = new Long[1];
 | 
			
		||||
            orderIdArray[0] = orderId;
 | 
			
		||||
            deletePauseAndPlan(orderIdArray);
 | 
			
		||||
        }
 | 
			
		||||
        return row;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -119,21 +168,27 @@ public class SysOrderServiceImpl implements ISysOrderService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据订单ID更新该订单的服务到期时间
 | 
			
		||||
     * @param orderId
 | 
			
		||||
     * 根据订单ID更新该订单的服务到期时间,异步更新食谱计划
 | 
			
		||||
     * @param orderId  订单ID
 | 
			
		||||
     * @param updatePlan 是否更新食谱
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public int updateOrderServerEndDate(Long orderId){
 | 
			
		||||
    public int updateOrderServerEndDate(Long orderId, boolean updatePlan){
 | 
			
		||||
        int row = 0;
 | 
			
		||||
        //更新订单服务到期时间
 | 
			
		||||
        SysOrder sysOrder = selectSysOrderById(orderId);
 | 
			
		||||
        if(sysOrder != null){
 | 
			
		||||
            //设置服务到期时间
 | 
			
		||||
            setOrderServerEndDate(sysOrder);
 | 
			
		||||
            sysOrder.setUpdateTime(new Date());
 | 
			
		||||
            return updateSysOrder(sysOrder);
 | 
			
		||||
            row = updateSysOrder(sysOrder);
 | 
			
		||||
            if(row > 0){
 | 
			
		||||
                //异步更新食谱计划
 | 
			
		||||
                sysRecipesPlanService.regenerateRecipesPlan(sysOrder.getOrderId());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return 0;
 | 
			
		||||
        return row;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -143,4 +198,15 @@ public class SysOrderServiceImpl implements ISysOrderService {
 | 
			
		||||
    private void setOrderServerEndDate(SysOrder sysOrder){
 | 
			
		||||
        sysOrder.setServerEndTime(DateUtils.localDateToDate(sysCommissionDayService.getServerEndDate(sysOrder)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 删除订单的同时删除暂停记录、食谱计划安排
 | 
			
		||||
     * @param orderIds 订单ID集合
 | 
			
		||||
     */
 | 
			
		||||
    private void deletePauseAndPlan(Long[] orderIds){
 | 
			
		||||
        //删除暂停记录
 | 
			
		||||
        sysOrderPauseService.deletePauseByOrderId(orderIds);
 | 
			
		||||
        //删除食谱计划
 | 
			
		||||
        sysRecipesPlanService.delRecipesPlanByOrderId(orderIds);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -91,6 +91,8 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
 | 
			
		||||
    public int updateSysRecipesPlan(SysRecipesPlan sysRecipesPlan)
 | 
			
		||||
    {
 | 
			
		||||
        sysRecipesPlan.setUpdateTime(DateUtils.getNowDate());
 | 
			
		||||
        //目前只能修改发送状态,所以修改时加上发送时间
 | 
			
		||||
        sysRecipesPlan.setSendTime(DateUtils.getNowDate());
 | 
			
		||||
        return sysRecipesPlanMapper.updateSysRecipesPlan(sysRecipesPlan);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -119,40 +121,50 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据订单ID生成对应的食谱计划
 | 
			
		||||
     * 异步方法,根据订单ID生成对应的食谱计划,退款订单不生成食谱计划
 | 
			
		||||
     *
 | 
			
		||||
     * @param orderId 订单ID
 | 
			
		||||
     * @return 结果
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    @Async("generateRecipesPlan")
 | 
			
		||||
    public void autoGenerateRecipesPlanByOrderId(Long orderId){
 | 
			
		||||
    @Async
 | 
			
		||||
    public void regenerateRecipesPlan(Long orderId){
 | 
			
		||||
        if(orderId == null || orderId <= 0){
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        SysOrder sysOrder = sysOrderService.selectSysOrderById(orderId);
 | 
			
		||||
        //订单为空、金额小于0不进行食谱生成、更新
 | 
			
		||||
        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());
 | 
			
		||||
                    }
 | 
			
		||||
                SysRecipesPlan queryParam = new SysRecipesPlan();
 | 
			
		||||
                queryParam.setOrderId(orderId);
 | 
			
		||||
                List<SysRecipesPlan> oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam);
 | 
			
		||||
                //判断是否已存在食谱
 | 
			
		||||
                if(oldRecipesPlanList != null && oldRecipesPlanList.size() > 0){
 | 
			
		||||
                    Long[] orderIdArray = new Long[1];
 | 
			
		||||
                    orderIdArray[0] = orderId;
 | 
			
		||||
                    //删除该订单对于食谱
 | 
			
		||||
                    delRecipesPlanByOrderId(orderIdArray);
 | 
			
		||||
                }
 | 
			
		||||
                //判断订单金额、开始时间、结束时间,为空则直接返回,不重新生成食谱计划
 | 
			
		||||
                if(sysOrder.getAmount().floatValue() <= 0 || sysOrder.getStartTime() == null || sysOrder.getServerEndTime() == null){
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                SysOrderPause pauseParam = new SysOrderPause();
 | 
			
		||||
                pauseParam.setOrderId(sysOrder.getOrderId());
 | 
			
		||||
                //暂停记录列表
 | 
			
		||||
                List<SysOrderPause> pauseList = sysOrderPauseService.selectSysOrderPauseList(pauseParam);
 | 
			
		||||
                List<SysRecipesPlan> planList = generatePlan(orderId, oldRecipesPlanList, 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) {
 | 
			
		||||
@@ -174,23 +186,21 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据订单ID、订单开始服务时间、结束时间、暂停列表生成食谱计划列表
 | 
			
		||||
     * @param orderId 订单ID
 | 
			
		||||
     * @param oldRecipesPlanList 旧的食谱计划
 | 
			
		||||
     * @param serverStartDate 服务开始时间
 | 
			
		||||
     * @param serverEndDate 服务结束时间
 | 
			
		||||
     * @param pauseList 暂停列表
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public List<SysRecipesPlan> generatePlan(Long orderId, LocalDate serverStartDate, LocalDate serverEndDate, List<SysOrderPause> pauseList){
 | 
			
		||||
    public List<SysRecipesPlan> generatePlan(Long orderId, List<SysRecipesPlan> oldRecipesPlanList, 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{
 | 
			
		||||
            if(ChronoUnit.DAYS.between(planEndDate, serverEndDate) <= 0){
 | 
			
		||||
                planEndDate = serverEndDate;
 | 
			
		||||
                breakFlag = true;
 | 
			
		||||
            }
 | 
			
		||||
@@ -200,6 +210,17 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
 | 
			
		||||
            sysRecipesPlan.setStartDate(DateUtils.localDateToDate(planStartDate));
 | 
			
		||||
            sysRecipesPlan.setEndDate(DateUtils.localDateToDate(planEndDate));
 | 
			
		||||
            sysRecipesPlan.setOrderId(orderId);
 | 
			
		||||
            /*//当开始时间小于等于当前时间,默认为已发送,发送时间为前一天
 | 
			
		||||
            if(ChronoUnit.DAYS.between(planStartDate, LocalDate.now()) >= 0){
 | 
			
		||||
                sysRecipesPlan.setSendFlag(1);
 | 
			
		||||
                sysRecipesPlan.setSendTime(DateUtils.localDateToDate(LocalDate.now().minusDays(1)));
 | 
			
		||||
            }*/
 | 
			
		||||
            //将旧食谱计划中的发送状态、发送时间、食谱复制到新食谱计划中
 | 
			
		||||
            boolean existFlag =oldRecipesPlanList.size() >= planList.size()+1;
 | 
			
		||||
            sysRecipesPlan.setSendFlag(existFlag ? oldRecipesPlanList.get(planList.size()).getSendFlag() : 0);
 | 
			
		||||
            sysRecipesPlan.setSendTime(existFlag ? oldRecipesPlanList.get(planList.size()).getSendTime() : null);
 | 
			
		||||
            sysRecipesPlan.setRecipesId(existFlag ? oldRecipesPlanList.get(planList.size()).getRecipesId() : null);
 | 
			
		||||
 | 
			
		||||
            planList.add(sysRecipesPlan);
 | 
			
		||||
 | 
			
		||||
            planStartDate = planEndDate.plusDays(1);
 | 
			
		||||
@@ -240,4 +261,24 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
 | 
			
		||||
        }
 | 
			
		||||
        return pauseDay;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据订单ID删除所有食谱安排计划
 | 
			
		||||
     * @param orderIds 订单ID
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public int delRecipesPlanByOrderId(Long[] orderIds){
 | 
			
		||||
        return sysRecipesPlanMapper.delRecipesPlanByOrderId(orderIds);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 多条件查询食谱计划列表
 | 
			
		||||
     * @param sysRecipesPlan
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<SysRecipesPlan> selectPlanListByCondition(SysRecipesPlan sysRecipesPlan){
 | 
			
		||||
        return sysRecipesPlanMapper.selectPlanListByCondition(sysRecipesPlan);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user