6 天以前 0c23c1e9b9e06ffc570edac28ee45555b772b99c
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
package com.ruoyi.safety.service.impl;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.safety.pojo.SafetyBaseEntity;
import com.ruoyi.safety.service.SafetyBaseService;
import org.apache.commons.lang3.StringUtils;
 
import java.time.LocalDateTime;
 
public abstract class SafetyBaseServiceImpl<M extends BaseMapper<T>, T extends SafetyBaseEntity>
        extends ServiceImpl<M, T> implements SafetyBaseService<T> {
 
    @Override
    public boolean saveSafety(T entity) {
        entity.setCreateBy(currentUsername());
        entity.setCreateTime(LocalDateTime.now());
        if (entity.getDelFlag() == null) {
            entity.setDelFlag(0);
        }
        return save(entity);
    }
 
    @Override
    public boolean updateSafety(T entity) {
        entity.setUpdateBy(currentUsername());
        entity.setUpdateTime(LocalDateTime.now());
        return updateById(entity);
    }
 
    @Override
    public boolean deleteSafetyById(Long id) {
        return removeById(id);
    }
 
    protected boolean hasText(String value) {
        return StringUtils.isNotBlank(value);
    }
 
    protected String currentUsername() {
        try {
            return SecurityUtils.getLoginUser().getNickName();
        } catch (Exception ignored) {
            return null;
        }
    }
 
    protected Long currentUserId() {
        try {
            return SecurityUtils.getUserId();
        } catch (Exception ignored) {
            return null;
        }
    }
}