OffSiteTransportationController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. package com.steerinfo.dil.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.steerinfo.dil.service.ITmstruckLeaveFactoryResultService;
  5. import com.steerinfo.dil.service.impl.OffSiteTransportationServiceImpl;
  6. import com.steerinfo.dil.util.BaseRESTfulController;
  7. import com.steerinfo.dil.util.ColumnDataUtil;
  8. import com.steerinfo.dil.util.PageListAdd;
  9. import com.steerinfo.framework.controller.RESTfulResult;
  10. import com.steerinfo.framework.service.pagehelper.PageHelper;
  11. import com.steerinfo.route.config.ImageFileUtils;
  12. import com.steerinfo.route.service.impl.RouteServiceImpl;
  13. import com.steerinfo.route.threeRequest.ZhongJiaoXingLu;
  14. import com.steerinfo.route.util.DataConversionTool;
  15. import com.steerinfo.route.util.HTTPRequestUtils;
  16. import com.steerinfo.route.vo.FullPathVisualizationTo.ViewVisualization;
  17. import com.steerinfo.route.vo.resultJson.SearchPoint;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiImplicitParam;
  20. import io.swagger.annotations.ApiImplicitParams;
  21. import io.swagger.annotations.ApiOperation;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.beans.factory.annotation.Value;
  24. import org.springframework.data.redis.core.RedisTemplate;
  25. import org.springframework.http.MediaType;
  26. import org.springframework.web.bind.annotation.*;
  27. import org.springframework.web.multipart.MultipartFile;
  28. import org.springframework.web.multipart.MultipartRequest;
  29. import java.net.URLEncoder;
  30. import java.text.SimpleDateFormat;
  31. import java.util.*;
  32. import java.util.concurrent.CompletableFuture;
  33. import java.util.concurrent.TimeUnit;
  34. @Api("厂外运输接口")
  35. @RestController
  36. @RequestMapping("/${api.version}/pathDisplay")
  37. public class OffSiteTransportationController extends BaseRESTfulController {
  38. @Autowired
  39. private ITmstruckLeaveFactoryResultService tmstruckLeaveFactoryResultService;
  40. @Autowired
  41. private RouteServiceImpl routeService;
  42. @Autowired
  43. ColumnDataUtil columnDataUtil;
  44. @Autowired
  45. ImageFileUtils imageFileUtils;
  46. @Autowired
  47. private ZhongJiaoXingLu zhongJiaoXingLu;
  48. @Value("${str.tengxun.key}")
  49. private String key;
  50. @Value("${redis.prefix.order}")
  51. private String prefixOrder;
  52. @Value("${redis.prefix.line}")
  53. private String prefixLine;
  54. @Value("${redis.prefix.suffix}")
  55. private String suffix;
  56. @Autowired
  57. private RedisTemplate redisTemplate;
  58. @Autowired
  59. OffSiteTransportationServiceImpl offSiteTransportationService;
  60. @ApiOperation("保存路径")
  61. @PostMapping("/savePath")
  62. public CompletableFuture<String> savePath() throws Exception {
  63. Map<String, Object> parem=tmstruckLeaveFactoryResultService.getTruckFactoryResult("WYSDD2022032400030239");
  64. parem.put("turnOf","0");
  65. return routeService.createTotalResult(parem);
  66. //运输订单号:orderNumber、车牌号:capacityNumber、出厂时间:resultOutGateTime、预警开关:turnOf、发货地址:shipperName、收货地址:receiveAddress
  67. //初始化请求参数
  68. // HashMap<String,Object> mapValue=new HashMap<>();
  69. // mapValue.put("orderNumber","WYSDD2021091000000001");
  70. // mapValue.put("capacityNumber","豫SB6238");
  71. // mapValue.put("resultOutGateTime","2021-11-17 14:20:19");
  72. // mapValue.put("turnOf","0");
  73. // mapValue.put("shipperName","四川达州钢铁集团有限");
  74. // mapValue.put("receiveAddress","长沙市");
  75. // return routeService.createTotalResult(mapValue);
  76. }
  77. @ApiOperation("全路径查询")
  78. @PostMapping("/fullPath")
  79. public Object fullPath(String orderNumber) throws Exception {
  80. //运输订单号:orderNumber、车牌号:capacityNumber、出厂时间:resultOutGateTime、预警开关:turnOf、发货地址:shipperName、收货地址:receiveAddress
  81. //初始化请求参数
  82. HashMap<String,Object> mapValue=new HashMap<>();
  83. mapValue.put("orderNumber",orderNumber);
  84. return routeService.fullPathVisualization(mapValue);
  85. }
  86. @ApiOperation("查询在途运输")
  87. @ApiImplicitParams({
  88. @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"),
  89. @ApiImplicitParam(name = "apiId", value = "动态表头", required = false, dataType = "Integer"),
  90. @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"),
  91. @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer")
  92. })
  93. @PostMapping("/getInTransitTransportation")
  94. public RESTfulResult getInTransitTransportation(@RequestBody Map<String,Object> mapValue,
  95. @RequestParam(required = true,defaultValue = "468",name = "apiId")Integer apiId,
  96. @RequestParam(required = false,defaultValue = "1",name = "pageNum")Integer pageNum,
  97. @RequestParam(required = false,defaultValue = "20",name = "pageSize")Integer pageSize
  98. )
  99. {
  100. if(mapValue.containsKey("startTime")&&mapValue.containsKey("endTime")){
  101. Date startDate=new Date(Long.parseLong(mapValue.get("startTime").toString())) ;
  102. Date endDate=new Date(Long.parseLong(mapValue.get("endTime").toString())) ;
  103. Calendar ca = Calendar.getInstance();
  104. ca.setTime(endDate);
  105. ca.add(Calendar.DATE,1);
  106. SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
  107. String startTime1=simpleDateFormat.format(startDate);
  108. String endTime1=simpleDateFormat.format(ca.getTime());
  109. mapValue.replace("startTime",startTime1);
  110. mapValue.replace("endTime",endTime1);
  111. }else {
  112. Date startDate=new Date() ;
  113. Date endDate=new Date() ;
  114. Calendar ca = Calendar.getInstance();
  115. ca.setTime(endDate);
  116. ca.add(Calendar.DATE,1);
  117. SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
  118. String startTime1=simpleDateFormat.format(startDate);
  119. String endTime1=simpleDateFormat.format(ca.getTime());
  120. mapValue.replace("startTime",startTime1);
  121. mapValue.replace("endTime",endTime1);
  122. }
  123. List<Map<String,Object>> filter= offSiteTransportationService.getInTransitTransportation(mapValue);
  124. PageHelper.startPage(pageNum, pageSize);
  125. List<Map<String,Object>> list= offSiteTransportationService.getInTransitTransportation(mapValue);
  126. PageListAdd pageList = columnDataUtil.tableColumnData(apiId, filter,list);
  127. return success(pageList);
  128. }
  129. @ApiOperation("查询在途运输")
  130. @ApiImplicitParams({
  131. @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"),
  132. @ApiImplicitParam(name = "apiId", value = "动态表头", required = false, dataType = "Integer"),
  133. @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"),
  134. @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer")
  135. })
  136. @PostMapping("/getFinishTruckOrderInfo")
  137. public RESTfulResult getFinishTruckOrderInfo(@RequestBody Map<String,Object> mapValue,
  138. @RequestParam(required = true,defaultValue = "468",name = "apiId")Integer apiId,
  139. @RequestParam(required = false,defaultValue = "1",name = "pageNum")Integer pageNum,
  140. @RequestParam(required = false,defaultValue = "20",name = "pageSize")Integer pageSize
  141. )
  142. {
  143. if(mapValue.containsKey("startTime")&&mapValue.containsKey("endTime")){
  144. Date startDate=new Date(Long.parseLong(mapValue.get("startTime").toString())) ;
  145. Date endDate=new Date(Long.parseLong(mapValue.get("endTime").toString())) ;
  146. Calendar ca = Calendar.getInstance();
  147. ca.setTime(endDate);
  148. ca.add(Calendar.DATE,1);
  149. SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
  150. String startTime1=simpleDateFormat.format(startDate);
  151. String endTime1=simpleDateFormat.format(ca.getTime());
  152. mapValue.replace("startTime",startTime1);
  153. mapValue.replace("endTime",endTime1);
  154. }else {
  155. Date startDate=new Date() ;
  156. Date endDate=new Date() ;
  157. Calendar ca = Calendar.getInstance();
  158. ca.setTime(endDate);
  159. ca.add(Calendar.DATE,1);
  160. SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
  161. String startTime1=simpleDateFormat.format(startDate);
  162. String endTime1=simpleDateFormat.format(ca.getTime());
  163. mapValue.replace("startTime",startTime1);
  164. mapValue.replace("endTime",endTime1);
  165. }
  166. //已经完成
  167. mapValue.put("orderStatus",2);
  168. List<Map<String,Object>> filter= offSiteTransportationService.getInTransitTransportation(mapValue);
  169. PageHelper.startPage(pageNum, pageSize);
  170. List<Map<String,Object>> list= offSiteTransportationService.getInTransitTransportation(mapValue);
  171. PageListAdd pageList = columnDataUtil.tableColumnData(apiId, filter,list);
  172. return success(pageList);
  173. }
  174. @PostMapping(value = "/addTmstruckReceiptResult" )
  175. public synchronized RESTfulResult addTmstruckReceiptResult(@RequestBody Map<String,Object> value , Integer num, String orderNumber, String resultArrivalAddress, Integer imgcount3, Integer imgcount4) throws Exception {
  176. Map<String,Object> map = new HashMap<String,Object>();
  177. map.put("orderNumber",orderNumber);
  178. map.put("resultArrivalAddress",resultArrivalAddress);
  179. Integer orderStatus = offSiteTransportationService.getOrderStatus(map);
  180. //判断是否已经结束
  181. if (orderStatus!=null&&orderStatus==2){
  182. return failed(-3);
  183. }
  184. map.putAll(value);
  185. //添加入库实绩
  186. Integer resTfulResult = offSiteTransportationService.addTmstruckReceiptResult(map);
  187. if (!resTfulResult.equals("4")){
  188. //保存路线
  189. String redisJson = (String) redisTemplate.opsForValue().get(prefixOrder+":"+orderNumber);
  190. HashMap mapValue = JSON.parseObject(redisJson, HashMap.class);
  191. String json = zhongJiaoXingLu.visualRoute(mapValue);
  192. ViewVisualization to=null;
  193. if (json!=null){
  194. //设置60天后过期
  195. Calendar calendar=Calendar.getInstance();
  196. long agoTime= calendar.getTime().getTime();
  197. calendar.add(Calendar.MONTH,2);
  198. long lateTime= calendar.getTime().getTime();
  199. long saveTime=(lateTime-agoTime)/1000;
  200. redisTemplate.opsForValue().set(prefixLine+":"+orderNumber, json, saveTime, TimeUnit.SECONDS);
  201. //删除订单
  202. redisTemplate.delete(prefixOrder+":"+orderNumber);
  203. redisTemplate.delete(prefixOrder+":"+orderNumber+suffix);
  204. //添加运输距离
  205. to= (ViewVisualization) DataConversionTool.jsonToBean(json,ViewVisualization.class);
  206. }else {
  207. HashMap<String,Object> hashMap=new HashMap();
  208. hashMap.put("orderNumber",orderNumber);
  209. Map<String,Object> resultMap= offSiteTransportationService.getStartAndEndCapacityNumber(hashMap);
  210. if (resultMap!=null){
  211. json= getPathJSON(resultMap.get("capacityNumber").toString(),resultMap.get("resultOutGateTime").toString());
  212. if (json!=null&&!json.equals("")){
  213. to= (ViewVisualization) DataConversionTool.jsonToBean(json,ViewVisualization.class);
  214. }
  215. }
  216. }
  217. //设置运输距离,并且结束订单
  218. if (to!=null&&to.getResult()!=null&&to.getResult().getRunDistance()!=null){
  219. Map<String,Object> ordermap=new HashMap<>();
  220. ordermap.put("orderNumber",orderNumber);
  221. ordermap.put("orderMileage",to.getResult().getRunDistance()==null?"1":to.getResult().getRunDistance());
  222. offSiteTransportationService.insertOrderMileage(ordermap);
  223. }else {
  224. if (to!=null&&to.getStatus()==1006){
  225. Map<String,Object> ordermap=new HashMap<>();
  226. ordermap.put("orderNumber",orderNumber);
  227. ordermap.put("orderMileage","-1");
  228. offSiteTransportationService.insertOrderMileage(ordermap);
  229. }else if (to!=null&&to.getStatus()==1001){
  230. Map<String,Object> ordermap=new HashMap<>();
  231. ordermap.put("orderNumber",orderNumber);
  232. ordermap.put("orderMileage","1");
  233. offSiteTransportationService.insertOrderMileage(ordermap);
  234. } else {
  235. Map<String,Object> ordermap=new HashMap<>();
  236. ordermap.put("orderNumber",orderNumber);
  237. ordermap.put("orderMileage","-1");
  238. offSiteTransportationService.insertOrderMileage(ordermap);
  239. }
  240. }
  241. //关闭运输订单
  242. offSiteTransportationService.orderClose(orderNumber);
  243. }
  244. return success(1);
  245. }
  246. //如果内容丢失重新获得
  247. public String getPathJSON(String capacityNumber,String resultOutGateTime) throws Exception {
  248. //入网验证
  249. String netValidationResult = zhongJiaoXingLu.netValidation(capacityNumber);
  250. Map netValidationMap = (Map) JSONObject.parse(netValidationResult);
  251. if (Integer.parseInt(netValidationMap.get("status").toString())==1001&&netValidationMap.get("result").toString().equals("yes")){
  252. String searchPointJson = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+ URLEncoder.encode("四川省达州钢铁集团有限责任公司","utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y");
  253. SearchPoint searchPoint= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson, SearchPoint.class);
  254. String searchPointJson2 = HTTPRequestUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address="+URLEncoder.encode("四川省达州钢铁集团有限责任公司","utf-8")+"&key=WDTBZ-A5VKJ-UDLFI-KYJY6-WTP2S-A6B4Y");
  255. SearchPoint searchPoint2= (SearchPoint) DataConversionTool.jsonToBean(searchPointJson2, SearchPoint.class);
  256. //运单生成之后保存
  257. HashMap<String,String> redisMap=new HashMap<>();
  258. String startLon=searchPoint.getResult().getLocation().getLng().toString().length()>9?searchPoint.getResult().getLocation().getLng().toString().substring(0,9):searchPoint.getResult().getLocation().getLng().toString();
  259. String startLat=searchPoint.getResult().getLocation().getLat().toString().length()>9?searchPoint.getResult().getLocation().getLat().toString().substring(0,8):searchPoint.getResult().getLocation().getLat().toString();
  260. redisMap.put("startLonlat", startLon+","+startLat);
  261. String endLon= searchPoint2.getResult().getLocation().getLng().toString().length()>9?searchPoint2.getResult().getLocation().getLng().toString().substring(0,9):searchPoint2.getResult().getLocation().getLng().toString();
  262. String endLat= searchPoint2.getResult().getLocation().getLat().toString().length()>9?searchPoint2.getResult().getLocation().getLat().toString().substring(0,8):searchPoint2.getResult().getLocation().getLat().toString();
  263. redisMap.put("endLonlat",endLon+","+endLat);
  264. redisMap.put("vclN", capacityNumber);
  265. redisMap.put("vco","2");
  266. SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
  267. String qryBtm=resultOutGateTime;
  268. //获得23小时、45分钟之后的时间
  269. Date parse = simpleDateFormat.parse(qryBtm);
  270. //时间添加
  271. Calendar calendar = Calendar.getInstance();
  272. calendar.setTime(parse);
  273. calendar.add(Calendar.HOUR_OF_DAY, 23);
  274. calendar.add(Calendar.SECOND, 45);
  275. redisMap.put("qryBtm", qryBtm);
  276. redisMap.put("qryEtm",simpleDateFormat.format(calendar.getTime()));
  277. System.out.println(redisMap);
  278. String json = zhongJiaoXingLu.visualRoute(redisMap);
  279. System.out.println(json.length()>100?json.substring(0,100):json);
  280. return json;
  281. }
  282. return null;
  283. }
  284. public String removeData(){
  285. offSiteTransportationService.removeDate();
  286. return "success";
  287. }
  288. }