Merge branch 'develop' of http://139.196.179.195:3000/chenxudong/electromagnetic-data-new into develop
This commit is contained in:
commit
ad2f822dca
|
|
@ -6,6 +6,7 @@ import cn.hutool.json.JSONUtil;
|
||||||
import com.electromagnetic.industry.software.common.annotations.UserOperation;
|
import com.electromagnetic.industry.software.common.annotations.UserOperation;
|
||||||
import com.electromagnetic.industry.software.common.cons.UserConstants;
|
import com.electromagnetic.industry.software.common.cons.UserConstants;
|
||||||
import com.electromagnetic.industry.software.common.enums.AdminTypeEnum;
|
import com.electromagnetic.industry.software.common.enums.AdminTypeEnum;
|
||||||
|
import com.electromagnetic.industry.software.common.pojo.AccessSuccessInfo;
|
||||||
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
|
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.IdWorker;
|
||||||
|
|
@ -26,6 +27,7 @@ import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
|
@ -134,37 +136,40 @@ public class LoginInterceptor implements HandlerInterceptor {
|
||||||
String reqArgs = UserThreadLocal.getReqArgs();
|
String reqArgs = UserThreadLocal.getReqArgs();
|
||||||
|
|
||||||
UserLoginInfo user = Optional.of(UserThreadLocal.getUser()).orElse(new UserLoginInfo());
|
UserLoginInfo user = Optional.of(UserThreadLocal.getUser()).orElse(new UserLoginInfo());
|
||||||
|
List<AccessSuccessInfo> successInfoList = user.getSuccessInfoList();
|
||||||
|
for (AccessSuccessInfo accessSuccessInfo : successInfoList) {
|
||||||
|
UserAccessLog userAccessLog = new UserAccessLog()
|
||||||
|
.setId(IdWorker.getSnowFlakeIdString())
|
||||||
|
.setUserId(user.getUserId())
|
||||||
|
.setAccessStartTime(DateUtil.date(accessStartTime))
|
||||||
|
.setAccessEndTime(DateUtil.date(accessEndTime))
|
||||||
|
.setAccessDuration(accessEndTime - accessStartTime)
|
||||||
|
.setAction(userOperation.value())
|
||||||
|
.setRequestUrl(request.getRequestURL().toString())
|
||||||
|
.setRequestIp(parseIpFromUrl(request.getRequestURL().toString()))
|
||||||
|
.setReqArgs(reqArgs)
|
||||||
|
.setRemoteAddr(getRealIp(request))
|
||||||
|
.setAccessSuccess(true)
|
||||||
|
.setCreateTime(new Date())
|
||||||
|
.setOperationModule(userOperation.modelName().key)
|
||||||
|
.setOperationMsg(accessSuccessInfo.getSuccessMsg())
|
||||||
|
.setDataId(accessSuccessInfo.getDataId())
|
||||||
|
.setParentId(accessSuccessInfo.getParentId());
|
||||||
|
|
||||||
UserAccessLog userAccessLog = new UserAccessLog()
|
ElectromagneticResult<?> result = user.getResult();
|
||||||
.setId(IdWorker.getSnowFlakeIdString())
|
if (result != null) {
|
||||||
.setUserId(user.getUserId())
|
userAccessLog.setResponse(JSONUtil.toJsonStr(result));
|
||||||
.setAccessStartTime(DateUtil.date(accessStartTime))
|
if (!result.getSuccess()) {
|
||||||
.setAccessEndTime(DateUtil.date(accessEndTime))
|
userAccessLog.setAccessSuccess(false);
|
||||||
.setAccessDuration(accessEndTime - accessStartTime)
|
userAccessLog.setOperationMsg(result.getErrorMessage());
|
||||||
.setAction(userOperation.value())
|
userAccessLog.setExceptionDetail(UserThreadLocal.getUser().getExceptionDetail());
|
||||||
.setRequestUrl(request.getRequestURL().toString())
|
}
|
||||||
.setRequestIp(parseIpFromUrl(request.getRequestURL().toString()))
|
} else { // 返回为ResponseEntity,且状态为失败。
|
||||||
.setReqArgs(reqArgs)
|
|
||||||
.setRemoteAddr(getRealIp(request))
|
|
||||||
.setAccessSuccess(true)
|
|
||||||
.setCreateTime(new Date())
|
|
||||||
.setOperationModule(userOperation.modelName().key)
|
|
||||||
.setOperationMsg(UserThreadLocal.getUser().getSuccessMsg())
|
|
||||||
.setDataId(user.getDataId())
|
|
||||||
.setParentId(user.getParentId());
|
|
||||||
|
|
||||||
ElectromagneticResult<?> result = user.getResult();
|
|
||||||
if (result != null) {
|
|
||||||
userAccessLog.setResponse(JSONUtil.toJsonStr(result));
|
|
||||||
if (!result.getSuccess()) {
|
|
||||||
userAccessLog.setAccessSuccess(false);
|
userAccessLog.setAccessSuccess(false);
|
||||||
userAccessLog.setOperationMsg(result.getErrorMessage());
|
|
||||||
userAccessLog.setExceptionDetail(UserThreadLocal.getUser().getExceptionDetail());
|
|
||||||
}
|
}
|
||||||
} else { // 返回为ResponseEntity,且状态为失败。
|
userAccessLogMapper.insert(userAccessLog);
|
||||||
userAccessLog.setAccessSuccess(false);
|
|
||||||
}
|
}
|
||||||
userAccessLogMapper.insert(userAccessLog);
|
|
||||||
UserThreadLocal.remove();
|
UserThreadLocal.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,20 +23,20 @@ public class FileRecycleController {
|
||||||
private FileRecycleService fileRecycleService;
|
private FileRecycleService fileRecycleService;
|
||||||
|
|
||||||
@RequestMapping("list")
|
@RequestMapping("list")
|
||||||
@UserOperation(value = "查看回收站", modelName = UserOperationModuleEnum.SYS_PRJ_DATABASE)
|
@UserOperation(value = "查看回收站", modelName = UserOperationModuleEnum.BACKUP_FILE)
|
||||||
public ElectromagneticResult<?> list(@RequestBody RecycleFileQueryDTO pars) {
|
public ElectromagneticResult<?> list(@RequestBody RecycleFileQueryDTO pars) {
|
||||||
return fileRecycleService.list(pars);
|
return fileRecycleService.list(pars);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("remove")
|
@RequestMapping("remove")
|
||||||
@UserOperation(value = "彻底清除文件", modelName = UserOperationModuleEnum.SYS_PRJ_DATABASE)
|
@UserOperation(value = "彻底清除文件", modelName = UserOperationModuleEnum.BACKUP_FILE)
|
||||||
public ElectromagneticResult<?> remove(@RequestParam String fileId) {
|
public ElectromagneticResult<?> remove(@RequestParam String fileId) {
|
||||||
Assert.isTrue(UserThreadLocal.getAdminType().equals(AdminTypeEnum.SYSTEM.getValue()), "当前用户没有删除文件权限");
|
Assert.isTrue(UserThreadLocal.getAdminType().equals(AdminTypeEnum.SYSTEM.getValue()), "当前用户没有删除文件权限");
|
||||||
return fileRecycleService.remove(fileId);
|
return fileRecycleService.remove(fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("recover")
|
@RequestMapping("recover")
|
||||||
@UserOperation(value = "文件恢复", modelName = UserOperationModuleEnum.SYS_PRJ_DATABASE)
|
@UserOperation(value = "文件恢复", modelName = UserOperationModuleEnum.BACKUP_FILE)
|
||||||
public ElectromagneticResult<?> recover(@RequestParam String fileId) {
|
public ElectromagneticResult<?> recover(@RequestParam String fileId) {
|
||||||
Assert.isTrue(UserThreadLocal.getAdminType().equals(AdminTypeEnum.SYSTEM.getValue()), "当前用户没有文件恢复权限");
|
Assert.isTrue(UserThreadLocal.getAdminType().equals(AdminTypeEnum.SYSTEM.getValue()), "当前用户没有文件恢复权限");
|
||||||
return fileRecycleService.recover(fileId);
|
return fileRecycleService.recover(fileId);
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -98,10 +96,12 @@ public class FileRecycleServiceImpl implements FileRecycleService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!UserThreadLocal.getAdminType().equals(AdminTypeEnum.SYSTEM.getValue())) {
|
if (!UserThreadLocal.getAdminType().equals(AdminTypeEnum.SYSTEM.getValue())) {
|
||||||
List<String> ids = edFileInfoMapper.selectList(Wrappers.<EdFileInfo>lambdaQuery().select(EdFileInfo::getId).eq(EdFileInfo::getDataOwn, DataOwnEnum.USER_FILE.code))
|
LambdaQueryWrapper<EdFileInfo> userPrjWrapper = Wrappers.<EdFileInfo>lambdaQuery().select(EdFileInfo::getId, EdFileInfo::getFileCode)
|
||||||
.stream()
|
.eq(EdFileInfo::getDataOwn, DataOwnEnum.USER_FILE.code)
|
||||||
.map(EdFileInfo::getId)
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
||||||
.collect(Collectors.toList());
|
.eq(EdFileInfo::getAllDeleted, true)
|
||||||
|
.eq(EdFileInfo::getPermanentDeleted, false);
|
||||||
|
List<String> ids = edFileInfoMapper.selectList(userPrjWrapper).stream().map(EdFileInfo::getFileCode).map(e -> e.substring(0, 6)).collect(Collectors.toList());
|
||||||
List<String> accessibleTree = permissionService.getAccessibleTree();
|
List<String> accessibleTree = permissionService.getAccessibleTree();
|
||||||
accessibleTree.addAll(ids);
|
accessibleTree.addAll(ids);
|
||||||
if (CollUtil.isNotEmpty(accessibleTree)) {
|
if (CollUtil.isNotEmpty(accessibleTree)) {
|
||||||
|
|
@ -133,7 +133,7 @@ public class FileRecycleServiceImpl implements FileRecycleService {
|
||||||
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
||||||
.set(EdFileInfo::getPermanentDeleted, true)
|
.set(EdFileInfo::getPermanentDeleted, true)
|
||||||
.set(EdFileInfo::getAllDeleted, true));
|
.set(EdFileInfo::getAllDeleted, true));
|
||||||
UserThreadLocal.setSuccessInfo("", "", "删除文件 {} 成功,文件id {}", edFileInfos.get(0).getFileName() + "." + edFileInfos.get(0).getFileType(), fileId);
|
UserThreadLocal.setSuccessInfo(edFileInfo.getParentId(), edFileInfo.getId(), "删除文件 {} 成功,文件id {}", edFileInfos.get(0).getFileName() + "." + edFileInfos.get(0).getFileType(), fileId);
|
||||||
BackupFileResLog resLog = backupHandler.deleteFile(edFileInfo.getId());
|
BackupFileResLog resLog = backupHandler.deleteFile(edFileInfo.getId());
|
||||||
if (!Optional.ofNullable(resLog).map(BackupFileResLog::getBackupSuccess).orElse(false)) {
|
if (!Optional.ofNullable(resLog).map(BackupFileResLog::getBackupSuccess).orElse(false)) {
|
||||||
log.warn("删除备份文件异常");
|
log.warn("删除备份文件异常");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.electromagnetic.industry.software.common.pojo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class AccessSuccessInfo {
|
||||||
|
private String successMsg;
|
||||||
|
private String dataId;
|
||||||
|
private String parentId;
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,9 @@ package com.electromagnetic.industry.software.common.pojo;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class UserLoginInfo {
|
public class UserLoginInfo {
|
||||||
|
|
||||||
|
|
@ -54,10 +57,11 @@ public class UserLoginInfo {
|
||||||
|
|
||||||
private String dataId;
|
private String dataId;
|
||||||
|
|
||||||
|
private List<AccessSuccessInfo> successInfoList = new ArrayList<>();
|
||||||
|
|
||||||
public void setSuccessInfo(String parentId, String successMsg, String dataId) {
|
public void setSuccessInfo(String parentId, String successMsg, String dataId) {
|
||||||
this.successMsg = successMsg;
|
AccessSuccessInfo successInfo = new AccessSuccessInfo(dataId, parentId, successMsg);
|
||||||
this.dataId = dataId;
|
successInfoList.add(successInfo);
|
||||||
this.parentId = parentId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue