commonfield

This commit is contained in:
2023-03-02 17:02:10 +08:00
parent b0c884d210
commit e405dcb06a
3 changed files with 23 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ package com.cnbm.admin.base;
import com.alibaba.fastjson.JSON;
import com.cnbm.admin.dto.LoginUserDTO;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.enums.WhetherEnum;
import lombok.Builder;
import lombok.Data;
@@ -32,18 +33,18 @@ import java.time.LocalDateTime;
@Service
public class BaseSupport {
protected LoginUserDTO getLoginUser() {
protected LoginUser getLoginUser() {
// 后续完善拦截器再使用该方式
// LoginUser loginUser = loginUserHolder.get();
// if (loginUser != null) {
// return loginUser;
// }
HttpSession session = getHttpServletRequest().getSession(false);
LoginUserDTO loginUser = null;
LoginUser loginUser = null;
if (session != null) {
String loginUserJson = (String) session.getAttribute(LoginUserDTO.HTTP_HEADER_NAME);
String loginUserJson = (String) session.getAttribute(LoginUser.HTTP_HEADER_NAME);
if (StringUtils.isNotBlank(loginUserJson)) {
loginUser = JSON.parseObject(loginUserJson, LoginUserDTO.class);
loginUser = JSON.parseObject(loginUserJson, LoginUser.class);
return loginUser;
}
}
@@ -93,11 +94,11 @@ public class BaseSupport {
.enabled(WhetherEnum.YES.getValue())
.valid(WhetherEnum.YES.getValue())
.createTime(LocalDateTime.now())
.creatorId(getLoginUser().getUserId())
.creatorName(getLoginUser().getUserName())
.creatorId(getLoginUser().getSysUserEntity().getId())
.creatorName(getLoginUser().getUsername())
.updateTime(LocalDateTime.now())
.updaterId(getLoginUser().getUserId())
.updaterName(getLoginUser().getUserName())
.updaterId(getLoginUser().getSysUserEntity().getId())
.updaterName(getLoginUser().getUsername())
.build();
BeanUtils.copyProperties(commonField, t, ignoreProperties);
return t;
@@ -117,8 +118,8 @@ public class BaseSupport {
*/
public <T extends Serializable> T setUpdateCommonField(T t) {
CommonField commonField = CommonField.builder()
.updaterId(getLoginUser().getUserId())
.updaterName(getLoginUser().getUserName())
.updaterId(getLoginUser().getSysUserEntity().getId())
.updaterName(getLoginUser().getUsername())
.updateTime(LocalDateTime.now())
.build();
BeanUtils.copyProperties(commonField, t, "enabled", "valid");