作者 王兆博

我的老师

@@ -77,7 +77,7 @@ public class LonginController { @@ -77,7 +77,7 @@ public class LonginController {
77 return loginService.loginInit(loginBo); 77 return loginService.loginInit(loginBo);
78 } 78 }
79 79
80 - @ApiOperation(value = "用户授权或绑定") 80 + @ApiOperation(value = "用户授权或绑定 在openId字段上传code值 ")
81 @PostMapping("/loginCode") 81 @PostMapping("/loginCode")
82 public AjaxResult loginCode(@Valid @RequestBody LoginBo loginBo) { 82 public AjaxResult loginCode(@Valid @RequestBody LoginBo loginBo) {
83 return loginService.loginCode(loginBo); 83 return loginService.loginCode(loginBo);
@@ -89,4 +89,7 @@ public class LonginController { @@ -89,4 +89,7 @@ public class LonginController {
89 public AjaxResult logOut(){ 89 public AjaxResult logOut(){
90 return this.loginService.logOut(); 90 return this.loginService.logOut();
91 } 91 }
  92 +
  93 +
  94 +
92 } 95 }
@@ -51,6 +51,16 @@ public class CTeacherVo { @@ -51,6 +51,16 @@ public class CTeacherVo {
51 @Excel(name = "学科") 51 @Excel(name = "学科")
52 @ApiModelProperty("学科") 52 @ApiModelProperty("学科")
53 private String subject; 53 private String subject;
  54 + /**
  55 + * 老师身份证号
  56 + */
  57 + @ApiModelProperty("学科")
54 58
  59 + private String identityCard;
  60 + /**
  61 + * 老师名字
  62 + */
  63 + @ApiModelProperty("老师名字")
  64 + private String name;
55 65
56 } 66 }
@@ -25,6 +25,7 @@ public interface CRelationshipStudentSgcMapper extends BaseMapperPlus<CRelations @@ -25,6 +25,7 @@ public interface CRelationshipStudentSgcMapper extends BaseMapperPlus<CRelations
25 * 根据学生id 查找学生关联的班级; 25 * 根据学生id 查找学生关联的班级;
26 * @return 26 * @return
27 */ 27 */
28 - List<MyTeacherVO> getMyCassl(); 28 + List<MyTeacherVO> getMyCassl(Long userId);
  29 +
29 30
30 } 31 }
@@ -60,5 +60,10 @@ public interface LonginService { @@ -60,5 +60,10 @@ public interface LonginService {
60 */ 60 */
61 AjaxResult logOut(); 61 AjaxResult logOut();
62 62
  63 + /**
  64 + * 微信授权登录 传code
  65 + * @param loginBo
  66 + * @return
  67 + */
63 AjaxResult loginCode(LoginBo loginBo); 68 AjaxResult loginCode(LoginBo loginBo);
64 } 69 }
@@ -18,6 +18,7 @@ import com.example.client.security.LoginUser; @@ -18,6 +18,7 @@ import com.example.client.security.LoginUser;
18 import com.example.client.security.TokenService; 18 import com.example.client.security.TokenService;
19 import com.example.client.service.LonginService; 19 import com.example.client.service.LonginService;
20 import com.example.client.service.UserService; 20 import com.example.client.service.UserService;
  21 +import com.example.client.utils.HttpUtils;
