|
|
@@ -0,0 +1,71 @@
|
|
|
+package com.ruoyi.interfaces.snailJob;
|
|
|
+
|
|
|
+import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
|
|
|
+import com.aizuda.snailjob.client.job.core.dto.JobArgs;
|
|
|
+import com.aizuda.snailjob.model.dto.ExecuteResult;
|
|
|
+import com.ruoyi.common.utils.DateUtils;
|
|
|
+import com.ruoyi.common.utils.JsonUtils;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.interfaces.domain.MdAppFlow;
|
|
|
+import com.ruoyi.interfaces.domain.PtServiceLog;
|
|
|
+import com.ruoyi.interfaces.domain.PtServiceLogStatis;
|
|
|
+import com.ruoyi.interfaces.mapper.MdJobScheduleMapper;
|
|
|
+import com.ruoyi.interfaces.mapper.PtServiceLogMapper;
|
|
|
+import com.ruoyi.interfaces.service.IPtServiceLogService;
|
|
|
+import com.ruoyi.interfaces.service.IPtServiceLogStatisService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class ServiceLogStatisJob {
|
|
|
+
|
|
|
+
|
|
|
+ public final static String PRO_CODE = "SERVICE_LOG_STATIS";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IPtServiceLogService ptServiceLogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IPtServiceLogStatisService serviceLogStatisService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MdJobScheduleMapper jobScheduleMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @JobExecutor(name = "serviceLogStatisJob")
|
|
|
+ public ExecuteResult ServiceLogStatisJob(JobArgs jobArgs) {
|
|
|
+ HashMap<String, String> hashMap = null;
|
|
|
+ if (StringUtils.isNotEmpty(jobArgs.getJobParams().toString()))
|
|
|
+ hashMap = JsonUtils.jsonToPojo(jobArgs.getJobParams().toString(), HashMap.class);
|
|
|
+ Date schedule = null;
|
|
|
+ Date endTime = DateUtils.getNowDate();
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(hashMap)) {
|
|
|
+ schedule = jobScheduleMapper.selectScheduleByProCode(PRO_CODE);
|
|
|
+ if (StringUtils.isNull(schedule)) {
|
|
|
+ Date lastHourTime = DateUtils.getLastHourTime(new Date(), 24);
|
|
|
+ schedule = DateUtils.getDateDD(lastHourTime);
|
|
|
+ jobScheduleMapper.insertScheduleByProCode(PRO_CODE, schedule);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ schedule = DateUtils.dateTime(DateUtils.YYYY_MM_DD, hashMap.get("beginTime").toString());
|
|
|
+ endTime = DateUtils.dateTime(DateUtils.YYYY_MM_DD, hashMap.get("endTime").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ for (long i = schedule.getTime(); i <= endTime.getTime(); ) {
|
|
|
+ PtServiceLogStatis serviceLogStatis = new PtServiceLogStatis();
|
|
|
+ serviceLogStatis.getParams().put("beginTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date(i)));
|
|
|
+ serviceLogStatis.getParams().put("endTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.getLastHourTime(new Date(i), -24)));
|
|
|
+ List<PtServiceLogStatis> ptServiceLogStatis = ptServiceLogService.selectServiceLogStatis(serviceLogStatis);
|
|
|
+ ptServiceLogStatis.forEach(serviceLogStatisService::insertPtServiceLogStatis);
|
|
|
+ i = DateUtils.getLastHourTime(new Date(i), -24).getTime();
|
|
|
+ if (StringUtils.isEmpty(hashMap))
|
|
|
+ jobScheduleMapper.updateScheduleByProCode(PRO_CODE, new Date(i));
|
|
|
+ }
|
|
|
+ return ExecuteResult.success("执行成功");
|
|
|
+ }
|
|
|
+}
|