实现逻辑:
查询产品详情 代码重构
This commit is contained in:
parent
08619a8f5e
commit
5e470575a3
@ -6,8 +6,14 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* saas-产品表(SaasProduct)表实体类
|
* saas-产品表(SaasProduct)表实体类
|
||||||
@ -85,5 +91,14 @@ public class ProductModule extends BaseEntity<ProductModule> {
|
|||||||
protected Serializable pkVal() {
|
protected Serializable pkVal() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Integer> parseOuType() {
|
||||||
|
if (StringUtils.isNotBlank(this.ouType)) {
|
||||||
|
return Arrays.asList(this.ouType.split(",")).stream().map(e -> Integer.valueOf(e.trim())).collect(Collectors.toList());
|
||||||
|
} else {
|
||||||
|
// 避免下游空指针
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -61,7 +61,7 @@ public class ProductServiceImpl implements ProductService {
|
|||||||
ArrayList<ProductVO> result = new ArrayList<>();
|
ArrayList<ProductVO> result = new ArrayList<>();
|
||||||
list.forEach(e -> {
|
list.forEach(e -> {
|
||||||
ProductVO product = BeanMapper.copyBean(e, ProductVO.class);
|
ProductVO product = BeanMapper.copyBean(e, ProductVO.class);
|
||||||
product.setOuTypes(Arrays.stream(e.getOuType().split(",")).filter(org.apache.commons.lang3.StringUtils::isNotBlank).map(s -> Integer.valueOf(s.trim())).collect(Collectors.toList()));
|
product.setOuTypes(e.parseOuType());
|
||||||
result.add(product);
|
result.add(product);
|
||||||
});
|
});
|
||||||
return ApiResult.ok(BeanMapper.copyList(list, ProductVO.class));
|
return ApiResult.ok(BeanMapper.copyList(list, ProductVO.class));
|
||||||
@ -81,7 +81,10 @@ public class ProductServiceImpl implements ProductService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiResult<ProductVO> getById(Long id) {
|
public ApiResult<ProductVO> getById(Long id) {
|
||||||
return ApiResult.ok(BeanMapper.copyBean(productModuleDao.getById(id), ProductVO.class));
|
ProductModule byId = productModuleDao.getById(id);
|
||||||
|
ProductVO productVO = BeanMapper.copyBean(byId, ProductVO.class);
|
||||||
|
productVO.setOuTypes(byId.parseOuType());
|
||||||
|
return ApiResult.ok(productVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user