jyy
2021-04-08 31d69134d1bcaac9c50b6a57784aeb436d5bd75c
zq-erp/src/main/java/com/matrix/system/common/actions/CommonAction.java
@@ -13,9 +13,11 @@
import com.matrix.system.common.authority.DefaultAuthorityManager;
import com.matrix.system.common.authority.strategy.AccountPasswordLogin;
import com.matrix.system.common.authority.strategy.LoginStrategy;
import com.matrix.system.common.authority.strategy.ScanQrCodeLogin;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.constance.AppConstance;
import com.matrix.system.common.dao.ProjExceptionDao;
import com.matrix.system.common.dto.WebLoginDto;
import com.matrix.system.common.service.SysUsersService;
import com.matrix.system.hive.dao.SysShopInfoDao;
import com.matrix.system.hive.statistics.StatisticsBusinessDataJob;
@@ -97,17 +99,22 @@
    * 
    *  登录验证
    * @author:姜友瑶
    * @param user
    * @return 返回类型 AjaxResult
    * @date 2016年8月30日
    */
   @RequestMapping(value = "/dologin")
   public @ResponseBody AjaxResult dologin(SysUsers user) {
      long sqlStart = System.currentTimeMillis();
      decryptAccountAndPassword(user);
      LoginStrategy apLogin = new AccountPasswordLogin(user, sysUsersService);
   public @ResponseBody AjaxResult dologin(WebLoginDto webLoginDto) {
      user = authorityManager.login(apLogin);
      long sqlStart = System.currentTimeMillis();
      SysUsers user=null;
      if(WebLoginDto.ACCOUNT_LOGIN.equals(webLoginDto.getLoginType())){
         user= decryptAccountAndPassword(webLoginDto);
         LoginStrategy apLogin = new AccountPasswordLogin(user, sysUsersService);
         user = authorityManager.login(apLogin);
      }else {
         ScanQrCodeLogin apLogin = new ScanQrCodeLogin( sysUsersService,webLoginDto.getLoginQrCodeKey());
         user = authorityManager.login(apLogin);
      }
      if(user.getShopId()!=null){
@@ -155,28 +162,27 @@
    * @author JIANGYOUYAO
    * @email 935090232@qq.com
    * @date 2017年12月11日
    * @param user
    */
   private void decryptAccountAndPassword(SysUsers user) {
   private SysUsers decryptAccountAndPassword(WebLoginDto webLoginDto) {
      String privateKey = WebUtil.getSessionAttribute(MatrixConstance.PRIVATE_KEY);
      if (StringUtils.isBlank(privateKey)) {
         throw new GlobleException(SystemErrorCode.REQUEST_INVALID);
      }
      SysUsers user=new SysUsers();
      try {
         // 账号解密
         byte[] acccountData = RSAUtils.decryptByPrivateKey(user.getSuAccount(), privateKey);
         byte[] acccountData = RSAUtils.decryptByPrivateKey(webLoginDto.getSuAccount(), privateKey);
         user.setSuAccount(new String(acccountData));
         // 密码解密
         byte[] passWordData = RSAUtils.decryptByPrivateKey(user.getSuPassword(), privateKey);
         byte[] passWordData = RSAUtils.decryptByPrivateKey(webLoginDto.getSuPassword(), privateKey);
         user.setSuPassword(new String(passWordData));
      } catch (Exception e) {
         LogUtil.error("用户账号密码解密失败", e);
         throw new GlobleException(SystemErrorCode.LOGIN_FAIL);
      }
      return user;
   }
@@ -246,44 +252,6 @@
         return "admin/hive/mobile/mobileLogin";
      }
   }
   /**
    * 移动端登录
    * @param user
    * @return
    */
   @RequestMapping(value = "/doHiveMobilelogin")
   public @ResponseBody AjaxResult doHiveMobilelogin(SysUsers user) {
      long sqlStart = System.currentTimeMillis();
      decryptAccountAndPassword(user);
      LoginStrategy apLogin = new AccountPasswordLogin(user, sysUsersService);
      user = authorityManager.login(apLogin);
      // 获取该账户的岗位信息,并判断是否为店长
      if(user.getShopId()!=null){
         user.setShopName(sysShopInfoDao.selectById(user.getShopId()).getShopName());
      }
      AjaxResult result = new AjaxResult();
      authorityManager.initUserPower(result);
      result.setStatus(AjaxResult.STATUS_SUCCESS);
      LogUtil.info("#用户登录成功 账号={}#", user.getSuAccount());
      switch (user.getSuUserType()) {
         // 企业管理员
         case AppConstance.USER_TYPE_ADMIN:
            result.setPage(HIVE_MOBILE_REDIRECT_INDEX);
            break;
         // 企业用户
         case AppConstance.USER_TYPE_EMPLOYEE:
            result.setPage(HIVE_MOBILE_REDIRECT_INDEX);
            break;
         default:// 不能识别的用户
            result.setPage("common/redirect/404");
      }
      long endStart = System.currentTimeMillis();
      LogUtil.info("本次登录耗时#{}毫秒", (endStart-sqlStart)+"");
      return result;
   }
   @GetMapping(value = "/hiveMobileLoginOut")