LogicOperation.java
7.8 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package com.sy.logic;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.sy.crossDomain.buildBarCode;
import com.sy.model.GatherInfo;
import com.sy.model.LandBusinessTypeList;
import com.sy.model.LandRoadVe;
import com.sy.service.LandBusListService;
import com.sy.service.LandRoadVeService;
import com.sy.socket.CommandClient;
import com.sy.utils.FileTool;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.List;
import java.util.Map;
@Component
public class LogicOperation {
private static final Logger logger = Logger.getLogger(LogicOperation.class);
@Autowired
private LandBusListService listService;
@Autowired
private LandRoadVeService veService;
private static LogicOperation logic;
//读取配置文件里的载重与称重的可控范围
private static String checkWt = FileTool.readProperties("grossWt");
//逻辑判断后的结果定义
private static String PERMITTHOUGH = "直接放行";
private static String GROWSSEXCETION = "禁止通行,重量不在可控范围";
private static String NORECORD = "车辆未备案";
private static String INPUTSTATION = "此车辆未做进站申请";
private static String ENTERSTATION = "此车辆未做出站申请";
private static String ISVALID = "二维码已失效或者此车辆未做出入申请";
@PostConstruct
public void init() {
logic = this;
logic.listService = this.listService;
logic.veService = this.veService;
}
/**
* @Param info 卡口采集数据
* @Result 计算卡口采集数据并发送报文
*/
public static boolean operation(GatherInfo info) {
boolean result = false;
if(info.getBarcode()==null || info.getBarcode().length()<=0 ){
return result;
}
BigDecimal grosswt = info.getGrosswt();
//转为double类型
double growssWt = grosswt.doubleValue();
String ietype = info.getIetype();
List<LandBusinessTypeList> lists = null;
String vaName = info.getVename();
if(vaName==null || vaName.length()<=0 ){
return result;
}
LandRoadVe ve = logic.veService.selectByFrameNo(vaName);
LandBusinessTypeList list = logic.listService.selectForOne(info.getVename(),info.getBarcode(),info.getAreaid
(),info.getChnlno(),info.getIetype());
if("0".equals(list.getIsvalid())){
double goodsWt = 0.0;
if (list.getMasterList()!=null || list.getMasterList().length()>0 ) {
goodsWt = GoodsWt(list.getMasterList(), info.getIetype());
}
double selfWt = Double.parseDouble(ve.getSelfWt());
if (sendBw(info, growssWt, selfWt, goodsWt)) {
if ("I".equals(info.getIetype())) {
list.setContrastflag("已进站");
} else {
list.setContrastflag("已出站");
}
logic.listService.updateById(list);
List<LandBusinessTypeList> businessTypeLists = logic.listService.selectByBarcode(info.getBarcode());
int count = 0;
for(int i=0; i<businessTypeLists.size(); i++){
String flag1 = businessTypeLists.get(i).getContrastflag();
if(flag1 != null){
count++;
}
}
if("货物流转".equals(list.getBusinesstype())){
if(count==4){
buildBarCode.cancleBarCode(vaName);
logic.listService.updateByBarcode(info.getBarcode());
}
}else{
if(count==2){
buildBarCode.cancleBarCode(vaName);
logic.listService.updateByBarcode(info.getBarcode());
}
}
result = true;
}
}else{
CommandClient.Client(info, ISVALID);
}
return result;
}
//将获取的checkWt进行小数转化
public static double valueDob() {
NumberFormat nf = NumberFormat.getPercentInstance();
Number m = null;
try {
m = nf.parse(checkWt);//将百分数转换成Number类型
} catch (ParseException e) {
e.printStackTrace();
logger.info(e.getMessage());
}
return m.doubleValue();
}
/**
* @Param grossWt 地磅称重
* @Param wt 车辆自重
* @Param goodsWt 货物总重
* @Result 获取运单重量
*/
//校验载重和称重是否在合理的范围
public static boolean checkResult(double grossWt, double wt, double goodsWt) {
DecimalFormat df=new DecimalFormat("0.00");
boolean flag = false;
double result = 0.0;
if (goodsWt > 0) {
result = Double.parseDouble(df.format(Math.abs((goodsWt+wt-grossWt)/grossWt)));
} else {
result = Double.parseDouble(df.format(Math.abs((grossWt - wt)/grossWt)));
}
if (result <= valueDob()) {
flag = true;
}
return flag;
}
/**
* @Param mainifast 主单列表
* @Param ietype 进出标志
* 获取货物总重
*/
public static double GoodsWt(String mainifast, String ietype) {
Double sum = 0.0;
if (mainifast.length() > 0) {
String[] mainifastList = mainifast.split(",");
for (String mainBill : mainifastList) {
sum = sum += getGrossWt(mainBill, ietype);
}
}
return sum;
}
/**
* @Param waybill 主单号
* @Param imp 进出港标识
* @Result 获取运单重量
*/
public static double getGrossWt(String waybill, String imp) {
String url = "http://tjfx.15miaoo.com:8003/tj/orig/orig?waybill=" + waybill + "&imp=" + imp;
StringBuilder json = new StringBuilder();
Map map = null;
double bg = 0;
try {
URL Url = new URL(url);
URLConnection yc = Url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine = null;
while ((inputLine = in.readLine()) != null) {
json.append(inputLine);
}
JSONArray array = JSONArray.parseArray(json.toString());
for (int i = 0; i < array.size(); i++) {
map = JSON.parseObject(array.getString(i));
if (map.get("receiptinformation").toString().startsWith("41301") || map.get("receiptinformation")
.toString().startsWith("41106")) {
bg = Double.parseDouble((String) map.get("totalweight"));
return bg;
}
}
in.close();
} catch (MalformedURLException e) {
e.getMessage();
} catch (IOException e) {
e.getMessage();
}
return bg;
}
/**
* 校验重量并发送报文
*/
public static boolean sendBw(GatherInfo info, double growsswWt, double selfWt, double goodsWt) {
boolean flag = false;
if (checkResult(growsswWt, selfWt, goodsWt)) {
CommandClient.Client(info, PERMITTHOUGH);
flag = true;
} else {
CommandClient.Client(info, GROWSSEXCETION);
}
return flag;
}
}