食谱计划修改
This commit is contained in:
parent
a244a4a536
commit
2ceefcf9a5
running/pdf
stdiet-custom/src/main
java/com/stdiet/custom
mapper
service
resources/mapper/custom
Binary file not shown.
@ -3,6 +3,7 @@ package com.stdiet.custom.mapper;
|
||||
import java.util.List;
|
||||
import com.stdiet.custom.domain.SysRecipesPlan;
|
||||
import com.stdiet.custom.domain.SysRecipesPlanListInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 食谱计划Mapper接口
|
||||
@ -81,6 +82,13 @@ public interface SysRecipesPlanMapper
|
||||
*/
|
||||
List<SysRecipesPlan> selectPlanListByCondition(SysRecipesPlan sysRecipesPlan);
|
||||
|
||||
/**
|
||||
* 根据客户ID查询最后一天食谱计划
|
||||
* @param customerId
|
||||
* @return
|
||||
*/
|
||||
SysRecipesPlan getLastDayRecipesPlan(@Param("customerId")Long customerId);
|
||||
|
||||
/**
|
||||
* 根据订单ID查询食谱计划
|
||||
* @param sysRecipesPlan
|
||||
@ -93,4 +101,11 @@ public interface SysRecipesPlanMapper
|
||||
List<SysRecipesPlanListInfo> selectRecipesPlanListInfo(String outId);
|
||||
|
||||
List<SysRecipesPlan> selectPlanListByCusId(Long cusId);
|
||||
|
||||
/**
|
||||
* 批量更新食谱计划的开始时间、结束时间
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
int updateMuchRecipesPlanDate(SysRecipesPlan sysRecipesPlan);
|
||||
}
|
@ -99,6 +99,13 @@ public interface ISysRecipesPlanService
|
||||
*/
|
||||
Long getCusIdByOutId(String outId);
|
||||
|
||||
/**
|
||||
* 根据客户ID查询最后一天食谱计划
|
||||
* @param customerId
|
||||
* @return
|
||||
*/
|
||||
SysRecipesPlan getLastDayRecipesPlan(Long customerId);
|
||||
|
||||
/**
|
||||
* 通过outId查询食谱计划简要
|
||||
* @param outId
|
||||
|
@ -157,8 +157,8 @@ public class SysCustomerHealthyServiceImpl implements ISysCustomerHealthyService
|
||||
@Override
|
||||
public AjaxResult generateHealthyReport(HealthyDetailRequest healthyDetailRequest){
|
||||
AjaxResult ajaxResult = AjaxResult.error();
|
||||
//String templatePath = "/home/workspace/ShengTangManage/running/pdf/healthyReport.pdf";
|
||||
String templatePath = "D:\\contract\\healthyReport.pdf";
|
||||
String templatePath = "/home/workspace/ShengTangManage/running/pdf/healthyReport.pdf";
|
||||
//String templatePath = "D:\\contract\\healthyReport.pdf";
|
||||
String fileName = "healthyReport" + healthyDetailRequest.getCustomerId() + System.currentTimeMillis() + ".pdf";
|
||||
String filePath = RuoYiConfig.getDownloadPath() + fileName;
|
||||
//查询客户健康信息
|
||||
|
@ -206,11 +206,9 @@ public class SysOrderServiceImpl implements ISysOrderService {
|
||||
//更新订单
|
||||
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;
|
||||
}
|
||||
@ -223,6 +221,9 @@ public class SysOrderServiceImpl implements ISysOrderService {
|
||||
* @return
|
||||
*/
|
||||
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()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.stdiet.custom.service.impl;
|
||||
|
||||
import com.stdiet.common.utils.DateUtils;
|
||||
import com.stdiet.common.utils.SynchrolockUtil;
|
||||
import com.stdiet.common.utils.sign.Md5Utils;
|
||||
import com.stdiet.custom.domain.SysOrder;
|
||||
import com.stdiet.custom.domain.SysOrderPause;
|
||||
import com.stdiet.custom.domain.SysRecipesPlan;
|
||||
@ -131,8 +132,8 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
return;
|
||||
}
|
||||
SysOrder sysOrder = sysOrderService.selectSysOrderById(orderId);
|
||||
//订单为空、金额小于0不进行食谱生成、更新,只对2021年开始的订单进行食谱计划生成,判断订单金额、开始时间、结束时间,为空则直接返回,不重新生成食谱计划
|
||||
if (sysOrder == null && DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear() < 2021
|
||||
//订单为空、金额小于0、订单未审核不进行食谱生成、更新,只对2021年开始的订单进行食谱计划生成,判断订单金额、开始时间、结束时间,为空则直接返回,不重新生成食谱计划
|
||||
if (sysOrder == null || !sysOrder.getReviewStatus().equals("yes") || DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear() < 2021
|
||||
|| sysOrder.getAmount().floatValue() <= 0 || sysOrder.getStartTime() == null || sysOrder.getServerEndTime() == null) {
|
||||
return;
|
||||
}
|
||||
@ -145,24 +146,17 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
try {
|
||||
//获取redis中该订单对应的锁
|
||||
if (synchrolockUtil.lock(String.format(generateRecipesPlanLockKey, orderId))) {
|
||||
//判断是否已存在食谱计划
|
||||
SysRecipesPlan queryParam = new SysRecipesPlan();
|
||||
queryParam.setOrderId(orderId);
|
||||
//判断是否已存在食谱
|
||||
/*if (oldRecipesPlanList != null && oldRecipesPlanList.size() > 0) {
|
||||
Long[] orderIdArray = new Long[1];
|
||||
orderIdArray[0] = orderId;
|
||||
//删除该订单对于食谱
|
||||
//delRecipesPlanByOrderId(orderIdArray);
|
||||
}*/
|
||||
List<SysRecipesPlan> oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam);
|
||||
SysOrderPause pauseParam = new SysOrderPause();
|
||||
pauseParam.setOrderId(sysOrder.getOrderId());
|
||||
//暂停记录列表
|
||||
List<SysOrderPause> pauseList = sysOrderPauseService.selectSysOrderPauseList(pauseParam);
|
||||
List<SysRecipesPlan> planList = generatePlan(sysOrder, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList);
|
||||
//判断是否已存在食谱计划
|
||||
List<SysRecipesPlan> oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam);
|
||||
List<SysRecipesPlan> planList = generatePlan(sysOrder, oldRecipesPlanList, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList);
|
||||
if(oldRecipesPlanList != null && oldRecipesPlanList.size() > 0){
|
||||
|
||||
updateOrAddRecipesPlan(oldRecipesPlanList, planList);
|
||||
}else{
|
||||
if (planList != null && planList.size() > 0) {
|
||||
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、订单开始服务时间、结束时间、暂停列表生成食谱计划列表
|
||||
*
|
||||
@ -186,7 +220,15 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
* @param pauseList 暂停列表
|
||||
* @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<>();
|
||||
boolean breakFlag = false;
|
||||
LocalDate planStartDate = serverStartDate;
|
||||
@ -205,12 +247,11 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
sysRecipesPlan.setEndDate(DateUtils.localDateToDate(planEndDate));
|
||||
sysRecipesPlan.setOrderId(sysOrder.getOrderId());
|
||||
sysRecipesPlan.setCusId(sysOrder.getCusId());
|
||||
sysRecipesPlan.setEndNumDay();
|
||||
//将旧食谱计划中的发送状态、发送时间、食谱复制到新食谱计划中
|
||||
/*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);*/
|
||||
sysRecipesPlan.setOutId(Md5Utils.hash(String.valueOf(sysOrder.getCusId())));
|
||||
oldStartNumDay += 1;
|
||||
sysRecipesPlan.setStartNumDay(oldStartNumDay);
|
||||
oldStartNumDay += 6;
|
||||
sysRecipesPlan.setEndNumDay(oldStartNumDay);
|
||||
planList.add(sysRecipesPlan);
|
||||
|
||||
planStartDate = planEndDate.plusDays(1);
|
||||
@ -231,7 +272,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
* @param pauseList 暂停列表
|
||||
* @return
|
||||
*/
|
||||
public long getPauseDayeCount(LocalDate planStartDate, LocalDate planEndDate, List<SysOrderPause> pauseList) {
|
||||
private long getPauseDayeCount(LocalDate planStartDate, LocalDate planEndDate, List<SysOrderPause> pauseList) {
|
||||
long pauseDay = 0;
|
||||
//判断这个时间内是否存在暂停
|
||||
if (pauseList != null && pauseList.size() > 0) {
|
||||
@ -286,6 +327,15 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
return sysRecipesPlanMapper.selectPlanListByOrderId(sysRecipesPlan);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据客户ID查询最后一天食谱计划
|
||||
* @param customerId
|
||||
* @return
|
||||
*/
|
||||
public SysRecipesPlan getLastDayRecipesPlan(Long customerId){
|
||||
return sysRecipesPlanMapper.getLastDayRecipesPlan(customerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCusIdByOutId(String outId) {
|
||||
return sysRecipesPlanMapper.getCusIdByOutId(outId);
|
||||
|
@ -52,6 +52,8 @@
|
||||
<if test="sendFlag != null ">and send_flag = #{sendFlag}</if>
|
||||
<if test="sendTime != null ">and send_time = #{sendTime}</if>
|
||||
<if test="reviewStatus != null ">and review_status = #{reviewStatus}</if>
|
||||
<!-- 请勿轻易修改排序方式,会影响食谱生成等逻辑 -->
|
||||
order by id ASC
|
||||
</select>
|
||||
|
||||
<select id="selectSysRecipesPlanById" parameterType="Long" resultMap="SysRecipesPlanResult">
|
||||
@ -59,11 +61,18 @@
|
||||
where id = #{id} and del_flag = 0
|
||||
</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 into sys_recipes_plan
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="orderId != null">order_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="endDate != null">end_date,</if>
|
||||
<if test="startNumDay != null">start_num_day,</if>
|
||||
@ -81,6 +90,7 @@
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="orderId != null">#{orderId},</if>
|
||||
<if test="cusId != null">#{cusId},</if>
|
||||
<if test="outId != null">#{outId},</if>
|
||||
<if test="startDate != null">#{startDate},</if>
|
||||
<if test="endDate != null">#{endDate},</if>
|
||||
<if test="startNumDay != null">#{startNumDay},</if>
|
||||
@ -102,6 +112,7 @@
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="orderId != null">order_id = #{orderId},</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="endDate != null">end_date = #{endDate},</if>
|
||||
<if test="startNumDay != null">start_num_day = #{startNumDay},</if>
|
||||
@ -133,10 +144,10 @@
|
||||
<!-- 批量插入食谱计划 -->
|
||||
<insert id="insertBatch">
|
||||
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
|
||||
<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})
|
||||
</foreach>
|
||||
</insert>
|
||||
@ -234,4 +245,12 @@
|
||||
<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>
|
||||
|
||||
<!-- 批量修改食谱计划 -->
|
||||
<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>
|
Loading…
x
Reference in New Issue
Block a user