guoshilong
2024-02-01 91a17daf8bcda53729e56ecdf1109b22cf022c73
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
package cn.gistack.sm.sjztmd.service.impl;
 
import cn.gistack.sm.sjztmd.entity.RelResLabel;
import cn.gistack.sm.sjztmd.mapper.RelResLabelMapper;
import cn.gistack.sm.sjztmd.service.IRelResLabelService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
@Service
@DS("zt")
public class RelResLabelServiceImpl extends ServiceImpl<RelResLabelMapper, RelResLabel> implements IRelResLabelService {
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateEntity(String guid, String label) {
 
        //删除表中原来的标签
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("\"guid\"",guid);
 
        boolean remove = remove(queryWrapper);
        //添加新标签数据
        if (StringUtil.isNotBlank(label)){
            List<RelResLabel> list = new ArrayList<>();
 
            List<String> labelList = Arrays.asList(label.split(","));
 
            labelList.forEach(e->{
                RelResLabel relResLabel = new RelResLabel();
 
                relResLabel.setGuid(guid);
                relResLabel.setLabel(e);
 
                list.add(relResLabel);
            });
 
            boolean saveBatch = saveBatch(list);
            return saveBatch;
        }
        return remove;
    }
}