| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package com.steerinfo.dil.service.impl;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.steerinfo.dil.mapper.CommonMapper;
- import com.steerinfo.dil.mapper.TmsRouteResultMapper;
- import com.steerinfo.dil.model.TmsRouteResult;
- import com.steerinfo.dil.util.DataChange;
- import oracle.sql.CLOB;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.sql.rowset.serial.SerialClob;
- import javax.xml.crypto.Data;
- import java.math.BigDecimal;
- import java.sql.Clob;
- import java.sql.SQLException;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * TmsRouteResult服务实现:
- * @author generator
- * @version 1.0-SNAPSHORT 2024-03-13 10:21
- * 类描述
- * 修订历史:
- * 日期:2024-03-13
- * 作者:generator
- * 参考:
- * 描述:TmsRouteResult服务实现
- * @see null
- * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
- */
- @Service(value = "tmsRouteResultService")
- public class TmsRouteResultServiceImpl {
- @Autowired
- private TmsRouteResultMapper tmsRouteResultMapper;
- private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- public Object getPathByOrder(Map<String, Object> map) throws Exception {
- BigDecimal orderId = DataChange.dataToBigDecimal(map.get("transOrderId").toString());
- //查询
- Map<String,Object> params = new HashMap<>();
- params.put("transOrderId",orderId);
- List<TmsRouteResult> searchList = tmsRouteResultMapper.selectByParameters(params);
- if(searchList.size() > 0){
- return JSONObject.parseObject(searchList.get(0).getPath());
- }
- return null;
- }
- // @Transactional(rollbackFor = Exception.class)
- public String uploadLocation(Map<String, Object> map) throws Exception {
- BigDecimal transOrderId = DataChange.dataToBigDecimal(map.get("transOrderId").toString());
- JSONObject location = JSONObject.parseObject(JSONObject.toJSONString(map.get("location")));
- //查询
- Map<String,Object> params = new HashMap<>();
- params.put("transOrderId",transOrderId);
- List<TmsRouteResult> searchList = tmsRouteResultMapper.selectByParameters(params);
- if(searchList.size() > 0){
- //更新
- TmsRouteResult tmsRouteResult = searchList.get(0);
- JSONObject path = JSONObject.parseObject(tmsRouteResult.getPath());
- //路径数组
- List<String[]> pathArr = JSONArray.parseArray(JSONArray.toJSONString(path.get("pathArr")),String[].class);
- pathArr.add(new String[]{
- location.getString("longitude"),
- location.getString("latitude")});
- path.put("pathArr",pathArr);
- //详情数组(包括时间和速度)
- List<JSONObject> detailArr = JSONArray.parseArray(JSONArray.toJSONString(path.get("detailArr")),JSONObject.class);
- JSONObject detail = new JSONObject();
- detail.put("speed",location.get("speed"));
- detail.put("time",dateFormat.format(new Date()));
- detailArr.add(detail);
- path.put("detailArr",detailArr);
- //更新实绩
- tmsRouteResult.setPath(path.toJSONString());
- tmsRouteResult.setUpdateUsername(map.get("userName").toString());
- tmsRouteResult.setUpdateTime(new Date());
- tmsRouteResultMapper.updateByPrimaryKey(tmsRouteResult);
- }else{
- //新增
- //构建路径json
- JSONObject path = new JSONObject();
- //路径数组
- List<String[]> pathArr = new ArrayList<>();
- pathArr.add(new String[]{
- location.getString("longitude"),
- location.getString("latitude")});
- path.put("pathArr",pathArr);
- //详情数组(包括时间和速度)
- List<JSONObject> detailArr = new ArrayList<>();
- JSONObject detail = new JSONObject();
- detail.put("speed",location.get("speed"));
- detail.put("time",dateFormat.format(new Date()));
- detailArr.add(detail);
- path.put("detailArr",detailArr);
- //新增实绩
- TmsRouteResult tmsRouteResult = new TmsRouteResult();
- tmsRouteResult.setResultId(tmsRouteResultMapper.nextId());
- tmsRouteResult.setTransOrderId(transOrderId);
- tmsRouteResult.setPath(path.toJSONString());
- tmsRouteResult.setInsertUsername(map.get("userName").toString());
- tmsRouteResult.setInsertTime(new Date());
- tmsRouteResultMapper.insertSelective(tmsRouteResult);
- }
- return "记录成功!";
- }
- }
|