From 9ed4cb53a2c643b879f993537f5a2793fba56ba1 Mon Sep 17 00:00:00 2001 From: ZY <zc857179121@qq.com> Date: 星期一, 31 三月 2025 07:57:13 +0800 Subject: [PATCH] 1 --- src/main/java/com/zy/asrs/task/ReportDataScheduler.java | 97 +++++++++++++++++++++--------------------------- 1 files changed, 42 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/zy/asrs/task/ReportDataScheduler.java b/src/main/java/com/zy/asrs/task/ReportDataScheduler.java index 1a850fa..73fb731 100644 --- a/src/main/java/com/zy/asrs/task/ReportDataScheduler.java +++ b/src/main/java/com/zy/asrs/task/ReportDataScheduler.java @@ -1,9 +1,10 @@ package com.zy.asrs.task; -import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; import com.core.common.Cools; import com.core.exception.CoolException; import com.zy.asrs.entity.ReportData; @@ -11,6 +12,7 @@ import com.zy.asrs.service.ApiLogService; import com.zy.asrs.service.ReportDataLogService; import com.zy.asrs.service.ReportDataService; +import com.zy.asrs.task.handler.ReportDataHandler; import com.zy.common.utils.HttpHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,7 +20,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.HashMap; @@ -40,10 +41,11 @@ @Autowired private ReportDataLogService reportDataLogService; - @Autowired private ApiLogService apiLogService; + @Autowired + private ReportDataHandler reportDataHandler; @Value("${mes.appKey}") private String appKey; @@ -52,73 +54,50 @@ @Value("${mes.appSecret}") private String appSecret; + @Value("${mes.report}") private Boolean flag; - - @Value("${mes.url}") - private String url; @Value("${mes.getTokenUrl}") private String getTokenUrl; - @Value("${mes.orderReportPath}") - private String orderReportPath; - - @Value("${mes.pakinReportPath}") - private String pakinReportPath; - - @Value("${mes.buyPakinReportPath}") - private String buyPakinReportPath; - - @Value("${mes.pakoutReportPath}") - private String pakoutReportPath; - @Value("${mes.getTokenPath}") private String getTokenPath; + @Value("${mes.stock}") + private String stock; - @Scheduled(cron = "0/10 * * * * ? ") + + /** + * 鍒犻櫎鍛婅鏃ュ織 + */ + @Scheduled(cron = "0 0 2 * * ? ") + private void delReportDataLog() { + String format = DateUtil.format(DateUtil.offsetMonth(new Date(), -2), "yyyy-MM-dd HH:mm:ss"); + List<ReportDataLog> agvWarnList = reportDataLogService.selectList(new EntityWrapper<ReportDataLog>().le("create_time", format)); + for (ReportDataLog agvWarn : agvWarnList) { + reportDataLogService.deleteById(agvWarn); + } + } + + + @Scheduled(fixedDelay = 30000) public void execute() { - log.info("瀹氭椂浠诲姟寮�濮嬫墽琛�"); if (!flag) { return; } - Map<String, Object> mesTokenInfo = getMesTokenInfo(); - List<ReportData> reportData = reportDataService.selectList(new EntityWrapper<>()); - for (ReportData data : reportData) { - process(data, mesTokenInfo); - } - log.info("瀹氭椂浠诲姟缁撴潫鎵ц"); - } - - @Transactional - public void process(ReportData data, Map<String, Object> mesTokenInfo) { - String mesPath = ""; - if ("MES".equals(data.getReportType())) { - switch (data.getMemo()) { - case "涓婃姤mes閲囪喘鍏ュ簱淇℃伅": - mesPath = buyPakinReportPath; - break; - case "涓婃姤mes鍏ュ簱淇℃伅": - mesPath = pakinReportPath; - break; - case "涓婃姤mes鍑哄簱淇℃伅": - mesPath = pakoutReportPath; - break; - case "涓婃姤mes璋冩嫧淇℃伅": - mesPath = orderReportPath; - break; + Page<ReportData> objectPage = new Page<>(1, 100); + Page<ReportData> reportData = reportDataService.selectPage(objectPage, new EntityWrapper<ReportData>().orderBy("create_time", false)); + if (reportData != null && !Cools.isEmpty(reportData.getRecords())) { + Map<String, Object> mesTokenInfo = getMesTokenInfo(); + for (ReportData data : reportData.getRecords()) { + try { + reportDataHandler.start(data, mesTokenInfo); + } catch (Exception e) { + log.error("鏁版嵁澶勭悊寮傚父锛寋}", data.getId()); + } } - doHttpRequest(data.getReportJson(), mesTokenInfo, data.getMemo(), url, mesPath, null, "127.0.0.1"); - reportDataService.deleteById(data.getId()); - ReportDataLog reportDataLog = new ReportDataLog(); - BeanUtil.copyProperties(data, reportDataLog); - reportDataLog.setReportTime(new Date()); - reportDataLog.setReportDataId(data.getId()); - reportDataLogService.insert(reportDataLog); } - - } //鑾峰彇mes token淇℃伅 @@ -156,9 +135,17 @@ log.error(e.getMessage()); throw new CoolException(e.getMessage()); } finally { - apiLogService.save(namespace, url + path, appkey, ip, JSON.toJSONString(JSONObject.toJSONString(requestParam)), response, success); + apiLogService.save(namespace, url + path, appkey, ip, requestParam, response, success); } } + //@Scheduled(fixedDelay = 1000 * 60 * 30) + public void executeStock() { + if (!flag) { + return; + } + Map<String, Object> mesTokenInfo = getMesTokenInfo(); + reportDataHandler.stock(mesTokenInfo); + } } -- Gitblit v1.9.1