|
|
@@ -52,9 +52,9 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
public List<StoreDictionary> queryBusinessSectionTree() {
|
|
|
// 查询所有经营种类数据
|
|
|
LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(StoreDictionary::getTypeName, "business_section");
|
|
|
+ queryWrapper.in(StoreDictionary::getTypeName, "business_section","business_type","business_classify");
|
|
|
queryWrapper.eq(StoreDictionary::getDeleteFlag, 0);
|
|
|
- queryWrapper.orderByAsc(StoreDictionary::getDictId);
|
|
|
+ queryWrapper.orderByAsc(StoreDictionary::getSortId);
|
|
|
List<StoreDictionary> storeDictionaryList = storeDictionaryMapper.selectList(queryWrapper);
|
|
|
|
|
|
// 构建三级树形结构
|
|
|
@@ -122,7 +122,7 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
}
|
|
|
|
|
|
// 设置固定字段
|
|
|
- storeDictionary.setTypeName("business_section");
|
|
|
+// storeDictionary.setTypeName("business_section");
|
|
|
// storeDictionary.setTypeDetail("经营板块");
|
|
|
storeDictionary.setDeleteFlag(0);
|
|
|
storeDictionary.setCreatedTime(new Date());
|
|
|
@@ -137,16 +137,24 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
// 如果是二级或三级,验证父节点是否存在
|
|
|
if (parentId != 0) {
|
|
|
StoreDictionary parent = storeDictionaryMapper.selectById(parentId);
|
|
|
- if (parent == null || !"business_section".equals(parent.getTypeName()) || parent.getDeleteFlag() == 1) {
|
|
|
+ if (parent == null || parent.getDeleteFlag() == 1) {
|
|
|
throw new IllegalArgumentException("父节点不存在或已删除");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 生成 dict_id:查询同级(相同 parent_id)的最大 dict_id,然后 +1
|
|
|
- String maxDictId = getMaxDictIdByParentId(parentId);
|
|
|
- int nextDictId = (maxDictId == null ? 0 : Integer.parseInt(maxDictId)) + 1;
|
|
|
+ // 生成 dict_id:根据 typeName 查询最大 dict_id,然后 +1
|
|
|
+ String typeName = storeDictionary.getTypeName();
|
|
|
+ if (StringUtils.isBlank(typeName)) {
|
|
|
+ throw new IllegalArgumentException("typeName不能为空");
|
|
|
+ }
|
|
|
+ String maxDictId = getMaxDictIdByTypeName(typeName);
|
|
|
+ int nextDictId = (maxDictId == null ? 1 : Integer.parseInt(maxDictId)) + 1;
|
|
|
storeDictionary.setDictId(String.valueOf(nextDictId));
|
|
|
|
|
|
+ // 生成 sort_id
|
|
|
+ Integer maxSortId = getMaxSortIdByParentId(parentId);
|
|
|
+ storeDictionary.setSortId(maxSortId == null ? 1 : maxSortId + 1);
|
|
|
+
|
|
|
// 保存
|
|
|
return this.save(storeDictionary);
|
|
|
}
|
|
|
@@ -172,9 +180,6 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
if (existing == null) {
|
|
|
throw new IllegalArgumentException("记录不存在");
|
|
|
}
|
|
|
- if (!"business_section".equals(existing.getTypeName())) {
|
|
|
- throw new IllegalArgumentException("该记录不是经营种类类型");
|
|
|
- }
|
|
|
if (existing.getDeleteFlag() == 1) {
|
|
|
throw new IllegalArgumentException("该记录已删除");
|
|
|
}
|
|
|
@@ -202,8 +207,8 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
// 标准化parentId用于比较(null转为0)
|
|
|
Integer normalizedParentId = (parentId == null) ? 0 : parentId;
|
|
|
Integer normalizedExistingParentId = (existingParentId == null) ? 0 : existingParentId;
|
|
|
- String oldDictId = existing.getDictId();
|
|
|
- String newDictId = storeDictionary.getDictId();
|
|
|
+ Integer oldSortId = existing.getSortId();
|
|
|
+ Integer newSortId = storeDictionary.getSortId();
|
|
|
boolean parentIdChanged = !normalizedParentId.equals(normalizedExistingParentId);
|
|
|
|
|
|
// 判断是否修改了关键字段(parent_id)
|
|
|
@@ -221,41 +226,41 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
if (parentIdChanged) {
|
|
|
if (parentId != 0) {
|
|
|
StoreDictionary parent = storeDictionaryMapper.selectById(parentId);
|
|
|
- if (parent == null || !"business_section".equals(parent.getTypeName()) || parent.getDeleteFlag() == 1) {
|
|
|
+ if (parent == null || parent.getDeleteFlag() == 1) {
|
|
|
throw new IllegalArgumentException("父节点不存在或已删除");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 如果用户指定了新位置(newDictId不为空),使用用户指定的位置
|
|
|
+ // 如果用户指定了新位置(newSortId不为空),使用用户指定的位置
|
|
|
// 否则,使用新节点下的最大+1
|
|
|
- if (StringUtils.isBlank(newDictId)) {
|
|
|
- String maxDictId = getMaxDictIdByParentId(parentId);
|
|
|
- int nextDictId = (maxDictId == null ? 0 : Integer.parseInt(maxDictId)) + 1;
|
|
|
- newDictId = String.valueOf(nextDictId);
|
|
|
- storeDictionary.setDictId(newDictId);
|
|
|
+ if (newSortId == null) {
|
|
|
+ Integer maxSortId = getMaxSortIdByParentId(parentId);
|
|
|
+ int nextSortId = (maxSortId == null ? 1 : maxSortId) + 1;
|
|
|
+ newSortId = nextSortId;
|
|
|
+ storeDictionary.setSortId(newSortId);
|
|
|
}
|
|
|
|
|
|
// 原节点下,原位置之后的记录需要前移(dictId - 1)
|
|
|
- adjustSortOrderForMoveOut(existing.getId(), normalizedExistingParentId, oldDictId);
|
|
|
+ adjustSortOrderForMoveOut(existing.getId(), normalizedExistingParentId, oldSortId);
|
|
|
|
|
|
// 新节点下,如果指定了新位置,需要调整新节点下的排序
|
|
|
- if (StringUtils.isNotBlank(newDictId)) {
|
|
|
+ if (newSortId != null) {
|
|
|
try {
|
|
|
- int newOrder = Integer.parseInt(newDictId);
|
|
|
- String maxDictId = getMaxDictIdByParentId(parentId);
|
|
|
- int maxOrder = (maxDictId == null ? 0 : Integer.parseInt(maxDictId));
|
|
|
+ int newOrder = newSortId;
|
|
|
+ Integer maxSortId = getMaxSortIdByParentId(parentId);
|
|
|
+ int maxOrder = (maxSortId == null ? 0 : maxSortId);
|
|
|
// 如果新位置不是最大+1,需要调整新节点下的排序
|
|
|
if (newOrder <= maxOrder) {
|
|
|
- adjustSortOrderForMoveIn(existing.getId(), normalizedParentId, newDictId);
|
|
|
+ adjustSortOrderForMoveIn(existing.getId(), normalizedParentId, newSortId);
|
|
|
}
|
|
|
} catch (NumberFormatException e) {
|
|
|
- log.warn("无法解析新dictId: {}", newDictId, e);
|
|
|
+ log.warn("无法解析新sortId: {}", newSortId, e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 设置固定字段
|
|
|
- storeDictionary.setTypeName("business_section");
|
|
|
+// storeDictionary.setTypeName("business_section");
|
|
|
// 如果没有指定删除标记,保持原有值;如果指定了,使用新值
|
|
|
Integer oldHidden = existing.getHidden();
|
|
|
Integer newHidden = storeDictionary.getHidden() == null ? oldHidden : storeDictionary.getHidden();
|
|
|
@@ -268,11 +273,11 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
// 处理排序逻辑:如果 parentId 没有改变,但 dictId 改变了,需要调整同级其他记录的排序
|
|
|
if (!parentIdChanged) {
|
|
|
// 如果 dictId 为空,保持原有值
|
|
|
- if (StringUtils.isBlank(newDictId)) {
|
|
|
- storeDictionary.setDictId(oldDictId);
|
|
|
- } else if (!newDictId.equals(oldDictId)) {
|
|
|
+ if (newSortId == null) {
|
|
|
+ storeDictionary.setSortId(oldSortId);
|
|
|
+ } else if (!newSortId.equals(oldSortId)) {
|
|
|
// 调整同级其他记录的排序
|
|
|
- adjustSortOrder(existing.getId(), normalizedParentId, oldDictId, newDictId);
|
|
|
+ adjustSortOrder(existing.getId(), normalizedParentId, oldSortId, newSortId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -297,7 +302,7 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
*/
|
|
|
private boolean hasUndeletedChildren(Integer parentId) {
|
|
|
LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(StoreDictionary::getTypeName, "business_section");
|
|
|
+ queryWrapper.in(StoreDictionary::getTypeName, "business_section","business_type","business_classify");;
|
|
|
queryWrapper.eq(StoreDictionary::getParentId, parentId);
|
|
|
queryWrapper.eq(StoreDictionary::getDeleteFlag, 0);
|
|
|
queryWrapper.last("LIMIT 1");
|
|
|
@@ -320,7 +325,7 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
|
|
|
// 查询所有未删除的子节点
|
|
|
LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(StoreDictionary::getTypeName, "business_section");
|
|
|
+ queryWrapper.in(StoreDictionary::getTypeName, "business_section","business_type","business_classify");
|
|
|
queryWrapper.eq(StoreDictionary::getParentId, parentId);
|
|
|
queryWrapper.eq(StoreDictionary::getDeleteFlag, 0);
|
|
|
|
|
|
@@ -343,14 +348,32 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据 parent_id 获取同级最大 dict_id
|
|
|
+ * 根据 typeName 获取最大 dict_id
|
|
|
*
|
|
|
- * @param parentId 父节点ID
|
|
|
+ * @param typeName 类型名称
|
|
|
* @return 最大 dict_id,如果不存在则返回 null
|
|
|
*/
|
|
|
- private String getMaxDictIdByParentId(Integer parentId) {
|
|
|
+ private String getMaxDictIdByTypeName(String typeName) {
|
|
|
LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(StoreDictionary::getTypeName, "business_section");
|
|
|
+ queryWrapper.eq(StoreDictionary::getTypeName, typeName);
|
|
|
+ queryWrapper.eq(StoreDictionary::getDeleteFlag, 0);
|
|
|
+
|
|
|
+ queryWrapper.orderByDesc(StoreDictionary::getDictId);
|
|
|
+ queryWrapper.last("LIMIT 1");
|
|
|
+
|
|
|
+ StoreDictionary maxDict = storeDictionaryMapper.selectOne(queryWrapper);
|
|
|
+ return maxDict != null ? maxDict.getDictId() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据parentId获取最大的sortId
|
|
|
+ *
|
|
|
+ * @param parentId 父节点ID
|
|
|
+ * @return 最大的sortId,如果不存在则返回null
|
|
|
+ */
|
|
|
+ private Integer getMaxSortIdByParentId(Integer parentId) {
|
|
|
+ LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(StoreDictionary::getTypeName, "business_section","business_type","business_classify");;
|
|
|
queryWrapper.eq(StoreDictionary::getDeleteFlag, 0);
|
|
|
|
|
|
if (parentId == null || parentId == 0) {
|
|
|
@@ -360,11 +383,11 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
queryWrapper.eq(StoreDictionary::getParentId, parentId);
|
|
|
}
|
|
|
|
|
|
- queryWrapper.orderByDesc(StoreDictionary::getDictId);
|
|
|
+ queryWrapper.orderByDesc(StoreDictionary::getSortId);
|
|
|
queryWrapper.last("LIMIT 1");
|
|
|
|
|
|
StoreDictionary maxDict = storeDictionaryMapper.selectOne(queryWrapper);
|
|
|
- return maxDict != null ? maxDict.getDictId() : null;
|
|
|
+ return maxDict != null && maxDict.getSortId() != null ? maxDict.getSortId() : null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -374,13 +397,13 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
*
|
|
|
* @param currentId 当前记录ID
|
|
|
* @param parentId 父节点ID
|
|
|
- * @param oldDictId 原dictId
|
|
|
- * @param newDictId 新dictId
|
|
|
+ * @param oldSortId 原sortId
|
|
|
+ * @param newSortId 新sortId
|
|
|
*/
|
|
|
- private void adjustSortOrder(Integer currentId, Integer parentId, String oldDictId, String newDictId) {
|
|
|
+ private void adjustSortOrder(Integer currentId, Integer parentId, Integer oldSortId, Integer newSortId) {
|
|
|
try {
|
|
|
- int oldOrder = Integer.parseInt(oldDictId);
|
|
|
- int newOrder = Integer.parseInt(newDictId);
|
|
|
+ int oldOrder = oldSortId;
|
|
|
+ int newOrder = newSortId;
|
|
|
|
|
|
// 如果排序没有改变,直接返回
|
|
|
if (oldOrder == newOrder) {
|
|
|
@@ -389,7 +412,7 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
|
|
|
// 查询同级所有记录(排除当前记录)
|
|
|
LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(StoreDictionary::getTypeName, "business_section");
|
|
|
+ queryWrapper.in(StoreDictionary::getTypeName, "business_section","business_type","business_classify");;
|
|
|
queryWrapper.eq(StoreDictionary::getDeleteFlag, 0);
|
|
|
queryWrapper.ne(StoreDictionary::getId, currentId);
|
|
|
|
|
|
@@ -411,14 +434,14 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
// 将新dictId到原dictId之间的记录的dictId都+1
|
|
|
for (StoreDictionary sibling : siblings) {
|
|
|
try {
|
|
|
- int siblingOrder = Integer.parseInt(sibling.getDictId());
|
|
|
+ int siblingOrder = sibling.getSortId();
|
|
|
if (siblingOrder >= newOrder && siblingOrder < oldOrder) {
|
|
|
- sibling.setDictId(String.valueOf(siblingOrder + 1));
|
|
|
+ sibling.setSortId(siblingOrder + 1);
|
|
|
sibling.setUpdatedTime(new Date());
|
|
|
storeDictionaryMapper.updateById(sibling);
|
|
|
}
|
|
|
} catch (NumberFormatException e) {
|
|
|
- log.warn("无法解析dictId: {}", sibling.getDictId(), e);
|
|
|
+ log.warn("无法解析sortId: {}", sibling.getSortId(), e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -427,19 +450,19 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
// 将原dictId到新dictId之间的记录的dictId都-1
|
|
|
for (StoreDictionary sibling : siblings) {
|
|
|
try {
|
|
|
- int siblingOrder = Integer.parseInt(sibling.getDictId());
|
|
|
+ int siblingOrder = sibling.getSortId();
|
|
|
if (siblingOrder > oldOrder && siblingOrder <= newOrder) {
|
|
|
- sibling.setDictId(String.valueOf(siblingOrder - 1));
|
|
|
+ sibling.setSortId(siblingOrder - 1);
|
|
|
sibling.setUpdatedTime(new Date());
|
|
|
storeDictionaryMapper.updateById(sibling);
|
|
|
}
|
|
|
} catch (NumberFormatException e) {
|
|
|
- log.warn("无法解析dictId: {}", sibling.getDictId(), e);
|
|
|
+ log.warn("无法解析sortId: {}", sibling.getSortId(), e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} catch (NumberFormatException e) {
|
|
|
- log.error("调整排序失败,dictId格式错误: oldDictId={}, newDictId={}", oldDictId, newDictId, e);
|
|
|
+ log.error("调整排序失败,sortId格式错误: oldSortId={}, newSortId={}", oldSortId, newSortId, e);
|
|
|
} catch (Exception e) {
|
|
|
log.error("调整排序失败", e);
|
|
|
}
|
|
|
@@ -450,15 +473,15 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
*
|
|
|
* @param currentId 当前记录ID
|
|
|
* @param oldParentId 原父节点ID
|
|
|
- * @param oldDictId 原dictId
|
|
|
+ * @param oldSortId 原sortId
|
|
|
*/
|
|
|
- private void adjustSortOrderForMoveOut(Integer currentId, Integer oldParentId, String oldDictId) {
|
|
|
+ private void adjustSortOrderForMoveOut(Integer currentId, Integer oldParentId, Integer oldSortId) {
|
|
|
try {
|
|
|
- int oldOrder = Integer.parseInt(oldDictId);
|
|
|
+ int oldOrder = oldSortId;
|
|
|
|
|
|
// 查询原节点同级所有记录(排除当前记录)
|
|
|
LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(StoreDictionary::getTypeName, "business_section");
|
|
|
+ queryWrapper.in(StoreDictionary::getTypeName, "business_section","business_type","business_classify");;
|
|
|
queryWrapper.eq(StoreDictionary::getDeleteFlag, 0);
|
|
|
queryWrapper.ne(StoreDictionary::getId, currentId);
|
|
|
|
|
|
@@ -478,18 +501,18 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
// 原位置之后的记录需要前移(dictId - 1)
|
|
|
for (StoreDictionary sibling : siblings) {
|
|
|
try {
|
|
|
- int siblingOrder = Integer.parseInt(sibling.getDictId());
|
|
|
+ int siblingOrder = sibling.getSortId();
|
|
|
if (siblingOrder > oldOrder) {
|
|
|
- sibling.setDictId(String.valueOf(siblingOrder - 1));
|
|
|
+ sibling.setSortId(siblingOrder - 1);
|
|
|
sibling.setUpdatedTime(new Date());
|
|
|
storeDictionaryMapper.updateById(sibling);
|
|
|
}
|
|
|
} catch (NumberFormatException e) {
|
|
|
- log.warn("无法解析dictId: {}", sibling.getDictId(), e);
|
|
|
+ log.warn("无法解析sortId: {}", sibling.getSortId(), e);
|
|
|
}
|
|
|
}
|
|
|
} catch (NumberFormatException e) {
|
|
|
- log.error("移出节点排序调整失败,dictId格式错误: oldDictId={}", oldDictId, e);
|
|
|
+ log.error("移出节点排序调整失败,sortId格式错误: oldSortId={}", oldSortId, e);
|
|
|
} catch (Exception e) {
|
|
|
log.error("移出节点排序调整失败", e);
|
|
|
}
|
|
|
@@ -500,15 +523,15 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
*
|
|
|
* @param currentId 当前记录ID
|
|
|
* @param newParentId 新父节点ID
|
|
|
- * @param newDictId 新dictId
|
|
|
+ * @param newSortId 新sortId
|
|
|
*/
|
|
|
- private void adjustSortOrderForMoveIn(Integer currentId, Integer newParentId, String newDictId) {
|
|
|
+ private void adjustSortOrderForMoveIn(Integer currentId, Integer newParentId, Integer newSortId) {
|
|
|
try {
|
|
|
- int newOrder = Integer.parseInt(newDictId);
|
|
|
+ int newOrder = newSortId;
|
|
|
|
|
|
// 查询新节点同级所有记录(排除当前记录)
|
|
|
LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(StoreDictionary::getTypeName, "business_section");
|
|
|
+ queryWrapper.in(StoreDictionary::getTypeName, "business_section","business_type","business_classify");;
|
|
|
queryWrapper.eq(StoreDictionary::getDeleteFlag, 0);
|
|
|
queryWrapper.ne(StoreDictionary::getId, currentId);
|
|
|
|
|
|
@@ -528,9 +551,9 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
// 新位置之后的记录需要后移(dictId + 1)
|
|
|
for (StoreDictionary sibling : siblings) {
|
|
|
try {
|
|
|
- int siblingOrder = Integer.parseInt(sibling.getDictId());
|
|
|
+ int siblingOrder = sibling.getSortId();
|
|
|
if (siblingOrder >= newOrder) {
|
|
|
- sibling.setDictId(String.valueOf(siblingOrder + 1));
|
|
|
+ sibling.setSortId(siblingOrder + 1);
|
|
|
sibling.setUpdatedTime(new Date());
|
|
|
storeDictionaryMapper.updateById(sibling);
|
|
|
}
|
|
|
@@ -539,7 +562,7 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
}
|
|
|
}
|
|
|
} catch (NumberFormatException e) {
|
|
|
- log.error("移入节点排序调整失败,dictId格式错误: newDictId={}", newDictId, e);
|
|
|
+ log.error("移入节点排序调整失败,sortId格式错误: newSortId={}", newSortId, e);
|
|
|
} catch (Exception e) {
|
|
|
log.error("移入节点排序调整失败", e);
|
|
|
}
|
|
|
@@ -733,7 +756,7 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
int level, String hidden, List<String> errorMessages, int rowIndex) {
|
|
|
try {
|
|
|
// 查找或创建一级分类
|
|
|
- StoreDictionary firstLevel = findOrCreateLevel(firstLevelName, 0, 0, hidden);
|
|
|
+ StoreDictionary firstLevel = findOrCreateLevel(firstLevelName, null, 0, hidden);
|
|
|
if (firstLevel == null) {
|
|
|
throw new IllegalArgumentException("创建一级分类失败");
|
|
|
}
|
|
|
@@ -769,7 +792,7 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
private StoreDictionary findOrCreateLevel(String dictDetail, Integer parentId, int expectedLevel, String hidden) {
|
|
|
// 查找是否存在
|
|
|
LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(StoreDictionary::getTypeName, "business_section");
|
|
|
+ queryWrapper.in(StoreDictionary::getTypeName, "business_section","business_type","business_classify");;
|
|
|
queryWrapper.eq(StoreDictionary::getDeleteFlag, 0);
|
|
|
queryWrapper.eq(StoreDictionary::getDictDetail, dictDetail);
|
|
|
|
|
|
@@ -788,40 +811,30 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
|
|
|
// 创建新分类
|
|
|
StoreDictionary newDict = new StoreDictionary();
|
|
|
- newDict.setTypeName("business_section");
|
|
|
newDict.setDictDetail(dictDetail);
|
|
|
// 一级为经营版块 ,二级为经营种类,三级为分类
|
|
|
if (expectedLevel == 0) {
|
|
|
newDict.setTypeDetail("经营板块");
|
|
|
+ newDict.setTypeName("business_section");
|
|
|
} else if (expectedLevel == 1) {
|
|
|
newDict.setTypeDetail("经营种类");
|
|
|
+ newDict.setTypeName("business_type");
|
|
|
} else if (expectedLevel == 2) {
|
|
|
newDict.setTypeDetail("分类");
|
|
|
+ newDict.setTypeName("business_classify");
|
|
|
}
|
|
|
- newDict.setParentId(parentId == null ? 0 : parentId);
|
|
|
+ newDict.setParentId(parentId == null ? null : parentId);
|
|
|
newDict.setHidden(StringUtils.isNotBlank(hidden) && hidden.equals("隐藏") ? 1 : 0);
|
|
|
newDict.setDeleteFlag(0);
|
|
|
newDict.setCreatedTime(new Date());
|
|
|
|
|
|
// 生成 dict_id
|
|
|
- String maxDictId = getMaxDictIdByParentId(newDict.getParentId());
|
|
|
- /*int nextDictId;
|
|
|
- if (StringUtils.isNotBlank(sortOrder) && expectedLevel == 1) {
|
|
|
- try {
|
|
|
- nextDictId = Integer.parseInt(sortOrder);
|
|
|
- // 如果指定的排序已存在,需要调整
|
|
|
- String existingDictId = getDictIdByParentIdAndOrder(newDict.getParentId(), nextDictId);
|
|
|
- if (existingDictId != null) {
|
|
|
- // 使用最大+1
|
|
|
- nextDictId = (maxDictId == null ? 0 : Integer.parseInt(maxDictId)) + 1;
|
|
|
- }
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- nextDictId = (maxDictId == null ? 0 : Integer.parseInt(maxDictId)) + 1;
|
|
|
- }
|
|
|
- } else {
|
|
|
- nextDictId = (maxDictId == null ? 0 : Integer.parseInt(maxDictId)) + 1;
|
|
|
- }*/
|
|
|
+ String maxDictId = getMaxDictIdByTypeName(newDict.getTypeName());
|
|
|
newDict.setDictId(String.valueOf(maxDictId == null ? 1 : Integer.parseInt(maxDictId) + 1));
|
|
|
+
|
|
|
+ // 生成 sort_id
|
|
|
+ Integer maxSortId = getMaxSortIdByParentId(newDict.getParentId());
|
|
|
+ newDict.setSortId(maxSortId == null ? 1 : maxSortId + 1);
|
|
|
|
|
|
boolean saved = this.save(newDict);
|
|
|
return saved ? newDict : null;
|
|
|
@@ -836,7 +849,7 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
*/
|
|
|
private String getDictIdByParentIdAndOrder(Integer parentId, int order) {
|
|
|
LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(StoreDictionary::getTypeName, "business_section");
|
|
|
+ queryWrapper.in(StoreDictionary::getTypeName, "business_section","business_type","business_classify");;
|
|
|
queryWrapper.eq(StoreDictionary::getDeleteFlag, 0);
|
|
|
queryWrapper.eq(StoreDictionary::getDictId, String.valueOf(order));
|
|
|
|
|
|
@@ -848,7 +861,7 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
|
|
|
}
|
|
|
|
|
|
StoreDictionary dict = storeDictionaryMapper.selectOne(queryWrapper);
|
|
|
- return dict != null ? dict.getDictId() : null;
|
|
|
+ return dict != null ? dict.getSortId().toString() : null;
|
|
|
}
|
|
|
|
|
|
/**
|