src/main/java/com/zy/asrs/task/ReportDataScheduler.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/asrs/task/handler/AgvWrkMastHandler.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/asrs/task/handler/ReportDataHandler.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/zy/asrs/task/ReportDataScheduler.java
@@ -1,16 +1,15 @@ package com.zy.asrs.task; import cn.hutool.core.bean.BeanUtil; 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; import com.zy.asrs.entity.ReportDataLog; 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,11 +17,8 @@ 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; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -38,12 +34,10 @@ private ReportDataService reportDataService; @Autowired private ReportDataLogService reportDataLogService; @Autowired private ApiLogService apiLogService; @Autowired private ReportDataHandler reportDataHandler; @Value("${mes.appKey}") private String appKey; @@ -52,75 +46,36 @@ @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; @Scheduled(cron = "0/10 * * * * ? ") @Scheduled(fixedDelay = 5000) public void execute() { log.info("定时任务开始执行"); if (!flag) { return; } List<ReportData> reportData = reportDataService.selectList(new EntityWrapper<>()); if (!Cools.isEmpty(reportData)) { Page<ReportData> objectPage = new Page<>(1, 1000); 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) { process(data, mesTokenInfo); for (ReportData data : reportData.getRecords()) { try { reportDataHandler.start(data, mesTokenInfo); } catch (Exception e) { log.error("数据处理异常,{}", data.getId()); } } } 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; } 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信息 @@ -162,5 +117,4 @@ } } } src/main/java/com/zy/asrs/task/handler/AgvWrkMastHandler.java
@@ -715,10 +715,19 @@ } } if (OUT_TYPE_List.contains(agvWrkMast.getIoType())) { reportMesPakoutOrder(agvWrkMast, agvWrkDetls); String barcode = agvWrkMast.getBarcode(); if (barcode.startsWith("20") || barcode.startsWith("21") || barcode.startsWith("40")) { reportMesPakoutOrder(agvWrkMast, agvWrkDetls); } } if (MOVE_TYPE_List.contains(agvWrkMast.getIoType())) { generateMesParam(agvWrkMast, agvWrkDetls); String barcode = agvWrkMast.getBarcode(); if (agvWrkMast == null || agvWrkMast.getBarcode() == null) { return; } if (barcode.startsWith("20") || barcode.startsWith("21") || barcode.startsWith("40")) { generateMesParam(agvWrkMast, agvWrkDetls); } } src/main/java/com/zy/asrs/task/handler/ReportDataHandler.java
New file @@ -0,0 +1,115 @@ package com.zy.asrs.task.handler; import cn.hutool.core.bean.BeanUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.core.common.Cools; import com.core.exception.CoolException; import com.zy.asrs.entity.ReportData; import com.zy.asrs.entity.ReportDataLog; import com.zy.asrs.service.ApiLogService; import com.zy.asrs.service.ReportDataLogService; import com.zy.asrs.service.ReportDataService; import com.zy.asrs.task.AbstractHandler; import com.zy.asrs.task.core.ReturnT; import com.zy.common.utils.HttpHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.Map; import java.util.concurrent.TimeUnit; /** * Created by vincent on 2020/7/7 */ @Service public class ReportDataHandler extends AbstractHandler<String> { private static final Logger log = LoggerFactory.getLogger(ReportDataHandler.class); @Autowired private ReportDataService reportDataService; @Autowired private ReportDataLogService reportDataLogService; @Autowired private ApiLogService apiLogService; @Value("${mes.url}") private String url; @Value("${mes.orderReportPath}") private String orderReportPath; @Value("${mes.pakinReportPath}") private String pakinReportPath; @Value("${mes.buyPakinReportPath}") private String buyPakinReportPath; @Value("${mes.pakoutReportPath}") private String pakoutReportPath; @Transactional public ReturnT<String> start(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; } 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); } return SUCCESS; } private JSONObject doHttpRequest(String requestParam, Map<String, Object> headParam, String namespace, String url, String path, String appkey, String ip) { String response = ""; boolean success = false; try { response = new HttpHandler.Builder().setUri(url).setPath(path).setTimeout(30, TimeUnit.SECONDS).setHeaders(headParam).setJson(requestParam).setHttps(true).build().doPost(); JSONObject jsonObject = JSON.parseObject(response); if (Cools.isEmpty(jsonObject.get("code")) || Integer.parseInt(jsonObject.get("code").toString()) != 200) { log.info("mes接口调用失败,返回信息:" + jsonObject); //TODO 张超 throw new CoolException("mes接口调用失败,返回信息:" + jsonObject); } success = true; return jsonObject; } catch (Exception e) { log.error(e.getMessage()); throw new CoolException(e.getMessage()); } finally { apiLogService.save(namespace, url + path, appkey, ip, requestParam, response, success); } } }