修复未生成食谱逻辑错误
This commit is contained in:
parent
81ce32847a
commit
666cb34d2a
@ -1,24 +1,24 @@
|
|||||||
package com.stdiet.custom.service.impl;
|
package com.stdiet.custom.service.impl;
|
||||||
|
|
||||||
|
import com.stdiet.common.utils.DateUtils;
|
||||||
|
import com.stdiet.common.utils.SynchrolockUtil;
|
||||||
|
import com.stdiet.custom.domain.SysOrder;
|
||||||
|
import com.stdiet.custom.domain.SysOrderPause;
|
||||||
|
import com.stdiet.custom.domain.SysRecipesPlan;
|
||||||
|
import com.stdiet.custom.mapper.SysRecipesPlanMapper;
|
||||||
|
import com.stdiet.custom.service.ISysOrderPauseService;
|
||||||
|
import com.stdiet.custom.service.ISysOrderService;
|
||||||
|
import com.stdiet.custom.service.ISysRecipesPlanService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.stdiet.common.utils.DateUtils;
|
|
||||||
import com.stdiet.common.utils.SynchrolockUtil;
|
|
||||||
import com.stdiet.custom.domain.SysOrder;
|
|
||||||
import com.stdiet.custom.domain.SysOrderPause;
|
|
||||||
import com.stdiet.custom.service.ISysOrderPauseService;
|
|
||||||
import com.stdiet.custom.service.ISysOrderService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.annotation.QueryAnnotation;
|
|
||||||
import org.springframework.scheduling.annotation.Async;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import com.stdiet.custom.mapper.SysRecipesPlanMapper;
|
|
||||||
import com.stdiet.custom.domain.SysRecipesPlan;
|
|
||||||
import com.stdiet.custom.service.ISysRecipesPlanService;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 食谱计划Service业务层处理
|
* 食谱计划Service业务层处理
|
||||||
@ -28,22 +28,17 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
*/
|
*/
|
||||||
@Service("sysRecipesPlanService")
|
@Service("sysRecipesPlanService")
|
||||||
@Transactional
|
@Transactional
|
||||||
public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||||
{
|
public static final String generateRecipesPlanLockKey = "generateRecipesPlanLock::%s";
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysRecipesPlanMapper sysRecipesPlanMapper;
|
private SysRecipesPlanMapper sysRecipesPlanMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysOrderService sysOrderService;
|
private ISysOrderService sysOrderService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysOrderPauseService sysOrderPauseService;
|
private ISysOrderPauseService sysOrderPauseService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SynchrolockUtil synchrolockUtil;
|
private SynchrolockUtil synchrolockUtil;
|
||||||
|
|
||||||
public static final String generateRecipesPlanLockKey = "generateRecipesPlanLock::%s";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询食谱计划
|
* 查询食谱计划
|
||||||
*
|
*
|
||||||
@ -51,8 +46,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
* @return 食谱计划
|
* @return 食谱计划
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SysRecipesPlan selectSysRecipesPlanById(Long id)
|
public SysRecipesPlan selectSysRecipesPlanById(Long id) {
|
||||||
{
|
|
||||||
return sysRecipesPlanMapper.selectSysRecipesPlanById(id);
|
return sysRecipesPlanMapper.selectSysRecipesPlanById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +57,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
* @return 食谱计划
|
* @return 食谱计划
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysRecipesPlan> selectSysRecipesPlanList(SysRecipesPlan sysRecipesPlan)
|
public List<SysRecipesPlan> selectSysRecipesPlanList(SysRecipesPlan sysRecipesPlan) {
|
||||||
{
|
|
||||||
return sysRecipesPlanMapper.selectSysRecipesPlanList(sysRecipesPlan);
|
return sysRecipesPlanMapper.selectSysRecipesPlanList(sysRecipesPlan);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,8 +68,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int insertSysRecipesPlan(SysRecipesPlan sysRecipesPlan)
|
public int insertSysRecipesPlan(SysRecipesPlan sysRecipesPlan) {
|
||||||
{
|
|
||||||
sysRecipesPlan.setCreateTime(DateUtils.getNowDate());
|
sysRecipesPlan.setCreateTime(DateUtils.getNowDate());
|
||||||
return sysRecipesPlanMapper.insertSysRecipesPlan(sysRecipesPlan);
|
return sysRecipesPlanMapper.insertSysRecipesPlan(sysRecipesPlan);
|
||||||
}
|
}
|
||||||
@ -88,8 +80,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int updateSysRecipesPlan(SysRecipesPlan sysRecipesPlan)
|
public int updateSysRecipesPlan(SysRecipesPlan sysRecipesPlan) {
|
||||||
{
|
|
||||||
sysRecipesPlan.setUpdateTime(DateUtils.getNowDate());
|
sysRecipesPlan.setUpdateTime(DateUtils.getNowDate());
|
||||||
//目前只能修改发送状态,所以修改时加上发送时间
|
//目前只能修改发送状态,所以修改时加上发送时间
|
||||||
sysRecipesPlan.setSendTime(DateUtils.getNowDate());
|
sysRecipesPlan.setSendTime(DateUtils.getNowDate());
|
||||||
@ -103,8 +94,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int deleteSysRecipesPlanByIds(Long[] ids)
|
public int deleteSysRecipesPlanByIds(Long[] ids) {
|
||||||
{
|
|
||||||
return sysRecipesPlanMapper.deleteSysRecipesPlanByIds(ids);
|
return sysRecipesPlanMapper.deleteSysRecipesPlanByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,8 +105,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int deleteSysRecipesPlanById(Long id)
|
public int deleteSysRecipesPlanById(Long id) {
|
||||||
{
|
|
||||||
return sysRecipesPlanMapper.deleteSysRecipesPlanById(id);
|
return sysRecipesPlanMapper.deleteSysRecipesPlanById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,47 +117,47 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Async
|
@Async
|
||||||
public void regenerateRecipesPlan(Long orderId){
|
public void regenerateRecipesPlan(Long orderId) {
|
||||||
if(orderId == null || orderId <= 0){
|
if (orderId == null || orderId <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SysOrder sysOrder = sysOrderService.selectSysOrderById(orderId);
|
SysOrder sysOrder = sysOrderService.selectSysOrderById(orderId);
|
||||||
//订单为空、金额小于0不进行食谱生成、更新,只对2021年开始的订单进行食谱计划生成
|
//订单为空、金额小于0不进行食谱生成、更新,只对2021年开始的订单进行食谱计划生成
|
||||||
if(sysOrder == null && DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear() < 2021){
|
if (sysOrder == null && DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear() < 2021) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.println(DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear());
|
// System.out.println(DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear());
|
||||||
try{
|
try {
|
||||||
//获取redis中该订单对应的锁
|
//获取redis中该订单对应的锁
|
||||||
if(synchrolockUtil.lock(String.format(generateRecipesPlanLockKey, orderId))){
|
if (synchrolockUtil.lock(String.format(generateRecipesPlanLockKey, orderId))) {
|
||||||
SysRecipesPlan queryParam = new SysRecipesPlan();
|
SysRecipesPlan queryParam = new SysRecipesPlan();
|
||||||
queryParam.setOrderId(orderId);
|
queryParam.setOrderId(orderId);
|
||||||
List<SysRecipesPlan> oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam);
|
List<SysRecipesPlan> oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam);
|
||||||
//判断是否已存在食谱
|
//判断是否已存在食谱
|
||||||
if(oldRecipesPlanList != null && oldRecipesPlanList.size() > 0){
|
if (oldRecipesPlanList != null && oldRecipesPlanList.size() > 0) {
|
||||||
Long[] orderIdArray = new Long[1];
|
Long[] orderIdArray = new Long[1];
|
||||||
orderIdArray[0] = orderId;
|
orderIdArray[0] = orderId;
|
||||||
//删除该订单对于食谱
|
//删除该订单对于食谱
|
||||||
delRecipesPlanByOrderId(orderIdArray);
|
delRecipesPlanByOrderId(orderIdArray);
|
||||||
}
|
}
|
||||||
//判断订单金额、开始时间、结束时间,为空则直接返回,不重新生成食谱计划
|
//判断订单金额、开始时间、结束时间,为空则直接返回,不重新生成食谱计划
|
||||||
if(sysOrder.getAmount().floatValue() <= 0 || sysOrder.getStartTime() == null || sysOrder.getServerEndTime() == null){
|
if (sysOrder.getAmount().floatValue() <= 0 || sysOrder.getStartTime() == null || sysOrder.getServerEndTime() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SysOrderPause pauseParam = new SysOrderPause();
|
SysOrderPause pauseParam = new SysOrderPause();
|
||||||
pauseParam.setOrderId(sysOrder.getOrderId());
|
pauseParam.setOrderId(sysOrder.getOrderId());
|
||||||
//暂停记录列表
|
//暂停记录列表
|
||||||
List<SysOrderPause> pauseList = sysOrderPauseService.selectSysOrderPauseList(pauseParam);
|
List<SysOrderPause> pauseList = sysOrderPauseService.selectSysOrderPauseList(pauseParam);
|
||||||
List<SysRecipesPlan> planList = generatePlan(orderId, oldRecipesPlanList, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList);
|
List<SysRecipesPlan> planList = generatePlan(sysOrder, oldRecipesPlanList,
|
||||||
if(planList != null && planList.size() > 0){
|
DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList);
|
||||||
|
if (planList != null && planList.size() > 0) {
|
||||||
sysRecipesPlanMapper.insertBatch(planList);
|
sysRecipesPlanMapper.insertBatch(planList);
|
||||||
}
|
}
|
||||||
/*for (SysRecipesPlan sysRecipesPlan : planList) {
|
/*for (SysRecipesPlan sysRecipesPlan : planList) {
|
||||||
getTestDate(sysRecipesPlan.getStartDate(), sysRecipesPlan.getEndDate());
|
getTestDate(sysRecipesPlan.getStartDate(), sysRecipesPlan.getEndDate());
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
// 一定要释放锁
|
// 一定要释放锁
|
||||||
@ -176,32 +165,34 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getTestDate(Date date, Date date2){
|
public void getTestDate(Date date, Date date2) {
|
||||||
LocalDate d = DateUtils.dateToLocalDate(date);
|
LocalDate d = DateUtils.dateToLocalDate(date);
|
||||||
LocalDate d2 = DateUtils.dateToLocalDate(date2);
|
LocalDate d2 = DateUtils.dateToLocalDate(date2);
|
||||||
String s1 = d.getYear() +"-" + d.getMonthValue() + "-" + d.getDayOfMonth();
|
String s1 = d.getYear() + "-" + d.getMonthValue() + "-" + d.getDayOfMonth();
|
||||||
String s2 = d2.getYear() +"-" + d2.getMonthValue() + "-" + d2.getDayOfMonth();
|
String s2 = d2.getYear() + "-" + d2.getMonthValue() + "-" + d2.getDayOfMonth();
|
||||||
System.out.println(s1 + " " + s2);
|
System.out.println(s1 + " " + s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据订单ID、订单开始服务时间、结束时间、暂停列表生成食谱计划列表
|
* 根据订单ID、订单开始服务时间、结束时间、暂停列表生成食谱计划列表
|
||||||
* @param orderId 订单ID
|
*
|
||||||
|
* @param sysOrder 订单对象
|
||||||
* @param oldRecipesPlanList 旧的食谱计划
|
* @param oldRecipesPlanList 旧的食谱计划
|
||||||
* @param serverStartDate 服务开始时间
|
* @param serverStartDate 服务开始时间
|
||||||
* @param serverEndDate 服务结束时间
|
* @param serverEndDate 服务结束时间
|
||||||
* @param pauseList 暂停列表
|
* @param pauseList 暂停列表
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<SysRecipesPlan> generatePlan(Long orderId, List<SysRecipesPlan> oldRecipesPlanList, LocalDate serverStartDate, LocalDate serverEndDate, List<SysOrderPause> pauseList){
|
public List<SysRecipesPlan> generatePlan(SysOrder sysOrder, List<SysRecipesPlan> oldRecipesPlanList,
|
||||||
|
LocalDate serverStartDate, LocalDate serverEndDate, List<SysOrderPause> pauseList) {
|
||||||
List<SysRecipesPlan> planList = new ArrayList<>();
|
List<SysRecipesPlan> planList = new ArrayList<>();
|
||||||
boolean breakFlag = false;
|
boolean breakFlag = false;
|
||||||
LocalDate planStartDate = serverStartDate;
|
LocalDate planStartDate = serverStartDate;
|
||||||
LocalDate planEndDate = planStartDate.plusDays(6);
|
LocalDate planEndDate = planStartDate.plusDays(6);
|
||||||
while (true){
|
while (true) {
|
||||||
SysRecipesPlan sysRecipesPlan = new SysRecipesPlan();
|
SysRecipesPlan sysRecipesPlan = new SysRecipesPlan();
|
||||||
//判断是否大于服务到期时间
|
//判断是否大于服务到期时间
|
||||||
if(ChronoUnit.DAYS.between(planEndDate, serverEndDate) <= 0){
|
if (ChronoUnit.DAYS.between(planEndDate, serverEndDate) <= 0) {
|
||||||
planEndDate = serverEndDate;
|
planEndDate = serverEndDate;
|
||||||
breakFlag = true;
|
breakFlag = true;
|
||||||
}
|
}
|
||||||
@ -210,14 +201,15 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
planEndDate = planEndDate.plusDays(pauseDay);
|
planEndDate = planEndDate.plusDays(pauseDay);
|
||||||
sysRecipesPlan.setStartDate(DateUtils.localDateToDate(planStartDate));
|
sysRecipesPlan.setStartDate(DateUtils.localDateToDate(planStartDate));
|
||||||
sysRecipesPlan.setEndDate(DateUtils.localDateToDate(planEndDate));
|
sysRecipesPlan.setEndDate(DateUtils.localDateToDate(planEndDate));
|
||||||
sysRecipesPlan.setOrderId(orderId);
|
sysRecipesPlan.setOrderId(sysOrder.getOrderId());
|
||||||
|
sysRecipesPlan.setCusId(sysOrder.getCusId());
|
||||||
/*//当开始时间小于等于当前时间,默认为已发送,发送时间为前一天
|
/*//当开始时间小于等于当前时间,默认为已发送,发送时间为前一天
|
||||||
if(ChronoUnit.DAYS.between(planStartDate, LocalDate.now()) >= 0){
|
if(ChronoUnit.DAYS.between(planStartDate, LocalDate.now()) >= 0){
|
||||||
sysRecipesPlan.setSendFlag(1);
|
sysRecipesPlan.setSendFlag(1);
|
||||||
sysRecipesPlan.setSendTime(DateUtils.localDateToDate(LocalDate.now().minusDays(1)));
|
sysRecipesPlan.setSendTime(DateUtils.localDateToDate(LocalDate.now().minusDays(1)));
|
||||||
}*/
|
}*/
|
||||||
//将旧食谱计划中的发送状态、发送时间、食谱复制到新食谱计划中
|
//将旧食谱计划中的发送状态、发送时间、食谱复制到新食谱计划中
|
||||||
boolean existFlag =oldRecipesPlanList.size() >= planList.size()+1;
|
boolean existFlag = oldRecipesPlanList.size() >= planList.size() + 1;
|
||||||
sysRecipesPlan.setSendFlag(existFlag ? oldRecipesPlanList.get(planList.size()).getSendFlag() : 0);
|
sysRecipesPlan.setSendFlag(existFlag ? oldRecipesPlanList.get(planList.size()).getSendFlag() : 0);
|
||||||
sysRecipesPlan.setSendTime(existFlag ? oldRecipesPlanList.get(planList.size()).getSendTime() : null);
|
sysRecipesPlan.setSendTime(existFlag ? oldRecipesPlanList.get(planList.size()).getSendTime() : null);
|
||||||
sysRecipesPlan.setRecipesId(existFlag ? oldRecipesPlanList.get(planList.size()).getRecipesId() : null);
|
sysRecipesPlan.setRecipesId(existFlag ? oldRecipesPlanList.get(planList.size()).getRecipesId() : null);
|
||||||
@ -227,7 +219,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
planStartDate = planEndDate.plusDays(1);
|
planStartDate = planEndDate.plusDays(1);
|
||||||
planEndDate = planStartDate.plusDays(6);
|
planEndDate = planStartDate.plusDays(6);
|
||||||
|
|
||||||
if(breakFlag){
|
if (breakFlag) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,25 +228,26 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据食谱开始时间、结束时间、暂停列表获取在食谱计划范围内的暂停天数
|
* 根据食谱开始时间、结束时间、暂停列表获取在食谱计划范围内的暂停天数
|
||||||
|
*
|
||||||
* @param planStartDate 计划开始时间
|
* @param planStartDate 计划开始时间
|
||||||
* @param planEndDate 计划结束时间
|
* @param planEndDate 计划结束时间
|
||||||
* @param pauseList 暂停列表
|
* @param pauseList 暂停列表
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public long getPauseDayeCount(LocalDate planStartDate, LocalDate planEndDate, List<SysOrderPause> pauseList){
|
public long getPauseDayeCount(LocalDate planStartDate, LocalDate planEndDate, List<SysOrderPause> pauseList) {
|
||||||
long pauseDay = 0;
|
long pauseDay = 0;
|
||||||
//判断这个时间内是否存在暂停
|
//判断这个时间内是否存在暂停
|
||||||
if(pauseList != null && pauseList.size() > 0){
|
if (pauseList != null && pauseList.size() > 0) {
|
||||||
for(SysOrderPause sysOrderPause : pauseList){
|
for (SysOrderPause sysOrderPause : pauseList) {
|
||||||
LocalDate pauseStartDate = DateUtils.dateToLocalDate(sysOrderPause.getPauseStartDate());
|
LocalDate pauseStartDate = DateUtils.dateToLocalDate(sysOrderPause.getPauseStartDate());
|
||||||
LocalDate pauseEndDate = DateUtils.dateToLocalDate(sysOrderPause.getPauseEndDate());
|
LocalDate pauseEndDate = DateUtils.dateToLocalDate(sysOrderPause.getPauseEndDate());
|
||||||
if(ChronoUnit.DAYS.between(pauseEndDate, planStartDate) > 0 || ChronoUnit.DAYS.between(planEndDate, pauseStartDate) > 0){
|
if (ChronoUnit.DAYS.between(pauseEndDate, planStartDate) > 0 || ChronoUnit.DAYS.between(planEndDate, pauseStartDate) > 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(ChronoUnit.DAYS.between(pauseStartDate, planStartDate) > 0){
|
if (ChronoUnit.DAYS.between(pauseStartDate, planStartDate) > 0) {
|
||||||
pauseStartDate = planStartDate;
|
pauseStartDate = planStartDate;
|
||||||
}
|
}
|
||||||
if(ChronoUnit.DAYS.between(planEndDate, pauseEndDate) > 0){
|
if (ChronoUnit.DAYS.between(planEndDate, pauseEndDate) > 0) {
|
||||||
pauseEndDate = planEndDate;
|
pauseEndDate = planEndDate;
|
||||||
}
|
}
|
||||||
pauseDay += ChronoUnit.DAYS.between(pauseStartDate, pauseEndDate);
|
pauseDay += ChronoUnit.DAYS.between(pauseStartDate, pauseEndDate);
|
||||||
@ -265,31 +258,34 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据订单ID删除所有食谱安排计划
|
* 根据订单ID删除所有食谱安排计划
|
||||||
|
*
|
||||||
* @param orderIds 订单ID
|
* @param orderIds 订单ID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int delRecipesPlanByOrderId(Long[] orderIds){
|
public int delRecipesPlanByOrderId(Long[] orderIds) {
|
||||||
return sysRecipesPlanMapper.delRecipesPlanByOrderId(orderIds);
|
return sysRecipesPlanMapper.delRecipesPlanByOrderId(orderIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 多条件查询食谱计划列表
|
* 多条件查询食谱计划列表
|
||||||
|
*
|
||||||
* @param sysRecipesPlan
|
* @param sysRecipesPlan
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysRecipesPlan> selectPlanListByCondition(SysRecipesPlan sysRecipesPlan){
|
public List<SysRecipesPlan> selectPlanListByCondition(SysRecipesPlan sysRecipesPlan) {
|
||||||
return sysRecipesPlanMapper.selectPlanListByCondition(sysRecipesPlan);
|
return sysRecipesPlanMapper.selectPlanListByCondition(sysRecipesPlan);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据订单ID查询食谱计划
|
* 根据订单ID查询食谱计划
|
||||||
|
*
|
||||||
* @param sysRecipesPlan
|
* @param sysRecipesPlan
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysRecipesPlan> selectPlanListByOrderId(SysRecipesPlan sysRecipesPlan){
|
public List<SysRecipesPlan> selectPlanListByOrderId(SysRecipesPlan sysRecipesPlan) {
|
||||||
return sysRecipesPlanMapper.selectPlanListByOrderId(sysRecipesPlan);
|
return sysRecipesPlanMapper.selectPlanListByOrderId(sysRecipesPlan);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,7 +5,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
import { createNamespacedHelpers } from "vuex";
|
||||||
name: 'App'
|
const { mapActions } = createNamespacedHelpers("global");
|
||||||
}
|
export default {
|
||||||
|
name: "App",
|
||||||
|
created() {
|
||||||
|
this.init();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions(["init"]),
|
||||||
|
},
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -6,6 +6,7 @@ import tagsView from "./modules/tagsView";
|
|||||||
import permission from "./modules/permission";
|
import permission from "./modules/permission";
|
||||||
import settings from "./modules/settings";
|
import settings from "./modules/settings";
|
||||||
import recipes from "./modules/recipes";
|
import recipes from "./modules/recipes";
|
||||||
|
import global from "./modules/global";
|
||||||
|
|
||||||
import getters from "./getters";
|
import getters from "./getters";
|
||||||
|
|
||||||
@ -18,7 +19,8 @@ const store = new Vuex.Store({
|
|||||||
tagsView,
|
tagsView,
|
||||||
permission,
|
permission,
|
||||||
settings,
|
settings,
|
||||||
recipes
|
recipes,
|
||||||
|
global
|
||||||
},
|
},
|
||||||
getters
|
getters
|
||||||
});
|
});
|
||||||
|
62
stdiet-ui/src/store/modules/global.js
Normal file
62
stdiet-ui/src/store/modules/global.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import { getOptions } from "@/api/custom/order";
|
||||||
|
|
||||||
|
const oriState = {
|
||||||
|
nutritionistIdOptions: [],
|
||||||
|
nutriAssisIdOptions: [],
|
||||||
|
preSaleIdOptions: [],
|
||||||
|
afterSaleIdOptions: [],
|
||||||
|
plannerIdOptions: [],
|
||||||
|
plannerAssisIdOptions: [],
|
||||||
|
operatorIdOptions: [],
|
||||||
|
operatorAssisIdOptions: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const mutations = {
|
||||||
|
save(state, payload) {
|
||||||
|
Object.keys(payload).forEach(key => {
|
||||||
|
state[key] = payload[key];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
clean(state) {
|
||||||
|
Object.keys(oriState).forEach(key => {
|
||||||
|
state[key] = oriState[key];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const actions = {
|
||||||
|
async init({ commit }, payload) {
|
||||||
|
const { data: optionsData } = await getOptions();
|
||||||
|
const options = optionsData.reduce((opts, cur) => {
|
||||||
|
if (!opts[cur.postCode]) {
|
||||||
|
opts[cur.postCode] = [
|
||||||
|
// { dictValue: null, dictLabel: "全部", remark: null }
|
||||||
|
];
|
||||||
|
}
|
||||||
|
opts[cur.postCode].push({
|
||||||
|
dictValue: cur.userId,
|
||||||
|
dictLabel: cur.userName,
|
||||||
|
remark: cur.remark
|
||||||
|
});
|
||||||
|
return opts;
|
||||||
|
}, {});
|
||||||
|
commit("save", {
|
||||||
|
nutritionistIdOptions: options["nutri"] || [],
|
||||||
|
nutriAssisIdOptions: options["nutri_assis"] || [],
|
||||||
|
preSaleIdOptions: options["pre_sale"] || [],
|
||||||
|
afterSaleIdOptions: options["after_sale"] || [],
|
||||||
|
plannerIdOptions: options["planner"] || [],
|
||||||
|
plannerAssisIdOptions: options["planner_assis"] || [],
|
||||||
|
operatorIdOptions: options["operator"] || [],
|
||||||
|
operatorAssisIdOptions: options["operator_assis"] || []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const getters = {};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespaced: true,
|
||||||
|
state: Object.assign({}, oriState),
|
||||||
|
mutations,
|
||||||
|
actions,
|
||||||
|
getters
|
||||||
|
};
|
@ -1,4 +1,3 @@
|
|||||||
import { getOrder } from "@/api/custom/order";
|
|
||||||
import { getCustomerPhysicalSignsByCusId } from "@/api/custom/customer";
|
import { getCustomerPhysicalSignsByCusId } from "@/api/custom/customer";
|
||||||
import { dealHealthy } from "@/utils/healthyData";
|
import { dealHealthy } from "@/utils/healthyData";
|
||||||
import {
|
import {
|
||||||
@ -54,7 +53,7 @@ const mutations = {
|
|||||||
// console.log(payload);
|
// console.log(payload);
|
||||||
state.recipesData[payload.num].dishes = state.recipesData[
|
state.recipesData[payload.num].dishes = state.recipesData[
|
||||||
payload.num
|
payload.num
|
||||||
].dishes.filter(obj => obj.id !== payload.dishesId);
|
].dishes.filter(obj => obj.id !== payload.id);
|
||||||
},
|
},
|
||||||
updateStateData(state, payload) {
|
updateStateData(state, payload) {
|
||||||
Object.keys(payload).forEach(key => {
|
Object.keys(payload).forEach(key => {
|
||||||
@ -92,7 +91,7 @@ const actions = {
|
|||||||
commit("updateStateData", { dishesTypeOptions: response.data });
|
commit("updateStateData", { dishesTypeOptions: response.data });
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
// 健康数据
|
||||||
if (payload.cusId) {
|
if (payload.cusId) {
|
||||||
dispatch("getHealthyData", payload);
|
dispatch("getHealthyData", payload);
|
||||||
}
|
}
|
||||||
@ -104,7 +103,6 @@ const actions = {
|
|||||||
},
|
},
|
||||||
async getHealthyData({ commit }, payload) {
|
async getHealthyData({ commit }, payload) {
|
||||||
commit("updateStateData", { healthDataLoading: true });
|
commit("updateStateData", { healthDataLoading: true });
|
||||||
// 健康数据
|
|
||||||
const healthyDataResult = await getCustomerPhysicalSignsByCusId(
|
const healthyDataResult = await getCustomerPhysicalSignsByCusId(
|
||||||
payload.cusId
|
payload.cusId
|
||||||
);
|
);
|
||||||
@ -211,7 +209,9 @@ const actions = {
|
|||||||
};
|
};
|
||||||
const result = await addRecipesApi(params);
|
const result = await addRecipesApi(params);
|
||||||
if (result.code === 200) {
|
if (result.code === 200) {
|
||||||
dispatch("getRecipesInfo", { recipesId: result.data });
|
const recipesId = result.data;
|
||||||
|
commit("updateStateData", { recipesId });
|
||||||
|
dispatch("getRecipesInfo", { recipesId });
|
||||||
}
|
}
|
||||||
// console.log(params);
|
// console.log(params);
|
||||||
},
|
},
|
||||||
@ -238,10 +238,10 @@ const actions = {
|
|||||||
payload.data.id = result.data;
|
payload.data.id = result.data;
|
||||||
commit("addRecipesDishes", payload);
|
commit("addRecipesDishes", payload);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
commit("addRecipesDishes", payload);
|
|
||||||
}
|
}
|
||||||
// console.log(result);
|
// console.log(result);
|
||||||
|
} else {
|
||||||
|
commit("addRecipesDishes", payload);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async updateDishes({ commit, state }, payload) {
|
async updateDishes({ commit, state }, payload) {
|
||||||
|
@ -43,11 +43,11 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
prop="proteinRatio"
|
prop="proteinRatio"
|
||||||
label="蛋白质/100g"
|
label="P/100g"
|
||||||
align="center"
|
align="center"
|
||||||
/>
|
/>
|
||||||
<el-table-column prop="fatRatio" label="脂肪/100g" align="center" />
|
<el-table-column prop="fatRatio" label="F/100g" align="center" />
|
||||||
<el-table-column prop="carbonRatio" label="碳水/100g" align="center" />
|
<el-table-column prop="carbonRatio" label="C/100g" align="center" />
|
||||||
</el-table>
|
</el-table>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="推荐人群">
|
<el-form-item label="推荐人群">
|
||||||
|
@ -92,7 +92,7 @@ export default {
|
|||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(data);
|
// console.log(data);
|
||||||
this.selDishes = data;
|
this.selDishes = data;
|
||||||
this.active = 1;
|
this.active = 1;
|
||||||
this.typeOptions = data.type.split(",").reduce((arr, cur, idx) => {
|
this.typeOptions = data.type.split(",").reduce((arr, cur, idx) => {
|
||||||
@ -143,7 +143,7 @@ export default {
|
|||||||
type,
|
type,
|
||||||
igdList,
|
igdList,
|
||||||
});
|
});
|
||||||
console.log(this.selDishes);
|
// console.log(this.selDishes);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -296,13 +296,14 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleOnDishesConfirm(data) {
|
handleOnDishesConfirm(data) {
|
||||||
|
// console.log(data);
|
||||||
this.addDishes({
|
this.addDishes({
|
||||||
num: this.num - 1,
|
num: this.num - 1,
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
...mapActions(["updateDishes", "addDishes", "deleteDishes"]),
|
...mapActions(["updateDishes", "addDishes", "deleteDishes"]),
|
||||||
...mapMutations(["setCurrentDay",]),
|
...mapMutations(["setCurrentDay"]),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -111,14 +111,14 @@
|
|||||||
:data="recipesPlanList"
|
:data="recipesPlanList"
|
||||||
@selection-change="handleSelectionChange"
|
@selection-change="handleSelectionChange"
|
||||||
>
|
>
|
||||||
<el-table-column type="selection" width="55" align="center" />
|
<!-- <el-table-column type="selection" width="55" align="center" /> -->
|
||||||
<el-table-column label="客户姓名" align="center" prop="customer" />
|
<el-table-column label="客户姓名" align="center" prop="customer" />
|
||||||
<el-table-column
|
<!-- <el-table-column
|
||||||
label="客户手机号"
|
label="客户手机号"
|
||||||
align="center"
|
align="center"
|
||||||
prop="hidePhone"
|
prop="hidePhone"
|
||||||
width="180"
|
width="180"
|
||||||
/>
|
/> -->
|
||||||
<el-table-column
|
<el-table-column
|
||||||
label="食谱日期范围"
|
label="食谱日期范围"
|
||||||
align="center"
|
align="center"
|
||||||
@ -236,8 +236,7 @@
|
|||||||
|
|
||||||
<!-- 查看完整计划 -->
|
<!-- 查看完整计划 -->
|
||||||
<el-dialog
|
<el-dialog
|
||||||
title="食谱计划表"
|
:title="allRecipesPlanTitle"
|
||||||
v-if="allRecipesPlanOpen"
|
|
||||||
:visible.sync="allRecipesPlanOpen"
|
:visible.sync="allRecipesPlanOpen"
|
||||||
width="800px"
|
width="800px"
|
||||||
append-to-body
|
append-to-body
|
||||||
@ -269,7 +268,7 @@
|
|||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="allRecipesPlanList" width="700px">
|
<el-table v-loading="loading" :data="allRecipesPlanList" width="700px">
|
||||||
<el-table-column label="客户姓名" align="center" prop="customer" />
|
<!-- <el-table-column label="客户姓名" align="center" prop="customer" /> -->
|
||||||
<!--<el-table-column label="营养师名称" align="center" prop="nutritionist" />
|
<!--<el-table-column label="营养师名称" align="center" prop="nutritionist" />
|
||||||
<el-table-column label="营养师助理名称" align="center" prop="nutritionistAssis" />-->
|
<el-table-column label="营养师助理名称" align="center" prop="nutritionistAssis" />-->
|
||||||
|
|
||||||
@ -313,9 +312,9 @@
|
|||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
<!-- 查看订单 -->
|
<!-- 查看订单 -->
|
||||||
<order-dialog ref="orderDialog" />
|
<!-- <order-dialog ref="orderDialog" /> -->
|
||||||
<!-- 查看体征 -->
|
<!-- 查看体征 -->
|
||||||
<body_sign_dialog ref="bodySignDialog" />
|
<!-- <body_sign_dialog ref="bodySignDialog" /> -->
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -327,8 +326,8 @@ import {
|
|||||||
updateRecipesPlan,
|
updateRecipesPlan,
|
||||||
} from "@/api/custom/recipesPlan";
|
} from "@/api/custom/recipesPlan";
|
||||||
import { getOptions } from "@/api/custom/order";
|
import { getOptions } from "@/api/custom/order";
|
||||||
import OrderDetail from "@/components/OrderDetail";
|
// import OrderDetail from "@/components/OrderDetail";
|
||||||
import BodySignDetail from "@/components/BodySignDetail";
|
// import BodySignDetail from "@/components/BodySignDetail";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
|
|
||||||
@ -378,6 +377,7 @@ export default {
|
|||||||
allRecipesPlanList: [],
|
allRecipesPlanList: [],
|
||||||
//订单弹窗状态
|
//订单弹窗状态
|
||||||
allRecipesPlanOpen: false,
|
allRecipesPlanOpen: false,
|
||||||
|
allRecipesPlanTitle: '',
|
||||||
//订单弹窗中查询参数
|
//订单弹窗中查询参数
|
||||||
allRecipesPlanQueryParam: {
|
allRecipesPlanQueryParam: {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
@ -394,8 +394,8 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
"order-dialog": OrderDetail,
|
// "order-dialog": OrderDetail,
|
||||||
body_sign_dialog: BodySignDetail,
|
// body_sign_dialog: BodySignDetail,
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
getOptions().then((response) => {
|
getOptions().then((response) => {
|
||||||
@ -476,6 +476,7 @@ export default {
|
|||||||
dayjs(item.endDate).format("YYYY-MM-DD");
|
dayjs(item.endDate).format("YYYY-MM-DD");
|
||||||
});
|
});
|
||||||
this.allRecipesPlanOpen = true;
|
this.allRecipesPlanOpen = true;
|
||||||
|
this.allRecipesPlanTitle = `「${this.allRecipesPlanList[0].customer}」食谱计划表`
|
||||||
this.allRecipesPlanTotal = response.total;
|
this.allRecipesPlanTotal = response.total;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user