TmsRouteResultServiceImpl.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package com.steerinfo.dil.service.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.steerinfo.dil.mapper.CommonMapper;
  6. import com.steerinfo.dil.mapper.TmsRouteResultMapper;
  7. import com.steerinfo.dil.model.TmsRouteResult;
  8. import com.steerinfo.dil.util.DataChange;
  9. import oracle.sql.CLOB;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import javax.sql.rowset.serial.SerialClob;
  14. import javax.xml.crypto.Data;
  15. import java.math.BigDecimal;
  16. import java.sql.Clob;
  17. import java.sql.SQLException;
  18. import java.text.DateFormat;
  19. import java.text.SimpleDateFormat;
  20. import java.util.*;
  21. /**
  22. * TmsRouteResult服务实现:
  23. * @author generator
  24. * @version 1.0-SNAPSHORT 2024-03-13 10:21
  25. * 类描述
  26. * 修订历史:
  27. * 日期:2024-03-13
  28. * 作者:generator
  29. * 参考:
  30. * 描述:TmsRouteResult服务实现
  31. * @see null
  32. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  33. */
  34. @Service(value = "tmsRouteResultService")
  35. public class TmsRouteResultServiceImpl {
  36. @Autowired
  37. private TmsRouteResultMapper tmsRouteResultMapper;
  38. private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  39. public Object getPathByOrder(Map<String, Object> map) throws Exception {
  40. BigDecimal orderId = DataChange.dataToBigDecimal(map.get("transOrderId").toString());
  41. //查询
  42. Map<String,Object> params = new HashMap<>();
  43. params.put("transOrderId",orderId);
  44. List<TmsRouteResult> searchList = tmsRouteResultMapper.selectByParameters(params);
  45. if(searchList.size() > 0){
  46. return JSONObject.parseObject(searchList.get(0).getPath());
  47. }
  48. return null;
  49. }
  50. // @Transactional(rollbackFor = Exception.class)
  51. public String uploadLocation(Map<String, Object> map) throws Exception {
  52. BigDecimal transOrderId = DataChange.dataToBigDecimal(map.get("transOrderId").toString());
  53. JSONObject location = JSONObject.parseObject(JSONObject.toJSONString(map.get("location")));
  54. //查询
  55. Map<String,Object> params = new HashMap<>();
  56. params.put("transOrderId",transOrderId);
  57. List<TmsRouteResult> searchList = tmsRouteResultMapper.selectByParameters(params);
  58. if(searchList.size() > 0){
  59. //更新
  60. TmsRouteResult tmsRouteResult = searchList.get(0);
  61. JSONObject path = JSONObject.parseObject(tmsRouteResult.getPath());
  62. //路径数组
  63. List<String[]> pathArr = JSONArray.parseArray(JSONArray.toJSONString(path.get("pathArr")),String[].class);
  64. pathArr.add(new String[]{
  65. location.getString("longitude"),
  66. location.getString("latitude")});
  67. path.put("pathArr",pathArr);
  68. //详情数组(包括时间和速度)
  69. List<JSONObject> detailArr = JSONArray.parseArray(JSONArray.toJSONString(path.get("detailArr")),JSONObject.class);
  70. JSONObject detail = new JSONObject();
  71. detail.put("speed",location.get("speed"));
  72. detail.put("time",dateFormat.format(new Date()));
  73. detailArr.add(detail);
  74. path.put("detailArr",detailArr);
  75. //更新实绩
  76. tmsRouteResult.setPath(path.toJSONString());
  77. tmsRouteResult.setUpdateUsername(map.get("userName").toString());
  78. tmsRouteResult.setUpdateTime(new Date());
  79. tmsRouteResultMapper.updateByPrimaryKey(tmsRouteResult);
  80. }else{
  81. //新增
  82. //构建路径json
  83. JSONObject path = new JSONObject();
  84. //路径数组
  85. List<String[]> pathArr = new ArrayList<>();
  86. pathArr.add(new String[]{
  87. location.getString("longitude"),
  88. location.getString("latitude")});
  89. path.put("pathArr",pathArr);
  90. //详情数组(包括时间和速度)
  91. List<JSONObject> detailArr = new ArrayList<>();
  92. JSONObject detail = new JSONObject();
  93. detail.put("speed",location.get("speed"));
  94. detail.put("time",dateFormat.format(new Date()));
  95. detailArr.add(detail);
  96. path.put("detailArr",detailArr);
  97. //新增实绩
  98. TmsRouteResult tmsRouteResult = new TmsRouteResult();
  99. tmsRouteResult.setResultId(tmsRouteResultMapper.nextId());
  100. tmsRouteResult.setTransOrderId(transOrderId);
  101. tmsRouteResult.setPath(path.toJSONString());
  102. tmsRouteResult.setInsertUsername(map.get("userName").toString());
  103. tmsRouteResult.setInsertTime(new Date());
  104. tmsRouteResultMapper.insertSelective(tmsRouteResult);
  105. }
  106. return "记录成功!";
  107. }
  108. }