24282 1 年之前
父节点
当前提交
2a40a8f17f

+ 1 - 1
sd-business/src/main/java/com/sd/business/entity/work/constant/MaterialsConstant.java

@@ -10,7 +10,7 @@ public interface MaterialsConstant {
     /**
      * 卷材长度
      */
-    int MASTER_LENGTH = 4300;
+    int MASTER_LENGTH = 355;
 
     /**
      * 卷材宽度

+ 0 - 2
sd-business/src/main/java/com/sd/business/service/work/impl/fixation/FixationFactory.java

@@ -2,8 +2,6 @@ package com.sd.business.service.work.impl.fixation;
 
 import com.ruoyi.common.exception.ServiceException;
 import com.sd.business.entity.work.enums.WorkOrderFixationSpecEnum;
-import com.sd.business.service.work.impl.fixation.strategy.FixationStrategy;
-import com.sd.business.service.work.impl.fixation.strategy.Fixation_30_40;
 
 public class FixationFactory {
 

+ 55 - 0
sd-business/src/main/java/com/sd/business/service/work/impl/fixation/FixationStrategy.java

@@ -0,0 +1,55 @@
+package com.sd.business.service.work.impl.fixation;
+
+import com.sd.business.entity.work.constant.MaterialsConstant;
+import lombok.Getter;
+
+import java.math.BigDecimal;
+
+public abstract class FixationStrategy {
+
+    /**
+     * 卷材长度
+     */
+    protected final BigDecimal masterLength = new BigDecimal(MaterialsConstant.MASTER_LENGTH);
+
+    /**
+     * 卷材宽度
+     */
+    protected final BigDecimal masterWidth = new BigDecimal(MaterialsConstant.MASTER_WIDTH);
+
+    /**
+     * 卷材面积
+     */
+    protected final BigDecimal masterArea = masterLength.multiply(masterWidth);
+
+    /**
+     * 是否可以继续排版
+     */
+    protected Boolean hasNext = true;
+
+    /**
+     * 排版参数
+     */
+    @Getter
+    private TypeSettingBo typeSettingBo;
+
+    /**
+     * 获取下一个排版信息
+     */
+    public abstract TypeSettingBo next();
+
+    /**
+     * 是否有下一个排版信息
+     */
+    public boolean hasNext() {
+        return this.hasNext;
+    }
+
+    /**
+     * 赋值下一个排版信息
+     */
+    protected void setTypeSettingBo(TypeSettingBo typeSettingBo) {
+        this.typeSettingBo = typeSettingBo;
+    }
+
+}

+ 160 - 0
sd-business/src/main/java/com/sd/business/service/work/impl/fixation/Fixation_30_40.java

