diff --git a/running/pdf/healthyReport.pdf b/running/pdf/healthyReport.pdf index 9e2f110fa..bd2295f14 100644 Binary files a/running/pdf/healthyReport.pdf and b/running/pdf/healthyReport.pdf differ diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysRecipesPlanMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysRecipesPlanMapper.java index a4fb2093f..e4d3ee2c1 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysRecipesPlanMapper.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysRecipesPlanMapper.java @@ -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 selectPlanListByCondition(SysRecipesPlan sysRecipesPlan); + /** + * 根据客户ID查询最后一天食谱计划 + * @param customerId + * @return + */ + SysRecipesPlan getLastDayRecipesPlan(@Param("customerId")Long customerId); + /** * 根据订单ID查询食谱计划 * @param sysRecipesPlan @@ -93,4 +101,11 @@ public interface SysRecipesPlanMapper List selectRecipesPlanListInfo(String outId); List selectPlanListByCusId(Long cusId); + + /** + * 批量更新食谱计划的开始时间、结束时间 + * @param list + * @return + */ + int updateMuchRecipesPlanDate(SysRecipesPlan sysRecipesPlan); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysRecipesPlanService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysRecipesPlanService.java index 146b1f68b..cffc8b111 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysRecipesPlanService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysRecipesPlanService.java @@ -99,6 +99,13 @@ public interface ISysRecipesPlanService */ Long getCusIdByOutId(String outId); + /** + * 根据客户ID查询最后一天食谱计划 + * @param customerId + * @return + */ + SysRecipesPlan getLastDayRecipesPlan(Long customerId); + /** * 通过outId查询食谱计划简要 * @param outId diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHealthyServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHealthyServiceImpl.java index 52c1b052f..05d21b6d5 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHealthyServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHealthyServiceImpl.java @@ -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; //查询客户健康信息 diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysOrderServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysOrderServiceImpl.java index 6932b3abb..c822e243c 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysOrderServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysOrderServiceImpl.java @@ -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; } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysRecipesPlanServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysRecipesPlanServiceImpl.java index 86439343d..7fdd20866 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysRecipesPlanServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysRecipesPlanServiceImpl.java @@ -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 oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam); SysOrderPause pauseParam = new SysOrderPause(); pauseParam.setOrderId(sysOrder.getOrderId()); //暂停记录列表 List pauseList = sysOrderPauseService.selectSysOrderPauseList(pauseParam); - List planList = generatePlan(sysOrder, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList); - //判断是否已存在食谱计划 - List oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam); + List 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 oldRecipesPlanList, List newRecipesPlanList){ + int newSize = newRecipesPlanList.size(); + int index = 0; + List addList = new ArrayList<>(); + List updateList = new ArrayList<>(); + List 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 generatePlan(SysOrder sysOrder, LocalDate serverStartDate, LocalDate serverEndDate, List pauseList) { + private List generatePlan(SysOrder sysOrder, List oldRecipesPlanList, LocalDate serverStartDate, LocalDate serverEndDate, List 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 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 pauseList) { + private long getPauseDayeCount(LocalDate planStartDate, LocalDate planEndDate, List 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); diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysRecipesPlanMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysRecipesPlanMapper.xml index 3a114d26f..031af09b1 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysRecipesPlanMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysRecipesPlanMapper.xml @@ -52,6 +52,8 @@ and send_flag = #{sendFlag} and send_time = #{sendTime} and review_status = #{reviewStatus} + + order by id ASC + + + insert into sys_recipes_plan order_id, cus_id, + out_id, start_date, end_date, start_num_day, @@ -81,6 +90,7 @@ #{orderId}, #{cusId}, + #{outId}, #{startDate}, #{endDate}, #{startNumDay}, @@ -102,6 +112,7 @@ order_id = #{orderId}, cus_id = #{cusId}, + out_id = #{outId}, start_date = #{startDate}, end_date = #{endDate}, start_num_day = #{startNumDay}, @@ -133,10 +144,10 @@ 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 - (#{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}) @@ -234,4 +245,12 @@ + + +   + + update sys_recipes_plan set start_date = #{startDate},end_date = #{endDate} where id = #{id} + \ No newline at end of file