充血模型是DDD分层架构中实体设计的一种方案,可以使关注点聚焦于业务实现,可有效提升开发效率、提升可维护性;
调用关系图中的Entity为实体,从进入领域服务(Domin)时开始使用,直到最后返回。

充血模型是实体设计的一种方法,简单来说,就是一种带有具体行为方法和聚合关联关系的特殊实体;
解决方案:
public CooperateServicePackageConfig save() {// 直接调用基础设施层进行保存cooperateServicePackageConfigRepository.save(this);return this;}
public CooperateServicePackageConfig save() {// 将处理过程放在工具类中ServicePackageSaveUtils.save(this);return this;}
private LabelInfoRepository labelInfoRepository = ApplicationContextUtils.getBean(LabelInfoRepository.class);2、充血模型的实体序列化,排除非必要属性,在一些redis对象缓存时可能会用到。例:
// 使用注解排除序列化属性private LabelInfoRepository labelInfoRepository = ApplicationContextUtils.getBean(LabelInfoRepository.class);
// 使用注解排除序列化属性(serialize = false)private ServicePackageConfig servicePackageConfig;
// 使用注解排除序列化 get 方法(serialize = false)public static CooperateServicePackageRepositoryQuery getAllCodeQuery(Long contractId) {CooperateServicePackageRepositoryQuery repositoryQuery = new CooperateServicePackageRepositoryQuery();repositoryQuery.setContractIds(com.google.common.collect.Lists.newArrayList(contractId));repositoryQuery.setCode(RightsPlatformConstants.CODE_ALL);return repositoryQuery;}
public void setServiceSkuInfos(List<ServiceSkuInfo> serviceSkuInfos) {if (CollectionUtils.isEmpty(serviceSkuInfos)){return;}this.serviceSkuInfos = serviceSkuInfos;List<String> allSkuNoSet = serviceSkuInfos.stream().map(one -> one.getSkuNo()).collect(Collectors.toList());String skuJoinStr = Joiner.on(GlobalConstant.SPLIT_CHAR).join(allSkuNoSet);this.setSkuNoSet(skuJoinStr);}-end-

