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
8.0 KiB
179 lines
8.0 KiB
package com.hxjt.dataupload.jobhandler.doubleprevent;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.hxjt.dataupload.model.entity.doubleprevent.Fxfxdx;
|
|
import com.hxjt.dataupload.model.entity.doubleprevent.Yhpcrw;
|
|
import com.hxjt.dataupload.service.FxfxdxService;
|
|
import com.hxjt.dataupload.utils.HttpUtils;
|
|
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.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
|
|
@Component
|
|
public class YhpcrwJobHandler {
|
|
|
|
private Logger log = LoggerFactory.getLogger(YhpcrwJobHandler.class);
|
|
|
|
@Autowired
|
|
FxfxdxService fxfxdxService;
|
|
|
|
@XxlJob(value = "YhpcrwJobHandler", 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;
|
|
ArrayList<Fxfxdx> zdwxys = fxfxdxService.getZdwxys();
|
|
|
|
int pageNum = 1;
|
|
do {
|
|
List<Yhpcrw> onePage = new ArrayList<>();
|
|
// 1. 启动分页(必须紧邻查询语句)
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
// 2. 执行查询(此时SQL已被自动拦截并添加分页逻辑)
|
|
if (jobParam.equals("全量")) {
|
|
onePage = fxfxdxService.getOneYhpcrwsPage("N");
|
|
} else {
|
|
onePage = fxfxdxService.getOneYhpcrwsPage("Y");
|
|
}
|
|
|
|
// 3. 封装分页结果
|
|
PageInfo<Yhpcrw> 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++) {
|
|
|
|
|
|
|
|
//在此进行上传
|
|
|
|
String HAZARD_NAME = pageInfo.getList().get(x).getFengxianfenxiduixian();
|
|
for (int j = 0; j < zdwxys.size(); j++) {
|
|
String DANGESOURCE_NAME = zdwxys.get(j).getZhongdaweixianyuanmi();
|
|
switch (HAZARD_NAME) {
|
|
case "重大危险源甲醇中间储存":
|
|
if (DANGESOURCE_NAME.equals("甲醇中间储存单元")) {
|
|
pageInfo.getList().get(x).setZhongdaweixianyuanmi(DANGESOURCE_NAME);
|
|
pageInfo.getList().get(x).setZhongdaweixianyuande(zdwxys.get(j).getZhongdaweixianyuande());
|
|
}
|
|
break;
|
|
case "重大危险源化产油库":
|
|
if (DANGESOURCE_NAME.equals("化产油库区")) {
|
|
pageInfo.getList().get(x).setZhongdaweixianyuanmi(DANGESOURCE_NAME);
|
|
pageInfo.getList().get(x).setZhongdaweixianyuande(zdwxys.get(j).getZhongdaweixianyuande());
|
|
}
|
|
break;
|
|
case "重大危险源甲醇储罐":
|
|
if (DANGESOURCE_NAME.equals("甲醇储存单元")) {
|
|
pageInfo.getList().get(x).setZhongdaweixianyuanmi(DANGESOURCE_NAME);
|
|
pageInfo.getList().get(x).setZhongdaweixianyuande(zdwxys.get(j).getZhongdaweixianyuande());
|
|
}
|
|
break;
|
|
case "重大危险源空分站":
|
|
if (DANGESOURCE_NAME.equals("空分站单元")) {
|
|
pageInfo.getList().get(x).setZhongdaweixianyuanmi(DANGESOURCE_NAME);
|
|
pageInfo.getList().get(x).setZhongdaweixianyuande(zdwxys.get(j).getZhongdaweixianyuande());
|
|
}
|
|
break;
|
|
case "重大危险源气柜储存":
|
|
if (DANGESOURCE_NAME.equals("气柜")) {
|
|
pageInfo.getList().get(x).setZhongdaweixianyuanmi(DANGESOURCE_NAME);
|
|
pageInfo.getList().get(x).setZhongdaweixianyuande(zdwxys.get(j).getZhongdaweixianyuande());
|
|
}
|
|
break;
|
|
case "重大危险源粗苯蒸馏":
|
|
if (DANGESOURCE_NAME.equals("粗苯蒸馏单元")) {
|
|
pageInfo.getList().get(x).setZhongdaweixianyuanmi(DANGESOURCE_NAME);
|
|
pageInfo.getList().get(x).setZhongdaweixianyuande(zdwxys.get(j).getZhongdaweixianyuande());
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if ((!StringUtils.isBlank(pageInfo.getList().get(x).getZhongdaweixianyuande())) && pageInfo.getList().get(x).getZhongdaweixianyuande().length() > 2) {
|
|
pageInfo.getList().get(x).setZhongdaweixianyuande(pageInfo.getList().get(x).getZhongdaweixianyuande().substring(0, 2));
|
|
}
|
|
|
|
|
|
|
|
String company = pageInfo.getList().get(x).getQiyemingcheng();
|
|
String url = "https://www.ny-fxfk.com/space-ningyanghuagongchany/sapi/qpaas/tiga/dys/keyAuthentication/yinhuanpaicharenwu/v1/yinhuanpaicharenwu";
|
|
switch (company) {
|
|
case "山东恒信高科能源有限公司":
|
|
case "恒信中碳氢能源科技(山东)有限公司":
|
|
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(pageInfo.getList().get(x));
|
|
String post = null;
|
|
try {
|
|
post = HttpUtils.sendDataUpload(url, jsonObject, HTTP.UTF_8, "tp9tNKR6nGsS2mpdWzrQ02D93621E3411A0F");
|
|
|
|
JSONObject postJsonObj = JSONObject.parseObject(post);
|
|
if(postJsonObj.get("msg").equals("成功")&&postJsonObj.get("code").toString().equals("1000000")&&postJsonObj.get("status").toString().equals("200")){//status
|
|
//成功
|
|
System.out.println("成功"+(x+1)+",");
|
|
//System.out.println(jsonObject);
|
|
//System.out.println("post:" + post.toString());
|
|
//XxlJobHelper.log("执行日志:" + company + post.toString());
|
|
|
|
success++;
|
|
}else{
|
|
System.out.println("成功"+(x+1)+",");
|
|
System.out.println("post:" + post.toString());
|
|
XxlJobHelper.log("执行日志:" + company + post.toString()+jsonObject);
|
|
|
|
fail++;
|
|
}
|
|
} catch (IOException e) {
|
|
fail++;
|
|
e.printStackTrace();
|
|
System.out.println(jsonObject);
|
|
XxlJobHelper.handleFail( "-->任务执行失败" + e.getMessage()+jsonObject);
|
|
}
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
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 方法调用成功");
|
|
}
|
|
|
|
}
|
|
|