feat:添加产品分类工艺路线相关接口

main
HuangHuiKang 1 day ago
parent c9c5035f75
commit 74df3581ef

@ -70,8 +70,7 @@ public class ErpProductCategoryController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('erp:product-category:query')")
public CommonResult<ErpProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) {
ErpProductCategoryDO category = productCategoryService.getProductCategory(id);
return success(BeanUtils.toBean(category, ErpProductCategoryRespVO.class));
return success(productCategoryService.getProductCategoryResp(id));
}
@GetMapping("/list")

@ -110,6 +110,14 @@ public class ErpProductController {
return success(productService.getProduct(id, code));
}
@GetMapping("/get-process-route")
@Operation(summary = "获得产品对应的工艺路线快照")
@Parameter(name = "productId", description = "产品编号", required = true, example = "1")
@PreAuthorize("@ss.hasPermission('erp:product:query')")
public CommonResult<ErpProductProcessRouteRespVO> getProductProcessRoute(@RequestParam("productId") Long productId) {
return success(productService.getProductProcessRoute(productId));
}
@GetMapping("/page")
@Operation(summary = "获得产品分页")
@PreAuthorize("@ss.hasPermission('erp:product:query')")

@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.erp.controller.admin.product.vo.category;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - ERP 产品分类工艺路线明细快照 Response VO")
@Data
public class ErpProductCategoryProcessRouteItemRespVO {
@Schema(description = "编号", example = "1")
private Long id;
@Schema(description = "产品分类编号", example = "1")
private Long categoryId;
@Schema(description = "工艺路线编号", example = "1")
private Long processRouteId;
@Schema(description = "工艺路线明细编号", example = "1")
private Long processRouteItemId;
@Schema(description = "排序,从 1 开始", example = "1")
private Integer sort;
@Schema(description = "工艺参数编号", example = "100")
private Long processParameterId;
@Schema(description = "工艺参数编码")
private String processParameterCode;
@Schema(description = "工艺参数名称")
private String processParameterName;
@Schema(description = "备注")
private String remark;
}

@ -11,6 +11,7 @@ import static cn.iocoder.yudao.module.erp.enums.DictTypeConstants.PRODUCT_CATEGO
import static cn.iocoder.yudao.module.system.enums.DictTypeConstants.COMMON_STATUS;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - ERP 产品分类 Response VO")
@Data
@ -51,4 +52,13 @@ public class ErpProductCategoryRespVO {
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "工艺路线 ID对应 /mes/process-route", example = "1")
private Long processRouteId;
@Schema(description = "工艺路线名称")
private String processRouteName;
@Schema(description = "工艺路线明细快照")
private List<ErpProductCategoryProcessRouteItemRespVO> processRouteItems;
}

@ -37,4 +37,7 @@ public class ErpProductCategorySaveReqVO {
@NotNull(message = "开启状态不能为空")
private Integer status;
@Schema(description = "工艺路线 ID对应 /mes/process-route", example = "1")
private Long processRouteId;
}

@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.erp.controller.admin.product.vo.product;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryProcessRouteItemRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - ERP 产品工艺路线快照 Response VO")
@Data
public class ErpProductProcessRouteRespVO {
@Schema(description = "产品编号", example = "1")
private Long productId;
@Schema(description = "工艺路线 ID对应 /mes/process-route", example = "1")
private Long processRouteId;
@Schema(description = "工艺路线名称")
private String processRouteName;
@Schema(description = "工艺路线明细快照")
private List<ErpProductCategoryProcessRouteItemRespVO> processRouteItems;
}

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.erp.controller.admin.product.vo.product;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryProcessRouteItemRespVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
@ -162,4 +163,13 @@ public class ErpProductRespVO extends ErpProductDO {
@Schema(description = "默认供应商 ID", example = "1")
private Long defaultSupplierId;
@Schema(description = "产品分类关联的工艺路线 ID对应 /mes/process-route", example = "1")
private Long processRouteId;
@Schema(description = "产品分类关联的工艺路线名称")
private String processRouteName;
@Schema(description = "产品分类保存的工艺路线明细快照")
private List<ErpProductCategoryProcessRouteItemRespVO> processRouteItems;
}

