Просмотр исходного кода

feat: add dimension config and knowledge tag services

Ultraworked with Sisyphus

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Sisyphus 3 месяцев назад
Родитель
Сommit
104032c01f

+ 29 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/DanKnowledgeTagService.java

@@ -0,0 +1,29 @@
+package com.etotem.cfc.service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.etotem.cfc.entity.DanKnowledgeTag;
+import com.etotem.cfc.mapper.DanKnowledgeTagMapper;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class DanKnowledgeTagService extends ServiceImpl<DanKnowledgeTagMapper, DanKnowledgeTag> {
+
+    public List<DanKnowledgeTag> listAll() {
+        return this.list();
+    }
+
+    public DanKnowledgeTag saveTag(DanKnowledgeTag tag) {
+        if (tag.getId() != null) {
+            this.updateById(tag);
+        } else {
+            this.save(tag);
+        }
+        return tag;
+    }
+
+    public boolean deleteTag(Long id) {
+        return this.removeById(id);
+    }
+}

+ 77 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/ProductDimensionConfigService.java

@@ -0,0 +1,77 @@
+package com.etotem.cfc.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.etotem.cfc.entity.ProductDimensionConfig;
+import com.etotem.cfc.mapper.ProductDimensionConfigMapper;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Service
+public class ProductDimensionConfigService extends ServiceImpl<ProductDimensionConfigMapper, ProductDimensionConfig> {
+
+    public Map<String, Object> list(String dimensionType, Integer enabled, int page, int size) {
+        Page<ProductDimensionConfig> p = new Page<>(page, size);
+        LambdaQueryWrapper<ProductDimensionConfig> wrapper = new LambdaQueryWrapper<>();
+        if (dimensionType != null && !dimensionType.isEmpty()) {
+            wrapper.eq(ProductDimensionConfig::getDimensionType, dimensionType);
+        }
+        if (enabled != null) {
+            wrapper.eq(ProductDimensionConfig::getEnabled, enabled);
+        }
+        wrapper.orderByAsc(ProductDimensionConfig::getSort);
+        this.page(p, wrapper);
+        Map<String, Object> data = new HashMap<>();
+        data.put("records", p.getRecords());
+        data.put("total", p.getTotal());
+        data.put("page", p.getCurrent());
+        data.put("size", p.getSize());
+        return data;
+    }
+
+    public ProductDimensionConfig getByCode(String dimensionCode) {
+        LambdaQueryWrapper<ProductDimensionConfig> wrapper = new LambdaQueryWrapper<ProductDimensionConfig>()
+            .eq(ProductDimensionConfig::getDimensionCode, dimensionCode);
+        return this.getOne(wrapper, false);
+    }
+
+    public ProductDimensionConfig saveConfig(ProductDimensionConfig config) {
+        if (config.getId() != null) {
+            this.updateById(config);
+        } else {
+            this.save(config);
+        }
+        return config;
+    }
+
+    public boolean deleteConfig(Long id) {
+        return this.removeById(id);
+    }
+
+    public List<ProductDimensionConfig> tree() {
+        List<ProductDimensionConfig> all = this.list();
+        List<ProductDimensionConfig> roots = all.stream()
+            .filter(d -> d.getParentId() == null)
+            .collect(Collectors.toList());
+        for (ProductDimensionConfig root : roots) {
+            buildChildren(root, all);
+        }
+        return roots;
+    }
+
+    private void buildChildren(ProductDimensionConfig parent, List<ProductDimensionConfig> all) {
+        List<ProductDimensionConfig> children = all.stream()
+            .filter(d -> parent.getId().equals(d.getParentId()))
+            .collect(Collectors.toList());
+        if (!children.isEmpty()) {
+            for (ProductDimensionConfig child : children) {
+                buildChildren(child, all);
+            }
+        }
+    }
+}