LogicOperation.java
5.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
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
package com.sy.logic;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
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.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");
@PostConstruct
public void init(){
logic = this;
logic.listService = this.listService;
logic.veService = this.veService;
}
public boolean operation(GatherInfo info){
//开关
boolean sign = false;
BigDecimal grosswt = info.getGrosswt();
//转为double类型
double growsswWt = grosswt.doubleValue();
String ietype = info.getIetype();
List<LandBusinessTypeList>lists = null;
LandRoadVe ve = logic.veService.selectByFrameNo(info.getIcvename());
if("E".equals(ietype)){
ietype = "出场站";
lists = logic.listService.selectByFrameNoAndType(info.getIcvename(),ietype);
for (LandBusinessTypeList list:lists) {
//查询是否做了出场申请
if(list.getContrastflag()=="" | list.getContrastflag()==null){
//判断车重
//判断载货重量是否符合所设定的范围
double goodsWt = GoodsWt(list.getMasterList(),"E");
if(checkResult(growsswWt,Double.parseDouble(ve.getSelfWt()),goodsWt)){
sign = true;
}
//发送放行指令
String flag = "";
CommandClient.Client(info,flag);
}
}
}else {
ietype = "进场站";
lists = listService.selectByFrameNoAndType(info.getIcvename(),ietype);
}
return sign;
}
//将获取的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 boolean checkResult(double grossWt,double wt,double goodsWt){
boolean flag = false;
double result = (grossWt-wt)/goodsWt;
BigDecimal bd = new BigDecimal(result);
if(bd.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue()<=valueDob()){
flag = true;
}
return flag;
}
/**
* @Param mainifast 主单列表
* @Param ietype 进出标志
* 获取货物总重
* */
public static double GoodsWt(String mainifast,String ietype){
String [] mainifastList = mainifast.split(",");
Double sum = 0.0;
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 oracle = new URL(url);
URLConnection yc = oracle.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")) {
bg = Double.parseDouble((String) map.get("totalweight"));
return bg;
}
}
in.close();
} catch (MalformedURLException e) {
e.getMessage();
} catch (IOException e) {
e.getMessage();
}
return bg;
}
}