Showing
9 changed files
with
145 additions
and
9 deletions
| ... | @@ -6,7 +6,9 @@ import com.infoloop.tianting.intercepter.ApiSignInterceptor; | ... | @@ -6,7 +6,9 @@ import com.infoloop.tianting.intercepter.ApiSignInterceptor; |
| 6 | import com.infoloop.tianting.intercepter.LoginInterceptor; | 6 | import com.infoloop.tianting.intercepter.LoginInterceptor; |
| 7 | import com.infoloop.tianting.intercepter.RequestMonitor; | 7 | import com.infoloop.tianting.intercepter.RequestMonitor; |
| 8 | import com.infoloop.tianting.intercepter.ResourceInjector; | 8 | import com.infoloop.tianting.intercepter.ResourceInjector; |
| 9 | +import com.infoloop.tianting.service.client.ClientCustomerServiceRpcClient; | ||
| 9 | import com.infoloop.tianting.tracing.HttpTracingInterceptor; | 10 | import com.infoloop.tianting.tracing.HttpTracingInterceptor; |
| 11 | +import lombok.RequiredArgsConstructor; | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.boot.web.servlet.FilterRegistrationBean; | 13 | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| 12 | import org.springframework.context.annotation.Bean; | 14 | import org.springframework.context.annotation.Bean; |
| ... | @@ -30,12 +32,13 @@ public class WebMvcConfig implements WebMvcConfigurer { | ... | @@ -30,12 +32,13 @@ public class WebMvcConfig implements WebMvcConfigurer { |
| 30 | 32 | ||
| 31 | @Autowired | 33 | @Autowired |
| 32 | public WebMvcConfig(final Tracing tracing, | 34 | public WebMvcConfig(final Tracing tracing, |
| 33 | - final ResourceInjector resourceInjector) { | 35 | + final ResourceInjector resourceInjector, |
| 36 | + final ClientCustomerServiceRpcClient clientCustomerServiceRpcClient) { | ||
| 34 | this.httpInterceptors = new ArrayList<>(); | 37 | this.httpInterceptors = new ArrayList<>(); |
| 35 | this.httpInterceptors.add(new HttpTracingInterceptor(tracing)); | 38 | this.httpInterceptors.add(new HttpTracingInterceptor(tracing)); |
| 36 | this.httpInterceptors.add(new RequestMonitor()); | 39 | this.httpInterceptors.add(new RequestMonitor()); |
| 37 | this.httpInterceptors.add(new ApiSignInterceptor()); | 40 | this.httpInterceptors.add(new ApiSignInterceptor()); |
| 38 | - this.httpInterceptors.add(new LoginInterceptor()); | 41 | + this.httpInterceptors.add(new LoginInterceptor(clientCustomerServiceRpcClient)); |
| 39 | this.httpInterceptors.add(resourceInjector); | 42 | this.httpInterceptors.add(resourceInjector); |
| 40 | 43 | ||
| 41 | } | 44 | } |
| ... | @@ -75,6 +78,7 @@ public class WebMvcConfig implements WebMvcConfigurer { | ... | @@ -75,6 +78,7 @@ public class WebMvcConfig implements WebMvcConfigurer { |
| 75 | final var registrationBean = new FilterRegistrationBean<HttpServletRequestWrapperFilter>(); | 78 | final var registrationBean = new FilterRegistrationBean<HttpServletRequestWrapperFilter>(); |
| 76 | registrationBean.setFilter(new HttpServletRequestWrapperFilter()); | 79 | registrationBean.setFilter(new HttpServletRequestWrapperFilter()); |
| 77 | registrationBean.addUrlPatterns("/*"); | 80 | registrationBean.addUrlPatterns("/*"); |
| 81 | + registrationBean.addUrlPatterns(); | ||
| 78 | return registrationBean; | 82 | return registrationBean; |
| 79 | } | 83 | } |
| 80 | } | 84 | } | ... | ... |
| 1 | package com.infoloop.tianting.controller; | 1 | package com.infoloop.tianting.controller; |
| 2 | 2 | ||
| 3 | +import cn.dev33.satoken.annotation.SaIgnore; | ||
| 4 | +import cn.dev33.satoken.stp.SaTokenInfo; | ||
| 3 | import com.github.xiaoymin.knife4j.annotations.ApiSupport; | 5 | import com.github.xiaoymin.knife4j.annotations.ApiSupport; |
| 4 | import com.infoloop.tianting.model.dto.ClientCustomerDbDTO.ClientCustomerDto; | 6 | import com.infoloop.tianting.model.dto.ClientCustomerDbDTO.ClientCustomerDto; |
| 5 | import com.infoloop.tianting.model.dto.ClientCustomerDbDTO.HospitalRecordDto; | 7 | import com.infoloop.tianting.model.dto.ClientCustomerDbDTO.HospitalRecordDto; |
| 8 | +import com.infoloop.tianting.model.dto.PermissionDTO.LoginDto; | ||
| 6 | import com.infoloop.tianting.model.dto.WxUserDto.WxUserOpenIdDto; | 9 | import com.infoloop.tianting.model.dto.WxUserDto.WxUserOpenIdDto; |
| 7 | import com.infoloop.tianting.model.dto.WxUserDto.WxUserPhoneResponseDto; | 10 | import com.infoloop.tianting.model.dto.WxUserDto.WxUserPhoneResponseDto; |
| 8 | import com.infoloop.tianting.service.ClientCustomerService; | 11 | import com.infoloop.tianting.service.ClientCustomerService; |
| 12 | +import com.infoloop.tianting.service.LoginService; | ||
| 9 | import com.infoloop.tianting.service.WxMiniProgramService; | 13 | import com.infoloop.tianting.service.WxMiniProgramService; |
| 10 | import io.swagger.annotations.Api; | 14 | import io.swagger.annotations.Api; |
| 11 | import io.swagger.annotations.ApiOperation; | 15 | import io.swagger.annotations.ApiOperation; |
| 12 | import java.util.List; | 16 | import java.util.List; |
| 17 | +import javax.validation.Valid; | ||
| 13 | import lombok.RequiredArgsConstructor; | 18 | import lombok.RequiredArgsConstructor; |
| 14 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
| 15 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | @@ -17,6 +22,8 @@ import org.springframework.http.HttpStatus; | ... | @@ -17,6 +22,8 @@ import org.springframework.http.HttpStatus; |
| 17 | import org.springframework.validation.annotation.Validated; | 22 | import org.springframework.validation.annotation.Validated; |
| 18 | import org.springframework.web.bind.annotation.GetMapping; | 23 | import org.springframework.web.bind.annotation.GetMapping; |
| 19 | import org.springframework.web.bind.annotation.PathVariable; | 24 | import org.springframework.web.bind.annotation.PathVariable; |
| 25 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 26 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 20 | import org.springframework.web.bind.annotation.ResponseStatus; | 27 | import org.springframework.web.bind.annotation.ResponseStatus; |
| 21 | import org.springframework.web.bind.annotation.RestController; | 28 | import org.springframework.web.bind.annotation.RestController; |
| 22 | 29 | ||
| ... | @@ -29,6 +36,7 @@ import org.springframework.web.bind.annotation.RestController; | ... | @@ -29,6 +36,7 @@ import org.springframework.web.bind.annotation.RestController; |
| 29 | public class ClientCustomerController { | 36 | public class ClientCustomerController { |
| 30 | private final ClientCustomerService clientCustomerService; | 37 | private final ClientCustomerService clientCustomerService; |
| 31 | private final WxMiniProgramService wxMiniProgramService; | 38 | private final WxMiniProgramService wxMiniProgramService; |
| 39 | + private final LoginService loginService; | ||
| 32 | 40 | ||
| 33 | @ApiOperation(value = "根据hisCustomerId获取ClientCustomer") | 41 | @ApiOperation(value = "根据hisCustomerId获取ClientCustomer") |
| 34 | @GetMapping("/customers/his/{hisCustomerId}") | 42 | @GetMapping("/customers/his/{hisCustomerId}") |
| ... | @@ -67,4 +75,12 @@ public class ClientCustomerController { | ... | @@ -67,4 +75,12 @@ public class ClientCustomerController { |
| 67 | return wxMiniProgramService.getUserPhoneInfoByCode(code); | 75 | return wxMiniProgramService.getUserPhoneInfoByCode(code); |
| 68 | } | 76 | } |
| 69 | 77 | ||
| 78 | + @SaIgnore | ||
| 79 | + @ApiOperation(value = "登陆") | ||
| 80 | + @PostMapping("/login") | ||
| 81 | + @ResponseStatus(HttpStatus.OK) | ||
| 82 | + public SaTokenInfo login(@Valid@RequestBody LoginDto loginDto) { | ||
| 83 | + return loginService.login(loginDto); | ||
| 84 | + } | ||
| 85 | + | ||
| 70 | } | 86 | } | ... | ... |
| 1 | +package com.infoloop.tianting.enums; | ||
| 2 | + | ||
| 3 | +import com.infoloop.tianting.exception.BaseEnum; | ||
| 4 | +import lombok.AllArgsConstructor; | ||
| 5 | +import lombok.Getter; | ||
| 6 | + | ||
| 7 | +@Getter | ||
| 8 | +@AllArgsConstructor | ||
| 9 | +public enum LoginSourceEnum{ | ||
| 10 | + CUSTOMER(1, "小程序住院客户"), | ||
| 11 | + MINI_PROGRAM(2, "小程序非住院客户"), | ||
| 12 | + CLIENT(3, "院区端"), | ||
| 13 | + KDS(4, "KDS"), | ||
| 14 | + ; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 订单类型的值 | ||
| 18 | + */ | ||
| 19 | + private final Integer value; | ||
| 20 | + /** | ||
| 21 | + * 订单类型的名字 | ||
| 22 | + */ | ||
| 23 | + private final String name; | ||
| 24 | +} |
| ... | @@ -3,13 +3,21 @@ package com.infoloop.tianting.intercepter; | ... | @@ -3,13 +3,21 @@ package com.infoloop.tianting.intercepter; |
| 3 | import cn.dev33.satoken.annotation.SaIgnore; | 3 | import cn.dev33.satoken.annotation.SaIgnore; |
| 4 | import cn.dev33.satoken.error.SaErrorCode; | 4 | import cn.dev33.satoken.error.SaErrorCode; |
| 5 | import cn.dev33.satoken.exception.SaTokenException; | 5 | import cn.dev33.satoken.exception.SaTokenException; |
| 6 | +import cn.dev33.satoken.stp.StpUtil; | ||
| 6 | import cn.dev33.satoken.strategy.SaStrategy; | 7 | import cn.dev33.satoken.strategy.SaStrategy; |
| 8 | +import cn.hutool.core.convert.Convert; | ||
| 9 | +import com.infoloop.tianting.constant.CommonConstants; | ||
| 7 | import com.infoloop.tianting.context.LoginContextHolder; | 10 | import com.infoloop.tianting.context.LoginContextHolder; |
| 11 | +import com.infoloop.tianting.enums.LoginSourceEnum; | ||
| 8 | import com.infoloop.tianting.exception.ErrorCodeEnum; | 12 | import com.infoloop.tianting.exception.ErrorCodeEnum; |
| 9 | import com.infoloop.tianting.model.common.ResponseResult; | 13 | import com.infoloop.tianting.model.common.ResponseResult; |
| 14 | +import com.infoloop.tianting.service.ClientCustomerService; | ||
| 15 | +import com.infoloop.tianting.service.client.ClientCustomerServiceRpcClient; | ||
| 10 | import com.infoloop.tianting.utils.ResponseUtil; | 16 | import com.infoloop.tianting.utils.ResponseUtil; |
| 11 | import lombok.RequiredArgsConstructor; | 17 | import lombok.RequiredArgsConstructor; |
| 12 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
| 19 | +import org.apache.tomcat.jni.Error; | ||
| 20 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 13 | import org.springframework.http.HttpStatus; | 21 | import org.springframework.http.HttpStatus; |
| 14 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
| 15 | import org.springframework.web.method.HandlerMethod; | 23 | import org.springframework.web.method.HandlerMethod; |
| ... | @@ -24,6 +32,8 @@ import java.io.IOException; | ... | @@ -24,6 +32,8 @@ import java.io.IOException; |
| 24 | @SuppressWarnings("all") | 32 | @SuppressWarnings("all") |
| 25 | @RequiredArgsConstructor | 33 | @RequiredArgsConstructor |
| 26 | public class LoginInterceptor extends HandlerInterceptorAdapter { | 34 | public class LoginInterceptor extends HandlerInterceptorAdapter { |
| 35 | +// private final ClientCustomerService clientCustomerService; | ||
| 36 | + private final ClientCustomerServiceRpcClient clientCustomerServiceRpcClient; | ||
| 27 | 37 | ||
| 28 | @Override | 38 | @Override |
| 29 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { | 39 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { |
| ... | @@ -52,13 +62,20 @@ public class LoginInterceptor extends HandlerInterceptorAdapter { | ... | @@ -52,13 +62,20 @@ public class LoginInterceptor extends HandlerInterceptorAdapter { |
| 52 | 62 | ||
| 53 | 63 | ||
| 54 | private boolean handleLogin(HttpServletRequest request, HttpServletResponse response, LoginContextHolder.LoginInfo.LoginInfoBuilder builder) throws SaTokenException { | 64 | private boolean handleLogin(HttpServletRequest request, HttpServletResponse response, LoginContextHolder.LoginInfo.LoginInfoBuilder builder) throws SaTokenException { |
| 55 | -// StpUtil.checkLogin(); | 65 | + StpUtil.checkLogin(); |
| 56 | -// final var loginId = StpUtil.getLoginIdAsInt(); | 66 | + final var loginId = StpUtil.getLoginIdAsInt(); |
| 57 | -// final var enterpriseId = Convert.toInt(StpUtil.getExtra(CommonConstants.ENTERPRISE_ID)); | 67 | + final var enterpriseId = Convert.toInt(StpUtil.getExtra(CommonConstants.ENTERPRISE_ID)); |
| 58 | - //TODO: 校验登录,获取登录用户信息,注入登录用户上下文信息 | 68 | + final var loginSource = Convert.toInt(StpUtil.getExtra(CommonConstants.LOGIN_SOURCE)); |
| 59 | - builder.id(1) | 69 | +// if (loginSource.equals(LoginSourceEnum.CUSTOMER.getValue())) { |
| 60 | - .enterpriseId(1) | 70 | + final var customer = clientCustomerServiceRpcClient.getClientCustomerById(loginId); |
| 61 | - .name("admin"); | 71 | + if (customer == null) { |
| 72 | + response.setStatus(HttpStatus.FORBIDDEN.value()); | ||
| 73 | + ResponseUtil.write(response, ResponseResult.failed(ErrorCodeEnum.VALIDATE_FAILED)); | ||
| 74 | + return false; | ||
| 75 | + } | ||
| 76 | + builder.id(loginId) | ||
| 77 | + .enterpriseId(enterpriseId) | ||
| 78 | + .name(customer.getResponse().getName()); | ||
| 62 | return true; | 79 | return true; |
| 63 | } | 80 | } |
| 64 | 81 | ... | ... |
| 1 | +package com.infoloop.tianting.model.dto; | ||
| 2 | + | ||
| 3 | +import com.infoloop.tianting.enums.LoginSourceEnum; | ||
| 4 | +import io.swagger.annotations.ApiModel; | ||
| 5 | +import lombok.Builder; | ||
| 6 | +import lombok.Data; | ||
| 7 | + | ||
| 8 | +@Data | ||
| 9 | +@ApiModel(description = "权限相关DTO") | ||
| 10 | +public class PermissionDTO { | ||
| 11 | + | ||
| 12 | + @Data | ||
| 13 | + @Builder | ||
| 14 | + @ApiModel(description = "Login DTO") | ||
| 15 | + public static class LoginDto { | ||
| 16 | + private LoginSourceEnum loginSourceEnum; | ||
| 17 | + private String hisCustomerId; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | +} |
| ... | @@ -9,6 +9,8 @@ import com.infoloop.tianting.clientcustomerservice.DeleteClientCustomerLabelRefs | ... | @@ -9,6 +9,8 @@ import com.infoloop.tianting.clientcustomerservice.DeleteClientCustomerLabelRefs |
| 9 | import com.infoloop.tianting.clientcustomerservice.DeleteClientCustomerLabelRefsRpcResponse; | 9 | import com.infoloop.tianting.clientcustomerservice.DeleteClientCustomerLabelRefsRpcResponse; |
| 10 | import com.infoloop.tianting.clientcustomerservice.GetClientCustomerByHISCustomerIdRpcRequest; | 10 | import com.infoloop.tianting.clientcustomerservice.GetClientCustomerByHISCustomerIdRpcRequest; |
| 11 | import com.infoloop.tianting.clientcustomerservice.GetClientCustomerByHISCustomerIdRpcResponse; | 11 | import com.infoloop.tianting.clientcustomerservice.GetClientCustomerByHISCustomerIdRpcResponse; |
| 12 | +import com.infoloop.tianting.clientcustomerservice.GetClientCustomerByIdRpcRequest; | ||
| 13 | +import com.infoloop.tianting.clientcustomerservice.GetClientCustomerByIdRpcResponse; | ||
| 12 | import com.infoloop.tianting.clientcustomerservice.GetClientCustomerByMobileRpcRequest; | 14 | import com.infoloop.tianting.clientcustomerservice.GetClientCustomerByMobileRpcRequest; |
| 13 | import com.infoloop.tianting.clientcustomerservice.GetClientCustomerByMobileRpcResponse; | 15 | import com.infoloop.tianting.clientcustomerservice.GetClientCustomerByMobileRpcResponse; |
| 14 | import com.infoloop.tianting.clientcustomerservice.GetClientCustomerHospitalRecordsByCustomerIdRpcRequest; | 16 | import com.infoloop.tianting.clientcustomerservice.GetClientCustomerHospitalRecordsByCustomerIdRpcRequest; |
| ... | @@ -40,6 +42,11 @@ public class ClientCustomerServiceRpcClient { | ... | @@ -40,6 +42,11 @@ public class ClientCustomerServiceRpcClient { |
| 40 | return clientCustomerServiceRpcBlockingStub.getClientCustomerByHISCustomerId(request); | 42 | return clientCustomerServiceRpcBlockingStub.getClientCustomerByHISCustomerId(request); |
| 41 | } | 43 | } |
| 42 | 44 | ||
| 45 | + public GetClientCustomerByIdRpcResponse getClientCustomerById(Integer id) { | ||
| 46 | + final var request = GetClientCustomerByIdRpcRequest.newBuilder().setId(id).build(); | ||
| 47 | + return clientCustomerServiceRpcBlockingStub.getClientCustomerById(request); | ||
| 48 | + } | ||
| 49 | + | ||
| 43 | public GetClientCustomerByMobileRpcResponse getClientCustomerByMobile(String phone) { | 50 | public GetClientCustomerByMobileRpcResponse getClientCustomerByMobile(String phone) { |
| 44 | final var request = GetClientCustomerByMobileRpcRequest.newBuilder() | 51 | final var request = GetClientCustomerByMobileRpcRequest.newBuilder() |
| 45 | .setMobile(phone) | 52 | .setMobile(phone) | ... | ... |
| 1 | +package com.infoloop.tianting.service.impl; | ||
| 2 | + | ||
| 3 | +import cn.dev33.satoken.stp.SaLoginModel; | ||
| 4 | +import cn.dev33.satoken.stp.SaTokenInfo; | ||
| 5 | +import cn.dev33.satoken.stp.StpUtil; | ||
| 6 | +import com.infoloop.tianting.constant.CommonConstants; | ||
| 7 | +import com.infoloop.tianting.exception.ClientEndExceptions; | ||
| 8 | +import com.infoloop.tianting.exception.ErrorCodeEnum; | ||
| 9 | +import com.infoloop.tianting.model.dto.PermissionDTO.LoginDto; | ||
| 10 | +import com.infoloop.tianting.service.ClientCustomerService; | ||
| 11 | +import com.infoloop.tianting.service.LoginService; | ||
| 12 | +import com.infoloop.tianting.service.client.ClientCustomerServiceRpcClient; | ||
| 13 | +import lombok.RequiredArgsConstructor; | ||
| 14 | +import lombok.extern.slf4j.Slf4j; | ||
| 15 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 16 | +import org.springframework.stereotype.Service; | ||
| 17 | + | ||
| 18 | +@Slf4j | ||
| 19 | +@Service | ||
| 20 | +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) | ||
| 21 | +public class LoginServiceImpl implements LoginService { | ||
| 22 | + | ||
| 23 | + private final ClientCustomerServiceRpcClient clientCustomerServiceRpcClient; | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public SaTokenInfo login(LoginDto loginDto) { | ||
| 27 | + final var customer = clientCustomerServiceRpcClient.getClientCustomerByHISCustomerId(loginDto.getHisCustomerId()); | ||
| 28 | + if (customer.getResponse().getId() == 0) { | ||
| 29 | + throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.UNAUTHORIZED.name()); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + StpUtil.login(customer.getResponse().getId(), SaLoginModel.create() | ||
| 33 | + .setExtra(CommonConstants.ENTERPRISE_ID, customer.getResponse().getEnterpriseId()) | ||
| 34 | + .setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue()) | ||
| 35 | + .build()); | ||
| 36 | + return StpUtil.getTokenInfo(); | ||
| 37 | + } | ||
| 38 | +} | ||
| 39 | + |
-
Please register or login to post a comment