From b0a4de74b47e2626f51eb4a844db3e62f6a4bf9d Mon Sep 17 00:00:00 2001
From: guoyujie <guoyujie@ng.com>
Date: 星期四, 18 十二月 2025 10:52:48 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/ERP_override

---
 north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue      |  141 +++++++++++++++++++++++++++++++++++++++++++----
 north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java |    4 
 north-glass-erp/northglass-erp/src/views/sd/basicData/SearchProcessAttributeConfig.vue   |    6 ++
 north-glass-erp/src/main/resources/mapper/sd/BasicGlassTypeMapper.xml                    |    2 
 4 files changed, 138 insertions(+), 15 deletions(-)

diff --git a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue
index 5a9490e..0612cf5 100644
--- a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue
+++ b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue
@@ -989,36 +989,153 @@
     }
     adjustGrayRectangles(layoutIndex);
   } else {
+    // 鏃嬭浆澶辫触锛屾仮澶嶅師濮嬪昂瀵�
     glassDetail.width = originalState.width;
     glassDetail.height = originalState.height;
-    ElMessage.warning('鏃犳硶鏃嬭浆锛屽瓨鍦ㄩ噸鍙犳垨瓒呭嚭杈圭晫');
+
+    // 灏濊瘯鍚戜笂绉诲姩骞舵棆杞�
+    const upResult = tryMoveAndRotate(layoutIndex, rectIndex, 'up');
+    if (!upResult) {
+      ElMessage.warning('鏃犳硶鏃嬭浆锛屽嵆浣跨Щ鍔ㄥ悗浠嶅瓨鍦ㄩ噸鍙犳垨瓒呭嚭杈圭晫');
+    }
   }
