You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
7.7 KiB
179 lines
7.7 KiB
package com.hxjt.dataupload.jobhandler.specialassignments;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.hxjt.dataupload.model.entity.tszy.aqcs.Aqcs;
|
|
import com.hxjt.dataupload.model.entity.tszy.upload.Dzaqzy;
|
|
import com.hxjt.dataupload.model.entity.tszy.upload.Lsydzy;
|
|
import com.hxjt.dataupload.service.FxfxdxService;
|
|
import com.hxjt.dataupload.utils.HttpUtils;
|
|
import com.hxjt.dataupload.utils.JingWeiDuConverter;
|
|
import com.hxjt.dataupload.utils.tszy.DzaqzyUtil;
|
|
import com.hxjt.dataupload.utils.tszy.LsydzyUtil;
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.http.protocol.HTTP;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
@Component
|
|
public class LsydzyJobHandler {
|
|
|
|
|
|
|
|
private Logger log = LoggerFactory.getLogger(LsydzyJobHandler.class);
|
|
|
|
@Autowired
|
|
FxfxdxService fxfxdxService;
|
|
|
|
@XxlJob(value = "LsydzyJobHandler", init = "init", destroy = "destroy")
|
|
public void execute(String param) {
|
|
String jobParam = XxlJobHelper.getJobParam();
|
|
|
|
int pageSize = 1000;
|
|
int success = 0;
|
|
int fail = 0;
|
|
long total = 0;
|
|
|
|
|
|
int pageNum = 1;
|
|
do {
|
|
List<Lsydzy> onePage = new ArrayList<>();
|
|
// 1. 启动分页(必须紧邻查询语句)
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
// 2. 执行查询(此时SQL已被自动拦截并添加分页逻辑)
|
|
if (jobParam.equals("全量")) {
|
|
onePage = fxfxdxService.getOneLsydzysPage("N");
|
|
} else {
|
|
onePage = fxfxdxService.getOneLsydzysPage("Y");
|
|
}
|
|
|
|
// 3. 封装分页结果
|
|
PageInfo<Lsydzy> 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()));
|
|
}
|
|
//对本页数据进行上传
|
|
for (int x = 0; x < pageInfo.getList().size(); x++) {
|
|
|
|
String shenqingdanwei = pageInfo.getList().get(x).getShenqingdanwei();
|
|
String url = "https://www.ny-fxfk.com/space-ningyanghuagongchany/sapi/qpaas/tiga/dys/keyAuthentication/linshiyongdiananquan/v1/linshiyongdiananquan";
|
|
if(shenqingdanwei.equals("山东恒信高科能源有限公司")){
|
|
//恒信高科
|
|
//查询安全措施
|
|
ArrayList<Aqcs> aqcsList = fxfxdxService.queryDhAqcsByBianhao(pageInfo.getList().get(x).getBianhao());
|
|
//根据安全措施列表便利处理给当前上传对象赋值相关字段
|
|
for (Aqcs aqcs: aqcsList) {
|
|
LsydzyUtil.handle(pageInfo.getList().get(x),aqcs);
|
|
//System.out.println(aqcs);
|
|
}
|
|
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, "C6MC32Ig7bjNMfNiFn9f0349DF6D105F39E0");
|
|
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();
|
|
}
|
|
|
|
}
|
|
}else{
|
|
//中碳氢能源
|
|
System.out.println(1);
|
|
}
|
|
|
|
|
|
}
|
|
pageNum++;
|
|
|
|
} while (total > (pageNum - 1) * pageSize);
|
|
|
|
|
|
|
|
|
|
if (total > 0) {
|
|
XxlJobHelper.log("执行日志:本次有" + total + "条需要上传,成功上传" + success + "条,失败" + fail + "条");
|
|
} else {
|
|
XxlJobHelper.log("执行日志:本次无新数据需上传");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void init() {
|
|
log.info("init 方法调用成功");
|
|
}
|
|
|
|
private void destroy() {
|
|
log.info("destroy 方法调用成功");
|
|
}
|
|
}
|
|
|