|
|
@@ -1,210 +0,0 @@
|
|
|
-package com.usoftchina.smartschool.wechat.controller;
|
|
|
-
|
|
|
-import java.util.*;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.github.kevinsawicki.http.HttpRequest;
|
|
|
-import com.usoftchina.smartschool.wechat.domain.SchoolDO;
|
|
|
-import com.usoftchina.smartschool.wechat.domain.TeacherDO;
|
|
|
-import com.usoftchina.smartschool.wechat.service.SchoolService;
|
|
|
-import com.usoftchina.smartschool.wechat.service.UserService;
|
|
|
-import com.usoftchina.smartschool.wechat.utils.ObjectUtils;
|
|
|
-import com.usoftchina.smartschool.wechat.utils.ResultBean;
|
|
|
-import org.apache.ibatis.annotations.Param;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.util.Assert;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-import org.springframework.web.servlet.ModelAndView;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
-import static com.usoftchina.smartschool.wechat.utils.ResultBean.ErrorCode.FAIL;
|
|
|
-
|
|
|
-/**
|
|
|
- * 账户表; InnoDB free: 5120 kB
|
|
|
- *
|
|
|
- * @author kl
|
|
|
- * @email ${email}
|
|
|
- * @date 2019-01-16 16:26:29
|
|
|
- */
|
|
|
-
|
|
|
-@RestController
|
|
|
-@RequestMapping("/wxSchool/user")
|
|
|
-public class UserController {
|
|
|
- @Autowired
|
|
|
- private UserService userService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SchoolService schoolService;
|
|
|
- /**
|
|
|
- * 发送验证码
|
|
|
- */
|
|
|
- @GetMapping("/sendCode")
|
|
|
- public ResultBean sendCode(String userPhone) {
|
|
|
- try {
|
|
|
- Assert.notNull(userPhone,"请填写手机号");
|
|
|
- userService.sendCode(userPhone);
|
|
|
- return new ResultBean("验证码已发送");
|
|
|
- /*HttpSession session = request.getSession();
|
|
|
- session.setAttribute("vcode",vcode);
|
|
|
- session.setMaxInactiveInterval(CodeConfig.getSessionDate());*/
|
|
|
- } catch (Exception e) {
|
|
|
- return new ResultBean(e);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /** 绑定 */
|
|
|
- @PostMapping("/bindOpenid")
|
|
|
- public ResultBean bindOpenid(@Param("userPhone")String userPhone, @Param("code")String code, @Param("openid")String openid,@Param("schoolId") Long schoolId){
|
|
|
- try {
|
|
|
- Assert.notNull(userPhone,"请填入手机号");
|
|
|
- Assert.notNull(code,"请输入验证码");
|
|
|
- Assert.notNull(openid,"openid不能为空");
|
|
|
- Assert.notNull(schoolId,"请选择学校");
|
|
|
- Long aLong = userService.bindOpenid(userPhone, code, openid, schoolId);
|
|
|
- return new ResultBean(aLong);
|
|
|
- }catch (Exception e){
|
|
|
- return new ResultBean(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/isBinding")
|
|
|
- public ResultBean isBinding(@Param("openid") String openid,@Param("schoolId")Long schoolId){
|
|
|
- try {
|
|
|
- Assert.notNull(openid,"openid不能为空");
|
|
|
- Long binding = userService.isBinding(openid, schoolId);
|
|
|
- if (ObjectUtils.isNotEmpty(binding)){
|
|
|
- return new ResultBean(binding);
|
|
|
- }else {
|
|
|
- return new ResultBean(false);
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- return new ResultBean(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 首页数据
|
|
|
- * @param schoolId
|
|
|
- */
|
|
|
- @PostMapping("/homePage")
|
|
|
- public ResultBean homePage(@Param("openid")String openid, @Param("schoolId") Long schoolId){
|
|
|
- try {
|
|
|
- Map<String, Object> map = userService.homePage(openid, schoolId);
|
|
|
- return new ResultBean(map);
|
|
|
- }catch (Exception e){
|
|
|
- return new ResultBean(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取openid回调
|
|
|
- * https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxbc1f8607137d3b8a&redirect_uri=https%3a%2f%2fwww.akuiguoshu.com%2fschool%2fuser%2fuserLogin&response_type=code&scope=snsapi_userinfo&connect_redirect=1#wechat_redirect
|
|
|
- * @param request
|
|
|
- * @return
|
|
|
- */
|
|
|
- @GetMapping("/userLogin")
|
|
|
- public ModelAndView userLogin(HttpServletRequest request) {
|
|
|
- String code=request.getParameter("code");
|
|
|
- String schoolId=request.getParameter("state");
|
|
|
- HashMap<String, Object> params=new HashMap<>();
|
|
|
- SchoolDO schoolDO = schoolService.get(Long.getLong(schoolId));
|
|
|
- params.put("appid",schoolDO.getSchoolAppid());
|
|
|
- params.put("secret",schoolDO.getSchoolSecret());
|
|
|
- params.put("code", code);
|
|
|
- params.put("grant_type", "authorization_code");
|
|
|
- HttpRequest response= HttpRequest.get("https://api.weixin.qq.com/sns/oauth2/access_token", params, true);
|
|
|
- String result=response.body();
|
|
|
- String openid= JSON.parseObject(result).getString("openid");
|
|
|
- String token= JSON.parseObject(result).getString("access_token");
|
|
|
- System.err.println(token);
|
|
|
- return new ModelAndView("redirect:https://tmobile.ubtob.com/smart-school/bindMenu/open/"+openid+"/"+token);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取所有老师的信息
|
|
|
- * @param schoolId
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @GetMapping("/getAllTeacher")
|
|
|
- public ResultBean getAllTeacher(Long schoolId) {
|
|
|
- try {
|
|
|
- List<TeacherDO> allTeacher = userService.getAllTeacher(schoolId);
|
|
|
- return new ResultBean(allTeacher);
|
|
|
- }catch (Exception e){
|
|
|
- return new ResultBean(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据学号获取相应班级及教师
|
|
|
- * @param stuId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @GetMapping("/getTeacherByStuId")
|
|
|
- public ResultBean getTeacherByStuId(Long stuId) {
|
|
|
- try {
|
|
|
- Map<String, Object> teacherByStuId = userService.getTeacherByStuId(stuId);
|
|
|
- return new ResultBean(teacherByStuId);
|
|
|
- }catch (Exception e){
|
|
|
- return new ResultBean(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 老师获取对应的学生及家长列表
|
|
|
- * @param teacherId
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @GetMapping("/getParentsByTeacherId")
|
|
|
- public ResultBean getParentsByTeacherId(Long teacherId) {
|
|
|
- try {
|
|
|
- List<Map<String, Object>> parentsByTeacherId = userService.getParentsByTeacherId(teacherId);
|
|
|
- return new ResultBean(parentsByTeacherId);
|
|
|
- }catch (Exception e){
|
|
|
- return new ResultBean(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 教师端获得所在班级的所有人员
|
|
|
- * @param teacherId
|
|
|
- */
|
|
|
- @GetMapping("/getClazzByTeacherId")
|
|
|
- public ResultBean getClazzByTeacherId(Long teacherId) {
|
|
|
- try {
|
|
|
- List<Map<String, Object>> clazzByTeacherId = userService.getClazzByTeacherId(teacherId);
|
|
|
- return new ResultBean(clazzByTeacherId);
|
|
|
- }catch (Exception e){
|
|
|
- return new ResultBean(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改手机号
|
|
|
- * @param userPhone
|
|
|
- * @param openid
|
|
|
- * @param code
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @PostMapping("/updatePhone")
|
|
|
- public ResultBean updatePhone(@Param("userPhone") String userPhone, @Param("openid") String openid, @Param("code") String code){
|
|
|
- try {
|
|
|
- int i = userService.updatePhone(userPhone, openid, code);
|
|
|
- if (i>0){
|
|
|
- return new ResultBean("修改成功");
|
|
|
- }else {
|
|
|
- return new ResultBean(FAIL, "修改失败,请联系管理员");
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- return new ResultBean(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|