From fec4beed2d60563430365d8ef5562bc8eeba23df Mon Sep 17 00:00:00 2001 From: zhangshuai Date: Wed, 4 Sep 2024 10:59:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:ASW-56=20device=20=E6=88=91=E7=9A=84?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=20=E6=8E=A5=E5=8F=A3=E5=BC=80=E5=8F=91=201.?= =?UTF-8?q?=E8=B0=83=E6=95=B4=20device=20=E6=8E=A5=E5=8F=A3=20path=202.?= =?UTF-8?q?=E8=B0=83=E6=95=B4=20device=20=20=E6=9B=BF=E6=8D=A2=E6=88=90=20?= =?UTF-8?q?environment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ....java => EnvironmentWebSocketHandler.java} | 78 +++++++---- .../config/websocket/WebSocketConfig.java | 10 +- .../websocket/WebSocketInterceptor.java | 6 +- .../net/geedge/asw/common/util/RCode.java | 6 + .../asw/module/device/dao/DeviceDao.java | 16 --- .../asw/module/device/dao/DeviceLogDao.java | 10 -- .../device/service/IDeviceLogService.java | 8 -- .../module/device/service/IDeviceService.java | 20 --- .../service/impl/DeviceLogServiceImpl.java | 15 -- .../service/impl/DeviceServiceImpl.java | 103 -------------- .../controller/EnvironmentController.java} | 63 +++++---- .../environment/dao/EnvironmentDao.java | 17 +++ .../dao/EnvironmentSessionDao.java | 10 ++ .../dao/EnvironmentWorkspaceDao.java | 9 ++ .../entity/EnvironmentEntity.java} | 7 +- .../entity/EnvironmentSessionEntity.java} | 8 +- .../entity/EnvironmentWorkspaceEntity.java | 19 +++ .../service/IEnvironmentService.java | 21 +++ .../service/IEnvironmentSessionService.java | 8 ++ .../service/IEnvironmentWorkspaceService.java | 7 + .../service/impl/EnvironmentServiceImpl.java | 129 ++++++++++++++++++ .../impl/EnvironmentSessionServiceImpl.java | 15 ++ .../impl/EnvironmentWorkspaceServiceImpl.java | 11 ++ .../util/EnvironmentUtil.java} | 29 ++-- .../db/mapper/device/DeviceMapper.xml | 79 ----------- .../db/mapper/device/EnvironmentMapper.xml | 129 ++++++++++++++++++ .../resources/db/migration/R__AZ_sys_i18n.sql | 4 + .../db/migration/V1.0.01__INIT_TABLES.sql | 35 +++-- 28 files changed, 526 insertions(+), 346 deletions(-) rename src/main/java/net/geedge/asw/common/config/websocket/{DeviceWebSocketHandler.java => EnvironmentWebSocketHandler.java} (52%) delete mode 100644 src/main/java/net/geedge/asw/module/device/dao/DeviceDao.java delete mode 100644 src/main/java/net/geedge/asw/module/device/dao/DeviceLogDao.java delete mode 100644 src/main/java/net/geedge/asw/module/device/service/IDeviceLogService.java delete mode 100644 src/main/java/net/geedge/asw/module/device/service/IDeviceService.java delete mode 100644 src/main/java/net/geedge/asw/module/device/service/impl/DeviceLogServiceImpl.java delete mode 100644 src/main/java/net/geedge/asw/module/device/service/impl/DeviceServiceImpl.java rename src/main/java/net/geedge/asw/module/{device/controller/DeviceController.java => environment/controller/EnvironmentController.java} (50%) create mode 100644 src/main/java/net/geedge/asw/module/environment/dao/EnvironmentDao.java create mode 100644 src/main/java/net/geedge/asw/module/environment/dao/EnvironmentSessionDao.java create mode 100644 src/main/java/net/geedge/asw/module/environment/dao/EnvironmentWorkspaceDao.java rename src/main/java/net/geedge/asw/module/{device/entity/DeviceEntity.java => environment/entity/EnvironmentEntity.java} (90%) rename src/main/java/net/geedge/asw/module/{device/entity/DeviceLogEntity.java => environment/entity/EnvironmentSessionEntity.java} (74%) create mode 100644 src/main/java/net/geedge/asw/module/environment/entity/EnvironmentWorkspaceEntity.java create mode 100644 src/main/java/net/geedge/asw/module/environment/service/IEnvironmentService.java create mode 100644 src/main/java/net/geedge/asw/module/environment/service/IEnvironmentSessionService.java create mode 100644 src/main/java/net/geedge/asw/module/environment/service/IEnvironmentWorkspaceService.java create mode 100644 src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentServiceImpl.java create mode 100644 src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentSessionServiceImpl.java create mode 100644 src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentWorkspaceServiceImpl.java rename src/main/java/net/geedge/asw/module/{device/util/DeviceUtil.java => environment/util/EnvironmentUtil.java} (86%) delete mode 100644 src/main/resources/db/mapper/device/DeviceMapper.xml create mode 100644 src/main/resources/db/mapper/device/EnvironmentMapper.xml diff --git a/src/main/java/net/geedge/asw/common/config/websocket/DeviceWebSocketHandler.java b/src/main/java/net/geedge/asw/common/config/websocket/EnvironmentWebSocketHandler.java similarity index 52% rename from src/main/java/net/geedge/asw/common/config/websocket/DeviceWebSocketHandler.java rename to src/main/java/net/geedge/asw/common/config/websocket/EnvironmentWebSocketHandler.java index 9fee936..e6fda1a 100644 --- a/src/main/java/net/geedge/asw/common/config/websocket/DeviceWebSocketHandler.java +++ b/src/main/java/net/geedge/asw/common/config/websocket/EnvironmentWebSocketHandler.java @@ -3,10 +3,13 @@ package net.geedge.asw.common.config.websocket; import cn.hutool.json.JSONObject; import cn.hutool.log.Log; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import net.geedge.asw.common.util.Constants; import net.geedge.asw.common.util.T; -import net.geedge.asw.module.device.entity.DeviceEntity; -import net.geedge.asw.module.device.service.IDeviceService; +import net.geedge.asw.module.environment.entity.EnvironmentEntity; +import net.geedge.asw.module.environment.entity.EnvironmentSessionEntity; +import net.geedge.asw.module.environment.service.IEnvironmentService; +import net.geedge.asw.module.environment.service.IEnvironmentSessionService; import org.springframework.stereotype.Component; import org.springframework.web.socket.*; import org.springframework.web.socket.handler.TextWebSocketHandler; @@ -19,28 +22,37 @@ import java.nio.ByteBuffer; import java.util.concurrent.CompletionStage; @Component -public class DeviceWebSocketHandler extends TextWebSocketHandler { +public class EnvironmentWebSocketHandler extends TextWebSocketHandler { private static final Log log = Log.get(); /** - * device id + * env id */ - private String id; + private String envId; /** - * device token + * session + */ + private String sessionId; + + /** + * env token */ private String token; - private IDeviceService deviceService; + private IEnvironmentService environmentService; - public DeviceWebSocketHandler(IDeviceService deviceService) { - this.deviceService = deviceService; + private IEnvironmentSessionService environmentSessionService; + + public EnvironmentWebSocketHandler(IEnvironmentService environmentService, IEnvironmentSessionService environmentSessionService) { + this.environmentService = environmentService; + this.environmentSessionService = environmentSessionService; } private void initFieldVal(WebSocketSession session) { - this.id = (String) session.getAttributes().get("id"); + this.envId = (String) session.getAttributes().get("envId"); + this.sessionId = (String) session.getAttributes().get("sessionId"); this.token = (String) session.getAttributes().get("token"); } @@ -49,28 +61,36 @@ public class DeviceWebSocketHandler extends TextWebSocketHandler { super.afterConnectionEstablished(session); this.initFieldVal(session); - log.info("WebSocket connectioned. after connection established open device begin... device id: {}", id); + log.info("WebSocket connectioned. after connection established open env begin... env id: {}", envId); - - DeviceEntity deviceEntity = deviceService.queryInfo(id); - JSONObject paramJSONObject = deviceEntity.getParamJSONObject(); - - if (T.StrUtil.equals(token, paramJSONObject.getStr("token"))) { - log.warn("WebSocket connectioned error. device token exception. device id: {}, token: {}", id, token); - session.sendMessage(new TextMessage("Token error, Please config device token")); + EnvironmentSessionEntity environmentSession = environmentSessionService.getOne(new LambdaQueryWrapper().eq(EnvironmentSessionEntity::getId, sessionId).eq(EnvironmentSessionEntity::getStatus, 1)); + if (environmentSession == null) { + log.warn("environment session does not exist. session id: {}", sessionId); + session.sendMessage(new TextMessage("environment session does not exist")); session.close(); return; } - String urlStr = String.format("ws://%s:%s%s", paramJSONObject.getStr("host"), paramJSONObject.getStr("port"), Constants.DEVICE_API_WEBSOCKET_PATH); + EnvironmentEntity deviceEntity = environmentService.queryInfo(envId); + JSONObject paramJSONObject = deviceEntity.getParamJSONObject(); + + if (T.StrUtil.equals(token, paramJSONObject.getStr("token"))) { + log.warn("WebSocket connectioned error. env token exception. env id: {}, token: {}", envId, token); + session.sendMessage(new TextMessage("Token error, Please config env token")); + session.close(); + return; + } + + String urlStr = String.format("%s%s", paramJSONObject.getStr("url"), Constants.DEVICE_API_WEBSOCKET_PATH); + urlStr = urlStr.replace("http", "ws"); HttpClient client = HttpClient.newHttpClient(); WebSocket webSocket = client.newWebSocketBuilder() .buildAsync(URI.create(urlStr), new WebSocketListener(session)) .get(); - log.info("[afterConnectionEstablished] [device server: {}]", T.JSONUtil.toJsonStr(paramJSONObject)); - session.getAttributes().put("deviceWebsocket", webSocket); + log.info("[afterConnectionEstablished] [env server: {}]", T.JSONUtil.toJsonStr(paramJSONObject)); + session.getAttributes().put("envWebsocket", webSocket); } @@ -97,7 +117,7 @@ public class DeviceWebSocketHandler extends TextWebSocketHandler { @Override public CompletionStage onClose(WebSocket webSocket, int statusCode, String reason) { - log.info("Device webSocket connection closed, Status: " + statusCode + ", Reason: " + reason); + log.info("Env webSocket connection closed, Status: " + statusCode + ", Reason: " + reason); return WebSocket.Listener.super.onClose(webSocket, statusCode, reason); } } @@ -105,10 +125,10 @@ public class DeviceWebSocketHandler extends TextWebSocketHandler { @Override protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) { try { - // asw -> device api - WebSocket vncSocket = (WebSocket) session.getAttributes().get("deviceWebsocket"); - if (vncSocket != null) { - vncSocket.sendBinary(message.getPayload(), true); + // asw -> env api + WebSocket envSocket = (WebSocket) session.getAttributes().get("envWebsocket"); + if (envSocket != null) { + envSocket.sendBinary(message.getPayload(), true); } } catch (Exception e) { log.error(e, "[handleBinaryMessage] [error]"); @@ -118,9 +138,9 @@ public class DeviceWebSocketHandler extends TextWebSocketHandler { @Override public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { log.info("[afterConnectionClosed] [WebSocket connection closed] [websocket uri: {}]", session.getUri()); - WebSocket deviceWebsocket = (WebSocket) session.getAttributes().get("deviceWebsocket"); - if (deviceWebsocket != null) { - deviceWebsocket.sendClose(WebSocket.NORMAL_CLOSURE, "Normal closure"); + WebSocket envWebsocket = (WebSocket) session.getAttributes().get("envWebsocket"); + if (envWebsocket != null) { + envWebsocket.sendClose(WebSocket.NORMAL_CLOSURE, "Normal closure"); } super.afterConnectionClosed(session, status); } diff --git a/src/main/java/net/geedge/asw/common/config/websocket/WebSocketConfig.java b/src/main/java/net/geedge/asw/common/config/websocket/WebSocketConfig.java index 6100c3e..1d9bd67 100644 --- a/src/main/java/net/geedge/asw/common/config/websocket/WebSocketConfig.java +++ b/src/main/java/net/geedge/asw/common/config/websocket/WebSocketConfig.java @@ -1,6 +1,7 @@ package net.geedge.asw.common.config.websocket; -import net.geedge.asw.module.device.service.IDeviceService; +import net.geedge.asw.module.environment.service.IEnvironmentService; +import net.geedge.asw.module.environment.service.IEnvironmentSessionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.web.socket.config.annotation.EnableWebSocket; @@ -12,11 +13,14 @@ import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry public class WebSocketConfig implements WebSocketConfigurer { @Autowired - private IDeviceService deviceService; + private IEnvironmentService deviceService; + + @Autowired + private IEnvironmentSessionService environmentSessionService; @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(new DeviceWebSocketHandler(deviceService), "/api/v1/device/{id}/novnc") + registry.addHandler(new EnvironmentWebSocketHandler(deviceService, environmentSessionService), "/api/v1/env/{envId}/session/{sessionId}/novnc") .addInterceptors(new WebSocketInterceptor()) .setAllowedOrigins("*"); } diff --git a/src/main/java/net/geedge/asw/common/config/websocket/WebSocketInterceptor.java b/src/main/java/net/geedge/asw/common/config/websocket/WebSocketInterceptor.java index cd60747..3b09538 100644 --- a/src/main/java/net/geedge/asw/common/config/websocket/WebSocketInterceptor.java +++ b/src/main/java/net/geedge/asw/common/config/websocket/WebSocketInterceptor.java @@ -1,6 +1,5 @@ package net.geedge.asw.common.config.websocket; -import jakarta.servlet.http.HttpSession; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; import org.springframework.http.server.ServletServerHttpRequest; @@ -20,9 +19,10 @@ public class WebSocketInterceptor extends HttpSessionHandshakeInterceptor { if (request instanceof ServletServerHttpRequest) { ServletServerHttpRequest servletRequest = (ServletServerHttpRequest) request; String servletPath = servletRequest.getServletRequest().getServletPath(); - UriTemplate template = new UriTemplate("/api/v1/device/{id}/novnc"); + UriTemplate template = new UriTemplate("/api/v1/env/{envId}/session/{sessionId}/novnc"); Map variables = template.match(servletPath); - attributes.put("id", variables.get("id")); + attributes.put("envId", variables.get("envId")); + attributes.put("sessionId", variables.get("sessionId")); attributes.put("token", servletRequest.getServletRequest().getParameter("token")); } return super.beforeHandshake(request, response, wsHandler, attributes); diff --git a/src/main/java/net/geedge/asw/common/util/RCode.java b/src/main/java/net/geedge/asw/common/util/RCode.java index 92ba8cc..dd36115 100644 --- a/src/main/java/net/geedge/asw/common/util/RCode.java +++ b/src/main/java/net/geedge/asw/common/util/RCode.java @@ -79,6 +79,12 @@ public enum RCode { PCAP_UPLOAD_WEB_SHARK_ERROR(501001, "web shark upload pcap error"), + //environment + ENVIRONMENT_SESSION_NOT_EXIST(601001, "environment session does not exist"), + ENVIRONMENT_NOT_EXIST(601002, "environment does not exist"), + + + SUCCESS(200, "success"); // 成功 private RCode(Integer code, String msg) { diff --git a/src/main/java/net/geedge/asw/module/device/dao/DeviceDao.java b/src/main/java/net/geedge/asw/module/device/dao/DeviceDao.java deleted file mode 100644 index 72897da..0000000 --- a/src/main/java/net/geedge/asw/module/device/dao/DeviceDao.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.geedge.asw.module.device.dao; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import net.geedge.asw.module.device.entity.DeviceEntity; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; -import java.util.Map; - -@Mapper -public interface DeviceDao extends BaseMapper { - - List queryList(Page page, Map params); - -} diff --git a/src/main/java/net/geedge/asw/module/device/dao/DeviceLogDao.java b/src/main/java/net/geedge/asw/module/device/dao/DeviceLogDao.java deleted file mode 100644 index da9ab72..0000000 --- a/src/main/java/net/geedge/asw/module/device/dao/DeviceLogDao.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.geedge.asw.module.device.dao; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import net.geedge.asw.module.device.entity.DeviceLogEntity; -import org.apache.ibatis.annotations.Mapper; - -@Mapper -public interface DeviceLogDao extends BaseMapper { - -} diff --git a/src/main/java/net/geedge/asw/module/device/service/IDeviceLogService.java b/src/main/java/net/geedge/asw/module/device/service/IDeviceLogService.java deleted file mode 100644 index f910179..0000000 --- a/src/main/java/net/geedge/asw/module/device/service/IDeviceLogService.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.geedge.asw.module.device.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import net.geedge.asw.module.device.entity.DeviceLogEntity; - -public interface IDeviceLogService extends IService{ - -} diff --git a/src/main/java/net/geedge/asw/module/device/service/IDeviceService.java b/src/main/java/net/geedge/asw/module/device/service/IDeviceService.java deleted file mode 100644 index 4236b3e..0000000 --- a/src/main/java/net/geedge/asw/module/device/service/IDeviceService.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.geedge.asw.module.device.service; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.service.IService; -import net.geedge.asw.module.device.entity.DeviceEntity; - -import java.util.List; -import java.util.Map; - -public interface IDeviceService extends IService{ - - DeviceEntity queryInfo(String id); - - Page queryList(Map params); - - DeviceEntity saveDevice(DeviceEntity entity); - - void removeDevice(List ids); - -} diff --git a/src/main/java/net/geedge/asw/module/device/service/impl/DeviceLogServiceImpl.java b/src/main/java/net/geedge/asw/module/device/service/impl/DeviceLogServiceImpl.java deleted file mode 100644 index 7fd1160..0000000 --- a/src/main/java/net/geedge/asw/module/device/service/impl/DeviceLogServiceImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.geedge.asw.module.device.service.impl; - -import cn.hutool.log.Log; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import net.geedge.asw.module.device.dao.DeviceLogDao; -import net.geedge.asw.module.device.entity.DeviceLogEntity; -import net.geedge.asw.module.device.service.IDeviceLogService; -import org.springframework.stereotype.Service; - -@Service -public class DeviceLogServiceImpl extends ServiceImpl implements IDeviceLogService { - - private static final Log log = Log.get(); - -} diff --git a/src/main/java/net/geedge/asw/module/device/service/impl/DeviceServiceImpl.java b/src/main/java/net/geedge/asw/module/device/service/impl/DeviceServiceImpl.java deleted file mode 100644 index e35b1f4..0000000 --- a/src/main/java/net/geedge/asw/module/device/service/impl/DeviceServiceImpl.java +++ /dev/null @@ -1,103 +0,0 @@ -package net.geedge.asw.module.device.service.impl; - -import cn.dev33.satoken.stp.StpUtil; -import cn.hutool.json.JSONObject; -import cn.hutool.log.Log; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import net.geedge.asw.common.util.RCode; -import net.geedge.asw.common.util.T; -import net.geedge.asw.module.device.dao.DeviceDao; -import net.geedge.asw.module.device.entity.DeviceEntity; -import net.geedge.asw.module.device.entity.DeviceLogEntity; -import net.geedge.asw.module.device.service.IDeviceLogService; -import net.geedge.asw.module.device.service.IDeviceService; -import net.geedge.asw.module.sys.entity.SysUserEntity; -import net.geedge.asw.module.sys.service.ISysUserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Map; - -@Service -public class DeviceServiceImpl extends ServiceImpl implements IDeviceService { - - private static final Log log = Log.get(); - - @Autowired - private ISysUserService sysUserService; - - @Autowired - private IDeviceLogService deviceLogService; - - @Override - public DeviceEntity queryInfo(String id) { - DeviceEntity device = this.getById(id); - T.VerifyUtil.is(device).notNull(RCode.SYS_RECORD_NOT_FOUND); - - // param - device.setParam(device.getParamJSONObject()); - - SysUserEntity createUser = sysUserService.getById(device.getCreateUserId()); - SysUserEntity updateUser = sysUserService.getById(device.getUpdateUserId()); - device.setCreateUser(createUser); - device.setUpdateUser(updateUser); - - DeviceLogEntity deviceLog = deviceLogService.getOne(new LambdaQueryWrapper().eq(DeviceLogEntity::getDeviceId, device.getId())); - if (null != deviceLog) { - SysUserEntity useUser = sysUserService.getById(deviceLog.getUserId()); - - JSONObject jsonObject = new JSONObject(); - jsonObject.set("id", useUser.getId()); - jsonObject.set("name", useUser.getName()); - jsonObject.set("startTimestamp", deviceLog.getStartTimestamp()); - jsonObject.set("endTimestamp", deviceLog.getEndTimestamp()); - device.setUseUser(jsonObject); - } - return device; - } - - @Override - public Page queryList(Map params) { - Page page = T.PageUtil.getPage(params); - List packageList = this.getBaseMapper().queryList(page, params); - - for (DeviceEntity entity : packageList) { - entity.setParam(entity.getParamJSONObject()); - } - page.setRecords(packageList); - return page; - } - - @Override - public DeviceEntity saveDevice(DeviceEntity entity) { - // param - entity.setParam(entity.getParamStr()); - - // default android - entity.setPlatform(T.StrUtil.emptyToDefault(entity.getPlatform(), "android")); - - entity.setCreateTimestamp(System.currentTimeMillis()); - entity.setUpdateTimestamp(System.currentTimeMillis()); - entity.setCreateUserId(StpUtil.getLoginIdAsString()); - entity.setUpdateUserId(StpUtil.getLoginIdAsString()); - - // save - this.save(entity); - return entity; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void removeDevice(List ids) { - // remove - this.removeBatchByIds(ids); - - // log - deviceLogService.remove(new LambdaQueryWrapper().in(DeviceLogEntity::getDeviceId, ids)); - } - -} \ No newline at end of file diff --git a/src/main/java/net/geedge/asw/module/device/controller/DeviceController.java b/src/main/java/net/geedge/asw/module/environment/controller/EnvironmentController.java similarity index 50% rename from src/main/java/net/geedge/asw/module/device/controller/DeviceController.java rename to src/main/java/net/geedge/asw/module/environment/controller/EnvironmentController.java index dd4907e..d1b3834 100644 --- a/src/main/java/net/geedge/asw/module/device/controller/DeviceController.java +++ b/src/main/java/net/geedge/asw/module/environment/controller/EnvironmentController.java @@ -1,40 +1,42 @@ -package net.geedge.asw.module.device.controller; +package net.geedge.asw.module.environment.controller; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.hutool.json.JSONObject; import cn.hutool.log.Log; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import net.geedge.asw.common.util.*; -import net.geedge.asw.module.device.entity.DeviceEntity; -import net.geedge.asw.module.device.service.IDeviceService; -import net.geedge.asw.module.device.util.DeviceUtil; +import net.geedge.asw.module.environment.entity.EnvironmentEntity; +import net.geedge.asw.module.environment.entity.EnvironmentSessionEntity; +import net.geedge.asw.module.environment.service.IEnvironmentService; +import net.geedge.asw.module.environment.service.IEnvironmentSessionService; +import net.geedge.asw.module.environment.util.EnvironmentUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import org.springframework.web.client.RestTemplate; import java.io.IOException; import java.util.*; @RestController -@RequestMapping("/api/v1/device") -public class DeviceController { +@RequestMapping("/api/v1/env") +public class EnvironmentController { private static final Log log = Log.get(); @Autowired - private IDeviceService deviceService; + private IEnvironmentService environmentService; @Autowired - private RestTemplate restTemplate; + private IEnvironmentSessionService environmentSessionService; @GetMapping("/{id}") public R detail(@PathVariable("id") String id) { - DeviceEntity entity = deviceService.queryInfo(id); + EnvironmentEntity entity = environmentService.queryInfo(id); return R.ok().putData("record", entity); } @@ -42,42 +44,41 @@ public class DeviceController { public R list(@RequestParam Map params) { T.VerifyUtil.is(params).notNull() .and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); - Page page = deviceService.queryList(params); + Page page = environmentService.queryList(params); return R.ok(page); } @PostMapping - public R add(@RequestBody DeviceEntity entity) { + public R add(@RequestBody EnvironmentEntity entity) { T.VerifyUtil.is(entity).notNull() .and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); - DeviceEntity deviceEntity = deviceService.saveDevice(entity); + EnvironmentEntity deviceEntity = environmentService.saveDevice(entity); return R.ok().putData("id", deviceEntity.getId()); } @DeleteMapping public R delete(String[] ids) { T.VerifyUtil.is(ids).notEmpty(); - deviceService.removeDevice(T.ListUtil.of(ids)); + environmentService.removeDevice(T.ListUtil.of(ids)); return R.ok(); } @PostMapping("/test") - public R testConnect(@RequestBody DeviceEntity entity) { + public R testConnect(@RequestBody EnvironmentEntity entity) { T.VerifyUtil.is(entity).notNull() .and(entity.getParam()).notEmpty(RCode.PARAM_CANNOT_EMPTY); JSONObject jsonObject = entity.getParamJSONObject(); - String host = jsonObject.getStr("host"); - String port = jsonObject.getStr("port"); + String url = jsonObject.getStr("url"); String token = jsonObject.getStr("token"); - if (T.StrUtil.hasEmpty(host, port, token)) { + if (T.StrUtil.hasEmpty(url, token)) { return R.error(RCode.PARAM_CANNOT_EMPTY); } try { - HttpRequest request = T.HttpUtil.createGet(String.format("http://%s:%s/api/v1/device/status", host, port)); + HttpRequest request = T.HttpUtil.createGet(String.format("%s/api/v1/device/status", url)); request.header("Authorization", token); HttpResponse response = request.execute(); log.info("[testConnect] [status: {}]", response.getStatus()); @@ -94,14 +95,24 @@ public class DeviceController { return R.error(RCode.ERROR); } - - @RequestMapping(value = "/{id}/**", method ={ RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE}, headers = "Upgrade!=websocket") - public void deviceAgent(@PathVariable("id") String deviceId, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - DeviceEntity device = deviceService.getById(deviceId); - if (T.ObjectUtil.isNull(device)) { - throw new ASWException(RCode.SYS_RECORD_NOT_FOUND); + @RequestMapping(value = "/{envId}/session/{sessionId}/**", method ={ RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE}, headers = "Upgrade!=websocket") + public void agentEvn(@PathVariable("envId") String envId, @PathVariable("sessionId") String sessionId, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + EnvironmentSessionEntity session = environmentSessionService.getOne(new LambdaQueryWrapper().eq(EnvironmentSessionEntity::getId, sessionId).eq(EnvironmentSessionEntity::getStatus, 1)); + if (T.ObjectUtil.isNull(session)){ + throw new ASWException(RCode.ENVIRONMENT_SESSION_NOT_EXIST); } - DeviceUtil.getForObject(device, request,response); + EnvironmentEntity environment = environmentService.getById(session.getEnvId()); + if (T.ObjectUtil.isNull(environment)) { + throw new ASWException(RCode.ENVIRONMENT_NOT_EXIST); + } + + EnvironmentUtil.getForObject(environment, request, response, sessionId); + } + + @GetMapping("/mySession") + public R mySession(@RequestParam Map params){ + Page page = environmentService.mySession(params); + return R.ok(page); } } \ No newline at end of file diff --git a/src/main/java/net/geedge/asw/module/environment/dao/EnvironmentDao.java b/src/main/java/net/geedge/asw/module/environment/dao/EnvironmentDao.java new file mode 100644 index 0000000..7be0154 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/environment/dao/EnvironmentDao.java @@ -0,0 +1,17 @@ +package net.geedge.asw.module.environment.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import net.geedge.asw.module.environment.entity.EnvironmentEntity; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; +import java.util.Map; + +@Mapper +public interface EnvironmentDao extends BaseMapper { + + List queryList(Page page, Map params); + + List mySession(Page page, Map params); +} diff --git a/src/main/java/net/geedge/asw/module/environment/dao/EnvironmentSessionDao.java b/src/main/java/net/geedge/asw/module/environment/dao/EnvironmentSessionDao.java new file mode 100644 index 0000000..f67b451 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/environment/dao/EnvironmentSessionDao.java @@ -0,0 +1,10 @@ +package net.geedge.asw.module.environment.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import net.geedge.asw.module.environment.entity.EnvironmentSessionEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface EnvironmentSessionDao extends BaseMapper { + +} diff --git a/src/main/java/net/geedge/asw/module/environment/dao/EnvironmentWorkspaceDao.java b/src/main/java/net/geedge/asw/module/environment/dao/EnvironmentWorkspaceDao.java new file mode 100644 index 0000000..e3471ef --- /dev/null +++ b/src/main/java/net/geedge/asw/module/environment/dao/EnvironmentWorkspaceDao.java @@ -0,0 +1,9 @@ +package net.geedge.asw.module.environment.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import net.geedge.asw.module.environment.entity.EnvironmentWorkspaceEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface EnvironmentWorkspaceDao extends BaseMapper { +} diff --git a/src/main/java/net/geedge/asw/module/device/entity/DeviceEntity.java b/src/main/java/net/geedge/asw/module/environment/entity/EnvironmentEntity.java similarity index 90% rename from src/main/java/net/geedge/asw/module/device/entity/DeviceEntity.java rename to src/main/java/net/geedge/asw/module/environment/entity/EnvironmentEntity.java index e2a9d2e..b50e1b4 100644 --- a/src/main/java/net/geedge/asw/module/device/entity/DeviceEntity.java +++ b/src/main/java/net/geedge/asw/module/environment/entity/EnvironmentEntity.java @@ -1,4 +1,4 @@ -package net.geedge.asw.module.device.entity; +package net.geedge.asw.module.environment.entity; import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.annotation.IdType; @@ -11,8 +11,8 @@ import net.geedge.asw.common.util.T; import net.geedge.asw.module.sys.entity.SysUserEntity; @Data -@TableName("device") -public class DeviceEntity { +@TableName("environment") +public class EnvironmentEntity { @TableId(type = IdType.ASSIGN_UUID) private String id; @@ -29,6 +29,7 @@ public class DeviceEntity { private String createUserId; private String updateUserId; + @TableField(exist = false) private String workspaceId; @TableField(exist = false) diff --git a/src/main/java/net/geedge/asw/module/device/entity/DeviceLogEntity.java b/src/main/java/net/geedge/asw/module/environment/entity/EnvironmentSessionEntity.java similarity index 74% rename from src/main/java/net/geedge/asw/module/device/entity/DeviceLogEntity.java rename to src/main/java/net/geedge/asw/module/environment/entity/EnvironmentSessionEntity.java index 2c9ec13..442918a 100644 --- a/src/main/java/net/geedge/asw/module/device/entity/DeviceLogEntity.java +++ b/src/main/java/net/geedge/asw/module/environment/entity/EnvironmentSessionEntity.java @@ -1,4 +1,4 @@ -package net.geedge.asw.module.device.entity; +package net.geedge.asw.module.environment.entity; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; @@ -6,12 +6,12 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @Data -@TableName("device_log") -public class DeviceLogEntity { +@TableName("environment_session") +public class EnvironmentSessionEntity { @TableId(type = IdType.ASSIGN_UUID) private String id; - private String deviceId; + private String envId; private String userId; private Integer status; private String jobId; diff --git a/src/main/java/net/geedge/asw/module/environment/entity/EnvironmentWorkspaceEntity.java b/src/main/java/net/geedge/asw/module/environment/entity/EnvironmentWorkspaceEntity.java new file mode 100644 index 0000000..9d4bc4c --- /dev/null +++ b/src/main/java/net/geedge/asw/module/environment/entity/EnvironmentWorkspaceEntity.java @@ -0,0 +1,19 @@ +package net.geedge.asw.module.environment.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + + +@Data +@TableName("environment_workspace") +public class EnvironmentWorkspaceEntity { + @TableId(type = IdType.ASSIGN_UUID) + private String id; + + private String envId; + private String workspaceId; + private Long createTimestamp; + private String createUserId; +} diff --git a/src/main/java/net/geedge/asw/module/environment/service/IEnvironmentService.java b/src/main/java/net/geedge/asw/module/environment/service/IEnvironmentService.java new file mode 100644 index 0000000..350c8cd --- /dev/null +++ b/src/main/java/net/geedge/asw/module/environment/service/IEnvironmentService.java @@ -0,0 +1,21 @@ +package net.geedge.asw.module.environment.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import net.geedge.asw.module.environment.entity.EnvironmentEntity; + +import java.util.List; +import java.util.Map; + +public interface IEnvironmentService extends IService{ + + EnvironmentEntity queryInfo(String id); + + Page queryList(Map params); + + EnvironmentEntity saveDevice(EnvironmentEntity entity); + + void removeDevice(List ids); + + Page mySession(Map params); +} diff --git a/src/main/java/net/geedge/asw/module/environment/service/IEnvironmentSessionService.java b/src/main/java/net/geedge/asw/module/environment/service/IEnvironmentSessionService.java new file mode 100644 index 0000000..105af84 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/environment/service/IEnvironmentSessionService.java @@ -0,0 +1,8 @@ +package net.geedge.asw.module.environment.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import net.geedge.asw.module.environment.entity.EnvironmentSessionEntity; + +public interface IEnvironmentSessionService extends IService{ + +} diff --git a/src/main/java/net/geedge/asw/module/environment/service/IEnvironmentWorkspaceService.java b/src/main/java/net/geedge/asw/module/environment/service/IEnvironmentWorkspaceService.java new file mode 100644 index 0000000..268c8b5 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/environment/service/IEnvironmentWorkspaceService.java @@ -0,0 +1,7 @@ +package net.geedge.asw.module.environment.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import net.geedge.asw.module.environment.entity.EnvironmentWorkspaceEntity; + +public interface IEnvironmentWorkspaceService extends IService { +} diff --git a/src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentServiceImpl.java b/src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentServiceImpl.java new file mode 100644 index 0000000..f060734 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentServiceImpl.java @@ -0,0 +1,129 @@ +package net.geedge.asw.module.environment.service.impl; + +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.log.Log; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import net.geedge.asw.common.config.Query; +import net.geedge.asw.common.util.RCode; +import net.geedge.asw.common.util.T; +import net.geedge.asw.module.environment.dao.EnvironmentDao; +import net.geedge.asw.module.environment.entity.EnvironmentEntity; +import net.geedge.asw.module.environment.entity.EnvironmentSessionEntity; +import net.geedge.asw.module.environment.entity.EnvironmentWorkspaceEntity; +import net.geedge.asw.module.environment.service.IEnvironmentService; +import net.geedge.asw.module.environment.service.IEnvironmentSessionService; +import net.geedge.asw.module.environment.service.IEnvironmentWorkspaceService; +import net.geedge.asw.module.sys.entity.SysUserEntity; +import net.geedge.asw.module.sys.service.ISysUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; + +@Service +public class EnvironmentServiceImpl extends ServiceImpl implements IEnvironmentService { + + private static final Log log = Log.get(); + + @Autowired + private ISysUserService sysUserService; + + @Autowired + private IEnvironmentSessionService deviceSessionService; + + @Autowired + private IEnvironmentWorkspaceService deviceWorkspaceService; + + @Override + public EnvironmentEntity queryInfo(String id) { + EnvironmentEntity environment = this.getById(id); + T.VerifyUtil.is(environment).notNull(RCode.SYS_RECORD_NOT_FOUND); + + // param + environment.setParam(environment.getParamJSONObject()); + + SysUserEntity createUser = sysUserService.getById(environment.getCreateUserId()); + SysUserEntity updateUser = sysUserService.getById(environment.getUpdateUserId()); + environment.setCreateUser(createUser); + environment.setUpdateUser(updateUser); + + EnvironmentSessionEntity deviceSession = deviceSessionService.getOne(new LambdaQueryWrapper().eq(EnvironmentSessionEntity::getEnvId, environment.getId())); + if (null != deviceSession) { + SysUserEntity useUser = sysUserService.getById(deviceSession.getUserId()); + + JSONObject jsonObject = new JSONObject(); + jsonObject.set("id", useUser.getId()); + jsonObject.set("name", useUser.getName()); + jsonObject.set("startTimestamp", deviceSession.getStartTimestamp()); + jsonObject.set("endTimestamp", deviceSession.getEndTimestamp()); + environment.setUseUser(jsonObject); + } + return environment; + } + + @Override + public Page queryList(Map params) { + Page page = T.PageUtil.getPage(params); + List packageList = this.getBaseMapper().queryList(page, params); + + for (EnvironmentEntity entity : packageList) { + entity.setParam(entity.getParamJSONObject()); + } + page.setRecords(packageList); + return page; + } + + @Override + public EnvironmentEntity saveDevice(EnvironmentEntity entity) { + // param + entity.setParam(entity.getParamStr()); + + // default android + entity.setPlatform(T.StrUtil.emptyToDefault(entity.getPlatform(), "android")); + + entity.setCreateTimestamp(System.currentTimeMillis()); + entity.setUpdateTimestamp(System.currentTimeMillis()); + entity.setCreateUserId(StpUtil.getLoginIdAsString()); + entity.setUpdateUserId(StpUtil.getLoginIdAsString()); + // save + this.save(entity); + + EnvironmentWorkspaceEntity environmentWorkspace = new EnvironmentWorkspaceEntity(); + environmentWorkspace.setEnvId(entity.getId()); + environmentWorkspace.setWorkspaceId(entity.getWorkspaceId()); + environmentWorkspace.setCreateUserId(StpUtil.getLoginIdAsString()); + environmentWorkspace.setCreateTimestamp(System.currentTimeMillis()); + deviceWorkspaceService.save(environmentWorkspace); + return entity; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void removeDevice(List ids) { + // remove + this.removeBatchByIds(ids); + + // session + deviceSessionService.remove(new LambdaQueryWrapper().in(EnvironmentSessionEntity::getEnvId, ids)); + + //device workspace + deviceWorkspaceService.remove(new LambdaQueryWrapper().in(EnvironmentWorkspaceEntity::getEnvId, ids)); + } + + @Override + public Page mySession(Map params) { + String currentUserId = StpUtil.getLoginIdAsString(); + params.put("currentUserId", currentUserId); + Page page = new Query(EnvironmentEntity.class).getPage(params); + + List packageList = this.getBaseMapper().mySession(page, params); + page.setRecords(packageList); + return page; + } + +} \ No newline at end of file diff --git a/src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentSessionServiceImpl.java b/src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentSessionServiceImpl.java new file mode 100644 index 0000000..651370f --- /dev/null +++ b/src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentSessionServiceImpl.java @@ -0,0 +1,15 @@ +package net.geedge.asw.module.environment.service.impl; + +import cn.hutool.log.Log; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import net.geedge.asw.module.environment.dao.EnvironmentSessionDao; +import net.geedge.asw.module.environment.entity.EnvironmentSessionEntity; +import net.geedge.asw.module.environment.service.IEnvironmentSessionService; +import org.springframework.stereotype.Service; + +@Service +public class EnvironmentSessionServiceImpl extends ServiceImpl implements IEnvironmentSessionService { + + private static final Log log = Log.get(); + +} diff --git a/src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentWorkspaceServiceImpl.java b/src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentWorkspaceServiceImpl.java new file mode 100644 index 0000000..635ed18 --- /dev/null +++ b/src/main/java/net/geedge/asw/module/environment/service/impl/EnvironmentWorkspaceServiceImpl.java @@ -0,0 +1,11 @@ +package net.geedge.asw.module.environment.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import net.geedge.asw.module.environment.dao.EnvironmentWorkspaceDao; +import net.geedge.asw.module.environment.entity.EnvironmentWorkspaceEntity; +import net.geedge.asw.module.environment.service.IEnvironmentWorkspaceService; +import org.springframework.stereotype.Service; + +@Service +public class EnvironmentWorkspaceServiceImpl extends ServiceImpl implements IEnvironmentWorkspaceService { +} diff --git a/src/main/java/net/geedge/asw/module/device/util/DeviceUtil.java b/src/main/java/net/geedge/asw/module/environment/util/EnvironmentUtil.java similarity index 86% rename from src/main/java/net/geedge/asw/module/device/util/DeviceUtil.java rename to src/main/java/net/geedge/asw/module/environment/util/EnvironmentUtil.java index ad73992..289d260 100644 --- a/src/main/java/net/geedge/asw/module/device/util/DeviceUtil.java +++ b/src/main/java/net/geedge/asw/module/environment/util/EnvironmentUtil.java @@ -1,4 +1,4 @@ -package net.geedge.asw.module.device.util; +package net.geedge.asw.module.environment.util; import cn.hutool.core.net.url.UrlBuilder; import cn.hutool.core.net.url.UrlPath; @@ -16,7 +16,7 @@ import jakarta.servlet.http.Part; import net.geedge.asw.common.util.ASWException; import net.geedge.asw.common.util.Constants; import net.geedge.asw.common.util.T; -import net.geedge.asw.module.device.entity.DeviceEntity; +import net.geedge.asw.module.environment.entity.EnvironmentEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ByteArrayResource; @@ -33,22 +33,22 @@ import java.util.*; @Configuration @SuppressWarnings("all") -public class DeviceUtil { +public class EnvironmentUtil { private static Log log = Log.get(); private static RestTemplate restTemplate; - public static void getForObject(DeviceEntity device, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + public static void getForObject(EnvironmentEntity device, HttpServletRequest request, HttpServletResponse response, String sessionId) throws IOException, ServletException { // path String pathProfix = T.StrUtil.concat(true, Constants.DEVICE_API_PREFIX, "/", device.getId()); - String path = request.getServletPath().replace(pathProfix,""); + String[] paths = request.getServletPath().split(sessionId); + String path = Arrays.asList(paths).getLast(); path = path.startsWith("/") ? (String.format("%s%s", Constants.DEVICE_API_PREFIX, path)) : (String.format("%s/%s", Constants.DEVICE_API_PREFIX, path)); // host port token JSONObject jsonObject = device.getParamJSONObject(); - String host = jsonObject.getStr("host"); - String port = jsonObject.getStr("port"); + String url = jsonObject.getStr("url"); String token = jsonObject.getStr("token"); // query param @@ -56,14 +56,11 @@ public class DeviceUtil { queryString = StrUtil.isNotBlank(queryString) ? queryString : ""; queryString = URLUtil.decode(queryString); - String urlStr = new UrlBuilder( - "http", - host, - Integer.valueOf(port), - UrlPath.of(path, Charset.forName("UTF-8")), - UrlQuery.of(queryString, Charset.forName("UTF-8"), false, true), - null, - StandardCharsets.UTF_8).toString(); + + String urlStr = UrlBuilder.of(url) + .setPath(UrlPath.of(path, Charset.forName("UTF-8"))) + .setQuery(UrlQuery.of(queryString, Charset.forName("UTF-8"), false, true)) + .setCharset(StandardCharsets.UTF_8).toString(); // token HttpHeaders headers = new HttpHeaders(); @@ -147,7 +144,7 @@ public class DeviceUtil { @Autowired public void setRestTemplate(RestTemplate restTemplate) { - DeviceUtil.restTemplate = restTemplate; + EnvironmentUtil.restTemplate = restTemplate; } } diff --git a/src/main/resources/db/mapper/device/DeviceMapper.xml b/src/main/resources/db/mapper/device/DeviceMapper.xml deleted file mode 100644 index a4aec0f..0000000 --- a/src/main/resources/db/mapper/device/DeviceMapper.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/db/mapper/device/EnvironmentMapper.xml b/src/main/resources/db/mapper/device/EnvironmentMapper.xml new file mode 100644 index 0000000..b395e36 --- /dev/null +++ b/src/main/resources/db/mapper/device/EnvironmentMapper.xml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/migration/R__AZ_sys_i18n.sql b/src/main/resources/db/migration/R__AZ_sys_i18n.sql index 255238f..8c93e58 100644 --- a/src/main/resources/db/migration/R__AZ_sys_i18n.sql +++ b/src/main/resources/db/migration/R__AZ_sys_i18n.sql @@ -121,5 +121,9 @@ INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_ INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (199, '100017', 'SYS_ROLE_BUILT_IN', '内置权限不能删除或修改', 'zh', '', 'admin', 1724030366000); INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (201, '100018', 'SYS_ROLE_NOT_DELETE', 'Used role cannot be delete', 'en', '', 'admin', 1724030366000); INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (203, '100018', 'SYS_ROLE_NOT_DELETE', '已使用权限不能删除', 'zh', '', 'admin', 1724030366000); +INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (205, '601001', 'ENVIRONMENT_SESSION_NOT_EXIST', 'environment session does not exist', 'en', '', 'admin', 1724030366000); +INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (207, '601001', 'ENVIRONMENT_SESSION_NOT_EXIST', '会话不存在', 'zh', '', 'admin', 1724030366000); +INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (209, '601002', 'ENVIRONMENT_NOT_EXIST', 'environment does not exist', 'en', '', 'admin', 1724030366000); +INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (211, '601002', 'ENVIRONMENT_NOT_EXIST', '环境不存在', 'zh', '', 'admin', 1724030366000); SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql b/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql index f423839..3a362f5 100644 --- a/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql +++ b/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql @@ -462,10 +462,10 @@ INSERT INTO `workspace_member` (`workspace_id`, `user_id`, `role_id`, `create_ti /** - * 新增 device 表 + * 新增 environment 表 */ -DROP TABLE IF EXISTS `device`; -CREATE TABLE `device` ( +DROP TABLE IF EXISTS `environment`; +CREATE TABLE `environment` ( `id` varchar(64) NOT NULL COMMENT '主键', `name` varchar(256) NOT NULL DEFAULT '' COMMENT '名称', `location` varchar(256) NOT NULL DEFAULT '' COMMENT '位置', @@ -478,24 +478,37 @@ CREATE TABLE `device` ( `update_timestamp` bigint(20) NOT NULL COMMENT '更新时间戳', `create_user_id` varchar(64) NOT NULL COMMENT '创建人', `update_user_id` varchar(64) NOT NULL COMMENT '更新人', - `workspace_id` varchar(64) NOT NULL DEFAULT '' COMMENT '工作空间ID', PRIMARY KEY (`id`) USING BTREE, KEY `idx_name` (`name`) USING BTREE, - KEY `idx_status` (`status`) USING BTREE, - KEY `idx_workspace_id` (`workspace_id`) USING BTREE + KEY `idx_status` (`status`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; /** - * 新增 device_log 表 + * 新增 environment_workspace 表 */ -DROP TABLE IF EXISTS `device_log`; -CREATE TABLE `device_log` ( +DROP TABLE IF EXISTS `environment_workspace`; +CREATE TABLE `environment_workspace` ( + `id` varchar(64) NOT NULL COMMENT '主键', + `env_id` varchar(64) NOT NULL DEFAULT '' COMMENT '名称', + `workspace_id` varchar(64) NOT NULL DEFAULT '' COMMENT '位置', + `create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳', + `create_user_id` varchar(64) NOT NULL COMMENT '创建人', + PRIMARY KEY (`id`) USING BTREE, + KEY `idx_workspace_id` (`workspace_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + + +/** + * 新增 environment_session 表 + */ +DROP TABLE IF EXISTS `environment_session`; +CREATE TABLE `environment_session` ( `id` varchar(64) NOT NULL COMMENT '主键', - `device_id` varchar(64) NOT NULL DEFAULT '' COMMENT '设备id', + `env_id` varchar(64) NOT NULL DEFAULT '' COMMENT '设备id', `user_id` varchar(64) NOT NULL DEFAULT '' COMMENT '用户id', `start_timestamp` bigint(20) NOT NULL COMMENT '开始时间', - `end_timestamp` bigint(20) NOT NULL COMMENT '结束时间', + `end_timestamp` bigint(20) NOT NULL DEFAULT -1 COMMENT '结束时间', `status` int(1) NOT NULL DEFAULT 1 COMMENT '状态,1:使用中;2:已结束', `job_id` varchar(64) NOT NULL DEFAULT '' COMMENT '任务id', `workspace_id` varchar(64) NOT NULL DEFAULT '' COMMENT '工作空间ID',