16639036659
2023-12-11 e6ab9c2b7af85ac676ef9fbe616327eb20f04139
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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() + ";");
//            }
 
 
    }
 
}