| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStream; |
| | | import java.math.BigDecimal; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.sql.Date; |
| | | import java.text.DecimalFormat; |
| | | import java.util.*; |
| | |
| | | RabbitMQUtil rabbitMQUtil; |
| | | //模拟计算 |
| | | |
| | | public Map<String, Object> SimulationCalculation(Map<String,Object> message) { |
| | | /*public Map<String, Object> SimulationCalculation(Map<String,Object> message) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | try { |
| | | rabbitMQUtil = new RabbitMQUtil(); |
| | |
| | | |
| | | |
| | | // 获取 computeData 和 cardData |
| | | /*Object computeData = message.get("computeData"); |
| | | Object cardData = message.get("cardData");*/ |
| | | *//*Object computeData = message.get("computeData"); |
| | | Object cardData = message.get("cardData");*//* |
| | | |
| | | rabbitMQUtil.sendMessage(message.toString()); |
| | | rabbitMQUtil.sendMessage(message.toString()); |
| | | System.out.println("send message: " + message); |
| | | String date = rabbitMQUtil.receiveMessages(); |
| | | System.out.println("Received message: " + date); |
| | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } catch (TimeoutException | InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return map; |
| | | }*/ |
| | | |
| | | public Map<String, Object> SimulationCalculation(Map<String,Object> message) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | try { |
| | | URL url = new URL("https://example.com"); // 替换为你的目标 URL |
| | | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
| | | |
| | | conn.setRequestMethod("POST"); |
| | | conn.setDoOutput(true); // 允许写入请求体 |
| | | conn.setConnectTimeout(5000); |
| | | // 读取超时(等待服务器响应的最大时间) |
| | | conn.setReadTimeout(108000); |
| | | |
| | | // 写入请求体数据 |
| | | String postData = message.toString(); |
| | | try (OutputStream os = conn.getOutputStream()) { |
| | | byte[] input = postData.getBytes(StandardCharsets.UTF_8); |
| | | os.write(input, 0, input.length); |
| | | } |
| | | |
| | | // 3. 获取状态码 |
| | | int statusCode = conn.getResponseCode(); |
| | | System.out.println("状态码: " + statusCode); |
| | | |
| | | // 4. 读取响应内容 |
| | | BufferedReader reader = new BufferedReader( |
| | | new InputStreamReader(conn.getInputStream()) |
| | | ); |
| | | String line; |
| | | StringBuilder response = new StringBuilder(); |
| | | while ((line = reader.readLine()) != null) { |
| | | response.append(line); |
| | | } |
| | | reader.close(); |
| | | |
| | | // 输出响应内容 |
| | | System.out.println("响应内容:\n" + response.toString()); |
| | | |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public String simulatedTypesetting(Map<String, Object> object) { |
| | | |
| | | String optionVal = ""; |
| | | Integer quantity = 0; |
| | | Double area = 0.0; |
| | | if (object.get("optionVal") != null) { |
| | | optionVal = object.get("optionVal").toString(); |
| | | } |
| | | if (object.get("quantity") != null) { |
| | | quantity = Integer.valueOf(object.get("quantity").toString()); |
| | | } |
| | | if (object.get("area") != null) { |
| | | area = Double.valueOf(object.get("area").toString()); |
| | | } |
| | | List<Map<String, Object>> flowCardListNormal = glassOptimizeMapper.getFlowCardListNormal(optionVal); |
| | | |
| | | |
| | | int currentQuantity = 0; |
| | | double currentArea = 0; |
| | | List<List<Map<String, Object>>> result = new ArrayList<>(); |
| | | List<Map<String, Object>> currentGroup = new ArrayList<>(); |
| | | |
| | | if(area==0 && quantity>0){ |
| | | for(Map<String, Object> flowCardNormal: flowCardListNormal){ |
| | | if (Integer.valueOf(flowCardNormal.get("quantity").toString()) > quantity ) { |
| | | continue; |
| | | } |
| | | int newQuantity = currentQuantity + Integer.valueOf(flowCardNormal.get("quantity").toString()); |
| | | double newArea = currentArea + Double.valueOf(flowCardNormal.get("area").toString()); |
| | | if(newQuantity>quantity){ |
| | | result.add(currentGroup); |
| | | currentGroup = new ArrayList<>(); |
| | | currentQuantity = 0; |
| | | currentArea = 0; |
| | | newQuantity = Integer.valueOf(flowCardNormal.get("quantity").toString()); |
| | | newArea = Double.valueOf(flowCardNormal.get("area").toString()); |
| | | |
| | | } |
| | | currentGroup.add(flowCardNormal); |
| | | currentQuantity = newQuantity; |
| | | currentArea = newArea; |
| | | |
| | | } |
| | | |
| | | if (!currentGroup.isEmpty()) { |
| | | result.add(currentGroup); |
| | | } |
| | | } |
| | | System.out.println(result); |
| | | |
| | | return ""; |
| | | |
| | | } |
| | | |
| | | public String simulatedTypesetting1(Map<String, Object> object) { |
| | | |
| | |
| | | } else { |
| | | area = 0.0; |
| | | } |
| | | List<Map<String, Object>> flowCardListNormal = glassOptimizeMapper.getFlowCardListNormal(optionVal); |
| | | |
| | | JSONArray materialStore = JSONArray.parseArray(JSONObject.toJSONString(object.get("materialStore"))); |
| | | |
| | | |
| | | List<Map<String, Object>> flowCardListNormal = glassOptimizeMapper.getFlowCardListSimulated(optionVal); |
| | | |
| | | |
| | | Queue<Map<String, Object>> queue = flowCardListNormal.stream() |