From d85b33f637114ad69e4e77ed3ce5f819f93fd9d7 Mon Sep 17 00:00:00 2001 From: yinzuomei <576302893@qq.com> Date: Tue, 21 Apr 2020 22:48:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4ErrorCode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/controller/GovLoginController.java | 13 +++++ .../com/epmet/service/GovLoginService.java | 10 ++++ .../service/impl/GovLoginServiceImpl.java | 16 +++++- .../epmet/service/impl/LoginServiceImpl.java | 2 +- .../epmet/common/token/enums/ErrorCode.java | 51 ------------------- .../epmet/common/token/error/IErrorCode.java | 11 ---- .../tools/exception/EpmetErrorCode.java | 5 ++ .../filter/CpAuthGatewayFilterFactory.java | 10 ++-- .../com/epmet/filter/FeignRequestFilter.java | 5 -- .../com/epmet/filter/UserTokenFilter.java | 5 +- .../com/epmet/dto/form/StaffOrgFormDTO.java | 4 ++ .../epmet/controller/CustomerController.java | 6 +-- .../controller/UserMessageController.java | 11 ++-- 13 files changed, 59 insertions(+), 90 deletions(-) delete mode 100644 epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java delete mode 100644 epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/error/IErrorCode.java diff --git a/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java b/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java index ea4b5c8974..886fb67bd0 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/GovLoginController.java @@ -1,5 +1,7 @@ package com.epmet.controller; +import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.GovWxmpEnteOrgFormDTO; @@ -80,5 +82,16 @@ public class GovLoginController { return govLoginService.enterOrg(formDTO); } + /** + * @param tokenDto + * @return com.epmet.commons.tools.utils.Result + * @Author yinzuomei + * @Description 政府端小程序退出 + * @Date 2020/4/21 22:22 + **/ + @PostMapping("/loginwxmp/loginout") + public Result loginOut(@LoginUser TokenDto tokenDto) { + return govLoginService.loginOut(tokenDto); + } } diff --git a/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java b/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java index 8e98ad44de..f61e9c8fab 100644 --- a/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java +++ b/epmet-auth/src/main/java/com/epmet/service/GovLoginService.java @@ -1,5 +1,6 @@ package com.epmet.service; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.GovWxmpEnteOrgFormDTO; import com.epmet.dto.form.GovWxmpFormDTO; @@ -51,4 +52,13 @@ public interface GovLoginService { * @Date 2020/4/20 13:08 **/ Result enterOrg(GovWxmpEnteOrgFormDTO formDTO); + + /** + * @return com.epmet.commons.tools.utils.Result + * @param tokenDto + * @Author yinzuomei + * @Description 政府端工作人员退出登录 + * @Date 2020/4/21 22:08 + **/ + Result loginOut(TokenDto tokenDto); } diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java index 75cf5d7300..2c0300a947 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java @@ -3,14 +3,18 @@ package com.epmet.service.impl; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import com.epmet.common.token.constant.LoginConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.GovTokenDto; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.CpUserDetailRedis; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.PhoneValidatorUtils; import com.epmet.dto.CustomerStaffDTO; import com.epmet.dto.form.*; -import com.epmet.dto.result.*; +import com.epmet.dto.result.StaffLatestAgencyResultDTO; +import com.epmet.dto.result.StaffOrgsResultDTO; +import com.epmet.dto.result.UserTokenResultDTO; import com.epmet.feign.EpmetUserFeignClient; import com.epmet.feign.GovOrgFeignClient; import com.epmet.feign.MessageFeignClient; @@ -201,6 +205,16 @@ public class GovLoginServiceImpl implements GovLoginService { return new Result().ok(userTokenResultDTO); } + @Override + public Result loginOut(TokenDto tokenDto) { + if(null == tokenDto){ + logger.error("token解析失败,直接跳转重新登录即可"); + throw new RenException("当前用户信息获取失败"); + } + cpUserDetailRedis.logout(tokenDto.getApp() , tokenDto.getClient() , tokenDto.getUserId()); + return new Result(); + } + //保存登录日志 private Result saveStaffLoginRecord(GovWxmpEnteOrgFormDTO formDTO, String staffId, String openId) { StaffLoginAgencyRecordFormDTO staffLoginAgencyRecordFormDTO = new StaffLoginAgencyRecordFormDTO(); diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java index 225e2520fb..f3cef61f98 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/LoginServiceImpl.java @@ -313,7 +313,7 @@ public class LoginServiceImpl implements LoginService { } cpUserDetailRedis.logout(tokenDto.getApp() , tokenDto.getClient() , tokenDto.getUserId()); //web端清空菜单栏和权限 - return new Result().ok("退出登录!"); + return new Result(); } /** diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java deleted file mode 100644 index 9296333cac..0000000000 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.epmet.common.token.enums; - - -import com.epmet.common.token.error.IErrorCode; - -/** - * client token错误码 - * - * @author rongchao - * @Date 18-11-24 - */ -public enum ErrorCode implements IErrorCode { - - SUCCESS(0, "请求成功"), - - ERR10001(10001, "token解析失败"), - ERR10002(10002, "token失效"), - ERR10003(10003, "token生成失败,请重试。"), - ERR10004(10004, "返回的Object类型不是EsuaResponse,无法添加token!"), - ERR10005(10005, "token不能为空"), - ERR10006(10006, "登录超时,请重新登录"), - ERR10007(10007, "当前帐号已在别处登录"), - - ERR500(500, "Internal Server Error"), - ERR501(501, "参数绑定异常"), - ERR401(401, "未授权"), - - - ERR(ErrorCode.COMMON_ERR_CODE, "其他异常"); - - private int code; - - private String msg; - - ErrorCode(final int code, final String msg) { - this.code = code; - this.msg = msg; - } - - public static final int COMMON_ERR_CODE = -1; - - @Override - public int getCode() { - return code; - } - - @Override - public String getMsg() { - return msg; - } -} diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/error/IErrorCode.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/error/IErrorCode.java deleted file mode 100644 index 9b58ccc96e..0000000000 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/error/IErrorCode.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.epmet.common.token.error; - -/** - * @author rongchao - * @Date 18-11-20 - */ -public interface IErrorCode { - int getCode(); - - String getMsg(); -} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index 230c53fbc8..0ddc89d09b 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -6,6 +6,11 @@ package com.epmet.commons.tools.exception; * @Description: */ public enum EpmetErrorCode { + ERR10005(10005, "token不能为空"), + ERR10006(10006, "登录超时,请重新登录"), + ERR10007(10007, "当前帐号已在别处登录"), + ERR401(401, "未授权"), + SERVER_ERROR(8000, "服务器开小差了..."), CANNOT_JOIN_GROUP(8001, "只有认证党员和居民才可以加入小组,请选择您的身份"), CANNOT_CREATE_GROUP(8002, "只有党员和热心居民才能创建小组,请选择您的身份"), diff --git a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java index ba348745d9..d3c7d60b6d 100644 --- a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java +++ b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java @@ -2,9 +2,9 @@ package com.epmet.filter; import com.alibaba.fastjson.JSON; -import com.epmet.common.token.enums.ErrorCode; import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.constant.Constant; +import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.BaseTokenDto; import com.epmet.commons.tools.security.dto.GovTokenDto; @@ -12,7 +12,6 @@ import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.CpUserDetailRedis; import com.epmet.commons.tools.utils.Result; import com.epmet.jwt.JwtTokenUtils; -import io.jsonwebtoken.Claims; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +32,6 @@ import reactor.core.publisher.Mono; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; -import java.util.function.Consumer; /** * app接口权限过滤器 @@ -90,7 +88,7 @@ public class CpAuthGatewayFilterFactory extends AbstractGatewayFilterFactory().error(ErrorCode.ERR10005.getCode(),ErrorCode.ERR10005.getMsg())); + return response(exchange,new Result<>().error(EpmetErrorCode.ERR10005.getCode(),EpmetErrorCode.ERR10005.getMsg())); } try { BaseTokenDto baseTokenDto = getBaseTokenDto(token, jwtTokenUtils); @@ -199,7 +197,7 @@ public class CpAuthGatewayFilterFactory extends AbstractGatewayFilterFactory customerIdList; } diff --git a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java index 87b1f0f38b..4beebeae8d 100644 --- a/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java +++ b/epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerController.java @@ -17,10 +17,7 @@ package com.epmet.controller; -import com.alibaba.fastjson.JSON; -import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.page.PageData; -import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ExcelUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.AssertUtils; @@ -133,8 +130,7 @@ public class CustomerController { * @Date 2020/3/11 21:58 **/ @GetMapping("getvalidcustomerlist") - public Result> getValidCustomerList(@LoginUser TokenDto tokenDTO) { - logger.info("getvalidcustomerlist:"+ JSON.toJSONString(tokenDTO)); + public Result> getValidCustomerList() { return customerService.getValidCustomerList(); } } diff --git a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/message/controller/UserMessageController.java b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/message/controller/UserMessageController.java index 217c08d278..e7d2ed2bf2 100644 --- a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/message/controller/UserMessageController.java +++ b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/message/controller/UserMessageController.java @@ -30,7 +30,7 @@ public class UserMessageController { /** * @param * @return com.epmet.commons.tools.utils.Result - * @Author yinzuomei + * @Author zhaoqifeng * @Description 查询我的消息 * @Date 2020/3/29 20:53 **/ @@ -39,33 +39,30 @@ public class UserMessageController { @RequestBody MymessageFormDTO mymessageFormDTO) { mymessageFormDTO.setUserId(tokenDto.getUserId()); ValidatorUtils.validateEntity(mymessageFormDTO); - //逻辑待实现 return userMessageService.getMessageList(tokenDto, mymessageFormDTO); } /** * @param fromDTO * @return com.epmet.commons.tools.utils.Result - * @Author yinzuomei + * @Author zhaoqifeng * @Description 单条消息标记为已读 * @Date 2020/3/29 21:05 **/ @PostMapping("readmsg") - public Result readMessage(@RequestBody ReadMessageFromDTO fromDTO) { - //逻辑待实现 + public Result readMessage(@LoginUser TokenDto tokenDto,@RequestBody ReadMessageFromDTO fromDTO) { return userMessageService.readMessage(fromDTO.getMessageId()); } /** * @param tokenDto * @return com.epmet.commons.tools.utils.Result - * @Author yinzuomei + * @Author zhaoqifeng * @Description 全部已读 * @Date 2020/3/29 21:06 **/ @PostMapping("readallmsg") public Result readAllMessage(@LoginUser TokenDto tokenDto, @RequestBody UserMessageDTO userMessageDTO) { - //逻辑待实现 return userMessageService.readAllMessage(tokenDto, userMessageDTO); } }