|
|
@ -0,0 +1,60 @@ |
|
|
|
|
|
package com.qniao.dam.infrastructure.persistent.repository.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.productspec.entity.ProductSpec; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.productspec.entity.ProductSpecTerm; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.productspec.repository.ProductSpecRepository; |
|
|
|
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.ProductSpecDao; |
|
|
|
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.ProductSpecTermDao; |
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
|
|
public class ProductSpecRepositoryImpl implements ProductSpecRepository { |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private ProductSpecDao productSpecDao; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private ProductSpecTermDao productSpecTermDao; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public ProductSpec load(Long id) { |
|
|
|
|
|
ProductSpec productSpec = productSpecDao.selectById(id); |
|
|
|
|
|
if (Objects.nonNull(productSpec)) { |
|
|
|
|
|
productSpec.setProductSpecTermList(productSpecTermDao.selectList(new LambdaQueryWrapper<ProductSpecTerm>() |
|
|
|
|
|
.eq(ProductSpecTerm::getProductSpecId, productSpec.getId()))); |
|
|
|
|
|
} |
|
|
|
|
|
return productSpec; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
@Override |
|
|
|
|
|
public Long save(ProductSpec entity) { |
|
|
|
|
|
if (Objects.isNull(entity) || Objects.isNull(productSpecDao.selectById(entity.getId()))) { |
|
|
|
|
|
productSpecDao.insert(entity); |
|
|
|
|
|
} else { |
|
|
|
|
|
productSpecDao.updateById(entity); |
|
|
|
|
|
} |
|
|
|
|
|
if (CollUtil.isNotEmpty(entity.getInsertProductSpecTermList())) { |
|
|
|
|
|
entity.getInsertProductSpecTermList().forEach(term -> { |
|
|
|
|
|
term.setProductSpecId(entity.getId()); |
|
|
|
|
|
productSpecTermDao.insert(term); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
if (CollUtil.isNotEmpty(entity.getUpdateProductSpecTermList())) { |
|
|
|
|
|
entity.getUpdateProductSpecTermList().forEach(term -> { |
|
|
|
|
|
term.setProductSpecId(entity.getId()); |
|
|
|
|
|
productSpecTermDao.updateById(term); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
if (CollUtil.isNotEmpty(entity.getDeleteProductSpecTermList())) { |
|
|
|
|
|
productSpecTermDao.deleteBatchIds(entity.getDeleteProductSpecTermList().stream().map(ProductSpecTerm::getId).collect(Collectors.toList())); |
|
|
|
|
|
} |
|
|
|
|
|
return entity.getId(); |
|
|
|
|
|
} |
|
|
|
|
|
} |