zxl
2026-03-25 74e332504d98caaf8fab951d7d24be762b169f49
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
package com.tievd.jyz.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tievd.jyz.entity.Label;
import com.tievd.jyz.mapper.LabelMapper;
import com.tievd.jyz.service.ILabelService;
import org.springframework.stereotype.Service;
 
import java.util.Arrays;
import java.util.List;
 
/**
 * Label
 *
 * @author cube
 * @version V2.0.0
 * @since 2023-02-27
 */
@Service
public class LabelServiceImpl extends ServiceImpl<LabelMapper, Label> implements ILabelService {
 
    @Override
    public List<String> listLabel() {
        return baseMapper.listLabel();
    }
 
    @Override
    public boolean save(Label label) throws RuntimeException {
        LambdaQueryWrapper<Label> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Label::getLabelType, label.getLabelType());
        boolean existType = baseMapper.exists(queryWrapper);
        if (existType) {
            throw new RuntimeException("标签类型重复");
        }
        queryWrapper.clear();
        String[] labelNameArr = label.getLabelName().split(",");
        if (labelNameArr.length > 0) {
            List<String> list = Arrays.asList(labelNameArr);
            queryWrapper.clear();
            queryWrapper.and(qw -> {
                list.forEach(item -> {
                    qw.apply("FIND_IN_SET('" + item + "', label_name)").or();
                });
            });
        }
        boolean existName = baseMapper.exists(queryWrapper);
        if (existName) {
            throw new RuntimeException("标签内容重复");
        }
        baseMapper.insert(label);
        return true;
    }
 
    @Override
    public boolean updateById(Label label) throws RuntimeException {
        LambdaQueryWrapper<Label> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Label::getLabelType, label.getLabelType());
        queryWrapper.ne(Label::getId, label.getId());
        boolean exists = baseMapper.exists(queryWrapper);
        if (exists) {
            throw new RuntimeException("标签类型重复");
        }
        String[] labelNameArr = label.getLabelName().split(",");
        if (labelNameArr.length > 0) {
            List<String> list = Arrays.asList(labelNameArr);
            queryWrapper.clear();
            queryWrapper.ne(Label::getId, label.getId());
            queryWrapper.and(qw -> {
                list.forEach(item -> {
                    qw.apply("FIND_IN_SET('" + item + "', label_name)").or();
                });
            });
        }
        boolean existName = baseMapper.exists(queryWrapper);
        if (existName) {
            throw new RuntimeException("标签内容重复");
        }
        baseMapper.updateById(label);
        return true;
    }
}