¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.basic.mapper.ProductPartMapper; |
| | | import com.ruoyi.basic.mapper.StructureTestObjectPartMapper; |
| | | import com.ruoyi.basic.pojo.ProductPart; |
| | | import com.ruoyi.basic.pojo.StructureTestObjectPart; |
| | | import com.ruoyi.basic.service.ProductPartService; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | @Transactional |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class ProductPartServiceImpl extends ServiceImpl<ProductPartMapper, ProductPart> implements ProductPartService { |
| | | |
| | | private ProductPartMapper productPartMapper; |
| | | private StructureTestObjectPartMapper structureTestObjectPartMapper; |
| | | |
| | | |
| | | @Override |
| | | public IPage<ProductPart> selectByProductId(IPage<ProductPart> page,ProductPart productPart) { |
| | | return productPartMapper.selectListByProductId(page, QueryWrappers.queryWrappers(productPart),productPart.getProductId()); |
| | | } |
| | | |
| | | @Override |
| | | public void addProductPart(ProductPart productPart) { |
| | | if (productPart.getProductId() == null) { |
| | | throw new BaseException("缺å°äº§å对象id"); |
| | | } |
| | | this.isPartNoExist(productPart.getPartNo(), productPart.getProductId(), null); |
| | | productPartMapper.insert(productPart); |
| | | } |
| | | |
| | | @Override |
| | | public void updateProductPartById(ProductPart productPart) { |
| | | this.isPartNoExist(productPart.getPartNo(), productPart.getProductId(), productPart.getId()); |
| | | if (productPart.getProductId() == null) { |
| | | throw new BaseException("缺å°äº§å对象id"); |
| | | } |
| | | productPartMapper.updateById(productPart); |
| | | } |
| | | |
| | | // 夿é¶ä»¶å·æ¯å¦åå¨ |
| | | public void isPartNoExist(String partNo,Integer productId, Integer id) { |
| | | // é¶ä»¶å·å¯ä¸ ä½ä¸å¿
å¡« |
| | | if (StringUtils.isNotBlank(partNo)) { |
| | | Long count = productPartMapper.selectCount(new LambdaQueryWrapper<ProductPart>() |
| | | // .eq(ProductPart::getProductId, productId) |
| | | .eq(ProductPart::getPartNo, partNo) |
| | | .ne(id != null, ProductPart::getId, id)); |
| | | Long selectCount = structureTestObjectPartMapper.selectCount(Wrappers.<StructureTestObjectPart>lambdaQuery() |
| | | .eq(StructureTestObjectPart::getPartNo, partNo)); |
| | | if (count > 0 || selectCount > 0) { |
| | | throw new BaseException("该é¶ä»¶å·å·²ç»å®è¿æ£éªå¯¹è±¡"); |
| | | } |
| | | } else { |
| | | throw new BaseException("请è¾å
¥é¶ä»¶å·"); |
| | | } |
| | | } |
| | | } |