|
|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|