|
@@ -1,6 +1,9 @@
|
|
|
package com.ruoyi.demo.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import com.ruoyi.demo.entity.Equipment;
|
|
|
import com.ruoyi.demo.entity.Store;
|
|
|
import com.ruoyi.demo.entity.bo.StoreBo;
|
|
@@ -12,8 +15,10 @@ import com.ruoyi.demo.utils.InitMapUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -32,6 +37,7 @@ public class StoreServiceImpl implements StoreService {
|
|
|
public void addStore(StoreVo storeVo) {
|
|
|
Store store = new Store(storeVo);
|
|
|
store.setAddrCodeInfo(initMapUtil.getInitAddrCodeMap(store.getAddrCode()));
|
|
|
+ store.setCreateTime(LocalDateTime.now());
|
|
|
storeMapper.insert(store);
|
|
|
}
|
|
|
|
|
@@ -50,62 +56,52 @@ public class StoreServiceImpl implements StoreService {
|
|
|
* 店铺管理设备(不支持设备上层没有店铺)
|
|
|
* */
|
|
|
@Override
|
|
|
- public List<StoreBo> getStoreTree(StoreVo storeVo) {
|
|
|
+ public HashMap getStoreList(StoreVo storeVo) {
|
|
|
//1.找到所有店铺列表
|
|
|
QueryWrapper<Store> queryWrapper = new QueryWrapper<>();
|
|
|
- if (storeVo.getStoreName() != null && !storeVo.getStoreName().equals("")){
|
|
|
- queryWrapper.like("store_name",storeVo.getStoreName());
|
|
|
- }
|
|
|
- if(storeVo.getAddrCode() != null && !storeVo.getAddrCode().equals("")){
|
|
|
- queryWrapper.and(storeQueryWrapper -> {
|
|
|
- storeQueryWrapper.eq("addr_code",storeVo.getAddrCode());
|
|
|
- });
|
|
|
- }
|
|
|
- if(storeVo.getPrincipalName() != null && !storeVo.getPrincipalName().equals("")){
|
|
|
- queryWrapper.and(storeQueryWrapper -> {
|
|
|
- storeQueryWrapper.like("principal_name",storeVo.getPrincipalName());
|
|
|
- });
|
|
|
+ if(storeVo.getSearchText() != null && !storeVo.getStoreName().equals("")){
|
|
|
+ queryWrapper.like("store_name",storeVo.getSearchText());
|
|
|
}
|
|
|
+ PageHelper.startPage(storeVo.getPageNum(),storeVo.getPageSize());
|
|
|
List<Store> stores = storeMapper.selectList(queryWrapper);
|
|
|
+ PageInfo<Store> pageInfo = new PageInfo<>(stores);
|
|
|
|
|
|
//2.找到子设备
|
|
|
- List<String> collect = stores.stream().map(item -> {
|
|
|
+ List<String> collect = pageInfo.getList().stream().map(item -> {
|
|
|
return item.getStoreId();
|
|
|
}).collect(Collectors.toList());
|
|
|
QueryWrapper<Equipment> queryWrapper1 = new QueryWrapper<>();
|
|
|
- queryWrapper1.select("equipment_id","equipment_name","addr_info","lat","lng","state");
|
|
|
+ queryWrapper1.select("store_id","count(*) as state");
|
|
|
queryWrapper1.in("store_id",collect);
|
|
|
+ queryWrapper1.groupBy("store_id");
|
|
|
List<Equipment> equipments = equipmentMapper.selectList(queryWrapper1);
|
|
|
|
|
|
List<StoreBo> storeBos = new ArrayList<>();
|
|
|
//组装
|
|
|
- for (Store store : stores) {
|
|
|
+ for (Store store : pageInfo.getList()) {
|
|
|
StoreBo storeBo = new StoreBo(store);
|
|
|
- storeBo.setEquipmentList(findEquipmentList(store.getStoreId(),equipments));
|
|
|
+ storeBo.setCount(findEquipmentCount(store.getStoreId(),equipments));
|
|
|
storeBos.add(storeBo);
|
|
|
}
|
|
|
- return storeBos;
|
|
|
+
|
|
|
+ pageInfo.setList(null);
|
|
|
+ HashMap<String, Object> objectObjectHashMap = new HashMap<>();
|
|
|
+ objectObjectHashMap.put("page",pageInfo);
|
|
|
+ objectObjectHashMap.put("data",stores);
|
|
|
+ return objectObjectHashMap;
|
|
|
}
|
|
|
|
|
|
- private List<Equipment> findEquipmentList(String storeId,List<Equipment> equipments){
|
|
|
- List<Equipment> collect = equipments.stream().filter(item -> {
|
|
|
- if (storeId.equals(item.getStoreId()))
|
|
|
- return true;
|
|
|
- return false;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- return collect;
|
|
|
+ private int findEquipmentCount(String storeId,List<Equipment> equipments){
|
|
|
+ for (Equipment equipment : equipments) {
|
|
|
+ if (equipment.getStoreId().equals(storeId))
|
|
|
+ return equipment.getState();
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public StoreBo getStore(String storeId) {
|
|
|
+ public Store getStore(String storeId) {
|
|
|
Store store = storeMapper.selectById(storeId);
|
|
|
- StoreBo storeBo = new StoreBo(store);
|
|
|
-
|
|
|
- QueryWrapper<Equipment> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("store_id",storeId);
|
|
|
- List<Equipment> equipment = equipmentMapper.selectList(queryWrapper);
|
|
|
-
|
|
|
- storeBo.setEquipmentList(equipment);
|
|
|
- return storeBo;
|
|
|
+ return store;
|
|
|
}
|
|
|
}
|