| | |
| | | package com.ruoyi.basic.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | 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.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.dto.ProductPartDto; |
| | | import com.ruoyi.basic.mapper.ProductPartLogMapper; |
| | | import com.ruoyi.basic.pojo.ProductPartLog; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.basic.mapper.ProductPartMapper; |
| | |
| | | import com.ruoyi.basic.pojo.ProductPart; |
| | | import com.ruoyi.basic.pojo.StructureTestObjectPart; |
| | | import com.ruoyi.basic.service.ProductPartService; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Transactional |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class ProductPartServiceImpl extends ServiceImpl<ProductPartMapper, ProductPart> implements ProductPartService { |
| | | |
| | | private ProductPartMapper productPartMapper; |
| | | private ProductPartMapper productPartMapper; |
| | | private StructureTestObjectPartMapper structureTestObjectPartMapper; |
| | | |
| | | private ProductPartLogMapper productPartLogMapper; |
| | | |
| | | |
| | | @Override |
| | | public IPage<ProductPart> selectByProductId(IPage<ProductPart> page,ProductPart productPart) { |
| | | return productPartMapper.selectListByProductId(page, QueryWrappers.queryWrappers(productPart),productPart.getProductId()); |
| | | public IPage<ProductPart> selectByProductId(IPage<ProductPart> page, ProductPart productPart) { |
| | | return productPartMapper.selectListByProductId(page, QueryWrappers.queryWrappers(productPart), productPart.getProductId()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | throw new BaseException("缺少产品对象id"); |
| | | } |
| | | this.isPartNoExist(productPart.getPartNo(), productPart.getProductId(), null); |
| | | productPart.setReview("待复核"); |
| | | productPartMapper.insert(productPart); |
| | | } |
| | | |
| | | @Override |
| | | public void updateProductPartById(ProductPart productPart) { |
| | | public int updateProductPartById(ProductPart productPart) { |
| | | if (productPart.getProductId() == null) { |
| | | throw new BaseException("缺少产品对象id"); |
| | | } |
| | | // this.isPartNoExist(productPart.getPartNo(), productPart.getProductId(), null); |
| | | if (!"已复核".equals(productPart.getReview())) { |
| | | productPart.setReview("待复核"); |
| | | } |
| | | return productPartMapper.updateById(productPart); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> inspectionItems(String sample, String productName) { |
| | | // 优先处理两个参数均非空的场景 |
| | | if (StringUtils.isNotEmpty(productName) && StringUtils.isNotEmpty(sample)) { |
| | | //先差产品,有过有值直接返回,没值再查大类 |
| | | List<Map<String, Object>> result = productPartMapper.inspectionItems(productName); |
| | | return result.isEmpty() ? productPartMapper.inspectionItems(sample) : result; |
| | | } |
| | | |
| | | // 其他情况直接选取有效参数(优先productName)或空字符串 |
| | | String param = StringUtils.isNotEmpty(productName) ? productName : |
| | | StringUtils.isNotEmpty(sample) ? sample : ""; |
| | | return productPartMapper.inspectionItems(param); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public int productPartReviewById(ProductPartDto productPartDto) { |
| | | |
| | | int userId = SecurityUtils.getUserId().intValue(); |
| | | String username = SecurityUtils.getUsername(); |
| | | ProductPart productPart = productPartMapper.selectById(productPartDto.getId()); |
| | | this.isPartNoExist(productPart.getPartNo(), productPart.getProductId(), productPart.getId()); |
| | | if (productPart.getProductId() == null) { |
| | | throw new BaseException("缺少产品对象id"); |
| | | } |
| | | productPartMapper.updateById(productPart); |
| | | productPart.setReview("已复核"); |
| | | int num = productPartMapper.updateById(productPart); |
| | | if (num > 0) { |
| | | ProductPartLog productPartLog = new ProductPartLog(); |
| | | productPartLog.setProductPartId(productPart.getId()); |
| | | productPartLog.setOperName(username); |
| | | productPartLog.setOperId(userId); |
| | | productPartLog.setOperTime(LocalDateTime.now()); |
| | | productPartLog.setColor(productPart.getColor()); |
| | | productPartLog.setColorCode(productPart.getColorCode()); |
| | | productPartLog.setPartNo(productPart.getPartNo()); |
| | | productPartLog.setInspectionItem(productPart.getInspectionItem()); |
| | | productPartLog.setReview(productPart.getReview()); |
| | | productPartLogMapper.insert(productPartLog); |
| | | } |
| | | return num; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<ProductPartLog> productPartLogList(Page page, Integer id) { |
| | | return productPartLogMapper.selectPage(page, Wrappers.<ProductPartLog>lambdaQuery() |
| | | .eq(ProductPartLog::getProductPartId, id)); |
| | | } |
| | | |
| | | // 判断零件号是否存在 |
| | | public void isPartNoExist(String partNo,Integer productId, Integer id) { |
| | | public void isPartNoExist(String partNo, Integer productId, Integer id) { |
| | | // 零件号唯一 但不必填 |
| | | if (StringUtils.isNotBlank(partNo)) { |
| | | Long count = productPartMapper.selectCount(new LambdaQueryWrapper<ProductPart>() |