Ver Fonte

update api

deason há 1 ano atrás
pai
commit
16c132d8de

+ 1 - 1
src/main/java/com/qmth/exam/reserve/bean/login/WechatLoginReq.java

@@ -14,7 +14,7 @@ public class WechatLoginReq implements IModel {
     @ApiModelProperty(value = "考生-微信OID", required = true)
     private String openId;
 
-    @ApiModelProperty(value = "考生-微信UID", required = true)
+    @ApiModelProperty(value = "考生-微信UID")
     private String uid;
 
 }

+ 13 - 7
src/main/java/com/qmth/exam/reserve/bean/student/StudentInfo.java

@@ -29,16 +29,22 @@ public class StudentInfo implements IModel {
     @ApiModelProperty(value = "考生头像相对路径")
     private String photoPath;
 
-    @ApiModelProperty(value = "所属教学点ID")
-    private Long teachingId;
-
-    @ApiModelProperty(value = "所属教学点名称")
-    private String teachingName;
+    @ApiModelProperty(value = "性别")
+    private String gender;
 
     @ApiModelProperty(value = "允许预约时段数量")
     private Integer applyNumber;
 
-    @ApiModelProperty(value = "考生教学点所在城市ID")
-    private Long cityId;
+    @ApiModelProperty(value = "所属预约任务ID")
+    private Long applyTaskId;
+
+    @ApiModelProperty(value = "所属教学点ID")
+    private Long categoryId;
+
+    @ApiModelProperty(value = "微信OID")
+    private String openId;
+
+    @ApiModelProperty(value = "微信UID")
+    private String uid;
 
 }

+ 4 - 1
src/main/java/com/qmth/exam/reserve/bean/student/WechatBindReq.java

@@ -11,10 +11,13 @@ public class WechatBindReq implements IModel {
 
     private static final long serialVersionUID = -3639457038451359896L;
 
-    @ApiModelProperty(value = "考生-微信OID")
+    @ApiModelProperty(value = "考生-微信OID", required = true)
     private String openId;
 
     @ApiModelProperty(value = "考生-微信UID")
     private String uid;
 
+    @ApiModelProperty(value = "考生ID", hidden = true)
+    private Long studentId;
+
 }

+ 12 - 0
src/main/java/com/qmth/exam/reserve/controller/BaseController.java

@@ -4,6 +4,7 @@ import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.boot.tools.io.IOUtils;
 import com.qmth.exam.reserve.bean.login.LoginUser;
+import com.qmth.exam.reserve.enums.Role;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
@@ -23,6 +24,17 @@ public class BaseController {
         return user;
     }
 
+    protected LoginUser curLoginStudent() {
+        LoginUser user = (LoginUser) this.curRequest().getAttribute(ApiConstant.ATTRIBUTE_ACCESS_ENTITY);
+        if (user == null) {
+            throw new StatusException("请先登录!");
+        }
+        if (Role.STUDENT != user.getRole()) {
+            throw new StatusException("请使用学生账号登录!");
+        }
+        return user;
+    }
+
     protected HttpServletRequest curRequest() {
         return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes()))
                 .getRequest();

+ 10 - 6
src/main/java/com/qmth/exam/reserve/controller/student/StudentController.java

@@ -5,10 +5,12 @@ import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.exam.reserve.bean.student.StudentInfo;
 import com.qmth.exam.reserve.bean.student.WechatBindReq;
 import com.qmth.exam.reserve.controller.BaseController;
