package com.steerinfo.dil.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.steerinfo.dil.feign.*; import com.steerinfo.dil.mapper.*; import com.steerinfo.dil.model.DilCapacityTimes; import com.steerinfo.dil.model.TmstruckLeaveFactoryResult; import com.steerinfo.dil.model.TmstruckWeightResult; import com.steerinfo.dil.service.ITmstruckLeaveFactoryResultService; import com.steerinfo.dil.util.DataChange; import com.steerinfo.dil.util.HTTPRequestUtils; import com.steerinfo.dil.util.getRequestUtils; import com.steerinfo.dil.util.newFileTool; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; import java.math.BigDecimal; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; /** * TmstruckLeaveFactoryResult服务实现: * @author generator * @version 1.0-SNAPSHORT 2021-09-11 10:32 * 类描述 * 修订历史: * 日期:2021-09-11 * 作者:generator * 参考: * 描述:TmstruckLeaveFactoryResult服务实现 * @see null * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved. */ @Service(value = "tmstruckLeaveFactoryResultService") public class TmstruckLeaveFactoryResultServiceImpl implements ITmstruckLeaveFactoryResultService { @Autowired private TmstruckLeaveFactoryResultMapper tmstruckLeaveFactoryResultMapper; @Autowired private TmstruckEnfactoryResultMapper tmstruckEnfactoryResultMapper; @Autowired private TmstruckLoadResultMapper tmstruckLoadResultMapper; @Autowired private UtilsServiceImpl utilsService; @Autowired private UtilsMapper utilsMapper; @Autowired private OtmsFeign otmsFeign; @Autowired private TmstruckEnfactoryResultServiceImpl tmstruckEnfactoryResultService; @Autowired private DilCapacityTimesMapper dilCapacityTimesMapper; @Autowired TmstruckSmsRusultServiceImpl tmstruckSmsRusultService; @Autowired OmsFeign omsFeign; @Autowired BmsTruckFeign bmsTruckFeign; @Autowired AmsFeign amsFeign; @Autowired JoinFeign joinFeign; //果园库测试接口:"http://113.204.217.110:9810/dagang/receiving"; //果园库正式接口 private String guoYuanUrl="http://114.117.208.165:9810/dagang/receiving"; //城嘉库登录访问接口 private String chengJiaLoginUrl="http://116.204.73.104:8083/dagon/login"; //城嘉库推送数据接口 private String chengJiaSendUrl="http://116.204.73.104:8083/dagon/selectSaleSteelOrder"; /** * 查看运输线路是否为出厂 * @param orderNumber * @return */ @Override public Integer selectTransportRoute(String orderNumber) { return tmstruckLeaveFactoryResultMapper.selectTransportRoute(orderNumber); } /** * 派单后新增出厂实绩 * 总实绩ID、线路终点 * @param map * @return */ @Override public int addLeaveFactory(Map map) { TmstruckLeaveFactoryResult tmstruckLeaveFactoryResult = new TmstruckLeaveFactoryResult(); //添加主键 tmstruckLeaveFactoryResult.setId(tmstruckLeaveFactoryResultMapper.selectMaxId()); //添加总实绩ID BigDecimal resultTotalId = DataChange.dataToBigDecimal(map.get("resultTotalId")); tmstruckLeaveFactoryResult.setResultTotalId(resultTotalId); List gatepostIdList = utilsMapper.getLineSegmentGateCalcId(map); gatepostIdList.remove(null); //随机取门岗值 Integer gatepostId = utilsService.randomGetValue(gatepostIdList); try{ //如果是物资里有钒渣,则取5 map.put("con","钒渣"); if(utilsMapper.getMaterialNumByTotal(map) > 0){ gatepostId=5; } }catch (Exception e){ e.printStackTrace(); } //获取门岗ID tmstruckLeaveFactoryResult.setGatepostId(new BigDecimal(gatepostId)); //添加路段顺序号 tmstruckLeaveFactoryResult.setSegmentSqe(DataChange.dataToBigDecimal(map.get("segmentSqe"))); //添加门岗ID 出厂门岗为线路的终点 int i=tmstruckLeaveFactoryResultMapper.insertSelective(tmstruckLeaveFactoryResult); try{ tmstruckLeaveFactoryResultMapper.clearRepeat(tmstruckLeaveFactoryResult); }catch (Exception e){ e.printStackTrace(); } return i; } @Override public Map getTruckFactoryResult(String orderNumber) { return tmstruckLeaveFactoryResultMapper.getTruckFactoryResult(orderNumber); } /** * APP查询出厂信息 * @param orderNumber * @return */ @Override public List> getLeaveFactoryList(String orderNumber) { return tmstruckLeaveFactoryResultMapper.getLeaveFactoryList(orderNumber); } /** * 查询所有的出厂实绩 * 1:销售订单;2:焦炭发运计划;3:水渣发运计划;4:内转到异地库;5:采购辅料订单;6:采购老区燃料订单; * 7:采购新区燃料订单;8:采购进口矿(万州-厂内);9:采购内转(达州-厂内);10:采购内转(老区-厂内); 11:厂内内转 * @param map * @return */ @Override public List> getLeaveFactoryResult(Map map) { Integer orderType = (Integer) map.get("orderTypee"); switch (orderType){ case 1: case 2: case 3: return tmstruckLeaveFactoryResultMapper.selectAllLeaveFacatoryForSale(map); case 4: return tmstruckLeaveFactoryResultMapper.selectSteelNzLeaveFactory(map); case 5: case 6: case 7: case 8: case 17: case 18: return tmstruckLeaveFactoryResultMapper.getCGLeaveFactoryResult(map); //apiId:110 case 9: return tmstruckLeaveFactoryResultMapper.getImportedDomesticNzEnFactoryResult(map); //apiId:110 case 10: case 20: case 23: case 24: return tmstruckEnfactoryResultMapper.getCgNzOutFactory(map); case 11: return tmstruckLeaveFactoryResultMapper.getInFactoryOutFactoryResult(map); //apiId:361 case 12: case 13: case 14: case 19: case 100: return tmstruckLeaveFactoryResultMapper.getSporadicLeaveFactory(map);//apiId:421 } return null; } /** * 通过 PDA 出厂 * 1:销售订单;2:焦炭发运计划;3:水渣发运计划;4:内转到异地库;5:采购辅料订单;6:采购老区燃料订单; * 7:采购新区燃料订单;8:采购进口矿(万州-厂内);9:采购内转(达州-厂内);10:采购内转(老区-厂内); 11:厂内内转 * @param map * @return */ @Transactional(rollbackFor = Exception.class) @Override public int leaveFactoryByPDA(Map map) throws Exception{ int i = 0; String orderNumber = (String) map.get("orderNumber"); orderNumber = orderNumber.substring(0, orderNumber.length() - 1); //通过订单号查询订单类型 及总实绩Id Map mesMap = utilsMapper.getOrderTypeByOrderNumber(orderNumber); int orderType = DataChange.dataToBigDecimal(mesMap.get("orderType")).intValue(); String capacityNumber = (String) mesMap.get("capacityNumber"); if(orderType == 11 || orderType == 15 || orderType == 16){ return orderType11Use(map, mesMap,capacityNumber); }else if(orderType == 21){ return tmstruckEnfactoryResultService.orderType21Use(map, orderNumber, DataChange.dataToBigDecimal(mesMap.get("orderId"))); } Map selectMap = tmstruckLeaveFactoryResultMapper.selectResultId(DataChange.dataToBigDecimal(mesMap.get("resultTotalId"))); if(selectMap == null){ if(orderType == 4) { return i; } throw new Exception("该车已出厂!!"); }else{ BigDecimal segmentSqe = DataChange.dataToBigDecimal(selectMap.get("segmentSqe")); BigDecimal orderSegmentSqe = DataChange.dataToBigDecimal(mesMap.get("orderSegmentSqe")); //如果当前路段顺序号 +1 不等于出厂路段顺序号 则不允许出厂 if(segmentSqe.intValue() != (orderSegmentSqe.intValue() + 1) && orderType != 1){ throw new Exception("该车作业环节未全部完成!"); } } if(orderType == 2){ Map loadResultMap = tmstruckLoadResultMapper.getLoadResultMap(DataChange.dataToBigDecimal(mesMap.get("resultTotalId"))); //根据总实绩ID查询该车有没有装货 if(loadResultMap == null || (loadResultMap != null && loadResultMap.get("loadEndTime") == null)){ throw new Exception("该车未扫装货,请提醒司机去补扫装货"); } // 查询运单所属的销售订单id BigDecimal saleOrderId = tmstruckLeaveFactoryResultMapper.getSaleOrderId(orderNumber); // 得到销售订单下已出厂车辆已计量净重 Double allNetWeight = tmstruckLeaveFactoryResultMapper.getLeaveFactoryNetWeight(saleOrderId); if (allNetWeight != null) { // 得到当前运单净重 Double nowNetWeight = tmstruckLeaveFactoryResultMapper.getNowNetWeight(orderNumber); // 得到销售订单下单总重量 Double saleWeight = tmstruckLeaveFactoryResultMapper.getSaleMaterialWeight(saleOrderId); //判断当前订单是否可出厂 Integer canWork = tmstruckLeaveFactoryResultMapper.getCanWorkStatus(DataChange.dataToBigDecimal(mesMap.get("orderId"))); if (allNetWeight + nowNetWeight > saleWeight && canWork == null) { throw new Exception("该销售订单吨位已超额,不允许出厂,请司机联系销售公司走流程卸货!"); } } } if(orderType == 13 ){ //检查物资类型 List materials=null; try{ materials=tmstruckLeaveFactoryResultMapper.getMaterial(orderNumber); }catch (Exception e){ e.printStackTrace(); System.out.println("查询物资失败,不检查是否装货,不影响后续执行"); } //检查是否装货 if(materials!=null && materials.size()>0){ Map loadResultMap = tmstruckLoadResultMapper.getLoadResultMap(DataChange.dataToBigDecimal(mesMap.get("resultTotalId"))); if(loadResultMap == null || (loadResultMap != null && loadResultMap.get("loadEndTime") == null)){ throw new Exception("该车未扫装货,请提醒司机去补扫装货"); } } } if(orderType == 23 || orderType == 24) { //查询卸货 Map unloadMap = tmstruckLeaveFactoryResultMapper.getUnloadResult(DataChange.dataToBigDecimal(mesMap.get("orderId"))); if (unloadMap == null || (unloadMap != null && unloadMap.get("resultEndTime") == null)) { throw new Exception("该车未扫卸货,请提醒司机去补扫卸货"); } } if(orderType == 1 && "true".equals(tmstruckLeaveFactoryResultMapper.getPrintFlag())) { //如果是钢材订单,且打印送货单是必须打印,那么进这个方法 Integer printNumber = tmstruckLeaveFactoryResultMapper.getPrintNumber(DataChange.dataToBigDecimal(mesMap.get("orderId"))); if(printNumber == 0){ throw new Exception("未打印送货单,请提醒司机去打印"); } } map.putAll(mesMap); map.putAll(selectMap); map.remove("Sqe"); map.put("orderNumber", orderNumber); BigDecimal orderId = DataChange.dataToBigDecimal(map.get("orderId")); i += updateLeaveResultByPDA(map); //更新出厂实绩 //更新路段顺序号 i += utilsService.updateOrderLineSequence(map); //判断是否抵达签收,然后根据各自类型不同情况判断是否需要关单 Boolean isArrivalFlag = isArrivalType(""+orderType); //查询自提 String isSelfMention = tmstruckLeaveFactoryResultMapper.getIsSelfMention(orderId); if(!isArrivalFlag || "是".equals(isSelfMention)){ //不涉及抵达签收,或者自提,统一在此处直接关单 i += utilsService.closeOrderNormally(map); } if(isArrivalFlag){ //如果涉及抵达签收,则标记为允许 utilsMapper.updateArrival(map); } switch (orderType){ case 1: try { if(isSelfMention != null && isSelfMention.equals("是")) { break; } } catch (Exception e) { e.printStackTrace(); } //查询该订单的出库单制作日期 // try { // List easPrimaryIds = tmstruckLeaveFactoryResultMapper.getEasPrimaryIds(orderNumber); // Map easPrimaryMap = new HashMap<>(); // easPrimaryMap.put("easPrimaryList",easPrimaryIds); // amsFeign.getMakeOrderDate(easPrimaryMap); // } catch (Exception e) { // e.printStackTrace(); // } //判断该订单是不是异地库 try { String addressPlace = tmstruckLeaveFactoryResultMapper.getAddressPlace(orderId); if (addressPlace != null && addressPlace.contains("城嘉库")) { List> data =getOffSiteWarehouse(orderNumber); //调用城嘉库登录接口获取token String token = DagonloginChenJiaku(); if (token != null) { for (Map map1:data) { map1.put("token", token); //接口发送日期 map1.put("sendTime",new Date()); ///调用城嘉库推送接口 sendMesToChengJia(map1); } } else { System.out.println("登录城嘉库失败"); } }else if(addressPlace!=null && addressPlace.contains("果园港")){ //果园库 List> data =getOffSiteWarehouse(orderNumber); Map details=new HashMap<>(); DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for(Map temp:data){ temp.put("resultOutGateTime",format.format((Date)(temp.get("outGateTime")))); temp.put("orderIssueTime",format.format((Date)(temp.get("orderIssueTime")))); temp.remove("outGateTime"); temp.put("orderWagonNo",temp.get("capacityNo")); } //发送时间 details.put("sendTime",format.format(new Date())); //系统代码 details.put("sysCode", "DGXT"); //仓库代码 details.put("warehouseCode", "LJJT"); //运输方式 details.put("transportType", "汽运"); //详细数据 details.put("details", data); //推送数据 sendMesToGuoyuan(details); } } catch (IOException e) { e.printStackTrace(); } try { //发送短信 Map messageMap = tmstruckLeaveFactoryResultMapper.getMessageMap(orderId); if(messageMap.get("saleOrderConsigneeTEL") != null){ String capacityNum = (String) messageMap.get("capacityNumber"); String mobile = (String)messageMap.get("saleOrderConsigneeTEL"); tmstruckSmsRusultService.generaSendMessage(mobile,capacityNum,orderId); } // 调用结算 }catch (Exception ex){ System.out.println(ex.getMessage()); } //销售厂外监控 try { Map parem = getTruckFactoryResult(orderNumber); parem.put("turnOf","0"); otmsFeign.createTotalResult(parem); } catch (Exception e) { e.printStackTrace(); } try { System.out.println(orderId + "生成结算数据"); bmsTruckFeign.addDetailsOrder(orderId); } catch (Exception e) { e.printStackTrace(); } break; case 2: case 3: //查询司机是否已确认订单 如果订单未确认 则不允许出厂 Integer driverConfirmation = utilsMapper.getDriverConfirmation(orderId); if(driverConfirmation == null){ throw new Exception("请提醒司机确认订单!"); } // i += utilsService.closeOrderNormally(map); // 判断是否要自动派单 Map mapValue = omsFeign.getSaleAllMessages(orderId.intValue()); Object closeStatus = mapValue.get("closeStatus"); if (closeStatus != null && DataChange.dataToBigDecimal(closeStatus).intValue() == 0) { amsFeign.dispatchTruckOrderByCarrier(mapValue); } try { bmsTruckFeign.addDetailsOrder(orderId); } catch (Exception e) { e.printStackTrace(); } break; case 4: // i += utilsService.closeOrderNormally(map); break; case 5: case 6: case 7: case 8: //判断出厂路段顺序号是否为最后一个 采购订单关闭订单 // i += utilsService.closeOrderNormally(map); //查询是否为一车多趟采购订单类型 Integer isMoreTripsStatus = tmstruckLeaveFactoryResultMapper.getIsMoreTripsStatus(DataChange.dataToBigDecimal(map.get("orderId"))); if(isMoreTripsStatus != null && isMoreTripsStatus == 1){ //如果是一车多趟 则重新下一个运输订单 omsFeign.addNewTransportOrder(orderId.intValue()); } break; case 9: case 17: case 18: //判断出厂路段顺序号是否为最后一个 采购订单关闭订单 // i += utilsService.closeOrderNormally(map); break; case 10: case 20: //生成新的采购内转运输订单 //判断出厂路段顺序号是否为最后一个 采购订单关闭订单 // i += utilsService.closeOrderNormally(map); //根据运输订单ID查询路段顺序号 Integer orderStatus = tmstruckLeaveFactoryResultMapper.getOrderStatus(orderId); if(orderStatus == 2){ //判断是否满足条件--计划是否被启用 Integer j = tmstruckLeaveFactoryResultMapper.getPlanEnable(orderId); if(j == 1){ //生成新的运输订单 omsFeign.addPurInwardOrder(orderId); } try { bmsTruckFeign.addInwardDetailsOrder(map); } catch (Exception e) { e.printStackTrace(); } } break; case 23: case 24: // i += utilsService.closeOrderNormally(map); omsFeign.addPurInwardOrder(orderId); try { bmsTruckFeign.addInwardDetailsOrder(map); } catch (Exception e) { e.printStackTrace(); } break; case 12: case 13: case 19: case 14: //关闭当前订单 // i += utilsService.closeOrderNormally(map); //生成新的零星订单 omsFeign.pushMessageToDriver(map); break; } utilsService.pushMesToWebsocket((String) map.get("capacityNumber"), "出厂"); return i; } /** * 内转订单类型 * @Author TXF * @Date 2022/3/18 18:03 * @param map * @param mesMap * @param capacityNumber * @return **/ public int orderType11Use(Map map, Map mesMap, String capacityNumber){ //内转订单类型 没有生成实绩 直接新增 int sqe = DataChange.dataToBigDecimal(mesMap.get("Sqe")).intValue(); sqe = sqe + 1; map.put("resultId",tmstruckLeaveFactoryResultMapper.selectMaxId());//出厂实绩ID map.put("Sqe",sqe);//查询路段顺序号+1 map.put(("totalId"),mesMap.get("totalId")); tmstruckLeaveFactoryResultMapper.insertSelective(generateLeaveFactory(map)); //更新路段顺序号 mesMap.put("orderLineSequence",sqe); utilsService.updateOrderLineSqeByOrderNumber(mesMap); utilsService.pushMesToWebsocket(capacityNumber, "出厂"); return 1; } //内转订单类型新增出厂实绩 private TmstruckLeaveFactoryResult generateLeaveFactory(Map map) { TmstruckLeaveFactoryResult tmstruckLeaveFactoryResult = new TmstruckLeaveFactoryResult(); //获取出厂实绩ID tmstruckLeaveFactoryResult.setResultId(DataChange.dataToBigDecimal(map.get("resultId"))); //添加门岗 tmstruckLeaveFactoryResult.setGatepostId(DataChange.dataToBigDecimal(map.get("gatepostId"))); //添加路段顺序号 tmstruckLeaveFactoryResult.setSegmentSqe(DataChange.dataToBigDecimal(map.get("Sqe"))); //添加出厂时间 tmstruckLeaveFactoryResult.setResultOutGateTime(new Date()); tmstruckLeaveFactoryResult.setInsertTime(new Date()); tmstruckLeaveFactoryResult.setResultOutMode("手动抬杆"); tmstruckLeaveFactoryResult.setInsertUsername("admin"); if(map.get("Sqe") !=null){ tmstruckLeaveFactoryResult.setSegmentSqe(DataChange.dataToBigDecimal(map.get("Sqe"))); } if(map.get("totalId") !=null){ tmstruckLeaveFactoryResult.setResultTotalId(DataChange.dataToBigDecimal(map.get("totalId"))); } return tmstruckLeaveFactoryResult; } /** * 更新出厂实绩 * @param mapValue {运输订单号:orderNumber 门岗名称:gatepostName} * @return */ public int updateLeaveResultByPDA(Map mapValue){ TmstruckLeaveFactoryResult tmstruckLeaveFactoryResult = new TmstruckLeaveFactoryResult(); tmstruckLeaveFactoryResult.setResultId(DataChange.dataToBigDecimal(mapValue.get("resultId"))); //通过门岗名称获取门岗ID if(mapValue.get("gatepostId") == null){ Integer gatepostId = tmstruckEnfactoryResultMapper.selectGatepostIdByGatepostName((String) mapValue.get("gatepostName")); if(gatepostId != null){ tmstruckLeaveFactoryResult.setGatepostId(new BigDecimal(gatepostId)); } }else { tmstruckLeaveFactoryResult.setGatepostId(DataChange.dataToBigDecimal(mapValue.get("gatepostId"))); } //设置常规字段 添加 出厂时间 和 出厂方式 tmstruckLeaveFactoryResult.setResultOutGateTime(new Date()); tmstruckLeaveFactoryResult.setResultOutMode("手动抬杠"); tmstruckLeaveFactoryResult.setInsertUsername("admin"); tmstruckLeaveFactoryResult.setInsertTime(new Date()); tmstruckLeaveFactoryResultMapper.updateResultTotalOutStatus(DataChange.dataToBigDecimal(mapValue.get("resultTotalId"))); try { DilCapacityTimes dilCapacityTimes = new DilCapacityTimes(); dilCapacityTimes.setId(dilCapacityTimesMapper.getDilCapacityTimesId()); dilCapacityTimes.setTimesCapacityNumber(mapValue.get("capacityNumber").toString()); dilCapacityTimes.setTimesValue(new Date()); dilCapacityTimes.setTimesType(new BigDecimal(2)); dilCapacityTimesMapper.insertSelective(dilCapacityTimes); } catch (Exception e) { e.printStackTrace(); } return tmstruckLeaveFactoryResultMapper.updateByPrimaryKeySelective(tmstruckLeaveFactoryResult); } /** * 通过总实绩Id修改出厂实绩出厂门岗 * @param resultTotalId * @param gatepostId * @return */ public int updateLeaveFactoryGatepostId(Integer resultTotalId, Integer gatepostId){ TmstruckLeaveFactoryResult tmstruckLeaveFactoryResult = new TmstruckLeaveFactoryResult(); //通过总实绩ID查询出产实绩 BigDecimal resultId = tmstruckLeaveFactoryResultMapper.getResultIdByTotalId(resultTotalId); tmstruckLeaveFactoryResult.setResultId(resultId); tmstruckLeaveFactoryResult.setGatepostId(new BigDecimal(gatepostId)); return tmstruckLeaveFactoryResultMapper.updateByPrimaryKeySelective(tmstruckLeaveFactoryResult); } /** * 查询零星物资出厂列表 * @param mapValue * @return */ @Override public List> getSporadicLeaveFactory(Map mapValue) { return tmstruckLeaveFactoryResultMapper.getSporadicLeaveFactory(mapValue); } public List> getOffSiteWarehouse(String orderNumber) { List> mapList = tmstruckLeaveFactoryResultMapper.getOffSiteWarehouse(orderNumber); for (Map map1:mapList){ String materialName =(String) map1.get("materialName"); if (materialName.contains("盘螺")){ map1.put("materialType","盘螺"); }else if (materialName.contains("盘圆")||materialName.contains("盘元")){ map1.put("materialType","盘圆"); }else if (materialName.contains("螺纹")){ map1.put("materialType","螺纹钢"); } } return mapList; } /** * 访问城嘉库接口方法 * @param * @return */ public String DagonloginChenJiaku() throws IOException { Map reqMap = new HashMap<>(); reqMap.put("username","dagon"); reqMap.put("password","147258"); // JSONObject jsonObject = new JSONObject(); // jsonObject.putAll(reqMap); // Map map=new HashMap<>(); // map.put("username","dagon"); // map.put("password","147258"); // jsonObject.putAll(map); // jsonObject.put("username","dagon"); // jsonObject.put("password","147258"); String jsonData = null; jsonData = getRequestUtils.doPost(chengJiaLoginUrl,reqMap); if(!"null".equals(jsonData)){ System.out.println(jsonData); HashMap hashMap = JSON.parseObject(jsonData, HashMap.class); BigDecimal code = DataChange.dataToBigDecimal( hashMap.get("code")); System.out.println(hashMap.get("message")); if(200==code.intValue()){ Map result =(Map) hashMap.get("result"); String token =(String) result.get("token"); return token; }else { System.out.println("推送数据失败"+hashMap.get("message")); } } return null; // String body = restTemplate.postForEntity(chengJiaLoginUrl, reqMap, String.class).getBody(); // System.out.println(body); // return body; } /** * 推送数据给城嘉库 */ public int sendMesToChengJia(Map map){ String token =(String) map.get("token"); Map jsonObject = new HashMap<>(); jsonObject.remove(token); jsonObject.putAll(map); //写入文件 try{ new Thread( new Runnable() { public void run(){ try { newFileTool.newFile("发送报文:"+chengJiaSendUrl+":"+jsonObject,"城嘉库报文"); } catch (IOException e) { e.printStackTrace(); } } }).start(); }catch (Exception e) { e.printStackTrace(); } String jsonData = null; jsonData = getRequestUtils.doPostAddHeader(chengJiaSendUrl, jsonObject,token); //写入文件 try{ String finalJsonData = jsonData; new Thread(new Runnable() { public void run(){ try { newFileTool.newFile("接收报文:"+chengJiaSendUrl+":"+ finalJsonData,"城嘉库报文"); } catch (IOException e) { e.printStackTrace(); } } }).start(); }catch (Exception e) { e.printStackTrace(); } if(!"null".equals(jsonData)){ System.out.println(jsonData); HashMap hashMap = JSON.parseObject(jsonData, HashMap.class); BigDecimal code = DataChange.dataToBigDecimal(hashMap.get("code")); System.out.println(hashMap.get("message")); if(code.intValue()==200){ return 1; }else { System.out.println("推送数据失败"+hashMap.get("message")); } } return 0; } /** * 访问重庆果园库接口方法 * @param map * @return */ public int sendMesToGuoyuan(Map map){ JSONObject jsonObject = new JSONObject(); jsonObject.putAll(map); String jsonData = null; //写入文件 try{ new Thread( new Runnable() { public void run(){ try { newFileTool.newFile("发送报文:"+guoYuanUrl+":"+jsonObject.toJSONString(),"果园库报文"); } catch (IOException e) { e.printStackTrace(); } } }).start(); }catch (Exception e) { e.printStackTrace(); } try { jsonData = HTTPRequestUtils.send(guoYuanUrl, jsonObject, "utf-8"); } catch (IOException e) { e.printStackTrace(); } //写入文件 try{ String finalJsonData = jsonData; new Thread(new Runnable() { public void run(){ try { newFileTool.newFile("接收报文:"+guoYuanUrl+":"+ finalJsonData,"果园库报文"); } catch (IOException e) { e.printStackTrace(); } } }).start(); }catch (Exception e) { e.printStackTrace(); } if(!"null".equals(jsonData)){ System.out.println(jsonData); try{ HashMap hashMap = JSON.parseObject(jsonData, HashMap.class); BigDecimal code =DataChange.dataToBigDecimal(hashMap.get("code")); System.out.println(hashMap.get("message")); if(code.intValue()==200){ return 1; }else { System.out.println("推送数据失败"+hashMap.get("message")); } }catch (Exception e){ } } return 0; } /** * 自动补扫出厂 */ @Scheduled(fixedRate = 1000*60*60*3) public void autoLeaveFactory(){ Date date=new Date(); Calendar calendar=Calendar.getInstance(); calendar.setTime(date); //非钢材,出净重24h后自动出厂,并关单 calendar.add(Calendar.HOUR_OF_DAY,-48); date=calendar.getTime(); Map map = new HashMap<>(); map.put("nowDate",date); List> list = tmstruckLeaveFactoryResultMapper.getWeightResultNetted(map); //钢材,打印送货单3小时后补扫出厂 calendar.setTime(new Date()); calendar.add(Calendar.HOUR_OF_DAY,-3); date=calendar.getTime(); map.put("nowDate",date); if(list != null){ list.addAll(tmstruckLeaveFactoryResultMapper.getSteelForLeave(map)); }else{ list = tmstruckLeaveFactoryResultMapper.getSteelForLeave(map); } for(Map item:list){ try{ System.out.println(item); leaveFactoryByPDA(item); }catch (Exception e){ e.printStackTrace(); if(DataChange.dataToBigDecimal(item.get("orderType")).compareTo(new BigDecimal(1)) != 0) { tmstruckLeaveFactoryResultMapper.updateOrderStatus(DataChange.dataToBigDecimal(item.get("orderId"))); } } } } /** * 校验是否允许抵达 * @param orderType * @return */ Boolean isArrivalType(String orderType){ try{ String[] arr = tmstruckLeaveFactoryResultMapper.getVersionValue(10).split(","); if(arr==null || arr.length<=0){ throw new Exception("数据库数据异常,类型字符串不存在!"); } for(String temp:arr){ if(temp.equals(orderType)){ return true; } } }catch (Exception e){ e.printStackTrace(); } return false; } }