| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | return result; |
| | | } |
| | | |
| | | // 工程号生成:使用数据库自增序号,避免重复 |
| | | // 工程号生成:每次导入都生成新的工程号(使用数据库自增序号,避免重复) |
| | | final String engineerId = engineeringSequenceService.generateAndSaveEngineeringId(new Date()); |
| | | final String filmsIdDefault = firstValue(excelRows, "filmsId", "白玻"); |
| | | final double thicknessDefault = parseDouble(firstValue(excelRows, "thickness"), 0d); |
| | |
| | | |
| | | List<Map<String, Object>> glassInfolList = excelRows.stream() |
| | | .flatMap(row -> { |
| | | int qty = (int) parseDouble(row.getOrDefault("quantity", 1), 1); |
| | | if (qty <= 0) qty = 1; |
| | | Object qtyObj = row.getOrDefault("quantity", 1); |
| | | int qty = parseDouble(qtyObj, 1) > 0 ? (int) parseDouble(qtyObj, 1) : 1; |
| | | |
| | | String glassId = str(row.get("glassId")); |
| | | String filmsId = strOrDefault(row.get("filmsId"), filmsIdDefaultFinal); |
| | | String flowCardId = str(row.get("flowCardId")); |
| | |
| | | double thickness = parseDouble(row.get("thickness"), thicknessDefaultFinal); |
| | | |
| | | int finalQty = qty; |
| | | log.info("解析到数量:row={}, quantity={}, 最终qty={}", row, qtyObj, finalQty); |
| | | return range(0, qty).mapToObj(idx -> { |
| | | String finalGlassId = finalQty > 1 ? glassId + "_" + (idx + 1) : glassId; |
| | | String finalFlowCardId = flowCardId.isEmpty() ? finalGlassId : flowCardId; |
| | | String baseGlassId = engineerIdFinal + glassId; |
| | | String finalGlassId = finalQty > 1 ? baseGlassId + "_" + (idx + 1) : baseGlassId; |
| | | |
| | | String baseFlowCardId = flowCardId.isEmpty() ? baseGlassId : flowCardId; |
| | | String finalFlowCardSequence = baseFlowCardId + "/" + (idx + 1); |
| | | String finalFlowCardId = baseFlowCardId; |
| | | |
| | | Map<String, Object> m = new HashMap<>(); |
| | | m.put("xAxis", 0); |
| | | m.put("xCoordinate", 0); |
| | |
| | | m.put("combine", 0); |
| | | m.put("markIcon", ""); |
| | | m.put("filmRemove", 0); |
| | | m.put("flowCardSequence", flowCardId + "/" + (idx + 1)); |
| | | m.put("flowCardSequence", finalFlowCardSequence); |
| | | m.put("process", ""); |
| | | m.put("rawAngle", 0); |
| | | m.put("graphNo", 0); |
| | |
| | | return Math.round(v * 100.0) / 100.0; |
| | | } |
| | | |
| | | @Override |
| | | public List<GlassInfo> getGlassInfosByEngineeringId(String engineeringId) { |
| | | if (engineeringId == null || engineeringId.trim().isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | try { |
| | | return baseMapper.selectByEngineeringId(engineeringId.trim()); |
| | | } catch (Exception e) { |
| | | log.error("根据工程号查询玻璃信息失败, engineeringId={}", engineeringId, e); |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void saveGlassInfosFromExcel(List<Map<String, Object>> excelRows, String engineeringId) { |
| | | if (excelRows == null || excelRows.isEmpty() || engineeringId == null || engineeringId.trim().isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | List<GlassInfo> glassInfos = new ArrayList<>(); |
| | | Date now = new Date(); |
| | | |
| | | for (Map<String, Object> row : excelRows) { |
| | | String glassId = str(row.get("glassId")); |
| | | if (glassId == null || glassId.trim().isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | int qty = (int) parseDouble(row.getOrDefault("quantity", 1), 1); |
| | | if (qty <= 0) qty = 1; |
| | | |
| | | double width = parseDouble(row.get("width"), 0d); |
| | | double height = parseDouble(row.get("height"), 0d); |
| | | double thickness = parseDouble(row.get("thickness"), 0d); |
| | | |
| | | // 与导入规则保持一致:glassId 前加工程号前缀,数量>1时追加序号 |
| | | String baseGlassId = engineeringId.trim() + glassId; |
| | | for (int idx = 0; idx < qty; idx++) { |
| | | String finalGlassId = qty > 1 ? baseGlassId + "_" + (idx + 1) : baseGlassId; |
| | | |
| | | GlassInfo glassInfo = new GlassInfo(); |
| | | glassInfo.setGlassId(finalGlassId); |
| | | glassInfo.setEngineeringId(engineeringId.trim()); |
| | | glassInfo.setGlassLength((int) Math.round(height)); |
| | | glassInfo.setGlassWidth((int) Math.round(width)); |
| | | glassInfo.setGlassThickness(BigDecimal.valueOf(thickness)); |
| | | glassInfo.setStatus(GlassInfo.Status.ACTIVE); |
| | | glassInfo.setState(0); |
| | | glassInfo.setCreatedTime(now); |
| | | glassInfo.setUpdatedTime(now); |
| | | glassInfo.setCreatedBy("system"); |
| | | glassInfo.setUpdatedBy("system"); |
| | | |
| | | glassInfos.add(glassInfo); |
| | | } |
| | | } |
| | | |
| | | if (!glassInfos.isEmpty()) { |
| | | batchSaveOrUpdateGlassInfo(glassInfos); |
| | | log.info("已保存 {} 条玻璃信息到本地数据库,工程号: {}", glassInfos.size(), engineeringId); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateGlassStateAfterScan(String glassId, Integer width, Integer height, Integer workLine) { |
| | | if (glassId == null || glassId.trim().isEmpty()) { |
| | | return false; |
| | | } |
| | | |
| | | try { |
| | | // 查询已存在的玻璃信息 |
| | | GlassInfo existing = baseMapper.selectByGlassId(glassId.trim()); |
| | | if (existing == null) { |
| | | log.debug("玻璃信息不存在,无法更新状态: glassId={}", glassId); |
| | | return false; |
| | | } |
| | | |
| | | // 更新状态为1(已扫码交互) |
| | | LambdaUpdateWrapper<GlassInfo> wrapper = new LambdaUpdateWrapper<>(); |
| | | wrapper.eq(GlassInfo::getGlassId, glassId.trim()) |
| | | .eq(GlassInfo::getIsDeleted, 0) |
| | | .set(GlassInfo::getState, 1) |
| | | .set(GlassInfo::getUpdatedTime, new Date()) |
| | | .set(GlassInfo::getUpdatedBy, "system"); |
| | | |
| | | // 如果提供了尺寸信息,也更新尺寸 |
| | | if (width != null) { |
| | | wrapper.set(GlassInfo::getGlassWidth, width); |
| | | } |
| | | if (height != null) { |
| | | wrapper.set(GlassInfo::getGlassLength, height); |
| | | } |
| | | if (workLine != null) { |
| | | wrapper.set(GlassInfo::getWorkLine, workLine); |
| | | } |
| | | |
| | | boolean updated = this.update(wrapper); |
| | | if (updated) { |
| | | log.info("已更新玻璃信息状态为已扫码交互: glassId={}, state=1", glassId); |
| | | } |
| | | return updated; |
| | | } catch (Exception e) { |
| | | log.error("更新玻璃信息状态失败: glassId={}", glassId, e); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int deleteGlassInfosByEngineeringId(String engineeringId) { |
| | | if (engineeringId == null || engineeringId.trim().isEmpty()) { |
| | | return 0; |
| | | } |
| | | |
| | | try { |
| | | // 先查询要删除的数量(删除前) |
| | | LambdaQueryWrapper<GlassInfo> countWrapper = new LambdaQueryWrapper<>(); |
| | | countWrapper.eq(GlassInfo::getEngineeringId, engineeringId.trim()) |
| | | .eq(GlassInfo::getIsDeleted, 0); // 查询未删除的记录 |
| | | long count = this.count(countWrapper); |
| | | |
| | | // 使用MyBatis-Plus的remove方法,会根据@TableLogic自动进行逻辑删除 |
| | | LambdaQueryWrapper<GlassInfo> removeWrapper = new LambdaQueryWrapper<>(); |
| | | removeWrapper.eq(GlassInfo::getEngineeringId, engineeringId.trim()) |
| | | .eq(GlassInfo::getIsDeleted, 0); // 只删除未删除的记录 |
| | | |
| | | boolean result = this.remove(removeWrapper); |
| | | if (result) { |
| | | log.info("已删除工程号下的玻璃信息: engineeringId={}, count={}", engineeringId, count); |
| | | return (int) count; |
| | | } |
| | | return 0; |
| | | } catch (Exception e) { |
| | | log.error("删除工程号下的玻璃信息失败: engineeringId={}", engineeringId, e); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |