diff --git a/src/main/java/com/cultural/heritage/controller/book/PhotoCategoryController.java b/src/main/java/com/cultural/heritage/controller/book/PhotoCategoryController.java index a1312a1..e7871f0 100644 --- a/src/main/java/com/cultural/heritage/controller/book/PhotoCategoryController.java +++ b/src/main/java/com/cultural/heritage/controller/book/PhotoCategoryController.java @@ -143,11 +143,11 @@ public class PhotoCategoryController { PhotoCategory photoCategory = photoCategoryService.getById(id); ThrowUtils.throwIf(photoCategory == null, ErrorCode.OPERATION_ERROR, "写真类别不存在"); // 获取写真产品列表 - List photoProductsList = commonService.findByFieldValue("categoryName", photoCategory.getName(), photoProductsService); + List photoProductsList = commonService.findByFieldEqTargetField("categoryName", photoCategory.getName(), photoProductsService); // 获取预约日期表 - List bookingDateList = commonService.findBySourceFieldValues(photoProductsList, bookingDateService, "id", "photoProductId"); + List bookingDateList = commonService.findByFieldInTargetField(photoProductsList, bookingDateService, PhotoProducts::getId, "photoProductId"); // 获取预约时间表 - List bookingTimeList = commonService.findBySourceFieldValues(bookingDateList, bookingTimeService, "id", "bookingDateId"); + List bookingTimeList = commonService.findByFieldInTargetField(bookingDateList, bookingTimeService, BookingDate::getId, "bookingDateId"); // 批量删除预约时间 boolean removeTime = bookingTimeService.removeBatchByIds(bookingTimeList); ThrowUtils.throwIf(!removeTime, ErrorCode.OPERATION_ERROR, "预约时间删除失败"); @@ -195,9 +195,9 @@ public class PhotoCategoryController { @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse> listCategoryByUsers() { // 获取已上架的写真产品列表 - List photoProductsList = commonService.findByFieldValue("isShelves", 1, photoProductsService); + List photoProductsList = commonService.findByFieldEqTargetField("isShelves", 1, photoProductsService); // 获取类别写真产品类别列表 - List photoCategoryList = commonService.findBySourceFieldValues(photoProductsList, photoCategoryService, "categoryName", "name"); + List photoCategoryList = commonService.findByFieldInTargetField(photoProductsList, photoCategoryService, PhotoProducts::getCategoryName, "name"); // 获取写真产品类别VO列表 List photoCategoryVOList = commonService.convertList(photoCategoryList, PhotoCategoryVO.class); @@ -224,7 +224,7 @@ public class PhotoCategoryController { Map fieldConditions = new HashMap<>(); fieldConditions.put("categoryName", categoryName); fieldConditions.put("isShelves", 1); - List photoProductsList = commonService.findByMultipleFieldValues(fieldConditions, photoProductsService); + List photoProductsList = commonService.findByFieldEqTargetFields(fieldConditions, photoProductsService); // 获取写真产品VO列表 List photoProductsVOS = commonService.convertList(photoProductsList, PhotoProductsVO.class); diff --git a/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java b/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java index faf1d02..de719d5 100644 --- a/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java +++ b/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java @@ -167,9 +167,9 @@ public class PhotoProductsController { } Long id = commonRequest.getId(); // 获取预约日期列表 - List bookingDateList = commonService.findByFieldValue("photoProductId", id, bookingDateService); + List bookingDateList = commonService.findByFieldEqTargetField("photoProductId", id, bookingDateService); // 获取预约时间列表 - List bookingTimeList = commonService.findBySourceFieldValues(bookingDateList, bookingTimeService, "id", "bookingDateId"); + List bookingTimeList = commonService.findByFieldInTargetField(bookingDateList, bookingTimeService, BookingDate::getId, "bookingDateId"); // 删除写真产品下的预约时间 boolean remove = bookingTimeService.removeBatchByIds(bookingTimeList); ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "预约时间批量删除失败"); @@ -199,9 +199,9 @@ public class PhotoProductsController { } List idList = commonBatchRequest.getIdList(); // 获取写真产品的预约日期 - List bookingDateList = commonService.findByMyIds(idList, bookingDateService); + List bookingDateList = commonService.findByFieldInTargetField(idList, bookingDateService, id -> id, "photoProductId"); // 获取写真产品的预约时间 - List bookingTimeList = commonService.findBySourceFieldValues(bookingDateList, bookingTimeService, "id", "bookingDateId"); + List bookingTimeList = commonService.findByFieldInTargetField(bookingDateList, bookingTimeService, BookingDate::getId, "bookingDateId"); // 删除写真产品下的预约时间 boolean remove = bookingTimeService.removeBatchByIds(bookingTimeList); ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "预约时间批量删除失败"); @@ -236,9 +236,9 @@ public class PhotoProductsController { // 获取写真产品列表 List records = page.getRecords(); // 获取预约日期表 - List bookingDateList = commonService.findBySourceFieldValues(records, bookingDateService, "id", "photoProductId"); + List bookingDateList = commonService.findByFieldInTargetField(records, bookingDateService, PhotoProducts::getId, "photoProductId"); // 获取预约时间表 - List bookingTimeList = commonService.findBySourceFieldValues(bookingDateList, bookingTimeService, "id", "bookingDateId"); + List bookingTimeList = commonService.findByFieldInTargetField(bookingDateList, bookingTimeService, BookingDate::getId, "bookingDateId"); // 封装成BookingTimeVO列表, 并将预约时间从小到大排序 List bookingTimeVOList = commonService.convertList(bookingTimeList, BookingTimeVO.class); bookingTimeVOList.sort((b1, b2) -> { @@ -306,9 +306,9 @@ public class PhotoProductsController { PhotoProducts photoProducts = photoProductsService.getById(id); ThrowUtils.throwIf(photoProducts == null || photoProducts.getIsShelves() == 0, ErrorCode.OPERATION_ERROR, "该商品已被删除或者已下架"); // 获取预约日期表 - List bookingDateList = commonService.findByFieldValue("photoProductId", id, bookingDateService); + List bookingDateList = commonService.findByFieldEqTargetField("photoProductId", id, bookingDateService); // 获取预约时间表 - List bookingTimeList = commonService.findBySourceFieldValues(bookingDateList, bookingTimeService, "id", "bookingDateId"); + List bookingTimeList = commonService.findByFieldInTargetField(bookingDateList, bookingTimeService, BookingDate::getId, "bookingDateId"); // 封装成BookingTimeVO列表, 并将预约时间从小到大排序 List bookingTimeVOList = commonService.convertList(bookingTimeList, BookingTimeVO.class); bookingTimeVOList.sort((b1, b2) -> { diff --git a/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java b/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java index c82d029..1da9558 100644 --- a/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java +++ b/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java @@ -288,7 +288,7 @@ public class AppointmentDateController { ThrowUtils.throwIf(good == null, ErrorCode.OPERATION_ERROR, "当前商品不存在"); // 获取预约日期列表 - List appointmentDateList = commonService.findByOtherIds(timePeriodList, appointmentDateService, TimePeriod::getAppointmentDateId); + List appointmentDateList = commonService.findByFieldInTargetField(timePeriodList, appointmentDateService, TimePeriod::getAppointmentDateId, "id"); // 封装map集合(键:预约日期id, 值:是否可预约) Map map = new HashMap<>(); diff --git a/src/main/java/com/cultural/heritage/controller/good/CartExperienceController.java b/src/main/java/com/cultural/heritage/controller/good/CartExperienceController.java index b60ab60..1ed7aab 100644 --- a/src/main/java/com/cultural/heritage/controller/good/CartExperienceController.java +++ b/src/main/java/com/cultural/heritage/controller/good/CartExperienceController.java @@ -95,7 +95,7 @@ public class CartExperienceController { userService.getLoginUser(request); // 获取服务类购物车商品列表 - List cartExperienceList = commonService.findByOtherIds(cartExperienceUpdateRequestList, cartExperienceService, CartExperienceUpdateRequest::getId); + List cartExperienceList = commonService.findByFieldInTargetField(cartExperienceUpdateRequestList, cartExperienceService, CartExperienceUpdateRequest::getId, "id"); // 封装map集合(键:购物车id, 值:商品数量) Map QuantityMap = new HashMap<>(); @@ -114,7 +114,7 @@ public class CartExperienceController { } // 获取商品列表 - List goodList = commonService.findByOtherIds(cartExperienceList, goodService, CartExperience::getGoodId); + List goodList = commonService.findByFieldInTargetField(cartExperienceList, goodService, CartExperience::getGoodId, "id"); // 封装map集合(键:商品id, 值:商品价格) Map priceMap = new HashMap<>(); @@ -222,10 +222,10 @@ public class CartExperienceController { userService.getLoginUser(request); List cartExperienceIds = commonBatchRequest.getIdList(); // 获取购物车信息列表 - List cartExperiences = commonService.findByMyIds(cartExperienceIds, cartExperienceService); + List cartExperiences = commonService.findByFieldInTargetField(cartExperienceIds, cartExperienceService, id -> id, "id"); // 获取购物车中的商品列表 - List goodList = commonService.findByOtherIds(cartExperiences, goodService, CartExperience::getGoodId); + List goodList = commonService.findByFieldInTargetField(cartExperiences, goodService, CartExperience::getGoodId, "id"); // 封装goodMap(根据商品id查询商品) Map goodMap = new HashMap<>(); diff --git a/src/main/java/com/cultural/heritage/controller/good/CartRecordController.java b/src/main/java/com/cultural/heritage/controller/good/CartRecordController.java index cb3a6ad..4a79ccc 100644 --- a/src/main/java/com/cultural/heritage/controller/good/CartRecordController.java +++ b/src/main/java/com/cultural/heritage/controller/good/CartRecordController.java @@ -88,7 +88,7 @@ public class CartRecordController { userService.getLoginUser(request); // 获取购物车列表 - List cartRecordList = commonService.findByOtherIds(cartRecordUpdateRequestList, cartRecordService, CartRecordUpdateRequest::getId); + List cartRecordList = commonService.findByFieldInTargetField(cartRecordUpdateRequestList, cartRecordService, CartRecordUpdateRequest::getId, "id"); // 封装map集合(键:购物车id, 值:商品数量) Map QuantityMap = new HashMap<>(); @@ -97,7 +97,7 @@ public class CartRecordController { } // 获取商品列表 - List goodList = commonService.findByOtherIds(cartRecordList, goodService, CartRecord::getGoodId); + List goodList = commonService.findByFieldInTargetField(cartRecordList, goodService, CartRecord::getGoodId, "id"); // 封装map集合(键:商品id, 值:商品价格) Map priceMap = new HashMap<>(); @@ -200,10 +200,10 @@ public class CartRecordController { userService.getLoginUser(request); List cartRecordIds = commonBatchRequest.getIdList(); // 根据id列表获取购物车信息列表 - List cartRecords = commonService.findByMyIds(cartRecordIds, cartRecordService); + List cartRecords = commonService.findByFieldInTargetField(cartRecordIds, cartRecordService, id -> id, "id"); // 提取出购物车中的商品列表 - List goodList = commonService.findByOtherIds(cartRecords, goodService, CartRecord::getGoodId); + List goodList = commonService.findByFieldInTargetField(cartRecords, goodService, CartRecord::getGoodId, "id"); // 封装goodMap(根据商品id查询商品) Map goodMap = new HashMap<>(); diff --git a/src/main/java/com/cultural/heritage/controller/good/CategoryController.java b/src/main/java/com/cultural/heritage/controller/good/CategoryController.java index 1215c7e..1b6ea58 100644 --- a/src/main/java/com/cultural/heritage/controller/good/CategoryController.java +++ b/src/main/java/com/cultural/heritage/controller/good/CategoryController.java @@ -130,7 +130,7 @@ public class CategoryController { } List idList = commonDelBatchRequest.getIdList(); // 批量删除当前类别下的所有商品 - List categoryList = commonService.findByMyIds(idList, categoryService); + List categoryList = commonService.findByFieldInTargetField(idList, categoryService, id -> id, "id"); List typeNameList = categoryList.stream().map(Category::getTypeName).toList(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.in("type", typeNameList); diff --git a/src/main/java/com/cultural/heritage/service/common/CommonService.java b/src/main/java/com/cultural/heritage/service/common/CommonService.java index 50972eb..3edc28e 100644 --- a/src/main/java/com/cultural/heritage/service/common/CommonService.java +++ b/src/main/java/com/cultural/heritage/service/common/CommonService.java @@ -8,31 +8,67 @@ import java.util.function.Function; public interface CommonService { +// +// /** +// * 从源集合中提取 ID 列表,并根据这些 ID 查询目标集合的数据。 +// * @param sourceList 源集合(List),包含需要提取 ID 的元素 +// * @param genericService 执行查询的 Service(IService) +// * @param getId 提取源集合中每个元素的 ID 的函数 +// * @param 源集合中元素的类型 +// * @param 目标集合中元素的类型 +// * @return 查询结果集合 +// */ +// List findByMyIdInOtherIds(List sourceList, IService genericService, Function getId); +// +// +// +// +// +// /** +// * 该方法接收一个 List 类型的 ID 列表,利用传入的服务接口和目标字段名,构造查询条件并执行查询。 +// * @param idList ID 列表(List) +// * @param service 执行查询的 Service +// * @param targetField 目标字段名 +// * @param 查询结果实体类型 +// * @return 查询结果集合 +// */ +// List findByMyFieldValueInOtherIds(List idList, IService service, String targetField); +// +// +// +// +// +// /** +// * 从第一个集合中提取某个属性值,并用这些值作为查询条件去查询第二个集合的数据。 +// * @param sourceList 原始集合(源数据) +// * @param service 要执行查询的 Service +// * @param sourceField 在原始集合中提取的字段名 +// * @param targetField 在目标集合中的查询字段名 +// * @param 目标查询实体类型 +// * @return 查询结果集合 +// */ +// List findByMyFieldValueInOtherFieldValues(List sourceList, IService service, String sourceField, String targetField); +// +// + - /** - * 取出一个集合的某个id列表, 去另外一个集合中筛选出属于这个id列表的集合 - */ - List findByOtherIds(List sourceList, IService genericService, Function getId); /** - * 根据 ID 列表获取对应的实体列表 - */ - List findByMyIds(List ids, IService genericService); - - - - /** - * 从第一个集合中提取某个属性值,并用这些值作为查询条件去查询第二个集合的数据。 - * @param sourceList 原始集合(源数据) - * @param service 要执行查询的 Service - * @param sourceField 在原始集合中提取的字段名 - * @param targetField 在目标集合中的查询字段名 - * @param 目标查询实体类型 + * 从源集合中提取指定属性并作为查询条件查询目标集合 + * @param sourceList 源集合(List),包含需要提取属性的元素 + * @param service 执行查询的 Service + * @param getField 提取源集合中每个元素的属性值的函数 + * @param targetField 目标集合中查询字段的字段名 + * @param 源集合元素类型 + * @param 目标集合中元素类型 * @return 查询结果集合 */ - List findBySourceFieldValues(List sourceList, IService service, String sourceField, String targetField); + List findByFieldInTargetField(List sourceList, IService service, Function getField, String targetField); + + + @@ -44,7 +80,8 @@ public interface CommonService { * @param service 用于执行查询的服务层对象 * @return 返回符合条件的实体类列表(`List`)。如果没有符合条件的记录,返回空列表。 */ - List findByFieldValue(String fieldName, Object fieldValue, IService service); + List findByFieldEqTargetField(String fieldName, Object fieldValue, IService service); + @@ -56,7 +93,9 @@ public interface CommonService { * @param service 执行查询操作的服务对象(通常是MyBatis-Plus的 IService) * @return 返回查询结果的列表 */ - List findByMultipleFieldValues(Map fieldConditions, IService service); + List findByFieldEqTargetFields(Map fieldConditions, IService service); + + diff --git a/src/main/java/com/cultural/heritage/service/common/impl/CommonServiceImpl.java b/src/main/java/com/cultural/heritage/service/common/impl/CommonServiceImpl.java index 99399fa..76f48d5 100644 --- a/src/main/java/com/cultural/heritage/service/common/impl/CommonServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/common/impl/CommonServiceImpl.java @@ -6,7 +6,6 @@ import com.cultural.heritage.service.common.CommonService; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; -import java.lang.reflect.Field; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -16,91 +15,147 @@ import java.util.stream.Collectors; public class CommonServiceImpl implements CommonService { - /** - * 取出一个集合的某个id列表, 去另外一个集合中筛选出属于这个id列表的集合 - */ - @Override - public List findByOtherIds(List sourceList, IService genericService, Function getId) { - // 提取ID - List ids = sourceList.stream() - .map(getId) // 提取每个元素的ID - .collect(Collectors.toList()); - - if (ids.isEmpty()) { - return List.of(); // 返回空集合 - } - // 构造查询条件 - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.in("id", ids); - - // 返回查询结果 - return genericService.list(queryWrapper); - } - /** - * 根据 ID 列表获取对应的实体列表 - */ - @Override - public List findByMyIds(List ids, IService genericService) { - if (ids.isEmpty()) { - return List.of(); // 返回空集合 - } - // 构造查询条件 - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.in("id", ids); // 使用 IN 条件 - - // 调用具体的服务执行查询 - return genericService.list(queryWrapper); - } +// +// +// /** +// * 从源集合中提取 ID 列表,并根据这些 ID 查询目标集合的数据。 +// * @param sourceList 源集合(List),包含需要提取 ID 的元素 +// * @param genericService 执行查询的 Service(IService) +// * @param getId 提取源集合中每个元素的 ID 的函数 +// * @param 源集合中元素的类型 +// * @param 目标集合中元素的类型 +// * @return 查询结果集合 +// */ +// @Override +// public List findByMyIdInOtherIds(List sourceList, IService genericService, Function getId) { +// // 提取ID +// List ids = sourceList.stream() +// .map(getId) // 提取每个元素的ID +// .collect(Collectors.toList()); +// +// if (ids.isEmpty()) { +// return List.of(); // 返回空集合 +// } +// // 构造查询条件 +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// queryWrapper.in("id", ids); +// +// // 返回查询结果 +// return genericService.list(queryWrapper); +// } +// +// +// +// +// /** +// * 该方法接收一个 List 类型的 ID 列表,利用传入的服务接口和目标字段名,构造查询条件并执行查询。 +// * @param idList ID 列表(List) +// * @param service 执行查询的 Service +// * @param targetField 目标字段名 +// * @param 查询结果实体类型 +// * @return 查询结果集合 +// */ +// public List findByMyFieldValueInOtherIds(List idList, IService service, String targetField) { +// // 如果 idList 为空或为 null,直接返回空集合 +// if (idList.isEmpty()) { +// return List.of(); // 返回空集合 +// } +// +// // 创建 QueryWrapper 对象,用于构建查询条件 +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// +// // 使用 in 方法,构造根据 targetField 字段值查询的条件 +// queryWrapper.in(targetField, idList); // 将传入的 ID 列表作为查询条件 +// +// // 调用 service 的 list 方法,执行查询并返回结果 +// return service.list(queryWrapper); // 返回查询结果 +// } +// +// +// +// +// +// /** +// * 从第一个集合中提取某个属性值,并用这些值作为查询条件去查询第二个集合的数据。 +// * @param sourceList 原始集合(源数据) +// * @param service 要执行查询的 Service +// * @param sourceField 在原始集合中提取的字段名 +// * @param targetField 在目标集合中的查询字段名 +// * @param 目标查询实体类型 +// * @return 查询结果集合 +// */ +// @Override +// public List findByMyFieldValueInOtherFieldValues(List sourceList, IService service, String sourceField, String targetField) { +// // 使用反射获取源集合中对应字段的值 +// List fieldValues = sourceList.stream() +// .map(item -> getFieldValue(item, sourceField)) // 获取字段值 +// .collect(Collectors.toList()); +// +// // 如果 fieldValues 为空,直接返回空集合 +// if (fieldValues.isEmpty()) { +// return List.of(); // 返回空集合 +// } +// // 创建查询条件 +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// queryWrapper.in(targetField, fieldValues); // 根据字段值进行查询 +// +// return service.list(queryWrapper); // 执行查询并返回结果 +// } +// +// +// +// /** +// * 使用反射获取对象的字段值 +// * @param object 对象 +// * @param fieldName 字段名 +// * @return 字段的值 +// */ +// private Object getFieldValue(Object object, String fieldName) { +// try { +// Field field = object.getClass().getDeclaredField(fieldName); +// field.setAccessible(true); +// return field.get(object); +// } catch (NoSuchFieldException | IllegalAccessException e) { +// throw new RuntimeException("字段获取失败", e); +// } +// } /** - * 从第一个集合中提取某个属性值,并用这些值作为查询条件去查询第二个集合的数据。 - * @param sourceList 原始集合(源数据) - * @param service 要执行查询的 Service - * @param sourceField 在原始集合中提取的字段名 - * @param targetField 在目标集合中的查询字段名 - * @param 目标查询实体类型 + * 从源集合中提取指定属性并作为查询条件查询目标集合 + * @param sourceList 源集合(List),包含需要提取属性的元素 + * @param service 执行查询的 Service + * @param getField 提取源集合中每个元素的属性值的函数 + * @param targetField 目标集合中查询字段的字段名 + * @param 源集合元素类型 + * @param 目标集合中元素类型 * @return 查询结果集合 */ - @Override - public List findBySourceFieldValues(List sourceList, IService service, String sourceField, String targetField) { - // 使用反射获取源集合中对应字段的值 + public List findByFieldInTargetField(List sourceList, IService service, Function getField, String targetField) { + // 提取源集合中每个元素的字段值 List fieldValues = sourceList.stream() - .map(item -> getFieldValue(item, sourceField)) // 获取字段值 + .map(getField) // 提取每个元素的字段值 .collect(Collectors.toList()); // 如果 fieldValues 为空,直接返回空集合 if (fieldValues.isEmpty()) { return List.of(); // 返回空集合 } + // 创建查询条件 - QueryWrapper queryWrapper = new QueryWrapper<>(); + QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.in(targetField, fieldValues); // 根据字段值进行查询 - return service.list(queryWrapper); // 执行查询并返回结果 + // 执行查询并返回结果 + return service.list(queryWrapper); } - /** - * 使用反射获取对象的字段值 - * @param object 对象 - * @param fieldName 字段名 - * @return 字段的值 - */ - private Object getFieldValue(Object object, String fieldName) { - try { - Field field = object.getClass().getDeclaredField(fieldName); - field.setAccessible(true); - return field.get(object); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new RuntimeException("字段获取失败", e); - } - } @@ -114,7 +169,7 @@ public class CommonServiceImpl implements CommonService { * @return 返回符合条件的实体类列表(`List`)。如果没有符合条件的记录,返回空列表。 */ @Override - public List findByFieldValue(String fieldName, Object fieldValue, IService service) { + public List findByFieldEqTargetField(String fieldName, Object fieldValue, IService service) { // 创建 QueryWrapper,动态构建查询条件 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq(fieldName, fieldValue); // 设置等值查询条件 @@ -134,7 +189,7 @@ public class CommonServiceImpl implements CommonService { * @return 返回查询结果的列表 */ @Override - public List findByMultipleFieldValues(Map fieldConditions, IService service) { + public List findByFieldEqTargetFields(Map fieldConditions, IService service) { // 创建 QueryWrapper,动态构建查询条件 QueryWrapper queryWrapper = new QueryWrapper<>(); diff --git a/src/main/java/com/cultural/heritage/service/good/impl/CartExperienceServiceImpl.java b/src/main/java/com/cultural/heritage/service/good/impl/CartExperienceServiceImpl.java index 9938b0b..3872eae 100644 --- a/src/main/java/com/cultural/heritage/service/good/impl/CartExperienceServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/good/impl/CartExperienceServiceImpl.java @@ -233,7 +233,7 @@ public class CartExperienceServiceImpl extends ServiceImpl getInvalidCartIds(List cartExperienceList) { // 获取购物车的商品id列表 - List goodList = commonService.findByOtherIds(cartExperienceList, goodService, CartExperience::getGoodId); + List goodList = commonService.findByFieldInTargetField(cartExperienceList, goodService, CartExperience::getGoodId, "id"); // 封装map集合(键:商品id, 值:商品详情信息) Map map = new HashMap<>(); for (Good good : goodList) { diff --git a/src/main/java/com/cultural/heritage/service/good/impl/CartRecordServiceImpl.java b/src/main/java/com/cultural/heritage/service/good/impl/CartRecordServiceImpl.java index 0444fac..ca012f9 100644 --- a/src/main/java/com/cultural/heritage/service/good/impl/CartRecordServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/good/impl/CartRecordServiceImpl.java @@ -179,7 +179,7 @@ public class CartRecordServiceImpl extends ServiceImpl cartRecordList = commonService.findByOtherIds(cartOrderItemAddRequestList, this, CartOrderItemAddRequest::getCartRecordId); + List cartRecordList = commonService.findByFieldInTargetField(cartOrderItemAddRequestList, this, CartOrderItemAddRequest::getCartRecordId, "id"); for (CartRecord cartRecord : cartRecordList) { Integer quantity = map.get(cartRecord.getId()); cartRecord.setQuantity(quantity); @@ -195,7 +195,7 @@ public class CartRecordServiceImpl extends ServiceImpl getInvalidCartIds(List cartRecords) { // 获取购物车的商品列表 - List goodList = commonService.findByOtherIds(cartRecords, goodService, CartRecord::getGoodId); + List goodList = commonService.findByFieldInTargetField(cartRecords, goodService, CartRecord::getGoodId, "id"); // 封装map集合(键:商品id, 值:商品详情信息) Map map = new HashMap<>(); for (Good good : goodList) {