| | |
| | | |
| | | @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"); |
| | | |
| | | // 定义通用的产品部分对象 |
| | | Object productPart = null; |
| | | if ("对象".equals(productPartDto.getType())) { |
| | | productPart = structureTestObjectPartMapper.selectById(productPartDto.getId()); |
| | | if (productPart != null && ((StructureTestObjectPart) productPart).getTestObjectId() == null) { |
| | | throw new BaseException("缺少产品对象id"); |
| | | } |
| | | } else { |
| | | productPart = productPartMapper.selectById(productPartDto.getId()); |
| | | if (productPart != null && ((ProductPart) productPart).getProductId() == null) { |
| | | throw new BaseException("缺少产品对象id"); |
| | | } |
| | | } |
| | | productPart.setReview("已复核"); |
| | | int num = productPartMapper.updateById(productPart); |
| | | |
| | | if (productPart == null) { |
| | | return 0; |
| | | } |
| | | |
| | | // 设置审核状态 |
| | | if (productPart instanceof StructureTestObjectPart) { |
| | | ((StructureTestObjectPart) productPart).setReview("已复核"); |
| | | } else { |
| | | ((ProductPart) productPart).setReview("已复核"); |
| | | } |
| | | |
| | | // 更新产品部分信息 |
| | | int num = 0; |
| | | if (productPart instanceof StructureTestObjectPart) { |
| | | num = structureTestObjectPartMapper.updateById((StructureTestObjectPart) productPart); |
| | | } else { |
| | | num = productPartMapper.updateById((ProductPart) 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); |
| | | createOrUpdateProductPartLog(productPart, username, userId, productPartDto.getType(), productPartDto); |
| | | } |
| | | |
| | | return num; |
| | | } |
| | | |
| | | private void createOrUpdateProductPartLog(Object productPart, String username, int userId, String type, ProductPartDto productPartDto) { |
| | | ProductPartLog productPartLog = new ProductPartLog(); |
| | | if (productPart instanceof StructureTestObjectPart) { |
| | | StructureTestObjectPart part = (StructureTestObjectPart) productPart; |
| | | productPartLog.setProductPartId(part.getId()); |
| | | productPartLog.setColor(part.getColor()); |
| | | productPartLog.setColorCode(part.getColorCode()); |
| | | productPartLog.setPartNo(part.getPartNo()); |
| | | productPartLog.setInspectionItem(part.getInspectionItem()); |
| | | productPartLog.setReview(part.getReview()); |
| | | } else { |
| | | ProductPart part = (ProductPart) productPart; |
| | | productPartLog.setProductPartId(part.getId()); |
| | | productPartLog.setColor(part.getColor()); |
| | | productPartLog.setColorCode(part.getColorCode()); |
| | | productPartLog.setPartNo(part.getPartNo()); |
| | | productPartLog.setInspectionItem(part.getInspectionItem()); |
| | | productPartLog.setReview(part.getReview()); |
| | | } |
| | | productPartLog.setOperName(username); |
| | | productPartLog.setOperId(userId); |
| | | productPartLog.setOperTime(LocalDateTime.now()); |
| | | productPartLog.setType(type); |
| | | |
| | | // 检查是否存在相同 ProductPartId 的日志记录 |
| | | ProductPartLog existingLog = productPartLogMapper.selectOne(new LambdaQueryWrapper<ProductPartLog>().eq(ProductPartLog::getProductPartId, productPartDto.getId())); |
| | | if (existingLog != null) { |
| | | // 如果存在,更新记录 |
| | | productPartLog.setId(existingLog.getId()); // 设置更新记录的 ID |
| | | productPartLogMapper.updateById(productPartLog); |
| | | } else { |
| | | // 如果不存在,插入新记录 |
| | | productPartLogMapper.insert(productPartLog); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public IPage<ProductPartLog> productPartLogList(Page page, Integer id) { |
| | | public IPage<ProductPartLog> productPartLogList(Page page, Integer id, String type) { |
| | | return productPartLogMapper.selectPage(page, Wrappers.<ProductPartLog>lambdaQuery() |
| | | .eq(ProductPartLog::getProductPartId, id)); |
| | | .eq(ProductPartLog::getProductPartId, id) |
| | | .eq(ProductPartLog::getType, type)); |
| | | } |
| | | |
| | | // 判断零件号是否存在 |