| | |
| | | */ |
| | | @Select("SELECT * FROM glass_info WHERE engineering_id = #{engineeringId} AND is_deleted = 0") |
| | | List<GlassInfo> selectByEngineeringId(@Param("engineeringId") String engineeringId); |
| | | |
| | | /** |
| | | * 根据玻璃ID查询玻璃信息(包括逻辑删除的记录) |
| | | * |
| | | * @param glassId 玻璃ID |
| | | * @return 玻璃信息 |
| | | */ |
| | | @Select("SELECT * FROM glass_info WHERE glass_id = #{glassId} LIMIT 1") |
| | | GlassInfo selectByGlassIdIncludingDeleted(@Param("glassId") String glassId); |
| | | |
| | | /** |
| | | * 恢复逻辑删除的记录并更新字段(绕过逻辑删除拦截器) |
| | | * |
| | | * @param id 记录ID |
| | | * @param glassId 玻璃ID |
| | | * @param glassLength 玻璃长度 |
| | | * @param glassWidth 玻璃宽度 |
| | | * @param glassThickness 玻璃厚度 |
| | | * @param status 状态 |
| | | * @param state 状态值 |
| | | * @param engineeringId 工程号 |
| | | * @param updatedTime 更新时间 |
| | | * @param updatedBy 更新人 |
| | | * @return 更新行数 |
| | | */ |
| | | @org.apache.ibatis.annotations.Update("UPDATE glass_info SET " + |
| | | "is_deleted = 0, " + |
| | | "glass_id = #{glassId}, " + |
| | | "glass_length = #{glassLength}, " + |
| | | "glass_width = #{glassWidth}, " + |
| | | "glass_thickness = #{glassThickness}, " + |
| | | "status = #{status}, " + |
| | | "state = #{state}, " + |
| | | "engineering_id = #{engineeringId}, " + |
| | | "updated_time = #{updatedTime}, " + |
| | | "updated_by = #{updatedBy} " + |
| | | "WHERE id = #{id}") |
| | | int restoreAndUpdateById(@Param("id") Long id, |
| | | @Param("glassId") String glassId, |
| | | @Param("glassLength") Integer glassLength, |
| | | @Param("glassWidth") Integer glassWidth, |
| | | @Param("glassThickness") java.math.BigDecimal glassThickness, |
| | | @Param("status") String status, |
| | | @Param("state") Integer state, |
| | | @Param("engineeringId") String engineeringId, |
| | | @Param("updatedTime") java.util.Date updatedTime, |
| | | @Param("updatedBy") String updatedBy); |
| | | } |
| | | |
| | |
| | | import com.mes.device.mapper.EngineeringSequenceMapper; |
| | | import com.mes.device.service.EngineeringSequenceService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.dao.DuplicateKeyException; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | String sequenceStr = engineeringId.substring(engineeringId.length() - 2); |
| | | int sequence = Integer.parseInt(sequenceStr); |
| | | |
| | | // 检查是否已存在 |
| | | EngineeringSequence existing = baseMapper.selectByEngineeringId(engineeringId); |
| | | |
| | | EngineeringSequence engineeringSequence = new EngineeringSequence(); |
| | | engineeringSequence.setEngineeringId(engineeringId); |
| | | engineeringSequence.setDate(date); |
| | | engineeringSequence.setSequence(sequence); |
| | | |
| | | boolean result; |
| | | if (existing != null) { |
| | | // 如果已存在,则更新 |
| | | engineeringSequence.setId(existing.getId()); |
| | | // 保留原始创建信息 |
| | | engineeringSequence.setCreatedTime(existing.getCreatedTime()); |
| | | engineeringSequence.setCreatedBy(existing.getCreatedBy()); |
| | | // 更新为当前时间 |
| | | engineeringSequence.setUpdatedTime(new Date()); |
| | | engineeringSequence.setUpdatedBy("system"); |
| | | result = updateById(engineeringSequence); |
| | | if (result) { |
| | | log.info("更新工程号成功: engineeringId={}, date={}, sequence={}", engineeringId, date, sequence); |
| | | } else { |
| | | log.error("更新工程号失败: engineeringId={}, date={}, sequence={}", engineeringId, date, sequence); |
| | | } |
| | | } else { |
| | | // 如果不存在,则插入 |
| | | engineeringSequence.setCreatedTime(new Date()); |
| | | engineeringSequence.setUpdatedTime(new Date()); |
| | | engineeringSequence.setCreatedBy("system"); |
| | | engineeringSequence.setUpdatedBy("system"); |
| | | |
| | | boolean result = save(engineeringSequence); |
| | | |
| | | result = save(engineeringSequence); |
| | | if (result) { |
| | | log.info("保存工程号成功: engineeringId={}, date={}, sequence={}", engineeringId, date, sequence); |
| | | } else { |
| | | log.error("保存工程号失败: engineeringId={}, date={}, sequence={}", engineeringId, date, sequence); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } catch (DuplicateKeyException dup) { |
| | | log.error("保存工程号唯一键冲突: date={}, engineeringId={}", date, engineeringId, dup); |
| | | throw new RuntimeException("保存工程号失败", dup); |
| | | } catch (Exception e) { |
| | | log.error("保存工程号失败, date={}, engineeringId={}", date, engineeringId, e); |
| | | throw new RuntimeException("保存工程号失败", e); |
| | |
| | | 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); |
| | | 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) { |
| | |
| | | VehicleStatus status = statusManager.getVehicleStatus(deviceId); |
| | | if (status != null && !status.isAvailable()) { |
| | | // 对于 feedGlass 操作,如果状态是 EXECUTING,允许继续执行 |
| | | // 因为定时器可能会重复调用,或者需要等待任务完成 |
| | | if ("feedGlass".equals(operation) && status.isExecuting()) { |
| | | log.debug("车辆 {} 当前状态为 EXECUTING,但允许继续执行 feedGlass(定时器重复调用)", deviceId); |
| | | // 允许继续执行,不返回错误 |