21 import com.example.client.utils.ip.IpUtils; 22 import com.example.client.utils.ip.IpUtils;
22 import com.example.client.utils.sign.Md5Utils; 23 import com.example.client.utils.sign.Md5Utils;
23 import com.example.client.utils.verification.PhoneUtils; 24 import com.example.client.utils.verification.PhoneUtils;
@@ -37,6 +38,12 @@ import java.util.concurrent.TimeUnit; @@ -37,6 +38,12 @@ import java.util.concurrent.TimeUnit;
37 */ 38 */
38 @Service 39 @Service
39 public class LonginServiceImpl implements LonginService { 40 public class LonginServiceImpl implements LonginService {
  41 + public static final String url = "https://api.weixin.qq.com/sns/oauth2/access_token";
  42 +
  43 + public static final String APPID = "";
  44 +
  45 + public static final String SECRET = "";
  46 +
40 @Autowired 47 @Autowired
41 private RedisCache redisCache; 48 private RedisCache redisCache;
42 @Autowired 49 @Autowired
@@ -166,13 +173,14 @@ public class LonginServiceImpl implements LonginService { @@ -166,13 +173,14 @@ public class LonginServiceImpl implements LonginService {
166 173
167 /** 174 /**
168 * 删除缓存 175 * 删除缓存
  176 + *
169 * @param key 177 * @param key
170 * @return 178 * @return
171 */ 179 */
172 - public AjaxResult logOut(String key ) { 180 + public AjaxResult logOut(String key) {
173 181
174 182
175 - String cacheObject = (String)redisCache.getCacheObject(key); 183 + String cacheObject = (String) redisCache.getCacheObject(key);
176 //刪除等記錄 184 //刪除等記錄
177 redisCache.deleteObject(key); 185 redisCache.deleteObject(key);
178 //退出 186 //退出
@@ -181,6 +189,7 @@ public class LonginServiceImpl implements LonginService { @@ -181,6 +189,7 @@ public class LonginServiceImpl implements LonginService {
181 189
182 return AjaxResult.success(true); 190 return AjaxResult.success(true);
183 } 191 }
  192 +
184 @Override 193 @Override
185 public AjaxResult forget(UpdatePasswordDTO dto) { 194 public AjaxResult forget(UpdatePasswordDTO dto) {
186 195
@@ -222,9 +231,9 @@ public class LonginServiceImpl implements LonginService { @@ -222,9 +231,9 @@ public class LonginServiceImpl implements LonginService {
222 231
223 CUserVo cUserVo = userService.queryById(userId); 232 CUserVo cUserVo = userService.queryById(userId);
224 233
225 - if(cUserVo==null){  
226 - return AjaxResult.error("非法进入");  
227 - } 234 + if (cUserVo == null) {
  235 + return AjaxResult.error("非法进入");
  236 + }
228 CUserBo cUserBo = new CUserBo(); 237 CUserBo cUserBo = new CUserBo();
229 cUserBo.setUserId(userId); 238 cUserBo.setUserId(userId);
230 //修改密码 239 //修改密码
@@ -236,7 +245,7 @@ public class LonginServiceImpl implements LonginService { @@ -236,7 +245,7 @@ public class LonginServiceImpl implements LonginService {
236 //判断是否登录 245 //判断是否登录
237 Object cacheObject = redisCache.getCacheObject(key); 246 Object cacheObject = redisCache.getCacheObject(key);
238 //删除缓存 重新登录 247 //删除缓存 重新登录
239 - if(cacheObject != null ){ 248 + if (cacheObject != null) {
240 logOut(key); 249 logOut(key);
241 } 250 }
242 251
@@ -250,11 +259,11 @@ public class LonginServiceImpl implements LonginService { @@ -250,11 +259,11 @@ public class LonginServiceImpl implements LonginService {
250 if (loginBo.getType() != null && loginBo.getType() == 1) { 259 if (loginBo.getType() != null && loginBo.getType() == 1) {
251 UserTrVo userTrVo = new UserTrVo(); 260 UserTrVo userTrVo = new UserTrVo();
252 CUserVo cUserVo = userService.queryById(UserContext.currentUserId()); 261 CUserVo cUserVo = userService.queryById(UserContext.currentUserId());
253 - if( user != null){ 262 + if (user != null) {
254 AjaxResult.error("这个微信号已经绑定了账号"); 263 AjaxResult.error("这个微信号已经绑定了账号");
255 } 264 }
256 265
257 - if (cUserVo != null ) { 266 + if (cUserVo != null) {
258 CUserBo cUserBo = new CUserBo(); 267 CUserBo cUserBo = new CUserBo();
259 cUserBo.setUserId(UserContext.currentUserId()); 268 cUserBo.setUserId(UserContext.currentUserId());
260 cUserBo.setOpenId(loginBo.getOpenId()); 269 cUserBo.setOpenId(loginBo.getOpenId());
@@ -274,7 +283,7 @@ public class LonginServiceImpl implements LonginService { @@ -274,7 +283,7 @@ public class LonginServiceImpl implements LonginService {
274 UserService.insert(cUser1); 283 UserService.insert(cUser1);
275 }*/ 284 }*/
276 285
277 - if(user !=null){ 286 + if (user != null) {
278 LoginTokenVO vo = new LoginTokenVO(); 287 LoginTokenVO vo = new LoginTokenVO();
279 //不返回密码 288 //不返回密码
280 user.setUserPassword(null); 289 user.setUserPassword(null);
@@ -302,18 +311,16 @@ public class LonginServiceImpl implements LonginService { @@ -302,18 +311,16 @@ public class LonginServiceImpl implements LonginService {
302 CUserVo user = userService.queryById(userId); 311 CUserVo user = userService.queryById(userId);
303 312
304 313
305 -  
306 -  
307 //账号和密码来做key 314 //账号和密码来做key
308 String key = user.getAccount() + user.getUserPassword(); 315 String key = user.getAccount() + user.getUserPassword();
309 316
310 - String cacheObject = (String)redisCache.getCacheObject(key); 317 + String cacheObject = (String) redisCache.getCacheObject(key);
311 // 318 //
312 CUserBo cUserBo = new CUserBo(); 319 CUserBo cUserBo = new CUserBo();
313 cUserBo.setUserId(UserContext.currentUserId()); 320 cUserBo.setUserId(UserContext.currentUserId());
314 cUserBo.setOpenId(null); 321 cUserBo.setOpenId(null);
315 //解除微信绑定 322 //解除微信绑定
316 - userService.updateOpenId(userId); 323 + userService.updateOpenId(userId);
317 userService.updateByBo(cUserBo); 324 userService.updateByBo(cUserBo);
318 325
319 //刪除等記錄 326 //刪除等記錄
@@ -327,6 +334,12 @@ public class LonginServiceImpl implements LonginService { @@ -327,6 +334,12 @@ public class LonginServiceImpl implements LonginService {
327 334
328 @Override 335 @Override
329 public AjaxResult loginCode(LoginBo loginBo) { 336 public AjaxResult loginCode(LoginBo loginBo) {
330 - return null; 337 +
  338 + String param = "appid=" + APPID + "&secret=" + SECRET + "&code=" + loginBo.getOpenId() + "&grant_type=authorization_code";
  339 + String s = HttpUtils.mySendGet(url, param);
  340 +
  341 + System.out.println("======================================================="+s);
  342 +
  343 + return AjaxResult.success(s);
331 } 344 }
332 } 345 }
@@ -14,6 +14,7 @@ import com.example.client.enumeration.Identity; @@ -14,6 +14,7 @@ import com.example.client.enumeration.Identity;
14 import com.example.client.mapper.*; 14 import com.example.client.mapper.*;
15 import com.example.client.service.MineService; 15 import com.example.client.service.MineService;
16 import lombok.extern.slf4j.Slf4j; 16 import lombok.extern.slf4j.Slf4j;
  17 +import org.aspectj.weaver.loadtime.Aj;
17 import org.springframework.beans.BeanUtils; 18 import org.springframework.beans.BeanUtils;
18 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.stereotype.Service; 20 import org.springframework.stereotype.Service;
@@ -43,7 +44,7 @@ public class MineServiceImpl implements MineService { @@ -43,7 +44,7 @@ public class MineServiceImpl implements MineService {
43 private CFollowerMapper cFollowerMapper; 44 private CFollowerMapper cFollowerMapper;
44 45
45 @Autowired 46 @Autowired
46 - private CActivityMapper cActivityMapper; 47 + private CTeacherMapper cTeacherMapper;
47 48
48 @Autowired 49 @Autowired
49 private CExperienceEducationMapper cExperienceEducationMapper; 50 private CExperienceEducationMapper cExperienceEducationMapper;
@@ -716,11 +717,21 @@ public class MineServiceImpl implements MineService { @@ -716,11 +717,21 @@ public class MineServiceImpl implements MineService {
716 public AjaxResult openMyTeacher() { 717 public AjaxResult openMyTeacher() {
717 Long userId = UserContext.currentUserId(); 718 Long userId = UserContext.currentUserId();
718 CUser cUser = cUserMapper.selectById(userId); 719 CUser cUser = cUserMapper.selectById(userId);
  720 + if(!cUser.getIdentityType().equals(Identity.STUDENT)){
  721 + return AjaxResult.error("只有学生有我的老师");
  722 + }
  723 + List<MyTeacherVO> myCassl = cRelationshipStudentSgcMapper.getMyCassl(userId);
  724 + if(myCassl==null){
  725 + return AjaxResult.error("你还没有绑定班级");
  726 + }
  727 + for (MyTeacherVO myTeacherVO : myCassl ){
719 728
720 - // cRelationshipStudentSgcMapper. 729 + List<CTeacher> cTeachers = cTeacherMapper.selectList(Wrappers.lambdaQuery(new CTeacher()).eq(CTeacher::getGradeId, myTeacherVO.getGradeId()));
721 730
  731 + myTeacherVO.setCTeachers(cTeachers);
  732 + }
722 733
723 - return null; 734 + return AjaxResult.success(myCassl);
724 } 735 }
725 736
726 /** 737 /**
@@ -60,7 +60,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -60,7 +60,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
60 60
61 <select id="getMyCassl" resultType="com.example.client.domain.vo.MyTeacherVO" parameterType="long"> 61 <select id="getMyCassl" resultType="com.example.client.domain.vo.MyTeacherVO" parameterType="long">
62 62
  63 + SELECT r.gerde_id, s.school_name FROM c_relationship_student_sgc r
  64 + LEFT JOIN c_register_school s on s.school_id =r.school_id
63 65
  66 + WHERE r.user_id = #{userId}
64 67
65 </select> 68 </select>
66 69