From 05e13dc68b3db44868d9e02a10ccc330366a49c6 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期二, 08 八月 2023 11:58:36 +0800
Subject: [PATCH] 修改bug
---
management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/TaskUtil.java | 97 ++++++++++++++++++++++++++++++++++++++----------
1 files changed, 77 insertions(+), 20 deletions(-)
diff --git a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/TaskUtil.java b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/TaskUtil.java
index 684cd4a..222aba3 100644
--- a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/TaskUtil.java
+++ b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/TaskUtil.java
@@ -3,10 +3,7 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.modular.system.enums.UserTypeEnum;
-import com.stylefeng.guns.modular.system.model.TAppUser;
-import com.stylefeng.guns.modular.system.model.TDriver;
-import com.stylefeng.guns.modular.system.model.TDriverWork;
-import com.stylefeng.guns.modular.system.model.TOrder;
+import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@@ -15,10 +12,12 @@
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
+import java.time.LocalDateTime;
import java.time.Period;
import java.util.Date;
import java.util.List;
import java.util.Objects;
+import java.util.stream.Collectors;
/**
@@ -37,15 +36,28 @@
private ITOrderService orderService;
@Autowired
private ITDriverWorkService tDriverWorkService;
+ @Autowired
+ private ITUserToCouponService userToCouponService;
/**
- * 每隔一分钟去处理的定时任务
+ * 每隔一分钟去处理的定时任务,过期优惠券
*/
@Scheduled(fixedRate = 1000 * 60)
public void taskMinute(){
try {
+ // 查询所有优惠券
+ List<TUserToCoupon> tUserToCoupons = userToCouponService.selectList(new EntityWrapper<TUserToCoupon>());
+ List<TUserToCoupon> collect2 = tUserToCoupons.stream().filter(tUserToCoupon -> LocalDateTime.now().isAfter(DateUtil.dateToLocalDateTime(tUserToCoupon.getExpireTime()))).collect(Collectors.toList());
+ for (TUserToCoupon userToCoupon : collect2) {
+ Integer validCount = userToCoupon.getValidCount();
+ userToCoupon.setExpireCount(validCount);
+ userToCoupon.setValidCount(0);
+ }
+ if(collect2.size() > 0){
+ userToCouponService.updateBatchById(collect2);
+ }
} catch (Exception e) {
e.printStackTrace();
}
@@ -58,7 +70,7 @@
@Scheduled(cron = "0 0 0 * * *")
public void taskDay(){
try {
- locationService.updateFence();//更新线上电子围栏
+// locationService.updateFence();//更新线上电子围栏
}catch (Exception e){
e.printStackTrace();
}
@@ -74,39 +86,46 @@
for (TAppUser tAppUser : appUserList) {
TOrder tOrder = orderService.selectOne(new EntityWrapper<TOrder>()
.eq("userId", tAppUser.getId())
+ .orderBy("createTime",false)
.last("LIMIT 1"));
int day;
if(Objects.nonNull(tOrder)){
// 客户一个月未下单,状态异常
Period period = Period.between(DateUtil.dateToLocalDate(tOrder.getCreateTime()), LocalDate.now());
+ int month = Math.abs(period.getMonths());
+ if(month > 0){
+ tAppUser.setIsException(2);
+ }
day = Math.abs(period.getDays());
}else {
Period period = Period.between(DateUtil.dateToLocalDate(tAppUser.getCreateTime()), LocalDate.now());
+ int month = Math.abs(period.getMonths());
+ if(month > 0){
+ tAppUser.setIsException(2);
+ }
day = Math.abs(period.getDays());
}
if(day > 29){
tAppUser.setIsException(2);
}
}
- appUserService.updateBatchById(appUserList);
+ if(appUserList.size() > 0){
+ appUserService.updateBatchById(appUserList);
+ }
}catch (Exception e){
e.printStackTrace();
}
}
/**
- * 每半天检测司机是否有异常
+ * 每半天检测司机未上线天数是否有异常
*/
@Scheduled(cron = "0 0 9,21 * * ? ")
public void queryDriverIsException(){
try {
- List<TDriver> driverList = driverService.selectList(new EntityWrapper<TDriver>().ne("status", 3));
+ List<TDriver> driverList = driverService.selectList(new EntityWrapper<TDriver>().ne("status", 3)
+ .eq("approvalStatus",2));
for (TDriver driver : driverList) {
- // 15天未上线异常,当月有效订单低于30单,异常
- Integer count = orderService.getValidOrderCount(driver.getId(),new BigDecimal(14),new SimpleDateFormat("yyyy-MM").format(new Date()));
- if(count < 30){
- driver.setIsException(2);
- }
TDriverWork tDriverWork = tDriverWorkService.selectOne(new EntityWrapper<TDriverWork>()
.eq("driverId", driver.getId())
.orderBy("workTime", false)
@@ -115,21 +134,59 @@
// 如果是下班状态,计算未上线天数,,如果为上班状态,则设置为0
if(tDriverWork.getStatus() == 2){
Period period = Period.between(DateUtil.dateToLocalDate(tDriverWork.getOffWorkTime()), LocalDate.now());
+ int month = Math.abs(period.getMonths());
+ if(month > 0){
+ driver.setIsException(2);
+ }
int day = Math.abs(period.getDays());
if(day>14){
driver.setIsException(2);
}
}
}else {
- // 没有上班记录,计算审核时间
- Period period = Period.between(DateUtil.dateToLocalDate(driver.getApprovalTime()), LocalDate.now());
- int day = Math.abs(period.getDays());
- if(day>14){
- driver.setIsException(2);
+ if(Objects.nonNull(driver.getApprovalTime())){
+ // 没有上班记录,计算审核时间
+ Period period = Period.between(DateUtil.dateToLocalDate(driver.getApprovalTime()), LocalDate.now());
+ int month = Math.abs(period.getMonths());
+ if(month > 0){
+ driver.setIsException(2);
+ }
+ int day = Math.abs(period.getDays());
+ if(day>14){
+ driver.setIsException(2);
+ }
}
}
}
- driverService.updateBatchById(driverList);
+ if(driverList.size() > 0){
+ driverService.updateBatchById(driverList);
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 每月检测司机有效订单是否有异常
+ * 每月最后一天中午12点检测
+ */
+ @Scheduled(cron = "0 0 12 28-31 * ? ")
+ public void queryDriverIsExceptionMonth(){
+ try {
+ List<TDriver> driverList = driverService.selectList(new EntityWrapper<TDriver>().ne("status", 3)
+ .eq("approvalStatus",2));
+ for (TDriver driver : driverList) {
+ // 15天未上线异常,当月有效订单低于30单,异常
+ Integer count = orderService.getValidOrderCount(driver.getId(),new BigDecimal(14),new SimpleDateFormat("yyyy-MM").format(new Date()));
+ if(count < 30){
+ driver.setIsException(2);
+ }else {
+ driver.setIsException(1);
+ }
+ }
+ if(driverList.size() > 0){
+ driverService.updateBatchById(driverList);
+ }
}catch (Exception e){
e.printStackTrace();
}
--
Gitblit v1.7.1