|
@@ -8,6 +8,7 @@ import com.qmth.exam.reserve.bean.student.WechatBindReq;
|
|
import com.qmth.exam.reserve.dao.StudentDao;
|
|
import com.qmth.exam.reserve.dao.StudentDao;
|
|
import com.qmth.exam.reserve.entity.StudentEntity;
|
|
import com.qmth.exam.reserve.entity.StudentEntity;
|
|
import com.qmth.exam.reserve.service.StudentService;
|
|
import com.qmth.exam.reserve.service.StudentService;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -18,12 +19,32 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
private static final Logger log = LoggerFactory.getLogger(StudentServiceImpl.class);
|
|
private static final Logger log = LoggerFactory.getLogger(StudentServiceImpl.class);
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public StudentEntity findStudentByStudentCode(Long orgId, String studentCode) {
|
|
|
|
|
|
+ public StudentEntity findByStudentCode(Long orgId, String studentCode) {
|
|
|
|
+ if (StringUtils.isEmpty(studentCode)) {
|
|
|
|
+ throw new StatusException("学号不能为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
QueryWrapper<StudentEntity> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<StudentEntity> wrapper = new QueryWrapper<>();
|
|
|
|
+ wrapper.lambda().eq(StudentEntity::getStudentCode, studentCode);
|
|
if (orgId != null) {
|
|
if (orgId != null) {
|
|
wrapper.lambda().eq(StudentEntity::getOrgId, orgId);
|
|
wrapper.lambda().eq(StudentEntity::getOrgId, orgId);
|
|
}
|
|
}
|
|
- wrapper.lambda().eq(StudentEntity::getStudentCode, studentCode);
|
|
|
|
|
|
+
|
|
|
|
+ return baseMapper.selectOne(wrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public StudentEntity findByOpenIdAndUid(String openId, String uid) {
|
|
|
|
+ if (StringUtils.isEmpty(openId)) {
|
|
|
|
+ throw new StatusException("微信OID不能为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QueryWrapper<StudentEntity> wrapper = new QueryWrapper<>();
|
|
|
|
+ wrapper.lambda().eq(StudentEntity::getOpenId, openId);
|
|
|
|
+ if (StringUtils.isNotEmpty(uid)) {
|
|
|
|
+ wrapper.lambda().eq(StudentEntity::getUid, uid);
|
|
|
|
+ }
|
|
|
|
+
|
|
return baseMapper.selectOne(wrapper);
|
|
return baseMapper.selectOne(wrapper);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -31,7 +52,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
public StudentInfo findInfoByStudentId(Long studentId) {
|
|
public StudentInfo findInfoByStudentId(Long studentId) {
|
|
StudentEntity entity = baseMapper.selectById(studentId);
|
|
StudentEntity entity = baseMapper.selectById(studentId);
|
|
if (entity == null) {
|
|
if (entity == null) {
|
|
- throw new StatusException("学生不存在");
|
|
|
|
|
|
+ throw new StatusException("学生信息不存在");
|
|
}
|
|
}
|
|
|
|
|
|
StudentInfo info = new StudentInfo();
|
|
StudentInfo info = new StudentInfo();
|
|
@@ -52,12 +73,36 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void bindingWechat(WechatBindReq req) {
|
|
public void bindingWechat(WechatBindReq req) {
|
|
|
|
+ StudentEntity stu = baseMapper.selectById(req.getStudentId());
|
|
|
|
+ if (stu == null) {
|
|
|
|
+ throw new StatusException("学生信息不存在");
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(stu.getOpenId())) {
|
|
|
|
+ throw new StatusException("微信账号已绑定");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ stu.setOpenId(req.getOpenId());
|
|
|
|
+ stu.setUid(req.getUid());
|
|
|
|
+ baseMapper.updateById(stu);
|
|
|
|
+ log.info("[WECHAT_BINDING] studentId:{} openId:{} uid:{}", stu.getId(), stu.getOpenId(), stu.getUid());
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void unbindWechatByStudentId(Long studentId) {
|
|
public void unbindWechatByStudentId(Long studentId) {
|
|
|
|
+ StudentEntity stu = baseMapper.selectById(studentId);
|
|
|
|
+ if (stu == null) {
|
|
|
|
+ throw new StatusException("学生信息不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ log.info("[WECHAT_UNBIND] studentId:{} openId:{} uid:{}", stu.getId(), stu.getOpenId(), stu.getUid());
|
|
|
|
+ if (StringUtils.isEmpty(stu.getOpenId())) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ stu.setOpenId(null);
|
|
|
|
+ stu.setUid(null);
|
|
|
|
+ baseMapper.updateById(stu);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|