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
package com.ruoyi.safety.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.safety.mapper.SafetyTrainingMaterialMapper;
import com.ruoyi.safety.pojo.SafetyTrainingMaterial;
import com.ruoyi.safety.service.SafetyTrainingMaterialService;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
 
@Service
public class SafetyTrainingMaterialServiceImpl
        extends SafetyBaseServiceImpl<SafetyTrainingMaterialMapper, SafetyTrainingMaterial>
        implements SafetyTrainingMaterialService {
 
    @Override
    public IPage<SafetyTrainingMaterial> queryPage(Page<SafetyTrainingMaterial> page,
                                                   SafetyTrainingMaterial query) {
        QueryWrapper<SafetyTrainingMaterial> wrapper =
                new QueryWrapper<SafetyTrainingMaterial>().orderByDesc("create_time");
        if (query != null) {
            if (hasText(query.getName())) {
                wrapper.like("name", query.getName());
            }
            if (hasText(query.getType())) {
                wrapper.eq("type", query.getType());
            }
            if (query.getStatus() != null) {
                wrapper.eq("status", query.getStatus());
            }
        }
        return page(page, wrapper);
    }
 
    @Override
    public boolean saveSafety(SafetyTrainingMaterial entity) {
        if (entity.getUploadTime() == null) {
            entity.setUploadTime(LocalDateTime.now());
        }
        if (!hasText(entity.getUploader())) {
            entity.setUploader(currentUsername());
        }
        if (entity.getUploaderId() == null) {
            entity.setUploaderId(currentUserId());
        }
        return super.saveSafety(entity);
    }
}