派生自 projectDept/qhighschool

yn147
2023-04-12 3db770d9519e532e36b370aba561fa7edbda4c3d
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";
   /**
    * 小程序appID
    */
   @Value("${wx.appId}")
   private String appId;
   /**
    * 小程序secret
    */
   @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({
@@ -294,18 +365,21 @@
    public Result platformLogin(@RequestParam("account") String account, @RequestParam("password") String password,String uuNumber,String uuReNumber,
                                HttpServletRequest request, HttpServletResponse response, String logType,String organizationId, String platForm) {
//      response.setHeader("Access-Control-Allow-Origin", "*");
       if(StringUtils.isEmpty(account)) {
          return new Result(false, "用户账号不能为空");
       }
      if (StringUtils.isEmpty(account)) {
         return new Result(false, "用户账号不能为空");
      }
//      System.out.println(account+password);
//      System.out.println("-------------------------"+organizationId+"--------------"+platForm+"-----------"+logType);
       String hql = null;
        List<Object> params = null;
      String hql = null;
      List<Object> params = null;
//        boolean flag=true;
       if("study".equals(logType)){
            hql = "from User where deleteFlag is false and account = ? and password = ? ";
            params =  CollectionUtils.newList(account,password);
        }else{
      if ("study".equals(logType)) {
         hql = "from User where deleteFlag is false and account = ? and password = ? ";
         params = CollectionUtils.newList(account, password);
      }else if("portal".equals(logType)){
         hql = "from User where deleteFlag is false and mobilePhone = ? and password = ? ";
         params = CollectionUtils.newList(account, password);
      }else{
            if(StringUtils.isEmpty(password)) {
            return new Result(false, "用户密码不能为空");
         }
@@ -371,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, "该用户未加入任何班级或未激活,请联系班主任");
         }*/