From 3db770d9519e532e36b370aba561fa7edbda4c3d Mon Sep 17 00:00:00 2001
From: yn147 <2270338776@qq.com>
Date: 星期三, 12 四月 2023 18:03:54 +0800
Subject: [PATCH] 删除subjectId

---
 src/main/java/com/qxueyou/scc/sys/action/LoginController.java |   77 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 74 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/qxueyou/scc/sys/action/LoginController.java b/src/main/java/com/qxueyou/scc/sys/action/LoginController.java
index 7aa42d1..81ed905 100644
--- a/src/main/java/com/qxueyou/scc/sys/action/LoginController.java
+++ b/src/main/java/com/qxueyou/scc/sys/action/LoginController.java
@@ -1,5 +1,6 @@
 package com.qxueyou.scc.sys.action;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -9,10 +10,16 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
+import com.alibaba.fastjson.JSONObject;
 import com.qxueyou.scc.base.util.*;
+import com.qxueyou.scc.wx.service.IWechatService;
+import freemarker.template.utility.StringUtil;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.kafka.common.network.LoginType;
+import org.apache.tomcat.util.net.openssl.ciphers.Authentication;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.StringRedisTemplate;
@@ -95,7 +102,71 @@
     @Autowired
     private IOrganizationService organizationService;
 
-    public static String UUNUMBER="QXYUUNUMBER";
+	/**
+	 * 灏忕▼搴廰ppID
+	 */
+	@Value("${wx.appId}")
+	private String appId;
+
+
+	/**
+	 * 灏忕▼搴弒ecret
+	 */
+	@Value("${wx.secret}")
+	private String secret;
+
+
+	public static String UUNUMBER="QXYUUNUMBER";
+
+	@Autowired
+	IWechatService wechatService;
+
+	/**
+	 * 寰俊鐧诲綍
+	 *
+	 * @param uid
+	 * @throws IOException
+	 */
+
+	@PostMapping("/wxlogin")
+	@ApiOperation("寰俊鐧诲綍")
+	@ResponseBody
+	public Result wechatLogin(String code,String number) {
+		JSONObject sessionKeyOrOpenId = wechatService.getSessionKeyOrOpenId(code);
+		JSONObject gettoken = wechatService.gettoken(appId, secret);
+		Result phone = wechatService.getNumber(gettoken.get("access_token").toString(), number);
+		if(phone.getSuccess()){
+			String hql = "from User where deleteFlag is false and mobilePhone = ? ";
+			System.out.println(phone.getData());
+			List<Object> params =  CollectionUtils.newList(phone.getData());
+			User user = commonDAO.findUnique(hql,params, User.class);
+			if(user==null){
+				//鏂板鐢ㄦ埛
+				User user1=new User();
+				user1.setMobilePhone(phone.getData().toString());
+				user1.setOpenId(sessionKeyOrOpenId.get("openid").toString());
+				commonDAO.save(user1);
+				//鏂板鍏宠仈瀛﹀憳
+				String addUserSql = "from User where deleteFlag is false and mobilePhone = ? ";
+				List<Object> newParams =  CollectionUtils.newList(phone.getData());
+				User newUser = commonDAO.findUnique(addUserSql,newParams, User.class);
+				StuStudent stuStudent=new StuStudent();
+				stuStudent.setStatus(StuStudent.STATUS_REGISTER);
+				stuStudent.setUserId(newUser.getUserId());
+				stuStudent.setMobilePhone(newUser.getMobilePhone());
+				commonDAO.save(stuStudent);
+			}
+			if(StringUtils.isEmpty(user.getOpenId())){
+				user.setOpenId(sessionKeyOrOpenId.get("openid").toString());
+				commonDAO.saveOrUpdate(user);
+			}
+			String studentSql = "from StuStudent where deleteFlag is false and userId = ? ";
+			List<Object> stuParams =  CollectionUtils.newList(user.getUserId());
+			StuStudent stuStudent = commonDAO.findUnique(studentSql, stuParams, StuStudent.class);
+			return new Result(true,"鎺堟潈鎴愬姛",CollectionUtils.newObjectMap("user",user,"ClassId",stuStudent.getClassId()));
+		}
+		return phone;
+}
 
 	@ApiOperation(value = "鐧诲叆鎺ュ彛", notes = "")
 	@ApiImplicitParams({
@@ -312,7 +383,7 @@
             if(StringUtils.isEmpty(password)) {
 				return new Result(false, "鐢ㄦ埛瀵嗙爜涓嶈兘涓虹┖");
 			}
-            hql = "from User where deleteFlag is false and mobilePhone = ? and password = ? ";
+            hql = "from User where deleteFlag is false and account = ? and password = ? ";
             params =  CollectionUtils.newList(account,password);
         }
 
@@ -374,7 +445,7 @@
 		// 瀛樺埌redis
 		redisTemplate.opsForValue().set(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper);
 		request.getSession().setAttribute(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper);
-		if ("study".equals(logType)) {
+		if ("study".equals(logType) || "portal".equals(logType)) {
 			/*if (StringUtils.isEmpty(ClientUtils.getClassId()) && user.getRoles() == null) {
 				return new Result(false, "璇ョ敤鎴锋湭鍔犲叆浠讳綍鐝骇鎴栨湭婵�娲伙紝璇疯仈绯荤彮涓讳换");
 			}*/

--
Gitblit v1.8.0