heheng
2024-11-27 3c633caa438147d94cbc37993b818766de06aafb
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
package com.gkhy.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.common.enums.DeleteFlagEnum;
import com.gkhy.common.exception.ServiceException;
import com.gkhy.common.utils.SecurityUtils;
import com.gkhy.common.utils.StringUtils;
import com.gkhy.system.domain.SysExpertClassify;
import com.gkhy.system.mapper.SysExpertClassifyMapper;
import com.gkhy.system.service.SysExpertClassifyService;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 系统专家分类表 服务实现类
 * </p>
 *
 * @author kzy
 * @since 2023-11-27 16:33:33
 */
@Service
public class SysExpertClassifyServiceImpl extends ServiceImpl<SysExpertClassifyMapper, SysExpertClassify> implements SysExpertClassifyService {
 
    @Override
    public List<SysExpertClassify> classifyTree(SysExpertClassify expertClassify) {
        LambdaQueryWrapper<SysExpertClassify> lambdaQueryWrapper = Wrappers.<SysExpertClassify>lambdaQuery();
        if(StringUtils.isNotBlank(expertClassify.getClassifyName())){
            lambdaQueryWrapper.like(SysExpertClassify::getClassifyName,expertClassify.getClassifyName());
        }
        lambdaQueryWrapper.eq(SysExpertClassify::getDelFlag, DeleteFlagEnum.UN_DELETE.getCode());
        List<SysExpertClassify> classifies= list(lambdaQueryWrapper);
        //筛选出所有一级标签
        return classifies.stream()
                .filter(classifyEntity -> classifyEntity.getParentId()==0L)
                .peek(classifyEntity -> classifyEntity.setChildren(this.listClassifyChildren(classifyEntity,classifies)))
                .collect(Collectors.toList());
    }
 
    public List<SysExpertClassify> listClassifyChildren(SysExpertClassify classify,List<SysExpertClassify> classifies){
        //递归查找子类
        return classifies.stream()
                .filter(classifyEntity -> Objects.equals(classifyEntity.getParentId(), classify.getId()))
                .peek(classifyEntity -> classifyEntity.setChildren(this.listClassifyChildren(classifyEntity,classifies)))
                .collect(Collectors.toList());
    }
 
 
    @Override
    public int modClassify(SysExpertClassify expertClassify) {
        expertClassify.setUpdateBy(SecurityUtils.getUsername());
        boolean b=updateById(expertClassify);
        if(!b){
            throw new ServiceException("修改专家分类失败");
        }
        return 1;
    }
 
    @Override
    public int delClassify(Long classifyId) {
        SysExpertClassify classify = new SysExpertClassify();
        classify.setId(classifyId);
        classify.setDelFlag(DeleteFlagEnum.DELETED.getCode().intValue());
        classify.setUpdateBy(SecurityUtils.getUsername());
        boolean b=updateById(classify);
        if(!b){
            throw new ServiceException("删除专家分类失败");
        }
        return 1;
    }
 
    @Override
    public int addClassify(SysExpertClassify expertClassify) {
        expertClassify.setCreateBy(SecurityUtils.getUsername());
        boolean b=save(expertClassify);
        if(!b){
            throw new ServiceException("新增专家分类失败");
        }
        return 1;
    }
}