BUGFIX:印花优先级不从1开始传导致数组越界

This commit is contained in:
2026-05-13 23:54:29 +08:00
parent d055331690
commit 3273a61066

View File

@@ -2912,72 +2912,71 @@ public class PythonService {
private PrintToPython resolveDesignSinglePrint(List<DesignSinglePrint> printObject, String partialDesign) { private PrintToPython resolveDesignSinglePrint(List<DesignSinglePrint> printObject, String partialDesign) {
PrintToPython printToPython = new PrintToPython(); PrintToPython printToPython = new PrintToPython();
// DesignPythonItemPrint printSingle = new DesignPythonItemPrint();
DesignPythonItemPrint printOverall = new DesignPythonItemPrint(); DesignPythonItemPrint printOverall = new DesignPythonItemPrint();
// printToPython.setSingle(printSingle);
printToPython.setOverall(printOverall); printToPython.setOverall(printOverall);
printToPython.setPartial(StringUtil.isNullOrEmpty(partialDesign) ? null : partialDesign); printToPython.setPartial(StringUtil.isNullOrEmpty(partialDesign) ? null : partialDesign);
if (Objects.isNull(printObject) || printObject.isEmpty()) { if (Objects.isNull(printObject) || printObject.isEmpty()) {
return printToPython; return printToPython;
} }
// 没有印花时的参数设置 // 1. 先对 printObject 按 priority 排序(升序)
// if (printObject.getIfSingle().equals(Boolean.FALSE) && CollectionUtil.isEmpty(printObject.getPrints())) { List<DesignSinglePrint> sortedPrints = printObject.stream()
// return new DesignPythonItemPrint(new ArrayList<>(), false); .sorted(Comparator.comparingInt(DesignSinglePrint::getPriority))
// } .toList();
// DesignPythonItemPrint print = CopyUtil.copyObject(printObject, DesignPythonItemPrint.class);
int size = printObject.size(); // 2. 分别收集单印和非单印的数据
// 占位符填充数组 List<DesignSinglePrint> singlePrints = sortedPrints.stream()
List<List<Float>> locationS = new ArrayList<>(Collections.nCopies(size, null)); .filter(DesignSinglePrint::getIfSingle)
List<List<Float>> scaleS = new ArrayList<>(Collections.nCopies(size, null)); .toList();
List<Double> angleS = new ArrayList<>(Collections.nCopies(size, null));
ArrayList<String> pathsS = new ArrayList<>(Collections.nCopies(size, null));
List<List<Float>> locationO = new ArrayList<>(Collections.nCopies(size, null)); List<DesignSinglePrint> overallPrints = sortedPrints.stream()
List<List<Float>> scaleO = new ArrayList<>(Collections.nCopies(size, null)); .filter(p -> !p.getIfSingle())
List<Double> angleO = new ArrayList<>(Collections.nCopies(size, null)); .toList();
ArrayList<String> pathsO = new ArrayList<>(Collections.nCopies(size, null));
// 设置印花的位置、大小、旋转角度 // 3. 处理单印数据
// 优先级越大越靠近顶层在传输给python的数组中越靠前 if (!singlePrints.isEmpty()) {
// List<DesignSinglePrint> prints = printObject.getPrints(); List<List<Float>> locationS = new ArrayList<>();
printObject.forEach(p -> { List<List<Float>> scaleS = new ArrayList<>();
p.getLocation().set(0, p.getLocation().get(0)); List<Double> angleS = new ArrayList<>();
p.getLocation().set(1, p.getLocation().get(1)); List<String> pathsS = new ArrayList<>();
Integer priority = p.getPriority();
setUriToMinioPath(p); for (DesignSinglePrint p : singlePrints) {
// todo 下标越界问题 setUriToMinioPath(p);
if (p.getIfSingle()) { locationS.add(p.getLocation());
locationS.set(priority - 1, p.getLocation()); scaleS.add(p.getScale());
scaleS.set(priority - 1, p.getScale()); angleS.add(p.getAngle());
angleS.set(priority - 1, p.getAngle()); pathsS.add(p.getMinIOPath());
pathsS.set(priority - 1, p.getMinIOPath());
} else {
locationO.set(priority - 1, p.getLocation());
scaleO.set(priority - 1, p.getScale());
angleO.set(priority - 1, p.getAngle());
pathsO.set(priority - 1, p.getMinIOPath());
} }
// log.info("本次print打点locations###{}###fileVO{}", p.getLocation(), JSON.toJSONString(fileVO));
});
/*locationS.removeAll(Collections.singleton(null));
scaleS.removeAll(Collections.singleton(null));
angleS.removeAll(Collections.singleton(null));
pathsS.removeAll(Collections.singleton(null));
printSingle.setLocation(locationS);
printSingle.setPrint_scale_list(scaleS);
printSingle.setPrint_angle_list(angleS);
printSingle.setPrint_path_list(pathsS);*/
locationO.removeAll(Collections.singleton(null)); // 注意:如果 printOverall 中需要设置单印数据,请在这里添加相应的 setter
scaleO.removeAll(Collections.singleton(null)); // 根据您的原始代码,似乎只设置了 overall非单印的数据
angleO.removeAll(Collections.singleton(null)); // 如果需要设置单印,请取消下面的注释并添加对应的字段
pathsO.removeAll(Collections.singleton(null)); // printOverall.setSingleLocation(locationS);
printOverall.setLocation(locationO); // printOverall.setSingleScale(scaleS);
printOverall.setPrint_scale_list(scaleO); // printOverall.setSingleAngle(angleS);
printOverall.setPrint_angle_list(angleO); // printOverall.setSinglePath(pathsS);
printOverall.setPrint_path_list(pathsO); }
// 4. 处理非单印数据(整体印花)
if (!overallPrints.isEmpty()) {
List<List<Float>> locationO = new ArrayList<>();
List<List<Float>> scaleO = new ArrayList<>();
List<Double> angleO = new ArrayList<>();
List<String> pathsO = new ArrayList<>();
for (DesignSinglePrint p : overallPrints) {
setUriToMinioPath(p);
locationO.add(p.getLocation());
scaleO.add(p.getScale());
angleO.add(p.getAngle());
pathsO.add(p.getMinIOPath());
}
printOverall.setLocation(locationO);
printOverall.setPrint_scale_list(scaleO);
printOverall.setPrint_angle_list(angleO);
printOverall.setPrint_path_list(pathsO);
}
return printToPython; return printToPython;
} }