|
|
|
|
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;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("dataupload/api/v1")
|
|
|
|
|
public class UploadController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AsyncTask asyncTask;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private FxfxdxService fxfxdxService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ZypSingleQueryMapper zypSingleQueryMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("list")
|
|
|
|
|
public Object list(){
|
|
|
|
|
|
|
|
|
|
Map<String,String > map = new HashMap<>();
|
|
|
|
|
map.put("1","asdfdsa");
|
|
|
|
|
map.put("2","S6543465");
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@GetMapping("async")
|
|
|
|
|
public JsonData testAsync(){
|
|
|
|
|
long begin = System.currentTimeMillis();
|
|
|
|
|
/*asyncTask.task1();
|
|
|
|
|
asyncTask.task2();
|
|
|
|
|
asyncTask.task3();*/
|
|
|
|
|
Future<String> task4 = asyncTask.task4();
|
|
|
|
|
Future<String> task5 = asyncTask.task5();
|
|
|
|
|
for(;;){
|
|
|
|
|
if(task4.isDone() && task5.isDone()){
|
|
|
|
|
try {
|
|
|
|
|
String task4Result = task4.get();
|
|
|
|
|
System.out.println(task4Result);
|
|
|
|
|
|
|
|
|
|
String task5Result = task5.get();
|
|
|
|
|
System.out.println(task5Result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}catch (InterruptedException e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}catch (ExecutionException e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
return JsonData.buildSuccess(end-begin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*获取用户有权限的启用状态的表单列表树形结构*/
|
|
|
|
|
@RequestMapping(value = "/getOTBILLIDById")
|
|
|
|
|
public JsonData getCustomerFormList(@RequestBody Map<String,String> requestBody) {
|
|
|
|
|
//System.out.println(requestBody.get("id"));
|
|
|
|
|
if(!StringUtils.isBlank(requestBody.get("id"))){
|
|
|
|
|
Map<String,String> result = fxfxdxService.getOTBILLIDById(requestBody.get("id"));
|
|
|
|
|
return JsonData.buildSuccess(result);
|
|
|
|
|
}else{
|
|
|
|
|
return JsonData.buildError("请先输入id");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/uploadPDF")
|
|
|
|
|
public ResponseEntity<String> uploadPdf(
|
|
|
|
|
@RequestParam("file") MultipartFile file,
|
|
|
|
|
@RequestParam("id") String id,
|
|
|
|
|
@RequestParam("ticketNumber") String ticketNumber,
|
|
|
|
|
@RequestParam("zypTypeId") String zypTypeId) {
|
|
|
|
|
//上线
|
|
|
|
|
String uploadDir = "F://dataUpload/zypPdfs/";
|
|
|
|
|
// 1. 验证文件类型和大小
|
|
|
|
|
if (file.isEmpty()) {
|
|
|
|
|
return ResponseEntity.badRequest().body("文件不能为空");
|
|
|
|
|
}
|
|
|
|
|
if (!file.getContentType().equals("application/pdf")) {
|
|
|
|
|
return ResponseEntity.badRequest().body("仅支持PDF格式");
|
|
|
|
|
}
|
|
|
|
|
if (file.getSize() > 10 * 1024 * 1024) { // 限制10MB
|
|
|
|
|
return ResponseEntity.badRequest().body("文件大小超过限制");
|
|
|
|
|
}
|
|
|
|
|
System.out.println(id);
|
|
|
|
|
System.out.println(ticketNumber);
|
|
|
|
|
System.out.println(zypTypeId);
|
|
|
|
|
try {
|
|
|
|
|
// 确保目录存在
|
|
|
|
|
File targetDir = new File(uploadDir);
|
|
|
|
|
if (!targetDir.exists()) {
|
|
|
|
|
targetDir.mkdirs(); // 自动创建多级目录
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 生成唯一文件名(可选,避免重复覆盖)
|
|
|
|
|
String fileName = id+ "_" +ticketNumber+".pdf";
|
|
|
|
|
|
|
|
|
|
// 构建目标文件的绝对路径
|
|
|
|
|
File targetFile = new File(targetDir.getAbsolutePath() + File.separator + fileName);
|
|
|
|
|
|
|
|
|
|
// 保存文件到磁盘
|
|
|
|
|
file.transferTo(targetFile);
|
|
|
|
|
|
|
|
|
|
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<String, Object> 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<Dhzy> 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<Dhzy> 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<Aqcs> 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("执行日志:本次无新数据需上传");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|