76 lines
2.3 KiB
Java
76 lines
2.3 KiB
Java
package com.ruoyi.system.constant;
|
||
|
||
import com.ruoyi.common.utils.StringUtils;
|
||
import com.ruoyi.system.domain.ProcessOrderPro;
|
||
|
||
import java.util.Locale;
|
||
|
||
/**
|
||
* 项目令号出图模式 {@code process_order_pro.drawing_mode}。
|
||
* 执行出图 / 添加产品前必须显式选择,不允许为空。
|
||
*/
|
||
public final class DrawingMode {
|
||
|
||
/** 正常:每个产品一行一个 ProductInfo,不按图纸路径合并 */
|
||
public static final String NORMAL = "normal";
|
||
|
||
/** 零部件:同一图纸路径下多个子件合成一个 ProductInfo */
|
||
public static final String PART = "part";
|
||
|
||
private DrawingMode() {
|
||
}
|
||
|
||
public static boolean isValid(String mode) {
|
||
if (StringUtils.isBlank(mode)) {
|
||
return false;
|
||
}
|
||
String m = mode.trim().toLowerCase(Locale.ROOT);
|
||
return NORMAL.equals(m) || PART.equals(m);
|
||
}
|
||
|
||
public static String normalize(String mode) {
|
||
if (StringUtils.isBlank(mode)) {
|
||
return null;
|
||
}
|
||
return mode.trim().toLowerCase(Locale.ROOT);
|
||
}
|
||
|
||
/**
|
||
* 出图模式不能为空,必须为 normal / part。
|
||
*/
|
||
public static void requireConfigured(ProcessOrderPro order) {
|
||
if (order == null) {
|
||
throw new IllegalArgumentException("项目不存在");
|
||
}
|
||
requireConfigured(order.getDrawingMode());
|
||
}
|
||
|
||
/**
|
||
* 出图模式不能为空,必须为 normal / part。
|
||
*/
|
||
public static void requireConfigured(String drawingMode) {
|
||
String mode = normalize(drawingMode);
|
||
if (!isValid(mode)) {
|
||
throw new IllegalArgumentException("出图模式不能为空,请先选择出图模式(正常/零部件)");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 是否零部件出图模式。仅认显式 {@link #PART};未设置视为未配置(由 {@link #requireConfigured} 拦截)。
|
||
*/
|
||
public static boolean isPartMode(ProcessOrderPro order) {
|
||
if (order == null) {
|
||
return false;
|
||
}
|
||
return PART.equals(normalize(order.getDrawingMode()));
|
||
}
|
||
|
||
/** 图纸路径比较用:去空白、统一斜杠 */
|
||
public static String normalizeDrawPath(String drawPath) {
|
||
if (StringUtils.isBlank(drawPath)) {
|
||
return "";
|
||
}
|
||
return drawPath.trim().replace('\\', '/');
|
||
}
|
||
}
|