| | |
| | | import com.example.erp.entity.userInfo.SysError; |
| | | import com.example.erp.mapper.pp.GlassOptimizeMapper; |
| | | import com.example.erp.service.userInfo.SysErrorService; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | List<Map<String, Object>> originalFilm = (List<Map<String, Object>>) object.get("originalFilm"); |
| | | glassOptimizeMapper.addOptimizeUse(originalFilm,projectId,"admin"); |
| | | |
| | | Map<String, Object> glassInfo = glassOptimizeMapper.getGlassInfo(projectId); |
| | | |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | String json = mapper.writeValueAsString(optimalResults); |
| | | glassOptimizeMapper.addOptimizeProjectFile(json,projectId,"admin"); |
| | |
| | | glassOptimizeMapper.addOptimizeLayout(objectMapList,projectId); |
| | | for(Map<String, Object> objectMap:objectMapList){ |
| | | List<Map<String, Object>> objectMap2 = (List<Map<String, Object>>) objectMap.get("glassDetails"); |
| | | //迭代玻璃明细集合删除余料 |
| | | //迭代玻璃明细集合处理余料和其他 |
| | | Iterator<Map<String, Object>> iterator = objectMap2.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Map<String, Object> map = iterator.next(); |
| | | if (map.get("isRemain").toString()=="true") { |
| | | iterator.remove(); |
| | | // 修改isRemain判断逻辑,支持数字0/1和字符串"0"/"1" |
| | | boolean isRemain = false; |
| | | if (map.containsKey("isRemain")) { |
| | | Object isRemainObj = map.get("isRemain"); |
| | | if (isRemainObj != null) { |
| | | if (isRemainObj instanceof Number) { |
| | | // 数字类型: 1表示true,0表示false |
| | | isRemain = ((Number) isRemainObj).intValue() == 1; |
| | | } else { |
| | | // 字符串类型: "1"表示true,"0"表示false |
| | | isRemain = "1".equals(isRemainObj.toString()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (isRemain) { |
| | | System.out.println( map); |
| | | if (glassInfo != null) { |
| | | String glassType = (String) glassInfo.get("glass_type"); |
| | | String glassThickness = (String) glassInfo.get("glass_thickness"); |
| | | // 余料存入optimizeoffcut |
| | | glassOptimizeMapper.addOptimizeOffcut(map, projectId, glassType, glassThickness); |
| | | } |
| | | iterator.remove(); // 从原列表中移除 |
| | | }else { |
| | | // 处理isRotate字段转换 (现在是0/1) |
| | | if (map.containsKey("isRotate")) { |
| | | Object isRotateObj = map.get("isRotate"); |
| | | if (isRotateObj != null) { |
| | | if (isRotateObj instanceof Number) { |
| | | // 直接使用数字值 |
| | | map.put("isRotate", ((Number) isRotateObj).intValue()); |
| | | } else { |
| | | // 字符串形式的"0"/"1" |
| | | String isRotateStr = isRotateObj.toString(); |
| | | if ("1".equals(isRotateStr)) { |
| | | map.put("isRotate", 1); |
| | | } else { |
| | | map.put("isRotate", 0); |
| | | } |
| | | } |
| | | } else { |
| | | map.put("isRotate", 0); // 默认值 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | return map; |
| | | } |
| | | |
| | | |
| | | public Boolean issuingProjects(String projectNo) throws JsonProcessingException { |
| | | boolean saveState=false; |
| | | try { |
| | | // 1. 创建URL对象 |
| | | URL url = new URL("http://localhost:88/api/loadGlass/engineering/importEngineer"); |
| | | |
| | | // 2. 打开连接 |
| | | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
| | | conn.setRequestMethod("POST"); |
| | | conn.setRequestProperty("Content-Type", "application/json"); |
| | | conn.setRequestProperty("Accept", "application/json"); |
| | | conn.setDoOutput(true); |
| | | |
| | | // 3. 准备请求体 |
| | | Map<String, Object> optimizeProject=glassOptimizeMapper.selectOptimizeProject(projectNo); |
| | | optimizeProject.put("engineeringRawQueueList", glassOptimizeMapper.selectOptimizeLayout(projectNo)); |
| | | optimizeProject.put("glassInfolList", glassOptimizeMapper.selectOptimizeDetail(projectNo)); |
| | | optimizeProject.put("flowCardInfoList", glassOptimizeMapper.selectFlowCardInfoList(projectNo)); |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | mapper.registerModule(new JavaTimeModule()); |
| | | String jsonInputString = mapper.writeValueAsString(optimizeProject); |
| | | |
| | | //发送请求 |
| | | try(OutputStream os = conn.getOutputStream()) { |
| | | byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); |
| | | os.write(input, 0, input.length); |
| | | } |
| | | |
| | | // 获取响应 |
| | | try(BufferedReader br = new BufferedReader( |
| | | new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { |
| | | StringBuilder response = new StringBuilder(); |
| | | String responseLine; |
| | | while ((responseLine = br.readLine()) != null) { |
| | | response.append(responseLine.trim()); |
| | | } |
| | | System.out.println("Response: " + response.toString()); |
| | | JSONObject obj = JSONObject.parseObject(response.toString()); |
| | | if(obj.get("code").equals(200)&&obj.get("data").equals(true)){ |
| | | saveState=true; |
| | | } |
| | | |
| | | } |
| | | |
| | | //关闭连接 |
| | | conn.disconnect(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | saveState= false; |
| | | } |
| | | return saveState; |
| | | } |
| | | |
| | | } |