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;
|
}
|
}
|