|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|