耗材重复绑定问题
This commit is contained in:
parent
ba06410d44
commit
74fee9a48e
|
|
@ -69,7 +69,7 @@ public class TbProskuConController {
|
|||
throw new Exception(be.getMessage());
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
throw new Exception("参数错误");
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -196,15 +196,31 @@ public class TbProskuConServiceImpl implements TbProskuConService {
|
|||
if (ObjectUtil.isNull(tbConsInfo) || ObjectUtil.isNull(tbConsInfo.getId())) {
|
||||
throw new BadRequestException("对应的耗材信息不存在");
|
||||
}
|
||||
TbProductSku sku = null;
|
||||
if (resource.getProductSkuId() != 0) {
|
||||
TbProductSku sku = tbProductSkuRepository.findById(resource.getProductSkuId()).orElseGet(TbProductSku::new);
|
||||
sku = tbProductSkuRepository.findById(resource.getProductSkuId()).orElseGet(TbProductSku::new);
|
||||
if (ObjectUtil.isNull(sku) || ObjectUtil.isNull(sku.getId())) {
|
||||
throw new BadRequestException("规格信息不存在");
|
||||
}
|
||||
}
|
||||
TbProskuCon tbConsInfo1 = new TbProskuCon();
|
||||
BeanUtil.copyProperties(resource,tbConsInfo1, CopyOptions.create().setIgnoreNullValue(true));
|
||||
newCons.add(tbConsInfo1);
|
||||
if (resource.getId() == null) {
|
||||
int count = tbProskuConRepository.countByConInfoIdAndProductSkuIdAndShopId(resource.getConInfoId(), resource.getProductSkuId(), resource.getShopId(), resource.getProductId());
|
||||
if (count <= 0) {
|
||||
BeanUtil.copyProperties(resource, tbConsInfo1, CopyOptions.create().setIgnoreNullValue(true));
|
||||
newCons.add(tbConsInfo1);
|
||||
} else {
|
||||
StringBuilder strResult = new StringBuilder(product.getName());
|
||||
if (sku != null) {
|
||||
strResult.append(" 规格" + sku.getSpecSnap());
|
||||
}
|
||||
strResult.append("与耗材 " + tbConsInfo.getConName() + " 的对应关系已存在");
|
||||
throw new BadRequestException(product.getName().concat("对应的").concat(Objects.nonNull(sku.getSpecSnap())?sku.getSpecSnap():"").concat("规格已存在"));
|
||||
}
|
||||
}else {
|
||||
BeanUtil.copyProperties(resource,tbConsInfo1, CopyOptions.create().setIgnoreNullValue(true));
|
||||
newCons.add(tbConsInfo1);
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(newCons)) {
|
||||
tbProskuConRepository.saveAll(newCons);
|
||||
|
|
|
|||
Loading…
Reference in New Issue