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