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