From 70211b41954df4ac1232f48420b89c13fb5fb451 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期三, 25 六月 2025 15:06:58 +0800 Subject: [PATCH] 更新用户端功能 --- UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/OrderPositionServiceImpl.java | 126 ++++++++++++++++-------------------------- 1 files changed, 48 insertions(+), 78 deletions(-) diff --git a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/OrderPositionServiceImpl.java b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/OrderPositionServiceImpl.java index 7ee14e8..9ba8ce5 100644 --- a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/OrderPositionServiceImpl.java +++ b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/OrderPositionServiceImpl.java @@ -1,19 +1,16 @@ package com.stylefeng.guns.modular.system.service.impl; -import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.service.impl.ServiceImpl; -import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.system.dao.OrderPositionMapper; import com.stylefeng.guns.modular.system.model.OrderPosition; import com.stylefeng.guns.modular.system.service.IOrderPositionService; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Sort; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -22,77 +19,50 @@ @Service public class OrderPositionServiceImpl extends ServiceImpl<OrderPositionMapper, OrderPosition> implements IOrderPositionService { - - @Resource - private OrderPositionMapper orderPositionMapper; - - @Value("${filePath}") - private String filePath; - - - /** - * 获取轨迹数据 - * @param orderId - * @param orderType - * @return - * @throws Exception - */ - @Override - public List<Map<String, Object>> queryTrack(Integer orderId, Integer orderType) throws Exception { -// return orderPositionMapper.queryTrack(orderId, orderType); - //将数据存储到文件中 - File file = new File(filePath + orderId + "_" + orderType + ".txt"); - if(!file.exists()){ - return new ArrayList<>(); - } - //读取文件(字符流) - BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8")); - //循环取出数据 - String str = null; - StringBuffer sb = new StringBuffer(); - while ((str = in.readLine()) != null) { - sb.append(str); - } - List<OrderPosition> list = JSONArray.parseArray(sb.toString(), OrderPosition.class); - List<Map<String, Object>> lonlat = new ArrayList<>(); - for(OrderPosition orderPosition : list){ - Map<String, Object> map = new HashMap<>(); - map.put("lon", orderPosition.getLon()); - map.put("lat", orderPosition.getLat()); - lonlat.add(map); - } + + @Resource + private OrderPositionMapper orderPositionMapper; + + @Resource + private MongoTemplate mongoTemplate; + + + /** + * 获取轨迹数据 + * + * @param orderId + * @param orderType + * @return + * @throws Exception + */ + @Override + public List<Map<String, Object>> queryTrack(Integer orderId, Integer orderType) throws Exception { + List<OrderPosition> positions = queryPosition(orderId, orderType); + List<Map<String, Object>> lonlat = new ArrayList<>(); + for (OrderPosition orderPosition : positions) { + Map<String, Object> map = new HashMap<>(); + map.put("lon", orderPosition.getLon()); + map.put("lat", orderPosition.getLat()); + lonlat.add(map); + } return lonlat; } - - - - /** - * 获取坐标文件中的坐标数据 - * @param orderId - * @param orderType - * @return - * @throws Exception - */ - @Override - public List<OrderPosition> queryPosition(Integer orderId, Integer orderType) throws Exception{ - //将数据存储到文件中 - File file = new File(filePath + orderId + "_" + orderType + ".txt"); - if(!file.exists()){ - return new ArrayList<>(); - } - //读取文件(字符流) - BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8")); - //循环取出数据 - String str = null; - StringBuffer sb = new StringBuffer(); - while ((str = in.readLine()) != null) { - sb.append(str); - } - List<OrderPosition> list = new ArrayList<>(); - if(ToolUtil.isNotEmpty(sb.toString())){ - list = JSONArray.parseArray(sb.toString(), OrderPosition.class); - } - System.err.println("坐标:" + sb); - return list; - } + + + /** + * 获取坐标文件中的坐标数据 + * + * @param orderId + * @param orderType + * @return + * @throws Exception + */ + @Override + public List<OrderPosition> queryPosition(Integer orderId, Integer orderType) throws Exception { + Query query = new Query() + .addCriteria(Criteria.where("orderId").is(orderId).and("orderType").is(orderType)) + .with(new Sort(Sort.Direction.ASC, "insertTime")); + List<OrderPosition> positions = mongoTemplate.find(query, OrderPosition.class); + return positions; + } } -- Gitblit v1.7.1