src/main/java/com/ruoyi/common/utils/ImageToBase64.java
@@ -1,11 +1,25 @@ package com.ruoyi.common.utils; import java.io.ByteArrayOutputStream; import java.io.InputStream; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.ruoyi.doublePrevention.entity.CJReport.PreventCJReportRiskAnaUnit; import com.ruoyi.doublePrevention.entity.ZDReport.HandlerZDReportParam; import com.ruoyi.doublePrevention.entity.ZDReport.PreventZDReportRiskAnaUnit; import com.ruoyi.doublePrevention.enums.SyncEnum; import lombok.extern.slf4j.Slf4j; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; import java.util.Date; import java.util.List; @Slf4j public class ImageToBase64 { public static String convertImageToBase64(String imageUrl) { @@ -45,4 +59,96 @@ } public static void main(String[] args) { pushFourColorPicture(); } public static String convertImageToBase64local(String imagePath) throws IOException { File file = new File(imagePath); FileInputStream imageInFile = new FileInputStream(file); // 读取文件为字节数组 byte[] imageData = new byte[(int) file.length()]; imageInFile.read(imageData); // 使用 Base64 编码 return Base64.getEncoder().encodeToString(imageData); } public static void convertBase64ToImage(String base64Data, String outputPath) throws IOException { // 去除 Base64 数据的前缀(如果有) if (base64Data.startsWith("data:image")) { base64Data = base64Data.split(",")[1]; } // 解码 Base64 数据为字节数组 byte[] imageBytes = Base64.getDecoder().decode(base64Data); // 写入字节数组到图片文件 try (FileOutputStream imageOutFile = new FileOutputStream(outputPath)) { imageOutFile.write(imageBytes); } } public static void pushFourColorPicture() { HttpURLConnection con = null; BufferedReader buffer = null; int responseCode = 200; StringBuffer unitResultBuffer = null; //上报数据 try { URL url = new URL( "http://218.31.50.112:8087/api/wwyt/t_qyfxfbxx_List"); con = (HttpURLConnection) url.openConnection(); // 设置请求方式和参数 con.setRequestMethod("POST"); con.setDoOutput(true); con.setDoInput(true); con.setUseCaches(false); con.setRequestProperty("token", "030B6744-EECB-4732-B679-280373E7E575"); con.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); JSONObject jsonObject = new JSONObject(); jsonObject.put("ID", "mn25kwer-8956-34hj-3sdl-dl980lcfdc8a"); jsonObject.put("IMG", convertImageToBase64local("D:\\1751424343390.png")); jsonObject.put("CREATE_TIME", "20220501000000"); jsonObject.put("UPDATE_TIME", "20250701000000"); jsonObject.put("DELETE_MARK", "0"); jsonObject.put("CREATE_BY", "李康"); jsonObject.put("UPDATE_BY","李康"); JSONArray jsonArray = new JSONArray(); jsonArray.add(jsonObject); // 发送请求体 try (OutputStream os = con.getOutputStream()) { os.write(JSON.toJSONString(jsonArray).getBytes(StandardCharsets.UTF_8)); } responseCode = con.getResponseCode(); //本段日志,测试成功后,可注释掉 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); } System.out.println("上传四色图:" + unitResultBuffer); } } catch (Exception e) { e.printStackTrace(); } } } src/main/java/com/ruoyi/doublePrevention/entity/CJReport/PreventCJReportCheckRecordFromTask.java
@@ -85,14 +85,16 @@ private String defend; /** * 上报时间 */ private Date zhunReportTime; /** * 上报状态 1-待上报;2-已上报;3-不上报 */ private Byte zhunReportStatus; /** * 上报时间 */ private Date zhunReportTime; } src/main/java/com/ruoyi/doublePrevention/scheduls/SearchReportDateSchedule.java
@@ -1,6 +1,7 @@ package com.ruoyi.doublePrevention.scheduls; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.doublePrevention.entity.*; import com.ruoyi.doublePrevention.entity.CJReport.*; @@ -466,7 +467,7 @@ if (recordReportConfig.getReportState().equals(SyncEnum.REPORT_ON.getCode())){ //logger.info("【##】5.检索排查任务记录数据..."); System.out.println("【##】5.检索排查任务记录数据..."); log.info("【##】5.检索排查任务记录数据..."); //查询所有 选择上报的数据 && (reportTime == null 或者 reportTime < updateReportDataTime) List<PreventRiskDangerCheckLog> tasks = preventRiskDangerCheckLogService.listReportTask(); @@ -528,7 +529,6 @@ } } } //封装上报昌吉州的任务数据 @@ -630,7 +630,7 @@ taskIds.add(task.getId()); tag ++; } System.out.println("【##】5.数据封装完成..."); log.info("【##】5.数据封装完成..."); } }else { @@ -639,15 +639,24 @@ if (CJRecordFromTaskLists.size() > 0){ log.info("【双重预防】排查任务记录CJ:数据处理..."); log.info("【双重预防】排查任务记录CJ:数据处理开始taskIds..." + JSONObject.toJSONString(taskIds)); //设置原始数据状态 int taskUpdateResult = preventRiskDangerCheckLogService.updateTaskReportStatusByList(taskIds); if (taskUpdateResult < taskIds.size()){ log.error("【双重预防】排查任务记录CJ:数据处理开始taskIds...排查任务记录原始数据更新失败, 取消操作"); throw new AusinessException(E.ADD_FAIL.getCode(), "排查任务记录原始数据更新失败, 取消操作"); } log.info("【双重预防】排查任务记录CJ:数据处理开始CJRecordFromTaskLists..." + JSONObject.toJSONString(CJRecordFromTaskLists)); int result = CJTaskRecordService.insertRecordList(CJRecordFromTaskLists); if (result < CJRecordFromTaskLists.size()){ log.error("【双重预防】排查任务记录CJ:数据处理开始taskIds...排查任务记录插入失败, 取消操作"); throw new AusinessException(E.ADD_FAIL.getCode(), "排查任务记录插入失败, 取消操作"); } } step = 6; }else { @@ -810,8 +819,6 @@ } // /** // * 7、检索检修记录数据 // * */ @@ -880,12 +887,6 @@ // logger.info("检修记录数据上报已关闭"); // } // // TODO 目前应急厅没有风险点概念,此处暂时不写。目前看,风险点概念,类似管控措施,对用某个具体的风险位置 src/main/resources/mybatis/doublePrevention/PreventCJReportCheckRecordFromTaskMapper.xml
@@ -87,8 +87,8 @@ values <foreach collection="list" item="record" separator=","> (null, #{record.id}, #{record.companyCode}, #{record.deleted}, #{record.createDate}, #{record.createBy}, #{record.updateDate},#{record.updateBy}, #{record.reportStatus}, #{record.reportTime}, #{record.dataSource}, #{record.checkTaskId}, #{record.checkStatus}, #{record.checkTime}, #{record.createByMobile}, #{record.updateByMobile}, #{record.taskId}, #{record.mobileCode}, #{record.defend}, #{record.zhunReportStatus}, #{record.zhunReportTime}) #{record.reportStatus}, null, #{record.dataSource}, #{record.checkTaskId}, #{record.checkStatus}, #{record.checkTime}, #{record.createByMobile}, #{record.updateByMobile}, #{record.taskId}, #{record.mobileCode}, #{record.defend}, #{record.zhunReportStatus}, null) </foreach> </insert>