返回数据修改

parent a17d29cb
...@@ -16,27 +16,27 @@ import java.util.Map; ...@@ -16,27 +16,27 @@ import java.util.Map;
@Slf4j @Slf4j
@UtilityClass @UtilityClass
public class ParamValidator { public class ParamValidator {
// ========== 基本参数验证 ========== // ========== 基本参数验证 ==========
public static void requireNonNull(Object value, String fieldName) { public static void requireNonNull(Object value, String fieldName) {
if (value == null) { if (value == null) {
throw new IllegalArgumentException(fieldName + "不能为空"); throw new IllegalArgumentException(fieldName + "不能为空");
} }
} }
public static void requireNotBlank(String value, String fieldName) { public static void requireNotBlank(String value, String fieldName) {
if (value == null || value.trim().isEmpty()) { if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException(fieldName + "不能为空"); throw new IllegalArgumentException(fieldName + "不能为空");
} }
} }
public static void requireNotEmpty(List<?> list, String fieldName) { public static void requireNotEmpty(List<?> list, String fieldName) {
if (list == null || list.isEmpty()) { if (list == null || list.isEmpty()) {
throw new IllegalArgumentException(fieldName + "不能为空"); throw new IllegalArgumentException(fieldName + "不能为空");
} }
} }
public static void requirePositive(Number number, String fieldName) { public static void requirePositive(Number number, String fieldName) {
if (number == null) { if (number == null) {
throw new IllegalArgumentException(fieldName + "不能为空"); throw new IllegalArgumentException(fieldName + "不能为空");
...@@ -45,7 +45,7 @@ public class ParamValidator { ...@@ -45,7 +45,7 @@ public class ParamValidator {
throw new IllegalArgumentException(fieldName + "必须大于0"); throw new IllegalArgumentException(fieldName + "必须大于0");
} }
} }
public static void requireNonNegative(Number number, String fieldName) { public static void requireNonNegative(Number number, String fieldName) {
if (number == null) { if (number == null) {
throw new IllegalArgumentException(fieldName + "不能为空"); throw new IllegalArgumentException(fieldName + "不能为空");
...@@ -54,13 +54,13 @@ public class ParamValidator { ...@@ -54,13 +54,13 @@ public class ParamValidator {
throw new IllegalArgumentException(fieldName + "不能为负数"); throw new IllegalArgumentException(fieldName + "不能为负数");
} }
} }
// ========== Map参数提取 ========== // ========== Map参数提取 ==========
public static String getString(Map<String, Object> params, String key, String fieldName) { public static String getString(Map<String, Object> params, String key, String fieldName) {
Object value = params.get(key); Object value = params.get(key);
requireNonNull(value, fieldName); requireNonNull(value, fieldName);
if (value instanceof String) { if (value instanceof String) {
String strValue = ((String) value).trim(); String strValue = ((String) value).trim();
if (strValue.isEmpty()) { if (strValue.isEmpty()) {
...@@ -68,14 +68,14 @@ public class ParamValidator { ...@@ -68,14 +68,14 @@ public class ParamValidator {
} }
return strValue; return strValue;
} }
throw new IllegalArgumentException(fieldName + "必须是字符串类型"); throw new IllegalArgumentException(fieldName + "必须是字符串类型");
} }
public static Integer getInteger(Map<String, Object> params, String key, String fieldName) { public static Integer getInteger(Map<String, Object> params, String key, String fieldName) {
Object value = params.get(key); Object value = params.get(key);
requireNonNull(value, fieldName); requireNonNull(value, fieldName);
try { try {
if (value instanceof Number) { if (value instanceof Number) {
return ((Number) value).intValue(); return ((Number) value).intValue();
...@@ -92,11 +92,32 @@ public class ParamValidator { ...@@ -92,11 +92,32 @@ public class ParamValidator {
throw new IllegalArgumentException(fieldName + "格式不正确: " + value); throw new IllegalArgumentException(fieldName + "格式不正确: " + value);
} }
} }
public static Double getDouble(Map<String, Object> params, String key, String fieldName) {
Object value = params.get(key);
requireNonNull(value, fieldName);
try {
if (value instanceof Number) {
return ((Number) value).doubleValue();
} else if (value instanceof String) {
String str = ((String) value).trim();
if (str.isEmpty()) {
throw new IllegalArgumentException(fieldName + "不能为空字符串");
}
return Double.parseDouble(str);
} else {
throw new IllegalArgumentException(fieldName + "格式不正确,必须是数字或字符串");
}
} catch (NumberFormatException e) {
throw new IllegalArgumentException(fieldName + "格式不正确: " + value);
}
}
public static Long getLong(Map<String, Object> params, String key, String fieldName) { public static Long getLong(Map<String, Object> params, String key, String fieldName) {
Object value = params.get(key); Object value = params.get(key);
requireNonNull(value, fieldName); requireNonNull(value, fieldName);
try { try {
if (value instanceof Number) { if (value instanceof Number) {
return ((Number) value).longValue(); return ((Number) value).longValue();
...@@ -113,11 +134,11 @@ public class ParamValidator { ...@@ -113,11 +134,11 @@ public class ParamValidator {
throw new IllegalArgumentException(fieldName + "格式不正确: " + value); throw new IllegalArgumentException(fieldName + "格式不正确: " + value);
} }
} }
public static Boolean getBoolean(Map<String, Object> params, String key, String fieldName) { public static Boolean getBoolean(Map<String, Object> params, String key, String fieldName) {
Object value = params.get(key); Object value = params.get(key);
requireNonNull(value, fieldName); requireNonNull(value, fieldName);
if (value instanceof Boolean) { if (value instanceof Boolean) {
return (Boolean) value; return (Boolean) value;
} else if (value instanceof String) { } else if (value instanceof String) {
...@@ -138,33 +159,33 @@ public class ParamValidator { ...@@ -138,33 +159,33 @@ public class ParamValidator {
throw new IllegalArgumentException(fieldName + "格式不正确"); throw new IllegalArgumentException(fieldName + "格式不正确");
} }
} }
public static List<?> getList(Map<String, Object> params, String key, String fieldName) { public static List<?> getList(Map<String, Object> params, String key, String fieldName) {
Object value = params.get(key); Object value = params.get(key);
requireNonNull(value, fieldName); requireNonNull(value, fieldName);
if (value instanceof List) { if (value instanceof List) {
return (List<?>) value; return (List<?>) value;
} }
throw new IllegalArgumentException(fieldName + "必须是列表类型"); throw new IllegalArgumentException(fieldName + "必须是列表类型");
} }
public static LocalDateTime getDateTime(Map<String, Object> params, String key, String fieldName) { public static LocalDateTime getDateTime(Map<String, Object> params, String key, String fieldName) {
String dateTimeStr = getString(params, key, fieldName); String dateTimeStr = getString(params, key, fieldName);
return parseDateTime(dateTimeStr, fieldName); return parseDateTime(dateTimeStr, fieldName);
} }
// ========== 日期时间解析 ========== // ========== 日期时间解析 ==========
public static LocalDateTime parseDateTime(String dateTimeStr, String fieldName) { public static LocalDateTime parseDateTime(String dateTimeStr, String fieldName) {
try { try {
if (dateTimeStr == null || dateTimeStr.trim().isEmpty()) { if (dateTimeStr == null || dateTimeStr.trim().isEmpty()) {
throw new IllegalArgumentException(fieldName + "不能为空"); throw new IllegalArgumentException(fieldName + "不能为空");
} }
String trimmed = dateTimeStr.trim(); String trimmed = dateTimeStr.trim();
// 支持ISO格式(带时区) // 支持ISO格式(带时区)
if (trimmed.endsWith("Z") || trimmed.contains("+") || trimmed.contains("-")) { if (trimmed.endsWith("Z") || trimmed.contains("+") || trimmed.contains("-")) {
try { try {
...@@ -174,22 +195,22 @@ public class ParamValidator { ...@@ -174,22 +195,22 @@ public class ParamValidator {
// 继续尝试其他格式 // 继续尝试其他格式
} }
} }
// 尝试标准ISO格式 // 尝试标准ISO格式
try { try {
return LocalDateTime.parse(trimmed); return LocalDateTime.parse(trimmed);
} catch (DateTimeParseException e) { } catch (DateTimeParseException e) {
// 继续尝试其他格式 // 继续尝试其他格式
} }
// 尝试常用格式 // 尝试常用格式
DateTimeFormatter[] formatters = { DateTimeFormatter[] formatters = {
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"),
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"),
DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"), DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"),
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss") DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
}; };
for (DateTimeFormatter formatter : formatters) { for (DateTimeFormatter formatter : formatters) {
try { try {
return LocalDateTime.parse(trimmed, formatter); return LocalDateTime.parse(trimmed, formatter);
...@@ -197,48 +218,48 @@ public class ParamValidator { ...@@ -197,48 +218,48 @@ public class ParamValidator {
// 继续尝试下一个格式 // 继续尝试下一个格式
} }
} }
throw new IllegalArgumentException(fieldName + "格式不正确: " + trimmed); throw new IllegalArgumentException(fieldName + "格式不正确: " + trimmed);
} catch (DateTimeParseException e) { } catch (DateTimeParseException e) {
throw new IllegalArgumentException(fieldName + "格式不正确: " + dateTimeStr); throw new IllegalArgumentException(fieldName + "格式不正确: " + dateTimeStr);
} }
} }
// ========== 批量参数验证 ========== // ========== 批量参数验证 ==========
public static void validateSceneExists(SceneService sceneService, String sceneId) { public static void validateSceneExists(SceneService sceneService, String sceneId) {
if (sceneId == null || sceneId.trim().isEmpty()) { if (sceneId == null || sceneId.trim().isEmpty()) {
throw new IllegalArgumentException("场景ID不能为空"); throw new IllegalArgumentException("场景ID不能为空");
} }
if (sceneService == null) { if (sceneService == null) {
throw new IllegalArgumentException("sceneService不能为空"); throw new IllegalArgumentException("sceneService不能为空");
} }
if (sceneService.loadChromosomeFromFile(sceneId) == null) { if (sceneService.loadChromosomeFromFile(sceneId) == null) {
throw new RuntimeException("未找到对应的场景文件: " + sceneId); throw new RuntimeException("未找到对应的场景文件: " + sceneId);
} }
} }
public static Double[] convertToDoubleArray(List<?> sourceList, String fieldName) { public static Double[] convertToDoubleArray(List<?> sourceList, String fieldName) {
requireNotEmpty(sourceList, fieldName); requireNotEmpty(sourceList, fieldName);
return sourceList.stream() return sourceList.stream()
.map(item -> { .map(item -> {
if (item instanceof Number) { if (item instanceof Number) {
return ((Number) item).doubleValue(); return ((Number) item).doubleValue();
} else if (item instanceof String) { } else if (item instanceof String) {
try { try {
return Double.parseDouble(((String) item).trim()); return Double.parseDouble(((String) item).trim());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new IllegalArgumentException(fieldName + "包含无效的数字: " + item); throw new IllegalArgumentException(fieldName + "包含无效的数字: " + item);
}
} else {
throw new IllegalArgumentException(fieldName + "包含不支持的数据类型: " +
(item != null ? item.getClass().getSimpleName() : "null"));
} }
} else { })
throw new IllegalArgumentException(fieldName + "包含不支持的数据类型: " + .toArray(Double[]::new);
(item != null ? item.getClass().getSimpleName() : "null"));
}
})
.toArray(Double[]::new);
} }
} }
\ No newline at end of file
...@@ -300,12 +300,7 @@ public class RoutingDataService { ...@@ -300,12 +300,7 @@ public class RoutingDataService {
if(PlanResources1!=null&&PlanResources1.size()>0) if(PlanResources1!=null&&PlanResources1.size()>0)
{ {
for (PlanResource PlanResource : PlanResources1) { for (PlanResource PlanResource : PlanResources1) {
machine.setCode(PlanResource.getCode());
machine.setName(PlanResource.getTitle());
if(PlanResource.getWorkSchedId()==null)
{
continue;
}
List<MesShiftWorkSched> ShiftWorkScheds = MesShiftWorkScheds.stream() List<MesShiftWorkSched> ShiftWorkScheds = MesShiftWorkScheds.stream()
.filter(t -> (long) t.getWeekWorkSchedId() == PlanResource.getWorkSchedId()) .filter(t -> (long) t.getWeekWorkSchedId() == PlanResource.getWorkSchedId())
.collect(Collectors.toList()); .collect(Collectors.toList());
...@@ -320,14 +315,7 @@ public class RoutingDataService { ...@@ -320,14 +315,7 @@ public class RoutingDataService {
} }
} }
if(shifts1.size()==0)
{
throw new RuntimeException(String.format(
"设备%s没有设置日历",
machine.getCode()+":"+machine.getName()));
}
machine.setShifts(shifts1); machine.setShifts(shifts1);
List<ProdEquipSpecialCal> Holidays = ProdEquipSpecialCals.stream() List<ProdEquipSpecialCal> Holidays = ProdEquipSpecialCals.stream()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment