|
|
|
|
@ -1,5 +1,14 @@
|
|
|
|
|
package cn.iocoder.yudao.module.erp.service.mold;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.product.ErpProductUnitService;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@ -18,6 +27,7 @@ import cn.iocoder.yudao.module.erp.dal.mysql.mold.MoldMapper;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
|
|
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -33,7 +43,10 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
|
private MoldBrandMapper moldBrandMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private MoldMapper moldMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpProductUnitService productUnitService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpProductService productService;
|
|
|
|
|
@Override
|
|
|
|
|
public Long createMoldBrand(MoldBrandSaveReqVO createReqVO) {
|
|
|
|
|
// 插入
|
|
|
|
|
@ -76,17 +89,40 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageResult<MoldBrandDO> getMoldBrandPage(MoldBrandPageReqVO pageReqVO) {
|
|
|
|
|
return moldBrandMapper.selectPage(pageReqVO);
|
|
|
|
|
public PageResult<MoldBrandRespVO> getMoldBrandPage(MoldBrandPageReqVO pageReqVO) {
|
|
|
|
|
PageResult<MoldBrandDO> pageResult = moldBrandMapper.selectPage(pageReqVO);
|
|
|
|
|
return new PageResult<>(buildMoldBrandVOList(pageResult.getList()),pageResult.getTotal());
|
|
|
|
|
}
|
|
|
|
|
private List<MoldBrandRespVO> buildMoldBrandVOList(List<MoldBrandDO> list) {
|
|
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
Map<Long, ErpProductDO> map = productService.getProductMap(
|
|
|
|
|
convertSet(list, MoldBrandDO::getProductId));
|
|
|
|
|
return BeanUtils.toBean(list, MoldBrandRespVO.class, item -> {
|
|
|
|
|
MapUtils.findAndThen(map, item.getProductId(),
|
|
|
|
|
product -> item.setProductName(product.getName()));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== 子表(模具) ====================
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageResult<MoldDO> getMoldPage(PageParam pageReqVO, Long brandId) {
|
|
|
|
|
return moldMapper.selectPage(pageReqVO, brandId);
|
|
|
|
|
public PageResult<MoldRespVO> getMoldPage(PageParam pageReqVO, Long brandId) {
|
|
|
|
|
PageResult<MoldDO> pageResult = moldMapper.selectPage(pageReqVO, brandId);
|
|
|
|
|
return new PageResult<>(buildMoldVOList(pageResult.getList()), pageResult.getTotal());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<MoldRespVO> buildMoldVOList(List<MoldDO> list) {
|
|
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(
|
|
|
|
|
convertSet(list, MoldDO::getUnitId));
|
|
|
|
|
return BeanUtils.toBean(list, MoldRespVO.class, product -> {
|
|
|
|
|
MapUtils.findAndThen(unitMap, product.getUnitId(),
|
|
|
|
|
unit -> product.setUnitName(unit.getName()));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public Long createMold(MoldDO mold) {
|
|
|
|
|
moldMapper.insert(mold);
|
|
|
|
|
|