| | |
| | | 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; |
| | |
| | | @Resource |
| | | private OrderPositionMapper orderPositionMapper; |
| | | |
| | | @Value("${filePath}") |
| | | private String filePath; |
| | | @Resource |
| | | private MongoTemplate mongoTemplate; |
| | | |
| | | |
| | | |
| | |
| | | @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; |
| | | 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; |
| | | } |
| | | } |