商品分组
This commit is contained in:
@@ -21,8 +21,14 @@ import cn.ysk.cashier.dto.product.TbProductGroupDto;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @author lyf
|
||||
@@ -31,4 +37,29 @@ import org.mapstruct.ReportingPolicy;
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface TbProductGroupMapper extends BaseMapper<TbProductGroupDto, TbProductGroup> {
|
||||
|
||||
@Mapping(target = "productIds", source = "productIds")
|
||||
TbProductGroupDto toDto(TbProductGroup entity);
|
||||
|
||||
// 自定义的字符串到整数列表的转换方法
|
||||
default List<Integer> map(String value) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 分割字符串,然后将每个数字字符串转换为Integer,收集到List中
|
||||
return Arrays.stream(value.split(","))
|
||||
.map(Integer::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// 如果需要从DTO转回实体,也可能需要实现反向的映射方法
|
||||
default String map(List<Integer> values) {
|
||||
if (values == null || values.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
// 将整数列表转换为由逗号分隔的字符串
|
||||
return values.stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user