Merge pull request 'yanyang' (#11) from yanyang into master

Reviewed-on: #11
This commit is contained in:
闫阳 2023-03-02 15:14:45 +08:00
förälder 3167ad09c4 b0c884d210
incheckning 458cedb42f
3 ändrade filer med 107 tillägg och 25 borttagningar

Visa fil

@ -43,6 +43,11 @@
<artifactId>ym-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
</dependencies>

Visa fil

@ -5,18 +5,13 @@
package com.cnbm.admin.base;
import com.cnbm.admin.entity.LoginUser;
import com.alibaba.fastjson.JSON;
import com.cnbm.admin.dto.LoginUserDTO;
import com.cnbm.admin.enums.WhetherEnum;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.NamedThreadLocal;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@ -26,10 +21,6 @@ import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
* 接口支持基类
@ -41,19 +32,40 @@ import java.util.concurrent.TimeUnit;
@Service
public class BaseSupport {
protected LoginUserDTO getLoginUser() {
// 后续完善拦截器再使用该方式
// LoginUser loginUser = loginUserHolder.get();
// if (loginUser != null) {
// return loginUser;
// }
HttpSession session = getHttpServletRequest().getSession(false);
LoginUserDTO loginUser = null;
if (session != null) {
String loginUserJson = (String) session.getAttribute(LoginUserDTO.HTTP_HEADER_NAME);
if (StringUtils.isNotBlank(loginUserJson)) {
loginUser = JSON.parseObject(loginUserJson, LoginUserDTO.class);
return loginUser;
}
}
return null;
}
/**
* 获取当前登录用户信息
* 获取当前http请求对象
*
* @return
*/
protected LoginUser getLoginUser() {
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
protected HttpServletRequest getHttpServletRequest() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}
if (Objects.isNull(authentication)) {
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
return loginUser;
}
return null;
/**
* 获取当前http响应对象
*
* @return
*/
protected HttpServletResponse getHttpServletResponse() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
}
@ -81,11 +93,11 @@ public class BaseSupport {
.enabled(WhetherEnum.YES.getValue())
.valid(WhetherEnum.YES.getValue())
.createTime(LocalDateTime.now())
.creatorId(getLoginUser().getSysUserEntity().getId())
.creatorName(getLoginUser().getUsername())
.creatorId(getLoginUser().getUserId())
.creatorName(getLoginUser().getUserName())
.updateTime(LocalDateTime.now())
.updaterId(getLoginUser().getSysUserEntity().getId())
.updaterName(getLoginUser().getUsername())
.updaterId(getLoginUser().getUserId())
.updaterName(getLoginUser().getUserName())
.build();
BeanUtils.copyProperties(commonField, t, ignoreProperties);
return t;
@ -105,8 +117,8 @@ public class BaseSupport {
*/
public <T extends Serializable> T setUpdateCommonField(T t) {
CommonField commonField = CommonField.builder()
.updaterId(getLoginUser().getSysUserEntity().getId())
.updaterName(getLoginUser().getUsername())
.updaterId(getLoginUser().getUserId())
.updaterName(getLoginUser().getUserName())
.updateTime(LocalDateTime.now())
.build();
BeanUtils.copyProperties(commonField, t, "enabled", "valid");

Visa fil

@ -0,0 +1,65 @@
/*
* Copyright (c) 2018.
* http://www.ulabcare.com
*/
package com.cnbm.admin.dto;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* @author jiff
* @date 2018/11/1
* @since 1.0
*/
@EqualsAndHashCode(callSuper = false)
@Builder
@Data
@Accessors(chain = true)
public class LoginUserDTO implements Serializable {
public static final String HTTP_HEADER_NAME = "loginUser";
public static final int USER_TYPE_PLATFORM = 1;
public static final int USER_TYPE_PARTNER = 2;
public static final int USER_TYPE_HOSPITAL = 3;
public static final int USER_TYPE_PATIENT = 4;
/**
* 会话ID
*/
private String sessionId;
private Long passportUserId;
private Long userId;
private Long partnerId;
private Long hospitalId;
private Long orgId;
private String mobile;
private String userName;
/**
* 用户类型
*/
private int userType;
/**
* 应用类型
*/
private int appType;
/**
* 应用代码
*/
private int appCode;
/**
* 登录类型1自主登录2漫游登录
*/
private int loginType;
/**
* 微信appId
*/
private String wechatAppId;
/**
* 微信openId
*/
private String openId;
}