commit
39171fd12d
stdiet-common/src/main/java/com/stdiet/common/utils
stdiet-custom/src/main
java/com/stdiet/custom
domain
mapper
service
resources/mapper/custom
stdiet-ui
@ -7,6 +7,7 @@ import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
|
||||
@ -186,4 +187,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
|
||||
return Date.from(zonedDateTime.toInstant());
|
||||
}
|
||||
|
||||
public static String localDateToString(LocalDate date, String pattern){
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern);
|
||||
return date.format(fmt);
|
||||
}
|
||||
|
||||
public static LocalDate stringToLocalDate(String date, String pattern){
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern);
|
||||
return LocalDate.parse(date, fmt);
|
||||
}
|
||||
}
|
||||
|
@ -116,6 +116,10 @@ public class SysRecipesPlan {
|
||||
*/
|
||||
private Integer reviewStatus;
|
||||
|
||||
/** 该食谱计划中暂停日期,使用 | 隔开 */
|
||||
//@Excel(name = "该食谱计划中暂停日期,使用 | 隔开")
|
||||
private String pauseDate;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
|
@ -75,4 +75,11 @@ public interface SysOrderPauseMapper
|
||||
int deletePauseByOrderId(Long[] orderIds);
|
||||
|
||||
long selectNearMainOrderIdByCusId(Long cusId);
|
||||
|
||||
/**
|
||||
* 根据订单ID获取暂停计划
|
||||
* @param orderId
|
||||
* @return
|
||||
*/
|
||||
List<SysOrderPause> getPauseListByOrderId(@Param("orderId")Long orderId);
|
||||
}
|
@ -73,5 +73,12 @@ public interface ISysOrderPauseService
|
||||
*/
|
||||
int deletePauseByOrderId(Long[] orderIds);
|
||||
|
||||
/**
|
||||
* 根据订单ID获取暂停记录
|
||||
* @param orderId
|
||||
* @return
|
||||
*/
|
||||
List<SysOrderPause> getPauseListByOrderId(Long orderId);
|
||||
|
||||
long selectNearMainOrderIdByCusId(Long cusId);
|
||||
}
|
@ -140,6 +140,16 @@ public class SysOrderPauseServiceImpl implements ISysOrderPauseService
|
||||
return sysOrderPauseMapper.deletePauseByOrderId(orderIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单ID获取暂停计划
|
||||
* @param orderId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysOrderPause> getPauseListByOrderId(Long orderId){
|
||||
return sysOrderPauseMapper.getPauseListByOrderId(orderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long selectNearMainOrderIdByCusId(Long cusId) {
|
||||
return sysOrderPauseMapper.selectNearMainOrderIdByCusId(cusId);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.stdiet.custom.service.impl;
|
||||
|
||||
import com.stdiet.common.utils.DateUtils;
|
||||
import com.stdiet.common.utils.StringUtils;
|
||||
import com.stdiet.common.utils.SynchrolockUtil;
|
||||
import com.stdiet.common.utils.sign.Md5Utils;
|
||||
import com.stdiet.custom.domain.SysOrder;
|
||||
@ -18,9 +19,7 @@ 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 java.util.*;
|
||||
|
||||
/**
|
||||
* 食谱计划Service业务层处理
|
||||
@ -150,10 +149,8 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
SysRecipesPlan queryParam = new SysRecipesPlan();
|
||||
queryParam.setOrderId(orderId);
|
||||
List<SysRecipesPlan> oldRecipesPlanList = sysRecipesPlanMapper.selectSysRecipesPlanList(queryParam);
|
||||
SysOrderPause pauseParam = new SysOrderPause();
|
||||
pauseParam.setOrderId(sysOrder.getOrderId());
|
||||
//暂停记录列表
|
||||
List<SysOrderPause> pauseList = sysOrderPauseService.selectSysOrderPauseList(pauseParam);
|
||||
//暂停记录列表,按暂停开始时间顺序
|
||||
List<SysOrderPause> pauseList = sysOrderPauseService.getPauseListByOrderId(sysOrder.getOrderId());
|
||||
List<SysRecipesPlan> planList = generatePlan(sysOrder, oldRecipesPlanList, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList);
|
||||
if(oldRecipesPlanList != null && oldRecipesPlanList.size() > 0){
|
||||
updateOrAddRecipesPlan(oldRecipesPlanList, planList);
|
||||
@ -184,9 +181,13 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
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);
|
||||
if(plan.getStartDate().compareTo(newRecipesPlanList.get(index).getStartDate()) != 0
|
||||
|| plan.getEndDate().compareTo(newRecipesPlanList.get(index).getEndDate()) != 0){
|
||||
plan.setStartDate(newRecipesPlanList.get(index).getStartDate());
|
||||
plan.setEndDate(newRecipesPlanList.get(index).getEndDate());
|
||||
plan.setPauseDate(newRecipesPlanList.get(index).getPauseDate());
|
||||
updateList.add(plan);
|
||||
}
|
||||
}else{
|
||||
delList.add(plan.getId());
|
||||
}
|
||||
@ -197,6 +198,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
}
|
||||
//更新
|
||||
if(updateList.size() > 0){
|
||||
System.out.println("更新数量:"+updateList.size());
|
||||
for (SysRecipesPlan plan : updateList) {
|
||||
sysRecipesPlanMapper.updateSysRecipesPlan(plan);
|
||||
}
|
||||
@ -230,19 +232,26 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
oldStartNumDay = oldRecipesPlanList.get(0).getStartNumDay() - 1;
|
||||
}
|
||||
List<SysRecipesPlan> planList = new ArrayList<>();
|
||||
boolean breakFlag = false;
|
||||
LocalDate planStartDate = serverStartDate;
|
||||
LocalDate planEndDate = planStartDate.plusDays(6);
|
||||
while (true) {
|
||||
LocalDate planStartDate = null;
|
||||
LocalDate planEndDate = serverStartDate.plusDays(-1);
|
||||
boolean breakFlag = true;
|
||||
do {
|
||||
SysRecipesPlan sysRecipesPlan = new SysRecipesPlan();
|
||||
planStartDate = planEndDate.plusDays(1);
|
||||
planEndDate = planStartDate.plusDays(6);
|
||||
//判断是否大于服务到期时间
|
||||
if (ChronoUnit.DAYS.between(planEndDate, serverEndDate) <= 0) {
|
||||
planEndDate = serverEndDate;
|
||||
breakFlag = true;
|
||||
breakFlag = false;
|
||||
}
|
||||
String[] pauseResult = dealPlanPause(planStartDate, planEndDate, pauseList);
|
||||
//开始时间变更为暂停结束之后的日期,因为暂停开始时间与食谱计划开始时间相同
|
||||
if(StringUtils.isNotEmpty(pauseResult[0])){
|
||||
planStartDate = DateUtils.stringToLocalDate(pauseResult[0],"yyyyMMdd");
|
||||
planEndDate = DateUtils.stringToLocalDate(pauseResult[1],"yyyyMMdd");
|
||||
}
|
||||
long pauseDay = getPauseDayeCount(planStartDate, planEndDate, pauseList);
|
||||
//加上暂停时间
|
||||
planEndDate = planEndDate.plusDays(pauseDay);
|
||||
planEndDate = planEndDate.plusDays(Integer.parseInt(pauseResult[2]));
|
||||
sysRecipesPlan.setStartDate(DateUtils.localDateToDate(planStartDate));
|
||||
sysRecipesPlan.setEndDate(DateUtils.localDateToDate(planEndDate));
|
||||
sysRecipesPlan.setOrderId(sysOrder.getOrderId());
|
||||
@ -252,30 +261,29 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
sysRecipesPlan.setStartNumDay(oldStartNumDay);
|
||||
oldStartNumDay += 6;
|
||||
sysRecipesPlan.setEndNumDay(oldStartNumDay);
|
||||
//暂停日期
|
||||
sysRecipesPlan.setPauseDate(pauseResult[3]);
|
||||
//添加暂停范围内的日期
|
||||
planList.add(sysRecipesPlan);
|
||||
|
||||
planStartDate = planEndDate.plusDays(1);
|
||||
planEndDate = planStartDate.plusDays(6);
|
||||
|
||||
if (breakFlag) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}while (breakFlag);
|
||||
return planList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据食谱开始时间、结束时间、暂停列表获取在食谱计划范围内的暂停天数
|
||||
*
|
||||
* @param planStartDate 计划开始时间
|
||||
* @param planEndDate 计划结束时间
|
||||
* @param pauseList 暂停列表
|
||||
* 根据食谱开始时间、结束时间、暂停列表获取在食谱计划范围内的暂停天数,以及返回调整之后的计划开始、结束时间,以及暂停日期
|
||||
* @param planStartDate 原先的计划开始时间
|
||||
* @param planEndDate 原先计划结束时间
|
||||
* @param pauseList 暂停列表集合
|
||||
* @return
|
||||
*/
|
||||
private long getPauseDayeCount(LocalDate planStartDate, LocalDate planEndDate, List<SysOrderPause> pauseList) {
|
||||
private String[] dealPlanPause(LocalDate planStartDate, LocalDate planEndDate, List<SysOrderPause> pauseList) {
|
||||
//分别为计划开始时间、计划结束时间,范围内暂停天数,具体暂停日期,使用|隔开
|
||||
String[] result = {"","","0",""};
|
||||
long pauseDay = 0;
|
||||
Set<String> pauseDateString = new TreeSet<>(new MyComparator());
|
||||
//判断这个时间内是否存在暂停
|
||||
if (pauseList != null && pauseList.size() > 0) {
|
||||
//每条暂停时间的范围不会重叠,在添加暂停时做了限制
|
||||
for (SysOrderPause sysOrderPause : pauseList) {
|
||||
LocalDate pauseStartDate = DateUtils.dateToLocalDate(sysOrderPause.getPauseStartDate());
|
||||
LocalDate pauseEndDate = DateUtils.dateToLocalDate(sysOrderPause.getPauseEndDate());
|
||||
@ -288,10 +296,48 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
||||
if (ChronoUnit.DAYS.between(planEndDate, pauseEndDate) > 0) {
|
||||
pauseEndDate = planEndDate;
|
||||
}
|
||||
pauseDay += ChronoUnit.DAYS.between(pauseStartDate, pauseEndDate);
|
||||
//判断暂停记录是否从食谱计划开始时间开始的
|
||||
if(ChronoUnit.DAYS.between(pauseStartDate, planStartDate) == 0){
|
||||
//记录该条暂停记录结束之后的第一天日期,如果两条记录连着,则取最后暂停结束之后的第一天
|
||||
if("".equals(result[0]) || result[0].equals(DateUtils.localDateToString(pauseStartDate,"yyyyMMdd"))){
|
||||
planStartDate = pauseEndDate.plusDays(1);
|
||||
planEndDate = planStartDate.plusDays(6);
|
||||
result[0] = DateUtils.localDateToString(planStartDate,"yyyyMMdd");
|
||||
result[1] = DateUtils.localDateToString(planEndDate,"yyyyMMdd");
|
||||
}
|
||||
}else{
|
||||
pauseDay += ChronoUnit.DAYS.between(pauseStartDate, pauseEndDate) + 1;
|
||||
pauseDateString.addAll(getPauseDateString(pauseStartDate, pauseEndDate));
|
||||
}
|
||||
}
|
||||
}
|
||||
return pauseDay;
|
||||
result[2] = pauseDay+"";
|
||||
result[3] = pauseDateString.size() > 0 ? StringUtils.join(pauseDateString,"|") : "";
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据暂停时间范围获取范围内的日期
|
||||
* @return
|
||||
*/
|
||||
private Set<String> getPauseDateString(LocalDate pauseStartDate, LocalDate pauseEndDate){
|
||||
Set<String> pauseDateList = new HashSet<>();
|
||||
long daysBetween = ChronoUnit.DAYS.between(pauseStartDate, pauseEndDate);
|
||||
for(int i = 0; i <= daysBetween; i++){
|
||||
pauseDateList.add(DateUtils.localDateToString(pauseStartDate.plusDays(i),"yyyyMMdd"));
|
||||
}
|
||||
return pauseDateList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 集合排序key值比较器
|
||||
* */
|
||||
class MyComparator implements Comparator<String>{
|
||||
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return Integer.parseInt(o1) - Integer.parseInt(o2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,4 +133,10 @@
|
||||
ORDER BY server_end_time ASC LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 根据订单ID获取暂停记录,根据暂停开始时间排序,用于生成食谱计划,不能随意修改排序方式 -->
|
||||
<select id="getPauseListByOrderId" parameterType="Long" resultMap="SysOrderPauseResult">
|
||||
<include refid="selectSysOrderPauseVo"></include>
|
||||
where sop.del_flag = 0 and sop.order_id = #{orderId} order by sop.pause_start_date asc
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -14,6 +14,7 @@
|
||||
<result property="recipesId" column="recipes_id"/>
|
||||
<result property="sendFlag" column="send_flag"/>
|
||||
<result property="sendTime" column="send_time"/>
|
||||
<result property="pauseDate" column="pause_date"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
@ -36,7 +37,7 @@
|
||||
|
||||
|
||||
<sql id="selectSysRecipesPlanVo">
|
||||
select id, order_id, cus_id, start_date, end_date, start_num_day, end_num_day, recipes_id, send_flag, send_time, create_time, create_by, update_time, update_by, del_flag, review_status from sys_recipes_plan
|
||||
select id, order_id, cus_id, start_date, end_date, start_num_day, end_num_day, recipes_id, send_flag, send_time, pause_date, create_time, create_by, update_time, update_by, del_flag, review_status from sys_recipes_plan
|
||||
</sql>
|
||||
|
||||
<select id="selectSysRecipesPlanList" parameterType="SysRecipesPlan" resultMap="SysRecipesPlanResult">
|
||||
@ -80,6 +81,7 @@
|
||||
<if test="recipesId != null">recipes_id,</if>
|
||||
<if test="sendFlag != null">send_flag,</if>
|
||||
<if test="sendTime != null">send_time,</if>
|
||||
<if test="pauseDate != null">pause_date,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
@ -99,6 +101,7 @@
|
||||
<if test="recipesId != null">#{recipesId},</if>
|
||||
<if test="sendFlag != null">#{sendFlag},</if>
|
||||
<if test="sendTime != null">#{sendTime},</if>
|
||||
<if test="pauseDate != null">#{pauseDate},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
@ -122,6 +125,7 @@
|
||||
<if test="recipesId != null">recipes_id = #{recipesId},</if>
|
||||
<if test="sendFlag != null">send_flag = #{sendFlag},</if>
|
||||
<if test="sendTime != null">send_time = #{sendTime},</if>
|
||||
<if test="pauseDate != null">pause_date = #{pauseDate},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
@ -136,27 +140,27 @@
|
||||
update sys_recipes_plan set del_flag = 1 where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteSysRecipesPlanByIds" parameterType="String">
|
||||
delete from sys_recipes_plan where id in
|
||||
<update id="deleteSysRecipesPlanByIds" parameterType="String">
|
||||
update sys_recipes_plan set del_flag = 1 where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</update>
|
||||
|
||||
<!-- 批量插入食谱计划 -->
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO sys_recipes_plan
|
||||
(order_id, cus_id, out_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, pause_date, recipes_id)
|
||||
VALUES
|
||||
<foreach collection="list" item="plan" separator=",">
|
||||
(#{plan.orderId}, #{plan.cusId}, #{plan.outId}, #{plan.startDate}, #{plan.endDate}, #{plan.startNumDay}, #{plan.endNumDay},
|
||||
#{plan.sendFlag}, #{plan.sendTime}, #{plan.recipesId})
|
||||
#{plan.sendFlag}, #{plan.sendTime}, #{plan.pauseDate}, #{plan.recipesId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<!-- 根据订单ID删除对应食谱计划 -->
|
||||
<update id="delRecipesPlanByOrderId" parameterType="String">
|
||||
delete from sys_recipes_plan where order_id in
|
||||
update sys_recipes_plan set del_flag = 1 where order_id in
|
||||
<foreach item="orderId" collection="array" open="(" separator="," close=")">
|
||||
#{orderId}
|
||||
</foreach>
|
||||
@ -217,7 +221,7 @@
|
||||
<!-- 根据cusId查询食谱计划-->
|
||||
<select id="selectPlanListByCusId" parameterType="Long" resultMap="SysRecipesPlanResult">
|
||||
select id, out_id, start_date, end_date, start_num_day, end_num_day, recipes_id, review_status from sys_recipes_plan
|
||||
where cus_id=#{cusId} order by id asc
|
||||
where cus_id=#{cusId} and del_flag = 0 order by id asc
|
||||
</select>
|
||||
|
||||
<select id="getCusIdByOutId" parameterType="String" resultType="Long">
|
||||
@ -235,7 +239,7 @@
|
||||
|
||||
<!-- 通过outId查询食谱计划简要-->
|
||||
<select id="selectRecipesPlanListInfo" resultMap="SysRecipesPlanListInfoResult">
|
||||
select id, start_date, end_date, start_num_day, end_num_day, recipes_id from sys_recipes_plan where out_id=#{outId}
|
||||
select id, start_date, end_date, start_num_day, end_num_day, recipes_id from sys_recipes_plan where out_id=#{outId} and del_flag = 0
|
||||
</select>
|
||||
|
||||
<resultMap type="SysRecipesDaily" id="SysRecipesResult">
|
||||
@ -244,7 +248,7 @@
|
||||
</resultMap>
|
||||
|
||||
<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 id, num_day from sys_customer_daily_menu where recipes_id=#{recipes_id} and del_flag = 0 order by num_day asc
|
||||
</select>
|
||||
|
||||
<!-- 批量修改食谱计划 -->
|
||||
@ -252,6 +256,6 @@
|
||||
<!--<foreach collection="list" item="item" separator=";" open="" close="">
|
||||
|
||||
</foreach>-->
|
||||
update sys_recipes_plan set start_date = #{startDate},end_date = #{endDate} where id = #{id}
|
||||
update sys_recipes_plan set start_date = #{startDate},end_date = #{endDate},pause_date=#{pauseDate} where id = #{id}
|
||||
</update>
|
||||
</mapper>
|
@ -34,7 +34,7 @@ module.exports = {
|
||||
proxy: {
|
||||
// detail: https://cli.vuejs.org/config/#devserver-proxy
|
||||
[process.env.VUE_APP_BASE_API]: {
|
||||
target: `http://localhost:8091`,
|
||||
target: `http://localhost:8090`,
|
||||
changeOrigin: true,
|
||||
pathRewrite: {
|
||||
['^' + process.env.VUE_APP_BASE_API]: ''
|
||||
|
Loading…
x
Reference in New Issue
Block a user