@ -57,4 +57,13 @@ public class ErpProductCategoryDO extends BaseDO {
*/
private Integer status;
/**
* 线 ID
*/
private Long processRouteId;
/**
* 线
*/
private String processRouteName;
}

@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.erp.dal.dataobject.product;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
/**
* ERP 线 DO
*/
@TableName("erp_product_category_process_route_item")
@KeySequence("erp_product_category_process_route_item_seq")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ErpProductCategoryProcessRouteItemDO extends BaseDO {
@TableId
private Long id;
private Long categoryId;
private Long processRouteId;
private Long processRouteItemId;
private Integer sort;
private Long processParameterId;
private String processParameterCode;
private String processParameterName;
private String remark;
}

@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.erp.dal.mysql.product;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryProcessRouteItemDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ErpProductCategoryProcessRouteItemMapper extends BaseMapperX<ErpProductCategoryProcessRouteItemDO> {
default List<ErpProductCategoryProcessRouteItemDO> selectListByCategoryId(Long categoryId) {
return selectList(new LambdaQueryWrapperX<ErpProductCategoryProcessRouteItemDO>()
.eq(ErpProductCategoryProcessRouteItemDO::getCategoryId, categoryId)
.orderByAsc(ErpProductCategoryProcessRouteItemDO::getSort)
.orderByAsc(ErpProductCategoryProcessRouteItemDO::getId));
}
default void deleteByCategoryId(Long categoryId) {
delete(new LambdaQueryWrapperX<ErpProductCategoryProcessRouteItemDO>()
.eq(ErpProductCategoryProcessRouteItemDO::getCategoryId, categoryId));
}
}

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.erp.service.product;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryListReqVO;
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;
@ -49,6 +50,10 @@ public interface ErpProductCategoryService {
*/
ErpProductCategoryDO getProductCategory(Long id);
ErpProductCategoryRespVO getProductCategoryResp(Long id);
ErpProductCategoryRespVO buildProductCategoryResp(ErpProductCategoryDO category);
/**
*
*
@ -84,4 +89,4 @@ public interface ErpProductCategoryService {
*/
ErpProductCategoryDO getProductCategoryByName(String name);
}
}

