食谱计划修改

This commit is contained in:
xiezhijun 2021-02-27 19:22:25 +08:00
parent a244a4a536
commit 2ceefcf9a5
7 changed files with 121 additions and 29 deletions

Binary file not shown.

View File

@ -3,6 +3,7 @@ package com.stdiet.custom.mapper;
import java.util.List; import java.util.List;
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.apache.ibatis.annotations.Param;
/** /**
* 食谱计划Mapper接口 * 食谱计划Mapper接口
@ -81,6 +82,13 @@ public interface SysRecipesPlanMapper
*/ */
List<SysRecipesPlan> selectPlanListByCondition(SysRecipesPlan sysRecipesPlan); List<SysRecipesPlan> selectPlanListByCondition(SysRecipesPlan sysRecipesPlan);
/**
* 根据客户ID查询最后一天食谱计划
* @param customerId
* @return
*/
SysRecipesPlan getLastDayRecipesPlan(@Param("customerId")Long customerId);
/** /**
* 根据订单ID查询食谱计划 * 根据订单ID查询食谱计划
* @param sysRecipesPlan * @param sysRecipesPlan
@ -93,4 +101,11 @@ public interface SysRecipesPlanMapper
List<SysRecipesPlanListInfo> selectRecipesPlanListInfo(String outId); List<SysRecipesPlanListInfo> selectRecipesPlanListInfo(String outId);
List<SysRecipesPlan> selectPlanListByCusId(Long cusId); List<SysRecipesPlan> selectPlanListByCusId(Long cusId);
/**
* 批量更新食谱计划的开始时间结束时间
* @param list
* @return
*/
int updateMuchRecipesPlanDate(SysRecipesPlan sysRecipesPlan);
} }

View File

