From cc49eba63b005ade54144099f5c995f2ba10e336 Mon Sep 17 00:00:00 2001
From: liwenxuan <1298531568@qq.com>
Date: Wed, 23 Apr 2025 09:06:05 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=A5=A8=E9=99=84=E4=BB=B6?=
=?UTF-8?q?=E4=B8=8A=E4=BC=A0-=E5=8A=A8=E7=81=AB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 5 +
.../controller/UploadController.java | 209 ++++-
.../hxjt/dataupload/mapper/FxfxdxMapper.java | 3 +-
.../mapper/ZypSingleQueryMapper.java | 28 +
.../hxjt/dataupload/mqtt/MqttCallback.java | 4 +-
.../dataupload/service/FxfxdxService.java | 3 +-
.../service/impl/FxfxdxServiceImpl.java | 3 +-
.../hxjt/dataupload/utils/FileUploadUtil.java | 73 ++
src/main/resources/application-dev.yml | 3 +-
src/main/resources/mapper/FxfxdxMapper.xml | 15 +-
.../resources/mapper/ZypSingleQueryMapper.xml | 839 ++++++++++++++++++
11 files changed, 1169 insertions(+), 16 deletions(-)
create mode 100644 src/main/java/com/hxjt/dataupload/mapper/ZypSingleQueryMapper.java
create mode 100644 src/main/java/com/hxjt/dataupload/utils/FileUploadUtil.java
create mode 100644 src/main/resources/mapper/ZypSingleQueryMapper.xml
diff --git a/pom.xml b/pom.xml
index f3a0830..7238a65 100644
--- a/pom.xml
+++ b/pom.xml
@@ -195,6 +195,11 @@
pagehelper-spring-boot-starter
1.4.6
+
+ com.konghq
+ unirest-java
+ 3.13.6
+
diff --git a/src/main/java/com/hxjt/dataupload/controller/UploadController.java b/src/main/java/com/hxjt/dataupload/controller/UploadController.java
index 80321e8..d7827ed 100644
--- a/src/main/java/com/hxjt/dataupload/controller/UploadController.java
+++ b/src/main/java/com/hxjt/dataupload/controller/UploadController.java
@@ -1,9 +1,23 @@
package com.hxjt.dataupload.controller;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.hxjt.dataupload.mapper.ZypSingleQueryMapper;
+import com.hxjt.dataupload.model.entity.tszy.aqcs.Aqcs;
+import com.hxjt.dataupload.model.entity.tszy.upload.Dhzy;
import com.hxjt.dataupload.service.FxfxdxService;
import com.hxjt.dataupload.task.AsyncTask;
+import com.hxjt.dataupload.utils.FileUploadUtil;
+import com.hxjt.dataupload.utils.HttpUtils;
+import com.hxjt.dataupload.utils.JingWeiDuConverter;
import com.hxjt.dataupload.utils.JsonData;
+import com.hxjt.dataupload.utils.tszy.DhAqcsUtil;
+//import com.xxl.job.core.context.XxlJobHelper;
import org.apache.commons.lang3.StringUtils;
+import org.apache.http.protocol.HTTP;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
@@ -17,11 +31,12 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
/**
* liwenxuan
@@ -37,6 +52,11 @@ private AsyncTask asyncTask;
@Autowired
private FxfxdxService fxfxdxService;
+@Autowired
+private ZypSingleQueryMapper zypSingleQueryMapper;
+
+
+
@RequestMapping("list")
public Object list(){
@@ -85,7 +105,7 @@ private FxfxdxService fxfxdxService;
public JsonData getCustomerFormList(@RequestBody Map requestBody) {
//System.out.println(requestBody.get("id"));
if(!StringUtils.isBlank(requestBody.get("id"))){
- String result = fxfxdxService.getOTBILLIDById(requestBody.get("id"));
+ Map result = fxfxdxService.getOTBILLIDById(requestBody.get("id"));
return JsonData.buildSuccess(result);
}else{
return JsonData.buildError("请先输入id");
@@ -96,7 +116,8 @@ private FxfxdxService fxfxdxService;
public ResponseEntity uploadPdf(
@RequestParam("file") MultipartFile file,
@RequestParam("id") String id,
- @RequestParam("ticketNumber") String ticketNumber) {
+ @RequestParam("ticketNumber") String ticketNumber,
+ @RequestParam("zypTypeId") String zypTypeId) {
//上线
String uploadDir = "F://dataUpload/zypPdfs/";
// 1. 验证文件类型和大小
@@ -109,9 +130,9 @@ private FxfxdxService fxfxdxService;
if (file.getSize() > 10 * 1024 * 1024) { // 限制10MB
return ResponseEntity.badRequest().body("文件大小超过限制");
}
- /*System.out.println(id);
+ System.out.println(id);
System.out.println(ticketNumber);
-*/
+ System.out.println(zypTypeId);
try {
// 确保目录存在
File targetDir = new File(uploadDir);
@@ -127,10 +148,182 @@ private FxfxdxService fxfxdxService;
// 保存文件到磁盘
file.transferTo(targetFile);
- return ResponseEntity.ok("上传成功");
+
+ if(zypTypeId.equals("e3dbc4258dae4f21961dbb0e83701929")||zypTypeId.equals("626e96e90760406a98c20f2f1f9d014f")){
+ boolean flag = dh(id, ticketNumber, zypTypeId,targetFile);
+ if(flag){
+ return ResponseEntity.ok("上传成功");
+ }else{
+ return ResponseEntity.internalServerError().body("失败");
+ }
+ }else{
+ return ResponseEntity.internalServerError().body("失败");
+ }
+
+
+ //return ResponseEntity.ok("上传成功");
} catch (IOException e) {
return ResponseEntity.internalServerError().body("文件存储失败:" + e.getMessage());
}
}
+
+ public boolean dh(String id,String ticketNumber,String zypTypeId,File file) {
+ //附件上传
+ FileUploadUtil fileUploadUtil = new FileUploadUtil();
+ Map uploadResult = fileUploadUtil.upload(file);
+ Object body1 = uploadResult.get("body");
+ String body1json = JSON.toJSONString(body1);
+ com.alibaba.fastjson2.JSONObject body1JsonObject = JSON.parseObject(body1json);
+ String body2Str = (String)body1JsonObject.get("body");
+ System.out.println(body2Str);
+ com.alibaba.fastjson2.JSONObject body2JsonObject = JSON.parseObject(body2Str);
+ JSONArray dataJsonArr = (JSONArray) body2JsonObject.get("data");
+ String dataStr = JSON.toJSONString(dataJsonArr);
+ System.out.println(dataStr);
+ String zuoyepiao = dataStr;
+ String jobParam = "全量";
+ //附件上传
+
+
+
+ int pageSize = 1000;
+ int success = 0;
+ int fail = 0;
+ long total = 0;
+
+
+ int pageNum = 1;
+ do {
+ List onePage = new ArrayList<>();
+ // 1. 启动分页(必须紧邻查询语句)
+ PageHelper.startPage(pageNum, pageSize);
+ // 2. 执行查询(此时SQL已被自动拦截并添加分页逻辑)
+ if (jobParam.equals("全量")) {
+ onePage = zypSingleQueryMapper.getOneDhzysPage("N",id);
+ } else {
+ onePage = zypSingleQueryMapper.getOneDhzysPage("Y",id);
+ }
+
+ // 3. 封装分页结果
+ PageInfo pageInfo = new PageInfo<>(onePage);
+ //设置总数
+ total = pageInfo.getTotal();
+ System.out.println("总条数:" + total);
+ System.out.println("第" + pageNum + "页");
+ System.out.println("本页条数:" + pageInfo.getList().size());
+ //处理经纬度
+ for (int x = 0; x < pageInfo.getList().size(); x++) {
+ pageInfo.getList().get(x).setJingweidu(JingWeiDuConverter.createGeoPoint(pageInfo.getList().get(x).getJingweidu()));
+ //附件上传
+ pageInfo.getList().get(x).setZuoyepiao(zuoyepiao);
+ //附件上传
+ }
+ //对本页数据进行上传
+ for (int x = 0; x < pageInfo.getList().size(); x++) {
+
+ String qiyebianma = pageInfo.getList().get(x).getQiyebianma();
+ String url = "https://ny-fxfk.com/space-ningyanghuagongchany/sapi/qpaas/tiga/dys/keyAuthentication/donghuozuoyebaobei/v1/donghuozuoyebaobei";
+ switch (qiyebianma) {
+ case "370910170":
+ //恒信高科
+ //查询安全措施
+ ArrayList dhAqcsList = fxfxdxService.queryDhAqcsByBianhao(pageInfo.getList().get(x).getBianhao());
+ //根据安全措施列表便利处理给当前上传对象赋值相关字段
+ for (Aqcs dhAqcs: dhAqcsList) {
+ DhAqcsUtil.handle(pageInfo.getList().get(x),dhAqcs);
+ }
+ JSONObject jsonObject = (JSONObject) JSONObject.toJSON(pageInfo.getList().get(x));
+ String post = null;
+
+ //System.out.println(jsonObject);
+
+
+ try {
+ post = HttpUtils.sendDataUpload(url, jsonObject, HTTP.UTF_8, "PrBMPrhf0qLDFwj6bnLJ7D1821BA364FFDC5");
+ boolean thisFailFlag = false;
+ boolean postIsNull = false;
+ boolean postNoMsgs = false;
+ if(!StringUtils.isBlank(post)){
+ JSONObject postJsonObj = JSONObject.parseObject(post);
+ if(postJsonObj.get("msg")!=null && postJsonObj.get("code")!=null && postJsonObj.get("status")!=null && !StringUtils.isBlank(postJsonObj.get("msg").toString())&&!StringUtils.isBlank(postJsonObj.get("code").toString())&&!StringUtils.isBlank(postJsonObj.get("status").toString())){
+ if(postJsonObj.get("msg").equals("成功")&&postJsonObj.get("code").toString().equals("1000000")&&postJsonObj.get("status").toString().equals("200")){//status
+ //成功
+ System.out.println("成功"+(x+1)+",");
+
+
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+ String formattedDate = LocalDateTime.now().format(formatter);
+ System.out.println(" 当前时间: " + formattedDate); // 示例输出:2025-03-12 08:29:25
+ System.out.println(jsonObject);
+ System.out.println("post:" + post.toString());
+
+ success++;
+ }else{
+ thisFailFlag = true;
+ }
+ }else{
+ thisFailFlag = true;
+ postNoMsgs = true;
+ }
+ }else{
+ postIsNull = true;
+ thisFailFlag = true;
+ }
+ if(thisFailFlag){//异常情况
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+ String formattedDate = LocalDateTime.now().format(formatter);
+ System.out.println(" 当前时间: " + formattedDate); // 示例输出:2025-03-12 08:29:25
+ System.out.println("失败"+(x+1)+",动火作业");
+ if(!postIsNull){
+ System.out.println("post:" + post.toString());
+ //XxlJobHelper.log("执行日志:(恒信高科)" + post.toString());
+ }
+
+ System.out.println(jsonObject);
+
+ fail++;
+ Thread.sleep(120000);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ //XxlJobHelper.log("错误信息:" + e);
+ //XxlJobHelper.log("请求体:" + jsonObject);
+ try {
+ TimeUnit.MINUTES.sleep(2); // 直接指定分钟
+ } catch (InterruptedException ie) {
+ Thread.currentThread().interrupt();
+ }
+
+ }
+ break;
+ case "370980326":
+ //中碳氢能源
+ System.out.println(1);
+ }
+
+
+ }
+ pageNum++;
+
+ } while (total > (pageNum - 1) * pageSize);
+
+
+
+ //附件上传
+ if (total > 0) {
+ return true;
+ //XxlJobHelper.log("执行日志:本次有" + total + "条需要上传,成功上传" + success + "条,失败" + fail + "条");
+ } else {
+ return false;
+ //XxlJobHelper.log("执行日志:本次无新数据需上传");
+ }
+
+
+ }
+
+
+
+
+
}
diff --git a/src/main/java/com/hxjt/dataupload/mapper/FxfxdxMapper.java b/src/main/java/com/hxjt/dataupload/mapper/FxfxdxMapper.java
index ff0c499..f419ab5 100644
--- a/src/main/java/com/hxjt/dataupload/mapper/FxfxdxMapper.java
+++ b/src/main/java/com/hxjt/dataupload/mapper/FxfxdxMapper.java
@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
@Mapper
public interface FxfxdxMapper {
@@ -47,5 +48,5 @@ public interface FxfxdxMapper {
List getOneDlzysPage(@Param("isSingleDay")String isSingleDay);
- String getOTBILLIDById(@Param("id")String id);
+ Map getOTBILLIDById(@Param("id")String id);
}
diff --git a/src/main/java/com/hxjt/dataupload/mapper/ZypSingleQueryMapper.java b/src/main/java/com/hxjt/dataupload/mapper/ZypSingleQueryMapper.java
new file mode 100644
index 0000000..5663eb0
--- /dev/null
+++ b/src/main/java/com/hxjt/dataupload/mapper/ZypSingleQueryMapper.java
@@ -0,0 +1,28 @@
+package com.hxjt.dataupload.mapper;
+
+import com.hxjt.dataupload.model.entity.tszy.aqcs.Aqcs;
+import com.hxjt.dataupload.model.entity.tszy.upload.*;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Mapper
+public interface ZypSingleQueryMapper {
+ List getOneDhzysPage(@Param("isSingleDay")String isSingleDay,@Param("id")String id);
+
+ List getOneSxkjzysPage(@Param("isSingleDay")String isSingleDay,@Param("id")String id);
+
+ List getOneMbcdzysPage(@Param("isSingleDay")String isSingleDay,@Param("id")String id);
+
+ List getOneGczysPage(@Param("isSingleDay")String isSingleDay,@Param("id")String id);
+
+ List getOneDzaqzysPage(@Param("isSingleDay")String isSingleDay,@Param("id")String id);
+
+ List getOneLsydzysPage(@Param("isSingleDay")String isSingleDay,@Param("id")String id);
+
+ List getOneDtzysPage(@Param("isSingleDay")String isSingleDay,@Param("id")String id);
+
+ List getOneDlzysPage(@Param("isSingleDay")String isSingleDay,@Param("id")String id);
+}
diff --git a/src/main/java/com/hxjt/dataupload/mqtt/MqttCallback.java b/src/main/java/com/hxjt/dataupload/mqtt/MqttCallback.java
index a554cae..0c483d5 100644
--- a/src/main/java/com/hxjt/dataupload/mqtt/MqttCallback.java
+++ b/src/main/java/com/hxjt/dataupload/mqtt/MqttCallback.java
@@ -23,11 +23,11 @@ public class MqttCallback implements org.eclipse.paho.client.mqttv3.MqttCallback
@Override
public void connectionLost(Throwable throwable) {
- // 连接丢失后,一般在这里面进行重连
+ /*// 连接丢失后,一般在这里面进行重连
logger.info("连接断开,可以做重连");
if (client == null || !client.isConnected()) {
mqttConfig.getMqttPushClient();
- }
+ }*/
}
@Override
diff --git a/src/main/java/com/hxjt/dataupload/service/FxfxdxService.java b/src/main/java/com/hxjt/dataupload/service/FxfxdxService.java
index 0d66caf..d5df444 100644
--- a/src/main/java/com/hxjt/dataupload/service/FxfxdxService.java
+++ b/src/main/java/com/hxjt/dataupload/service/FxfxdxService.java
@@ -7,6 +7,7 @@ import com.hxjt.dataupload.model.entity.tszy.upload.*;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
public interface FxfxdxService {
//风险分析对象
@@ -49,5 +50,5 @@ public interface FxfxdxService {
//断路作业
List getOneDlzysPage(String isSingleDay);
- String getOTBILLIDById(String id);
+ Map getOTBILLIDById(String id);
}
diff --git a/src/main/java/com/hxjt/dataupload/service/impl/FxfxdxServiceImpl.java b/src/main/java/com/hxjt/dataupload/service/impl/FxfxdxServiceImpl.java
index 6ad0534..df48852 100644
--- a/src/main/java/com/hxjt/dataupload/service/impl/FxfxdxServiceImpl.java
+++ b/src/main/java/com/hxjt/dataupload/service/impl/FxfxdxServiceImpl.java
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
@Service
public class FxfxdxServiceImpl implements FxfxdxService {
@@ -106,7 +107,7 @@ public class FxfxdxServiceImpl implements FxfxdxService {
}
@Override
- public String getOTBILLIDById(String id) {
+ public Map getOTBILLIDById(String id) {
return fxfxdxMapper.getOTBILLIDById(id);
}
}
diff --git a/src/main/java/com/hxjt/dataupload/utils/FileUploadUtil.java b/src/main/java/com/hxjt/dataupload/utils/FileUploadUtil.java
new file mode 100644
index 0000000..f7c1c14
--- /dev/null
+++ b/src/main/java/com/hxjt/dataupload/utils/FileUploadUtil.java
@@ -0,0 +1,73 @@
+package com.hxjt.dataupload.utils;
+
+
+import kong.unirest.HttpResponse;
+import kong.unirest.Unirest;
+import kong.unirest.UnirestException;
+import org.springframework.web.multipart.MultipartFile;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+public class FileUploadUtil {
+
+ // 通用文件上传方法(支持自定义Header)
+ public static Map upload(File file) {
+ String url = "https://ny-fxfk.com/gp-gateway/dts/file/upload";
+ String authorization = "3e382cf7-d5af-75be-9578-ee7911ed8e01";
+ Map result = new HashMap<>();
+
+ try {
+
+ // 构建请求并打印请求详情
+ System.out.println("========== HTTP REQUEST ==========");
+ System.out.println("POST " + url);
+ System.out.println("Headers:");
+ System.out.println(" Authorization: " + authorization);
+ System.out.println("Multipart Form Data:");
+ System.out.println(" file: " + file.getName() +
+ " (Size: " + file.length() + " bytes)");
+ System.out.println("===================================");
+
+ // 构建请求并添加Header
+ Unirest.post(url)
+ .header("Authorization", authorization) // 设置Authorization
+ .field("files", file)
+ .asString()
+ .ifSuccess(response -> {
+ result.put("status", response.getStatus());
+ result.put("body", response);
+ System.out.println(response.getBody());
+ })
+ .ifFailure(response -> {
+ result.put("status", response.getStatus());
+ result.put("error", response);
+ });
+ ;
+
+ } catch (UnirestException e) {
+ result.put("status", 500);
+ result.put("error", "请求失败: " + e.getMessage());
+ }
+ return result;
+ }
+
+ // 初始化配置(在Spring启动时调用)
+ public static void init() {
+ Unirest.config()
+ .connectTimeout(10000)
+ .socketTimeout(60000)
+ .concurrency(20, 5);
+ }
+
+ // 关闭资源(在Spring关闭时调用)
+ public static void shutdown() {
+ try {
+ Unirest.shutDown();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
index b444c8d..57ab867 100644
--- a/src/main/resources/application-dev.yml
+++ b/src/main/resources/application-dev.yml
@@ -18,6 +18,7 @@ spring:
multipart:
max-file-size: 10MB
max-request-size: 10MB
+ enabled: true
autoconfigure:
#去除durid配置
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
@@ -66,7 +67,7 @@ spring:
mqtt:
username: 10@ningyanghuagongchany20250328091457
password: 4c0d00b8dcdd4809ad75ad1d0e38533c
- hostUrl: tcp://112.245.55.112:18183
+ hostUrl: tcp://112.245.55.112:18183-----
clientId: 10@ningyanghuagongchany20250328091457
defaultTopic: /indoor/10@ningyanghuagongchany20250328091457/thirdParty/sensorData
timeout: 100
diff --git a/src/main/resources/mapper/FxfxdxMapper.xml b/src/main/resources/mapper/FxfxdxMapper.xml
index 7527f57..ca33fb3 100644
--- a/src/main/resources/mapper/FxfxdxMapper.xml
+++ b/src/main/resources/mapper/FxfxdxMapper.xml
@@ -3,8 +3,18 @@
-