fix:修改配方管理-配方配置的新增和编辑逻辑

plp
86158 1 month ago
parent fdba3ea563
commit 7f0031a589

@ -59,4 +59,10 @@ public class RecipeRespVO {
@Schema(description = "设备Id")
private Long machineId;
@Schema(description = "配方类型ID", example = "1001")
private Long recipeTypeId;
@Schema(description = "关联产品ID", example = "1001")
private Long productId;
}

@ -40,4 +40,10 @@ public class RecipeSaveReqVO {
@Schema(description = "设备Id")
private Long machineId;
@Schema(description = "配方类型ID", example = "1001")
private Long recipeTypeId;
@Schema(description = "关联产品ID", example = "1001")
private Long productId;
}

@ -61,9 +61,19 @@ public class RecipeDO extends BaseDO {
private String dataUnit;
/**
*
* ID
*/
private Long machineId;
/**
* ID
*/
private Long productId;
/**
* ID
*/
private Long recipeTypeId;

@ -105,10 +105,14 @@ import cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.iot.controller.admin.recipe.vo.RecipePageReqVO;
import cn.iocoder.yudao.module.iot.controller.admin.recipe.vo.RecipeRespVO;
import cn.iocoder.yudao.module.iot.controller.admin.recipe.vo.RecipeSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.recipe.RecipeDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.recipetype.RecipeTypeDO;
import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper;
import cn.iocoder.yudao.module.iot.dal.mysql.recipe.RecipeMapper;
import cn.iocoder.yudao.module.iot.service.recipetype.RecipeTypeService;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@ -138,6 +142,10 @@ public class RecipeServiceImpl implements RecipeService {
private RecipeMapper recipeMapper;
@Resource
private DeviceMapper deviceMapper; // 注入现有DeviceMapper
@Resource
private ErpProductService erpProductService;
@Resource
private RecipeTypeService recipeTypeService;
// ========== 原有方法保持不变 ==========
@Override
@ -152,7 +160,38 @@ public class RecipeServiceImpl implements RecipeService {
if (exists) {
throw new ServiceException(ErrorCodeConstants.RECIPE_CODE_DUPLICATE);
}
// 根据 ID 获取对应的名称
String productName = null;
if (createReqVO.getProductId() != null) {
ErpProductDO product = erpProductService.getProduct(createReqVO.getProductId());
if (product != null) {
productName = product.getName();
}
}
String machineName = null;
if (createReqVO.getMachineId() != null) {
DeviceDO device = deviceMapper.selectById(createReqVO.getMachineId());
if (device != null) {
machineName = device.getDeviceName();
}
}
String recipeType = null;
if (createReqVO.getRecipeTypeId() != null) {
RecipeTypeDO recipeTypeDO = recipeTypeService.getRecipeType(createReqVO.getRecipeTypeId());
if (recipeTypeDO != null) {
recipeType = recipeTypeDO.getName();
}
}
// 创建配方对象并设置属性
RecipeDO recipe = BeanUtils.toBean(createReqVO, RecipeDO.class);
recipe.setProductName(productName);
recipe.setMachineName(machineName);
recipe.setRecipeType(recipeType);
recipeMapper.insert(recipe);
return recipe.getId();
}
@ -160,7 +199,38 @@ public class RecipeServiceImpl implements RecipeService {
@Override
public void updateRecipe(RecipeSaveReqVO updateReqVO) {
validateRecipeExists(updateReqVO.getId());
// 根据 ID 获取对应的名称
String productName = null;
if (updateReqVO.getProductId() != null) {
ErpProductDO product = erpProductService.getProduct(updateReqVO.getProductId());
if (product != null) {
productName = product.getName();
}
}
String machineName = null;
if (updateReqVO.getMachineId() != null) {
DeviceDO device = deviceMapper.selectById(updateReqVO.getMachineId());
if (device != null) {
machineName = device.getDeviceName();
}
}
String recipeType = null;
if (updateReqVO.getRecipeTypeId() != null) {
RecipeTypeDO recipeTypeDO = recipeTypeService.getRecipeType(updateReqVO.getRecipeTypeId());
if (recipeTypeDO != null) {
recipeType = recipeTypeDO.getName();
}
}
// 创建更新对象并设置属性
RecipeDO updateObj = BeanUtils.toBean(updateReqVO, RecipeDO.class);
updateObj.setProductName(productName);
updateObj.setMachineName(machineName);
updateObj.setRecipeType(recipeType);
recipeMapper.updateById(updateObj);
}

Loading…
Cancel
Save