BillTask.java
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.agent.billcheck;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.agent.entity.agent.BillCheckEntity;
import com.agent.service.agent.BillCheckFeeService;
import com.agent.service.agent.BillCheckService;
import com.framework.util.JsonKit;
import com.jfinal.kit.HttpKit;
import com.jfinal.kit.StrKit;
/**
* Depiction:
* <p>
* Modify:
* <p>
* Author: William Lynn
* <p>
* Create Date:2018年9月6日 下午12:09:07
*
*/
@Component
public class BillTask {
public static boolean isRunning = false;
private final static String BILL_API = "http://10.50.3.64:8080/tj/cost/cost";
@Scheduled(cron = "10 * * * * ?")
public void perform() {
if (BillTask.isRunning) {
return;
}
BillTask.isRunning = true;
System.err.println();
System.err.println("BillTask start,will get json data......");
BillCheckService billCheckService = (BillCheckService) SpringContextKit.getBean("billCheckService");
BillCheckEntity last = billCheckService.last();
int fid = last != null ? last.getFid() : 0;
System.err.println("BillTask start,last fid is: " + fid);
Map<String, String> queryParas = new HashMap<>();
queryParas.put("fid", String.valueOf(fid));
String json = "";
try {
json = HttpKit.get(BILL_API, queryParas);
} catch (Exception e) {
System.err.println("BillTask get json data error -->" + e.toString());
}
List<BillCheckBean> list = JsonKit.parseArray(json, BillCheckBean.class);
if (list != null && !list.isEmpty()) {
BillCheckFeeService billCheckFeeService = (BillCheckFeeService) SpringContextKit
.getBean("billCheckFeeService");
for (BillCheckBean bean : list) {
String mawbNo = bean.getCode();
String start = mawbNo.substring(0, 3);
String end = mawbNo.substring(3, mawbNo.length());
mawbNo = start + "-" + end;
bean.setCode(mawbNo);
if (!billCheckService.exist(mawbNo)) {
bean.setStation(getStationCode(bean.getChgseq()));
billCheckService.save(bean);
}
if (!billCheckFeeService.exist(mawbNo, bean.getFeenm())) {
billCheckFeeService.save(bean);
}
}
}
System.err.println("BillTask end, get json data finish......");
BillTask.isRunning = false;
}
private String getStationCode(String str) {
if (StrKit.isBlank(str))
return "";
String code = str.replaceAll("[^(A-Za-z)]", "");
return code;
}
}