Fixiaobai
2023-09-05 c9da1b0da1178911e383ddcaebecd1e088fa6004
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
package com.yuanchu.limslaboratory.service.impl;
 
import cn.hutool.core.date.DateUtil;
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) {
        List<Classify> classify1 = classifyMapper.selectOneByName(classify);
        if (classify1.size()>0){
            return 2;
        } else {
            classify.setCreateTime(DateUtil.date());
            return classifyMapper.insert(classify);
        }
    }
 
    @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;
    }
}