|
|
package com.sy.logic;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.sy.crossDomain.buildBarCode;
|
|
|
import com.sy.model.*;
|
|
|
import com.sy.relation.VeManifestRelation;
|
|
|
import com.sy.service.EnterCancelServer;
|
|
|
import com.sy.service.LandBusListService;
|
|
|
import com.sy.service.LandRoadVeService;
|
|
|
import com.sy.service.ResMessageService;
|
|
|
import com.sy.socket.CommandClient;
|
|
|
import com.sy.utils.FileTool;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.client.HttpClient;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
import org.apache.log4j.PropertyConfigurator;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
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.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
@Component
|
|
|
public class LiftBar {
|
|
|
private static final Logger logger = Logger.getLogger(LiftBar.class);
|
|
|
@Autowired
|
|
|
private LandBusListService listService;//进出场申请表
|
|
|
@Autowired
|
|
|
private LandRoadVeService veService;//车辆信息备案表
|
|
|
@Autowired
|
|
|
private ResMessageService resMessageService;//查询运单放行表
|
|
|
@Autowired
|
|
|
private EnterCancelServer enterCancelServer;//调拨业务单独记录表
|
|
|
private static LiftBar logic = new LiftBar();
|
|
|
//从配置文件中读取货物重差可控范围
|
|
|
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 = "二维码数据异常,请使用正确的二维码数据";
|
|
|
private static String ERRORWT = "出起始场站的重量和进目的场站的重量不一致";
|
|
|
private static String IEPORSE = "无相对应进出场申请";
|
|
|
private static String FANGXING="有运单未放行";
|
|
|
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
logic = this;
|
|
|
logic.listService = this.listService;
|
|
|
logic.veService = this.veService;
|
|
|
logic.resMessageService = this.resMessageService;
|
|
|
logic.enterCancelServer = this.enterCancelServer;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Param info 卡口采集数据
|
|
|
* @Result 计算卡口采集数据并发送报文
|
|
|
*/
|
|
|
public static boolean liftBar(GatherInfo info) {
|
|
|
PropertyConfigurator.configure("config/log4j.properties");
|
|
|
//默认返回值
|
|
|
boolean result = false;
|
|
|
//获取过磅重量
|
|
|
double growssWt = info.getGrosswt().doubleValue();
|
|
|
double goodsWt=0.0,inWt=0.0,diffVal=0.0;
|
|
|
//取车牌号,判定卡口是否取到车牌号
|
|
|
String vaName = info.getVename();
|
|
|
//若无车牌号,返回未识别错误
|
|
|
if (vaName.length() <= 0) {
|
|
|
CommandClient.Client(info, NORECORD + vaName);
|
|
|
return result;
|
|
|
}
|
|
|
//校验车辆是否备案
|
|
|
LandRoadVe ve = logic.veService.selectByFrameNo(vaName);
|
|
|
//若无备案信息,返回车辆未备案或者识别错误
|
|
|
if (ve == null) {
|
|
|
CommandClient.Client(info, NORECORD + vaName);
|
|
|
return result;
|
|
|
}
|
|
|
/**
|
|
|
* 车牌号,二维码,场站ID/号,通道ID/号,进出业务类型标识I/E
|
|
|
* 查询是否已有此场站通道的申请
|
|
|
*/
|
|
|
//通过车牌号,二维码,场站,通道号,进出类型查询进出场站申请列表
|
|
|
LandBusinessTypeList list = logic.listService.selectForOne(info.getVename(), info.getBarcode(), info.getAreaid(), info.getChnlno(), info.getIetype());
|
|
|
//若查询结果为null,返回无相对应进出场申请
|
|
|
if (list == null) {
|
|
|
CommandClient.Client(info, IEPORSE);
|
|
|
return result;
|
|
|
}
|
|
|
//判断进出场申请二维码是否已经失效,若失效,sendError
|
|
|
if ("0".equals(list.getIsvalid())) {
|
|
|
//校验重量开始
|
|
|
boolean checkResult = false;
|
|
|
boolean check = false;
|
|
|
boolean checkMainfest =false;
|
|
|
|
|
|
//判断是进场申请还是出场申请
|
|
|
if("I".equals(info.getIetype())){
|
|
|
//进场申请宽进
|
|
|
checkResult=true;
|
|
|
}else{
|
|
|
//获取对应场站进场申请的货物重量,进场过磅重量
|
|
|
List<LandBusinessTypeList> listWt=logic.listService.selectwt(list.getTrailerFrameNo(),list.getBarcode(),list.getEndstation(),"I");
|
|
|
for(LandBusinessTypeList typeList:listWt){
|
|
|
if(typeList.getRemark()!=null && typeList.getRemark()!=""){
|
|
|
//货物重量
|
|
|
goodsWt=Double.parseDouble(typeList.getRemark());
|
|
|
}
|
|
|
if(typeList.getAislewt()!=null){
|
|
|
//对应场站进场过磅重量
|
|
|
inWt=typeList.getAislewt();
|
|
|
}
|
|
|
diffVal = inWt- growssWt;
|
|
|
}
|
|
|
//判断场站出场是否要重量校验
|
|
|
if(FileTool.readProperties("station").equals(list.getEndstation())){
|
|
|
checkResult=true;
|
|
|
}else if(!"普通货".equals(list.getCocode())){
|
|
|
checkResult=true;
|
|
|
}else {
|
|
|
check = logic.checkResult(growssWt, Double.parseDouble(ve.getSelfWt()), goodsWt,inWt);
|
|
|
if("出口送货".equals(list.getBusinesstype())){
|
|
|
if(check){
|
|
|
checkResult=true;
|
|
|
}else{
|
|
|
CommandClient.Client(info, GROWSSEXCETION);
|
|
|
}
|
|
|
}else{
|
|
|
checkMainfest = logic.checkManifest(list.getMasterList());
|
|
|
if(checkMainfest){
|
|
|
checkResult=check || checkMainfest;
|
|
|
}else{
|
|
|
CommandClient.Client(info, FANGXING);//有运单未放行
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if(logic.sendBw(info, checkResult)){//发送抬杆儿报文
|
|
|
if ("I".equals(info.getIetype())) {
|
|
|
list.setAislewt(info.getGrosswt().doubleValue());
|
|
|
list.setUpdateDate(new Date());
|
|
|
//list.setRemark(String.format("%.1f", goodsWt));
|
|
|
list.setRemark2(ve.getSelfWt());
|
|
|
list.setContrastflag("已进站");
|
|
|
logic.checkData(list);
|
|
|
} else {
|
|
|
LandRoadVe veName = logic.veService.selectByFrameNo(vaName);
|
|
|
list.setAislewt(info.getGrosswt().doubleValue());
|
|
|
list.setUpdateDate(new Date());
|
|
|
list.setRemark(String.format("%.1f", goodsWt));
|
|
|
list.setRemark1(String.format("%.1f", diffVal));
|
|
|
list.setRemark2(veName.getSelfWt());
|
|
|
list.setContrastflag("已出站");
|
|
|
logic.checkData(list);
|
|
|
}
|
|
|
logic.listService.updateById(list);//更新进出场申请业务表
|
|
|
//进出场申请业务表对应场站的卡口失效
|
|
|
logic.listService.updateisvalid(list.getTrailerFrameNo(),list.getBarcode(),list.getEndstation(),list.getTurnoverflag());
|
|
|
//判断是否为最后一个场站,若是最后个场站申请为出,二维码失效
|
|
|
int count=logic.listService.selectlaststation(list.getTrailerFrameNo(),list.getBarcode());
|
|
|
//二维码失效
|
|
|
if(count==0){
|
|
|
buildBarCode.cancleBarCode(vaName);
|
|
|
}
|
|
|
//调拨货冻结
|
|
|
if (list.getBusinesstype().indexOf("业务") > 0) {
|
|
|
logic.inOrUpEnterCancel(list);
|
|
|
}
|
|
|
}
|
|
|
//绑定车单关系
|
|
|
if(list.getMasterList().length()>0){
|
|
|
boolean flag = VeManifestRelation.createFile(list);
|
|
|
if(flag){
|
|
|
logger.info(">>>>>>>>>>-----车单关系报文生成成功-----<<<<<<<<<<<<");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
sendError(info);
|
|
|
logger.error("------->>>>>>>二维码数据异常,请使用正确的二维码数据<<<<<<<-----");
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
/**
|
|
|
* 校验重量并发送报文
|
|
|
*/
|
|
|
|
|
|
public boolean sendBw(GatherInfo info, boolean check) {
|
|
|
logger.info(String.format("开始发送指令:车牌%s,场站%s,通道%s,重量%s",info.getVename(),info.getAreaid(),info.getChnlno(),info.getGrosswt()));
|
|
|
boolean flag = false;
|
|
|
if (check) {
|
|
|
CommandClient.Client(info, PERMITTHOUGH);
|
|
|
logger.info("=============>>>>>>>>放行报文发送成功<<<<<<<<<==============");
|
|
|
flag = true;
|
|
|
} else {
|
|
|
CommandClient.Client(info, GROWSSEXCETION);
|
|
|
logger.info("=============>>>>>>>>重量异常报文发送成功<<<<<<<<<==============");
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
/**
|
|
|
* 给码头发送卡口数据
|
|
|
*
|
|
|
* @param stationCode
|
|
|
* @param carNo
|
|
|
* @param IEtype
|
|
|
*/
|
|
|
public static void sendData(String stationCode, String carNo, boolean IEtype) {
|
|
|
String url = "http://10.50.3.73:8080/air-api/car/channelCar?stationCode=" + stationCode + "&carNo=" + carNo + "&isPickup=" + IEtype;
|
|
|
try {
|
|
|
HttpClient httpClient = new DefaultHttpClient();
|
|
|
HttpGet httpGet = new HttpGet(url);
|
|
|
HttpResponse httpResponse = httpClient.execute(httpGet);
|
|
|
HttpEntity entity = httpResponse.getEntity();
|
|
|
String entityStr = EntityUtils.toString(entity);
|
|
|
logger.info("------------>>>>>>>>>>>>>>发送车辆信息:{stationCode:" + stationCode + ",carNo:" + carNo + ",isPickup:" + IEtype + "}");
|
|
|
logger.info("------------>>>>>>>>>>>>>>响应返回内容:" + entityStr + "<<<<<<<<<<<<-----------");
|
|
|
} catch (Exception e) {
|
|
|
logger.info(e.toString());
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 给码头发送卡口数据
|
|
|
*
|
|
|
* @param list
|
|
|
*/
|
|
|
public void checkData(LandBusinessTypeList list) {
|
|
|
String sationCode = null;
|
|
|
boolean flag = false;
|
|
|
if ("出口送货".equals(list.getBusinesstype()) || "出口流转".equals(list.getBusinesstype())) {
|
|
|
flag = false;
|
|
|
}
|
|
|
if ("进口提货".equals(list.getBusinesstype()) || "进口流转".equals(list.getBusinesstype())) {
|
|
|
flag = true;
|
|
|
}
|
|
|
if ("4604000000".equals(list.getEndstation())) {
|
|
|
if ("I".equals(list.getTurnoverflag())) {
|
|
|
sationCode = "HK05";
|
|
|
} else {
|
|
|
sationCode = "HK06";
|
|
|
}
|
|
|
//TODO:加场站判定
|
|
|
}
|
|
|
sendData(sationCode, list.getTrailerFrameNo(), flag);
|
|
|
}
|
|
|
/**
|
|
|
* 查询运单是否全部放行
|
|
|
*
|
|
|
* @param manifestList
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean checkManifest(String manifestList) {
|
|
|
if (manifestList.length() < 1) return false;
|
|
|
manifestList = manifestList.replace("-", "");
|
|
|
String[] maifest = manifestList.split(",");
|
|
|
boolean flag = false;
|
|
|
int count = 0;
|
|
|
for (int i = 0; i < maifest.length; i++) {
|
|
|
RESMESSAGE resmessage = logic.resMessageService.selectByManifest(maifest[i]);
|
|
|
if (resmessage != null) {
|
|
|
if ("11".equals(resmessage.getResponsecode())) {
|
|
|
count++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (count == maifest.length) {
|
|
|
flag = true;
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
/**
|
|
|
* 校验载重和称重是否在合理的范围
|
|
|
*
|
|
|
* @Param grossWt 地磅称重
|
|
|
* @Param wt 车辆自重
|
|
|
* @Param goodsWt 货物总重
|
|
|
* @Result 获取运单重量
|
|
|
*/
|
|
|
/**
|
|
|
* 进场卸货误差判定
|
|
|
* 出场重量 = 进场重量 - 货物重量
|
|
|
* 首先计算 进出场差值数 ABS(进场重量-货物重量-出场重量)/出场重量, 计算出出场误差百分比
|
|
|
* (出场重量 - 车辆备案重量) /出场重量
|
|
|
* (出场重量 - (车辆备案重量+货物重量)/出场重量
|
|
|
* (出场重量 - (进场重量+货物重量)/出场重量
|
|
|
*/
|
|
|
public boolean checkResult(double grossWt, double wt, double goodsWt,double inWt) {
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
boolean flag = false;
|
|
|
double result= 0.0,result2= 0.0,result3= 0.0,result4= 0.0;
|
|
|
if(grossWt>0){
|
|
|
result = Double.parseDouble(df.format(Math.abs((inWt - goodsWt - grossWt)) / grossWt));
|
|
|
result2 = Double.parseDouble(df.format(Math.abs((grossWt-wt)) / grossWt));
|
|
|
result3 = Double.parseDouble(df.format(Math.abs((grossWt-wt-goodsWt)) / grossWt));
|
|
|
result4 = Double.parseDouble(df.format(Math.abs((inWt + goodsWt)) / grossWt));
|
|
|
}
|
|
|
if (result <= valueDob() ||result2 <= valueDob() || result3 <= valueDob() || result4 <= valueDob()) {
|
|
|
flag = true;
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 排除当前系统问题发送错误commandInfo
|
|
|
*/
|
|
|
public static void sendError(GatherInfo info) {
|
|
|
//二维码数据异常,请使用正确的二维码数据
|
|
|
CommandClient.Client(info, ISVALID);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Param mainifast 主单列表
|
|
|
* @Param ietype 进出标志
|
|
|
* 获取货物总重
|
|
|
*/
|
|
|
public double GoodsWt(String mainifast, String ietype) {
|
|
|
Double sum = 0.0;
|
|
|
if (mainifast.length() > 0) {
|
|
|
String[] mainifastList = mainifast.split(",");
|
|
|
for (String mainBill : mainifastList) {
|
|
|
sum += getGrossWt(mainBill, ietype);
|
|
|
}
|
|
|
}
|
|
|
return sum;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Param waybill 主单号
|
|
|
* @Param imp 进出港标识
|
|
|
* @Result 获取运单重量
|
|
|
*/
|
|
|
public double getGrossWt(String waybill, String imp) {
|
|
|
logger.info("进入获取重量action");
|
|
|
if (!(waybill.indexOf("-") != -1)) {
|
|
|
waybill = waybill.substring(0, 3) + "-" + waybill.substring(3);
|
|
|
}
|
|
|
String url = "http://10.50.3.82:8081/orig/orig?waybill=" + waybill + "&imp=" + 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(), "utf-8"));
|
|
|
String inputLine = null;
|
|
|
while ((inputLine = in.readLine()) != null) {
|
|
|
json.append(inputLine);
|
|
|
}
|
|
|
logger.info("返回数据:" + json);
|
|
|
JSONArray array = JSONArray.parseArray(json.toString());
|
|
|
for (int i = 0; i < array.size(); i++) {
|
|
|
map = JSON.parseObject(array.getString(i));
|
|
|
if (map.containsKey("receiptinformation")) {
|
|
|
if (map.get("receiptinformation").toString().startsWith("41301") || map.get("receiptinformation")
|
|
|
.toString().startsWith("41106") || map.get("receiptinformation")
|
|
|
.toString().startsWith("31301") || map.get("receiptinformation")
|
|
|
.toString().startsWith("31106") || map.get("receiptinformation")
|
|
|
.toString().indexOf("提运单放行") != -1) {
|
|
|
logger.info(map);
|
|
|
bg = Double.parseDouble((String) map.get("totalweight"));
|
|
|
logger.info("for循环取重量:" + bg);
|
|
|
return bg;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
logger.info("访问返回的数据重量:" + bg);
|
|
|
in.close();
|
|
|
} catch (MalformedURLException e) {
|
|
|
e.printStackTrace();
|
|
|
logger.error(e);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
logger.error(e);
|
|
|
}
|
|
|
return bg;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断备案车重与运单重量和地磅称重是否在合理范围
|
|
|
*
|
|
|
* @param grossWt
|
|
|
* @param wt
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean checkFlag(double grossWt, double wt) {
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
boolean flag = false;
|
|
|
double reult = Double.parseDouble(df.format(Math.abs((grossWt - wt)) / grossWt));
|
|
|
if (reult <= valueDob()) {
|
|
|
flag = true;
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
//将获取的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 landBusinessTypeList
|
|
|
*/
|
|
|
public void inOrUpEnterCancel(LandBusinessTypeList landBusinessTypeList) {
|
|
|
if (landBusinessTypeList.getMasterList().length() < 1) return;
|
|
|
String[] list = landBusinessTypeList.getMasterList().split(",");
|
|
|
String flag = null;
|
|
|
for (int i = 0; i < list.length; i++) {
|
|
|
if("调拨业务".equals(landBusinessTypeList.getBusinesstype())){
|
|
|
flag = "E";
|
|
|
}else {
|
|
|
flag = "I";
|
|
|
}
|
|
|
double wt = getGrossWt(list[i],flag);
|
|
|
|
|
|
ENTERCANCCEL entercanccel = logic.enterCancelServer.selectByManifest(list[i]);
|
|
|
if (entercanccel != null) {
|
|
|
if(entercanccel.getVename().equals(landBusinessTypeList.getTrailerFrameNo())){
|
|
|
if ("0".equals(entercanccel.getIsfreeze())) {
|
|
|
entercanccel.setIsfreeze("1");
|
|
|
entercanccel.setEndport(landBusinessTypeList.getEndstation());
|
|
|
entercanccel.setUpdateBy(landBusinessTypeList.getCreateBy());
|
|
|
entercanccel.setUpdateTime(new Date());
|
|
|
logic.enterCancelServer.updateByPermaryKey(entercanccel);
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
if("E".equals(landBusinessTypeList.getTurnoverflag())){
|
|
|
ENTERCANCCEL canccel = new ENTERCANCCEL();
|
|
|
canccel.setIsfreeze("0");
|
|
|
canccel.setVename(landBusinessTypeList.getTrailerFrameNo());
|
|
|
canccel.setId(String.valueOf(System.currentTimeMillis()));
|
|
|
canccel.setVeCompanyName(landBusinessTypeList.getAgentno());
|
|
|
canccel.setBusinesstype(landBusinessTypeList.getBusinesstype());
|
|
|
canccel.setManifest(list[i]);
|
|
|
canccel.setAgentname(landBusinessTypeList.getAgentname());
|
|
|
canccel.setStartport(landBusinessTypeList.getEndstation());
|
|
|
canccel.setGrosswt(landBusinessTypeList.getAislewt());
|
|
|
canccel.setCreateBy(landBusinessTypeList.getCreateBy());
|
|
|
canccel.setCreateTime(new Date());
|
|
|
canccel.setUpdateBy(landBusinessTypeList.getCreateBy());
|
|
|
canccel.setUpdateTime(new Date());
|
|
|
canccel.setWeight(wt);
|
|
|
logic.enterCancelServer.insertEntry(canccel);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
|