“djh”
2 天以前 45c3b7aacf3d20e1915e597152ad30a3b40377a2
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package com.gkhy.exam.system.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.domain.entity.SysUser;
import com.gkhy.exam.common.enums.UserTypeEnum;
import com.gkhy.exam.common.exception.ApiException;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.ExExamRecord;
import com.gkhy.exam.system.domain.ExStudent;
import com.gkhy.exam.system.domain.RecordFile;
import com.gkhy.exam.system.mapper.ExExamRecordMapper;
import com.gkhy.exam.system.mapper.ExStudentMapper;
import com.gkhy.exam.system.service.ExExamRecordService;
import org.ehcache.core.util.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 * 线下教育登记表 服务实现类
 * </p>
 *
 * @author kzy
 * @since 2024-06-24 16:16:33
 */
@Service
public class ExExamRecordServiceImpl extends ServiceImpl<ExExamRecordMapper, ExExamRecord> implements ExExamRecordService {
 
 
    @Autowired
    private ExStudentMapper studentMapper;
 
 
    @Override
    public CommonPage selectExamRecordList(ExExamRecord examRecord) {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        if(!user.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){
            examRecord.setCompanyId(user.getCompanyId());
        }
        PageUtils.startPage();
        List<ExExamRecord> recordList=baseMapper.selectExamRecordList(examRecord);
        for (ExExamRecord exExamRecord : recordList) {
            List<RecordFile> recordFiles = baseMapper.selectFiles(exExamRecord.getId());
            exExamRecord.setFiles(recordFiles);
            List<ExStudent> exStudents = new ArrayList<>();
            String[] split = exExamRecord.getStudentId().split(",");
            for (String studentId : split) {
                ExStudent exStudent = studentMapper.selectStudentById(Long.valueOf(studentId));
                exStudents.add(exStudent);
            }
            exExamRecord.setStudents(exStudents);
        }
        return CommonPage.restPage(recordList);
    }
 
    @Override
    public ExExamRecord selectExamRecordById(Long recordId) {
        ExExamRecord exExamRecord = baseMapper.selectExamRecordById(recordId);
        List<RecordFile> recordFiles = baseMapper.selectFiles(exExamRecord.getId());
        exExamRecord.setFiles(recordFiles);
        List<ExStudent> exStudents = new ArrayList<>();
        String[] split = exExamRecord.getStudentId().split(",");
        for (String studentId : split) {
            ExStudent exStudent = studentMapper.selectStudentById(Long.valueOf(studentId));
            exStudents.add(exStudent);
        }
        exExamRecord.setStudents(exStudents);
        return exExamRecord;
    }
 
    @Override
    public int insertExamRecord(ExExamRecord examRecord) {
        checkUserAllowed(examRecord);
//        examRecord.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        examRecord.setCreateBy(SecurityUtils.getUsername());
        int row=baseMapper.insert(examRecord);
        List<RecordFile> files = examRecord.getFiles();
        if (!files.isEmpty()){
            baseMapper.insertFile(files,examRecord.getId());
        }
        if(row<1){
            throw new ApiException("新增登记记录失败");
        }
        return row;
    }
 
    @Override
    public int updateExamRecord(ExExamRecord examRecord) {
        checkUserAllowed(examRecord);
        examRecord.setUpdateBy(SecurityUtils.getUsername());
        int row=baseMapper.updateById(examRecord);
        List<RecordFile> files = examRecord.getFiles();
        baseMapper.deletedFile(examRecord.getId());
        if (!files.isEmpty()){
            baseMapper.insertFile(files, examRecord.getId());
        }
        if(row<1){
            throw new ApiException("更新登记记录失败");
        }
        return row;
    }
 
    @Override
    public int deleteExamRecordById(Long recordId) {
        checkUserAllowed(baseMapper.selectById(recordId));
        baseMapper.deletedFile(recordId);
        return baseMapper.deleteById(recordId);
    }
 
    public void checkUserAllowed(ExExamRecord examRecord) {
        SysUser currentUser= SecurityUtils.getLoginUser().getUser();
        if(currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){
            return;
        }
        if(currentUser.getUserType().equals(UserTypeEnum.STUDENT.getCode())){
            throw new ApiException("没有权限操作");
        }
        if(examRecord.getCompanyId()!=null&&!currentUser.getCompanyId().equals(examRecord.getCompanyId())){
            throw new ApiException("没有权限操作其他企业登记记录");
        }
    }
 
    @Override
    public boolean checkRecordUnique(ExExamRecord examRecord) {
        return false;
    }
 
    @Override
    public void importRecord(MultipartFile file) {
 
    }
}