From ce7c7e4525c900cb57cd6b7f8d0f6ba0c42b1632 Mon Sep 17 00:00:00 2001 From: xiezhijun <15270898033@163.com> Date: Tue, 29 Jun 2021 18:34:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A3=9F=E8=B0=B1=E8=AE=A1=E5=88=92=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=BC=98=E5=8C=96=EF=BC=8C=E8=A7=A3=E5=86=B3=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E8=AE=A2=E5=8D=95=E8=BF=9E=E6=8E=A5=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=AE=B5=E7=9A=84=E6=9A=82=E5=81=9C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stdiet/custom/mapper/SysOrderMapper.java | 7 +++++++ .../custom/service/ISysOrderService.java | 7 +++++++ .../service/impl/SysOrderServiceImpl.java | 9 +++++++++ .../impl/SysRecipesPlanServiceImpl.java | 19 ++++++++++++++++--- .../mapper/custom/SysOrderMapper.xml | 8 ++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysOrderMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysOrderMapper.java index 12285ba47..ef987004e 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysOrderMapper.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysOrderMapper.java @@ -120,4 +120,11 @@ public interface SysOrderMapper * @return */ SysOrder getLastOrderByNutritionistId(@Param("nutritionistId")Long nutritionistId); + + /** + * 根据用户ID查询最后一个订单 + * @param cusId 客户ID + * @return + */ + SysOrder getLastOrderByCusId(@Param("cusId")Long cusId); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysOrderService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysOrderService.java index 19fbd8b88..2c4575577 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysOrderService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysOrderService.java @@ -121,4 +121,11 @@ public interface ISysOrderService * @return */ int getOrderCountByOpenId(String openid); + + /** + * 根据用户ID查询最后一个订单 + * @param cusId 客户ID + * @return + */ + SysOrder getLastOrderByCusId(Long cusId); } \ No newline at end of file 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 7cd5b91bd..b4cc5a2bd 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 @@ -511,4 +511,13 @@ public class SysOrderServiceImpl implements ISysOrderService { public int getOrderCountByOpenId(String openid){ return sysOrderMapper.getOrderCountByOpenId(openid); } + + /** + * 根据用户ID查询最后一个订单 + * @param cusId 客户ID + * @return + */ + public SysOrder getLastOrderByCusId(Long cusId){ + return sysOrderMapper.getLastOrderByCusId(cusId); + } } \ No newline at end of file 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 9776978e6..c01921b36 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 @@ -15,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional; import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.*; @@ -326,6 +327,8 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { SysRecipesPlan beforeOrderLastPlan = getLastDayRecipesPlan(sysOrder.getCusId(), sysOrder.getOrderTime()); int startNumDay = 0; //System.out.println(sysOrder.getRecipesPlanContinue() == null); + int totalDays = (beforeOrderLastPlan != null ? beforeOrderLastPlan.getEndNumDay() : 0) + Integer.parseInt(sysOrder.getServeTimeId()+""); + System.out.println(totalDays); //之前是否存在食谱以及该订单食谱计划是否需要连续 if (beforeOrderLastPlan != null && sysOrder.getRecipesPlanContinue().intValue() == 1) { long differDay = ChronoUnit.DAYS.between(DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()), serverStartDate); @@ -333,11 +336,21 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { if (differDay <= 1) { //判断前一个订单食谱是否满七天,不满则需要接上 int differNum = beforeOrderLastPlan.getEndNumDay() - beforeOrderLastPlan.getStartNumDay(); - if (differNum < 6) { //更新该食谱计划 beforeOrderLastPlan.setEndNumDay(beforeOrderLastPlan.getStartNumDay() + 6); - beforeOrderLastPlan.setEndDate(DateUtils.localDateToDate(DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(6 - differNum))); + // + String[] pauseResult = dealPlanPause(DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(1), DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(6-differNum), pauseList); + //LocalDate planStartDate = DateUtils.stringToLocalDate(pauseResult[0], "yyyyMMdd"); + LocalDate planEndDate = DateUtils.stringToLocalDate(pauseResult[1], "yyyyMMdd"); + beforeOrderLastPlan.setEndDate(DateUtils.localDateToDate(planEndDate)); + + //beforeOrderLastPlan.setEndDate(DateUtils.localDateToDate(DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(6 - differNum))); + // + /*String[] pauseResult = dealPlanPause(DateUtils.dateToLocalDate(beforeOrderLastPlan.getStartDate()), DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()), pauseList); + //LocalDate planStartDate = DateUtils.stringToLocalDate(pauseResult[0], "yyyyMMdd"); + LocalDate planEndDate = DateUtils.stringToLocalDate(pauseResult[1], "yyyyMMdd"); + beforeOrderLastPlan.setEndDate(DateUtils.localDateToDate(planEndDate));*/ sysRecipesPlanMapper.updateSysRecipesPlan(beforeOrderLastPlan); serverStartDate = DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(1); } @@ -384,7 +397,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { sysRecipesPlan.setStartNumDay(startNumDay); long dayNumber = ChronoUnit.DAYS.between(planStartDate, planEndDate); startNumDay += dayNumber > 6 ? 6 : dayNumber; - sysRecipesPlan.setEndNumDay(startNumDay); + sysRecipesPlan.setEndNumDay(startNumDay > totalDays ? totalDays : startNumDay); //添加暂停范围内的日期 planList.add(sysRecipesPlan); //System.out.println(DateUtils.dateTime(sysRecipesPlan.getStartDate()) + "-----" + DateUtils.dateTime(sysRecipesPlan.getEndDate())); diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysOrderMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysOrderMapper.xml index 73c8bec76..a9ffa816d 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysOrderMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysOrderMapper.xml @@ -554,4 +554,12 @@ select * from sys_order so where del_flag = 0 and nutritionist_id = #{nutritionistId} order by order_id desc limit 1 + + + + + \ No newline at end of file