|
|
@@ -1,32 +1,32 @@
|
|
|
package org.dromara.mall.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import org.dromara.common.core.utils.MapstructUtils;
|
|
|
-import org.dromara.common.core.utils.StringUtils;
|
|
|
-import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
-import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.mall.domain.EpCategoryItem;
|
|
|
+import org.dromara.mall.domain.EpCategoryMain;
|
|
|
import org.dromara.mall.domain.bo.EpCategoryItemBo;
|
|
|
+import org.dromara.mall.domain.bo.EpCategoryMainBo;
|
|
|
import org.dromara.mall.domain.vo.EpCategoryItemVo;
|
|
|
+import org.dromara.mall.domain.vo.EpCategoryMainVo;
|
|
|
import org.dromara.mall.domain.vo.EpCategoryResponseVo;
|
|
|
import org.dromara.mall.mapper.EpCategoryItemMapper;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.dromara.mall.domain.bo.EpCategoryMainBo;
|
|
|
-import org.dromara.mall.domain.vo.EpCategoryMainVo;
|
|
|
-import org.dromara.mall.domain.EpCategoryMain;
|
|
|
import org.dromara.mall.mapper.EpCategoryMainMapper;
|
|
|
import org.dromara.mall.service.IEpCategoryMainService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Collection;
|
|
|
-import com.fasterxml.jackson.databind.JsonNode;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
/**
|
|
|
* 分类设置主Service业务层处理
|
|
|
@@ -37,7 +37,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
@Slf4j
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
-public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper, EpCategoryMain> implements IEpCategoryMainService {
|
|
|
+public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper, EpCategoryMain> implements IEpCategoryMainService {
|
|
|
|
|
|
private final EpCategoryMainMapper baseMapper;
|
|
|
|
|
|
@@ -52,7 +52,7 @@ public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper
|
|
|
* @return 分类设置主
|
|
|
*/
|
|
|
@Override
|
|
|
- public EpCategoryMainVo queryById(Long id){
|
|
|
+ public EpCategoryMainVo queryById(Long id) {
|
|
|
// 查询主表数据
|
|
|
EpCategoryMainVo mainVo = baseMapper.selectVoById(id);
|
|
|
if (mainVo == null) {
|
|
|
@@ -113,7 +113,6 @@ public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 分页查询分类设置主列表
|
|
|
*
|
|
|
@@ -125,6 +124,13 @@ public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper
|
|
|
public TableDataInfo<EpCategoryMainVo> queryPageList(EpCategoryMainBo bo, PageQuery pageQuery) {
|
|
|
LambdaQueryWrapper<EpCategoryMain> lqw = buildQueryWrapper(bo);
|
|
|
Page<EpCategoryMainVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ List<EpCategoryMainVo> records = result.getRecords();
|
|
|
+
|
|
|
+ // 为每个分类填充对应的标签项
|
|
|
+ for (EpCategoryMainVo record : records) {
|
|
|
+ fillCategoryItems(record);
|
|
|
+ }
|
|
|
+
|
|
|
return TableDataInfo.build(result);
|
|
|
}
|
|
|
|
|
|
@@ -168,7 +174,7 @@ public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
|
bo.setId(add.getId());
|
|
|
-
|
|
|
+
|
|
|
// 保存分类项列表
|
|
|
saveCategoryItems(add.getId(), bo);
|
|
|
}
|
|
|
@@ -200,17 +206,17 @@ public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper
|
|
|
* 保存分类项(从 remark 和 categoryItemList 中解析)
|
|
|
*
|
|
|
* @param categoryId 分类ID
|
|
|
- * @param bo 业务对象
|
|
|
+ * @param bo 业务对象
|
|
|
*/
|
|
|
private void saveCategoryItems(Long categoryId, EpCategoryMainBo bo) {
|
|
|
List<EpCategoryItem> items = new java.util.ArrayList<>();
|
|
|
-
|
|
|
+
|
|
|
// 1. 处理 remark 中的 JSON 数据
|
|
|
String remark = bo.getRemark();
|
|
|
if (StringUtils.isNotBlank(remark)) {
|
|
|
try {
|
|
|
JsonNode rootNode = objectMapper.readTree(remark);
|
|
|
-
|
|
|
+
|
|
|
// 处理 tags
|
|
|
JsonNode tagsNode = rootNode.get("tags");
|
|
|
if (tagsNode != null && tagsNode.isArray()) {
|
|
|
@@ -225,7 +231,7 @@ public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper
|
|
|
items.add(item);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 处理 notes
|
|
|
JsonNode notesNode = rootNode.get("notes");
|
|
|
if (notesNode != null && notesNode.isArray()) {
|
|
|
@@ -240,7 +246,7 @@ public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper
|
|
|
items.add(item);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 处理 groups(如果需要)
|
|
|
JsonNode groupsNode = rootNode.get("groups");
|
|
|
if (groupsNode != null && groupsNode.isArray()) {
|
|
|
@@ -259,7 +265,7 @@ public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper
|
|
|
log.error("解析 remark JSON 数据失败", e);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 2. 处理 categoryItemList(如果存在,优先级更高)
|
|
|
List<EpCategoryItemBo> categoryItemList = bo.getCategoryItemList();
|
|
|
if (categoryItemList != null && !categoryItemList.isEmpty()) {
|
|
|
@@ -269,17 +275,56 @@ public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper
|
|
|
items.add(item);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 3. 批量插入
|
|
|
if (!items.isEmpty()) {
|
|
|
categoryItemMapper.insertBatch(items);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 为分类填充标签项(根据 itemType 区分 tag 和 note)
|
|
|
+ *
|
|
|
+ * @param vo 分类主表 VO
|
|
|
+ */
|
|
|
+ private void fillCategoryItems(EpCategoryMainVo vo) {
|
|
|
+ if (vo == null || vo.getId() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询该分类下的所有子项
|
|
|
+ List<EpCategoryItemVo> allItems = categoryItemMapper.selectVoList(
|
|
|
+ Wrappers.<EpCategoryItem>lambdaQuery()
|
|
|
+ .eq(EpCategoryItem::getCategoryId, vo.getId())
|
|
|
+ .orderByAsc(EpCategoryItem::getSortOrder)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (allItems == null || allItems.isEmpty()) {
|
|
|
+ vo.setTags(new java.util.ArrayList<>());
|
|
|
+ vo.setNotes(new java.util.ArrayList<>());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据 itemType 分离 tag 和 note
|
|
|
+ List<EpCategoryItemVo> leftItems = new java.util.ArrayList<>(); // tag 类型
|
|
|
+ List<EpCategoryItemVo> rightItems = new java.util.ArrayList<>(); // note 类型
|
|
|
+
|
|
|
+ for (EpCategoryItemVo item : allItems) {
|
|
|
+ if ("tag".equals(item.getItemType())) {
|
|
|
+ leftItems.add(item);
|
|
|
+ } else if ("note".equals(item.getItemType())) {
|
|
|
+ rightItems.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setTags(leftItems);
|
|
|
+ vo.setNotes(rightItems);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存前的数据校验
|
|
|
*/
|
|
|
- private void validEntityBeforeSave(EpCategoryMain entity){
|
|
|
+ private void validEntityBeforeSave(EpCategoryMain entity) {
|
|
|
//TODO 做一些数据校验,如唯一约束
|
|
|
}
|
|
|
|
|
|
@@ -292,9 +337,23 @@ public class EpCategoryMainServiceImpl extends ServiceImpl<EpCategoryMainMapper
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
- if(isValid){
|
|
|
+ if (isValid) {
|
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
|
}
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改状态
|
|
|
+ *
|
|
|
+ * @param bo 信息
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int updateStatus(EpCategoryMainBo bo) {
|
|
|
+ EpCategoryMain categoryMain = new EpCategoryMain();
|
|
|
+ categoryMain.setId(bo.getId());
|
|
|
+ categoryMain.setStatus(bo.getStatus());
|
|
|
+ return baseMapper.updateById(categoryMain);
|
|
|
+ }
|
|
|
}
|