| | |
| | | |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.pro.route.MesProRouteMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteDO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.product.MesProRouteProductSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProductDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; |
| | |
| | | |
| | | @Resource |
| | | private MesProRouteProductMapper routeProductMapper; |
| | | @Resource |
| | | private MesProRouteMapper routeMapper; |
| | | |
| | | @Resource |
| | | @Lazy |
| | |
| | | private MesMdItemTypeService itemTypeService; |
| | | @Resource |
| | | private MesWmWarehouseAreaService warehouseAreaService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void setTemplateReference(Long id) { |
| | | MesProRouteProductDO initial = routeProductMapper.selectById(id); |
| | | validateRouteProductExists(initial); |
| | | MesProRouteDO route = routeMapper.selectOne(new LambdaQueryWrapperX<MesProRouteDO>() |
| | | .eq(MesProRouteDO::getId, initial.getRouteId()).last("FOR UPDATE")); |
| | | if (route == null) throw exception(PRO_ROUTE_NOT_EXISTS); |
| | | MesProRouteProductDO current = routeProductMapper.selectById(id); |
| | | validateRouteProductExists(current); |
| | | if (!java.util.Objects.equals(current.getRouteId(), route.getId())) throw exception(PRO_ROUTE_PRODUCT_NOT_EXISTS); |
| | | if (!isFinishedProduct(current.getItemId())) throw exception(PRO_ROUTE_TEMPLATE_REFERENCE_NOT_FINISHED); |
| | | routeProductMapper.update(null, new LambdaUpdateWrapper<MesProRouteProductDO>() |
| | | .eq(MesProRouteProductDO::getRouteId, route.getId()) |
| | | .eq(MesProRouteProductDO::getTemplateReference, true) |
| | | .set(MesProRouteProductDO::getTemplateReference, false)); |
| | | if (routeProductMapper.updateById(new MesProRouteProductDO().setId(id).setTemplateReference(true)) != 1) { |
| | | throw exception(PRO_ROUTE_PRODUCT_NOT_EXISTS); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Long createRouteProduct(MesProRouteProductSaveReqVO createReqVO) { |
| | |
| | | } |
| | | } |
| | | |
| | | private boolean isFinishedProduct(Long itemId) { |
| | | MesMdItemDO item = itemService.validateItemExists(itemId); |
| | | MesMdItemTypeDO type = itemTypeService.getItemType(item.getItemTypeId()); |
| | | java.util.Set<Long> seen = new java.util.HashSet<>(); |
| | | while (type != null && seen.add(type.getId())) { |
| | | if ("FG".equals(type.getCode())) return true; |
| | | if (type.getParentId() == null || MesMdItemTypeDO.PARENT_ID_ROOT.equals(type.getParentId())) break; |
| | | type = itemTypeService.getItemType(type.getParentId()); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private void validateProductItem(Long itemId) { |
| | | MesMdItemDO item = itemService.validateItemExistsAndEnable(itemId); |
| | | MesMdItemTypeDO itemType = itemTypeService.getItemType(item.getItemTypeId()); |
| | | if (itemType == null || !MesMdItemTypeEnum.isProduct(itemType.getItemOrProduct())) { |
| | | if (itemType == null || !isFinishedProduct(itemId)) { |
| | | throw exception(PRO_ROUTE_PRODUCT_ITEM_TYPE_INVALID); |
| | | } |
| | | } |