package com.steerinfo.dil.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.steerinfo.dil.service.ITmstruckLeaveFactoryResultService; import com.steerinfo.dil.service.impl.OffSiteTransportationServiceImpl; import com.steerinfo.dil.util.BaseRESTfulController; import com.steerinfo.dil.util.ColumnDataUtil; import com.steerinfo.dil.util.PageListAdd; import com.steerinfo.framework.controller.RESTfulResult; import com.steerinfo.framework.service.pagehelper.PageHelper; import com.steerinfo.route.config.ImageFileUtils; import com.steerinfo.route.service.impl.RouteServiceImpl; import com.steerinfo.route.threeRequest.ZhongJiaoXingLu; import com.steerinfo.route.util.DataConversionTool; import com.steerinfo.route.util.HTTPRequestUtils; import com.steerinfo.route.vo.FullPathVisualizationTo.ViewVisualization; import com.steerinfo.route.vo.Map.RouteVo; import com.steerinfo.route.vo.ResultWarn; import com.steerinfo.route.vo.resultJson.SearchPoint; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartRequest; import java.math.BigDecimal; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; @Api("厂外运输接口") @RestController @RequestMapping("/${api.version}/pathDisplay") public class OffSiteTransportationController extends BaseRESTfulController { @Autowired private ITmstruckLeaveFactoryResultService tmstruckLeaveFactoryResultService; @Autowired private RouteServiceImpl routeService; @Autowired ColumnDataUtil columnDataUtil; @Autowired ImageFileUtils imageFileUtils; @Autowired private ZhongJiaoXingLu zhongJiaoXingLu; @Value("${str.tengxun.key}") private String key; @Value("${redis.prefix.order}") private String prefixOrder; @Value("${redis.prefix.line}") private String prefixLine; @Value("${redis.prefix.suffix}") private String suffix; @Autowired private RedisTemplate redisTemplate; @Autowired OffSiteTransportationServiceImpl offSiteTransportationService; @ApiOperation("保存路径") @PostMapping("/savePath") public CompletableFuture savePath() throws Exception { Map parem=tmstruckLeaveFactoryResultService.getTruckFactoryResult("WYSDD2022040600045906"); parem.put("turnOf","0"); return routeService.createTotalResult(parem); //运输订单号:orderNumber、车牌号:capacityNumber、出厂时间:resultOutGateTime、预警开关:turnOf、发货地址:shipperName、收货地址:receiveAddress //初始化请求参数 // HashMap mapValue=new HashMap<>(); // mapValue.put("orderNumber","WYSDD2021091000000001"); // mapValue.put("capacityNumber","豫SB6238"); // mapValue.put("resultOutGateTime","2021-11-17 14:20:19"); // mapValue.put("turnOf","0"); // mapValue.put("shipperName","四川达州钢铁集团有限"); // mapValue.put("receiveAddress","长沙市"); // return routeService.createTotalResult(mapValue); } @ApiOperation("全路径查询") @PostMapping("/fullPath") public Object fullPath(String orderNumber) throws Exception { //运输订单号:orderNumber、车牌号:capacityNumber、出厂时间:resultOutGateTime、预警开关:turnOf、发货地址:shipperName、收货地址:receiveAddress //初始化请求参数 HashMap mapValue=new HashMap<>(); mapValue.put("orderNumber",orderNumber); return routeService.fullPathVisualization(mapValue); } @ApiOperation("查询在途运输") @ApiImplicitParams({ @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"), @ApiImplicitParam(name = "apiId", value = "动态表头", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer") }) @PostMapping("/getInTransitTransportation") public RESTfulResult getInTransitTransportation(@RequestBody Map mapValue, @RequestParam(required = true,defaultValue = "468",name = "apiId")Integer apiId, @RequestParam(required = false,defaultValue = "1",name = "pageNum")Integer pageNum, @RequestParam(required = false,defaultValue = "20",name = "pageSize")Integer pageSize ) { if(mapValue.containsKey("startTime")&&mapValue.containsKey("endTime")){ Date startDate=new Date(Long.parseLong(mapValue.get("startTime").toString())) ; Date endDate=new Date(Long.parseLong(mapValue.get("endTime").toString())) ; Calendar ca = Calendar.getInstance(); ca.setTime(endDate); ca.add(Calendar.DATE,1); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd"); String startTime1=simpleDateFormat.format(startDate); String endTime1=simpleDateFormat.format(ca.getTime()); mapValue.replace("startTime",startTime1); mapValue.replace("endTime",endTime1); }else { Date startDate=new Date() ; Date endDate=new Date() ; Calendar ca = Calendar.getInstance(); ca.setTime(endDate); ca.add(Calendar.DATE,1); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd"); String startTime1=simpleDateFormat.format(startDate); String endTime1=simpleDateFormat.format(ca.getTime()); mapValue.put("startTime",startTime1); mapValue.put("endTime",endTime1); } List> filter= offSiteTransportationService.getInTransitTransportation(mapValue); PageHelper.startPage(pageNum, pageSize); List> list= offSiteTransportationService.getInTransitTransportation(mapValue); PageListAdd pageList = columnDataUtil.tableColumnData(apiId, filter,list); return success(pageList); } @ApiOperation("有异常") @ApiImplicitParams({ @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"), @ApiImplicitParam(name = "apiId", value = "动态表头", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer") }) @PostMapping("/getHaveAbnormalTruckOrderInfo") public RESTfulResult getHaveAbnormalTruckOrderInfo(@RequestBody Map mapValue, @RequestParam(required = true,defaultValue = "468",name = "apiId")Integer apiId, @RequestParam(required = false,defaultValue = "1",name = "pageNum")Integer pageNum, @RequestParam(required = false,defaultValue = "20",name = "pageSize")Integer pageSize ) { if(mapValue.containsKey("startTime")&&mapValue.containsKey("endTime")){ Date startDate=new Date(Long.parseLong(mapValue.get("startTime").toString())) ; Date endDate=new Date(Long.parseLong(mapValue.get("endTime").toString())) ; Calendar ca = Calendar.getInstance(); ca.setTime(endDate); ca.add(Calendar.DATE,1); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd"); String startTime1=simpleDateFormat.format(startDate); String endTime1=simpleDateFormat.format(ca.getTime()); mapValue.replace("startTime",startTime1); mapValue.replace("endTime",endTime1); }else { Date startDate=new Date() ; Date endDate=new Date() ; Calendar ca = Calendar.getInstance(); ca.setTime(endDate); ca.add(Calendar.DATE,1); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd"); String startTime1=simpleDateFormat.format(startDate); String endTime1=simpleDateFormat.format(ca.getTime()); mapValue.put("startTime",startTime1); mapValue.put("endTime",endTime1); } List> filter= offSiteTransportationService.getHaveAbnormalTruckOrderInfo(mapValue); PageHelper.startPage(pageNum, pageSize); List> list= offSiteTransportationService.getHaveAbnormalTruckOrderInfo(mapValue); PageListAdd pageList = columnDataUtil.tableColumnData(apiId, filter,list); return success(pageList); } @ApiOperation("查询在途运输") @ApiImplicitParams({ @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"), @ApiImplicitParam(name = "apiId", value = "动态表头", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer") }) @PostMapping("/getFinishTruckOrderInfo") public RESTfulResult getFinishTruckOrderInfo(@RequestBody Map mapValue, @RequestParam(required = true,defaultValue = "468",name = "apiId")Integer apiId, @RequestParam(required = false,defaultValue = "1",name = "pageNum")Integer pageNum, @RequestParam(required = false,defaultValue = "20",name = "pageSize")Integer pageSize ) { if(mapValue.containsKey("startTime")&&mapValue.containsKey("endTime")){ Date startDate=new Date(Long.parseLong(mapValue.get("startTime").toString())) ; Date endDate=new Date(Long.parseLong(mapValue.get("endTime").toString())) ; Calendar ca = Calendar.getInstance(); ca.setTime(endDate); ca.add(Calendar.DATE,1); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd"); String startTime1=simpleDateFormat.format(startDate); String endTime1=simpleDateFormat.format(ca.getTime()); mapValue.replace("startTime",startTime1); mapValue.replace("endTime",endTime1); }else { Date startDate=new Date() ; Date endDate=new Date() ; Calendar ca = Calendar.getInstance(); ca.setTime(endDate); ca.add(Calendar.DATE,1); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd"); String startTime1=simpleDateFormat.format(startDate); String endTime1=simpleDateFormat.format(ca.getTime()); mapValue.put("startTime",startTime1); mapValue.put("endTime",endTime1); } //已经完成 mapValue.put("orderStatus",2); List> filter= offSiteTransportationService.getInTransitTransportation(mapValue); PageHelper.startPage(pageNum, pageSize); List> list= offSiteTransportationService.getInTransitTransportation(mapValue); PageListAdd pageList = columnDataUtil.tableColumnData(apiId, filter,list); return success(pageList); } @PostMapping(value = "/addTmstruckReceiptResult" ) public synchronized RESTfulResult addTmstruckReceiptResult(@RequestBody Map value , Integer num, String orderNumber, String resultArrivalAddress, Integer imgcount3, Integer imgcount4) throws Exception { Map map = new HashMap(); map.put("orderNumber",orderNumber); map.put("resultArrivalAddress",resultArrivalAddress); Integer orderStatus = offSiteTransportationService.getOrderStatus(map); //判断是否已经结束 if (orderStatus!=null&&orderStatus==2){ return failed(-3); } map.putAll(value); //添加入库实绩 Integer resTfulResult = offSiteTransportationService.addTmstruckReceiptResult(map); if (!resTfulResult.equals("4")){ //保存路线 String redisJson = (String) redisTemplate.opsForValue().get(prefixOrder+":"+orderNumber); HashMap mapValue = JSON.parseObject(redisJson, HashMap.class); String json = zhongJiaoXingLu.visualRoute(mapValue); ViewVisualization to=null; if (json!=null){ //设置60天后过期 Calendar calendar=Calendar.getInstance(); long agoTime= calendar.getTime().getTime(); calendar.add(Calendar.MONTH,2); long lateTime= calendar.getTime().getTime(); long saveTime=(lateTime-agoTime)/1000; redisTemplate.opsForValue().set(prefixLine+":"+orderNumber, json, saveTime, TimeUnit.SECONDS); //删除订单 redisTemplate.delete(prefixOrder+":"+orderNumber); redisTemplate.delete(prefixOrder+":"+orderNumber+suffix); //添加运输距离 to= (ViewVisualization) DataConversionTool.jsonToBean(json,ViewVisualization.class); }else { HashMap hashMap=new HashMap(); hashMap.put("orderNumber",orderNumber); Map resultMap= offSiteTransportationService.getStartAndEndCapacityNumber(hashMap); if (resultMap!=null){ json= getPathJSON(resultMap.get("capacityNumber").toString(),resultMap.get("resultOutGateTime").toString()); if (json!=null&&!json.equals("")){ to= (ViewVisualization) DataConversionTool.jsonToBean(json,ViewVisualization.class); } } } //设置运输距离,并且结束订单 if (to!=null&&to.getResult()!=null&&to.getResult().getRunDistance()!=null){ Map ordermap=new HashMap<>(); ordermap.put("orderNumber",orderNumber); ordermap.put("orderMileage",to.getResult().getRunDistance()==null?"1":to.getResult().getRunDistance()); offSiteTransportationService.insertOrderMileage(ordermap); }else { if (to!=null&&to.getStatus()==1006){ Map ordermap=new HashMap<>(); ordermap.put("orderNumber",orderNumber); ordermap.put("orderMileage","-1"); offSiteTransportationService.insertOrderMileage(ordermap); }else if (to!=null&&to.getStatus()==1001){ Map ordermap=new HashMap<>(); ordermap.put("orderNumber",orderNumber); ordermap.put("orderMileage","1"); offSiteTransportationService.insertOrderMileage(ordermap); } else { Map ordermap=new HashMap<>(); ordermap.put("orderNumber",orderNumber); ordermap.put("orderMileage","-1"); offSiteTransportationService.insertOrderMileage(ordermap); } } //关闭运输订单 offSiteTransportationService.orderClose(orderNumber); } return success(1); } //如果内容丢失重新获得 public String getPathJSON(String capacityNumber,String resultOutGateTime) throws Exception { //入网验证 String netValidationResult = zhongJiaoXingLu.netValidation(capacityNumber); Map netValidationMap = (Map) JSONObject.parse(netValidationResult); if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){ String searchPointJson = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+ URLEncoder.encode("四川省达州钢铁集团有限责任公司","utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y"); SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class); String searchPointJson2 = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+URLEncoder.encode("四川省达州钢铁集团有限责任公司","utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y"); SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class); //运单生成之后保存 HashMap redisMap=new HashMap<>(); String startLon=searchPoint.getResult().getLocation().getLng().toString().length()>9?searchPoint.getResult().getLocation().getLng().toString().substring(0,9):searchPoint.getResult().getLocation().getLng().toString(); String startLat=searchPoint.getResult().getLocation().getLat().toString().length()>9?searchPoint.getResult().getLocation().getLat().toString().substring(0,8):searchPoint.getResult().getLocation().getLat().toString(); redisMap.put("startLonlat", startLon+","+startLat); String endLon= searchPoint2.getResult().getLocation().getLng().toString().length()>9?searchPoint2.getResult().getLocation().getLng().toString().substring(0,9):searchPoint2.getResult().getLocation().getLng().toString(); String endLat= searchPoint2.getResult().getLocation().getLat().toString().length()>9?searchPoint2.getResult().getLocation().getLat().toString().substring(0,8):searchPoint2.getResult().getLocation().getLat().toString(); redisMap.put("endLonlat",endLon+","+endLat); redisMap.put("vclN", capacityNumber); redisMap.put("vco","2"); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); String qryBtm=resultOutGateTime; //获得23小时、45分钟之后的时间 Date parse = simpleDateFormat.parse(qryBtm); //时间添加 Calendar calendar = Calendar.getInstance(); calendar.setTime(parse); calendar.add(Calendar.HOUR_OF_DAY, 23); calendar.add(Calendar.SECOND, 45); redisMap.put("qryBtm", qryBtm); redisMap.put("qryEtm",simpleDateFormat.format(calendar.getTime())); System.out.println(redisMap); String json = zhongJiaoXingLu.visualRoute(redisMap); System.out.println(json.length()>100?json.substring(0,100):json); return json; } return null; } public String removeData(){ offSiteTransportationService.removeDate(); return "success"; } /**查询是否开启运输报警状态 * warnSwitch * @param * @return */ @ApiOperation(value="查询是否开启运输报警状态") @ApiImplicitParams({ }) @PostMapping(value = "/selectWarnSwitch") public RESTfulResult selectWarnSwitch() { Map warnSwitch = offSiteTransportationService.selectWarnSwitch(); return success(warnSwitch); } /**是否开启运输报警状态 * warnSwitchaddTmstruckTotalResult * @param * @returninTransitOrderMileage */ @ApiOperation(value="是否开启运输报警状态") @ApiImplicitParams({ @ApiImplicitParam(name = "warnSwitch", value = "运输报警状态", required = false, dataType = "String") }) @PostMapping(value = "/inTransitWarn") public RESTfulResult inTransitWarn(@RequestParam String warnSwitch,@RequestParam String radio) { int i = offSiteTransportationService.updateWarnSwitch(warnSwitch,radio); return success(i); } @PostMapping("/abnormalLineWarn") public String abnormalLineWarn(@RequestParam(value = "data") String data) throws Exception { System.out.println("abnormalLineWarn"); System.out.println(data); ResultWarn resultWarn= (ResultWarn) DataConversionTool.jsonToBean(data, ResultWarn.class); Map map= DataConversionTool.objectToMap(resultWarn); int i= offSiteTransportationService.addTransportationAlarm(map); return "success"; } @PostMapping("/parkWarn") public String parkWarn(@RequestParam(value = "data",required = false) String data) throws Exception { System.out.println("parkWarn"); System.out.println(data); ResultWarn resultWarn= (ResultWarn) DataConversionTool.jsonToBean(data, ResultWarn.class); Map map= DataConversionTool.objectToMap(resultWarn); int i=offSiteTransportationService.addTransportationAlarm(map); return "success"; } @PostMapping("/offLineWarn") public String offLineWarn(@RequestParam(value = "data") String data) throws Exception { System.out.println("offLineWarn"); System.out.println(data); ResultWarn resultWarn= (ResultWarn) DataConversionTool.jsonToBean(data, ResultWarn.class); Map map= DataConversionTool.objectToMap(resultWarn); int i=offSiteTransportationService.addTransportationAlarm(map); return "success"; } @ApiOperation(value="展示运输在途异常信息") @ApiImplicitParams({ @ApiImplicitParam(name = "apiId(472)", value = "表头", required = false, dataType = "Interger") }) @PostMapping("/getTransportAbnormalInfo") public RESTfulResult getTransportAbnormalInfo(@RequestBody(required=false) Map mapValue, @RequestParam(name = "apiId",defaultValue = "472") Integer apiId, @RequestParam(name = "pageNum") Integer pageNum, @RequestParam(name = "pageSize") Integer pageSize){ List> transportAbnormalInfo = offSiteTransportationService.getTransportAbnormalInfo(mapValue); PageHelper.startPage(pageNum,pageSize); List> transportAbnormalInfo1 = offSiteTransportationService.getTransportAbnormalInfo(mapValue); PageListAdd pageList = columnDataUtil.tableColumnData(apiId,transportAbnormalInfo,transportAbnormalInfo1); return success(pageList); } @ApiOperation(value="查询路径") @ApiImplicitParams({ @ApiImplicitParam(name = "mapValue", value = "查询条件", required = false, dataType = "HashMap") }) @PostMapping("/fullPathVisualizationByCarNumber") public RouteVo fullPathVisualizationByCarNumber(@RequestBody HashMap mapValue) throws Exception { CompletableFuture createOrder =routeService.fullPathVisualizationByCarNumber(mapValue); return createOrder.get(); } }