@ -99,6 +99,13 @@ public interface ISysRecipesPlanService
*/ */
Long getCusIdByOutId(String outId); Long getCusIdByOutId(String outId);
/**
* 根据客户ID查询最后一天食谱计划
* @param customerId
* @return
*/
SysRecipesPlan getLastDayRecipesPlan(Long customerId);
/** /**
* 通过outId查询食谱计划简要 * 通过outId查询食谱计划简要
* @param outId * @param outId

View File

@ -157,8 +157,8 @@ public class SysCustomerHealthyServiceImpl implements ISysCustomerHealthyService
@Override @Override
public AjaxResult generateHealthyReport(HealthyDetailRequest healthyDetailRequest){ public AjaxResult generateHealthyReport(HealthyDetailRequest healthyDetailRequest){
AjaxResult ajaxResult = AjaxResult.error(); AjaxResult ajaxResult = AjaxResult.error();
//String templatePath = "/home/workspace/ShengTangManage/running/pdf/healthyReport.pdf"; String templatePath = "/home/workspace/ShengTangManage/running/pdf/healthyReport.pdf";
String templatePath = "D:\\contract\\healthyReport.pdf"; //String templatePath = "D:\\contract\\healthyReport.pdf";
String fileName = "healthyReport" + healthyDetailRequest.getCustomerId() + System.currentTimeMillis() + ".pdf"; String fileName = "healthyReport" + healthyDetailRequest.getCustomerId() + System.currentTimeMillis() + ".pdf";
String filePath = RuoYiConfig.getDownloadPath() + fileName; String filePath = RuoYiConfig.getDownloadPath() + fileName;
//查询客户健康信息 //查询客户健康信息

View File

@ -206,12 +206,10 @@ public class SysOrderServiceImpl implements ISysOrderService {
//更新订单 //更新订单
int row = sysOrderMapper.updateSysOrder(sysOrder); int row = sysOrderMapper.updateSysOrder(sysOrder);
// 审核后的订单才生成食谱 // 审核后的订单才生成食谱
if (row > 0 && oldSysOrder.getReviewStatus().equals("no") && sysOrder.getReviewStatus().equals("yes")) { if (row > 0 && isNeedRegenerateRecipesPlan(oldSysOrder, sysOrder)) {
//异步更新食谱计划 //异步更新食谱计划
if (isNeedRegenerateRecipesPlan(oldSysOrder, sysOrder)) {
sysRecipesPlanService.regenerateRecipesPlan(sysOrder.getOrderId()); sysRecipesPlanService.regenerateRecipesPlan(sysOrder.getOrderId());
} }
}
return row; return row;
} }
@ -223,6 +221,9 @@ public class SysOrderServiceImpl implements ISysOrderService {
* @return * @return
*/ */
private boolean isNeedRegenerateRecipesPlan(SysOrder oldSysOrder, SysOrder newSysOrder) { private boolean isNeedRegenerateRecipesPlan(SysOrder oldSysOrder, SysOrder newSysOrder) {
if(oldSysOrder.getReviewStatus().equals("no") && newSysOrder.getReviewStatus().equals("yes")){
return true;
}
if (oldSysOrder.getServeTimeId() != null && newSysOrder.getServeTimeId() != null && oldSysOrder.getServeTimeId().intValue() != newSysOrder.getServeTimeId().intValue()) { if (oldSysOrder.getServeTimeId() != null && newSysOrder.getServeTimeId() != null && oldSysOrder.getServeTimeId().intValue() != newSysOrder.getServeTimeId().intValue()) {
return true; return true;
} }

View File

@ -2,6 +2,7 @@ package com.stdiet.custom.service.impl;
import com.stdiet.common.utils.DateUtils; import com.stdiet.common.utils.DateUtils;
import com.stdiet.common.utils.SynchrolockUtil; import com.stdiet.common.utils.SynchrolockUtil;
import com.stdiet.common.utils.sign.Md5Utils;
import com.stdiet.custom.domain.SysOrder; import com.stdiet.custom.domain.SysOrder;
import com.stdiet.custom.domain.SysOrderPause; import com.stdiet.custom.domain.SysOrderPause;
import com.stdiet.custom.domain.SysRecipesPlan; import com.stdiet.custom.domain.SysRecipesPlan;
@ -131,8 +132,8 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
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 || !sysOrder.getReviewStatus().equals("yes") || DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear() < 2021
|| sysOrder.getAmount().floatValue() <= 0 || sysOrder.getStartTime() == null || sysOrder.getServerEndTime() == null) { || sysOrder.getAmount().floatValue() <= 0 || sysOrder.getStartTime() == null || sysOrder.getServerEndTime() == null) {
return; return;
} }
@ -145,24 +146,17 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
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);
/*if (oldRecipesPlanList != null && oldRecipesPlanList.size() > 0) {
Long[] orderIdArray = new Long[1];
orderIdArray[0] = orderId;
//删除该订单对于食谱
//delRecipesPlanByOrderId(orderIdArray);
}*/
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(sysOrder, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList); List<SysRecipesPlan> planList = generatePlan(sysOrder, oldRecipesPlanList, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList);
//判断是否已存在食谱计划
List<SysRecipesPlan> oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam);
if(oldRecipesPlanList != null && oldRecipesPlanList.size() > 0){ if(oldRecipesPlanList != null && oldRecipesPlanList.size() > 0){
updateOrAddRecipesPlan(oldRecipesPlanList, planList);
}else{ }else{
if (planList != null && planList.size() > 0) { if (planList != null && planList.size() > 0) {
sysRecipesPlanMapper.insertBatch(planList); sysRecipesPlanMapper.insertBatch(planList);
@ -177,6 +171,46 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
} }
} }
/**
* 更新食谱计划删除旧食谱中多余的添加新食谱中多的
* @param oldRecipesPlanList
* @param newRecipesPlanList
*/
private void updateOrAddRecipesPlan(List<SysRecipesPlan> oldRecipesPlanList, List<SysRecipesPlan> newRecipesPlanList){
int newSize = newRecipesPlanList.size();
int index = 0;
List<SysRecipesPlan> addList = new ArrayList<>();
List<SysRecipesPlan> updateList = new ArrayList<>();
List<Long> delList = new ArrayList<>();
for (SysRecipesPlan plan : oldRecipesPlanList) {
if(index < newSize){
plan.setStartDate(newRecipesPlanList.get(index).getStartDate());
plan.setEndDate(newRecipesPlanList.get(index).getEndDate());
updateList.add(plan);
}else{
delList.add(plan.getId());
}
index++;
}
if(newSize > oldRecipesPlanList.size()){
addList = newRecipesPlanList.subList(oldRecipesPlanList.size(),newSize);
}
//更新
if(updateList.size() > 0){
for (SysRecipesPlan plan : updateList) {
sysRecipesPlanMapper.updateSysRecipesPlan(plan);
}
}
//删除多余的食谱计划
if(delList.size() > 0){
sysRecipesPlanMapper.deleteSysRecipesPlanByIds(delList.toArray(new Long[delList.size()]));
}
//添加新的
if(addList.size() > 0){
sysRecipesPlanMapper.insertBatch(addList);
}
}
/** /**
* 根据订单ID订单开始服务时间结束时间暂停列表生成食谱计划列表 * 根据订单ID订单开始服务时间结束时间暂停列表生成食谱计划列表
* *
@ -186,7 +220,15 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
* @param pauseList 暂停列表 * @param pauseList 暂停列表
* @return * @return
*/ */
public List<SysRecipesPlan> generatePlan(SysOrder sysOrder, LocalDate serverStartDate, LocalDate serverEndDate, List<SysOrderPause> pauseList) { private List<SysRecipesPlan> generatePlan(SysOrder sysOrder, List<SysRecipesPlan> oldRecipesPlanList, LocalDate serverStartDate, LocalDate serverEndDate, List<SysOrderPause> pauseList) {
//查询该客户最后一次食谱计划对应天数
int oldStartNumDay = 0;
if(oldRecipesPlanList.size() == 0){
SysRecipesPlan lastSysRecipesPlan = getLastDayRecipesPlan(sysOrder.getCusId());
oldStartNumDay = lastSysRecipesPlan == null || lastSysRecipesPlan.getEndNumDay() == null ? 0 : lastSysRecipesPlan.getEndNumDay().intValue();
}else{
oldStartNumDay = oldRecipesPlanList.get(0).getStartNumDay() - 1;
}
List<SysRecipesPlan> planList = new ArrayList<>(); List<SysRecipesPlan> planList = new ArrayList<>();
boolean breakFlag = false; boolean breakFlag = false;
LocalDate planStartDate = serverStartDate; LocalDate planStartDate = serverStartDate;
@ -205,12 +247,11 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
sysRecipesPlan.setEndDate(DateUtils.localDateToDate(planEndDate)); sysRecipesPlan.setEndDate(DateUtils.localDateToDate(planEndDate));
sysRecipesPlan.setOrderId(sysOrder.getOrderId()); sysRecipesPlan.setOrderId(sysOrder.getOrderId());
sysRecipesPlan.setCusId(sysOrder.getCusId()); sysRecipesPlan.setCusId(sysOrder.getCusId());
sysRecipesPlan.setEndNumDay(); sysRecipesPlan.setOutId(Md5Utils.hash(String.valueOf(sysOrder.getCusId())));
//将旧食谱计划中的发送状态发送时间食谱复制到新食谱计划中 oldStartNumDay += 1;
/*boolean existFlag = oldRecipesPlanList.size() >= planList.size() + 1; sysRecipesPlan.setStartNumDay(oldStartNumDay);
sysRecipesPlan.setSendFlag(existFlag ? oldRecipesPlanList.get(planList.size()).getSendFlag() : 0); oldStartNumDay += 6;
sysRecipesPlan.setSendTime(existFlag ? oldRecipesPlanList.get(planList.size()).getSendTime() : null); sysRecipesPlan.setEndNumDay(oldStartNumDay);
sysRecipesPlan.setRecipesId(existFlag ? oldRecipesPlanList.get(planList.size()).getRecipesId() : null);*/
planList.add(sysRecipesPlan); planList.add(sysRecipesPlan);
planStartDate = planEndDate.plusDays(1); planStartDate = planEndDate.plusDays(1);
@ -231,7 +272,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
* @param pauseList 暂停列表 * @param pauseList 暂停列表
* @return * @return
*/ */
public long getPauseDayeCount(LocalDate planStartDate, LocalDate planEndDate, List<SysOrderPause> pauseList) { private 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) {
@ -286,6 +327,15 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
return sysRecipesPlanMapper.selectPlanListByOrderId(sysRecipesPlan); return sysRecipesPlanMapper.selectPlanListByOrderId(sysRecipesPlan);
} }
/**
* 根据客户ID查询最后一天食谱计划
* @param customerId
* @return
*/
public SysRecipesPlan getLastDayRecipesPlan(Long customerId){
return sysRecipesPlanMapper.getLastDayRecipesPlan(customerId);
}
@Override @Override
public Long getCusIdByOutId(String outId) { public Long getCusIdByOutId(String outId) {
return sysRecipesPlanMapper.getCusIdByOutId(outId); return sysRecipesPlanMapper.getCusIdByOutId(outId);

View File

@ -52,6 +52,8 @@
<if test="sendFlag != null ">and send_flag = #{sendFlag}</if> <if test="sendFlag != null ">and send_flag = #{sendFlag}</if>
<if test="sendTime != null ">and send_time = #{sendTime}</if> <if test="sendTime != null ">and send_time = #{sendTime}</if>
<if test="reviewStatus != null ">and review_status = #{reviewStatus}</if> <if test="reviewStatus != null ">and review_status = #{reviewStatus}</if>
<!-- 请勿轻易修改排序方式,会影响食谱生成等逻辑 -->
order by id ASC
</select> </select>
<select id="selectSysRecipesPlanById" parameterType="Long" resultMap="SysRecipesPlanResult"> <select id="selectSysRecipesPlanById" parameterType="Long" resultMap="SysRecipesPlanResult">
@ -59,11 +61,18 @@
where id = #{id} and del_flag = 0 where id = #{id} and del_flag = 0
</select> </select>
<!-- 根据用户ID查询是否存在该用户最后一天食谱 -->
<select id="getLastDayRecipesPlan" resultMap="SysRecipesPlanResult" parameterType="Long">
<include refid="selectSysRecipesPlanVo"/>
where cus_id = #{customerId} and del_flag = 0 order by end_num_day DESC limit 1
</select>
<insert id="insertSysRecipesPlan" parameterType="SysRecipesPlan" useGeneratedKeys="true" keyProperty="id"> <insert id="insertSysRecipesPlan" parameterType="SysRecipesPlan" useGeneratedKeys="true" keyProperty="id">
insert into sys_recipes_plan insert into sys_recipes_plan
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="orderId != null">order_id,</if> <if test="orderId != null">order_id,</if>
<if test="cusId != null">cus_id,</if> <if test="cusId != null">cus_id,</if>
<if test="outId != null">out_id,</if>
<if test="startDate != null">start_date,</if> <if test="startDate != null">start_date,</if>
<if test="endDate != null">end_date,</if> <if test="endDate != null">end_date,</if>
<if test="startNumDay != null">start_num_day,</if> <if test="startNumDay != null">start_num_day,</if>
@ -81,6 +90,7 @@
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="orderId != null">#{orderId},</if> <if test="orderId != null">#{orderId},</if>
<if test="cusId != null">#{cusId},</if> <if test="cusId != null">#{cusId},</if>
<if test="outId != null">#{outId},</if>
<if test="startDate != null">#{startDate},</if> <if test="startDate != null">#{startDate},</if>
<if test="endDate != null">#{endDate},</if> <if test="endDate != null">#{endDate},</if>
<if test="startNumDay != null">#{startNumDay},</if> <if test="startNumDay != null">#{startNumDay},</if>
@ -102,6 +112,7 @@
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="orderId != null">order_id = #{orderId},</if> <if test="orderId != null">order_id = #{orderId},</if>
<if test="cusId != null">cus_id = #{cusId},</if> <if test="cusId != null">cus_id = #{cusId},</if>
<if test="outId != null">out_id = #{outId},</if>
<if test="startDate != null">start_date = #{startDate},</if> <if test="startDate != null">start_date = #{startDate},</if>
<if test="endDate != null">end_date = #{endDate},</if> <if test="endDate != null">end_date = #{endDate},</if>
<if test="startNumDay != null">start_num_day = #{startNumDay},</if> <if test="startNumDay != null">start_num_day = #{startNumDay},</if>
@ -133,10 +144,10 @@
<!-- 批量插入食谱计划 --> <!-- 批量插入食谱计划 -->
<insert id="insertBatch"> <insert id="insertBatch">
INSERT INTO sys_recipes_plan INSERT INTO sys_recipes_plan
(order_id, cus_id, start_date, end_date, start_num_day, end_num_day, send_flag, send_time, recipes_id) (order_id, cus_id, out_id, start_date, end_date, start_num_day, end_num_day, send_flag, send_time, recipes_id)
VALUES VALUES
<foreach collection="list" item="plan" separator=","> <foreach collection="list" item="plan" separator=",">
(#{plan.orderId}, #{plan.cusId}, #{plan.startDate}, #{plan.endDate}, #{plan.startNumDay}, #{plan.endNumDay}, (#{plan.orderId}, #{plan.cusId}, #{plan.outId}, #{plan.startDate}, #{plan.endDate}, #{plan.startNumDay}, #{plan.endNumDay},
#{plan.sendFlag}, #{plan.sendTime}, #{plan.recipesId}) #{plan.sendFlag}, #{plan.sendTime}, #{plan.recipesId})
</foreach> </foreach>
</insert> </insert>
@ -234,4 +245,12 @@
<select id="selectMenuIds" parameterType="Long" resultMap="SysRecipesResult"> <select id="selectMenuIds" parameterType="Long" resultMap="SysRecipesResult">
select id, num_day from sys_customer_daily_menu where recipes_id=#{recipes_id} order by num_day asc select id, num_day from sys_customer_daily_menu where recipes_id=#{recipes_id} order by num_day asc
</select> </select>
<!-- 批量修改食谱计划 -->
<update id="updateMuchRecipesPlanDate" parameterType="SysRecipesPlan"> 
<!--<foreach collection="list" item="item" separator=";" open="" close="">
</foreach>-->
update sys_recipes_plan set start_date = #{startDate},end_date = #{endDate} where id = #{id}
</update>
</mapper> </mapper>