diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/mapping/CsLinePOMapper.xml b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/mapping/CsLinePOMapper.xml index 9f3b5e6..8473e50 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/mapping/CsLinePOMapper.xml +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/mapper/mapping/CsLinePOMapper.xml @@ -28,7 +28,7 @@ t1.* from cs_equipment_delivery t0 - left join cs_line t1 on + right join cs_line t1 on t0.id = t1.device_id where t0.ndid = #{id} diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsDeviceUserPOService.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsDeviceUserPOService.java index d3f8af4..9c4380f 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsDeviceUserPOService.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/CsDeviceUserPOService.java @@ -55,4 +55,10 @@ public interface CsDeviceUserPOService extends IService{ void channelDevByUserId(UserDevParam param); List getList(UserDevParam param); + + /** + * 新增用户设备关系表数据 新增主用户信息 && 新增已关联工程的用户的设备关系 + * @return + */ + Boolean addRelation(UserDevParam param); } diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsDeviceUserPOServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsDeviceUserPOServiceImpl.java index efe7d9d..25cedb8 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsDeviceUserPOServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsDeviceUserPOServiceImpl.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import static java.util.Objects.isNull; @@ -545,4 +546,59 @@ public class CsDeviceUserPOServiceImpl extends ServiceImpl batchRecords = param.getList().stream() + .filter(Objects::nonNull) + .filter(item -> !Objects.equals(item, userIndex)) + .map(item -> { + CsDeviceUserPO relation = new CsDeviceUserPO(); + relation.setDeviceId(param.getUserId()); + relation.setPrimaryUserId(userIndex); + relation.setSubUserId(item); + relation.setStatus("1"); + return relation; + }) + .collect(Collectors.toList()); + + if (!batchRecords.isEmpty()) { + return this.saveBatch(batchRecords); + } + } + return true; + } + } diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java index a69c17b..8790f95 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsEquipmentDeliveryServiceImpl.java @@ -15,6 +15,7 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.client.naming.utils.CollectionUtils; +import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -25,14 +26,15 @@ import com.njcn.access.api.AskDeviceDataFeignClient; import com.njcn.access.utils.MqttUtil; import com.njcn.common.pojo.dto.DeviceLogDTO; import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.csdevice.api.CsLedgerFeignClient; import com.njcn.csdevice.api.CsLogsFeignClient; -import com.njcn.csdevice.api.EngineeringFeignClient; import com.njcn.csdevice.constant.DataParam; import com.njcn.csdevice.enums.AlgorithmResponseEnum; import com.njcn.csdevice.mapper.CsEquipmentDeliveryMapper; import com.njcn.csdevice.mapper.CsLedgerMapper; import com.njcn.csdevice.mapper.CsSoftInfoMapper; import com.njcn.csdevice.mapper.CsTerminalLogsMapper; +import com.njcn.csdevice.pojo.dto.DevDetailDTO; import com.njcn.csdevice.pojo.dto.PqsCommunicateDto; import com.njcn.csdevice.pojo.param.*; import com.njcn.csdevice.pojo.po.*; @@ -122,10 +124,10 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl csLedgerQueryWrapper = new QueryWrapper<>(); /** @@ -829,11 +831,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl devDetailList = csLedgerFeignClient.getDevInfoByEngineerIds(Collections.singletonList(param.getEngineeringId())).getData(); + if (!CollectionUtils.isEmpty(devDetailList)) { + List devIds = devDetailList.stream().map(DevDetailDTO::getEquipmentId).collect(Collectors.toList()); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.in(CsDeviceUserPO::getDeviceId, devIds); + List csDeviceUserPOList = csDeviceUserPOService.list(wrapper); + if (!CollectionUtils.isEmpty(csDeviceUserPOList)) { + List userIds = csDeviceUserPOList.stream().map(CsDeviceUserPO::getSubUserId).distinct().collect(Collectors.toList()); + UserDevParam param1 = new UserDevParam(); + param1.setUserId(csEquipmentDeliveryPo.getId()); + param1.setList(userIds); + addUser = csDeviceUserPOService.addRelation(param1); + } + } else { + UserDevParam param1 = new UserDevParam(); + param1.setUserId(csEquipmentDeliveryPo.getId()); + param1.setList(null); + addUser = csDeviceUserPOService.addRelation(param1); + } if (result && ObjectUtil.isNotNull(relation) && addLedger > 0 && addUser) { refreshDeviceDataCache(); @@ -889,7 +906,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl lambdaQueryWrapper = new LambdaQueryWrapper<>(); @@ -915,6 +932,10 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl csDeviceUserPOLambdaQueryWrapper = new LambdaQueryWrapper<>(); + csDeviceUserPOLambdaQueryWrapper.eq(CsDeviceUserPO::getDeviceId, id); + csDeviceUserPOService.remove(csDeviceUserPOLambdaQueryWrapper); //新增操作日志 CsTerminalLogs csTerminalLogs = new CsTerminalLogs(); csTerminalLogs.setDeviceId(id); diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsLedgerServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsLedgerServiceImpl.java index 788edd1..3f4fe27 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsLedgerServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsLedgerServiceImpl.java @@ -71,7 +71,6 @@ public class CsLedgerServiceImpl extends ServiceImpl i private final UserFeignClient userFeignClient; private final ICsUserPinsService csUserPinsService; private final CsCommTerminalFeignClient csCommTerminalFeignClient; - private final CsMarketDataFeignClient csMarketDataFeignClient; @Override @@ -291,22 +290,24 @@ public class CsLedgerServiceImpl extends ServiceImpl i tree.addAll(new ArrayList<>(engineeringMap.values())); - String id = IdUtil.simpleUUID(); - CsLedgerVO portable1 = new CsLedgerVO(); - portable1.setLevel(0); - portable1.setName("便携式工程"); - portable1.setPid("0"); - portable1.setId(id); + if (CollUtil.isNotEmpty(portables)) { + String id = IdUtil.simpleUUID(); + CsLedgerVO portable1 = new CsLedgerVO(); + portable1.setLevel(0); + portable1.setName("便携式工程"); + portable1.setPid("0"); + portable1.setId(id); - CsLedgerVO portable2 = new CsLedgerVO(); - portable2.setLevel(1); - portable2.setName("便携式项目"); - portable2.setPid(id); - portable2.setId(IdUtil.simpleUUID()); - portable2.setChildren(portables); + CsLedgerVO portable2 = new CsLedgerVO(); + portable2.setLevel(1); + portable2.setName("便携式项目"); + portable2.setPid(id); + portable2.setId(IdUtil.simpleUUID()); + portable2.setChildren(portables); - portable1.setChildren(Collections.singletonList(portable2)); - tree.add(portable1); + portable1.setChildren(Collections.singletonList(portable2)); + tree.add(portable1); + } if (CollectionUtil.isNotEmpty(list)) { csUserPinsService.channelTree(list, tree, 4); @@ -703,24 +704,26 @@ public class CsLedgerServiceImpl extends ServiceImpl i tree.addAll(new ArrayList<>(engineeringMap.values())); - String id = IdUtil.simpleUUID(); - CsLedgerVO portable1 = new CsLedgerVO(); - portable1.setLevel(0); - portable1.setName("便携式工程"); - portable1.setPid("0"); - portable1.setId(id); + if (CollUtil.isNotEmpty(portables)) { + String id = IdUtil.simpleUUID(); + CsLedgerVO portable1 = new CsLedgerVO(); + portable1.setLevel(0); + portable1.setName("便携式工程"); + portable1.setPid("0"); + portable1.setId(id); - CsLedgerVO portable2 = new CsLedgerVO(); - portable2.setLevel(1); - portable2.setName("便携式项目"); - portable2.setPid(id); - portable2.setId(IdUtil.simpleUUID()); - portable2.setChildren(portables); + CsLedgerVO portable2 = new CsLedgerVO(); + portable2.setLevel(1); + portable2.setName("便携式项目"); + portable2.setPid(id); + portable2.setId(IdUtil.simpleUUID()); + portable2.setChildren(portables); - List portable2List = new ArrayList<>(); - portable2List.add(portable2); - portable1.setChildren(portable2List); - tree.add(portable1); + List portable2List = new ArrayList<>(); + portable2List.add(portable2); + portable1.setChildren(portable2List); + tree.add(portable1); + } if (CollectionUtil.isNotEmpty(list)) { csUserPinsService.channelTree(list, tree, 4); diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/RoleEngineerDevServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/RoleEngineerDevServiceImpl.java index 101a46f..6c3c646 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/RoleEngineerDevServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/RoleEngineerDevServiceImpl.java @@ -47,7 +47,24 @@ public class RoleEngineerDevServiceImpl implements RoleEngineerDevService { QueryWrapper csLedgerQueryWrapper = new QueryWrapper<>(); List collect = new ArrayList<>(); - if(Objects.equals(role,AppRoleEnum.APP_VIP_USER.getCode()) || Objects.equals(role,AppRoleEnum.REGULAR_USER_8000.getCode())){ + if ( Objects.equals(role,AppRoleEnum.MARKET_USER.getCode())|| + Objects.equals(role, AppRoleEnum.ENGINEERING_USER.getCode())) { + QueryWrapper csMarketDataQueryWrapper = new QueryWrapper<>(); + csMarketDataQueryWrapper.eq("user_id", userIndex); + List csMarketData = csMarketDataMapper.selectList(csMarketDataQueryWrapper); + collect = csMarketData.stream().map(CsMarketData::getEngineerId).collect(Collectors.toList()); + + } else if (Objects.equals(role,AppRoleEnum.TOURIST.getCode())) { + //todo查询配置的游客工程 + List csTouristDataPOS = csTouristDataPOMapper.selectList(null); + collect = csTouristDataPOS.stream().map(CsTouristDataPO::getEnginerId).distinct().collect(Collectors.toList()); + + } + // ||Objects.equals(role,"bxs_user") + else if(Objects.equals(role,AppRoleEnum.ROOT.getCode()) || Objects.equals(role,AppRoleEnum.OPERATION_MANAGER.getCode())){ + List csEngineeringPOS = csEngineeringMapper.selectList(null); + collect =csEngineeringPOS.stream().filter(temp->Objects.equals(temp.getStatus(),"1")).map(CsEngineeringPO::getId).collect(Collectors.toList()); + } else { csDeviceUserPOQueryWrapper.clear(); csEngineeringUserPOQueryWrapper.clear(); csLedgerQueryWrapper.clear(); @@ -79,24 +96,6 @@ public class RoleEngineerDevServiceImpl implements RoleEngineerDevService { collect = collect.stream().distinct().collect(Collectors.toList()); } return collect; - - } else if ( Objects.equals(role,AppRoleEnum.MARKET_USER.getCode())|| - Objects.equals(role, AppRoleEnum.ENGINEERING_USER.getCode())) { - QueryWrapper csMarketDataQueryWrapper = new QueryWrapper<>(); - csMarketDataQueryWrapper.eq("user_id", userIndex); - List csMarketData = csMarketDataMapper.selectList(csMarketDataQueryWrapper); - collect = csMarketData.stream().map(CsMarketData::getEngineerId).collect(Collectors.toList()); - - } else if (Objects.equals(role,AppRoleEnum.TOURIST.getCode())) { - //todo查询配置的游客工程 - List csTouristDataPOS = csTouristDataPOMapper.selectList(null); - collect = csTouristDataPOS.stream().map(CsTouristDataPO::getEnginerId).distinct().collect(Collectors.toList()); - - } - // ||Objects.equals(role,"bxs_user") - else if(Objects.equals(role,AppRoleEnum.ROOT.getCode()) || Objects.equals(role,AppRoleEnum.OPERATION_MANAGER.getCode()) || Objects.equals(role,AppRoleEnum.REGULAR_USER.getCode()) ){ - List csEngineeringPOS = csEngineeringMapper.selectList(null); - collect =csEngineeringPOS.stream().filter(temp->Objects.equals(temp.getStatus(),"1")).map(CsEngineeringPO::getId).collect(Collectors.toList()); } return collect; @@ -115,37 +114,11 @@ public class RoleEngineerDevServiceImpl implements RoleEngineerDevService { QueryWrapper csLedgerQueryWrapper = new QueryWrapper<>(); List collect = new ArrayList<>(); - if( - Objects.equals(role,AppRoleEnum.APP_VIP_USER.getCode()) || Objects.equals(role,AppRoleEnum.REGULAR_USER_8000.getCode()) || Objects.equals(role,"bxs_user")){ - csDeviceUserPOQueryWrapper.clear(); - csDeviceUserPOQueryWrapper.eq("status","1").and(wq -> { - wq.eq("primary_user_id", userIndex) - .or() - .eq("sub_user_id",userIndex); - }); - List csDeviceUserPOS = csDeviceUserPOMapper.selectList(csDeviceUserPOQueryWrapper); - if(CollectionUtils.isEmpty(csDeviceUserPOS)){ - return new ArrayList<>(); - } - List collect1 = csDeviceUserPOS.stream().map(CsDeviceUserPO::getDeviceId).distinct().collect(Collectors.toList()); - return collect1; - - } //fix 新需求 工程用户可以看到关注工程的设备和对应的主用户和子用户的设备 //note 这边工程用户不查询主设备,只看关注的工程,做下调整,不然会出现工程用户未关注任何工程,但是有一台主设备,导致界面有数据 - else if (Objects.equals(role, AppRoleEnum.ENGINEERING_USER.getCode())) { + if (Objects.equals(role, AppRoleEnum.ENGINEERING_USER.getCode())) { List sumDevId = new ArrayList<>(); csDeviceUserPOQueryWrapper.clear(); -// csDeviceUserPOQueryWrapper.eq("status","1").and(wq -> { -// wq.eq("primary_user_id", userIndex) -// .or() -// .eq("sub_user_id",userIndex); -// }); -// List csDeviceUserPOS = csDeviceUserPOMapper.selectList(csDeviceUserPOQueryWrapper); -// if(!CollectionUtils.isEmpty(csDeviceUserPOS)){ -// sumDevId = csDeviceUserPOS.stream().map(CsDeviceUserPO::getDeviceId).distinct().collect(Collectors.toList()); -// } - QueryWrapper csMarketDataQueryWrapper = new QueryWrapper<>(); csMarketDataQueryWrapper.eq("user_id", userIndex); List csMarketData = csMarketDataMapper.selectList(csMarketDataQueryWrapper); @@ -198,15 +171,25 @@ public class RoleEngineerDevServiceImpl implements RoleEngineerDevService { collect = csTouristDataPOS.stream().map(CsTouristDataPO::getDeviceId).distinct().collect(Collectors.toList()); } - // ||Objects.equals(role,"bxs_user") - else if(Objects.equals(role,AppRoleEnum.ROOT.getCode())||Objects.equals(role,AppRoleEnum.OPERATION_MANAGER.getCode()) || Objects.equals(role,AppRoleEnum.REGULAR_USER.getCode())){ + else if(Objects.equals(role,AppRoleEnum.ROOT.getCode())||Objects.equals(role,AppRoleEnum.OPERATION_MANAGER.getCode())){ csLedgerQueryWrapper.clear(); csLedgerQueryWrapper.eq("level",2).eq("state",1); List csLedgers = csLedgerMapper.selectList(csLedgerQueryWrapper); collect = csLedgers.stream().map(CsLedger::getId).distinct().collect(Collectors.toList()); + } else { + csDeviceUserPOQueryWrapper.clear(); + csDeviceUserPOQueryWrapper.eq("status","1").and(wq -> { + wq.eq("primary_user_id", userIndex) + .or() + .eq("sub_user_id",userIndex); + }); + List csDeviceUserPOS = csDeviceUserPOMapper.selectList(csDeviceUserPOQueryWrapper); + if(CollectionUtils.isEmpty(csDeviceUserPOS)){ + return new ArrayList<>(); + } + List collect1 = csDeviceUserPOS.stream().map(CsDeviceUserPO::getDeviceId).distinct().collect(Collectors.toList()); + return collect1; } - - return collect; }