From 48ecde6caab92b250c396e10d3b986916c29aff4 Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Tue, 20 Apr 2021 23:51:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=95=B4=E5=90=88sentinel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ums/controller/app/AddressController.java | 15 ++++++++------- .../component/CustomBlockExceptionHandler.java | 7 +++++-- .../com/youlai/admin/mapper/SysUserMapper.java | 2 +- .../auth/service/UserDetailsServiceImpl.java | 10 +++++----- .../src/main/resources/bootstrap-dev.yml | 2 +- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/mall-ums/ums-boot/src/main/java/com/youlai/mall/ums/controller/app/AddressController.java b/mall-ums/ums-boot/src/main/java/com/youlai/mall/ums/controller/app/AddressController.java index 8c73d1120..2692182d9 100644 --- a/mall-ums/ums-boot/src/main/java/com/youlai/mall/ums/controller/app/AddressController.java +++ b/mall-ums/ums-boot/src/main/java/com/youlai/mall/ums/controller/app/AddressController.java @@ -28,9 +28,10 @@ public class AddressController { private final Integer ADDRESS_DEFAULTED = 1; - @ApiOperation(value = "获取会员的地址列表") + @ApiOperation(value = "获取登录会员的地址列表") @GetMapping - public Result list(@RequestParam(required = false) Long memberId) { + public Result list() { + Long memberId = RequestUtils.getUserId(); List addressList = iUmsAddressService.list(new LambdaQueryWrapper() .eq(UmsAddress::getMemberId, memberId) .orderByDesc(UmsAddress::getDefaulted)); @@ -42,11 +43,11 @@ public class AddressController { @ApiImplicitParam(name = "address", value = "实体JSON对象", required = true, paramType = "body", dataType = "UmsAddress") @PostMapping public Result add(@RequestBody UmsAddress address) { - Long userId = RequestUtils.getUserId(); - address.setMemberId(userId); + Long memberId = RequestUtils.getUserId(); + address.setMemberId(memberId); if (ADDRESS_DEFAULTED.equals(address.getDefaulted())) { // 修改其他默认地址为非默认 iUmsAddressService.update(new LambdaUpdateWrapper() - .eq(UmsAddress::getMemberId, userId) + .eq(UmsAddress::getMemberId, memberId) .eq(UmsAddress::getDefaulted, 1) .set(UmsAddress::getDefaulted, 0) ); @@ -65,10 +66,10 @@ public class AddressController { public Result update( @PathVariable Long id, @RequestBody UmsAddress address) { - Long userId = RequestUtils.getUserId(); + Long memberId = RequestUtils.getUserId(); if (address.getDefaulted().equals(1)) { // 修改其他默认地址为非默认 iUmsAddressService.update(new LambdaUpdateWrapper() - .eq(UmsAddress::getMemberId, userId) + .eq(UmsAddress::getMemberId, memberId) .eq(UmsAddress::getDefaulted, 1) .set(UmsAddress::getDefaulted, 0) ); diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/CustomBlockExceptionHandler.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/CustomBlockExceptionHandler.java index 5ec7422d6..ef25b9fe8 100644 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/CustomBlockExceptionHandler.java +++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/CustomBlockExceptionHandler.java @@ -14,7 +14,7 @@ import javax.servlet.http.HttpServletResponse; /** * @author haoxr - * @description TODO + * @description 自定义流控异常 * @createTime 2021/4/12 22:57 */ @Component @@ -26,8 +26,11 @@ public class CustomBlockExceptionHandler implements BlockExceptionHandler { response.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=utf-8"); + ObjectMapper objectMapper = new ObjectMapper(); + if(e instanceof FlowException){ - new ObjectMapper().writeValue(response.getWriter(), Result.failed(ResultCode.FLOW_LIMITING)); + // objectMapper.writeValue 用于将java对象转位JSON格式返回调用方 + objectMapper.writeValue(response.getWriter(), Result.failed(ResultCode.FLOW_LIMITING)); } } } diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java index 7b09d8001..c17970ee0 100644 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java +++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java @@ -20,7 +20,7 @@ public interface SysUserMapper extends BaseMapper { " left join sys_dept d on u.dept_id= d.id " + " left join sys_user_role ur on u.id=ur.user_id " + " left join sys_role r on ur.role_id=r.id " + - " where 1=1 " + + " where deleted != 1 " + " " + " and u.username like concat('%',#{user.username},'%')" + " " + diff --git a/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java b/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java index fac6d7a65..b7b7b44c8 100644 --- a/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java +++ b/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java @@ -1,15 +1,15 @@ package com.youlai.auth.service; -import com.youlai.admin.pojo.dto.UserDTO; import com.youlai.admin.api.UserFeignService; +import com.youlai.admin.pojo.dto.UserDTO; import com.youlai.auth.domain.User; import com.youlai.common.constant.AuthConstants; import com.youlai.common.result.Result; import com.youlai.common.result.ResultCode; import com.youlai.common.web.exception.BizException; import com.youlai.common.web.util.RequestUtils; -import com.youlai.mall.ums.pojo.dto.AuthMemberDTO; import com.youlai.mall.ums.api.UmsMemberFeignService; +import com.youlai.mall.ums.pojo.dto.AuthMemberDTO; import lombok.AllArgsConstructor; import org.springframework.security.authentication.AccountExpiredException; import org.springframework.security.authentication.DisabledException; @@ -43,7 +43,7 @@ public class UserDetailsServiceImpl implements UserDetailsService { UserDTO userDTO = (UserDTO) result.getData(); user = new User(userDTO); } else { - throw new BizException(ResultCode.getValue(result.getCode())); + throw new BizException(result.getMsg()); } break; case AuthConstants.WEAPP_CLIENT_ID: // 小程序会员 @@ -51,8 +51,8 @@ public class UserDetailsServiceImpl implements UserDetailsService { if (ResultCode.SUCCESS.getCode().equals(result.getCode())) { AuthMemberDTO authMemberDTO = (AuthMemberDTO) result.getData(); user = new User(authMemberDTO); - } else { - throw new BizException(ResultCode.getValue(result.getCode())); + } else { + throw new BizException(result.getMsg()); } break; } diff --git a/youlai-gateway/src/main/resources/bootstrap-dev.yml b/youlai-gateway/src/main/resources/bootstrap-dev.yml index 78a7ea0ec..74118fdbd 100644 --- a/youlai-gateway/src/main/resources/bootstrap-dev.yml +++ b/youlai-gateway/src/main/resources/bootstrap-dev.yml @@ -14,7 +14,7 @@ spring: server-addr: ${spring.cloud.nacos.discovery.server-addr} file-extension: yaml sentinel: - enabled: false + enabled: false # 网关流控开关 eager: true # 取消控制台懒加载,项目启动即连接Sentinel transport: client-ip: localhost