diff --git a/nxhs-common/src/main/java/cc/yunxi/common/utils/CommonUtil.java b/nxhs-common/src/main/java/cc/yunxi/common/utils/CommonUtil.java index 933aac6..07a37b2 100644 --- a/nxhs-common/src/main/java/cc/yunxi/common/utils/CommonUtil.java +++ b/nxhs-common/src/main/java/cc/yunxi/common/utils/CommonUtil.java @@ -89,7 +89,8 @@ public class CommonUtil { Class clazz = obj.getClass(); Field field = ReflectUtil.getField(clazz, fieldName); if (field != null) { - field.set(clazz, value); + field.setAccessible(true); + field.set(obj, value); } } @@ -100,7 +101,8 @@ public class CommonUtil { if (field == null) { return null; } - return field.get(clazz); + field.setAccessible(true); + return field.get(obj); } diff --git a/nxhs-service/src/main/java/cc/yunxi/controller/IndexController.java b/nxhs-service/src/main/java/cc/yunxi/controller/IndexController.java index 3cfcb01..06722e1 100644 --- a/nxhs-service/src/main/java/cc/yunxi/controller/IndexController.java +++ b/nxhs-service/src/main/java/cc/yunxi/controller/IndexController.java @@ -42,7 +42,7 @@ public class IndexController { @ApiOperation("废品类目列表") @GetMapping("/products") public CommonResult> queryProductList() { - List productList = priceProductService.queryProductList(Collections.emptyList()); + List productList = priceProductService.queryProductList(); List productSimpleVOList = BeanUtils.copyList(productList, ProductSimpleVO.class); return CommonResult.success(productSimpleVOList); } diff --git a/nxhs-service/src/main/java/cc/yunxi/controller/RecycleOrderController.java b/nxhs-service/src/main/java/cc/yunxi/controller/RecycleOrderController.java index 41cdd6e..5ffc6aa 100644 --- a/nxhs-service/src/main/java/cc/yunxi/controller/RecycleOrderController.java +++ b/nxhs-service/src/main/java/cc/yunxi/controller/RecycleOrderController.java @@ -244,7 +244,7 @@ public class RecycleOrderController { LocationDTO location = (LocationDTO) CommonUtil.obtainField(orderRespVO, "location"); if (location != null) { BigDecimal distance = CommonUtil.getDistance(longitude, latitude, location.getLongitude(), location.getLatitude()); - CommonUtil.assignField(orderRespVO, "distance2", distance); + CommonUtil.assignField(orderRespVO, "distance2", distance.doubleValue()); } }); } @@ -262,17 +262,19 @@ public class RecycleOrderController { List detailResponseVOList = BeanUtils.copyList(orderProducts, RecycleOrderDetailResponseVO.class); // 查询废品信息 Set productIds = detailResponseVOList.stream().map(RecycleOrderDetailResponseVO::getProductId).collect(Collectors.toSet()); - List productList = priceProductService.queryProductList(productIds); - Map productMap = productList.stream().collect(Collectors.toMap(Product::getId, p -> p, (k1, k2) -> k1)); - for (RecycleOrderDetailResponseVO detailVO : detailResponseVOList) { - Product product = productMap.get(detailVO.getProductId()); - detailVO.setProduct(BeanUtils.copyBean(product, ProductSimpleVO.class)); + List productList = priceProductService.getProductListByIds(productIds); + if (CollUtils.isNotEmpty(productList)) { + Map productMap = productList.stream().collect(Collectors.toMap(Product::getId, p -> p, (k1, k2) -> k1)); + for (RecycleOrderDetailResponseVO detailVO : detailResponseVOList) { + Product product = productMap.get(detailVO.getProductId()); + detailVO.setProduct(BeanUtils.copyBean(product, ProductSimpleVO.class)); + } + Map> orderProductsMap = + detailResponseVOList.stream().collect(Collectors.groupingBy(RecycleOrderDetailResponseVO::getRecycleOrderId)); + orderRespVOList.forEach(v -> { + CommonUtil.assignField(v, "orderDetails", orderProductsMap.get(v.getId())); + }); } - Map> orderProductsMap = - detailResponseVOList.stream().collect(Collectors.groupingBy(RecycleOrderDetailResponseVO::getRecycleOrderId)); - orderRespVOList.forEach(v -> { - CommonUtil.assignField(v, "orderDetails", orderProductsMap.get(v.getId())); - }); } @@ -288,14 +290,16 @@ public class RecycleOrderController { return Optional.ofNullable(clientAddressId).orElse(""); }, (k1, k2) -> k1)); Set addressIds = new HashSet<>(CollUtils.removeEmpty(orderAddressMap.values())); - List clientAddresses = clientAddressService.queryAddressList(addressIds); - List addressSimpleVOList = BeanUtils.copyList(clientAddresses, ClientAddressSimpleVO.class); - Map clientAddressMap = addressSimpleVOList.stream().collect( - Collectors.toMap(ClientAddressSimpleVO::getId, v -> v, (k1, k2) -> k1)); - orderRespVOList.forEach(v -> { - String clientAddressId = (String) CommonUtil.obtainField(v, "clientAddressId"); - CommonUtil.assignField(v, "clientAddressId", clientAddressId); - }); + List clientAddresses = clientAddressService.getAddressListByIds(addressIds); + if (CollUtils.isNotEmpty(clientAddresses)) { + List addressSimpleVOList = BeanUtils.copyList(clientAddresses, ClientAddressSimpleVO.class); + Map clientAddressMap = addressSimpleVOList.stream().collect( + Collectors.toMap(ClientAddressSimpleVO::getId, v -> v, (k1, k2) -> k1)); + orderRespVOList.forEach(v -> { + String clientAddressId = (String) CommonUtil.obtainField(v, "clientAddressId"); + CommonUtil.assignField(v, "clientAddressId", clientAddressId); + }); + } } @@ -309,16 +313,18 @@ public class RecycleOrderController { RecycleOrderRespVO::getId, v -> Optional.ofNullable(v.getStaffsId()).orElse(""), (k1, k2) -> k1)); Set recyclerIds = new HashSet<>(CollUtils.removeEmpty(orderRecyclerMap.values())); List recyclerList = recyclerService.getRecyclerByIds(recyclerIds); - List recyclerSimpleVOList = BeanUtils.copyList(recyclerList, RecyclerSimpleVO.class); - Map recyclerMap = recyclerSimpleVOList.stream().collect( - Collectors.toMap(RecyclerSimpleVO::getId, v -> v, (k1, k2) -> k1)); - orderRespVOList.forEach(v -> { - CommonUtil.assignField(v, "recyclerInfo", recyclerMap.get(v.getStaffsId())); - LocalDateTime appointmentTimeStart = (LocalDateTime) CommonUtil.obtainField(v, "appointmentTimeStart"); - if (ObjectUtil.isNotEmpty(appointmentTimeStart)) { - CommonUtil.assignField(v, "estimateArrivalTime", appointmentTimeStart.plusHours(1)); - } - }); + if (ObjectUtil.isNotEmpty(recyclerList)) { + List recyclerSimpleVOList = BeanUtils.copyList(recyclerList, RecyclerSimpleVO.class); + Map recyclerMap = recyclerSimpleVOList.stream().collect( + Collectors.toMap(RecyclerSimpleVO::getId, v -> v, (k1, k2) -> k1)); + orderRespVOList.forEach(v -> { + CommonUtil.assignField(v, "recyclerInfo", recyclerMap.get(v.getStaffsId())); + LocalDateTime appointmentTimeStart = (LocalDateTime) CommonUtil.obtainField(v, "appointmentTimeStart"); + if (ObjectUtil.isNotEmpty(appointmentTimeStart)) { + CommonUtil.assignField(v, "estimateArrivalTime", appointmentTimeStart.plusHours(1)); + } + }); + } } @@ -335,13 +341,15 @@ public class RecycleOrderController { }, (k1, k2) -> k1)); Set housingEstateIds = new HashSet<>(CollUtils.removeEmpty(orderHousingEstateMap.values())); List housingEstateList = housingEstateService.getHousingListByIds(housingEstateIds); - List housingSimpleVOList = BeanUtils.copyList(housingEstateList, HousingEstateSimpleVO.class); - Map housingEstateMap = housingSimpleVOList.stream().collect( - Collectors.toMap(HousingEstateSimpleVO::getId, v -> v, (k1, k2) -> k1)); - orderRespVOList.forEach(v -> { - String housingEstateId = (String) CommonUtil.obtainField(v, "housingEstateId"); - CommonUtil.assignField(v, "housingEstateInfo", housingEstateMap.get(housingEstateId)); - }); + if (CollUtils.isNotEmpty(housingEstateList)) { + List housingSimpleVOList = BeanUtils.copyList(housingEstateList, HousingEstateSimpleVO.class); + Map housingEstateMap = housingSimpleVOList.stream().collect( + Collectors.toMap(HousingEstateSimpleVO::getId, v -> v, (k1, k2) -> k1)); + orderRespVOList.forEach(v -> { + String housingEstateId = (String) CommonUtil.obtainField(v, "housingEstateId"); + CommonUtil.assignField(v, "housingEstateInfo", housingEstateMap.get(housingEstateId)); + }); + } } } diff --git a/nxhs-service/src/main/java/cc/yunxi/service/IClientAddressService.java b/nxhs-service/src/main/java/cc/yunxi/service/IClientAddressService.java index 15ef469..a42cda7 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/IClientAddressService.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/IClientAddressService.java @@ -34,7 +34,7 @@ public interface IClientAddressService extends IService { * @param addressIds * @return List */ - List queryAddressList(Collection addressIds); + List getAddressListByIds(Collection addressIds); diff --git a/nxhs-service/src/main/java/cc/yunxi/service/IPriceProductService.java b/nxhs-service/src/main/java/cc/yunxi/service/IPriceProductService.java index 33c2bb2..e79dd76 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/IPriceProductService.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/IPriceProductService.java @@ -22,7 +22,12 @@ public interface IPriceProductService extends IService { * 获取废品类目 * @return List */ - List queryProductList(Collection productIds); + List queryProductList(); + /** + * 通过id集获取废品类目 + * @return List + */ + List getProductListByIds(Collection productIds); } diff --git a/nxhs-service/src/main/java/cc/yunxi/service/impl/ClientAddressServiceImpl.java b/nxhs-service/src/main/java/cc/yunxi/service/impl/ClientAddressServiceImpl.java index 6020997..8ee5404 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/impl/ClientAddressServiceImpl.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/impl/ClientAddressServiceImpl.java @@ -48,8 +48,11 @@ public class ClientAddressServiceImpl extends ServiceImpl queryAddressList(Collection addressIds) { + public List getAddressListByIds(Collection addressIds) { LambdaQueryWrapperX wrapperX = new LambdaQueryWrapperX<>(); + if (CollUtils.isEmpty(addressIds)) { + return CollUtils.emptyList(); + } wrapperX.in(ClientAddress::getId, addressIds); return list(wrapperX); } diff --git a/nxhs-service/src/main/java/cc/yunxi/service/impl/HousingEstateServiceImpl.java b/nxhs-service/src/main/java/cc/yunxi/service/impl/HousingEstateServiceImpl.java index 82e1759..02f3fb2 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/impl/HousingEstateServiceImpl.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/impl/HousingEstateServiceImpl.java @@ -1,6 +1,7 @@ package cc.yunxi.service.impl; import cc.yunxi.common.exception.BizIllegalException; +import cc.yunxi.common.utils.CollUtils; import cc.yunxi.domain.dto.LocationDTO; import cc.yunxi.domain.po.HousingEstate; import cc.yunxi.domain.po.Recycler; @@ -48,6 +49,9 @@ public class HousingEstateServiceImpl extends ServiceImpl getHousingListByIds(Collection housingIds) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + if (CollUtils.isEmpty(housingIds)) { + return CollUtils.emptyList(); + } wrapper.in(HousingEstate::getId, housingIds); return this.list(wrapper); } diff --git a/nxhs-service/src/main/java/cc/yunxi/service/impl/PriceProductServiceImpl.java b/nxhs-service/src/main/java/cc/yunxi/service/impl/PriceProductServiceImpl.java index aba541d..95b0a99 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/impl/PriceProductServiceImpl.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/impl/PriceProductServiceImpl.java @@ -31,13 +31,20 @@ public class PriceProductServiceImpl extends ServiceImpl queryProductList() { + LambdaQueryWrapperX wrapperX = new LambdaQueryWrapperX<>(); + return productMapper.selectList(wrapperX); + } + @Override - public List queryProductList(Collection productIds) { + public List getProductListByIds(Collection productIds) { LambdaQueryWrapperX wrapperX = new LambdaQueryWrapperX<>(); - if (CollUtils.isNotEmpty(productIds)) { - wrapperX.inIfPresent(Product::getId, productIds); + if (CollUtils.isEmpty(productIds)) { + return CollUtils.emptyList(); } + wrapperX.in(Product::getId, productIds); return productMapper.selectList(wrapperX); } } diff --git a/nxhs-service/src/main/java/cc/yunxi/service/impl/RecyclerServiceImpl.java b/nxhs-service/src/main/java/cc/yunxi/service/impl/RecyclerServiceImpl.java index efff368..9f269ea 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/impl/RecyclerServiceImpl.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/impl/RecyclerServiceImpl.java @@ -5,6 +5,7 @@ import cc.yunxi.common.domain.LambdaUpdateWrapperX; import cc.yunxi.common.exception.BizIllegalException; import cc.yunxi.common.exception.DbException; import cc.yunxi.common.utils.BeanUtils; +import cc.yunxi.common.utils.CollUtils; import cc.yunxi.domain.po.Client; import cc.yunxi.domain.po.ClientAccountDetail; import cc.yunxi.domain.po.ClientAddress; @@ -73,6 +74,9 @@ public class RecyclerServiceImpl extends ServiceImpl i @Override public List getRecyclerByIds(Collection recyclerIds) { LambdaQueryWrapperX wrapperX = new LambdaQueryWrapperX<>(); + if (CollUtils.isEmpty(recyclerIds)) { + return CollUtils.emptyList(); + } wrapperX.in(Recycler::getId, recyclerIds); return list(wrapperX); }