yanyang #11
@ -43,6 +43,11 @@
|
|||||||
<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>
|
||||||
|
|
||||||
|
@ -5,18 +5,13 @@
|
|||||||
|
|
||||||
package com.cnbm.admin.base;
|
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 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;
|
||||||
@ -26,10 +21,6 @@ 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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口支持基类
|
* 接口支持基类
|
||||||
@ -41,19 +32,40 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Service
|
@Service
|
||||||
public class BaseSupport {
|
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
|
* @return
|
||||||
*/
|
*/
|
||||||
protected LoginUser getLoginUser() {
|
protected HttpServletRequest getHttpServletRequest() {
|
||||||
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||||
|
}
|
||||||
|
|
||||||
if (Objects.isNull(authentication)) {
|
/**
|
||||||
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
* 获取当前http响应对象
|
||||||
return loginUser;
|
*
|
||||||
}
|
* @return
|
||||||
return null;
|
*/
|
||||||
|
protected HttpServletResponse getHttpServletResponse() {
|
||||||
|
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -81,11 +93,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().getSysUserEntity().getId())
|
.creatorId(getLoginUser().getUserId())
|
||||||
.creatorName(getLoginUser().getUsername())
|
.creatorName(getLoginUser().getUserName())
|
||||||
.updateTime(LocalDateTime.now())
|
.updateTime(LocalDateTime.now())
|
||||||
.updaterId(getLoginUser().getSysUserEntity().getId())
|
.updaterId(getLoginUser().getUserId())
|
||||||
.updaterName(getLoginUser().getUsername())
|
.updaterName(getLoginUser().getUserName())
|
||||||
.build();
|
.build();
|
||||||
BeanUtils.copyProperties(commonField, t, ignoreProperties);
|
BeanUtils.copyProperties(commonField, t, ignoreProperties);
|
||||||
return t;
|
return t;
|
||||||
@ -105,8 +117,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().getSysUserEntity().getId())
|
.updaterId(getLoginUser().getUserId())
|
||||||
.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");
|
||||||
|
65
ym-admin/src/main/java/com/cnbm/admin/dto/LoginUserDTO.java
Normal file
65
ym-admin/src/main/java/com/cnbm/admin/dto/LoginUserDTO.java
Normal file
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user