package com.zteits.oa.report.web; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.zteits.oa.api.base.bean.BizResult; import com.zteits.oa.api.base.constants.ErrorType; import com.zteits.oa.api.base.constants.SessionEnum; import com.zteits.oa.api.dto.asraop.AsraOpDTO; import com.zteits.oa.api.dto.asraop.LoginOathRes; import com.zteits.oa.api.dto.asraop.param.AsraOpQueryReq; import com.zteits.oa.api.dto.asraop.param.LoginOauthReq; import com.zteits.oa.api.service.report.query.AsraOpRueryService; import com.zteits.oa.util.MD5Utils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @Api("用户登录授权") @RestController @RequestMapping("/oauth") public class OAuthController { private static final Logger logger = LoggerFactory.getLogger(OAuthController.class); @Autowired private AsraOpRueryService asraOpRueryService; @Autowired private HttpServletRequest request; @ApiOperation("用户登录") @PostMapping("/login") public BizResult login(@RequestBody LoginOauthReq req ) throws Exception { BizResult result = this._login(req); return result; } /** * 登陆验证.
* @param req * @return * 2018年7月31日 wangfs.
*/ private BizResult _login(LoginOauthReq req ){ BizResult result = new BizResult(); LoginOathRes loginOathRes = new LoginOathRes(); String loginCode = req.getLoginCode(); String passWord = req.getPassWord(); if(StringUtils.isEmpty(loginCode) || StringUtils.isEmpty(passWord)) { logger.info("校验登录信息,用户名 或者 登录密码为空!"); result.setErrorInfo(ErrorType.PARAMM_NULL, "用户名 或者 登录密码为空"); } AsraOpQueryReq asraOpQueryRe = new AsraOpQueryReq(); AsraOpDTO asraOpDTO = new AsraOpDTO(); boolean isCheckSuccess = false; //1.判断登录账号/密码 asraOpQueryRe.setLoginCode(loginCode); BizResult asraOpReult = asraOpRueryService.queryAsraOp(asraOpQueryRe); if(asraOpReult != null && asraOpReult.getData() != null){ asraOpDTO = asraOpReult.getData(); if(StringUtils.isEmpty(asraOpDTO.getLoginCode())){ logger.info("{}登录账号不存在",loginCode); result.setErrorInfo(ErrorType.AUTH_LOGIN_ERROR, "登录账号不存在!"); }else{ if(!asraOpDTO.getLoginPassword().equalsIgnoreCase(MD5Utils.enMD5(passWord))){ logger.info("{}登录账号输入的密码不正确",loginCode); result.setErrorInfo(ErrorType.AUTH_PASS_ERROR, "登录密码不匹配!"); }else{ isCheckSuccess = true; } } }else{ result.setErrorInfo(ErrorType.BIZ_ERROR, "用户登录失败"); } if(isCheckSuccess){ HttpSession session = request.getSession(); session.setAttribute(SessionEnum.USER_INFO.key(), asraOpDTO); logger.info("---获取到的session_id={}",session.getId()); loginOathRes.setOpId(asraOpDTO.getId()); loginOathRes.setLoginCode(loginCode); loginOathRes.setUserName(asraOpDTO.getOpName()); loginOathRes.setCityId(asraOpDTO.getCityId()); loginOathRes.setCityName(asraOpDTO.getCityName()); loginOathRes.setAccessToken(session.getId()); result.setData(loginOathRes); result.setErrorInfo(ErrorType.BIZ_SUCCESS, "登录成功"); } return result; } }