forked from github/dataease
feat: 新增导出中心功能
This commit is contained in:
parent
db3144ac12
commit
d2fe50eea3
BIN
core/core-backend/src/main/java/io/dataease/exportCenter/.DS_Store
vendored
Normal file
BIN
core/core-backend/src/main/java/io/dataease/exportCenter/.DS_Store
vendored
Normal file
Binary file not shown.
@ -0,0 +1,159 @@
|
|||||||
|
package io.dataease.exportCenter.dao.auto.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 导出任务表
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author fit2cloud
|
||||||
|
* @since 2024-05-23
|
||||||
|
*/
|
||||||
|
@TableName("core_export_task")
|
||||||
|
public class CoreExportTask implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
private Double fileSize;
|
||||||
|
|
||||||
|
private String fileSizeUnit;
|
||||||
|
|
||||||
|
private String exportFrom;
|
||||||
|
|
||||||
|
private String exportStatus;
|
||||||
|
|
||||||
|
private String exportFromType;
|
||||||
|
|
||||||
|
private Long exportTime;
|
||||||
|
|
||||||
|
private String exportProgress;
|
||||||
|
|
||||||
|
private String exportMachineName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过滤参数
|
||||||
|
*/
|
||||||
|
private String params;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(Long userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileName(String fileName) {
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getFileSize() {
|
||||||
|
return fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileSize(Double fileSize) {
|
||||||
|
this.fileSize = fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileSizeUnit() {
|
||||||
|
return fileSizeUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileSizeUnit(String fileSizeUnit) {
|
||||||
|
this.fileSizeUnit = fileSizeUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExportFrom() {
|
||||||
|
return exportFrom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExportFrom(String exportFrom) {
|
||||||
|
this.exportFrom = exportFrom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExportStatus() {
|
||||||
|
return exportStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExportStatus(String exportStatus) {
|
||||||
|
this.exportStatus = exportStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExportFromType() {
|
||||||
|
return exportFromType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExportFromType(String exportFromType) {
|
||||||
|
this.exportFromType = exportFromType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getExportTime() {
|
||||||
|
return exportTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExportTime(Long exportTime) {
|
||||||
|
this.exportTime = exportTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExportProgress() {
|
||||||
|
return exportProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExportProgress(String exportProgress) {
|
||||||
|
this.exportProgress = exportProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExportMachineName() {
|
||||||
|
return exportMachineName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExportMachineName(String exportMachineName) {
|
||||||
|
this.exportMachineName = exportMachineName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParams(String params) {
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CoreExportTask{" +
|
||||||
|
"id = " + id +
|
||||||
|
", userId = " + userId +
|
||||||
|
", fileName = " + fileName +
|
||||||
|
", fileSize = " + fileSize +
|
||||||
|
", fileSizeUnit = " + fileSizeUnit +
|
||||||
|
", exportFrom = " + exportFrom +
|
||||||
|
", exportStatus = " + exportStatus +
|
||||||
|
", exportFromType = " + exportFromType +
|
||||||
|
", exportTime = " + exportTime +
|
||||||
|
", exportProgress = " + exportProgress +
|
||||||
|
", exportMachineName = " + exportMachineName +
|
||||||
|
", params = " + params +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package io.dataease.exportCenter.dao.auto.mapper;
|
||||||
|
|
||||||
|
import io.dataease.exportCenter.dao.auto.entity.CoreExportTask;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 导出任务表 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author fit2cloud
|
||||||
|
* @since 2024-05-23
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface CoreExportTaskMapper extends BaseMapper<CoreExportTask> {
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,50 @@
|
|||||||
|
package io.dataease.exportCenter.server;
|
||||||
|
|
||||||
|
import io.dataease.api.exportCenter.ExportCenterApi;
|
||||||
|
import io.dataease.api.exportCenter.vo.ExportTaskDTO;
|
||||||
|
import io.dataease.exportCenter.manage.ExportCenterManage;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/exportCenter")
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class ExportCenterServer implements ExportCenterApi {
|
||||||
|
@Resource
|
||||||
|
private ExportCenterManage exportCenterManage;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ExportTaskDTO> exportTasks(String status) {
|
||||||
|
return exportCenterManage.exportTasks(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String id) {
|
||||||
|
exportCenterManage.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(List<String> ids) {
|
||||||
|
exportCenterManage.delete(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteAll(String type) {
|
||||||
|
exportCenterManage.deleteAll(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(String id, HttpServletResponse response) throws Exception {
|
||||||
|
exportCenterManage.download(id, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void retry(String id) {
|
||||||
|
exportCenterManage.retry(id);
|
||||||
|
}
|
||||||
|
}
|
BIN
core/core-backend/src/main/java/io/dataease/websocket/.DS_Store
vendored
Normal file
BIN
core/core-backend/src/main/java/io/dataease/websocket/.DS_Store
vendored
Normal file
Binary file not shown.
@ -0,0 +1,33 @@
|
|||||||
|
package io.dataease.websocket.aop;
|
||||||
|
|
||||||
|
import io.dataease.websocket.entity.WsMessage;
|
||||||
|
import io.dataease.websocket.service.WsService;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.aspectj.lang.JoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.AfterReturning;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
public class WSTrigger {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WsService wsService;
|
||||||
|
|
||||||
|
@AfterReturning(value = "execution(* io.dataease.service.message.service.strategy.SendStation.sendMsg(..))")
|
||||||
|
public void after(JoinPoint point) {
|
||||||
|
Object[] args = point.getArgs();
|
||||||
|
Optional.ofNullable(args).ifPresent(objs -> {
|
||||||
|
if (ArrayUtils.isEmpty(objs)) return;
|
||||||
|
Object arg = args[0];
|
||||||
|
Long userId = (Long) arg;
|
||||||
|
WsMessage message = new WsMessage(userId, "/web-msg-topic", "refresh");
|
||||||
|
wsService.releaseMessage(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package io.dataease.websocket.config;
|
||||||
|
|
||||||
|
import io.dataease.websocket.factory.DeWsHandlerFactory;
|
||||||
|
import io.dataease.websocket.handler.PrincipalHandshakeHandler;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
||||||
|
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||||
|
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||||
|
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
|
||||||
|
import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSocketMessageBroker
|
||||||
|
public class WsConfig implements WebSocketMessageBrokerConfigurer {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||||
|
registry.addEndpoint("/websocket")
|
||||||
|
.setAllowedOriginPatterns("*")
|
||||||
|
.setHandshakeHandler(new PrincipalHandshakeHandler())
|
||||||
|
.withSockJS();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configureMessageBroker(MessageBrokerRegistry registry) {
|
||||||
|
registry.enableSimpleBroker("/topic", "/user");
|
||||||
|
registry.setUserDestinationPrefix("/user");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configureWebSocketTransport(WebSocketTransportRegistration registry) {
|
||||||
|
registry.addDecoratorFactory(new DeWsHandlerFactory());
|
||||||
|
registry.setMessageSizeLimit(8192) //设置消息字节数大小
|
||||||
|
.setSendBufferSizeLimit(8192)//设置消息缓存大小
|
||||||
|
.setSendTimeLimit(10000); //设置消息发送时间限制毫秒
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package io.dataease.websocket.entity;
|
||||||
|
|
||||||
|
import java.security.Principal;
|
||||||
|
|
||||||
|
public class DePrincipal implements Principal {
|
||||||
|
|
||||||
|
public DePrincipal(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package io.dataease.websocket.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WsMessage<T> implements Serializable {
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
private String topic;
|
||||||
|
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
|||||||
|
package io.dataease.websocket.factory;
|
||||||
|
|
||||||
|
import io.dataease.websocket.util.WsUtil;
|
||||||
|
import org.springframework.web.socket.CloseStatus;
|
||||||
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
|
import org.springframework.web.socket.WebSocketSession;
|
||||||
|
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class DeWebSocketHandlerDecorator extends WebSocketHandlerDecorator {
|
||||||
|
|
||||||
|
|
||||||
|
public DeWebSocketHandlerDecorator(WebSocketHandler delegate) {
|
||||||
|
super(delegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||||
|
Optional.ofNullable(session.getPrincipal()).ifPresent(principal -> {
|
||||||
|
String name = principal.getName();
|
||||||
|
Long userId = Long.parseLong(name);
|
||||||
|
WsUtil.onLine(userId);
|
||||||
|
});
|
||||||
|
super.afterConnectionEstablished(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
||||||
|
Optional.ofNullable(session.getPrincipal()).ifPresent(principal -> {
|
||||||
|
String name = principal.getName();
|
||||||
|
Long userId = Long.parseLong(name);
|
||||||
|
WsUtil.offLine(userId);
|
||||||
|
});
|
||||||
|
|
||||||
|
super.afterConnectionClosed(session, closeStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package io.dataease.websocket.factory;
|
||||||
|
|
||||||
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
|
import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory;
|
||||||
|
|
||||||
|
public class DeWsHandlerFactory implements WebSocketHandlerDecoratorFactory {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WebSocketHandler decorate(WebSocketHandler webSocketHandler) {
|
||||||
|
return new DeWebSocketHandlerDecorator(webSocketHandler);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package io.dataease.websocket.handler;
|
||||||
|
|
||||||
|
import io.dataease.websocket.entity.DePrincipal;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.http.server.ServerHttpRequest;
|
||||||
|
import org.springframework.http.server.ServletServerHttpRequest;
|
||||||
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
|
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||||
|
|
||||||
|
import java.security.Principal;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PrincipalHandshakeHandler extends DefaultHandshakeHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) {
|
||||||
|
if (request instanceof ServletServerHttpRequest) {
|
||||||
|
ServletServerHttpRequest servletServerHttpRequest = (ServletServerHttpRequest) request;
|
||||||
|
HttpServletRequest httpRequest = servletServerHttpRequest.getServletRequest();
|
||||||
|
final String userId = httpRequest.getParameter("userId");
|
||||||
|
if (StringUtils.isEmpty(userId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new DePrincipal(userId);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package io.dataease.websocket.service;
|
||||||
|
|
||||||
|
import io.dataease.websocket.entity.WsMessage;
|
||||||
|
|
||||||
|
|
||||||
|
public interface WsService {
|
||||||
|
|
||||||
|
void releaseMessage(WsMessage wsMessage);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package io.dataease.websocket.service.impl;
|
||||||
|
|
||||||
|
import io.dataease.websocket.entity.WsMessage;
|
||||||
|
import io.dataease.websocket.service.WsService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class StandaloneWsService implements WsService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SimpMessagingTemplate messagingTemplate;
|
||||||
|
|
||||||
|
public void releaseMessage(WsMessage wsMessage){
|
||||||
|
if(ObjectUtils.isEmpty(wsMessage) || ObjectUtils.isEmpty(wsMessage.getUserId()) || ObjectUtils.isEmpty(wsMessage.getTopic())) return;
|
||||||
|
messagingTemplate.convertAndSendToUser(String.valueOf(wsMessage.getUserId()), wsMessage.getTopic(),wsMessage.getData());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package io.dataease.websocket.util;
|
||||||
|
|
||||||
|
|
||||||
|
import io.dataease.auth.bo.TokenUserBO;
|
||||||
|
import io.dataease.utils.AuthUtils;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
|
public class WsUtil {
|
||||||
|
|
||||||
|
private static final CopyOnWriteArraySet<Long> ONLINE_USERS = new CopyOnWriteArraySet();
|
||||||
|
|
||||||
|
public static boolean onLine() {
|
||||||
|
TokenUserBO user = AuthUtils.getUser();
|
||||||
|
if (ObjectUtils.isNotEmpty(user) && ObjectUtils.isNotEmpty(user.getUserId()))
|
||||||
|
return onLine(user.getUserId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean onLine(Long userId) {
|
||||||
|
return ONLINE_USERS.add(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean offLine() {
|
||||||
|
TokenUserBO user = AuthUtils.getUser();
|
||||||
|
if (ObjectUtils.isNotEmpty(user) && ObjectUtils.isNotEmpty(user.getUserId()))
|
||||||
|
return offLine(user.getUserId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean offLine(Long userId) {
|
||||||
|
return ONLINE_USERS.remove(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isOnLine(Long userId) {
|
||||||
|
return ONLINE_USERS.contains(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user