From c2090b25ad4a9a1981dc65467248d10307e096f6 Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期四, 28 十月 2021 16:58:21 +0800 Subject: [PATCH] 优化修改 --- phi_platform_user/src/main/java/com/hx/phip/controller/EmployeeLoginController.java | 91 ++++++++++++++++++++++++++++++++------------- 1 files changed, 65 insertions(+), 26 deletions(-) diff --git a/phi_platform_user/src/main/java/com/hx/phip/controller/EmployeeLoginController.java b/phi_platform_user/src/main/java/com/hx/phip/controller/EmployeeLoginController.java index 21eef5b..388f232 100644 --- a/phi_platform_user/src/main/java/com/hx/phip/controller/EmployeeLoginController.java +++ b/phi_platform_user/src/main/java/com/hx/phip/controller/EmployeeLoginController.java @@ -4,19 +4,15 @@ import com.alibaba.fastjson.JSONObject; import com.hx.common.BaseController; import com.hx.mybatisTool.SqlSentence; -import com.hx.phiappt.model.Employee; -import com.hx.phiappt.model.EmployeeRole; -import com.hx.phiappt.model.EmployeeRoleAdminAuthority; -import com.hx.phiappt.model.SysAdminAuthority; +import com.hx.phiappt.model.*; import com.hx.phip.common.corp.mp.WeiXinCorpMpUtil; -import com.hx.phip.config.WxParameter; -import com.hx.phip.dao.mapper.EmployeeMapper; -import com.hx.phip.dao.mapper.EmployeeRoleMapper; -import com.hx.phip.dao.mapper.EmployeeRoleTypeMapper; -import com.hx.phip.dao.mapper.SysAdminAuthorityMapper; +import com.hx.phip.dao.mapper.*; import com.hx.phip.entity.EmployeeQrLogin; import com.hx.phip.entity.EmployeeRoleLogin; +import com.hx.phip.model.ApplyParameter; +import com.hx.phip.tool.ApplyParameterTool; import com.hx.redis.RedisUtil; +import com.hx.util.AesUtil; import com.hx.util.HttpServletRequestUtil; import com.hx.util.JwtTool; import com.hx.util.StringUtils; @@ -29,6 +25,8 @@ import com.platform.util.corp.PersonnelTool; import com.platform.util.corp.entity.PersonnelQr; import org.apache.catalina.servlet4preview.http.HttpServletRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @@ -48,9 +46,8 @@ @RequestMapping("/employee") public class EmployeeLoginController extends BaseController { - - @Resource - private WxParameter wxParameter; + //log4j鏃ュ織 + private static Logger logger = LoggerFactory.getLogger(EmployeeLoginController.class.getName()); @Resource private RedisUtil redisUtil; @@ -79,17 +76,33 @@ } if (StringUtils.isEmpty(employeeQrLogin.getCode())) { - throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"first code is required"); + throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"code is required"); + } + + if (StringUtils.isEmpty(employeeQrLogin.getCorpId())) { + throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"corpId is required"); + } + + if (StringUtils.isEmpty(employeeQrLogin.getMpId())) { + throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"mpId is required"); + } + + //鑾峰彇搴旂敤鏁版嵁 + ApplyParameter applyParameter = ApplyParameterTool.getApplyParameter(employeeQrLogin.getCorpId(),employeeQrLogin.getMpId(),commonService); + if(applyParameter == null){ + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"corpId or mpId is error"); } // 瑙f瀽code - String accessToken = WeiXinCorpMpUtil.getApplicationAccessToken(commonService, wxParameter.getCorpId(), wxParameter.getHelperApplySecret()); + String accessToken = WeiXinCorpMpUtil.getApplicationAccessToken(commonService,applyParameter.getCorpId(), AesUtil.aesDecryp(applyParameter.getApplySecretKey())); if(StringUtils.isEmpty(accessToken)){ throw new PlatTipsException(PlatformCode.ERROR_SYSTEM,"鏈嶅姟閿欒"+ SystemCode.ERROR_GET_CORP_TOKEN); } //net.sf.json.JSONObject json = WeiXinCorpMpUtil.getLoginUserInfo(accessToken, employeeQrLogin.getCode()); PersonnelQr personnelQr = PersonnelTool.qrLoginInfo(accessToken,employeeQrLogin.getCode()); + + logger.info("鎵爜鐧诲綍锛�"+personnelQr.toString()); if(personnelQr == null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"浜哄憳淇℃伅涓嶅瓨鍦�"); @@ -132,8 +145,9 @@ values.clear(); values.put("employeeId",employee.getId()); - sqlSentence.setSqlSentence(" select ert.id,ert.name,ert.uniqueStr from employee_role o JOIN employee_role_type ert ON isDel = 0" + - " AND ert.id = o.roleTypeId where o.employeeId = #{m.employeeId} AND o.isDel = #{m.isDel}"); + values.put("isDel",EmployeeRole.NO); + sqlSentence.setSqlSentence(" select ert.id,ert.name,ert.uniqueStr,s.name AS shopName from employee_role o JOIN employee_role_type ert ON ert.isDel = 0" + + " AND ert.id = o.roleTypeId LEFT JOIN shop s ON s.id = o.shopId WHERE o.employeeId = #{m.employeeId} AND o.isDel = #{m.isDel}"); List<Map<String,Object>> roleList = commonService.selectListMap(EmployeeRoleTypeMapper.class,sqlSentence); Map<String,Object> data = new HashMap<>(); @@ -147,15 +161,17 @@ data.put("gender", employee.getGender()); data.put("loginToken", JwtTool.createJWT(employee.getId(), null, ttlMillis)); - if (redisUtil.hasKey(userId)){ - redisUtil.expire(userId,ttlMillis); + if (redisUtil.hasKey(employee.getId())){ + redisUtil.expire(employee.getId(),ttlMillis); }else { - redisUtil.set(userId,data,ttlMillis); + redisUtil.set(employee.getId(),data,ttlMillis); } return PlatformResult.success(data); } /**浼佷笟鍛樺伐-缃戦〉鐧诲綍 + * @param request + * @return */ @RequestMapping(value = "/login/webpage",method = RequestMethod.POST) public PlatformResult loginWebpage(HttpServletRequest request) { @@ -177,16 +193,33 @@ } if (StringUtils.isEmpty(employeeQrLogin.getCode())) { - throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"first code is required"); + throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"code is required"); } - String accessToken = WeiXinCorpMpUtil.getApplicationAccessToken(commonService, wxParameter.getCorpId(), wxParameter.getHelperApplySecret()); + if (StringUtils.isEmpty(employeeQrLogin.getCorpId())) { + throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"corpId is required"); + } + + if (StringUtils.isEmpty(employeeQrLogin.getMpId())) { + throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"mpId is required"); + } + + //鑾峰彇搴旂敤鏁版嵁 + ApplyParameter applyParameter = ApplyParameterTool.getApplyParameter(employeeQrLogin.getCorpId(),employeeQrLogin.getMpId(),commonService); + if(applyParameter == null){ + throw new PlatTipsException(PlatformCode.ERROR_TIPS,"corpId or mpId is error"); + } + + String accessToken = WeiXinCorpMpUtil.getApplicationAccessToken(commonService,applyParameter.getCorpId(),AesUtil.aesDecryp(applyParameter.getApplySecretKey())); + //鑾峰彇userId net.sf.json.JSONObject oauthObj = com.hx.mp.util.CorpMpUtil.code2Session(accessToken,employeeQrLogin.getCode()); //String errcode = oauthObj.optString("errcode", "");// 鏈夐敊璇殑鏃跺�欐墠鏈� // String corpId = oauthObj.optString("corpid", "");// 鏈夐敊璇殑鏃跺�欐墠鏈� String userId = oauthObj.optString("userid", ""); // String sessionKey = oauthObj.optString("session_key"); + + logger.info("缃戦〉鐧诲綍锛�"+oauthObj.toString()); if (StringUtils.isEmpty(userId)) { throw new PlatTipsException(PlatformCode.ERROR_TIPS,"浜哄憳娌℃湁鏉冮檺鐧诲綍"); @@ -220,8 +253,9 @@ values.clear(); values.put("employeeId",employee.getId()); - sqlSentence.setSqlSentence(" select ert.id,ert.name,ert.uniqueStr from employee_role o JOIN employee_role_type ert ON isDel = 0" + - " AND ert.id = o.roleTypeId where o.employeeId = #{m.employeeId} AND o.isDel = #{m.isDel}"); + values.put("isDel",EmployeeRole.NO); + sqlSentence.setSqlSentence(" select ert.id,ert.name,ert.uniqueStr,s.name AS shopName from employee_role o JOIN employee_role_type ert ON ert.isDel = 0" + + " AND ert.id = o.roleTypeId LEFT JOIN shop s ON s.id = o.shopId WHERE o.employeeId = #{m.employeeId} AND o.isDel = #{m.isDel}"); List<Map<String,Object>> roleList = commonService.selectListMap(EmployeeRoleTypeMapper.class,sqlSentence); Map<String,Object> data = new HashMap<>(); @@ -235,10 +269,10 @@ data.put("gender", employee.getGender()); data.put("loginToken", JwtTool.createJWT(employee.getId(), null, ttlMillis)); - if (redisUtil.hasKey(userId)){ - redisUtil.expire(userId,ttlMillis); + if (redisUtil.hasKey(employee.getId())){ + redisUtil.expire(employee.getId(),ttlMillis); }else { - redisUtil.set(userId,data,ttlMillis); + redisUtil.set(employee.getId(),data,ttlMillis); } return PlatformResult.success(data); } @@ -303,6 +337,11 @@ data.put("roleName", employeeRole.getRoleName()); data.put("authList", arrAuth); + Shop shop = commonService.selectOneByKey(ShopMapper.class,employeeRole.getShopId()); + if(shop != null){ + data.put("shopName", shop.getName()); + } + if (redisUtil.hasKey(employeeRole.getRoleTypeId())){ redisUtil.expire(employeeRole.getRoleTypeId(),ttlMillis); }else { -- Gitblit v1.8.0