|
@@ -1,39 +1,111 @@
|
|
|
package com.ruoyi.demo.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.ruoyi.demo.entity.Equipment;
|
|
|
import com.ruoyi.demo.entity.Store;
|
|
|
+import com.ruoyi.demo.entity.bo.StoreBo;
|
|
|
import com.ruoyi.demo.entity.vo.StoreVo;
|
|
|
+import com.ruoyi.demo.mapper.EquipmentMapper;
|
|
|
import com.ruoyi.demo.mapper.StoreMapper;
|
|
|
import com.ruoyi.demo.service.StoreService;
|
|
|
+import com.ruoyi.demo.utils.InitMapUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
@Service
|
|
|
public class StoreServiceImpl implements StoreService {
|
|
|
@Autowired
|
|
|
StoreMapper storeMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ EquipmentMapper equipmentMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ InitMapUtil initMapUtil;
|
|
|
+
|
|
|
@Override
|
|
|
public void addStore(StoreVo storeVo) {
|
|
|
Store store = new Store(storeVo);
|
|
|
+ store.setAddrCodeInfo(initMapUtil.getInitAddrCodeMap(store.getAddrCode()));
|
|
|
storeMapper.insert(store);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void updateStore(StoreVo storeVo) {
|
|
|
+ storeVo.setAddrCodeInfo(initMapUtil.getInitAddrCodeMap(storeVo.getAddrCode()));
|
|
|
storeMapper.updateStore(storeVo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void deleteStore(String[] storeIds) {
|
|
|
-
|
|
|
+ storeMapper.deleteBatchIds(Arrays.asList(storeIds));
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ * 店铺管理设备(不支持设备上层没有店铺)
|
|
|
+ * */
|
|
|
@Override
|
|
|
- public void getStoreTree(StoreVo storeVo) {
|
|
|
+ public List<StoreBo> getStoreTree(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());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ List<Store> stores = storeMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ //2.找到子设备
|
|
|
+ List<String> collect = stores.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.in("store_id",collect);
|
|
|
+ List<Equipment> equipments = equipmentMapper.selectList(queryWrapper1);
|
|
|
|
|
|
+ List<StoreBo> storeBos = new ArrayList<>();
|
|
|
+ //组装
|
|
|
+ for (Store store : stores) {
|
|
|
+ StoreBo storeBo = new StoreBo(store);
|
|
|
+ storeBo.setEquipmentList(findEquipmentList(store.getStoreId(),equipments));
|
|
|
+ storeBos.add(storeBo);
|
|
|
+ }
|
|
|
+ return storeBos;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void getStore(StoreVo storeVo) {
|
|
|
+ public StoreBo 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;
|
|
|
}
|
|
|
}
|