+};
+
+// 杈呭姪鏂规硶锛氬皾璇曠Щ鍔ㄥ苟鏃嬭浆
+const tryMoveAndRotate = (layoutIndex, rectIndex, direction) => {
+  // 淇濆瓨鍘熷鐘舵��
+  const layout = layouts.value[layoutIndex];
+  const glassDetail = layout.glassDetails[rectIndex];
+  const originalPosition = {
+    x: glassDetail.x,
+    y: glassDetail.y,
+    width: glassDetail.width,
+    height: glassDetail.height
+  };
+
+  let success = false;
+
+  if (direction === 'up') {
+    // 灏濊瘯鍚戜笂绉诲姩骞舵棆杞�
+    moveRectAndRotate(layoutIndex, rectIndex, 'down');
+
+    // 妫�鏌ユ槸鍚︽垚鍔�
+    const otherRects = layout.glassDetails.filter(r => !r.isRemain && r !== glassDetail);
+    let hasOverlap = false;
+
+    otherRects.forEach(otherRect => {
+      if (checkOverlap(glassDetail, otherRect)) {
+        hasOverlap = true;
+      }
+    });
+
+    if (!hasOverlap &&
+        glassDetail.x + glassDetail.width <= layout.width &&
+        glassDetail.y + glassDetail.height <= layout.height &&
+        glassDetail.x >= 0 && glassDetail.y >= 0) {
+      success = true;
+      // 濡傛灉鍚戜笂绉诲姩骞舵棆杞垚鍔燂紝鍒欏啀鍚戜笅绉诲姩锛岃鐭╁舰闈犺繎搴曢儴
+      moveRect(layoutIndex, rectIndex, 'up');
+    } else {
+      // 鍚戜笂绉诲姩骞舵棆杞け璐ワ紝鎭㈠鍘熷鐘舵��
+      glassDetail.x = originalPosition.x;
+      glassDetail.y = originalPosition.y;
+      glassDetail.width = originalPosition.width;
+      glassDetail.height = originalPosition.height;
+    }
+  } else if (direction === 'down') {
+    // 灏濊瘯鍚戜笅绉诲姩骞舵棆杞�
+    moveRectAndRotate(layoutIndex, rectIndex, 'up');
+
+    // 妫�鏌ユ槸鍚︽垚鍔�
+    const otherRects = layout.glassDetails.filter(r => !r.isRemain && r !== glassDetail);
+    let hasOverlap = false;
+
+    otherRects.forEach(otherRect => {
+      if (checkOverlap(glassDetail, otherRect)) {
+        hasOverlap = true;
+      }
+    });
+
+    if (!hasOverlap &&
+        glassDetail.x + glassDetail.width <= layout.width &&
+        glassDetail.y + glassDetail.height <= layout.height &&
+        glassDetail.x >= 0 && glassDetail.y >= 0) {
+      success = true;
+      // 濡傛灉鍚戜笅绉诲姩骞舵棆杞垚鍔燂紝鍒欏啀鍚戜笂绉诲姩锛岃鐭╁舰闈犺繎椤堕儴
+      moveRect(layoutIndex, rectIndex, 'down');
+    } else {
+      // 鍚戜笅绉诲姩骞舵棆杞け璐ワ紝鎭㈠鍘熷鐘舵��
+      glassDetail.x = originalPosition.x;
+      glassDetail.y = originalPosition.y;
+      glassDetail.width = originalPosition.width;
+      glassDetail.height = originalPosition.height;
+    }
+  }
+
+  return success;
 };
 
 //绉诲姩鏃嬭浆鏂规硶
 const moveRectAndRotate = (layoutIndex, rectIndex, direction) => {
   const layout = layouts.value[layoutIndex];
   const glassDetail = layout.glassDetails[rectIndex];
-  const grayRects = layout.glassDetails.filter(r => r.isRemain);
 
+  // 鍏堢Щ鍔�
+  moveRect(layoutIndex, rectIndex, direction);
+
+  // 鍐嶆棆杞�
+  const originalState = { ...glassDetail };
   const temp = glassDetail.width;
   glassDetail.width = glassDetail.height;
   glassDetail.height = temp;
 
-  const canPlace = grayRects.some(grayRect => {
-    return grayRect.width >= glassDetail.width && grayRect.height >= glassDetail.height;
+  const otherRects = layout.glassDetails.filter(r => !r.isRemain && r !== glassDetail);
+  let isValidRotation = true;
+
+  otherRects.forEach(otherRect => {
+    if (checkOverlap(glassDetail, otherRect)) {
+      isValidRotation = false;
+    }
   });
 
-  if (!canPlace) {
-    const temp = glassDetail.width;
-    glassDetail.width = glassDetail.height;
-    glassDetail.height = temp;
-    ElMessage.warning('鏃犳硶鏃嬭浆锛屾病鏈夎冻澶熺殑绌洪棿');
-    return;
+  if (glassDetail.x + glassDetail.width > layout.width || glassDetail.y + glassDetail.height > layout.height) {
+    isValidRotation = false;
   }
 
-  adjustGrayRectangles(layoutIndex);
-  moveRect(layoutIndex, rectIndex, direction);
+  if (isValidRotation) {
+    // 鏇存柊glassPoint鍧愭爣锛堝鏋滃瓨鍦級
+    if (glassDetail.glassPoint && Array.isArray(glassDetail.glassPoint)) {
+      const originalPoints = JSON.parse(JSON.stringify(glassDetail.glassPoint));
+      glassDetail.glassPoint.forEach((point, index) => {
+        const relX = originalPoints[index].X - originalState.x;
+        const relY = originalPoints[index].Y - originalState.y;
+        point.X = originalState.x + relY;
+        point.Y = originalState.y + (originalState.width - relX);
+        point.X = parseFloat(point.X.toFixed(2));
+        point.Y = parseFloat(point.Y.toFixed(2));
+      });
+    }
+    adjustGrayRectangles(layoutIndex);
+  } else {
+    // 鏃嬭浆澶辫触锛屾仮澶嶅師濮嬪昂瀵稿拰浣嶇疆
+    glassDetail.width = originalState.width;
+    glassDetail.height = originalState.height;
+    // 鎭㈠绉诲姩鍓嶇殑浣嶇疆
+    moveRect(layoutIndex, rectIndex, getReverseDirection(direction));
+    ElMessage.warning('鏃犳硶鏃嬭浆锛屽瓨鍦ㄩ噸鍙犳垨瓒呭嚭杈圭晫');
+  }
+};
+
+// 鑾峰彇鍙嶅悜鏂瑰悜鐨勮緟鍔╁嚱鏁�
+const getReverseDirection = (direction) => {
+  switch (direction) {
+    case 'up': return 'down';
+    case 'down': return 'up';
+    case 'left': return 'right';
+    case 'right': return 'left';
+    default: return direction;
+  }
 };
 
 //绉诲姩鏂规硶
diff --git a/north-glass-erp/northglass-erp/src/views/sd/basicData/SearchProcessAttributeConfig.vue b/north-glass-erp/northglass-erp/src/views/sd/basicData/SearchProcessAttributeConfig.vue
index bdaa1d6..3a088f1 100644
--- a/north-glass-erp/northglass-erp/src/views/sd/basicData/SearchProcessAttributeConfig.vue
+++ b/north-glass-erp/northglass-erp/src/views/sd/basicData/SearchProcessAttributeConfig.vue
@@ -102,6 +102,12 @@
     if ($grid) {
       switch (code) {
         case 'add': {
+          submit.value.glassLevel = [null,null]
+          submit.value.processType = null
+          submit.value.processName = null
+          submit.value.inputType = null
+          submit.value.id = null
+          rowIndex.value = null
           dialogTableVisible.value = true
           break
         }
diff --git a/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java b/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java
index 0ff4649..3ab6258 100644
--- a/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java
+++ b/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java
@@ -228,7 +228,7 @@
     }
 
 
-    @PostMapping("/calculate")
+    @PostMapping("/mesCalculate")
     public ResponseEntity<Map<String, Object>> receiveOptimizeRequest(
             @RequestBody Map<String, Object> requestData) {
 
@@ -240,7 +240,7 @@
             response.put("msg", "success");
             response.put("data", "");
 
-            // 寮傛澶勭悊璁$畻浠诲姟
+            // todo 寮傛澶勭悊璁$畻浠诲姟
 //            glassOptimizeService.processExternalOptimizeRequest(requestData);
             System.out.println(requestData);
 
diff --git a/north-glass-erp/src/main/resources/mapper/sd/BasicGlassTypeMapper.xml b/north-glass-erp/src/main/resources/mapper/sd/BasicGlassTypeMapper.xml
index fe2c744..6990e4b 100644
--- a/north-glass-erp/src/main/resources/mapper/sd/BasicGlassTypeMapper.xml
+++ b/north-glass-erp/src/main/resources/mapper/sd/BasicGlassTypeMapper.xml
@@ -91,7 +91,7 @@
             process_attribute_config as a
         set a.process_type = #{processAttributeConfig.processType},
             a.process_name = #{processAttributeConfig.processName},
-            a.input_type = #{processAttributeConfig.inputType},
+            a.input_type = #{processAttributeConfig.inputType}
         where a.id = #{processAttributeConfig.id}
     </update>
 

--
Gitblit v1.8.0