| | |
| | | return false; |
| | | } |
| | | try { |
| | | // 检查是否已存在 |
| | | GlassInfo existing = baseMapper.selectByGlassId(glassInfo.getGlassId()); |
| | | // 查询包括逻辑删除的记录 |
| | | GlassInfo existing = baseMapper.selectByGlassIdIncludingDeleted(glassInfo.getGlassId()); |
| | | if (existing != null) { |
| | | // 存在则更新 |
| | | glassInfo.setId(existing.getId()); |
| | | // 保留原始创建信息 |
| | | if (glassInfo.getCreatedTime() == null) { |
| | |
| | | if (glassInfo.getCreatedBy() == null) { |
| | | glassInfo.setCreatedBy(existing.getCreatedBy()); |
| | | } |
| | | // 更新为当前时间 |
| | | // 设置更新时间 |
| | | if (glassInfo.getUpdatedTime() == null) { |
| | | glassInfo.setUpdatedTime(new Date()); |
| | | } |
| | | if (glassInfo.getUpdatedBy() == null) { |
| | | glassInfo.setUpdatedBy("system"); |
| | | } |
| | | return updateById(glassInfo); |
| | | |
| | | if (existing.getIsDeleted() != null && existing.getIsDeleted() != 0) { |
| | | log.info("恢复逻辑删除的玻璃信息: glassId={}, id={}", glassInfo.getGlassId(), existing.getId()); |
| | | int updatedRows = baseMapper.restoreAndUpdateById( |
| | | existing.getId(), |
| | | glassInfo.getGlassId(), |
| | | glassInfo.getGlassLength(), |
| | | glassInfo.getGlassWidth(), |
| | | glassInfo.getGlassThickness(), |
| | | glassInfo.getStatus(), |
| | | glassInfo.getState(), |
| | | glassInfo.getEngineeringId(), |
| | | glassInfo.getUpdatedTime() != null ? glassInfo.getUpdatedTime() : new Date(), |
| | | glassInfo.getUpdatedBy() != null ? glassInfo.getUpdatedBy() : "system" |
| | | ); |
| | | boolean updated = updatedRows > 0; |
| | | log.info("恢复逻辑删除记录结果: glassId={}, updatedRows={}, updated={}", |
| | | glassInfo.getGlassId(), updatedRows, updated); |
| | | if (!updated) { |
| | | log.error("恢复逻辑删除记录失败,可能原因:更新条件不匹配或数据异常, glassId={}, id={}", |
| | | glassInfo.getGlassId(), existing.getId()); |
| | | } |
| | | return updated; |
| | | } else { |
| | | // 正常更新 |
| | | return updateById(glassInfo); |
| | | } |
| | | } else { |
| | | // 不存在则新增 |
| | | Date now = new Date(); |
| | | if (glassInfo.getCreatedTime() == null) { |
| | | glassInfo.setCreatedTime(now); |
| | |
| | | } |
| | | if (glassInfo.getUpdatedBy() == null) { |
| | | glassInfo.setUpdatedBy("system"); |
| | | } |
| | | if (glassInfo.getIsDeleted() == null) { |
| | | glassInfo.setIsDeleted(0); |
| | | } |
| | | return save(glassInfo); |
| | | } |
| | |
| | | return true; |
| | | } |
| | | try { |
| | | int successCount = 0; |
| | | int failCount = 0; |
| | | for (GlassInfo glassInfo : glassInfos) { |
| | | saveOrUpdateGlassInfo(glassInfo); |
| | | boolean result = saveOrUpdateGlassInfo(glassInfo); |
| | | if (result) { |
| | | successCount++; |
| | | } else { |
| | | failCount++; |
| | | log.warn("保存或更新玻璃信息失败: glassId={}", glassInfo != null ? glassInfo.getGlassId() : "null"); |
| | | } |
| | | } |
| | | return true; |
| | | log.info("批量保存或更新玻璃信息完成: 总数={}, 成功={}, 失败={}", glassInfos.size(), successCount, failCount); |
| | | return failCount == 0; |
| | | } catch (Exception e) { |
| | | log.error("批量保存或更新玻璃信息失败", e); |
| | | return false; |
| | |
| | | } |
| | | |
| | | if (!glassInfos.isEmpty()) { |
| | | batchSaveOrUpdateGlassInfo(glassInfos); |
| | | log.info("已保存 {} 条玻璃信息到本地数据库,工程号: {}", glassInfos.size(), engineeringId); |
| | | boolean success = batchSaveOrUpdateGlassInfo(glassInfos); |
| | | if (success) { |
| | | log.info("已保存 {} 条玻璃信息到本地数据库,工程号: {}", glassInfos.size(), engineeringId); |
| | | } else { |
| | | log.error("保存玻璃信息到本地数据库失败,工程号: {}, 总数: {}", engineeringId, glassInfos.size()); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | try { |
| | | // 先查询要删除的数量(删除前) |
| | | LambdaQueryWrapper<GlassInfo> countWrapper = new LambdaQueryWrapper<>(); |
| | | countWrapper.eq(GlassInfo::getEngineeringId, engineeringId.trim()) |
| | | .eq(GlassInfo::getIsDeleted, 0); // 查询未删除的记录 |
| | | countWrapper.eq(GlassInfo::getEngineeringId, engineeringId.trim()); |
| | | long count = this.count(countWrapper); |
| | | |
| | | // 使用MyBatis-Plus的remove方法,会根据@TableLogic自动进行逻辑删除 |
| | | LambdaQueryWrapper<GlassInfo> removeWrapper = new LambdaQueryWrapper<>(); |
| | | removeWrapper.eq(GlassInfo::getEngineeringId, engineeringId.trim()) |
| | | .eq(GlassInfo::getIsDeleted, 0); // 只删除未删除的记录 |
| | | removeWrapper.eq(GlassInfo::getEngineeringId, engineeringId.trim()); |
| | | |
| | | boolean result = this.remove(removeWrapper); |
| | | if (result) { |