|
|
|
@@ -120,9 +120,9 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
*/
|
|
|
|
|
@Async
|
|
|
|
|
public void regenerateRecipesPlan(Long cusId) {
|
|
|
|
|
try{
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(5000);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (cusId == null || cusId <= 0) {
|
|
|
|
@@ -132,17 +132,17 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
//获取redis中该订单对应的锁
|
|
|
|
|
if (synchrolockUtil.lock(String.format(generateRecipesPlanLockKey, cusId))) {
|
|
|
|
|
List<SysOrder> customerOrderList = sysOrderService.getAllOrderByCusId(cusId);
|
|
|
|
|
if(customerOrderList != null && customerOrderList.size() > 0){
|
|
|
|
|
if (customerOrderList != null && customerOrderList.size() > 0) {
|
|
|
|
|
|
|
|
|
|
for(SysOrder sysOrder : customerOrderList){
|
|
|
|
|
for (SysOrder sysOrder : customerOrderList) {
|
|
|
|
|
//订单为空、金额小于0、订单未审核不进行食谱生成、更新,只对2021年开始的订单进行食谱计划生成,判断订单金额、开始时间、结束时间,为空则直接返回,不重新生成食谱计划
|
|
|
|
|
if (sysOrder == null || !sysOrder.getReviewStatus().equals("yes") || sysOrder.getAmount().floatValue() <= 0 || sysOrder.getStartTime() == null || sysOrder.getServerEndTime() == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//判断是否提成单,拆分单中的副单,体验单,定金单
|
|
|
|
|
if(sysOrder.getAfterSaleCommissOrder().intValue() == 1 || ("1".equals(sysOrder.getOrderType()) && sysOrder.getMainOrderId().intValue() != 0) ||
|
|
|
|
|
"2".equals(sysOrder.getOrderType()) || "1".equals(sysOrder.getOrderMoneyType())){
|
|
|
|
|
System.out.println("---------------------"+sysOrder.getOrderId()+"不生成食谱------------------------");
|
|
|
|
|
if (sysOrder.getAfterSaleCommissOrder().intValue() == 1 || ("1".equals(sysOrder.getOrderType()) && sysOrder.getMainOrderId().intValue() != 0) ||
|
|
|
|
|
"2".equals(sysOrder.getOrderType()) || "1".equals(sysOrder.getOrderMoneyType()) || sysOrder.getCounted() == 1) {
|
|
|
|
|
System.out.println("---------------------" + sysOrder.getOrderId() + "不生成食谱------------------------");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//判断是否已存在食谱计划
|
|
|
|
@@ -157,9 +157,9 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
List<SysOrderPause> pauseList = sysOrderPauseService.getPauseListByCusIdAndOrderId(pauseParam);
|
|
|
|
|
|
|
|
|
|
List<SysRecipesPlan> planList = generatePlan(sysOrder, DateUtils.dateToLocalDate(sysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getServerEndTime()), pauseList);
|
|
|
|
|
if(oldRecipesPlanList != null && oldRecipesPlanList.size() > 0){
|
|
|
|
|
if (oldRecipesPlanList != null && oldRecipesPlanList.size() > 0) {
|
|
|
|
|
updateOrAddRecipesPlan(oldRecipesPlanList, planList);
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
if (planList != null && planList.size() > 0) {
|
|
|
|
|
sysRecipesPlanMapper.insertBatch(planList);
|
|
|
|
|
}
|
|
|
|
@@ -177,43 +177,44 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新食谱计划,删除旧食谱中多余的,添加新食谱中多的
|
|
|
|
|
*
|
|
|
|
|
* @param oldRecipesPlanList
|
|
|
|
|
* @param newRecipesPlanList
|
|
|
|
|
*/
|
|
|
|
|
private void updateOrAddRecipesPlan(List<SysRecipesPlan> oldRecipesPlanList, List<SysRecipesPlan> 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){
|
|
|
|
|
if (index < newSize) {
|
|
|
|
|
plan.setStartDate(newRecipesPlanList.get(index).getStartDate());
|
|
|
|
|
plan.setEndDate(newRecipesPlanList.get(index).getEndDate());
|
|
|
|
|
plan.setPauseDate(newRecipesPlanList.get(index).getPauseDate());
|
|
|
|
|
plan.setStartNumDay(newRecipesPlanList.get(index).getStartNumDay());
|
|
|
|
|
plan.setEndNumDay(newRecipesPlanList.get(index).getEndNumDay());
|
|
|
|
|
updateList.add(plan);
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
delList.add(plan.getId());
|
|
|
|
|
}
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
if(newSize > oldRecipesPlanList.size()){
|
|
|
|
|
addList = newRecipesPlanList.subList(oldRecipesPlanList.size(),newSize);
|
|
|
|
|
if (newSize > oldRecipesPlanList.size()) {
|
|
|
|
|
addList = newRecipesPlanList.subList(oldRecipesPlanList.size(), newSize);
|
|
|
|
|
}
|
|
|
|
|
//更新
|
|
|
|
|
if(updateList.size() > 0){
|
|
|
|
|
if (updateList.size() > 0) {
|
|
|
|
|
for (SysRecipesPlan plan : updateList) {
|
|
|
|
|
sysRecipesPlanMapper.updateSysRecipesPlan(plan);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//删除多余的食谱计划
|
|
|
|
|
if(delList.size() > 0){
|
|
|
|
|
if (delList.size() > 0) {
|
|
|
|
|
sysRecipesPlanMapper.deleteSysRecipesPlanByIds(delList.toArray(new Long[delList.size()]));
|
|
|
|
|
}
|
|
|
|
|
//添加新的
|
|
|
|
|
if(addList.size() > 0){
|
|
|
|
|
if (addList.size() > 0) {
|
|
|
|
|
sysRecipesPlanMapper.insertBatch(addList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -232,10 +233,10 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
SysRecipesPlan beforeOrderLastPlan = getLastDayRecipesPlan(sysOrder.getCusId(), sysOrder.getOrderTime());
|
|
|
|
|
int startNumDay = 0;
|
|
|
|
|
//之前是否存在食谱
|
|
|
|
|
if(beforeOrderLastPlan != null){
|
|
|
|
|
if (beforeOrderLastPlan != null) {
|
|
|
|
|
long differDay = ChronoUnit.DAYS.between(DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()), serverStartDate);
|
|
|
|
|
//检查之前食谱的结束时间和目前该订单的开始时间是否连续
|
|
|
|
|
if(differDay <= 1){
|
|
|
|
|
if (differDay <= 1) {
|
|
|
|
|
/*if(differDay <= 0){
|
|
|
|
|
serverStartDate = DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(1);
|
|
|
|
|
//更新该订单的开始时间
|
|
|
|
@@ -244,10 +245,10 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
//判断前一个订单食谱是否满七天,不满则需要接上
|
|
|
|
|
int differNum = beforeOrderLastPlan.getEndNumDay() - beforeOrderLastPlan.getStartNumDay();
|
|
|
|
|
|
|
|
|
|
if(differNum < 6){
|
|
|
|
|
if (differNum < 6) {
|
|
|
|
|
//更新该食谱计划
|
|
|
|
|
beforeOrderLastPlan.setEndNumDay(beforeOrderLastPlan.getStartNumDay()+6);
|
|
|
|
|
beforeOrderLastPlan.setEndDate(DateUtils.localDateToDate(DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(6-differNum)));
|
|
|
|
|
beforeOrderLastPlan.setEndNumDay(beforeOrderLastPlan.getStartNumDay() + 6);
|
|
|
|
|
beforeOrderLastPlan.setEndDate(DateUtils.localDateToDate(DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(6 - differNum)));
|
|
|
|
|
sysRecipesPlanMapper.updateSysRecipesPlan(beforeOrderLastPlan);
|
|
|
|
|
serverStartDate = DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(1);
|
|
|
|
|
}
|
|
|
|
@@ -268,8 +269,8 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
}
|
|
|
|
|
String[] pauseResult = dealPlanPause(planStartDate, planEndDate, pauseList);
|
|
|
|
|
//根据暂停结果返回的数据更新计划开始、结束时间
|
|
|
|
|
planStartDate = DateUtils.stringToLocalDate(pauseResult[0],"yyyyMMdd");
|
|
|
|
|
planEndDate = DateUtils.stringToLocalDate(pauseResult[1],"yyyyMMdd");
|
|
|
|
|
planStartDate = DateUtils.stringToLocalDate(pauseResult[0], "yyyyMMdd");
|
|
|
|
|
planEndDate = DateUtils.stringToLocalDate(pauseResult[1], "yyyyMMdd");
|
|
|
|
|
//判断是否大于服务到期时间
|
|
|
|
|
if (ChronoUnit.DAYS.between(planEndDate, serverEndDate) <= 0) {
|
|
|
|
|
planEndDate = serverEndDate;
|
|
|
|
@@ -279,7 +280,7 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
planStartDate = serverEndDate;
|
|
|
|
|
breakFlag = false;
|
|
|
|
|
}
|
|
|
|
|
if(planEndDate == planStartDate && StringUtils.isNotEmpty(pauseResult)) {
|
|
|
|
|
if (planEndDate == planStartDate && StringUtils.isNotEmpty(pauseResult)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//暂停日期
|
|
|
|
@@ -297,12 +298,13 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
//添加暂停范围内的日期
|
|
|
|
|
planList.add(sysRecipesPlan);
|
|
|
|
|
//System.out.println(DateUtils.dateTime(sysRecipesPlan.getStartDate()) + "-----" + DateUtils.dateTime(sysRecipesPlan.getEndDate()));
|
|
|
|
|
}while (breakFlag);
|
|
|
|
|
} while (breakFlag);
|
|
|
|
|
return planList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据食谱开始时间、结束时间、暂停列表获取在食谱计划范围内的暂停天数,以及返回调整之后的计划开始、结束时间,以及暂停日期
|
|
|
|
|
*
|
|
|
|
|
* @param planStartDate 原先的计划开始时间
|
|
|
|
|
* @param planEndDate 原先计划结束时间
|
|
|
|
|
* @param pauseList 暂停列表集合
|
|
|
|
@@ -310,14 +312,14 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
*/
|
|
|
|
|
private String[] dealPlanPause(LocalDate planStartDate, LocalDate planEndDate, List<SysOrderPause> pauseList) {
|
|
|
|
|
//分别为计划开始时间、计划结束时间,范围内暂停天数,具体暂停日期,使用|隔开
|
|
|
|
|
String[] result = {"","","0",""};
|
|
|
|
|
String[] result = {"", "", "0", ""};
|
|
|
|
|
long pauseDay = 0;
|
|
|
|
|
Set<String> pauseDateString = new TreeSet<>(new MyComparator());
|
|
|
|
|
//判断这个时间内是否存在暂停
|
|
|
|
|
if (pauseList != null && pauseList.size() > 0) {
|
|
|
|
|
//每条暂停时间的范围不会重叠,在添加暂停时做了限制
|
|
|
|
|
for (SysOrderPause sysOrderPause : pauseList) {
|
|
|
|
|
while(true){
|
|
|
|
|
while (true) {
|
|
|
|
|
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) {
|
|
|
|
@@ -330,10 +332,10 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
pauseEndDate = planEndDate;
|
|
|
|
|
}
|
|
|
|
|
//判断暂停记录是否从食谱计划开始时间开始的
|
|
|
|
|
if(ChronoUnit.DAYS.between(pauseStartDate, planStartDate) == 0){
|
|
|
|
|
if (ChronoUnit.DAYS.between(pauseStartDate, planStartDate) == 0) {
|
|
|
|
|
planStartDate = pauseEndDate.plusDays(1);
|
|
|
|
|
planEndDate = planStartDate.plusDays(6);
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
planEndDate = planEndDate.plusDays(ChronoUnit.DAYS.between(pauseStartDate, pauseEndDate) + 1);
|
|
|
|
|
pauseDateString.addAll(getPauseDateString(pauseStartDate, pauseEndDate));
|
|
|
|
|
break;
|
|
|
|
@@ -345,37 +347,27 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
System.out.println("---------------------------------------");*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result[0] = DateUtils.localDateToString(planStartDate,"yyyyMMdd");
|
|
|
|
|
result[1] = DateUtils.localDateToString(planEndDate,"yyyyMMdd");
|
|
|
|
|
result[0] = DateUtils.localDateToString(planStartDate, "yyyyMMdd");
|
|
|
|
|
result[1] = DateUtils.localDateToString(planEndDate, "yyyyMMdd");
|
|
|
|
|
result[2] = pauseDay + "";
|
|
|
|
|
result[3] = pauseDateString.size() > 0 ? StringUtils.join(pauseDateString,"|") : "";
|
|
|
|
|
result[3] = pauseDateString.size() > 0 ? StringUtils.join(pauseDateString, "|") : "";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据暂停时间范围获取范围内的日期
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Set<String> getPauseDateString(LocalDate pauseStartDate, LocalDate pauseEndDate){
|
|
|
|
|
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"));
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据订单ID删除所有食谱安排计划
|
|
|
|
|
*
|
|
|
|
@@ -411,10 +403,11 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据客户ID查询最后一天食谱计划
|
|
|
|
|
*
|
|
|
|
|
* @param customerId 客户ID
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public SysRecipesPlan getLastDayRecipesPlan(Long customerId, Date orderTime){
|
|
|
|
|
public SysRecipesPlan getLastDayRecipesPlan(Long customerId, Date orderTime) {
|
|
|
|
|
return sysRecipesPlanMapper.getLastDayRecipesPlan(customerId, orderTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -437,4 +430,15 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService {
|
|
|
|
|
return sysRecipesPlanMapper.selectRecipesModelList(sysRecipesPlan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 集合排序key值比较器
|
|
|
|
|
*/
|
|
|
|
|
class MyComparator implements Comparator<String> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int compare(String o1, String o2) {
|
|
|
|
|
return Integer.parseInt(o1) - Integer.parseInt(o2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|