Merge branch 'master' of https://gitee.com/darlk/ShengTangManage into xzj
This commit is contained in:
		| @@ -1,5 +1,6 @@ | ||||
| package com.stdiet.custom.domain; | ||||
|  | ||||
| import com.alibaba.fastjson.JSONArray; | ||||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||||
| import com.stdiet.common.annotation.Excel; | ||||
| import lombok.Data; | ||||
| @@ -74,6 +75,4 @@ public class SysDishes { | ||||
|  | ||||
|     private List<SysDishesIngredient> igdList; | ||||
|  | ||||
|     private List<SysDishesIngredient> detail; | ||||
|  | ||||
| } | ||||
| @@ -1,8 +1,6 @@ | ||||
| package com.stdiet.custom.domain; | ||||
|  | ||||
| import lombok.Data; | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||||
|  | ||||
| import java.math.BigDecimal; | ||||
|  | ||||
| @@ -27,4 +25,11 @@ public class SysDishesIngredient extends SysIngredient { | ||||
|  | ||||
|     private String remark; | ||||
|  | ||||
|     private Long id; | ||||
|  | ||||
|     private String cus_unit; | ||||
|  | ||||
|     private String cus_weight; | ||||
|  | ||||
|  | ||||
| } | ||||
| @@ -1,47 +1,17 @@ | ||||
| package com.stdiet.custom.domain; | ||||
|  | ||||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
|  | ||||
| @Data | ||||
| public class SysRecipes { | ||||
|     private static final long serialVersionUID = 1L; | ||||
|  | ||||
|     private Long id; | ||||
|  | ||||
|     private Integer numDay; | ||||
|     private Long cusId; | ||||
|  | ||||
|     private List<SysDishes> dishes; | ||||
|     private Long planId; | ||||
|  | ||||
|     private Integer reviewStatus; | ||||
|  | ||||
|     /** | ||||
|      * 创建者 | ||||
|      */ | ||||
|     private String createBy; | ||||
|  | ||||
|     /** | ||||
|      * 创建时间 | ||||
|      */ | ||||
|     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||||
|     private Date createTime; | ||||
|  | ||||
|     /** | ||||
|      * 更新者 | ||||
|      */ | ||||
|     private String updateBy; | ||||
|  | ||||
|     /** | ||||
|      * 更新时间 | ||||
|      */ | ||||
|     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||||
|     private Date updateTime; | ||||
|  | ||||
|     /** | ||||
|      * 备注 | ||||
|      */ | ||||
|     private String remark; | ||||
|     private List<SysRecipesDaily> menus; | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,34 @@ | ||||
| package com.stdiet.custom.domain; | ||||
|  | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
|  | ||||
| @Data | ||||
| public class SysRecipesDaily { | ||||
|     private Long id; | ||||
|  | ||||
|     private Integer numDay; | ||||
|  | ||||
|     private Date date; | ||||
|  | ||||
|     private Long recipesId; | ||||
|  | ||||
|     private Long cusId; | ||||
|  | ||||
|     private Integer reviewStatus; | ||||
|  | ||||
|     private Date createTime; | ||||
|  | ||||
|     private String createBy; | ||||
|  | ||||
|     private Date updateTime; | ||||
|  | ||||
|     private String updateBy; | ||||
|  | ||||
|     private String remark; | ||||
|  | ||||
|     private List<SysRecipesDailyDishes> dishes; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,28 @@ | ||||
| package com.stdiet.custom.domain; | ||||
|  | ||||
| import com.alibaba.fastjson.JSONArray; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
|  | ||||
| @Data | ||||
| public class SysRecipesDailyDishes { | ||||
|     private Long id; | ||||
|  | ||||
|     private Long menuId; | ||||
|  | ||||
|     private String name; | ||||
|  | ||||
|     private Long dishesId; | ||||
|  | ||||
|     private JSONArray detail; | ||||
|  | ||||
|     private String methods; | ||||
|  | ||||
|     private List<SysDishesIngredient> igdList; | ||||
|  | ||||
|     private String type; | ||||
|  | ||||
|     private Integer isMain; | ||||
| } | ||||
| @@ -26,6 +26,8 @@ public class SysRecipesPlan extends BaseEntity | ||||
|     //@Excel(name = "订单ID") | ||||
|     private Long orderId; | ||||
|  | ||||
|     private Long cusId; | ||||
|  | ||||
|     //客户ID | ||||
|     private Long customerId; | ||||
|  | ||||
|   | ||||
| @@ -1,10 +1,28 @@ | ||||
| package com.stdiet.custom.mapper; | ||||
|  | ||||
| import com.stdiet.custom.domain.SysRecipes; | ||||
| import com.stdiet.custom.domain.SysRecipesDaily; | ||||
| import com.stdiet.custom.domain.SysRecipesDailyDishes; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| public interface SysRecipesMapper { | ||||
|  | ||||
|  | ||||
|     public int addRecipes(SysRecipes sysRecipes); | ||||
|  | ||||
|     public int bashAddDishes(List<SysRecipesDailyDishes> dishes); | ||||
|  | ||||
|     public int bashAddMenus(List<SysRecipesDaily> menus); | ||||
|  | ||||
|  | ||||
|     public int getNumDayByCusId(Long id); | ||||
|  | ||||
|     public List<SysRecipes> selectSysRecipesByRecipesId(Long id); | ||||
|  | ||||
|     public int updateDishesDetail(SysRecipesDailyDishes sysRecipesDaily); | ||||
|  | ||||
|     public int addDishes(SysRecipesDailyDishes sysRecipesDaily); | ||||
|  | ||||
|     public int deleteDishes(Long id); | ||||
| } | ||||
|   | ||||
| @@ -1,9 +1,20 @@ | ||||
| package com.stdiet.custom.service; | ||||
|  | ||||
| import com.stdiet.custom.domain.SysRecipes; | ||||
| import com.stdiet.custom.domain.SysRecipesDaily; | ||||
| import com.stdiet.custom.domain.SysRecipesDailyDishes; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| public interface ISysRecipesService { | ||||
|  | ||||
|     public int addRecipes(SysRecipes sysRecipes); | ||||
|  | ||||
|     public List<SysRecipes> selectSysRecipesByRecipesId(Long id); | ||||
|  | ||||
|     public int updateDishesDetail(SysRecipesDailyDishes sysRecipesDaily); | ||||
|  | ||||
|     public int addDishes(SysRecipesDailyDishes sysRecipesDaily); | ||||
|  | ||||
|     public int deleteDishes(Long id); | ||||
| } | ||||
|   | ||||
| @@ -1,24 +1,24 @@ | ||||
| package com.stdiet.custom.service.impl; | ||||
|  | ||||
| import com.stdiet.common.utils.DateUtils; | ||||
| import com.stdiet.common.utils.SynchrolockUtil; | ||||
| import com.stdiet.custom.domain.SysOrder; | ||||
| import com.stdiet.custom.domain.SysOrderPause; | ||||
| import com.stdiet.custom.domain.SysRecipesPlan; | ||||
| import com.stdiet.custom.mapper.SysRecipesPlanMapper; | ||||
| import com.stdiet.custom.service.ISysOrderPauseService; | ||||
| import com.stdiet.custom.service.ISysOrderService; | ||||
| import com.stdiet.custom.service.ISysRecipesPlanService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.scheduling.annotation.Async; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
|  | ||||
| import java.time.LocalDate; | ||||
| import java.time.temporal.ChronoUnit; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import com.stdiet.common.utils.DateUtils; | ||||
| import com.stdiet.common.utils.SynchrolockUtil; | ||||
| import com.stdiet.custom.domain.SysOrder; | ||||
| import com.stdiet.custom.domain.SysOrderPause; | ||||
| import com.stdiet.custom.service.ISysOrderPauseService; | ||||
| import com.stdiet.custom.service.ISysOrderService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.data.annotation.QueryAnnotation; | ||||
| import org.springframework.scheduling.annotation.Async; | ||||
| import org.springframework.stereotype.Service; | ||||
| import com.stdiet.custom.mapper.SysRecipesPlanMapper; | ||||
| import com.stdiet.custom.domain.SysRecipesPlan; | ||||
| import com.stdiet.custom.service.ISysRecipesPlanService; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
|  | ||||
| /** | ||||
|  * 食谱计划Service业务层处理 | ||||
| @@ -28,22 +28,17 @@ import org.springframework.transaction.annotation.Transactional; | ||||
|  */ | ||||
| @Service("sysRecipesPlanService") | ||||
| @Transactional | ||||
| public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
| { | ||||
| public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { | ||||
|     public static final String generateRecipesPlanLockKey = "generateRecipesPlanLock::%s"; | ||||
|     @Autowired | ||||
|     private SysRecipesPlanMapper sysRecipesPlanMapper; | ||||
|  | ||||
|     @Autowired | ||||
|     private ISysOrderService sysOrderService; | ||||
|  | ||||
|     @Autowired | ||||
|     private ISysOrderPauseService sysOrderPauseService; | ||||
|  | ||||
|     @Autowired | ||||
|     private SynchrolockUtil synchrolockUtil; | ||||
|  | ||||
|     public static final String generateRecipesPlanLockKey = "generateRecipesPlanLock::%s"; | ||||
|  | ||||
|     /** | ||||
|      * 查询食谱计划 | ||||
|      * | ||||
| @@ -51,8 +46,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|      * @return 食谱计划 | ||||
|      */ | ||||
|     @Override | ||||
|     public SysRecipesPlan selectSysRecipesPlanById(Long id) | ||||
|     { | ||||
|     public SysRecipesPlan selectSysRecipesPlanById(Long id) { | ||||
|         return sysRecipesPlanMapper.selectSysRecipesPlanById(id); | ||||
|     } | ||||
|  | ||||
| @@ -63,8 +57,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|      * @return 食谱计划 | ||||
|      */ | ||||
|     @Override | ||||
|     public List<SysRecipesPlan> selectSysRecipesPlanList(SysRecipesPlan sysRecipesPlan) | ||||
|     { | ||||
|     public List<SysRecipesPlan> selectSysRecipesPlanList(SysRecipesPlan sysRecipesPlan) { | ||||
|         return sysRecipesPlanMapper.selectSysRecipesPlanList(sysRecipesPlan); | ||||
|     } | ||||
|  | ||||
| @@ -75,8 +68,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int insertSysRecipesPlan(SysRecipesPlan sysRecipesPlan) | ||||
|     { | ||||
|     public int insertSysRecipesPlan(SysRecipesPlan sysRecipesPlan) { | ||||
|         sysRecipesPlan.setCreateTime(DateUtils.getNowDate()); | ||||
|         return sysRecipesPlanMapper.insertSysRecipesPlan(sysRecipesPlan); | ||||
|     } | ||||
| @@ -88,8 +80,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int updateSysRecipesPlan(SysRecipesPlan sysRecipesPlan) | ||||
|     { | ||||
|     public int updateSysRecipesPlan(SysRecipesPlan sysRecipesPlan) { | ||||
|         sysRecipesPlan.setUpdateTime(DateUtils.getNowDate()); | ||||
|         //目前只能修改发送状态,所以修改时加上发送时间 | ||||
|         sysRecipesPlan.setSendTime(DateUtils.getNowDate()); | ||||
| @@ -103,8 +94,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteSysRecipesPlanByIds(Long[] ids) | ||||
|     { | ||||
|     public int deleteSysRecipesPlanByIds(Long[] ids) { | ||||
|         return sysRecipesPlanMapper.deleteSysRecipesPlanByIds(ids); | ||||
|     } | ||||
|  | ||||
| @@ -115,8 +105,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteSysRecipesPlanById(Long id) | ||||
|     { | ||||
|     public int deleteSysRecipesPlanById(Long id) { | ||||
|         return sysRecipesPlanMapper.deleteSysRecipesPlanById(id); | ||||
|     } | ||||
|  | ||||
| @@ -128,47 +117,47 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|      */ | ||||
|     @Override | ||||
|     @Async | ||||
|     public void regenerateRecipesPlan(Long orderId){ | ||||
|         if(orderId == null || orderId <= 0){ | ||||
|     public void regenerateRecipesPlan(Long orderId) { | ||||
|         if (orderId == null || orderId <= 0) { | ||||
|             return; | ||||
|         } | ||||
|         SysOrder sysOrder = sysOrderService.selectSysOrderById(orderId); | ||||
|         //订单为空、金额小于0不进行食谱生成、更新,只对2021年开始的订单进行食谱计划生成 | ||||
|         if(sysOrder == null && DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear() < 2021){ | ||||
|         if (sysOrder == null && DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear() < 2021) { | ||||
|             return; | ||||
|         } | ||||
|         System.out.println(DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear()); | ||||
|         try{ | ||||
| //        System.out.println(DateUtils.dateToLocalDate(sysOrder.getOrderTime()).getYear()); | ||||
|         try { | ||||
|             //获取redis中该订单对应的锁 | ||||
|             if(synchrolockUtil.lock(String.format(generateRecipesPlanLockKey, orderId))){ | ||||
|             if (synchrolockUtil.lock(String.format(generateRecipesPlanLockKey, orderId))) { | ||||
|                 SysRecipesPlan queryParam = new SysRecipesPlan(); | ||||
|                 queryParam.setOrderId(orderId); | ||||
|                 List<SysRecipesPlan> oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam); | ||||
|                 //判断是否已存在食谱 | ||||
|                 if(oldRecipesPlanList != null && oldRecipesPlanList.size() > 0){ | ||||
|                 if (oldRecipesPlanList != null && oldRecipesPlanList.size() > 0) { | ||||
|                     Long[] orderIdArray = new Long[1]; | ||||
|                     orderIdArray[0] = orderId; | ||||
|                     //删除该订单对于食谱 | ||||
|                     delRecipesPlanByOrderId(orderIdArray); | ||||
|                 } | ||||
|                 //判断订单金额、开始时间、结束时间,为空则直接返回,不重新生成食谱计划 | ||||
|                 if(sysOrder.getAmount().floatValue() <= 0 || sysOrder.getStartTime() == null || sysOrder.getServerEndTime() == null){ | ||||
|                 if (sysOrder.getAmount().floatValue() <= 0 || sysOrder.getStartTime() == null || sysOrder.getServerEndTime() == null) { | ||||
|                     return; | ||||
|                 } | ||||
|                 SysOrderPause pauseParam = new SysOrderPause(); | ||||
|                 pauseParam.setOrderId(sysOrder.getOrderId()); | ||||
|                 //暂停记录列表 | ||||
|                 List<SysOrderPause> pauseList = sysOrderPauseService.selectSysOrderPauseList(pauseParam); | ||||
|                 List<SysRecipesPlan> planList = generatePlan(orderId, oldRecipesPlanList, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList); | ||||
|                 if(planList != null && planList.size() > 0){ | ||||
|                 List<SysRecipesPlan> planList = generatePlan(sysOrder, oldRecipesPlanList, | ||||
|                         DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList); | ||||
|                 if (planList != null && planList.size() > 0) { | ||||
|                     sysRecipesPlanMapper.insertBatch(planList); | ||||
|                 } | ||||
|                 /*for (SysRecipesPlan sysRecipesPlan : planList) { | ||||
|                      getTestDate(sysRecipesPlan.getStartDate(), sysRecipesPlan.getEndDate()); | ||||
|                  }*/ | ||||
|             } | ||||
|         } | ||||
|         catch (Exception e) { | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|         } finally { | ||||
|             // 一定要释放锁 | ||||
| @@ -176,32 +165,34 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void getTestDate(Date date, Date date2){ | ||||
|     public void getTestDate(Date date, Date date2) { | ||||
|         LocalDate d = DateUtils.dateToLocalDate(date); | ||||
|         LocalDate d2 =  DateUtils.dateToLocalDate(date2); | ||||
|         String s1 = d.getYear() +"-" + d.getMonthValue() + "-" + d.getDayOfMonth(); | ||||
|         String s2 = d2.getYear() +"-" + d2.getMonthValue() + "-" + d2.getDayOfMonth(); | ||||
|         LocalDate d2 = DateUtils.dateToLocalDate(date2); | ||||
|         String s1 = d.getYear() + "-" + d.getMonthValue() + "-" + d.getDayOfMonth(); | ||||
|         String s2 = d2.getYear() + "-" + d2.getMonthValue() + "-" + d2.getDayOfMonth(); | ||||
|         System.out.println(s1 + "   " + s2); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID、订单开始服务时间、结束时间、暂停列表生成食谱计划列表 | ||||
|      * @param orderId 订单ID | ||||
|      * | ||||
|      * @param sysOrder           订单对象 | ||||
|      * @param oldRecipesPlanList 旧的食谱计划 | ||||
|      * @param serverStartDate 服务开始时间 | ||||
|      * @param serverEndDate 服务结束时间 | ||||
|      * @param pauseList 暂停列表 | ||||
|      * @param serverStartDate    服务开始时间 | ||||
|      * @param serverEndDate      服务结束时间 | ||||
|      * @param pauseList          暂停列表 | ||||
|      * @return | ||||
|      */ | ||||
|     public List<SysRecipesPlan> generatePlan(Long orderId, List<SysRecipesPlan> oldRecipesPlanList, LocalDate serverStartDate, LocalDate serverEndDate, List<SysOrderPause> pauseList){ | ||||
|     public List<SysRecipesPlan> generatePlan(SysOrder sysOrder, List<SysRecipesPlan> oldRecipesPlanList, | ||||
|                                              LocalDate serverStartDate, LocalDate serverEndDate, List<SysOrderPause> pauseList) { | ||||
|         List<SysRecipesPlan> planList = new ArrayList<>(); | ||||
|         boolean breakFlag = false; | ||||
|         LocalDate planStartDate = serverStartDate; | ||||
|         LocalDate planEndDate = planStartDate.plusDays(6); | ||||
|         while (true){ | ||||
|         while (true) { | ||||
|             SysRecipesPlan sysRecipesPlan = new SysRecipesPlan(); | ||||
|             //判断是否大于服务到期时间 | ||||
|             if(ChronoUnit.DAYS.between(planEndDate, serverEndDate) <= 0){ | ||||
|             if (ChronoUnit.DAYS.between(planEndDate, serverEndDate) <= 0) { | ||||
|                 planEndDate = serverEndDate; | ||||
|                 breakFlag = true; | ||||
|             } | ||||
| @@ -210,14 +201,15 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|             planEndDate = planEndDate.plusDays(pauseDay); | ||||
|             sysRecipesPlan.setStartDate(DateUtils.localDateToDate(planStartDate)); | ||||
|             sysRecipesPlan.setEndDate(DateUtils.localDateToDate(planEndDate)); | ||||
|             sysRecipesPlan.setOrderId(orderId); | ||||
|             sysRecipesPlan.setOrderId(sysOrder.getOrderId()); | ||||
|             sysRecipesPlan.setCusId(sysOrder.getCusId()); | ||||
|             /*//当开始时间小于等于当前时间,默认为已发送,发送时间为前一天 | ||||
|             if(ChronoUnit.DAYS.between(planStartDate, LocalDate.now()) >= 0){ | ||||
|                 sysRecipesPlan.setSendFlag(1); | ||||
|                 sysRecipesPlan.setSendTime(DateUtils.localDateToDate(LocalDate.now().minusDays(1))); | ||||
|             }*/ | ||||
|             //将旧食谱计划中的发送状态、发送时间、食谱复制到新食谱计划中 | ||||
|             boolean existFlag =oldRecipesPlanList.size() >= planList.size()+1; | ||||
|             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); | ||||
| @@ -227,7 +219,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|             planStartDate = planEndDate.plusDays(1); | ||||
|             planEndDate = planStartDate.plusDays(6); | ||||
|  | ||||
|             if(breakFlag){ | ||||
|             if (breakFlag) { | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
| @@ -236,25 +228,26 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|  | ||||
|     /** | ||||
|      * 根据食谱开始时间、结束时间、暂停列表获取在食谱计划范围内的暂停天数 | ||||
|      * | ||||
|      * @param planStartDate 计划开始时间 | ||||
|      * @param planEndDate 计划结束时间 | ||||
|      * @param pauseList  暂停列表 | ||||
|      * @param planEndDate   计划结束时间 | ||||
|      * @param pauseList     暂停列表 | ||||
|      * @return | ||||
|      */ | ||||
|     public long getPauseDayeCount(LocalDate planStartDate, LocalDate planEndDate, List<SysOrderPause> pauseList){ | ||||
|     public long getPauseDayeCount(LocalDate planStartDate, LocalDate planEndDate, List<SysOrderPause> pauseList) { | ||||
|         long pauseDay = 0; | ||||
|         //判断这个时间内是否存在暂停 | ||||
|         if(pauseList != null && pauseList.size() > 0){ | ||||
|             for(SysOrderPause sysOrderPause : pauseList){ | ||||
|         if (pauseList != null && pauseList.size() > 0) { | ||||
|             for (SysOrderPause sysOrderPause : pauseList) { | ||||
|                 LocalDate pauseStartDate = DateUtils.dateToLocalDate(sysOrderPause.getPauseStartDate()); | ||||
|                 LocalDate pauseEndDate = DateUtils.dateToLocalDate(sysOrderPause.getPauseEndDate()); | ||||
|                 if(ChronoUnit.DAYS.between(pauseEndDate, planStartDate) > 0 || ChronoUnit.DAYS.between(planEndDate, pauseStartDate) > 0){ | ||||
|                 if (ChronoUnit.DAYS.between(pauseEndDate, planStartDate) > 0 || ChronoUnit.DAYS.between(planEndDate, pauseStartDate) > 0) { | ||||
|                     continue; | ||||
|                 } | ||||
|                 if(ChronoUnit.DAYS.between(pauseStartDate, planStartDate) > 0){ | ||||
|                 if (ChronoUnit.DAYS.between(pauseStartDate, planStartDate) > 0) { | ||||
|                     pauseStartDate = planStartDate; | ||||
|                 } | ||||
|                 if(ChronoUnit.DAYS.between(planEndDate, pauseEndDate) > 0){ | ||||
|                 if (ChronoUnit.DAYS.between(planEndDate, pauseEndDate) > 0) { | ||||
|                     pauseEndDate = planEndDate; | ||||
|                 } | ||||
|                 pauseDay += ChronoUnit.DAYS.between(pauseStartDate, pauseEndDate); | ||||
| @@ -265,31 +258,34 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID删除所有食谱安排计划 | ||||
|      * | ||||
|      * @param orderIds 订单ID | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public int delRecipesPlanByOrderId(Long[] orderIds){ | ||||
|     public int delRecipesPlanByOrderId(Long[] orderIds) { | ||||
|         return sysRecipesPlanMapper.delRecipesPlanByOrderId(orderIds); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 多条件查询食谱计划列表 | ||||
|      * | ||||
|      * @param sysRecipesPlan | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public List<SysRecipesPlan> selectPlanListByCondition(SysRecipesPlan sysRecipesPlan){ | ||||
|     public List<SysRecipesPlan> selectPlanListByCondition(SysRecipesPlan sysRecipesPlan) { | ||||
|         return sysRecipesPlanMapper.selectPlanListByCondition(sysRecipesPlan); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据订单ID查询食谱计划 | ||||
|      * | ||||
|      * @param sysRecipesPlan | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public List<SysRecipesPlan> selectPlanListByOrderId(SysRecipesPlan sysRecipesPlan){ | ||||
|     public List<SysRecipesPlan> selectPlanListByOrderId(SysRecipesPlan sysRecipesPlan) { | ||||
|         return sysRecipesPlanMapper.selectPlanListByOrderId(sysRecipesPlan); | ||||
|     } | ||||
| } | ||||
| @@ -1,12 +1,18 @@ | ||||
| package com.stdiet.custom.service.impl; | ||||
|  | ||||
| import com.stdiet.custom.domain.SysRecipes; | ||||
| import com.stdiet.custom.domain.SysRecipesDaily; | ||||
| import com.stdiet.custom.domain.SysRecipesDailyDishes; | ||||
| import com.stdiet.custom.domain.SysRecipesPlan; | ||||
| import com.stdiet.custom.mapper.SysRecipesMapper; | ||||
| import com.stdiet.custom.mapper.SysRecipesPlanMapper; | ||||
| import com.stdiet.custom.service.ISysRecipesService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
|  | ||||
| @Service | ||||
| @@ -16,8 +22,64 @@ public class SysRecipesServiceImpl implements ISysRecipesService { | ||||
|     @Autowired | ||||
|     private SysRecipesMapper sysRecipesMapper; | ||||
|  | ||||
|     @Autowired | ||||
|     private SysRecipesPlanMapper sysRecipesPlanMapper; | ||||
|  | ||||
|  | ||||
|     @Override | ||||
|     public int addRecipes(SysRecipes sysRecipes) { | ||||
|         int rows = sysRecipesMapper.addRecipes(sysRecipes); | ||||
|         if (rows > 0) { | ||||
|             int count = sysRecipesMapper.getNumDayByCusId(sysRecipes.getCusId()); | ||||
|             List<SysRecipesDaily> menus = sysRecipes.getMenus(); | ||||
|             List<SysRecipesDailyDishes> dishes = new ArrayList<>(); | ||||
|             int size = menus.size(); | ||||
|             for (int i = 0; i < size; i++) { | ||||
|                 SysRecipesDaily tarMenu = menus.get(i); | ||||
|                 // 计算menuId | ||||
|                 long dailyId = sysRecipes.getId() + new Date().getTime() + i; | ||||
|                 tarMenu.setId(dailyId); | ||||
|                 // 插入recipiesId | ||||
|                 tarMenu.setRecipesId(sysRecipes.getId()); | ||||
|                 // 插入numDay | ||||
|                 tarMenu.setNumDay(count + i + 1); | ||||
|                 for (SysRecipesDailyDishes tmpDishes : tarMenu.getDishes()) { | ||||
|                     // 让菜品插入menuId | ||||
|                     tmpDishes.setMenuId(dailyId); | ||||
|                     dishes.add(tmpDishes); | ||||
|                 } | ||||
|             } | ||||
|             // 插入每天食谱 | ||||
|             sysRecipesMapper.bashAddMenus(menus); | ||||
|             // 插入每天菜品 | ||||
|             sysRecipesMapper.bashAddDishes(dishes); | ||||
|             // 更新食谱计划 | ||||
|             SysRecipesPlan sysRecipesPlan = new SysRecipesPlan(); | ||||
|             sysRecipesPlan.setId(sysRecipes.getPlanId()); | ||||
|             sysRecipesPlan.setRecipesId(sysRecipes.getId()); | ||||
|             sysRecipesPlanMapper.updateSysRecipesPlan(sysRecipesPlan); | ||||
|         } | ||||
|  | ||||
|         return rows; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<SysRecipes> selectSysRecipesByRecipesId(Long id) { | ||||
|         return sysRecipesMapper.selectSysRecipesByRecipesId(id); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int updateDishesDetail(SysRecipesDailyDishes sysRecipesDailyDishes) { | ||||
|         return sysRecipesMapper.updateDishesDetail(sysRecipesDailyDishes); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int addDishes(SysRecipesDailyDishes sysRecipesDailyDishes) { | ||||
|         return sysRecipesMapper.addDishes(sysRecipesDailyDishes); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int deleteDishes(Long id) { | ||||
|         return sysRecipesMapper.deleteDishes(id); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -4,7 +4,7 @@ | ||||
|         "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
| <mapper namespace="com.stdiet.custom.mapper.SysRecipesMapper"> | ||||
|  | ||||
|     <resultMap type="SysRecipes" id="SysRecipesResult"> | ||||
|     <resultMap type="SysRecipesDaily" id="SysRecipesResult"> | ||||
|         <result property="id" column="id"/> | ||||
|         <result property="numDay" column="num_day"/> | ||||
|         <result property="updateBy" column="update_by"/> | ||||
| @@ -15,14 +15,16 @@ | ||||
|         <association property="dishes" column="id" select="selectDishesByMenuId"/> | ||||
|     </resultMap> | ||||
|  | ||||
|     <resultMap id="SysDishesResult" type="SysDishes"> | ||||
|         <result property="id" column="dishes_id"/> | ||||
|     <resultMap id="SysDishesResult" type="SysRecipesDailyDishes"> | ||||
|         <result property="dishesId" column="dishes_id"/> | ||||
|         <result property="menuId" column="menu_id"/> | ||||
|         <result property="id" column="id" /> | ||||
|         <result property="name" column="name"/> | ||||
|         <result property="type" column="type"/> | ||||
|         <result property="methods" column="methods"/> | ||||
|         <result property="isMain" column="is_main"/> | ||||
|         <result property="detail" column="detail" typeHandler="com.stdiet.custom.typehandler.ArrayJsonHandler" | ||||
|                 javaType="com.stdiet.custom.domain.SysDishesIngredientInfo"/> | ||||
|                 javaType="com.stdiet.custom.domain.SysDishesIngredient"/> | ||||
|         <association property="igdList" column="dishes_id" select="selectIngredientsByDishesId"/> | ||||
|     </resultMap> | ||||
|  | ||||
| @@ -76,4 +78,67 @@ | ||||
|         ) ing USING(id) | ||||
|     </select> | ||||
|  | ||||
|     <!-- 更新菜品--> | ||||
|     <update id="updateDishesDetail" parameterType="SysRecipesDailyDishes"> | ||||
|         update sys_customer_menu_dishes | ||||
|         <trim prefix="SET" suffixOverrides=","> | ||||
|             <if test="detail != null">detail = #{detail, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ArrayJsonHandler},</if> | ||||
|         </trim> | ||||
|         where id = #{id} | ||||
|     </update> | ||||
|  | ||||
|     <!-- 插入菜品--> | ||||
|     <insert id="addDishes" parameterType="SysRecipesDailyDishes" useGeneratedKeys="true" keyProperty="id"> | ||||
|         insert into sys_customer_menu_dishes | ||||
|         <trim prefix="(" suffix=")" suffixOverrides=","> | ||||
|             <if test="menuId != null">menu_id,</if> | ||||
|             <if test="dishesId != null">dishes_id,</if> | ||||
|             <if test="type != null">type,</if> | ||||
|             <if test="detail != null">detail,</if> | ||||
|         </trim> | ||||
|         <trim prefix="values (" suffix=")" suffixOverrides=","> | ||||
|             <if test="menuId != null">#{menuId},</if> | ||||
|             <if test="dishesId != null">#{dishesId},</if> | ||||
|             <if test="type != null">#{type},</if> | ||||
|             <if test="detail != null">#{detail, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ArrayJsonHandler},</if> | ||||
|         </trim> | ||||
|     </insert> | ||||
|  | ||||
|     <!-- 删除菜品--> | ||||
|     <delete id="deleteDishes" parameterType="Long"> | ||||
|         delete from sys_customer_menu_dishes where id = #{id} | ||||
|     </delete> | ||||
|  | ||||
|     <!--    查询已有食谱天数--> | ||||
|     <select id="getNumDayByCusId" parameterType="Long" resultType="Integer"> | ||||
|         select count(*) from sys_customer_daily_menu where cus_id = #{id} | ||||
|     </select> | ||||
|      | ||||
|     <!--  新增食谱  --> | ||||
|     <insert id="addRecipes" parameterType="SysRecipes" useGeneratedKeys="true" keyProperty="id"> | ||||
|         insert into sys_customer_menu | ||||
|         <trim prefix="(" suffix=")" suffixOverrides=","> | ||||
|             <if test="cusId != null">cus_id,</if> | ||||
|         </trim> | ||||
|         <trim prefix="values (" suffix=")" suffixOverrides=","> | ||||
|             <if test="cusId != null">#{cusId},</if> | ||||
|         </trim> | ||||
|     </insert> | ||||
|  | ||||
|     <!--  新增每菜单 --> | ||||
|     <insert id="bashAddMenus"> | ||||
|         insert into sys_customer_daily_menu (id, num_day, date, recipes_id, cus_id) values | ||||
|         <foreach collection="list" separator="," item="item" index="index"> | ||||
|             (#{item.id}, #{item.numDay}, #{item.date}, #{item.recipesId}, #{item.cusId}) | ||||
|         </foreach> | ||||
|     </insert> | ||||
|  | ||||
|     <!--    新增菜单对应菜品--> | ||||
|     <insert id="bashAddDishes" > | ||||
|         insert into sys_customer_menu_dishes (menu_id, type, dishes_id, detail) values | ||||
|         <foreach collection="list" separator="," item="item" index="index"> | ||||
|             (#{item.menuId}, #{item.type}, #{item.dishesId}, #{item.detail, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ArrayJsonHandler}) | ||||
|         </foreach> | ||||
|     </insert> | ||||
|  | ||||
| </mapper> | ||||
| @@ -17,6 +17,7 @@ | ||||
|         <result property="updateTime"    column="update_time"    /> | ||||
|         <result property="updateBy"    column="update_by"    /> | ||||
|         <result property="delFlag"    column="del_flag"    /> | ||||
|         <result property="cusId"    column="cus_id"    /> | ||||
|         <!-- 非持久化字段 --> | ||||
|         <result property="customerId" column="cus_id"></result><!-- 客户ID --> | ||||
|         <result property="customer"    column="customer"    /><!-- 客户姓名 --> | ||||
| @@ -127,7 +128,7 @@ | ||||
|  | ||||
|     <!-- 食谱计划、订单表联查 --> | ||||
|     <select id="selectPlanListByCondition" parameterType="SysRecipesPlan" resultMap="SysRecipesPlanResult"> | ||||
|       SELECT srp.id,srp.order_id,sr.customer,sr.cus_id,sr.phone,su_nutritionist.nick_name nutritionist,su_nutritionist_assis.nick_name AS nutritionist_assis,sr.start_time,sr.server_end_time, srp.start_date,srp.end_date,srp.send_flag,srp.send_time | ||||
|       SELECT srp.id,srp.order_id,srp.recipes_id,sr.customer,sr.cus_id,sr.phone,su_nutritionist.nick_name nutritionist,su_nutritionist_assis.nick_name AS nutritionist_assis,sr.start_time,sr.server_end_time, srp.start_date,srp.end_date,srp.send_flag,srp.send_time | ||||
|       FROM sys_recipes_plan srp | ||||
|       LEFT JOIN sys_order sr ON sr.order_id = srp.order_id | ||||
|       LEFT JOIN sys_user su_nutritionist ON su_nutritionist.user_id = sr.nutritionist_id AND su_nutritionist.del_flag = 0 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user