大家都遇到过保存时校验“柜体类型+产品名称+产品类型+工序”四个字段的信息与其他数据不可重复;
编辑也是校验“柜体类型+产品名称+产品类型+工序”四个字段的信息与其他数据不可重复;
下面上代码
以下是保存的时候
@Override
@Transactional(rollbackFor = Exception.class)
public boolean addProduceExecute(FtProduceExecuteDTO ftProduceExecuteDTO) {
Assert.notNull(ftProduceExecuteDTO, "produceExecuteDTO must not be null");
if (CollectionUtil.isEmpty(ftProduceExecuteDTO.getProduceExecuteDetails())) {
throw new RuntimeException("生产记录执行要求明细信息为空");
}
/**
*保存时校验“柜体类型+产品名称+产品类型+工序”四个字段的信息与其他数据不可重复;
*/
int count = this.count(Wrappers.<ProduceExecute>lambdaQuery().eq(ProduceExecute::getCabinetType, ftProduceExecuteDTO.getCabinetType()).
eq(ProduceExecute::getProduceType, ftProduceExecuteDTO.getProduceType()).
eq(ProduceExecute::getProductName, ftProduceExecuteDTO.getProductName()).
eq(ProduceExecute::getBomPropertyId, ftProduceExecuteDTO.getBomPropertyId()));
if (count > 0) {
log.error("体类型+产品名称+产品类型+工序重复 数据信息{}", ftProduceExecuteDTO);
throw new RuntimeException("生产记录执行要求信息重复");
}
this.save(ftProduceExecuteDTO);
executeDetailInfosHandel(ftProduceExecuteDTO.getProduceExecuteDetails(), ftProduceExecuteDTO.getProduceExecuteId());
return iProduceExecuteDetailService.saveBatch(ftProduceExecuteDTO.getProduceExecuteDetails());
}
下面是编辑的
@Override
@Transactional(rollbackFor = Exception.class)
public boolean addProduceExecute(FtProduceExecuteDTO ftProduceExecuteDTO) {
Assert.notNull(ftProduceExecuteDTO, "produceExecuteDTO must not be null");
if (CollectionUtil.isEmpty(ftProduceExecuteDTO.getProduceExecuteDetails())) {
throw new RuntimeException("生产记录执行要求明细信息为空");
}
/**
*保存时校验“柜体类型+产品名称+产品类型+工序”四个字段的信息与其他数据不可重复;
*/
int count = this.count(Wrappers.<ProduceExecute>lambdaQuery().eq(ProduceExecute::getCabinetType, ftProduceExecuteDTO.getCabinetType()).
eq(ProduceExecute::getProduceType, ftProduceExecuteDTO.getProduceType()).
eq(ProduceExecute::getProductName, ftProduceExecuteDTO.getProductName()).
eq(ProduceExecute::getBomPropertyId, ftProduceExecuteDTO.getBomPropertyId()));
if (count > 0) {
log.error("体类型+产品名称+产品类型+工序重复 数据信息{}", ftProduceExecuteDTO);
throw new RuntimeException("生产记录执行要求信息重复");
}
this.save(ftProduceExecuteDTO);
executeDetailInfosHandel(ftProduceExecuteDTO.getProduceExecuteDetails(), ftProduceExecuteDTO.getProduceExecuteId());
return iProduceExecuteDetailService.saveBatch(ftProduceExecuteDTO.getProduceExecuteDetails());
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateProduceExecute(FtProduceExecuteDTO ftProduceExecuteDTO) {
Assert.notNull(ftProduceExecuteDTO, "produceExecuteDTO must not be null");
Assert.notNull(ftProduceExecuteDTO.getProduceExecuteId(), "produceExecuteId must not be null");
if (CollectionUtil.isEmpty(ftProduceExecuteDTO.getProduceExecuteDetails())) {
throw new RuntimeException("生产记录执行要求明细信息为空");
}
ProduceExecute produceExecute = this.getById(ftProduceExecuteDTO.getProduceExecuteId());
if (ObjectUtils.isEmpty(produceExecute)) {
throw new RuntimeException("生产记录执行要求信息不存在");
}
//判断车间编码是否重复
if (!(StringUtils.equals(produceExecute.getCabinetType(), ftProduceExecuteDTO.getCabinetType())
&& StringUtils.equals(produceExecute.getProduceType(), ftProduceExecuteDTO.getProduceType())
&& StringUtils.equals(produceExecute.getProductName(), ftProduceExecuteDTO.getProductName())
&& produceExecute.getBomPropertyId().compareTo(ftProduceExecuteDTO.getBomPropertyId())==0 )) {
/**
*保存时校验“柜体类型+产品名称+产品类型+工序”四个字段的信息与其他数据不可重复;
*/
int count = this.count(Wrappers.<ProduceExecute>lambdaQuery().eq(ProduceExecute::getCabinetType, ftProduceExecuteDTO.getCabinetType()).
eq(ProduceExecute::getProduceType, ftProduceExecuteDTO.getProduceType()).
eq(ProduceExecute::getProductName, ftProduceExecuteDTO.getProductName()).
eq(ProduceExecute::getBomPropertyId, ftProduceExecuteDTO.getBomPropertyId()));
if (count > 0) {
log.error("体类型+产品名称+产品类型+工序重复 数据信息{}", ftProduceExecuteDTO);
throw new RuntimeException("生产记录执行要求信息重复");
}
}
this.updateById(ftProduceExecuteDTO);
iProduceExecuteDetailService.remove(Wrappers.<ProduceExecuteDetail>lambdaQuery().eq(ProduceExecuteDetail::getProduceExecuteId, ftProduceExecuteDTO.getProduceExecuteId()));
executeDetailInfosHandel(ftProduceExecuteDTO.getProduceExecuteDetails(), ftProduceExecuteDTO.getProduceExecuteId());
return iProduceExecuteDetailService.saveBatch(ftProduceExecuteDTO.getProduceExecuteDetails());
}