| | |
| | | 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.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; |
| | |
| | | |
| | | @Autowired |
| | | private YwConditionerMapper ywConditionerMapper; |
| | | @Autowired |
| | | private YwElectricalRoomMapper ywElectricalRoomMapper; |
| | | @Autowired |
| | | private YwConditionerGatewayMapper gatewayMapper; |
| | | @Autowired |
| | |
| | | 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); |
| | | } |
| | | } |