| | |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.dto.YwConditionerEditDTO; |
| | | import com.doumee.dao.business.dto.YwConditionerLockDTO; |
| | | import com.doumee.dao.business.dto.YwConditionerOperateDTO; |
| | | import com.doumee.dao.business.YwConditionerGatewayMapper; |
| | | import com.doumee.dao.business.YwConditionerMapper; |
| | | import com.doumee.dao.business.YwElectricalRoomMapper; |
| | | import com.doumee.dao.business.model.YwConditioner; |
| | | import com.doumee.dao.business.model.YwConditionerActions; |
| | | import com.doumee.dao.business.model.YwConditionerGateway; |
| | | import com.doumee.dao.business.model.YwElectricalRoom; |
| | | import com.doumee.dao.business.model.YwBuilding; |
| | | import com.doumee.dao.business.model.YwFloor; |
| | | import com.doumee.dao.business.model.YwRoom; |
| | | import com.doumee.service.business.ConditionerBizService; |
| | | import com.doumee.service.business.YwConditionerActionsService; |
| | | import com.doumee.service.business.YwConditionerService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 空调设备信息Service实现 |
| | |
| | | |
| | | @Autowired |
| | | private YwConditionerMapper ywConditionerMapper; |
| | | @Autowired |
| | | private YwElectricalRoomMapper ywElectricalRoomMapper; |
| | | @Autowired |
| | | private YwConditionerGatewayMapper gatewayMapper; |
| | | @Autowired |
| | | private ConditionerBizService conditionerBizService; |
| | | @Autowired |
| | | private YwConditionerActionsService ywConditionerActionsService; |
| | | |
| | | @Override |
| | | public Integer create(YwConditioner ywConditioner) { |
| | |
| | | IPage<YwConditioner> iPage = ywConditionerMapper.selectJoinPage(page, YwConditioner.class, queryWrapper); |
| | | return PageData.from(iPage); |
| | | } |
| | | |
| | | @Override |
| | | public PageData<YwConditioner> findCardPage(PageWrap<YwConditioner> pageWrap) { |
| | | IPage<YwConditioner> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | YwConditioner model = pageWrap.getModel() == null ? new YwConditioner() : pageWrap.getModel(); |
| | | MPJLambdaWrapper<YwConditioner> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(YwConditioner.class) |
| | | .eq(YwConditioner::getIsdeleted, Constants.ZERO) |
| | | .isNotNull(YwConditioner::getPlatformDevId) |
| | | .and(StringUtils.isNotBlank(model.getDevKeyword()), w -> w |
| | | .like(YwConditioner::getName, model.getDevKeyword()) |
| | | .or().like(YwConditioner::getCode, model.getDevKeyword()) |
| | | .or().like(YwConditioner::getRoomName, model.getDevKeyword())) |
| | | .eq(StringUtils.isNotBlank(model.getOnlineFilter()), YwConditioner::getOnline, model.getOnlineFilter()) |
| | | .eq(model.getPwrFilter() != null, YwConditioner::getPwr, model.getPwrFilter()) |
| | | .eq(StringUtils.isNotBlank(model.getWgMacFilter()), YwConditioner::getWgMac, model.getWgMacFilter()) |
| | | .orderByAsc(YwConditioner::getWgQid) |
| | | .orderByAsc(YwConditioner::getId); |
| | | PageData<YwConditioner> pageData = PageData.from( |
| | | ywConditionerMapper.selectJoinPage(page, YwConditioner.class, queryWrapper)); |
| | | fillGatewayBzFromGateway(pageData.getRecords()); |
| | | return pageData; |
| | | } |
| | | |
| | | /** |
| | | * 从本地网关镜像表 yw_conditioner_gateway 关联填充备注(优先平台网关ID,其次 MAC) |
| | | */ |
| | | private void fillGatewayBzFromGateway(List<YwConditioner> records) { |
| | | if (CollectionUtils.isEmpty(records)) { |
| | | return; |
| | | } |
| | | List<String> macs = records.stream() |
| | | .map(YwConditioner::getWgMac) |
| | | .filter(StringUtils::isNotBlank) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | List<Integer> platformWgIds = records.stream() |
| | | .map(YwConditioner::getWgId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | if (macs.isEmpty() && platformWgIds.isEmpty()) { |
| | | return; |
| | | } |
| | | QueryWrapper<YwConditionerGateway> gwQuery = new QueryWrapper<>(); |
| | | gwQuery.lambda().eq(YwConditionerGateway::getIsdeleted, Constants.ZERO); |
| | | if (!macs.isEmpty() && !platformWgIds.isEmpty()) { |
| | | gwQuery.lambda().and(w -> w.in(YwConditionerGateway::getWgMac, macs) |
| | | .or().in(YwConditionerGateway::getPlatformWgId, platformWgIds)); |
| | | } else if (!macs.isEmpty()) { |
| | | gwQuery.lambda().in(YwConditionerGateway::getWgMac, macs); |
| | | } else { |
| | | gwQuery.lambda().in(YwConditionerGateway::getPlatformWgId, platformWgIds); |
| | | } |
| | | List<YwConditionerGateway> gateways = gatewayMapper.selectList(gwQuery); |
| | | Map<String, String> bzByMac = new HashMap<>(); |
| | | Map<Integer, String> bzByPlatformWgId = new HashMap<>(); |
| | | for (YwConditionerGateway gw : gateways) { |
| | | if (StringUtils.isNotBlank(gw.getWgBz())) { |
| | | if (StringUtils.isNotBlank(gw.getWgMac())) { |
| | | bzByMac.putIfAbsent(gw.getWgMac().trim(), gw.getWgBz()); |
| | | } |
| | | if (gw.getPlatformWgId() != null) { |
| | | bzByPlatformWgId.putIfAbsent(gw.getPlatformWgId(), gw.getWgBz()); |
| | | } |
| | | } |
| | | } |
| | | for (YwConditioner row : records) { |
| | | String bz = null; |
| | | if (StringUtils.isNotBlank(row.getWgMac())) { |
| | | bz = bzByMac.get(row.getWgMac().trim()); |
| | | } |
| | | if (StringUtils.isBlank(bz) && row.getWgId() != null) { |
| | | bz = bzByPlatformWgId.get(row.getWgId()); |
| | | } |
| | | if (StringUtils.isNotBlank(bz)) { |
| | | row.setWgBz(bz); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public String syncAll() { |
| | | return conditionerBizService.syncAll(); |
| | | } |
| | | |
| | | @Override |
| | | public String syncDevicesAndStatus() { |
| | | return conditionerBizService.syncIndoorUnits(); |
| | | } |
| | | |
| | | @Override |
| | | public String operate(YwConditionerOperateDTO dto, LoginUserInfo user) { |
| | | return conditionerBizService.operate(dto, user); |
| | | } |
| | | |
| | | @Override |
| | | public String lock(YwConditionerLockDTO dto, LoginUserInfo user) { |
| | | return conditionerBizService.lock(dto, user); |
| | | } |
| | | |
| | | @Override |
| | | public PageData<YwConditionerActions> historyPage(PageWrap<YwConditionerActions> pageWrap) { |
| | | return ywConditionerActionsService.findPage(pageWrap); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> gatewayOptions() { |
| | | return conditionerBizService.gatewayOptions(); |
| | | } |
| | | |
| | | @Override |
| | | public PageData<YwConditioner> findDeviceManagePage(PageWrap<YwConditioner> pageWrap) { |
| | | IPage<YwConditioner> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | YwConditioner model = pageWrap.getModel() == null ? new YwConditioner() : pageWrap.getModel(); |
| | | MPJLambdaWrapper<YwConditioner> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(YwConditioner.class) |
| | | .eq(YwConditioner::getIsdeleted, Constants.ZERO) |
| | | .and(StringUtils.isNotBlank(model.getManageKeyword()), w -> w |
| | | .like(YwConditioner::getName, model.getManageKeyword()) |
| | | .or().like(YwConditioner::getCode, model.getManageKeyword()) |
| | | .or().like(YwConditioner::getRoomName, model.getManageKeyword()) |
| | | .or().like(YwConditioner::getWgMac, model.getManageKeyword())) |
| | | .eq(StringUtils.isNotBlank(model.getManageOnlineFilter()), YwConditioner::getOnline, model.getManageOnlineFilter()) |
| | | .eq(StringUtils.isNotBlank(model.getWgMacFilter()), YwConditioner::getWgMac, model.getWgMacFilter()) |
| | | .orderByDesc(YwConditioner::getCreateDate) |
| | | .orderByDesc(YwConditioner::getId); |
| | | PageData<YwConditioner> pageData = PageData.from( |
| | | ywConditionerMapper.selectJoinPage(page, YwConditioner.class, queryWrapper)); |
| | | fillRoomNames(pageData.getRecords()); |
| | | fillGatewayBzFromGateway(pageData.getRecords()); |
| | | return pageData; |
| | | } |
| | | |
| | | @Override |
| | | public YwConditionerEditDTO getManageDetail(Integer id) { |
| | | YwConditioner conditioner = findById(id); |
| | | if (conditioner == null || Objects.equals(conditioner.getIsdeleted(), Constants.ONE)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | YwConditionerEditDTO dto = new YwConditionerEditDTO(); |
| | | BeanUtils.copyProperties(conditioner, dto); |
| | | List<YwElectricalRoom> rooms = ywElectricalRoomMapper.selectList(new QueryWrapper<YwElectricalRoom>().lambda() |
| | | .eq(YwElectricalRoom::getIsdeleted, Constants.ZERO) |
| | | .eq(YwElectricalRoom::getType, Constants.ONE) |
| | | .eq(YwElectricalRoom::getObjId, id)); |
| | | dto.setRoomIds(rooms.stream().map(YwElectricalRoom::getRoomId).filter(Objects::nonNull).collect(Collectors.toList())); |
| | | fillRoomNames(Collections.singletonList(dto)); |
| | | return dto; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateManageDetail(YwConditionerEditDTO dto, LoginUserInfo user) { |
| | | if (dto == null || dto.getId() == null) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | YwConditioner exist = findById(dto.getId()); |
| | | if (exist == null || Objects.equals(exist.getIsdeleted(), Constants.ONE)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | saveRooms(dto.getId(), dto.getRoomIds(), user); |
| | | Integer primaryRoomId = CollectionUtils.isEmpty(dto.getRoomIds()) ? null : dto.getRoomIds().get(0); |
| | | ywConditionerMapper.update(null, new UpdateWrapper<YwConditioner>().lambda() |
| | | .eq(YwConditioner::getId, dto.getId()) |
| | | .set(YwConditioner::getRoomId, primaryRoomId) |
| | | .set(YwConditioner::getRemark, dto.getRemark()) |
| | | .set(YwConditioner::getEditor, user.getId()) |
| | | .set(YwConditioner::getEditDate, new Date())); |
| | | } |
| | | |
| | | private void saveRooms(Integer conditionerId, List<Integer> roomIds, LoginUserInfo user) { |
| | | ywElectricalRoomMapper.update(null, new UpdateWrapper<YwElectricalRoom>().lambda() |
| | | .set(YwElectricalRoom::getIsdeleted, Constants.ONE) |
| | | .set(YwElectricalRoom::getEditDate, new Date()) |
| | | .set(YwElectricalRoom::getEditor, user.getId()) |
| | | .eq(YwElectricalRoom::getObjId, conditionerId) |
| | | .eq(YwElectricalRoom::getType, Constants.ONE)); |
| | | if (CollectionUtils.isEmpty(roomIds)) { |
| | | return; |
| | | } |
| | | int sort = 0; |
| | | for (Integer roomId : roomIds) { |
| | | if (roomId == null) { |
| | | continue; |
| | | } |
| | | YwElectricalRoom rel = new YwElectricalRoom(); |
| | | rel.setCreator(user.getId()); |
| | | rel.setCreateDate(new Date()); |
| | | rel.setEditor(user.getId()); |
| | | rel.setEditDate(new Date()); |
| | | rel.setIsdeleted(Constants.ZERO); |
| | | rel.setType(Constants.ONE); |
| | | rel.setObjId(conditionerId); |
| | | rel.setRoomId(roomId); |
| | | rel.setSortnum(++sort); |
| | | ywElectricalRoomMapper.insert(rel); |
| | | } |
| | | } |
| | | |
| | | private void fillRoomNames(List<? extends YwConditioner> list) { |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return; |
| | | } |
| | | List<Integer> ids = list.stream().map(YwConditioner::getId).filter(Objects::nonNull).collect(Collectors.toList()); |
| | | if (ids.isEmpty()) { |
| | | return; |
| | | } |
| | | MPJLambdaWrapper<YwElectricalRoom> wrapper = new MPJLambdaWrapper<>(); |
| | | wrapper.selectAll(YwElectricalRoom.class) |
| | | .selectAs(YwRoom::getRoomNum, YwElectricalRoom::getRoomName) |
| | | .selectAs(YwBuilding::getName, YwElectricalRoom::getBuildingName) |
| | | .selectAs(YwFloor::getName, YwElectricalRoom::getFloorName) |
| | | .leftJoin(YwRoom.class, YwRoom::getId, YwElectricalRoom::getRoomId) |
| | | .leftJoin(YwFloor.class, YwFloor::getId, YwRoom::getFloor) |
| | | .leftJoin(YwBuilding.class, YwBuilding::getId, YwRoom::getBuildingId) |
| | | .eq(YwElectricalRoom::getIsdeleted, Constants.ZERO) |
| | | .eq(YwElectricalRoom::getType, Constants.ONE) |
| | | .in(YwElectricalRoom::getObjId, ids); |
| | | List<YwElectricalRoom> rooms = ywElectricalRoomMapper.selectJoinList(YwElectricalRoom.class, wrapper); |
| | | Map<Integer, List<YwElectricalRoom>> grouped = rooms.stream() |
| | | .collect(Collectors.groupingBy(YwElectricalRoom::getObjId)); |
| | | for (YwConditioner row : list) { |
| | | List<YwElectricalRoom> rs = grouped.get(row.getId()); |
| | | if (CollectionUtils.isEmpty(rs)) { |
| | | continue; |
| | | } |
| | | row.setRoomNames(rs.stream().map(this::formatRoomPath).filter(StringUtils::isNotBlank) |
| | | .collect(Collectors.joining("、"))); |
| | | } |
| | | } |
| | | |
| | | private String formatRoomPath(YwElectricalRoom room) { |
| | | List<String> parts = new ArrayList<>(); |
| | | if (StringUtils.isNotBlank(room.getBuildingName())) { |
| | | parts.add(room.getBuildingName()); |
| | | } |
| | | if (StringUtils.isNotBlank(room.getFloorName())) { |
| | | parts.add(room.getFloorName()); |
| | | } |
| | | if (StringUtils.isNotBlank(room.getRoomName())) { |
| | | parts.add(room.getRoomName()); |
| | | } |
| | | return String.join("/", parts); |
| | | } |
| | | } |