zhongrj
2024-03-12 149d04de35cf9f6adb2f568da141bfd5f5a27329
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.category.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.common.node.TreeIntegerNode;
import org.springblade.common.utils.NodeTreeUtil;
import org.springblade.modules.category.dto.CategoryDTO;
import org.springblade.modules.category.entity.CategoryEntity;
import org.springblade.modules.category.excel.CategoryExcel;
import org.springblade.modules.category.vo.CategoryVO;
import org.springblade.modules.category.mapper.CategoryMapper;
import org.springblade.modules.category.service.ICategoryService;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
 
import java.util.List;
import java.util.Map;
 
/**
 * 天地图poi 分类表 服务实现类
 *
 * @author BladeX
 * @since 2023-10-28
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEntity> implements ICategoryService {
 
    @Override
    public IPage<CategoryVO> selectCategoryPage(IPage<CategoryVO> page, CategoryVO category) {
        return page.setRecords(baseMapper.selectCategoryPage(page, category));
    }
 
    /**
     * 天地图poi 分类获取
     */
    @Override
    public Object getCategory(CategoryVO category) {
        return baseMapper.getCategory(category);
    }
    /**
     * 查询场所标签
     * @param categoryDTO
     * @return
     */
    @Override
    public List<CategoryDTO> selectCategoryLabelList(CategoryDTO categoryDTO) {
        return this.baseMapper.selectCategoryList(categoryDTO);
    }
 
    @Override
    public List<TreeIntegerNode> tree(CategoryVO category) {
        Map<Integer, TreeIntegerNode> labelTreeList = baseMapper.getTreeList(category);
        List<TreeIntegerNode> nodeTree = NodeTreeUtil.getNodeTree(labelTreeList);
        nodeTree.forEach(node -> recursion(node));
        return nodeTree;
    }
 
    private void recursion(TreeIntegerNode node) {
        if (node.getChildren() != null && node.getChildren().size() > 0) {
            node.getChildren().forEach(node2 -> recursion(node2));
        } else {
            node.setChildren(null);
        }
    }
 
    /**
     * 标签导入
     * @param data
     * @param isCovered
     */
    @Override
    public void importCategory(List<CategoryExcel> data, Boolean isCovered) {
        for (CategoryExcel categoryExcel : data) {
            // 查询是否已存在
            QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("category_no",categoryExcel.getCategoryNo()).eq("is_deleted",0);
            CategoryEntity one = getOne(wrapper);
            if (null==one){
                // 新增
                CategoryEntity categoryEntity = new CategoryEntity();
                categoryEntity.setCategoryNo(categoryExcel.getCategoryNo());
                categoryEntity.setCategoryName(categoryExcel.getCategoryName());
                categoryEntity.setLevel(categoryExcel.getLevel());
                categoryEntity.setIsDeleted(0);
                categoryEntity.setParentNo(categoryExcel.getCategoryNo().substring(0,4));
                categoryEntity.setDescription(categoryExcel.getDescription());
                categoryEntity.setRemark(categoryExcel.getRemark());
                // 新增
                save(categoryEntity);
            }
        }
    }
}