linzhijie
2021-04-12 c632636e2f5b4188b430f5efc9d9f68c8dbe3d6d
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
package com.ots.project.exam.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ots.project.exam.domain.Subject;
import com.ots.project.exam.mapper.SubjectMapper;
import com.ots.project.exam.service.SubjectService;
import com.ots.project.exam.viewmodel.SubjectPageRequestVM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("examSubject")
public class SubjectServiceImpl extends BaseServiceImpl<Subject> implements SubjectService {
    private final static String CACHE_NAME = "Subject";
    @Autowired
    private SubjectMapper subjectMapper;
    @Autowired
    public SubjectServiceImpl(SubjectMapper subjectMapper) {
        super(subjectMapper);
        this.subjectMapper = subjectMapper;
    }
    @Override
    @Cacheable(value = CACHE_NAME, key = "#id", unless = "#result == null")
    public Subject selectById(Integer id) {
        return super.selectById(id);
    }
    @Override
    @CacheEvict(value = CACHE_NAME, key = "#record.id")
    public int updateByIdFilter(Subject record) {
        return super.updateByIdFilter(record);
    }
    @Override
    public List<Subject> getSubjectByLevel(Integer level) {
        return subjectMapper.getSubjectByLevel(level);
    }
    @Override
    public List<Subject> allSubject() {
        return subjectMapper.allSubject();
    }
    @Override
    public Integer levelBySubjectId(Integer id) {
        return this.selectById(id).getLevel();
    }
    @Override
    public PageInfo<Subject> page(SubjectPageRequestVM requestVM) {
        return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() ->
                subjectMapper.page(requestVM)
        );
    }
}