StudentServiceImpl.java
4.64 KB
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
package com.meishu.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.meishu.common.exception.HttpException;
import com.meishu.dto.student.LoginDTO;
import com.meishu.mapper.BatchDictMapper;
import com.meishu.mapper.BatchExamsStudentsMapper;
import com.meishu.mapper.BatchStudentMappingMapper;
import com.meishu.model.BatchDictDO;
import com.meishu.model.BatchStudentMappingDO;
import com.meishu.model.StudentDO;
import com.meishu.mapper.StudentMapper;
import com.meishu.model.BatchExamStudentsDO;
import com.meishu.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.vo.student.LoginVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* <p>
* 学生表 服务实现类
* </p>
*
* @author Tuyp
* @since 2023-07-11
*/
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, StudentDO> implements StudentService {
@Autowired
private BatchExamsStudentsMapper batchExamsStudentsMapper;
@Autowired
private BatchStudentMappingMapper batchStudentMappingMapper;
@Autowired
private BatchDictMapper batchDictMapper;
public LoginVO login(LoginDTO loginDTO) throws Exception{
StudentDO studentDO1 = this.baseMapper.selectOne(new QueryWrapper<StudentDO>()
.lambda()
.eq(StudentDO::getIdCard, loginDTO.getIdCard()));
if (null == studentDO1){
throw new HttpException(10001);
}
BatchStudentMappingDO batchStudentMappingDO = batchStudentMappingMapper.selectOne(new QueryWrapper<BatchStudentMappingDO>()
.lambda()
.eq(BatchStudentMappingDO::getStudentId, studentDO1.getId())
.eq(BatchStudentMappingDO::getExamCode, loginDTO.getExamCode()));
if (null == batchStudentMappingDO) {
throw new HttpException(10001);
}
BatchDictDO batchDictDO = batchDictMapper.selectById(batchStudentMappingDO.getBatchId());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (simpleDateFormat.parse(batchDictDO.getStartDate()).after(new Date())||simpleDateFormat.parse(batchDictDO.getEndDate()).before(new Date())){
throw new HttpException(10004);
}
//签到 取第一次
if (null == batchStudentMappingDO.getSignDate()){
batchStudentMappingDO.setSignDate(new Date());
batchStudentMappingMapper.updateById(batchStudentMappingDO);
}
LoginVO loginVO = new LoginVO();
loginVO.setId(studentDO1.getId());
loginVO.setUserName(studentDO1.getUserName());
loginVO.setExamCode(batchStudentMappingDO.getExamCode());
loginVO.setCompanyName(studentDO1.getCompanyName());
loginVO.setBatchId(batchStudentMappingDO.getBatchId());
return loginVO;
}
public List<StudentDO> students(StudentDO studentDO) {
return this.baseMapper.students(studentDO.getUserName());
}
public String deleteStudent(StudentDO studentDO) {
Integer count = batchExamsStudentsMapper.selectCount(new QueryWrapper<BatchExamStudentsDO>()
.lambda()
.eq(BatchExamStudentsDO::getStudentId, studentDO.getId()));
if (count > 0) {
throw new HttpException(20001);
}
this.baseMapper.deleteById(studentDO.getId());
return ConstantUtils.DELETE_SUCCESS;
}
public String updateStudent(StudentDO studentDO) {
StudentDO studentDO1 = this.baseMapper.selectById(studentDO.getId());
if (StringUtils.isNotEmpty(studentDO.getIdCard())) {
studentDO1.setIdCard(studentDO.getIdCard());
}
if (StringUtils.isNotEmpty(studentDO.getCompanyName())) {
studentDO1.setCompanyName(studentDO.getCompanyName());
}
if (StringUtils.isNotEmpty(studentDO.getUserName())) {
studentDO1.setUserName(studentDO.getUserName());
}
this.baseMapper.updateById(studentDO1);
return ConstantUtils.SET_SUCCESS;
}
public String addStudent(StudentDO studentDO) {
int coount = this.baseMapper.selectCount(new QueryWrapper<StudentDO>()
.lambda()
.eq(StudentDO::getIdCard, studentDO.getIdCard()));
if (coount > 0) {
throw new HttpException(10002);
}
this.baseMapper.insert(studentDO);
return ConstantUtils.ADD_SUCCESS;
}
}