123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- 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<String> savePath() throws Exception {
- Map<String, Object> parem=tmstruckLeaveFactoryResultService.getTruckFactoryResult("WYSDD2022040600045906");
- parem.put("turnOf","0");
- return routeService.createTotalResult(parem);
- //运输订单号:orderNumber、车牌号:capacityNumber、出厂时间:resultOutGateTime、预警开关:turnOf、发货地址:shipperName、收货地址:receiveAddress
- //初始化请求参数
- // HashMap<String,Object> 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<String,Object> 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<String,Object> 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<Map<String,Object>> filter= offSiteTransportationService.getInTransitTransportation(mapValue);
- PageHelper.startPage(pageNum, pageSize);
- List<Map<String,Object>> 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<String,Object> 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<Map<String,Object>> filter= offSiteTransportationService.getHaveAbnormalTruckOrderInfo(mapValue);
- PageHelper.startPage(pageNum, pageSize);
- List<Map<String,Object>> 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<String,Object> 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<Map<String,Object>> filter= offSiteTransportationService.getInTransitTransportation(mapValue);
- PageHelper.startPage(pageNum, pageSize);
- List<Map<String,Object>> list= offSiteTransportationService.getInTransitTransportation(mapValue);
- PageListAdd pageList = columnDataUtil.tableColumnData(apiId, filter,list);
- return success(pageList);
- }
- @PostMapping(value = "/addTmstruckReceiptResult" )
- public synchronized RESTfulResult addTmstruckReceiptResult(@RequestBody Map<String,Object> value , Integer num, String orderNumber, String resultArrivalAddress, Integer imgcount3, Integer imgcount4) throws Exception {
- Map<String,Object> map = new HashMap<String,Object>();
- 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<String,Object> hashMap=new HashMap();
- hashMap.put("orderNumber",orderNumber);
- Map<String,Object> 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<String,Object> 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<String,Object> ordermap=new HashMap<>();
- ordermap.put("orderNumber",orderNumber);
- ordermap.put("orderMileage","-1");
- offSiteTransportationService.insertOrderMileage(ordermap);
- }else if (to!=null&&to.getStatus()==1001){
- Map<String,Object> ordermap=new HashMap<>();
- ordermap.put("orderNumber",orderNumber);
- ordermap.put("orderMileage","1");
- offSiteTransportationService.insertOrderMileage(ordermap);
- } else {
- Map<String,Object> 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<String,String> 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<String,Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String,Object> mapValue,
- @RequestParam(name = "apiId",defaultValue = "472") Integer apiId,
- @RequestParam(name = "pageNum") Integer pageNum,
- @RequestParam(name = "pageSize") Integer pageSize){
- List<Map<String, Object>> transportAbnormalInfo = offSiteTransportationService.getTransportAbnormalInfo(mapValue);
- PageHelper.startPage(pageNum,pageSize);
- List<Map<String, Object>> 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<RouteVo> createOrder =routeService.fullPathVisualizationByCarNumber(mapValue);
- return createOrder.get();
- }
- }
|