食谱计划修改
This commit is contained in:
		@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user