From 85f362e775a4abf8f898a0db8421cc06476ceda5 Mon Sep 17 00:00:00 2001 From: xiezhijun <15270898033@163.com> Date: Fri, 14 May 2021 18:38:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E7=8F=AD=E4=BC=98=E5=8C=96=E5=8A=A0?= =?UTF-8?q?=E4=B8=8A=E4=B8=80=E9=94=AE=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E8=90=A5=E5=85=BB=E7=9F=A5=E8=AF=86=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E3=80=81=E8=A7=86=E9=A2=91=E5=88=97=E8=A1=A8=E5=8A=A0=E4=B8=8A?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/SysLiveSchedulController.java | 51 +++++++++++++++-- .../com/stdiet/common/utils/DateUtils.java | 36 +++++++++++- .../response/NutritionQuestionResponse.java | 2 + .../custom/mapper/SysLiveSchedulMapper.java | 13 +++++ .../service/ISysLiveSchedulService.java | 8 +++ .../impl/SysLiveSchedulServiceImpl.java | 55 +++++++++++++++++++ .../impl/SysNutritionQuestionServiceImpl.java | 12 +++- .../service/impl/SysOrderServiceImpl.java | 17 +++++- .../mapper/custom/SysLiveSchedulMapper.xml | 18 ++++++ stdiet-ui/src/api/custom/liveSchedul.js | 11 ++++ .../src/views/custom/liveSchedul/index.vue | 22 +++++++- .../views/custom/nutritionQuestion/index.vue | 6 +- .../views/custom/nutritionalVideo/index.vue | 5 ++ 13 files changed, 242 insertions(+), 14 deletions(-) diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysLiveSchedulController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysLiveSchedulController.java index 258244d2a..09a427db4 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysLiveSchedulController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysLiveSchedulController.java @@ -2,6 +2,8 @@ package com.stdiet.web.controller.custom; import java.util.Date; import java.util.List; + +import com.stdiet.common.utils.DateUtils; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -84,7 +86,12 @@ public class SysLiveSchedulController extends BaseController //下播,补全下播时间 if (sysLiveSchedul.getLiveStatus() != null && sysLiveSchedul.getLiveStatus().longValue() == 2 && sysLiveSchedul.getLiveEndTime() == null){ - sysLiveSchedul.setLiveEndTime(new Date()); + Date now = new Date(); + if(!DateUtils.isSameDay(now,sysLiveSchedul.getLiveStartTime())){ + sysLiveSchedul.setLiveEndTime(DateUtils.getLastMinuteDate(sysLiveSchedul.getLiveStartTime())); + }else{ + sysLiveSchedul.setLiveEndTime(now); + } } int row = sysLiveSchedulService.insertSysLiveSchedul(sysLiveSchedul); if(row > 0){ @@ -96,7 +103,11 @@ public class SysLiveSchedulController extends BaseController if(lastLiveSchedul != null && lastLiveSchedul.getLiveStatus().longValue() == 1){ lastLiveSchedul.setLiveStatus(2L); if(lastLiveSchedul.getLiveEndTime() == null){ - lastLiveSchedul.setLiveEndTime(sysLiveSchedul.getLiveStartTime()); + if(!DateUtils.isSameDay(lastLiveSchedul.getLiveStartTime(),sysLiveSchedul.getLiveStartTime())){ + lastLiveSchedul.setLiveEndTime(DateUtils.getLastMinuteDate(lastLiveSchedul.getLiveStartTime())); + }else{ + lastLiveSchedul.setLiveEndTime(sysLiveSchedul.getLiveStartTime()); + } } row = sysLiveSchedulService.updateSysLiveSchedul(lastLiveSchedul); } @@ -121,7 +132,12 @@ public class SysLiveSchedulController extends BaseController //下播,补全下播时间 if (sysLiveSchedul.getLiveStatus() != null && sysLiveSchedul.getLiveStatus().longValue() == 2 && sysLiveSchedul.getLiveEndTime() == null){ - sysLiveSchedul.setLiveEndTime(new Date()); + Date now = new Date(); + if(!DateUtils.isSameDay(now,sysLiveSchedul.getLiveStartTime())){ + sysLiveSchedul.setLiveEndTime(DateUtils.getLastMinuteDate(sysLiveSchedul.getLiveStartTime())); + }else{ + sysLiveSchedul.setLiveEndTime(now); + } } int row = sysLiveSchedulService.updateSysLiveSchedulById(sysLiveSchedul); if(row > 0){ @@ -133,7 +149,11 @@ public class SysLiveSchedulController extends BaseController if(lastLiveSchedul != null && lastLiveSchedul.getLiveStatus().longValue() == 1){ lastLiveSchedul.setLiveStatus(2L); if(lastLiveSchedul.getLiveEndTime() == null){ - lastLiveSchedul.setLiveEndTime(sysLiveSchedul.getLiveStartTime()); + if(!DateUtils.isSameDay(lastLiveSchedul.getLiveStartTime(),sysLiveSchedul.getLiveStartTime())){ + lastLiveSchedul.setLiveEndTime(DateUtils.getLastMinuteDate(lastLiveSchedul.getLiveStartTime())); + }else{ + lastLiveSchedul.setLiveEndTime(sysLiveSchedul.getLiveStartTime()); + } } row = sysLiveSchedulService.updateSysLiveSchedul(lastLiveSchedul); } @@ -178,7 +198,11 @@ public class SysLiveSchedulController extends BaseController if(lastLiveSchedul != null && lastLiveSchedul.getLiveStatus().longValue() == 1){ lastLiveSchedul.setLiveStatus(2L); if(lastLiveSchedul.getLiveEndTime() == null){ - lastLiveSchedul.setLiveEndTime(sysLiveSchedul.getLiveStartTime()); + if(!DateUtils.isSameDay(lastLiveSchedul.getLiveStartTime(),sysLiveSchedul.getLiveStartTime())){ + lastLiveSchedul.setLiveEndTime(DateUtils.getLastMinuteDate(lastLiveSchedul.getLiveStartTime())); + }else{ + lastLiveSchedul.setLiveEndTime(sysLiveSchedul.getLiveStartTime()); + } } row = sysLiveSchedulService.updateSysLiveSchedul(lastLiveSchedul); } @@ -188,10 +212,25 @@ public class SysLiveSchedulController extends BaseController }else{ SysLiveSchedul newLiveSchedul = sysLiveSchedulService.selectSysLiveSchedulById(sysLiveSchedul.getId()); if(newLiveSchedul != null && newLiveSchedul.getLiveEndTime() == null){ - sysLiveSchedul.setLiveEndTime(new Date()); + Date now = new Date(); + if(!DateUtils.isSameDay(now,newLiveSchedul.getLiveStartTime())){ + sysLiveSchedul.setLiveEndTime(DateUtils.getLastMinuteDate(newLiveSchedul.getLiveStartTime())); + }else{ + sysLiveSchedul.setLiveEndTime(now); + } } row = sysLiveSchedulService.updateSysLiveSchedul(sysLiveSchedul); } return toAjax(row); } + + /** + * 复制上次直播记录 + */ + @PreAuthorize("@ss.hasPermi('custom:liveSchedul:add')") + @Log(title = "复制上次直播记录", businessType = BusinessType.INSERT) + @GetMapping(value = "/copyLastTimeLiveSchedul") + public AjaxResult copyLastTimeLiveSchedul(){ + return sysLiveSchedulService.copyLastTimeLiveSchedul(); + } } \ No newline at end of file diff --git a/stdiet-common/src/main/java/com/stdiet/common/utils/DateUtils.java b/stdiet-common/src/main/java/com/stdiet/common/utils/DateUtils.java index 642eaff7a..2ae896768 100644 --- a/stdiet-common/src/main/java/com/stdiet/common/utils/DateUtils.java +++ b/stdiet-common/src/main/java/com/stdiet/common/utils/DateUtils.java @@ -169,7 +169,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils * LocalDateTime对象转Date * */ public static Date localDateTimeToDate(LocalDateTime localDateTime){ - ZonedDateTime zdt = LocalDateTime.now().atZone(ZoneId.systemDefault()); + ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault()); return Date.from(zdt.toInstant()); } @@ -193,8 +193,42 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils return date.format(fmt); } + public static String localDateTimeToString(LocalDateTime 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); } + + /** + * 获取当前Date型日期 + * + * @return Date() 当前日期 + */ + public static Date dateToDate(Date date) + { + return parseDate(DateFormatUtils.format(date, YYYY_MM_DD)); + } + + /** + * 判断两个日期是否同一天 + * @param dateOne + * @param dateTwo + * @return + */ + public static boolean isSameDay(Date dateOne, Date dateTwo){ + return dateToDate(dateOne).getTime() == dateToDate(dateTwo).getTime(); + } + + /** + * 获取该日期的最后一秒对应时间 + * @param date + * @return + */ + public static Date getLastMinuteDate(Date date){ + return new Date(dateToDate(date).getTime()+(24 * 60 * 60 * 1000 - 1000)); + } } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/NutritionQuestionResponse.java b/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/NutritionQuestionResponse.java index 5806e7640..76240ead0 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/NutritionQuestionResponse.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/NutritionQuestionResponse.java @@ -26,4 +26,6 @@ public class NutritionQuestionResponse implements Serializable { /** 小程序是否显示,0不显示 1显示 */ private String showFlag; + + private String createTime; } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysLiveSchedulMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysLiveSchedulMapper.java index a64893bbc..4f876aac1 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysLiveSchedulMapper.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysLiveSchedulMapper.java @@ -77,4 +77,17 @@ public interface SysLiveSchedulMapper * @return */ public SysLiveSchedul getLastLiveSchedulById(SysLiveSchedul sysLiveSchedul); + + /** + * 获取所有计划 + * @param sysLiveSchedul + * @return + */ + public List getAllLiveSchedulByDate(SysLiveSchedul sysLiveSchedul); + + /** + * 获取最后一次直播计划 + * @return + */ + public SysLiveSchedul getLastLiveSchedul(); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysLiveSchedulService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysLiveSchedulService.java index cd75428c4..e22d2b77a 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysLiveSchedulService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysLiveSchedulService.java @@ -1,6 +1,8 @@ package com.stdiet.custom.service; import java.util.List; + +import com.stdiet.common.core.domain.AjaxResult; import com.stdiet.custom.domain.SysLiveSchedul; /** @@ -77,4 +79,10 @@ public interface ISysLiveSchedulService * @return */ public SysLiveSchedul getLastLiveSchedulById(SysLiveSchedul sysLiveSchedul); + + /** + * 复制上一次直播间计划,并将上次的直播计划状态全部改为未开播 + * @return + */ + public AjaxResult copyLastTimeLiveSchedul(); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysLiveSchedulServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysLiveSchedulServiceImpl.java index 8e15c6662..37455737b 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysLiveSchedulServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysLiveSchedulServiceImpl.java @@ -1,7 +1,13 @@ package com.stdiet.custom.service.impl; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Date; import java.util.List; + +import com.stdiet.common.core.domain.AjaxResult; import com.stdiet.common.utils.DateUtils; +import com.stdiet.common.utils.SecurityUtils; import lombok.Data; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -123,4 +129,53 @@ public class SysLiveSchedulServiceImpl implements ISysLiveSchedulService public SysLiveSchedul getLastLiveSchedulById(SysLiveSchedul sysLiveSchedul){ return sysLiveSchedulMapper.getLastLiveSchedulById(sysLiveSchedul); } + + /** + * 复制上一次直播间计划,并将上次的直播计划状态全部改为未开播 + * @return + */ + @Override + public AjaxResult copyLastTimeLiveSchedul(){ + AjaxResult result = AjaxResult.success(); + //获取上一次直播时间 + SysLiveSchedul lastLiveSchedul = sysLiveSchedulMapper.getLastLiveSchedul(); + if(lastLiveSchedul == null){ + return AjaxResult.error("不存在直播记录,无法复制"); + } + Date nowDate = new Date(); + LocalDate nowLocalDate = DateUtils.dateToLocalDate(nowDate); + if(DateUtils.isSameDay(lastLiveSchedul.getLiveSchedulDate(), nowDate)){ + return AjaxResult.error("今日已存在直播记录,无法复制"); + } + //获取上一次所有计划 + List list = sysLiveSchedulMapper.getAllLiveSchedulByDate(lastLiveSchedul); + if(list != null && list.size() > 0){ + int row = 0; + for (SysLiveSchedul schedul : list) { + schedul.setLiveStatus(0L); + schedul.setCreateTime(new Date()); + schedul.setUpdateTime(null); + schedul.setCreateBy(SecurityUtils.getLoginUser().getUser().getUserId()+""); + schedul.setUpdateBy(null); + schedul.setLiveSchedulDate(DateUtils.dateToDate(nowDate)); + if(schedul.getLiveStartTime() != null) { + LocalDateTime liveStartTime = DateUtils.dateToLocalDateTime(schedul.getLiveStartTime()); + schedul.setLiveStartTime(DateUtils.localDateTimeToDate(LocalDateTime.of(nowLocalDate.getYear(),nowLocalDate.getMonthValue(),nowLocalDate.getDayOfMonth(), + liveStartTime.getHour(),liveStartTime.getMinute()))); + System.out.println(liveStartTime.getHour() + "-" +liveStartTime.getMinute()); + } + if(schedul.getLiveEndTime() != null) { + LocalDateTime liveEndTime = DateUtils.dateToLocalDateTime(schedul.getLiveEndTime()); + schedul.setLiveEndTime(DateUtils.localDateTimeToDate(LocalDateTime.of(nowLocalDate.getYear(),nowLocalDate.getMonthValue(),nowLocalDate.getDayOfMonth(), + liveEndTime.getHour(),liveEndTime.getMinute()))); + System.out.println(liveEndTime.getHour() + "-" +liveEndTime.getMinute()); + } + + row = sysLiveSchedulMapper.insertSysLiveSchedul(schedul); + } + }else{ + return AjaxResult.error("不存在直播记录,无法复制"); + } + return result; + } } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysNutritionQuestionServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysNutritionQuestionServiceImpl.java index 0287f99a1..67ec70667 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysNutritionQuestionServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysNutritionQuestionServiceImpl.java @@ -40,7 +40,7 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer public String index_path; //建立索引的字段名称 - public static final String[] index_field_array = {"id", "title", "content", "key", "showFlag"}; + public static final String[] index_field_array = {"id", "title", "content", "key", "showFlag", "createTime"}; //查询字段 public static final String[] index_select_field_array = {"title", "content", "key"}; @@ -275,7 +275,8 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer private NutritionQuestionResponse documentToNutritionQuestion(Document document){ NutritionQuestionResponse nutritionQuestionResponse = new NutritionQuestionResponse(); for (String fieldName : index_field_array) { - ReflectUtils.setFieldValue(nutritionQuestionResponse, fieldName, document.get(fieldName)); + String value = document.get(fieldName); + ReflectUtils.setFieldValue(nutritionQuestionResponse, fieldName, StringUtils.isEmpty(value) ? "" : value); } return nutritionQuestionResponse; } @@ -288,7 +289,12 @@ public class SysNutritionQuestionServiceImpl implements ISysNutritionQuestionSer private Document nutritionQuestionToDocument(SysNutritionQuestion sysNutritionQuestion){ Document document = new Document(); for (String fieldName : index_field_array) { - TextField field = new TextField(fieldName, ReflectUtils.getFieldValue(sysNutritionQuestion, fieldName)+"", Field.Store.YES); + TextField field = null; + if("createTime".equals(fieldName)){ + field = new TextField(fieldName, DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,sysNutritionQuestion.getCreateTime()), Field.Store.YES); + } else{ + field = new TextField(fieldName, ReflectUtils.getFieldValue(sysNutritionQuestion, fieldName)+"", Field.Store.YES); + } if(nutritionQuestionBoostMap.containsKey(fieldName)){ field.setBoost(nutritionQuestionBoostMap.get(fieldName).floatValue()); } 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 b7e43f43a..f3a3924bb 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 @@ -208,6 +208,19 @@ public class SysOrderServiceImpl implements ISysOrderService { sysOrder.setOperatorId(null); sysOrder.setOperatorAssisId(null); } + if(oldSysOrder.getStartTime() == null){//确保提成计算时间不为空 + sysOrder.setCommissStartTime(sysOrder.getOrderTime()); + } + //如果更新了开始服务时间,需要判断是否需要同步提成计算时间 + if (oldSysOrder.getStartTime() != null && sysOrder.getStartTime() != null + && ChronoUnit.DAYS.between(DateUtils.dateToLocalDate(oldSysOrder.getStartTime()), DateUtils.dateToLocalDate(sysOrder.getStartTime())) != 0) { + //本月第一天 + LocalDate monthStart = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()); + //旧的开始时间和新的开始时间都要需要大于本月第一天 + if(oldSysOrder.getCommissStartTime() != null && ChronoUnit.DAYS.between(monthStart, DateUtils.dateToLocalDate(oldSysOrder.getCommissStartTime())) >= 0 && ChronoUnit.DAYS.between(monthStart, DateUtils.dateToLocalDate(sysOrder.getStartTime())) >= 0){ + sysOrder.setCommissStartTime(sysOrder.getStartTime()); + } + } //更新订单 int row = sysOrderMapper.updateSysOrder(sysOrder); // 审核后的订单才生成食谱 @@ -300,7 +313,7 @@ public class SysOrderServiceImpl implements ISysOrderService { for (SysOrder sysOrder : orderList) { LocalDate newStartTime = null; //判断是否提成单,拆分单中的副单,体验单,定金单 - if(sysOrder.getAfterSaleCommissOrder().intValue() == 1 || ("1".equals(sysOrder.getOrderType()) && sysOrder.getMainOrderId().intValue() != 0) || + if(sysOrder.getStartTime() == null || sysOrder.getAfterSaleCommissOrder().intValue() == 1 || ("1".equals(sysOrder.getOrderType()) && sysOrder.getMainOrderId().intValue() != 0) || "2".equals(sysOrder.getOrderType()) || "1".equals(sysOrder.getOrderMoneyType())){ continue; } @@ -310,7 +323,7 @@ public class SysOrderServiceImpl implements ISysOrderService { //本月第一天 LocalDate monthStart = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()); //旧的开始时间和新的开始时间都要需要大于本月第一天 - if(ChronoUnit.DAYS.between(monthStart, DateUtils.dateToLocalDate(sysOrder.getStartTime())) >= 0 && ChronoUnit.DAYS.between(monthStart, newStartTime) >= 0){ + if(sysOrder.getCommissStartTime() != null && ChronoUnit.DAYS.between(monthStart, DateUtils.dateToLocalDate(sysOrder.getCommissStartTime())) >= 0 && ChronoUnit.DAYS.between(monthStart, newStartTime) >= 0){ sysOrder.setCommissStartTime(DateUtils.localDateToDate(newStartTime)); } sysOrder.setStartTime(DateUtils.localDateToDate(newStartTime)); diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysLiveSchedulMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysLiveSchedulMapper.xml index 878d805bc..d1b686eb3 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysLiveSchedulMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysLiveSchedulMapper.xml @@ -193,4 +193,22 @@ from sys_live_schedul where id #{id} and del_flag = 0 and live_room = #{liveRoom} order by live_start_time desc limit 1 + + + + + + + + \ No newline at end of file diff --git a/stdiet-ui/src/api/custom/liveSchedul.js b/stdiet-ui/src/api/custom/liveSchedul.js index 1e9b49b5c..716796df0 100644 --- a/stdiet-ui/src/api/custom/liveSchedul.js +++ b/stdiet-ui/src/api/custom/liveSchedul.js @@ -61,3 +61,14 @@ export function updateLiveStatus(data) { params: data }) } + +// 复制上次直播记录 +export function copyLastTimeLiveSchedul() { + return request({ + url: '/custom/liveSchedul/copyLastTimeLiveSchedul', + method: 'get', + params: {} + }) +} + + diff --git a/stdiet-ui/src/views/custom/liveSchedul/index.vue b/stdiet-ui/src/views/custom/liveSchedul/index.vue index 36ce6d0c7..688127e60 100644 --- a/stdiet-ui/src/views/custom/liveSchedul/index.vue +++ b/stdiet-ui/src/views/custom/liveSchedul/index.vue @@ -96,6 +96,15 @@ v-hasPermi="['custom:liveSchedul:remove']" >删除 + + 一键复制上次记录 + +