luoyb
2021-02-18 fbfb38ac0c904c1246b410270585e14453d7ce5b
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
package cc.mrbird.febs.server.hr.service.impl;
 
import cc.mrbird.febs.common.core.constant.ModuleCode;
import cc.mrbird.febs.common.core.utils.FebsUtil;
import cc.mrbird.febs.common.core.utils.SequenceUtil;
import cc.mrbird.febs.server.hr.entity.Folder;
import cc.mrbird.febs.server.hr.entity.Label;
import cc.mrbird.febs.server.hr.mapper.LabelMapper;
import cc.mrbird.febs.server.hr.service.ILabelService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cc.mrbird.febs.common.core.entity.QueryRequest;
 
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
 
/**
 * 标签 Service实现
 *
 * @author yz
 * @date 2021-02-17 22:18:51
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class LabelServiceImpl extends ServiceImpl<LabelMapper, Label> implements ILabelService {
 
    private final LabelMapper labelMapper;
    private final String operatorId = Optional.ofNullable(FebsUtil.getCurrentUser())
            .map(u -> u.getUserId().toString())
            .orElse("1");
    @Override
    public IPage<Label> findLabels(QueryRequest request, Label label) {
        LambdaQueryWrapper<Label> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        Page<Label> page = new Page<>(request.getPageNum(), request.getPageSize());
        return this.page(page, queryWrapper);
    }
 
    @Override
    public List<Label> findLabels(Label label) {
        LambdaQueryWrapper<Label> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(Label::getLabelcode,Label::getLabelname,Label::getLabelid).eq(Label::getDelFlag,0);
        return this.baseMapper.selectList(queryWrapper);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createLabel(Label label) {
        label.setLabelid(SequenceUtil.generateId(0L, ModuleCode.HR_FIlE));
        label.setCreator(operatorId);
        label.setModifier(operatorId);
        label.setCreatetime(new Date());
        label.setModifytime(new Date());
        label.setVersion(0);
        this.save(label);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateLabel(Label label) {
        this.saveOrUpdate(label);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteLabel(Label label) {
        LambdaUpdateWrapper<Label> wapper = new LambdaUpdateWrapper<>();
        wapper.eq(Label::getLabelid,label.getLabelid()).setSql("delFlag = 1");
        this.update(wapper);
    }
}