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.
91 lines
3.6 KiB
91 lines
3.6 KiB
package com.hxjt.dataupload.jobhandler.doubleprevent;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.hxjt.dataupload.model.entity.doubleprevent.Fxfxdx;
|
|
import com.hxjt.dataupload.model.entity.doubleprevent.Fxfxdy;
|
|
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.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;
|
|
|
|
|
|
@Component
|
|
public class FxsjJobHandler {
|
|
|
|
private Logger log = LoggerFactory.getLogger(FxsjJobHandler.class);
|
|
|
|
@Autowired
|
|
FxfxdxService fxfxdxService;
|
|
|
|
@XxlJob(value = "FxsjJobHandler", init = "init", destroy = "destroy")
|
|
public void execute(String param) {
|
|
|
|
ArrayList<Fxsj> fxsjs = fxfxdxService.getFxsjs();
|
|
int success = 0;
|
|
int fail = 0;
|
|
|
|
for (int i = 0; i < fxsjs.size(); i++) {
|
|
|
|
String company = fxsjs.get(i).getQiyemingcheng();
|
|
String url = "https://www.ny-fxfk.com/space-ningyanghuagongchany/sapi/qpaas/tiga/dys/keyAuthentication/fengxianshijianxinxi/v1/fengxianshijianxinxi";
|
|
switch (company) {
|
|
case "山东恒信高科能源有限公司":
|
|
case "恒信中碳氢能源科技(山东)有限公司":
|
|
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(fxsjs.get(i));
|
|
String post = null;
|
|
try {
|
|
//success++;
|
|
post = HttpUtils.sendDataUpload(url, jsonObject, HTTP.UTF_8, "GGUIPRh5bemgUmX8bvyn76E2ACA7DEE82AB4");
|
|
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("成功"+(i+1)+",");
|
|
//System.out.println(jsonObject);
|
|
//System.out.println("post:" + post.toString());
|
|
//XxlJobHelper.log("执行日志:" + company + post.toString());
|
|
|
|
success++;
|
|
}else{
|
|
System.out.println("成功"+(i+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;
|
|
//System.out.println("post:"+post1.toString());
|
|
}
|
|
}
|
|
if(fxsjs.size()>0){
|
|
XxlJobHelper.log("执行日志:本次有"+fxsjs.size()+"条需要上传,成功上传"+success+"条,失败"+fail+"条");
|
|
}else{
|
|
XxlJobHelper.log("执行日志:本次无新数据需上传");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private void init() {
|
|
log.info("init 方法调用成功");
|
|
}
|
|
|
|
private void destroy() {
|
|
log.info("destroy 方法调用成功");
|
|
}
|
|
|
|
}
|
|
|