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.
110 lines
4.7 KiB
110 lines
4.7 KiB
package com.hxjt.dataupload.jobhandler.doubleprevent;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.hxjt.dataupload.model.entity.doubleprevent.Fxgkcs;
|
|
import com.hxjt.dataupload.model.entity.doubleprevent.Fxsj;
|
|
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.apache.ibatis.annotations.Param;
|
|
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;
|
|
|
|
|
|
@Component
|
|
public class FxgkcsJobHandler {
|
|
|
|
private Logger log = LoggerFactory.getLogger(FxgkcsJobHandler.class);
|
|
|
|
@Autowired
|
|
FxfxdxService fxfxdxService;
|
|
|
|
@XxlJob(value = "FxgkcsJobHandler", init = "init", destroy = "destroy")
|
|
public void execute(String param) {
|
|
String jobParam = XxlJobHelper.getJobParam();
|
|
ArrayList<Fxgkcs> fxgkcs = new ArrayList<>();
|
|
if (jobParam.equals("全量")) {
|
|
fxgkcs = fxfxdxService.getFxgkcss("N");
|
|
}else if(jobParam.equals("每日")){
|
|
fxgkcs = fxfxdxService.getFxgkcss("Y");
|
|
}
|
|
int success = 0;
|
|
int fail = 0;
|
|
for (int i = 0; i < fxgkcs.size(); i++) {
|
|
System.out.println(i + 1);
|
|
String company = fxgkcs.get(i).getQiyemingcheng();
|
|
String url = "https://www.ny-fxfk.com/space-ningyanghuagongchany/sapi/qpaas/tiga/dys/keyAuthentication/fengxianguankongqing/v1/fengxianguankongqing";
|
|
switch (company) {
|
|
case "山东恒信高科能源有限公司":
|
|
case "恒信中碳氢能源科技(山东)有限公司":
|
|
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(fxgkcs.get(i));
|
|
String post = null;
|
|
try {
|
|
post = HttpUtils.sendDataUpload(url, jsonObject, HTTP.UTF_8, "7CTkAyBoL26Jo7ZMNVmg0EA57A0791FD71AB");
|
|
boolean thisFailFlag = false;
|
|
boolean postIsNull = false;
|
|
boolean postNoMsgs = false;
|
|
if(!StringUtils.isBlank(post)){
|
|
JSONObject postJsonObj = JSONObject.parseObject(post);
|
|
if(!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("成功"+(i+1)+",");
|
|
//System.out.println(jsonObject);
|
|
//System.out.println("post:" + post.toString());
|
|
//XxlJobHelper.log("执行日志:" + company + post.toString());
|
|
|
|
success++;
|
|
}else{
|
|
thisFailFlag = true;
|
|
}
|
|
}else{
|
|
thisFailFlag = true;
|
|
postNoMsgs = true;
|
|
}
|
|
}else{
|
|
postIsNull = true;
|
|
thisFailFlag = true;
|
|
}
|
|
if(thisFailFlag){//异常情况
|
|
System.out.println("失败"+(i+1)+",隐患排查任务");
|
|
if(!postIsNull){
|
|
System.out.println("post:" + post.toString());
|
|
XxlJobHelper.log("执行日志:" + company + post.toString());
|
|
}
|
|
|
|
fail++;
|
|
}
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if(fxgkcs.size()>0){
|
|
XxlJobHelper.log("执行日志:本次有"+fxgkcs.size()+"条需要上传,成功上传"+success+"条,失败"+fail+"条");
|
|
}else{
|
|
XxlJobHelper.log("执行日志:本次无新数据需上传");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void init() {
|
|
log.info("init 方法调用成功");
|
|
}
|
|
|
|
private void destroy() {
|
|
log.info("destroy 方法调用成功");
|
|
}
|
|
|
|
}
|
|
|