@@ -0,0 +1,160 @@
+package com.sd.business.service.work.impl.fixation;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.exception.ServiceException;
+import com.sd.business.entity.work.constant.MaterialsConstant;
+
+import java.math.BigDecimal;
+
+public class Fixation_30_40 extends FixationStrategy {
+
+    /**
+     * 不考虑旋转长宽
+     */
+    private final BigDecimal l = new BigDecimal("30");
+    private final BigDecimal w = new BigDecimal("40");
+
+    /**
+     * 不考虑旋转出血长宽
+     */
+    private final BigDecimal bl = this.l.add(BigDecimal.valueOf((MaterialsConstant.RESERVE)));
+    private final BigDecimal bw = this.w.add(BigDecimal.valueOf((MaterialsConstant.RESERVE)));
+
+    /**
+     * 不考虑旋转出血面积
+     */
+    private final BigDecimal bArea = bl.multiply(bw);
+
+    /**
+     * 第一列到第四列左边x轴坐标
+     */
+    private final BigDecimal x1 = BigDecimal.ZERO;
+    private final BigDecimal x2 = this.bw;
+    private final BigDecimal x3 = this.x2.add(this.bw);
+    private final BigDecimal x4 = this.x3.add(this.bl);
+
+    /**
+     * 第一列到第四列下边y坐标
+     */
+    private BigDecimal y1 = this.bl;
+    private BigDecimal y2 = BigDecimal.ZERO;
+    private BigDecimal y3 = BigDecimal.ZERO;
+    private BigDecimal y4 = BigDecimal.ZERO;
+
+    public static void main(String[] args) {
+        Fixation_30_40 fixation3040 = new Fixation_30_40();
+
+        while (fixation3040.hasNext()) {
+            TypeSettingBo demo = fixation3040.next();
+            System.out.println(JSONObject.toJSONString(demo));
+        }
+    }
+
+    @Override
+    public TypeSettingBo next() {
+
+        if (!this.hasNext) {
+            throw new ServiceException("无法继续排版");
+        }
+
+        TypeSettingBo typeSettingBo = getTypeSettingBo();
+
+        if (typeSettingBo == null) {
+            typeSettingBo = new TypeSettingBo(
+                    this.masterArea, this.bArea, BigDecimal.ONE, BigDecimal.ZERO, BigDecimal.ZERO,
+                    this.l, this.w, this.bl, false);
+
+            setTypeSettingBo(typeSettingBo);
+            return typeSettingBo;
+        }
+
+        // 对比排第一列最大高度小还是第三列最大高度小
+        BigDecimal tempY1 = this.y1.add(this.bl);
+        BigDecimal tempY3 = this.y3.add(this.bw);
+        BigDecimal tempMinY3 = this.y3.add(this.bl);
+
+        // 排版个数为偶数时,排第二列或者第四列
+        if (typeSettingBo.getSchedulingNum().add(BigDecimal.ONE).intValue() % 2 == 0) {
+
+            // 如果第一列和第二列轴不相等,则排第二列
+            if (this.y1.compareTo(this.y2) != 0) {
+                setNextTypeSettingBo(typeSettingBo, this.x2, this.y2, false);
+                this.y2 = this.y2.add(this.bl);
+            }
+            // 否则排第四列
+            else {
+                setNextTypeSettingBo(typeSettingBo, this.x4, this.y4, true);
+                this.y4 = this.y4.add(this.bw);
+            }
+
+            // 判断是否还能继续排版
+            if (tempY1.compareTo(masterLength) > 0
+                    && tempY3.compareTo(masterLength) > 0
+                    && tempMinY3.compareTo(masterLength) > 0) {
+                this.hasNext = false;
+            }
+        }
+
+        // 排版个数为奇数时,排第一列或者第三列
+        else {
+            // 如果第一列后高度小于等于排第三列后高度,则排第一列
+            if (tempY1.compareTo(tempY3) <= 0) {
+                BigDecimal maxLength = tempY1.compareTo(this.y3) > 0 ? tempY1 : this.y3;
+                setNextTypeSettingBo(typeSettingBo, this.x1, this.y1, maxLength, false);
+                this.y1 = tempY1;
+            }
+            // 否则排第三列
+            else {
+                // 如果第三列高度无法旋转排版,则表示第三列第四列合并排版非选择垫子
+                if (tempY3.compareTo(masterLength) > 0) {
+                    setNextTypeSettingBo(typeSettingBo, this.x3, this.y3, false);
+                    this.y3 = tempMinY3;
+                    this.hasNext = false;
+                }
+                // 旋转排版
+                else {
+                    BigDecimal maxLength = this.y1.compareTo(tempY3) > 0 ? this.y1 : tempY3;
+                    setNextTypeSettingBo(typeSettingBo, this.x3, this.y3, maxLength, true);
+                    this.y3 = tempY3;
+                }
+            }
+        }
+        return getTypeSettingBo();
+    }
+
+    /**
+     * 赋值下一个排版参数
+     *
+     * @param typeSettingBo 当前排版参数
+     * @param x             x轴
+     * @param y             y轴
+     * @param hasRotate     是否旋转
+     */
+    private void setNextTypeSettingBo(TypeSettingBo typeSettingBo, BigDecimal x, BigDecimal y, Boolean hasRotate) {
+        setNextTypeSettingBo(typeSettingBo, x, y, typeSettingBo.getMaxLength(), hasRotate);
+    }
+
+    /**
+     * 赋值下一个排版参数
+     *
+     * @param typeSettingBo 当前排版参数
+     * @param x             x轴
+     * @param y             y轴
+     * @param maxLength     最大长度
+     * @param hasRotate     是否旋转
+     */
+    private void setNextTypeSettingBo(TypeSettingBo typeSettingBo, BigDecimal x, BigDecimal y, BigDecimal maxLength, Boolean hasRotate) {
+        TypeSettingBo nextTypeSettingBo = new TypeSettingBo(
+                this.masterArea,
+                typeSettingBo.getUsedArea().add(this.bArea),
+                typeSettingBo.getSchedulingNum().add(BigDecimal.ONE),
+                x, y,
+                hasRotate ? this.w : this.l,
+                hasRotate ? this.l : this.w,
+                maxLength,
+                hasRotate);
+
+        setTypeSettingBo(nextTypeSettingBo);
+    }
+
+}

