dev fix:designSingle代码本地提交 sysfile加入style字段
This commit is contained in:
@@ -294,10 +294,10 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
List<DesignItemDetail> existingDetails = designItemDetailService.selectByDesignItemId(designItemId);
|
||||
// 创建 Map,以 priority 为 key,方便快速查找
|
||||
Map<Integer, DesignItemDetail> existingDetailMap = existingDetails.stream()
|
||||
.filter(detail -> Objects.nonNull(detail.getPriority()))
|
||||
.collect(Collectors.toMap(DesignItemDetail::getPriority, detail -> detail, (old, newVal) -> old));
|
||||
|
||||
// 收集新 detail 的 priority,用于后续删除不存在的旧记录
|
||||
Set<Integer> newDetailPriorities = new HashSet<>();
|
||||
Map<String, Deque<DesignItemDetail>> detailBuckets = buildDetailTypeBuckets(existingDetails);
|
||||
Set<Long> reusedDetailIds = new HashSet<>();
|
||||
|
||||
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
|
||||
pythonObjects.getObjects().get(0).getItems().forEach(detail -> {
|
||||
@@ -305,16 +305,12 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
return;
|
||||
}
|
||||
Integer priority = SysFileLevel2TypeEnum.BODY.getRealName().equals(detail.getType()) ? 0 : detail.getPriority();
|
||||
newDetailPriorities.add(priority);
|
||||
|
||||
DesignItemDetail designItemDetail;
|
||||
// 如果存在相同 priority 的记录,则更新;否则创建新记录
|
||||
if (existingDetailMap.containsKey(priority)) {
|
||||
// 更新现有记录
|
||||
designItemDetail = existingDetailMap.get(priority);
|
||||
DesignItemDetail designItemDetail = reuseDesignItemDetail(priority, detail.getType(),
|
||||
existingDetailMap, detailBuckets, reusedDetailIds);
|
||||
if (Objects.nonNull(designItemDetail)) {
|
||||
designItemDetail.setUpdateDate(DateUtil.getByTimeZone(timeZone));
|
||||
} else {
|
||||
// 创建新记录
|
||||
designItemDetail = new DesignItemDetail();
|
||||
designItemDetail.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
}
|
||||
@@ -334,6 +330,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
// 非BODY类型使用path字段
|
||||
designItemDetail.setPath(detail.getPath());
|
||||
}
|
||||
designItemDetail.setColor(detail.getColor());
|
||||
designItemDetail.setIconPath(detail.getIcon());
|
||||
// todo
|
||||
DesignPythonItemPrint printObject = detail.getPrint().getSingle();
|
||||
@@ -342,17 +339,16 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
designItemDetails.add(designItemDetail);
|
||||
});
|
||||
|
||||
// 逻辑删除不在新列表中的旧记录
|
||||
existingDetails.forEach(existingDetail -> {
|
||||
if (!newDetailPriorities.contains(existingDetail.getPriority())) {
|
||||
// 该记录不在新列表中,需要逻辑删除
|
||||
UpdateWrapper<DesignItemDetail> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", existingDetail.getId());
|
||||
updateWrapper.set("is_deleted", (byte) 1);
|
||||
updateWrapper.set("update_date", DateUtil.getByTimeZone(timeZone));
|
||||
designItemDetailService.update(null, updateWrapper);
|
||||
}
|
||||
});
|
||||
// 逻辑删除未复用的旧记录
|
||||
existingDetails.stream()
|
||||
.filter(existingDetail -> Objects.nonNull(existingDetail.getId()) && !reusedDetailIds.contains(existingDetail.getId()))
|
||||
.forEach(existingDetail -> {
|
||||
UpdateWrapper<DesignItemDetail> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", existingDetail.getId());
|
||||
updateWrapper.set("is_deleted", (byte) 1);
|
||||
updateWrapper.set("update_date", DateUtil.getByTimeZone(timeZone));
|
||||
designItemDetailService.update(null, updateWrapper);
|
||||
});
|
||||
|
||||
designItemDetailService.saveOrUpdateBatch(designItemDetails);
|
||||
//封装item信息
|
||||
@@ -388,10 +384,10 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
List<DesignItemDetail> existingDetails = designItemDetailService.selectByDesignItemId(designItemId);
|
||||
// 创建 Map,以 priority 为 key,方便快速查找
|
||||
Map<Integer, DesignItemDetail> existingDetailMap = existingDetails.stream()
|
||||
.filter(detail -> Objects.nonNull(detail.getPriority()))
|
||||
.collect(Collectors.toMap(DesignItemDetail::getPriority, detail -> detail, (old, newVal) -> old));
|
||||
|
||||
// 收集新 detail 的 priority,用于后续删除不存在的旧记录
|
||||
Set<Integer> newDetailPriorities = new HashSet<>();
|
||||
Map<String, Deque<DesignItemDetail>> detailBuckets = buildDetailTypeBuckets(existingDetails);
|
||||
Set<Long> reusedDetailIds = new HashSet<>();
|
||||
|
||||
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
|
||||
// 3、保存新的designItemDetail(使用 saveOrUpdate 方式)
|
||||
@@ -400,16 +396,12 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
return;
|
||||
}
|
||||
Integer priority = SysFileLevel2TypeEnum.BODY.getRealName().equals(detail.getType()) ? 0 : detail.getPriority();
|
||||
newDetailPriorities.add(priority);
|
||||
|
||||
DesignItemDetail designItemDetail;
|
||||
// 如果存在相同 priority 的记录,则更新;否则创建新记录
|
||||
if (existingDetailMap.containsKey(priority)) {
|
||||
// 更新现有记录
|
||||
designItemDetail = existingDetailMap.get(priority);
|
||||
DesignItemDetail designItemDetail = reuseDesignItemDetail(priority, detail.getType(),
|
||||
existingDetailMap, detailBuckets, reusedDetailIds);
|
||||
if (Objects.nonNull(designItemDetail)) {
|
||||
designItemDetail.setUpdateDate(DateUtil.getByTimeZone(timeZone));
|
||||
} else {
|
||||
// 创建新记录
|
||||
designItemDetail = new DesignItemDetail();
|
||||
designItemDetail.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
}
|
||||
@@ -429,6 +421,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
// 非BODY类型使用path字段
|
||||
designItemDetail.setPath(detail.getPath());
|
||||
}
|
||||
designItemDetail.setColor(detail.getColor());
|
||||
designItemDetail.setIconPath(detail.getIcon());
|
||||
// designItemDetail.setUndividedLayer(priorityAndUndividedLayer.get(detail.getType().toLowerCase()));
|
||||
if (!detail.getType().equals("Body")) {
|
||||
@@ -446,17 +439,16 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
designItemDetails.add(designItemDetail);
|
||||
});
|
||||
|
||||
// 逻辑删除不在新列表中的旧记录
|
||||
existingDetails.forEach(existingDetail -> {
|
||||
if (!newDetailPriorities.contains(existingDetail.getPriority())) {
|
||||
// 该记录不在新列表中,需要逻辑删除
|
||||
UpdateWrapper<DesignItemDetail> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", existingDetail.getId());
|
||||
updateWrapper.set("is_deleted", (byte) 1);
|
||||
updateWrapper.set("update_date", DateUtil.getByTimeZone(timeZone));
|
||||
designItemDetailService.update(null, updateWrapper);
|
||||
}
|
||||
});
|
||||
// 逻辑删除未复用的旧记录
|
||||
existingDetails.stream()
|
||||
.filter(existingDetail -> Objects.nonNull(existingDetail.getId()) && !reusedDetailIds.contains(existingDetail.getId()))
|
||||
.forEach(existingDetail -> {
|
||||
UpdateWrapper<DesignItemDetail> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", existingDetail.getId());
|
||||
updateWrapper.set("is_deleted", (byte) 1);
|
||||
updateWrapper.set("update_date", DateUtil.getByTimeZone(timeZone));
|
||||
designItemDetailService.update(null, updateWrapper);
|
||||
});
|
||||
|
||||
// businessId 来自t_sys_file或者t_library
|
||||
designItemDetailService.saveOrUpdateBatch(designItemDetails);
|
||||
@@ -476,10 +468,10 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
List<TDesignPythonOutfitDetail> existingLayers = designPythonOutfitDetailService.getDetailByDesignPythonOutfitId(designPythonOutfit.getId());
|
||||
// 创建 Map,以 priority 为 key,方便快速查找
|
||||
Map<Integer, TDesignPythonOutfitDetail> existingLayerMap = existingLayers.stream()
|
||||
.collect(Collectors.toMap(TDesignPythonOutfitDetail::getPriority, layer -> layer, (old, newVal) -> old));
|
||||
|
||||
// 收集新 layer 的 priority,用于后续删除不存在的旧记录
|
||||
Set<Integer> newLayerPriorities = new HashSet<>();
|
||||
.filter(layer -> Objects.nonNull(layer.getPriority()))
|
||||
.collect(Collectors.toMap(layer -> Math.abs(layer.getPriority()), layer -> layer, (old, newVal) -> old));
|
||||
Map<String, Deque<TDesignPythonOutfitDetail>> layerBuckets = buildOutfitCategoryBuckets(existingLayers);
|
||||
Set<Long> reusedLayerIds = new HashSet<>();
|
||||
|
||||
// 7、将新生成的图层信息存入designPythonOutfitDetail表(使用 saveOrUpdate 方式)
|
||||
JSONArray layers = outfit.getJSONArray("layers");
|
||||
@@ -493,16 +485,12 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
for (int i = 0; i < layers.size(); i++) {
|
||||
JSONObject jsonObject = layers.getJSONObject(i);
|
||||
Integer priority = (Integer) jsonObject.get("priority");
|
||||
newLayerPriorities.add(Math.abs(priority));
|
||||
|
||||
TDesignPythonOutfitDetail designPythonOutfitDetail;
|
||||
// 如果存在相同 priority 的记录,则更新;否则创建新记录
|
||||
if (existingLayerMap.containsKey(Math.abs(priority))) {
|
||||
// 更新现有记录
|
||||
designPythonOutfitDetail = existingLayerMap.get(Math.abs(priority));
|
||||
TDesignPythonOutfitDetail designPythonOutfitDetail = reuseOutfitDetail(priority,
|
||||
jsonObject.getString("image_category"), existingLayerMap, layerBuckets, reusedLayerIds);
|
||||
if (Objects.nonNull(designPythonOutfitDetail)) {
|
||||
designPythonOutfitDetail.setUpdateDate(LocalDateTime.now(ZoneId.of(timeZone)));
|
||||
} else {
|
||||
// 创建新记录
|
||||
designPythonOutfitDetail = new TDesignPythonOutfitDetail();
|
||||
designPythonOutfitDetail.setCreateDate(LocalDateTime.now(ZoneId.of(timeZone)));
|
||||
}
|
||||
@@ -525,17 +513,16 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
list.add(designPythonOutfitDetail);
|
||||
}
|
||||
|
||||
// 逻辑删除不在新列表中的旧记录
|
||||
existingLayers.forEach(existingLayer -> {
|
||||
if (!newLayerPriorities.contains(Math.abs(existingLayer.getPriority()))) {
|
||||
// 该记录不在新列表中,需要逻辑删除
|
||||
UpdateWrapper<TDesignPythonOutfitDetail> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", existingLayer.getId());
|
||||
updateWrapper.set("is_deleted", 1);
|
||||
updateWrapper.set("update_date", LocalDateTime.now(ZoneId.of(timeZone)));
|
||||
designPythonOutfitDetailService.update(null, updateWrapper);
|
||||
}
|
||||
});
|
||||
// 逻辑删除未复用的旧记录
|
||||
existingLayers.stream()
|
||||
.filter(existingLayer -> Objects.nonNull(existingLayer.getId()) && !reusedLayerIds.contains(existingLayer.getId()))
|
||||
.forEach(existingLayer -> {
|
||||
UpdateWrapper<TDesignPythonOutfitDetail> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", existingLayer.getId());
|
||||
updateWrapper.set("is_deleted", 1);
|
||||
updateWrapper.set("update_date", LocalDateTime.now(ZoneId.of(timeZone)));
|
||||
designPythonOutfitDetailService.update(null, updateWrapper);
|
||||
});
|
||||
|
||||
designPythonOutfitDetailService.saveOrUpdateBatch(list);
|
||||
|
||||
@@ -575,6 +562,112 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
return list;
|
||||
}
|
||||
|
||||
private Map<String, Deque<DesignItemDetail>> buildDetailTypeBuckets(List<DesignItemDetail> details) {
|
||||
return details.stream()
|
||||
.collect(Collectors.groupingBy(DesignItemDetail::getType,
|
||||
Collectors.collectingAndThen(Collectors.toList(), list -> {
|
||||
list.sort(Comparator
|
||||
.comparingInt(this::extractDetailPriorityForSort)
|
||||
.thenComparing(DesignItemDetail::getId, Comparator.nullsLast(Long::compareTo)));
|
||||
return new ArrayDeque<>(list);
|
||||
})));
|
||||
}
|
||||
|
||||
private DesignItemDetail reuseDesignItemDetail(Integer priority, String type,
|
||||
Map<Integer, DesignItemDetail> priorityMap,
|
||||
Map<String, Deque<DesignItemDetail>> typeBuckets,
|
||||
Set<Long> reusedIds) {
|
||||
DesignItemDetail reused = null;
|
||||
if (Objects.nonNull(priority)) {
|
||||
reused = priorityMap.remove(priority);
|
||||
}
|
||||
if (Objects.nonNull(reused)) {
|
||||
markReusedDetail(reused, reusedIds);
|
||||
return reused;
|
||||
}
|
||||
Deque<DesignItemDetail> bucket = typeBuckets.get(type);
|
||||
while (bucket != null && !bucket.isEmpty()) {
|
||||
DesignItemDetail candidate = bucket.pollFirst();
|
||||
if (markReusedDetail(candidate, reusedIds)) {
|
||||
Integer candidatePriority = candidate.getPriority();
|
||||
if (Objects.nonNull(candidatePriority)) {
|
||||
priorityMap.remove(candidatePriority, candidate);
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, Deque<TDesignPythonOutfitDetail>> buildOutfitCategoryBuckets(List<TDesignPythonOutfitDetail> details) {
|
||||
return details.stream()
|
||||
.collect(Collectors.groupingBy(TDesignPythonOutfitDetail::getImageCategory,
|
||||
Collectors.collectingAndThen(Collectors.toList(), list -> {
|
||||
list.sort(Comparator
|
||||
.comparingInt(this::extractOutfitPriorityForSort)
|
||||
.thenComparing(TDesignPythonOutfitDetail::getId, Comparator.nullsLast(Long::compareTo)));
|
||||
return new ArrayDeque<>(list);
|
||||
})));
|
||||
}
|
||||
|
||||
private TDesignPythonOutfitDetail reuseOutfitDetail(Integer priority, String imageCategory,
|
||||
Map<Integer, TDesignPythonOutfitDetail> priorityMap,
|
||||
Map<String, Deque<TDesignPythonOutfitDetail>> categoryBuckets,
|
||||
Set<Long> reusedIds) {
|
||||
TDesignPythonOutfitDetail reused = null;
|
||||
if (Objects.nonNull(priority)) {
|
||||
reused = priorityMap.remove(Math.abs(priority));
|
||||
}
|
||||
if (Objects.nonNull(reused)) {
|
||||
markReusedLayer(reused, reusedIds);
|
||||
return reused;
|
||||
}
|
||||
Deque<TDesignPythonOutfitDetail> bucket = categoryBuckets.get(imageCategory);
|
||||
while (bucket != null && !bucket.isEmpty()) {
|
||||
TDesignPythonOutfitDetail candidate = bucket.pollFirst();
|
||||
if (markReusedLayer(candidate, reusedIds)) {
|
||||
Integer candidatePriority = candidate.getPriority();
|
||||
if (Objects.nonNull(candidatePriority)) {
|
||||
priorityMap.remove(Math.abs(candidatePriority), candidate);
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean markReusedDetail(DesignItemDetail detail, Set<Long> reusedIds) {
|
||||
if (Objects.isNull(detail)) {
|
||||
return false;
|
||||
}
|
||||
Long id = detail.getId();
|
||||
return Objects.isNull(id) || reusedIds.add(id);
|
||||
}
|
||||
|
||||
private boolean markReusedLayer(TDesignPythonOutfitDetail detail, Set<Long> reusedIds) {
|
||||
if (Objects.isNull(detail)) {
|
||||
return false;
|
||||
}
|
||||
Long id = detail.getId();
|
||||
return Objects.isNull(id) || reusedIds.add(id);
|
||||
}
|
||||
|
||||
private int safePriorityValue(Integer priority) {
|
||||
return Objects.isNull(priority) ? Integer.MAX_VALUE : priority;
|
||||
}
|
||||
|
||||
private int safeAbsPriorityValue(Integer priority) {
|
||||
return Objects.isNull(priority) ? Integer.MAX_VALUE : Math.abs(priority);
|
||||
}
|
||||
|
||||
private int extractDetailPriorityForSort(DesignItemDetail detail) {
|
||||
return safePriorityValue(detail.getPriority());
|
||||
}
|
||||
|
||||
private int extractOutfitPriorityForSort(TDesignPythonOutfitDetail detail) {
|
||||
return safeAbsPriorityValue(detail.getPriority());
|
||||
}
|
||||
|
||||
private DesignItem selectById(Long id) {
|
||||
QueryWrapper<DesignItem> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id);
|
||||
|
||||
Reference in New Issue
Block a user