| 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.stereotype.Service; | 
|   | 
| import javax.annotation.Resource; | 
| import java.io.*; | 
| import java.util.ArrayList; | 
| import java.util.List; | 
|   | 
|   | 
| @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 OrderPosition queryNew(Integer orderId, Integer orderType) throws Exception { | 
|         List<OrderPosition> orderPositions = this.queryPosition(orderId, orderType); | 
|         return orderPositions.size() > 0 ? orderPositions.get(orderPositions.size() - 1) : null; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 获取坐标文件中的坐标数据 | 
|      * @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); | 
|         } | 
|         return list; | 
|     } | 
| } |