| | |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.dao.DuplicateKeyException; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | |
| | | @Override |
| | | public int addOrEditProductModel(ProductModelDto productModelDto) { |
| | | |
| | | if (productModelDto.getId() == null) { |
| | | ProductModel productModel = new ProductModel(); |
| | | BeanUtils.copyProperties(productModelDto, productModel); |
| | | return productModelMapper.insert(productModel); |
| | | } else { |
| | | return productModelMapper.updateById(productModelDto); |
| | | ProductModel productModel = new ProductModel(); |
| | | BeanUtils.copyProperties(productModelDto, productModel); |
| | | try { |
| | | if (productModelDto.getId() == null) { |
| | | int result = productModelMapper.insert(productModel); |
| | | productModelDto.setId(productModel.getId()); |
| | | return result; |
| | | } else { |
| | | int result = productModelMapper.updateById(productModel); |
| | | productModelDto.setId(productModel.getId()); |
| | | return result; |
| | | } |
| | | } catch (DuplicateKeyException e) { |
| | | // 捕获数据库唯一约束异常 |
| | | throw new RuntimeException("该产品已存在相同的规格型号和单位", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public int delProductModel(Long[] ids) { |