6 changed files with 315 additions and 0 deletions
@ -0,0 +1,179 @@ |
|||
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.Dlzy; |
|||
import com.hxjt.dataupload.model.entity.tszy.upload.Dtzy; |
|||
import com.hxjt.dataupload.service.FxfxdxService; |
|||
import com.hxjt.dataupload.utils.HttpUtils; |
|||
import com.hxjt.dataupload.utils.JingWeiDuConverter; |
|||
import com.hxjt.dataupload.utils.tszy.DlzyUtil; |
|||
import com.hxjt.dataupload.utils.tszy.DtzyUtil; |
|||
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 DlzyJobHandler { |
|||
|
|||
|
|||
|
|||
private Logger log = LoggerFactory.getLogger(DlzyJobHandler.class); |
|||
|
|||
@Autowired |
|||
FxfxdxService fxfxdxService; |
|||
|
|||
@XxlJob(value = "DlzyJobHandler", 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<Dlzy> onePage = new ArrayList<>(); |
|||
// 1. 启动分页(必须紧邻查询语句)
|
|||
PageHelper.startPage(pageNum, pageSize); |
|||
// 2. 执行查询(此时SQL已被自动拦截并添加分页逻辑)
|
|||
if (jobParam.equals("全量")) { |
|||
onePage = fxfxdxService.getOneDlzysPage("N"); |
|||
} else { |
|||
onePage = fxfxdxService.getOneDlzysPage("Y"); |
|||
} |
|||
|
|||
// 3. 封装分页结果
|
|||
PageInfo<Dlzy> 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/duanluanquanzuoyebao/v1/duanluanquanzuoyebao"; |
|||
if(shenqingdanwei.equals("山东恒信高科能源有限公司")){ |
|||
//恒信高科
|
|||
//查询安全措施
|
|||
ArrayList<Aqcs> aqcsList = fxfxdxService.queryDhAqcsByBianhao(pageInfo.getList().get(x).getBianhao()); |
|||
//根据安全措施列表便利处理给当前上传对象赋值相关字段
|
|||
for (Aqcs aqcs: aqcsList) { |
|||
DlzyUtil.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, "vSc603IKlc4iaKAsbCV8880424DAAA87A529"); |
|||
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 方法调用成功"); |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
package com.hxjt.dataupload.utils.tszy; |
|||
|
|||
import com.hxjt.dataupload.model.entity.tszy.aqcs.Aqcs; |
|||
import com.hxjt.dataupload.model.entity.tszy.upload.Dlzy; |
|||
import com.hxjt.dataupload.model.entity.tszy.upload.Dtzy; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
public class DlzyUtil { |
|||
public static void handle(Dlzy dlzy, Aqcs aqcs) { |
|||
if(StringUtils.isBlank(aqcs.getQuerenren())||StringUtils.isBlank(aqcs.getShifousheji())){ |
|||
|
|||
}else{ |
|||
if(aqcs.getAncuoneirong().startsWith("作业前,制定交通组织")){ |
|||
dlzy.setAnquancuoshi1(aqcs.getShifousheji().equals("Y")?"是":"否"); |
|||
dlzy.setQuerenren1(aqcs.getQuerenren()); |
|||
}else if(aqcs.getAncuoneirong().startsWith("作业前,在断路的路口")){ |
|||
dlzy.setAnquancuoshi2(aqcs.getShifousheji().equals("Y")?"是":"否"); |
|||
dlzy.setQuerenren2(aqcs.getQuerenren()); |
|||
}else if(aqcs.getAncuoneirong().startsWith("夜间作业设")){ |
|||
dlzy.setAnquancuoshi3(aqcs.getShifousheji().equals("Y")?"是":"否"); |
|||
dlzy.setQuerenren3(aqcs.getQuerenren()); |
|||
}else if(aqcs.getAncuoneirong().startsWith("夜间作业设")){ |
|||
dlzy.setAnquancuoshi3(aqcs.getShifousheji().equals("Y")?"是":"否"); |
|||
dlzy.setQuerenren3(aqcs.getQuerenren()); |
|||
}else if(aqcs.getAncuoneirong().startsWith("其他安全措")){ |
|||
dlzy.setQitaanquancuoshi(DhAqcsUtil.processSecurityMeasures(aqcs.getAncuoneirong())); |
|||
dlzy.setBianzhiren(aqcs.getQuerenren()); |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
Loading…
Reference in new issue