package com.ruoyi.doublePrevention.scheduls;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.ruoyi.doublePrevention.entity.CJReport.ReportResultDTO;
|
import com.ruoyi.doublePrevention.entity.PreventReportConfig;
|
import com.ruoyi.doublePrevention.enums.SyncEnum;
|
import com.ruoyi.doublePrevention.service.baseService.*;
|
import com.ruoyi.doublePrevention.utilsCJ.AesGcm256Util;
|
import com.ruoyi.project.tr.report.service.ReportService;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.io.*;
|
import java.net.HttpURLConnection;
|
import java.net.URL;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
@Component
|
public class CheckExecResultSchedule {
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
@Autowired
|
private ReportService reportService;
|
|
@Autowired
|
private PreventCJReportRiskAnaUnitService CJRiskAnaUnitService;
|
@Autowired
|
private PreventCJReportRiskEventService CJEventService;
|
@Autowired
|
private PreventCJReportRiskControlMeasureService CJMeasureService;
|
@Autowired
|
private PreventCJReportCheckTaskFromWorkService CJTaskFromWorkService;
|
@Autowired
|
private PreventCJReportCheckRecordFromTaskService CJTaskRecordService;
|
@Autowired
|
private PreventCJReportDangerInfoService CJDangerInfoService;
|
@Autowired
|
private PreventCJReportPointService CJPointService;
|
@Autowired
|
private PreventCJReportOverhaulLogService CJOverhaulLogService;
|
@Autowired
|
private PreventReportConfigService preventReportConfigService;
|
|
String token = "GT6gGJV7JV";
|
String key = "Bv+NeBolwqg2Pbc1yVwrZA==";
|
String iv = "4QC9V8eAiB7tdlgBkMsTAw==";
|
|
public static final int MAC_BIT_SIZE = 128;
|
|
// public static String encrypt(String plainText, byte[] key, byte[] iv) {
|
// String sr;
|
// try {
|
// byte[] plainBytes = plainText.getBytes(StandardCharsets.UTF_8);
|
// GCMBlockCipher cipher = new GCMBlockCipher(new
|
// AESFastEngine());
|
// AEADParameters parameters =
|
// new AEADParameters(new KeyParameter(key),
|
// MAC_BIT_SIZE, iv, null);
|
// cipher.init(true, parameters);
|
// byte[] encryptedBytes = new
|
// byte[cipher.getOutputSize(plainBytes.length)];
|
// int retLen = cipher.processBytes(plainBytes, 0, plainBytes.length,
|
// encryptedBytes, 0);
|
// cipher.doFinal(encryptedBytes, retLen);
|
// sr = Base64.getEncoder().encodeToString(encryptedBytes);
|
// } catch (Exception ex) {
|
// throw new RuntimeException(ex.getMessage());
|
// }
|
// return sr;
|
// }
|
//
|
|
|
@Transactional
|
// @Scheduled(cron = "0 0 23 * * ?") //每天晚上23点执行一次0 0 22,23 * * ?
|
// @Scheduled(cron = "0 0 22,23 * * ?") //每天晚上22、23点执行一次
|
// @Scheduled(cron = "0 0/1 * * * ? ") // 分钟
|
// @Scheduled(cron = "0 0/20 * * * ? ") // 分钟
|
// @Scheduled(cron = "0/10 * * * * ?")
|
public void execReportDateSchedule() throws UnsupportedEncodingException {
|
logger.info("【¥¥】检查上报结果...");
|
|
String token = "4348187236"; // todo token暂时使用众泰
|
String key = "84702E415A73CE27077B5F726E7BDBB0";
|
String iv = "1C7AA98593AA69F4AAE119BD5C01D9ED";
|
|
HttpURLConnection con = null;
|
BufferedReader buffer = null;
|
int responseCode = 200;
|
|
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
|
|
Date date = new Date();
|
//格式化时间,作为token的时间戳
|
SimpleDateFormat tokenDate= new SimpleDateFormat("yyyyMMddHHMMssSSS");
|
String formatDate = tokenDate.format(date);
|
|
//使用风险分析单元数据上报主配置,作为自动上报开关
|
PreventReportConfig reportConfig = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_ANA_UNIT.getCode());
|
if (reportConfig.getReportType() == 0){
|
return;
|
}
|
|
/**
|
* 1、处理安全风险分析单元数据
|
* */
|
logger.info("查询处理数据...");
|
//加密数据
|
StringBuffer unitResultBuffer = null;
|
|
List<String> batchId = new ArrayList<>();
|
batchId.add("e7272b6b-fb68-4db7-ad06-f763a43b351c");
|
|
//上报数据
|
try {
|
URL url = new URL("http://117.190.86.66:6022/v2/data/receive/getLog");
|
//得到连接对象
|
con = (HttpURLConnection) url.openConnection();
|
//设置请求类型
|
con.setRequestMethod("POST");
|
//允许写出
|
con.setDoOutput(true);
|
//允许读入
|
con.setDoInput(true);
|
//不使用缓存
|
con.setUseCaches(false);
|
con.setInstanceFollowRedirects(true);
|
//设置请求头
|
con.setRequestProperty("Authorization",token + formatDate.toString());
|
//设置Content-Type,此处根据实际情况确定
|
con.setRequestProperty("Content-Type", "application/json;charset=utf8");
|
|
OutputStream os = con.getOutputStream();
|
Map paraMap = new HashMap();
|
paraMap.put("batchId", batchId);
|
/**封装数据*/
|
//组装入参,设置请求体
|
os.write(JSON.toJSONString(paraMap).getBytes());
|
|
//本段日志,测试成功后,可注释掉
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
//得到响应流
|
InputStream inputStream = con.getInputStream();
|
//将响应流转换成字符串
|
unitResultBuffer = new StringBuffer();
|
String line;
|
buffer = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
while ((line = buffer.readLine()) != null) {
|
unitResultBuffer.append(line);
|
}
|
logger.info("result:" + unitResultBuffer.toString());
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
//接收返回值,保存返回值
|
List<String> errorIdList= new ArrayList<>();
|
|
//拼接上报数据的uuid
|
StringBuffer idTextBuffer = new StringBuffer();
|
|
//接收参数,转为对象
|
ReportResultDTO unitResult = JSONObject.parseObject(unitResultBuffer.toString(), ReportResultDTO.class);
|
|
//设置所有数据上报成功
|
// for (PreventCJReportRiskAnaUnit riskAnaUnit : CJRiskAnaUnits) {
|
// HandlerReportParam handlerReportParam = new HandlerReportParam();
|
// //封装数据
|
// handlerReportParam.setId(riskAnaUnit.getRiskUnitId());
|
// handlerReportParam.setReportStatus(SyncEnum.SYNC_EXEC_SUCCESS.getCode());
|
// handlerReportParam.setReportTime(date);
|
// CJRiskAnaUnitService.updateReportStatus(handlerReportParam);
|
// idTextBuffer.append(riskAnaUnit.getId() + ";");
|
// }
|
|
|
}
|
|
}
|