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 map) throws Exception { BigDecimal orderId = DataChange.dataToBigDecimal(map.get("transOrderId").toString()); //查询 Map params = new HashMap<>(); params.put("transOrderId",orderId); List 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 map) throws Exception { BigDecimal transOrderId = DataChange.dataToBigDecimal(map.get("transOrderId").toString()); JSONObject location = JSONObject.parseObject(JSONObject.toJSONString(map.get("location"))); //查询 Map params = new HashMap<>(); params.put("transOrderId",transOrderId); List searchList = tmsRouteResultMapper.selectByParameters(params); if(searchList.size() > 0){ //更新 TmsRouteResult tmsRouteResult = searchList.get(0); JSONObject path = JSONObject.parseObject(tmsRouteResult.getPath()); //路径数组 List 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 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 pathArr = new ArrayList<>(); pathArr.add(new String[]{ location.getString("longitude"), location.getString("latitude")}); path.put("pathArr",pathArr); //详情数组(包括时间和速度) List 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 "记录成功!"; } }