|
|
|
|
@ -2,14 +2,23 @@ package cn.iocoder.yudao.module.erp.service.product;
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryListReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryProcessRouteItemRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategorySaveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryProcessRouteItemDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductCategoryMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductCategoryProcessRouteItemMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.api.processroute.ProcessRouteApi;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.api.processroute.dto.ProcessRouteItemSnapshotRespDTO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.api.processroute.dto.ProcessRouteSnapshotRespDTO;
|
|
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
@ -29,11 +38,18 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpProductCategoryMapper erpProductCategoryMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpProductCategoryProcessRouteItemMapper productCategoryProcessRouteItemMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ProcessRouteApi processRouteApi;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
@Lazy // 延迟加载,避免循环依赖
|
|
|
|
|
private ErpProductService productService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Long createProductCategory(ErpProductCategorySaveReqVO createReqVO) {
|
|
|
|
|
// 校验父分类编号的有效性
|
|
|
|
|
validateParentProductCategory(null, createReqVO.getParentId());
|
|
|
|
|
@ -42,12 +58,15 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService
|
|
|
|
|
|
|
|
|
|
// 插入
|
|
|
|
|
ErpProductCategoryDO category = BeanUtils.toBean(createReqVO, ErpProductCategoryDO.class);
|
|
|
|
|
fillProcessRouteSnapshot(category);
|
|
|
|
|
erpProductCategoryMapper.insert(category);
|
|
|
|
|
saveProcessRouteItemSnapshot(category.getId(), category.getProcessRouteId());
|
|
|
|
|
// 返回
|
|
|
|
|
return category.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void updateProductCategory(ErpProductCategorySaveReqVO updateReqVO) {
|
|
|
|
|
// 校验存在
|
|
|
|
|
validateProductCategoryExists(updateReqVO.getId());
|
|
|
|
|
@ -58,7 +77,10 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService
|
|
|
|
|
|
|
|
|
|
// 更新
|
|
|
|
|
ErpProductCategoryDO updateObj = BeanUtils.toBean(updateReqVO, ErpProductCategoryDO.class);
|
|
|
|
|
fillProcessRouteSnapshot(updateObj);
|
|
|
|
|
erpProductCategoryMapper.updateById(updateObj);
|
|
|
|
|
productCategoryProcessRouteItemMapper.deleteByCategoryId(updateReqVO.getId());
|
|
|
|
|
saveProcessRouteItemSnapshot(updateReqVO.getId(), updateObj.getProcessRouteId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ -74,9 +96,43 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService
|
|
|
|
|
throw exception(PRODUCT_CATEGORY_EXITS_PRODUCT);
|
|
|
|
|
}
|
|
|
|
|
// 2. 删除
|
|
|
|
|
productCategoryProcessRouteItemMapper.deleteByCategoryId(id);
|
|
|
|
|
erpProductCategoryMapper.deleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fillProcessRouteSnapshot(ErpProductCategoryDO category) {
|
|
|
|
|
if (category.getProcessRouteId() == null) {
|
|
|
|
|
category.setProcessRouteName(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ProcessRouteSnapshotRespDTO processRoute = processRouteApi.getProcessRouteSnapshot(category.getProcessRouteId());
|
|
|
|
|
category.setProcessRouteName(processRoute == null ? null : processRoute.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveProcessRouteItemSnapshot(Long categoryId, Long processRouteId) {
|
|
|
|
|
if (categoryId == null || processRouteId == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ProcessRouteSnapshotRespDTO processRoute = processRouteApi.getProcessRouteSnapshot(processRouteId);
|
|
|
|
|
if (processRoute == null || processRoute.getItems() == null || processRoute.getItems().isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<ErpProductCategoryProcessRouteItemDO> saveList = new ArrayList<>();
|
|
|
|
|
for (ProcessRouteItemSnapshotRespDTO item : processRoute.getItems()) {
|
|
|
|
|
ErpProductCategoryProcessRouteItemDO snapshot = new ErpProductCategoryProcessRouteItemDO();
|
|
|
|
|
snapshot.setCategoryId(categoryId);
|
|
|
|
|
snapshot.setProcessRouteId(processRouteId);
|
|
|
|
|
snapshot.setProcessRouteItemId(item.getId());
|
|
|
|
|
snapshot.setSort(item.getSort());
|
|
|
|
|
snapshot.setProcessParameterId(item.getProcessParameterId());
|
|
|
|
|
snapshot.setProcessParameterCode(item.getProcessParameterCode());
|
|
|
|
|
snapshot.setProcessParameterName(item.getProcessParameterName());
|
|
|
|
|
snapshot.setRemark(item.getRemark());
|
|
|
|
|
saveList.add(snapshot);
|
|
|
|
|
}
|
|
|
|
|
productCategoryProcessRouteItemMapper.insertBatch(saveList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateProductCategoryExists(Long id) {
|
|
|
|
|
if (erpProductCategoryMapper.selectById(id) == null) {
|
|
|
|
|
throw exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
|
|
|
|
@ -136,6 +192,22 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService
|
|
|
|
|
return erpProductCategoryMapper.selectById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ErpProductCategoryRespVO getProductCategoryResp(Long id) {
|
|
|
|
|
return buildProductCategoryResp(getProductCategory(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ErpProductCategoryRespVO buildProductCategoryResp(ErpProductCategoryDO category) {
|
|
|
|
|
if (category == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
ErpProductCategoryRespVO respVO = BeanUtils.toBean(category, ErpProductCategoryRespVO.class);
|
|
|
|
|
List<ErpProductCategoryProcessRouteItemDO> items = productCategoryProcessRouteItemMapper.selectListByCategoryId(category.getId());
|
|
|
|
|
respVO.setProcessRouteItems(BeanUtils.toBean(items, ErpProductCategoryProcessRouteItemRespVO.class));
|
|
|
|
|
return respVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<ErpProductCategoryDO> getProductCategoryList(ErpProductCategoryListReqVO listReqVO) {
|
|
|
|
|
return erpProductCategoryMapper.selectList(listReqVO);
|
|
|
|
|
@ -151,4 +223,4 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService
|
|
|
|
|
return erpProductCategoryMapper.selectByName(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|