+ 6 - 9
sd-business/src/main/java/com/sd/business/service/work/impl/fixation/Test.java

@@ -1,8 +1,6 @@
 package com.sd.business.service.work.impl.fixation;
 
 import com.sd.business.entity.work.constant.MaterialsConstant;
-import com.sd.business.service.work.impl.fixation.strategy.FixationStrategy;
-import com.sd.business.service.work.impl.fixation.strategy.Fixation_30_40;
 import javafx.scene.Scene;
 import javafx.scene.canvas.Canvas;
 import javafx.scene.canvas.GraphicsContext;
@@ -37,22 +35,21 @@ public class Test extends javafx.application.Application {
         nextButton.setOnAction(actionEvent -> {
             try {
 
+                TypeSettingBo next = fixationStrategy.next();
+
                 draw(canvas,
-                        fixationStrategy.getX().doubleValue(),
-                        fixationStrategy.getY().doubleValue(),
-                        fixationStrategy.getBleedingWidth().doubleValue(),
-                        fixationStrategy.getBleedingLength().doubleValue(),
+                        next.getX().doubleValue(),
+                        next.getY().doubleValue(),
+                        next.getBleedingWidth().doubleValue(),
+                        next.getBleedingLength().doubleValue(),
                         false);
 
-                fixationStrategy.next();
-
             } catch (Exception e) {
                 Alert alert = new Alert(Alert.AlertType.WARNING);
                 alert.setContentText("已经没有可以放置的矩形了!");
                 alert.showAndWait();
             }
         });
-        //
         pane.getChildren().add(nextButton);
         primaryStage.setTitle("二维矩形装箱可视化");
         primaryStage.setScene(new Scene(pane, MaterialsConstant.MASTER_WIDTH + 200, MaterialsConstant.MASTER_LENGTH + 200, Color.AQUA));

+ 46 - 11
sd-business/src/main/java/com/sd/business/service/work/impl/fixation/TypeSettingBo.java

@@ -1,48 +1,83 @@
 package com.sd.business.service.work.impl.fixation;
 
+import com.sd.business.entity.work.constant.MaterialsConstant;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 
+/**
+ * 排版参数
+ */
+@Getter
+@AllArgsConstructor
 public class TypeSettingBo {
 
     /**
+     * 卷材面积
+     */
+    private BigDecimal masterArea;
+
+    /**
      * 已使用面积
      */
-    protected BigDecimal usedArea;
+    private BigDecimal usedArea;
 
     /**
-     * x轴坐标
+     * 排单数量
      */
-    protected BigDecimal x;
+    private BigDecimal schedulingNum;
 
     /**
-     * y轴坐标
+     * x轴坐标
      */
-    protected BigDecimal y;
+    private BigDecimal x;
 
     /**
-     * 排单数量
+     * y轴坐标
      */
-    protected BigDecimal schedulingNum;
+    private BigDecimal y;
 
     /**
      * 长(考虑旋转后的)
      */
-    protected BigDecimal length;
+    private BigDecimal length;
 
     /**
      * 宽(考虑旋转后的)
      */
-    protected BigDecimal width;
+    private BigDecimal width;
 
     /**
      * 最大长度
      */
-    protected BigDecimal maxLength;
+    private BigDecimal maxLength;
 
     /**
      * 是否旋转
      */
-    protected Boolean hasRotate;
+    private Boolean hasRotate;
 
+    /**
+     * 获取使用率
+     */
+    public final BigDecimal getUseRatio() {
+        return usedArea.multiply(new BigDecimal(100)).divide(masterArea, 2, RoundingMode.HALF_UP);
+    }
+
+    /**
+     * 获取出血长度
+     */
+    public final BigDecimal getBleedingLength() {
+        return this.length.add(BigDecimal.valueOf((MaterialsConstant.RESERVE)));
+    }
+
+    /**
+     * 获取出血宽度
+     */
+    public final BigDecimal getBleedingWidth() {
+        return this.width.add(BigDecimal.valueOf((MaterialsConstant.RESERVE)));
+    }
 
 }

+ 0 - 93
sd-business/src/main/java/com/sd/business/service/work/impl/fixation/strategy/FixationStrategy.java

@@ -1,93 +0,0 @@
-package com.sd.business.service.work.impl.fixation.strategy;
-
-import com.sd.business.entity.work.constant.MaterialsConstant;
-import lombok.Getter;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-
-@Getter
-public abstract class FixationStrategy {
-
-    /**
-     * 卷材面积
-     */
-    protected final BigDecimal masterArea;
-    /**
-     * 已使用面积
-     */
-    protected BigDecimal usedArea;
-    /**
-     * x轴坐标
-     */
-    protected BigDecimal x;
-    /**
-     * y轴坐标
-     */
-    protected BigDecimal y;
-    /**
-     * 排单数量
-     */
-    protected BigDecimal schedulingNum;
-    /**
-     * 长(考虑旋转后的)
-     */
-    protected BigDecimal length;
-    /**
-     * 宽(考虑旋转后的)
-     */
-    protected BigDecimal width;
-    /**
-     * 最大长度
-     */
-    protected BigDecimal maxLength;
-    /**
-     * 是否旋转
-     */
-    protected Boolean hasRotate;
-    /**
-     * 是否可以继续排版
-     */
-    protected Boolean hasNext;
-
-    protected FixationStrategy(BigDecimal length, BigDecimal width, BigDecimal maxLength, boolean HasRotate) {
-        this.length = length;
-        this.width = width;
-        this.maxLength = maxLength;
-        this.hasRotate = HasRotate;
-
-        this.masterArea = new BigDecimal(MaterialsConstant.MASTER_LENGTH * MaterialsConstant.MASTER_WIDTH);
-        this.usedArea = BigDecimal.ZERO;
-        this.x = BigDecimal.ZERO;
-        this.y = BigDecimal.ZERO;
-        this.schedulingNum = BigDecimal.ONE;
-        this.hasNext = true;
-    }
-
-    /**
-     * 下一个排版信息
-     */
-    public abstract void next();
-
-    /**
-     * 获取使用率
-     */
-    public final BigDecimal getUseRatio() {
-        return usedArea.multiply(new BigDecimal(100)).divide(masterArea, 2, RoundingMode.HALF_UP);
-    }
-
-    /**
-     * 获取出血长度
-     */
-    public final BigDecimal getBleedingLength() {
-        return this.length.add(BigDecimal.valueOf((MaterialsConstant.RESERVE)));
-    }
-
-    /**
-     * 获取出血宽度
-     */
-    public final BigDecimal getBleedingWidth() {
-        return this.width.add(BigDecimal.valueOf((MaterialsConstant.RESERVE)));
-    }
-
-}

+ 0 - 148
sd-business/src/main/java/com/sd/business/service/work/impl/fixation/strategy/Fixation_30_40.java

@@ -1,148 +0,0 @@
-package com.sd.business.service.work.impl.fixation.strategy;
-
-import com.alibaba.fastjson2.JSONObject;
-import com.ruoyi.common.exception.ServiceException;
-import com.sd.business.entity.work.constant.MaterialsConstant;
-
-import java.math.BigDecimal;
-
-public class Fixation_30_40 extends FixationStrategy {
-
-    private final BigDecimal masterLength = new BigDecimal(MaterialsConstant.MASTER_LENGTH);
-
-    /**
-     * 不考虑旋转长宽
-     */
-    private final BigDecimal l = this.length;
-    private final BigDecimal w = this.width;
-
-    /**
-     * 不考虑旋转出血长宽
-     */
-    private final BigDecimal bl = getBleedingLength();
-    private final BigDecimal bw = getBleedingWidth();
-
-    /**
-     * 第一列到第四列左边x轴坐标
-     */
-    private final BigDecimal x1 = BigDecimal.ZERO;
-    private final BigDecimal x2 = getBleedingWidth();
-    private final BigDecimal x3 = this.x2.add(getBleedingWidth());
-    private final BigDecimal x4 = this.x3.add(getBleedingLength());
-
-    /**
-     * 第一列到第四列下边y坐标
-     */
-    private BigDecimal y1 = this.bl;
-    private BigDecimal y2 = BigDecimal.ZERO;
-    private BigDecimal y3 = BigDecimal.ZERO;
-    private BigDecimal y4 = BigDecimal.ZERO;
-
-    public Fixation_30_40() {
-        super(
-                new BigDecimal("30"),
-                new BigDecimal("40"),
-                new BigDecimal("30").add(BigDecimal.valueOf((MaterialsConstant.RESERVE))),
-                false
-        );
-    }
-
-    public static void main(String[] args) {
-        Fixation_30_40 fixation3040 = new Fixation_30_40();
-
-
-        while (true) {
-            System.out.println(JSONObject.toJSONString(fixation3040));
-            fixation3040.next();
-
-
-        }
-    }
-
-    @Override
-    public void next() {
-
-        if (!this.hasNext) {
-            throw new ServiceException("卷材排满,无法继续排版了");
-        }
-
-        // 排版个数为偶数时,排第二列或者第四列
-        if (schedulingNum.add(BigDecimal.ONE).intValue() % 2 == 0) {
-            // 如果第一列和第二列轴相等,排第四列
-            if (this.y1.compareTo(this.y2) == 0) {
-                this.x = this.x4;
-                this.y = this.y4;
-                this.length = this.w;
-                this.width = this.l;
-                this.hasRotate = true;
-
-                this.y4 = this.y4.add(this.bw);
-            }
-            // 否则排第二列
-            else {
-                this.x = this.x2;
-                this.y = this.y2;
-                this.length = this.l;
-                this.width = this.w;
-                this.hasRotate = false;
-
-                this.y2 = this.y2.add(this.bl);
-            }
-
-            // 查看是否还能排版
-            if (this.y1.add(this.bl).compareTo(masterLength) > 0
-                    && this.y3.add(this.bw).compareTo(masterLength) > 0
-                    && this.y3.add(this.bl).compareTo(masterLength) > 0) {
-                this.hasNext = false;
-            }
-
-        }
-
-        // 排版个数为奇数时,排第一列或者第三列
-        else {
-            // 对比排第一列最大高度小还是第三列最大高度小
-            BigDecimal tempY1 = this.y1.add(this.bl);
-            BigDecimal tempY3 = this.y3.add(this.bw);
-
-            // 如果第一列最大高度大,排第三列
-            if (tempY1.compareTo(tempY3) > 0) {
-
-                this.x = this.x3;
-                this.y = this.y3;
-
-                // 无法继续旋转排版
-                if (tempY3.compareTo(masterLength) > 0) {
-                    this.length = this.l;
-                    this.width = this.w;
-                    this.hasRotate = false;
-                    this.y3 = this.y3.add(this.bl);
-                    this.hasNext = false;
-                }
-                // 旋转排版
-                else {
-                    this.length = this.w;
-                    this.width = this.l;
-                    this.hasRotate = true;
-                    this.y3 = tempY3;
-                }
-
-            }
-            // 否则排第一列
-            else {
-                this.x = this.x1;
-                this.y = this.y1;
-                this.length = this.l;
-                this.width = this.w;
-                this.hasRotate = false;
-
-                this.y1 = tempY1;
-            }
-
-        }
-
-        this.schedulingNum = this.schedulingNum.add(BigDecimal.ONE);
-        this.maxLength = this.y1.compareTo(this.y3) > 0 ? this.y1 : this.y3;
-        this.usedArea = this.usedArea.add(getBleedingWidth().multiply(getBleedingLength()));
-    }
-
-}