|
@@ -1,6 +1,7 @@
|
|
|
package com.qmth.exam.reserve.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
|
import com.qmth.exam.reserve.bean.student.StudentInfo;
|
|
@@ -12,6 +13,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@Service
|
|
|
public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> implements StudentService {
|
|
@@ -24,10 +26,10 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
throw new StatusException("学号不能为空");
|
|
|
}
|
|
|
|
|
|
- QueryWrapper<StudentEntity> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.lambda().eq(StudentEntity::getStudentCode, studentCode);
|
|
|
+ LambdaQueryWrapper<StudentEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(StudentEntity::getStudentCode, studentCode);
|
|
|
if (orgId != null) {
|
|
|
- wrapper.lambda().eq(StudentEntity::getOrgId, orgId);
|
|
|
+ wrapper.eq(StudentEntity::getOrgId, orgId);
|
|
|
}
|
|
|
|
|
|
return baseMapper.selectOne(wrapper);
|
|
@@ -39,10 +41,10 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
throw new StatusException("微信OID不能为空");
|
|
|
}
|
|
|
|
|
|
- QueryWrapper<StudentEntity> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.lambda().eq(StudentEntity::getOpenId, openId);
|
|
|
+ LambdaQueryWrapper<StudentEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(StudentEntity::getOpenId, openId);
|
|
|
if (StringUtils.isNotEmpty(uid)) {
|
|
|
- wrapper.lambda().eq(StudentEntity::getUid, uid);
|
|
|
+ wrapper.eq(StudentEntity::getUid, uid);
|
|
|
}
|
|
|
|
|
|
return baseMapper.selectOne(wrapper);
|
|
@@ -71,6 +73,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
public void bindingWechat(WechatBindReq req) {
|
|
|
StudentEntity stu = baseMapper.selectById(req.getStudentId());
|
|
@@ -82,12 +85,19 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
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());
|
|
|
+ if (StringUtils.isEmpty(req.getOpenId())) {
|
|
|
+ throw new StatusException("微信OID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<StudentEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.set(StudentEntity::getOpenId, req.getOpenId());
|
|
|
+ updateWrapper.set(StudentEntity::getUid, req.getUid());
|
|
|
+ updateWrapper.eq(StudentEntity::getId, req.getStudentId());
|
|
|
+ this.update(updateWrapper);
|
|
|
+ log.info("[WECHAT_BINDING] studentId:{} openId:{} uid:{}", req.getStudentId(), req.getOpenId(), req.getUid());
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
public void unbindWechatByStudentId(Long studentId) {
|
|
|
StudentEntity stu = baseMapper.selectById(studentId);
|
|
@@ -95,14 +105,16 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
|
|
|
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);
|
|
|
+ LambdaUpdateWrapper<StudentEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.set(StudentEntity::getOpenId, null);
|
|
|
+ updateWrapper.set(StudentEntity::getUid, null);
|
|
|
+ updateWrapper.eq(StudentEntity::getId, studentId);
|
|
|
+ this.update(updateWrapper);
|
|
|
+ log.info("[WECHAT_UNBIND] studentId:{} openId:{} uid:{}", stu.getId(), stu.getOpenId(), stu.getUid());
|
|
|
}
|
|
|
|
|
|
}
|