+import com.qmth.exam.reserve.service.StudentService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -22,24 +24,26 @@ public class StudentController extends BaseController {
 
     private static final Logger log = LoggerFactory.getLogger(StudentController.class);
 
+    @Autowired
+    private StudentService studentService;
+
     @ApiOperation(value = "考生账号与微信号绑定")
     @PostMapping(value = "/wechat/binding")
     public void binding(@RequestBody WechatBindReq req) {
-        //todo
+        req.setStudentId(curLoginStudent().getId());
+        studentService.bindingWechat(req);
     }
 
     @ApiOperation(value = "考生账号与微信号解绑")
     @PostMapping(value = "/wechat/unbind")
-    public void unbind(@RequestBody WechatBindReq req) {
-        //todo
+    public void unbind() {
+        studentService.unbindWechatByStudentId(curLoginStudent().getId());
     }
 
     @ApiOperation(value = "获取考生信息")
     @PostMapping(value = "/info")
     public StudentInfo info() {
-        StudentInfo info = new StudentInfo();
-        //todo
-        return info;
+        return studentService.findInfoByStudentId(curLoginStudent().getId());
     }
 
 }

+ 1 - 1
src/main/java/com/qmth/exam/reserve/controller/student/StudentLoginController.java

@@ -44,7 +44,7 @@ public class StudentLoginController extends BaseController {
     @ApiOperation(value = "考生登出")
     @PostMapping(value = "/logout")
     public void logout() {
-        authService.logout(curLoginUser());
+        authService.logout(curLoginStudent());
     }
 
 }

+ 8 - 0
src/main/java/com/qmth/exam/reserve/service/StudentService.java

@@ -1,10 +1,18 @@
 package com.qmth.exam.reserve.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.exam.reserve.bean.student.StudentInfo;
+import com.qmth.exam.reserve.bean.student.WechatBindReq;
 import com.qmth.exam.reserve.entity.StudentEntity;
 
 public interface StudentService extends IService<StudentEntity> {
 
     StudentEntity findStudentByStudentCode(Long orgId, String studentCode);
 
+    StudentInfo findInfoByStudentId(Long studentId);
+
+    void bindingWechat(WechatBindReq req);
+
+    void unbindWechatByStudentId(Long studentId);
+
 }

+ 4 - 0
src/main/java/com/qmth/exam/reserve/service/impl/AuthServiceImpl.java

@@ -114,6 +114,10 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
 
     @Override
     public LoginUser wechatLogin(WechatLoginReq req) {
+        if (StringUtils.isBlank(req.getOpenId())) {
+            throw new StatusException("微信OID不能为空");
+        }
+
         return null;
     }
 

+ 36 - 0
src/main/java/com/qmth/exam/reserve/service/impl/StudentServiceImpl.java

@@ -2,6 +2,9 @@ package com.qmth.exam.reserve.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.core.exception.StatusException;
+import com.qmth.exam.reserve.bean.student.StudentInfo;
+import com.qmth.exam.reserve.bean.student.WechatBindReq;
 import com.qmth.exam.reserve.dao.StudentDao;
 import com.qmth.exam.reserve.entity.StudentEntity;
 import com.qmth.exam.reserve.service.StudentService;
@@ -24,4 +27,37 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
         return baseMapper.selectOne(wrapper);
     }
 
+    @Override
+    public StudentInfo findInfoByStudentId(Long studentId) {
+        StudentEntity entity = baseMapper.selectById(studentId);
+        if (entity == null) {
+            throw new StatusException("学生不存在");
+        }
+
+        StudentInfo info = new StudentInfo();
+        info.setOrgId(entity.getOrgId());
+        info.setId(entity.getId());
+        info.setName(entity.getName());
+        info.setStudentCode(entity.getStudentCode());
+        info.setIdentityNumber(entity.getIdentityNumber());
+        info.setPhotoPath(entity.getPhotoPath());
+        info.setGender(entity.getGender());
+        info.setApplyNumber(entity.getApplyNumber());
+        info.setApplyTaskId(entity.getApplyTaskId());
+        info.setCategoryId(entity.getCategoryId());
+        info.setOpenId(entity.getOpenId());
+        info.setUid(entity.getUid());
+        return info;
+    }
+
+    @Override
+    public void bindingWechat(WechatBindReq req) {
+
+    }
+
+    @Override
+    public void unbindWechatByStudentId(Long studentId) {
+
+    }
+
 }

+ 8 - 6
src/test/java/com/qmth/exam/reserve/test/AuthTest.java

@@ -14,12 +14,13 @@ import java.util.Map;
 
 public class AuthTest {
 
-    private final static String SERVER_URL = "http://localhost:8080";
+    private final static String SERVER_URL = "http://192.168.10.41:8080";
 
-    // @Test
+    @Test
     public void demo() throws Exception {
-        LoginUser loginUser = this.doLogin();
-        this.doLogout(loginUser);
+        // LoginUser loginUser = this.doLogin();
+        // this.doLogout(loginUser.getSessionId(), loginUser.getToken());
+        this.doLogout("S_1", "000000001efe1d02000000000dce14e5");
     }
 
     private LoginUser doLogin() {
@@ -48,11 +49,12 @@ public class AuthTest {
         throw new RuntimeException("登录失败!");
     }
 
-    private void doLogout(LoginUser loginUser) {
+    private void doLogout(String sessionId, String token) {
         String apiUrl = "/api/student/logout";
+        // String apiUrl = "/api/student/info";
         long timestamp = System.currentTimeMillis();
         String signature = SignatureEntity.build(SignatureType.TOKEN, "POST", apiUrl,
-                timestamp, loginUser.getSessionId(), loginUser.getToken());
+                timestamp, sessionId, token);
 
         Map<String, String> headers = new HashMap<>();
         headers.put("authorization", signature);