@ -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);
}
}
}

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.erp.service.product;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductImportExcelVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductProcessRouteRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductImportRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductListReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductPageReqVO;
@ -67,6 +68,8 @@ public interface ErpProductService {
ErpProductRespVO getProduct(Long id, String code);
ErpProductProcessRouteRespVO getProductProcessRoute(Long productId);
/**
* VO
*

@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.common.enums.CodeTypeEnum;
import cn.iocoder.yudao.module.common.enums.QrcodeBizTypeEnum;
import cn.iocoder.yudao.module.common.service.qrcordrecord.QrcodeRecordService;
import cn.iocoder.yudao.module.erp.controller.admin.autocode.util.AutoCodeUtil;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.*;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpPackagingSchemeDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
@ -417,6 +418,12 @@ public class ErpProductServiceImpl implements ErpProductService {
.ifPresent(item -> respVO.setDefaultSupplierId(item.getSupplierId()));
if (erpProductCategoryDO !=null ){
respVO.setCategoryType(erpProductCategoryDO.getType());
ErpProductCategoryRespVO categoryRespVO = productCategoryService.buildProductCategoryResp(erpProductCategoryDO);
if (categoryRespVO != null) {
respVO.setProcessRouteId(categoryRespVO.getProcessRouteId());
respVO.setProcessRouteName(categoryRespVO.getProcessRouteName());
respVO.setProcessRouteItems(categoryRespVO.getProcessRouteItems());
}
}
if (respVO.getPurchaseUnitId() != null && respVO.getPurchaseUnitName() == null) {
ErpProductUnitDO purchaseUnit = productUnitService.getProductUnit(respVO.getPurchaseUnitId());
@ -522,6 +529,27 @@ public class ErpProductServiceImpl implements ErpProductService {
throw exception(PRODUCT_NOT_EXISTS);
}
@Override
public ErpProductProcessRouteRespVO getProductProcessRoute(Long productId) {
ErpProductDO product = productMapper.selectById(productId);
if (product == null) {
return null;
}
ErpProductProcessRouteRespVO respVO = new ErpProductProcessRouteRespVO();
respVO.setProductId(productId);
Long categoryId = product.getSubCategoryId() != null ? product.getSubCategoryId() : product.getCategoryId();
if (categoryId == null) {
return respVO;
}
ErpProductCategoryRespVO categoryRespVO = productCategoryService.buildProductCategoryResp(productCategoryMapper.selectById(categoryId));
if (categoryRespVO != null) {
respVO.setProcessRouteId(categoryRespVO.getProcessRouteId());
respVO.setProcessRouteName(categoryRespVO.getProcessRouteName());
respVO.setProcessRouteItems(categoryRespVO.getProcessRouteItems());
}
return respVO;
}
private boolean isSpareProductCategory(ErpProductRespVO product) {
Long categoryId = product.getSubCategoryId() != null ? product.getSubCategoryId() : product.getCategoryId();
if (categoryId == null) {

@ -0,0 +1,12 @@
package cn.iocoder.yudao.module.mes.api.processroute;
import cn.iocoder.yudao.module.mes.api.processroute.dto.ProcessRouteSnapshotRespDTO;
/**
* 线 API
*/
public interface ProcessRouteApi {
ProcessRouteSnapshotRespDTO getProcessRouteSnapshot(Long id);
}

@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.mes.api.processroute.dto;
import lombok.Data;
/**
* 线 DTO
*/
@Data
public class ProcessRouteItemSnapshotRespDTO {
private Long id;
private Long routeId;
private Integer sort;
private Long processParameterId;
private String processParameterCode;
private String processParameterName;
private String remark;
}

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.mes.api.processroute.dto;
import lombok.Data;
import java.util.List;
/**
* 线 DTO
*/
@Data
public class ProcessRouteSnapshotRespDTO {
private Long id;
private String code;
private String name;
private List<ProcessRouteItemSnapshotRespDTO> items;
}

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.mes.api.processroute;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.api.processroute.dto.ProcessRouteItemSnapshotRespDTO;
import cn.iocoder.yudao.module.mes.api.processroute.dto.ProcessRouteSnapshotRespDTO;
import cn.iocoder.yudao.module.mes.dal.dataobject.processroute.ProcessRouteDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.processroute.ProcessRouteItemDO;
import cn.iocoder.yudao.module.mes.dal.mysql.processroute.ProcessRouteItemMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.processroute.ProcessRouteMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 线 API
*/
@Service
public class ProcessRouteApiImpl implements ProcessRouteApi {
@Resource
private ProcessRouteMapper processRouteMapper;
@Resource
private ProcessRouteItemMapper processRouteItemMapper;
@Override
public ProcessRouteSnapshotRespDTO getProcessRouteSnapshot(Long id) {
if (id == null) {
return null;
}
ProcessRouteDO processRoute = processRouteMapper.selectById(id);
if (processRoute == null) {
return null;
}
ProcessRouteSnapshotRespDTO respDTO = BeanUtils.toBean(processRoute, ProcessRouteSnapshotRespDTO.class);
List<ProcessRouteItemDO> items = processRouteItemMapper.selectListByRouteId(id);
respDTO.setItems(BeanUtils.toBean(items, ProcessRouteItemSnapshotRespDTO.class));
return respDTO;
}
}
Loading…
Cancel
Save