| | |
| | | import com.doumee.dao.business.dto.*; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.service.business.ConditionerBizService; |
| | | import com.doumee.service.business.YwCustomerDeviceAutoBindService; |
| | | import com.doumee.service.business.YwCustomerRechargeBizService; |
| | | import com.doumee.service.business.YwElectricalBizService; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | |
| | | @Autowired |
| | | private YwElectricalMapper ywElectricalMapper; |
| | | @Autowired |
| | | private YwElectricalRoomMapper ywElectricalRoomMapper; |
| | | @Autowired |
| | | private YwRoomMapper ywRoomMapper; |
| | | @Autowired |
| | | private YwConditionerMapper ywConditionerMapper; |
| | | @Autowired |
| | | private YwElectricalChargeMapper ywElectricalChargeMapper; |
| | |
| | | private YwElectricalBizService ywElectricalBizService; |
| | | @Autowired |
| | | private ConditionerBizService conditionerBizService; |
| | | @Autowired |
| | | private YwCustomerDeviceAutoBindService ywCustomerDeviceAutoBindService; |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | | |
| | | @Override |
| | | public PageData<YwCustomerRechargeMerchantVO> findMerchantPage(PageWrap<YwCustomerRechargeQueryDTO> pageWrap) { |
| | |
| | | |
| | | Map<Integer, YwCustomerGs> gsMap = loadGsMap(customerIds); |
| | | |
| | | List<YwCustomerElectrical> relE = loadCustomerElectricalRels(customerIds); |
| | | Map<Integer, List<Integer>> customerElectricalIds = relE.stream() |
| | | .collect(Collectors.groupingBy(YwCustomerElectrical::getCustomerId, |
| | | Collectors.mapping(YwCustomerElectrical::getElectricalId, Collectors.toList()))); |
| | | Map<Integer, List<Integer>> customerElectricalIds = ywCustomerDeviceAutoBindService |
| | | .batchListElectricalIdsByActiveContracts(customerIds); |
| | | Map<Integer, List<Integer>> customerConditionerIds = ywCustomerDeviceAutoBindService |
| | | .batchListConditionerIdsByActiveContracts(customerIds); |
| | | |
| | | List<YwCustomerConditioner> relC = loadCustomerConditionerRels(customerIds); |
| | | Map<Integer, List<Integer>> customerConditionerIds = relC.stream() |
| | | .collect(Collectors.groupingBy(YwCustomerConditioner::getCustomerId, |
| | | Collectors.mapping(YwCustomerConditioner::getConditionerId, Collectors.toList()))); |
| | | |
| | | Set<Integer> allElectricalIds = relE.stream().map(YwCustomerElectrical::getElectricalId).collect(Collectors.toSet()); |
| | | Set<Integer> allElectricalIds = customerElectricalIds.values().stream() |
| | | .flatMap(List::stream).collect(Collectors.toSet()); |
| | | Map<Integer, YwElectrical> electricalMap = loadElectricalMap(allElectricalIds); |
| | | |
| | | Set<Integer> allConditionerIds = relC.stream().map(YwCustomerConditioner::getConditionerId).collect(Collectors.toSet()); |
| | | Set<Integer> allConditionerIds = customerConditionerIds.values().stream() |
| | | .flatMap(List::stream).collect(Collectors.toSet()); |
| | | Map<Integer, YwConditioner> conditionerMap = loadConditionerMap(allConditionerIds); |
| | | |
| | | List<YwCustomerRechargeMerchantVO> list = new ArrayList<>(); |
| | |
| | | } |
| | | } |
| | | |
| | | private List<YwCustomerElectrical> loadCustomerElectricalRels(List<Integer> customerIds) { |
| | | if (CollectionUtils.isEmpty(customerIds)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | try { |
| | | return ywCustomerElectricalMapper.selectList(new QueryWrapper<YwCustomerElectrical>().lambda() |
| | | .select(YwCustomerElectrical::getCustomerId, YwCustomerElectrical::getElectricalId) |
| | | .eq(YwCustomerElectrical::getIsdeleted, Constants.ZERO) |
| | | .in(YwCustomerElectrical::getCustomerId, customerIds)); |
| | | } catch (Exception e) { |
| | | log.warn("load yw_customer_electrical failed, skip electrical stats: {}", e.getMessage()); |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | |
| | | private List<YwCustomerConditioner> loadCustomerConditionerRels(List<Integer> customerIds) { |
| | | if (CollectionUtils.isEmpty(customerIds)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | try { |
| | | return ywCustomerConditionerMapper.selectList(new QueryWrapper<YwCustomerConditioner>().lambda() |
| | | .select(YwCustomerConditioner::getCustomerId, YwCustomerConditioner::getConditionerId) |
| | | .eq(YwCustomerConditioner::getIsdeleted, Constants.ZERO) |
| | | .in(YwCustomerConditioner::getCustomerId, customerIds)); |
| | | } catch (Exception e) { |
| | | log.warn("load yw_customer_conditioner failed, skip conditioner stats: {}", e.getMessage()); |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | |
| | | private Map<Integer, YwElectrical> loadElectricalMap(Set<Integer> electricalIds) { |
| | | if (CollectionUtils.isEmpty(electricalIds)) { |
| | | return Collections.emptyMap(); |
| | |
| | | @Override |
| | | public YwCustomerRechargeDetailVO getDetail(Integer customerId) { |
| | | YwCustomer customer = requireCustomer(customerId); |
| | | ywCustomerDeviceAutoBindService.refreshCustomerDevices(customerId, systemUser()); |
| | | YwCustomerRechargeDetailVO vo = new YwCustomerRechargeDetailVO(); |
| | | vo.setCustomerId(customer.getId()); |
| | | vo.setCustomerName(customer.getName()); |
| | |
| | | @Override |
| | | public PageData<YwElectrical> listCustomerElectrical(PageWrap<YwElectrical> pageWrap, Integer customerId) { |
| | | requireCustomer(customerId); |
| | | ywCustomerDeviceAutoBindService.refreshCustomerDevices(customerId, systemUser()); |
| | | List<Integer> ids = listBoundElectricalIds(customerId); |
| | | if (ids.isEmpty()) { |
| | | return emptyPage(pageWrap); |
| | |
| | | @Override |
| | | public PageData<YwConditioner> listCustomerConditioner(PageWrap<YwConditioner> pageWrap, Integer customerId) { |
| | | requireCustomer(customerId); |
| | | ywCustomerDeviceAutoBindService.refreshCustomerDevices(customerId, systemUser()); |
| | | List<YwConditioner> list = loadCustomerConditionerList(customerId); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return emptyPage(pageWrap); |
| | |
| | | charge.setStatusTime(new Date()); |
| | | charge.setStatusInfo("充值中"); |
| | | charge.setDeviceInfo("GS-" + gs.getPlatformGsId() + " " + customer.getName()); |
| | | applyRechargeOperator(charge, user); |
| | | return charge; |
| | | } |
| | | |
| | | private void applyRechargeOperator(YwElectricalCharge charge, LoginUserInfo user) { |
| | | if (charge == null || user == null) { |
| | | return; |
| | | } |
| | | if (user.getMemberId() != null) { |
| | | charge.setMemberId(user.getMemberId()); |
| | | } |
| | | String operatorName = resolveRechargeUserName(user); |
| | | if (StringUtils.isNotBlank(operatorName)) { |
| | | charge.setRechargeUserName(operatorName); |
| | | } |
| | | } |
| | | |
| | | private String resolveRechargeUserName(LoginUserInfo user) { |
| | | if (user == null) { |
| | | return null; |
| | | } |
| | | if (StringUtils.isNotBlank(user.getMemberName())) { |
| | | return user.getMemberName(); |
| | | } |
| | | if (Constants.equalsInteger(user.getH5UserType(), LoginUserInfo.H5_USER_CUSTOMER) |
| | | && StringUtils.isNotBlank(user.getDisplayName())) { |
| | | int idx = user.getDisplayName().lastIndexOf('-'); |
| | | if (idx >= 0 && idx < user.getDisplayName().length() - 1) { |
| | | return user.getDisplayName().substring(idx + 1).trim(); |
| | | } |
| | | } |
| | | return StringUtils.trimToNull(user.getRealname()); |
| | | } |
| | | |
| | | private void fillRecordText(YwCustomerRechargeRecordVO vo) { |
| | |
| | | vo.setDeviceInfo(StringUtils.defaultString(vo.getAddress()) + " " + StringUtils.defaultString(vo.getName())); |
| | | } |
| | | } |
| | | vo.setTypeText(Objects.equals(vo.getType(), Constants.ONE) ? "空调" : "电表"); |
| | | vo.setTypeText(Objects.equals(vo.getType(), Constants.ONE) ? "空调充值" : "电表充值"); |
| | | if (StringUtils.isBlank(vo.getRechargeUserName()) && vo.getMemberId() != null) { |
| | | Member member = memberMapper.selectById(vo.getMemberId()); |
| | | if (member != null && StringUtils.isNotBlank(member.getName())) { |
| | | vo.setRechargeUserName(member.getName()); |
| | | } |
| | | } |
| | | if (Objects.equals(vo.getStatus(), Constants.ZERO)) { |
| | | vo.setStatusText("充值中"); |
| | | } else if (Objects.equals(vo.getStatus(), Constants.ONE)) { |
| | |
| | | } |
| | | |
| | | private void assertElectricalBound(Integer customerId, Integer electricalId) { |
| | | Long cnt = ywCustomerElectricalMapper.selectCount(new QueryWrapper<YwCustomerElectrical>().lambda() |
| | | .eq(YwCustomerElectrical::getCustomerId, customerId) |
| | | .eq(YwCustomerElectrical::getElectricalId, electricalId) |
| | | .eq(YwCustomerElectrical::getIsdeleted, Constants.ZERO)); |
| | | if (cnt == null || cnt == 0) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "电表未关联该商户"); |
| | | List<Integer> boundIds = ywCustomerDeviceAutoBindService.listElectricalIdsByActiveContracts(customerId); |
| | | if (!boundIds.contains(electricalId)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "电表未关联该商户有效合同房源"); |
| | | } |
| | | } |
| | | |
| | | private List<Integer> listBoundElectricalIds(Integer customerId) { |
| | | return ywCustomerElectricalMapper.selectList(new QueryWrapper<YwCustomerElectrical>().lambda() |
| | | .eq(YwCustomerElectrical::getCustomerId, customerId) |
| | | .eq(YwCustomerElectrical::getIsdeleted, Constants.ZERO)) |
| | | .stream().map(YwCustomerElectrical::getElectricalId).collect(Collectors.toList()); |
| | | return ywCustomerDeviceAutoBindService.listElectricalIdsByActiveContracts(customerId); |
| | | } |
| | | |
| | | private Set<Integer> listAllBoundElectricalIds() { |
| | |
| | | } |
| | | |
| | | private List<YwConditioner> loadCustomerConditionerList(Integer customerId) { |
| | | List<YwCustomerConditioner> rels = ywCustomerConditionerMapper.selectList(new QueryWrapper<YwCustomerConditioner>().lambda() |
| | | .eq(YwCustomerConditioner::getCustomerId, customerId) |
| | | .eq(YwCustomerConditioner::getIsdeleted, Constants.ZERO)); |
| | | if (rels.isEmpty()) { |
| | | List<Integer> conditionerIds = ywCustomerDeviceAutoBindService.listConditionerIdsByActiveContracts(customerId); |
| | | if (conditionerIds.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | Map<Integer, Integer> ratioMap = rels.stream() |
| | | Map<Integer, Integer> ratioMap = ywCustomerConditionerMapper.selectList(new QueryWrapper<YwCustomerConditioner>().lambda() |
| | | .eq(YwCustomerConditioner::getCustomerId, customerId) |
| | | .eq(YwCustomerConditioner::getIsdeleted, Constants.ZERO)) |
| | | .stream() |
| | | .collect(Collectors.toMap(YwCustomerConditioner::getConditionerId, YwCustomerConditioner::getDevRatio, (a, b) -> a)); |
| | | List<YwConditioner> list = ywConditionerMapper.selectBatchIds(ratioMap.keySet()); |
| | | List<YwConditioner> list = ywConditionerMapper.selectBatchIds(conditionerIds); |
| | | list = list.stream().filter(c -> !Objects.equals(c.getIsdeleted(), Constants.ONE)).collect(Collectors.toList()); |
| | | enrichConditionerRoomNames(list, customerId); |
| | | for (YwConditioner c : list) { |
| | | c.setDevRatio(ratioMap.get(c.getId())); |
| | | c.setDevRatio(ratioMap.getOrDefault(c.getId(), 100)); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | private void enrichConditionerRoomNames(List<YwConditioner> list, Integer customerId) { |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return; |
| | | } |
| | | List<Integer> contractRoomIds = ywCustomerDeviceAutoBindService.listActiveContractRoomIds(customerId); |
| | | Map<Integer, Integer> conditionerRoomMap = new HashMap<>(); |
| | | if (!CollectionUtils.isEmpty(contractRoomIds)) { |
| | | ywElectricalRoomMapper.selectList(new QueryWrapper<YwElectricalRoom>().lambda() |
| | | .in(YwElectricalRoom::getRoomId, contractRoomIds) |
| | | .eq(YwElectricalRoom::getType, Constants.ONE) |
| | | .eq(YwElectricalRoom::getIsdeleted, Constants.ZERO)) |
| | | .forEach(rel -> { |
| | | if (rel.getObjId() != null && rel.getRoomId() != null) { |
| | | conditionerRoomMap.putIfAbsent(rel.getObjId(), rel.getRoomId()); |
| | | } |
| | | }); |
| | | } |
| | | Set<Integer> roomIds = new HashSet<>(contractRoomIds); |
| | | for (YwConditioner conditioner : list) { |
| | | Integer roomId = conditionerRoomMap.getOrDefault(conditioner.getId(), conditioner.getRoomId()); |
| | | if (roomId != null) { |
| | | roomIds.add(roomId); |
| | | } |
| | | } |
| | | if (roomIds.isEmpty()) { |
| | | return; |
| | | } |
| | | Map<Integer, YwRoom> roomMap = ywRoomMapper.selectBatchIds(roomIds).stream() |
| | | .filter(r -> !Objects.equals(r.getIsdeleted(), Constants.ONE)) |
| | | .collect(Collectors.toMap(YwRoom::getId, r -> r, (a, b) -> a)); |
| | | for (YwConditioner conditioner : list) { |
| | | if (StringUtils.isNotBlank(conditioner.getRoomName())) { |
| | | continue; |
| | | } |
| | | Integer roomId = conditionerRoomMap.getOrDefault(conditioner.getId(), conditioner.getRoomId()); |
| | | YwRoom room = roomId != null ? roomMap.get(roomId) : null; |
| | | if (room != null) { |
| | | conditioner.setRoomName(StringUtils.defaultString(room.getRoomNum())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private LoginUserInfo systemUser() { |
| | | LoginUserInfo user = new LoginUserInfo(); |
| | | user.setId(1); |
| | | user.setRealname("system"); |
| | | return user; |
| | | } |
| | | |
| | | private PageData<YwElectrical> pageElectricalByIds(PageWrap<YwElectrical> pageWrap, List<Integer> ids) { |
| | | IPage<YwElectrical> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | YwElectrical model = pageWrap.getModel(); |