Compare commits

..

No commits in common. "b0c884d2100d6d4513a167b0d465faaa4d2e7c15" and "df44cf308ff1b020827436d8cca15f74b9cc3c48" have entirely different histories.

3 changed files with 28 additions and 110 deletions

View File

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

View File

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

View File

@ -1,65 +0,0 @@
/*
* 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;
}