From 566c44cc5712ab9c997424ee5a5438e0a81a016e Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期三, 17 五月 2023 18:49:38 +0800 Subject: [PATCH] BUG修改 --- management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/TaskUtil.java | 103 +++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 83 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 fe42e7e..62e7a81 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 @@ -2,16 +2,23 @@ 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.service.ITDriverService; -import com.stylefeng.guns.modular.system.service.ITLocationService; -import com.stylefeng.guns.modular.system.service.IUserCouponRecordService; +import com.stylefeng.guns.modular.system.model.TDriverWork; +import com.stylefeng.guns.modular.system.model.TOrder; +import com.stylefeng.guns.modular.system.service.*; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.Period; +import java.util.Date; import java.util.List; +import java.util.Objects; /** @@ -22,15 +29,14 @@ @Autowired private ITLocationService locationService; - - @Autowired - private PushMinistryOfTransportUtil pushMinistryOfTransportUtil; - - @Value("${pushMinistryOfTransport}") - private boolean pushMinistryOfTransport; - @Autowired private ITDriverService driverService; + @Autowired + private ITAppUserService appUserService; + @Autowired + private ITOrderService orderService; + @Autowired + private ITDriverWorkService tDriverWorkService; @@ -58,22 +64,79 @@ } } - - /** - * 每月第一天的1点执行的任务 + * 每半天检测用户是否有异常 */ - @Scheduled(cron = "0 0 1 1 * *") - public void taskMonth(){ + @Scheduled(cron = "0 0 0,12 * * ? ") + public void queryUserIsException(){ try { - if(pushMinistryOfTransport){ - List<TDriver> tDrivers = driverService.selectList(new EntityWrapper<TDriver>().eq("authState", 2).ne("flag", 3)); - for(TDriver driver : tDrivers){ - pushMinistryOfTransportUtil.baseInfoDriverStat(driver.getId()); + List<TAppUser> appUserList = appUserService.selectList(new EntityWrapper<TAppUser>().ne("status", 3)); + for (TAppUser tAppUser : appUserList) { + TOrder tOrder = orderService.selectOne(new EntityWrapper<TOrder>() + .eq("userId", tAppUser.getId()) + .last("LIMIT 1")); + int day; + if(Objects.nonNull(tOrder)){ + // 客户一个月未下单,状态异常 + Period period = Period.between(DateUtil.dateToLocalDate(tOrder.getCreateTime()), LocalDate.now()); + day = Math.abs(period.getDays()); + }else { + Period period = Period.between(DateUtil.dateToLocalDate(tAppUser.getCreateTime()), LocalDate.now()); + day = Math.abs(period.getDays()); + } + if(day > 29){ + tAppUser.setIsException(2); } } + 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)); + 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); + } + TDriverWork tDriverWork = tDriverWorkService.selectOne(new EntityWrapper<TDriverWork>() + .eq("driverId", driver.getId()) + .orderBy("workTime", false) + .last("LIMIT 1")); + if(Objects.nonNull(tDriverWork)){ + // 如果是下班状态,计算未上线天数,,如果为上班状态,则设置为0 + if(tDriverWork.getStatus() == 2){ + Period period = Period.between(DateUtil.dateToLocalDate(tDriverWork.getOffWorkTime()), LocalDate.now()); + int day = Math.abs(period.getDays()); + if(day>14){ + driver.setIsException(2); + } + } + }else { + if(Objects.nonNull(driver.getApprovalTime())){ + // 没有上班记录,计算审核时间 + Period period = Period.between(DateUtil.dateToLocalDate(driver.getApprovalTime()), LocalDate.now()); + int day = Math.abs(period.getDays()); + if(day>14){ + driver.setIsException(2); + } + } + } + } + driverService.updateBatchById(driverList); + }catch (Exception e){ + e.printStackTrace(); + } + } + } -- Gitblit v1.7.1