Merge remote-tracking branch 'origin/master'
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);
|
||||
}
|
||||
}
|
@ -213,4 +213,9 @@
|
||||
select * from sys_physical_signs sps where FIND_IN_SET(id, #{physical_signs_id})
|
||||
</select>
|
||||
|
||||
<!-- 根据手机号查询体征 -->
|
||||
<select id="selectSysCustomerAndSignByPhone" parameterType="String" resultMap="SysCustomerSignResult">
|
||||
<include refid="selectSysCustomerAndSign"/> where sc.del_flag = 0 and sc.phone = #{phone} limit 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -112,4 +112,12 @@
|
||||
order by id desc
|
||||
</select>
|
||||
|
||||
<!-- 根据订单ID删除暂停记录 -->
|
||||
<update id="deletePauseByOrderId" parameterType="String">
|
||||
update sys_order_pause set del_flag = 1 where order_id in
|
||||
<foreach item="orderId" collection="array" open="(" separator="," close=")">
|
||||
#{orderId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
</mapper>
|
@ -17,6 +17,15 @@
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="delFlag" column="del_flag" />
|
||||
<!-- 非持久化字段 -->
|
||||
<result property="customer" column="customer" />
|
||||
<result property="phone" column="phone" />
|
||||
<result property="orderStartDate" column="order_start_date" />
|
||||
<result property="orderEndDate" column="order_end_date" />
|
||||
<result property="nutritionistId" column="nutritionist_id" />
|
||||
<result property="nutritionist" column="nutritionist" />
|
||||
<result property="nutritionistAssisId" column="nutritionist_assis_id" />
|
||||
<result property="nutritionistAssis" column="nutritionist_assis" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysRecipesPlanVo">
|
||||
@ -87,11 +96,11 @@
|
||||
</update>
|
||||
|
||||
<delete id="deleteSysRecipesPlanById" parameterType="Long">
|
||||
update sys_recipes_plan set del_flag = 0 where id = #{id}
|
||||
update sys_recipes_plan set del_flag = 1 where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteSysRecipesPlanByIds" parameterType="String">
|
||||
update sys_recipes_plan set del_flag = 0 where id in
|
||||
update sys_recipes_plan set del_flag = 1 where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
@ -100,16 +109,34 @@
|
||||
<!-- 批量插入食谱计划 -->
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO sys_recipes_plan
|
||||
(order_id, start_date, end_date)
|
||||
(order_id, start_date, end_date, send_flag, send_time, recipes_id)
|
||||
VALUES
|
||||
<foreach collection ="list" item="plan" separator =",">
|
||||
(#{plan.orderId}, #{plan.startDate}, #{plan.end_date})
|
||||
(#{plan.orderId}, #{plan.startDate}, #{plan.endDate}, #{plan.sendFlag}, #{plan.sendTime}, #{plan.recipesId})
|
||||
</foreach >
|
||||
</insert>
|
||||
|
||||
<!-- 根据订单ID删除对应食谱计划 -->
|
||||
<update id="delRecipesPlanByOrderId" parameterType="Long">
|
||||
update sys_recipes_plan set del_flag = 0 and order_id = #{orderId}
|
||||
<update id="delRecipesPlanByOrderId" parameterType="String">
|
||||
update sys_recipes_plan set del_flag = 1 where order_id in
|
||||
<foreach item="orderId" collection="array" open="(" separator="," close=")">
|
||||
#{orderId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 食谱计划、订单表联查 -->
|
||||
<select id="selectPlanListByCondition" parameterType="SysRecipesPlan" resultMap="SysRecipesPlanResult">
|
||||
SELECT srp.id,srp.order_id,sr.customer,sr.phone,su_nutritionist.nick_name nutritionist,su_nutritionist_assis.nick_name AS nutritionist_assis,sr.start_time,sr.server_end_time, srp.start_date,srp.end_date,srp.send_flag,srp.send_time
|
||||
FROM sys_recipes_plan srp
|
||||
LEFT JOIN sys_order sr ON sr.order_id = srp.order_id
|
||||
LEFT JOIN sys_user su_nutritionist ON su_nutritionist.user_id = sr.nutritionist_id AND su_nutritionist.del_flag = 0
|
||||
LEFT JOIN sys_user su_nutritionist_assis ON su_nutritionist_assis.user_id = sr.nutri_assis_id AND su_nutritionist_assis.del_flag = 0
|
||||
WHERE srp.del_flag = 0
|
||||
<if test="orderId != null">AND srp.order_id = #{orderId}</if>
|
||||
<if test="customer != null and customer != ''">AND sr.customer like concat('%',#{customer},'%')</if>
|
||||
<if test="nutritionistId != null">AND su_nutritionist.user_id = #{nutritionistId}</if>
|
||||
<if test="nutritionistAssisId != null">AND su_nutritionist_assis.user_id = #{nutritionistAssisId}</if>
|
||||
<if test="startDate != null and endDate != null ">AND srp.start_date BETWEEN date_format(#{startDate},'%y%m%d') AND date_format(#{endDate},'%y%m%d') </if>
|
||||
ORDER BY srp.order_id DESC,srp.id ASC
|
||||
</select>
|
||||
</mapper>
|
Reference in New Issue
Block a user