123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package com.ruoyi.web.controller.task;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.util.StrUtil;
- import com.ruoyi.common.core.redis.RedisCache;
- import com.ruoyi.qdtl.domain.PlanUser;
- import com.ruoyi.qdtl.domain.TlInspectionLocation;
- import com.ruoyi.qdtl.domain.TlInspectionPlan;
- import com.ruoyi.qdtl.domain.TlPlanRecord;
- import com.ruoyi.qdtl.service.ITlInspectionLocationService;
- import com.ruoyi.qdtl.service.ITlInspectionPlanService;
- import com.ruoyi.qdtl.service.ITlPlanRecordService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.concurrent.TimeUnit;
- /**
- * @Description: 巡检计划任务
- * @Author: huangcheng
- * @Date: 2022/3/30
- * @Version V1.0
- */
- @Component("planTask")
- public class PlanTask {
- @Autowired
- private ITlInspectionPlanService planService;
- @Autowired
- private ITlPlanRecordService planRecordService;
- @Autowired
- private ITlInspectionLocationService locationService;
- @Autowired
- private RedisCache redisCache;
- /**
- * 根据巡检计划生成下一日巡检计划数据
- * params参数:如果传了参数,就根据参数的日期来生成计划(为了测试方便)
- */
- public void createPlan(String params) {
- // 查询符合条件的计划。根据当前时间点,如果是晚20点~24点之间,就去生成第二天的计划,如果是凌晨0点~1点,就生成当天的计划
- // 生成过的计划,标记已生成放到redis中
- String queryDate;
- if (StrUtil.isNotBlank(params)) {
- queryDate = params;
- } else {
- int hour = DateUtil.hour(new Date(), true);
- if (20 <= hour && hour <= 24) {
- queryDate = DateUtil.formatDate(DateUtil.tomorrow());
- } else if (0 <= hour && hour <= 1) {
- queryDate = DateUtil.today();
- } else {
- return;
- }
- }
- Boolean recordFlag = redisCache.getCacheObject("tl:planrecord:" + queryDate);
- if (recordFlag != null && recordFlag) {
- return;
- }
- List<TlInspectionPlan> planList = planService.queryPlanByDate(queryDate);
- if (planList != null && planList.size() > 0) {
- List<TlPlanRecord> planRecords = new ArrayList<>();
- for (TlInspectionPlan inspectionPlan : planList) {
- // 查询计划的人员.根据计划id查询人员以及设备号
- List<PlanUser> userList = planService.queryPlanUser(inspectionPlan.getId());
- // 查询计划的线路及点位
- List<TlInspectionLocation> lineLocations = locationService.queryLocationByLineId(inspectionPlan.getLineId());
- if (userList != null && userList.size() > 0) {
- // 组装计划数据
- for (PlanUser planUser : userList) {
- for (TlInspectionLocation lineLocation : lineLocations) {
- TlPlanRecord planRecord = new TlPlanRecord();
- planRecord.setPlanId(planUser.getPlanId());
- planRecord.setPlanDate(queryDate);
- planRecord.setPlanName(inspectionPlan.getPlanName());
- planRecord.setUserId(planUser.getUserId());
- planRecord.setNickName(planUser.getNickName());
- planRecord.setCard(planUser.getCard());
- planRecord.setScore(inspectionPlan.getScore());
- planRecord.setCheckpointCard(lineLocation.getLocationCode());
- planRecord.setLineId(inspectionPlan.getLineId());
- planRecord.setLineName("");
- planRecords.add(planRecord);
- }
- }
- }
- }
- if (planRecords.size() > 0) {
- planRecordService.batchInsert(planRecords);
- redisCache.setCacheObject("tl:planrecord:" + queryDate, true, 2, TimeUnit.DAYS);
- }
- }
- }
- }
|