|
|
@@ -11,12 +11,14 @@ import com.template.config.WxOpenidConfig;
|
|
|
import com.template.model.enumModel.eIdentityTypeStatu;
|
|
|
import com.template.model.enumModel.eStatu;
|
|
|
import com.template.model.pojo.WelcomeAccount;
|
|
|
+import com.template.model.pojo.WelcomeOrg;
|
|
|
import com.template.model.pojo.WelcomeStudent;
|
|
|
import com.template.model.request.*;
|
|
|
import com.template.model.result.CommonResult;
|
|
|
import com.template.model.result.Wx_user;
|
|
|
import com.template.model.vo.*;
|
|
|
import com.template.services.WelcomeAccountService;
|
|
|
+import com.template.services.WelcomeOrgService;
|
|
|
import com.template.services.WelcomeStudentService;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
@@ -51,6 +53,8 @@ public class LoginController implements LoginControllerAPI {
|
|
|
private WelcomeAccountService welcomeAccountService;
|
|
|
@Resource
|
|
|
private WelcomeStudentService welcomeStudentService;
|
|
|
+ @Resource
|
|
|
+ private WelcomeOrgService welcomeOrgService;
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(LoginController.class);
|
|
|
|
|
|
@@ -93,7 +97,7 @@ public class LoginController implements LoginControllerAPI {
|
|
|
return CommonResult.fail("密码错误");
|
|
|
}
|
|
|
|
|
|
- TokenDateVo tokenDate = JWTUtil.getToken(result.getId(),null);
|
|
|
+ TokenDateVo tokenDate = JWTUtil.getToken(result.getId(), null);
|
|
|
String token = tokenDate == null ? "" : tokenDate.getToken();
|
|
|
Date expireTime = tokenDate == null ? new Date() : tokenDate.getExpireTime();
|
|
|
LoginVO login = new LoginVO();
|
|
|
@@ -145,7 +149,7 @@ public class LoginController implements LoginControllerAPI {
|
|
|
@PassToken
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
|
public CommonResult Openid(String wxcode) throws Exception {
|
|
|
- System.out.println("微校授权:"+wxcode);
|
|
|
+ System.out.println("微校授权:" + wxcode);
|
|
|
Gson gson = new Gson();
|
|
|
String tokenUrl = "https://open.wecard.qq.com/connect/oauth2/token";
|
|
|
Map<String, String> tokenParams = new HashMap<>();
|
|
|
@@ -174,22 +178,20 @@ public class LoginController implements LoginControllerAPI {
|
|
|
String card_number = null;
|
|
|
String user_name = null;
|
|
|
String phone = null;
|
|
|
- int identity_type = 0;
|
|
|
String college = null;
|
|
|
String grade = null;
|
|
|
String profession = null;
|
|
|
String campus = null;
|
|
|
String id_card = null;
|
|
|
String classStr = null;
|
|
|
- System.out.println("微校授权获取用户信息:"+userinfo);
|
|
|
+ System.out.println("微校授权获取用户信息:" + userinfo);
|
|
|
Wx_user userinfos = gson.fromJson(userinfo, new TypeToken<Wx_user>() {
|
|
|
}.getType());
|
|
|
- System.out.println("微校授权获取用户信息类别:"+userinfos.getIdentity_type());
|
|
|
+ System.out.println("微校授权获取用户信息类别:" + userinfos.getIdentity_type());
|
|
|
try {
|
|
|
card_number = userinfos.getCard_number();
|
|
|
user_name = userinfos.getName();
|
|
|
phone = userinfos.getTelephone();
|
|
|
- identity_type = userinfos.getIdentity_type();
|
|
|
college = userinfos.getCollege();
|
|
|
classStr = userinfos.getClassStr();
|
|
|
grade = userinfos.getGrade();
|
|
|
@@ -198,7 +200,7 @@ public class LoginController implements LoginControllerAPI {
|
|
|
id_card = userinfos.getId_card();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- System.out.println("微校授权异常信息:"+e.getMessage());
|
|
|
+ System.out.println("微校授权异常信息:" + e.getMessage());
|
|
|
return CommonResult.fail(e.getMessage());
|
|
|
}
|
|
|
|
|
|
@@ -212,11 +214,11 @@ public class LoginController implements LoginControllerAPI {
|
|
|
// return CommonResult.fail("非法权限,授权失败");
|
|
|
//}
|
|
|
|
|
|
- System.out.println("微校授权校区:"+campus);
|
|
|
+ System.out.println("微校授权校区:" + campus);
|
|
|
|
|
|
Integer studentId = 0;
|
|
|
if (student == null) {
|
|
|
- try{
|
|
|
+ try {
|
|
|
student = new WelcomeStudent();
|
|
|
student.setAdmissNum(card_number);
|
|
|
student.setName(user_name);
|
|
|
@@ -227,15 +229,15 @@ public class LoginController implements LoginControllerAPI {
|
|
|
student.setCardId(id_card);//身份证号
|
|
|
int num = welcomeStudentService.insertWelcomeStudent(student);
|
|
|
if (num <= 0) {
|
|
|
- System.out.println("微校授权失败,学生信息新增异常:"+user_name+""+card_number);
|
|
|
+ System.out.println("微校授权失败,学生信息新增异常:" + user_name + "" + card_number);
|
|
|
throw new Exception("微校授权失败!");
|
|
|
}
|
|
|
studentId = num;
|
|
|
- }catch (Exception e){
|
|
|
- System.out.println("微校授权异常信息:"+e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("微校授权异常信息:" + e.getMessage());
|
|
|
throw new Exception("微校授权失败!");
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//更新微校获取的年纪信息
|
|
|
student.setAdmissNum(card_number);
|
|
|
student.setName(user_name);
|
|
|
@@ -247,22 +249,60 @@ public class LoginController implements LoginControllerAPI {
|
|
|
|
|
|
int num = welcomeStudentService.updateWelcomeStudent(student);
|
|
|
if (num <= 0) {
|
|
|
- System.out.println("微校授权失败,用户信息新增异常:"+user_name+""+card_number);
|
|
|
+ System.out.println("微校授权失败,用户信息新增异常:" + user_name + "" + card_number);
|
|
|
throw new Exception("微校授权失败!");
|
|
|
}
|
|
|
studentId = student.getId();
|
|
|
}
|
|
|
-
|
|
|
wxLoginVo wlv = new wxLoginVo();
|
|
|
+ List<WelcomeOrg> orgs = welcomeOrgService.queryDatas(college, profession, classStr);
|
|
|
+ if (orgs != null && orgs.size() > 0) {
|
|
|
+ for (WelcomeOrg org : orgs) {
|
|
|
+ if (org.getName().equals(college)) {
|
|
|
+ wlv.setCollegeId(org.getId());
|
|
|
+ wlv.setCollege(college);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (org.getName().equals(profession)) {
|
|
|
+ wlv.setMajorId(org.getId());
|
|
|
+ wlv.setMajor(profession);
|
|
|
+ }
|
|
|
+ if (org.getName().equals(classStr)) {
|
|
|
+ wlv.setClassstrId(org.getId());
|
|
|
+ wlv.setClassstr(classStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wlv.setId(studentId);
|
|
|
+ wlv.setAdmissNum(card_number);
|
|
|
+ wlv.setName(user_name);
|
|
|
+ wlv.setPicture(student.getPicture());
|
|
|
+ wlv.setCardId(id_card);
|
|
|
+ wlv.setSex(student.getSex());
|
|
|
|
|
|
- wlv.setUserId(studentId);
|
|
|
- wlv.setUserName(student.getName());
|
|
|
- wlv.setUserPhone(student.getPhone().replace("(+86)",""));
|
|
|
+ wlv.setPhone(student.getPhone().replace("(+86)", ""));
|
|
|
wlv.setCollege(college == null ? "微校获取不到院校" : college);
|
|
|
long expired = 1000 * 60 * 60 * 24 * 365;
|
|
|
TokenDateVo token = JWTUtil.getToken(student.getId(), expired);
|
|
|
wlv.setToken(token.getToken());
|
|
|
- System.out.println("微校授权成功:"+user_name+""+card_number);
|
|
|
+ System.out.println("微校授权成功:" + user_name + "" + card_number);
|
|
|
return CommonResult.ok(wlv);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult mobileLogin(mobileLoginRequest mlr, BindingResult bindingResult) {
|
|
|
+ if (mlr == null) {
|
|
|
+ return CommonResult.fail("请传递参数");
|
|
|
+ }
|
|
|
+ if (bindingResult.hasErrors()) {
|
|
|
+ String st = paramUtils.getParamError(bindingResult);
|
|
|
+ return CommonResult.fail(st);
|
|
|
+ }
|
|
|
+
|
|
|
+ WelcomeStudent student = welcomeStudentService.getDataByIdcardOrNum(mlr.getAdmissNum(), mlr.getCardId());
|
|
|
+ if(student == null){
|
|
|
+ student = new WelcomeStudent();
|
|
|
+ }
|
|
|
+ return CommonResult.ok(student);
|
|
|
+ }
|
|
|
}
|