XiaoRuby
2023-07-25 653cbd6bc42565dbdcc7fdbe652874738b1908df
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
package com.yuanchu.limslaboratory.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yuanchu.limslaboratory.pojo.Classify;
import com.yuanchu.limslaboratory.mapper.ClassifyMapper;
import com.yuanchu.limslaboratory.service.ClassifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-20
 */
@Service
public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify> implements ClassifyService {
 
    @Resource
    private ClassifyMapper classifyMapper;
 
    @Override
    public Integer addClassifyInformation(Classify classify) {
        if (ObjectUtils.isEmpty(classify.getFatherName())){
            classify.setFatherName(classify.getSonName());
            classify.setSonName(null);
            LambdaQueryWrapper<Classify> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(Classify::getFatherName, classify.getFatherName());
            wrapper.isNull(Classify::getSonName);
            wrapper.eq(Classify::getState, 1);
            Classify classify1 = classifyMapper.selectOne(wrapper);
            if (ObjectUtils.isEmpty(classify1)){
                return classifyMapper.insert(classify);
            }
            return 2;
        }
        LambdaQueryWrapper<Classify> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Classify::getFatherName, classify.getFatherName());
        wrapper.eq(Classify::getSonName, classify.getSonName());
        wrapper.eq(Classify::getState, 1);
        Classify classify1 = classifyMapper.selectOne(wrapper);
        if (ObjectUtils.isEmpty(classify1)){
            return classifyMapper.insert(classify);
        } else {
            return 3;
        }
    }
 
    @Override
    public List<Map<String, Object>> getListClassifyInformation(String classifyName) {
        LambdaQueryWrapper<Classify> wrapper = new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(classifyName)){
            wrapper.like(Classify::getFatherName, classifyName);
        }
        wrapper.groupBy(Classify::getFatherName);
        wrapper.select(Classify::getId, Classify::getFatherName);
        List<Map<String, Object>> maps = classifyMapper.selectMaps(wrapper);
        for (Map<String, Object> map : maps){
            LambdaQueryWrapper<Classify> wrapper1 = new LambdaQueryWrapper<>();
            wrapper1.eq(Classify::getFatherName, map.get("father_name"));
            wrapper1.isNotNull(Classify::getSonName);
            wrapper1.select(Classify::getId, Classify::getSonName);
            List<Map<String, Object>> maps1 = classifyMapper.selectMaps(wrapper1);
            if (!ObjectUtils.isEmpty(maps1)){
                map.put("children", maps1);
                map.remove("id");
            } else {
                map.put("children", null);
            }
        }
        return maps;
    }
 
    @Override
    public Boolean deleteClassifyInformation(String classifyId) {
        LambdaUpdateWrapper<Classify> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Classify::getId, classifyId);
        wrapper.set(Classify::getState, 0);
        int isDeleteSuccess = classifyMapper.update(new Classify(), wrapper);
        return isDeleteSuccess > 0;
    }
 
    @Override
    public Boolean updateClassifyInformation(Classify classify) {
        LambdaUpdateWrapper<Classify> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(Classify::getId, classify.getId());
        int isUpdateClassifySuccess = classifyMapper.update(classify, updateWrapper);
        return isUpdateClassifySuccess > 0;
    }
}