Browse Source

增加资源删除接口

chenlei1231 3 months ago
parent
commit
71d276f55a

+ 6 - 1
jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/WebsocketConst.java

@@ -29,6 +29,11 @@ public class WebsocketConst {
     public static final String MSG_USER_ID = "userId";
 
     /**
+     * 消息json key:msgTitle
+     */
+    public static final String MSG_TITLE = "msgTitle";
+
+    /**
      * 消息json key:chat
      */
     public static final String MSG_CHAT = "chat";
@@ -51,7 +56,7 @@ public class WebsocketConst {
     /**
      * 消息类型 user 用户消息
      */
-    public static final String CMD_CREATE_SITE = "create_site";
+    public static final String CMD_MANAGE_SITE = "manage_site";
 
     /**
      * 消息类型 topic 系统通知

+ 2 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/common/service/WebSocketService.java

@@ -17,9 +17,10 @@ public class WebSocketService {
     @Resource
     private WebSocket webSocket;
 
-    public void sendMessage(String[] userIds, String message, String CMD) {
+    public void sendMessage(String[] userIds, String title, String message, String CMD) {
         JSONObject obj = new JSONObject();
         obj.put(WebsocketConst.MSG_CMD, CMD);
+        obj.put(WebsocketConst.MSG_TITLE, title);
         obj.put(WebsocketConst.MSG_TXT, message);
         webSocket.sendMessage(userIds, obj.toJSONString());
     }

+ 1 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/service/impl/AdwebEnquiryServiceImpl.java

@@ -314,7 +314,7 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
         String[] userIds = {targetSite.getUid(), sysUser.getId()};
 
         // TODO 之后仅对有效询盘进行发送消息通知
-        webSocketService.sendMessage(userIds, "您已经收到询盘,请尽快处理", WebsocketConst.CMD_ENQUIRY);
+        webSocketService.sendMessage(userIds, "询盘通知", "您已经收到询盘,请尽快处理", WebsocketConst.CMD_ENQUIRY);
 
 
         // 发送询盘邮件

+ 34 - 7
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/site/controller/AdwebSiteController.java

@@ -17,18 +17,23 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.FastJsonUtil;
+import org.jeecg.config.security.utils.SecureUtil;
 import org.jeecg.modules.adweb.common.constant.AdwebConstant;
 import org.jeecg.modules.adweb.seo.mapper.SeoPlanSubscriptionMapper;
 import org.jeecg.modules.adweb.site.dto.param.SiteStepDTO;
 import org.jeecg.modules.adweb.site.entity.AdwebSite;
+import org.jeecg.modules.adweb.site.entity.AdwebSitePermission;
 import org.jeecg.modules.adweb.site.service.IAdwebSiteService;
+import org.jeecg.modules.adweb.site.service.ISitePermissionService;
 import org.jeecg.modules.adweb.site.service.ISiteUserPermissionService;
+import org.jeecg.modules.adweb.site.service.SelfWebSiteService;
 import org.jeecg.modules.adweb.system.service.SysAdwebApi;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.jeecg.modules.base.service.BaseCommonService;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.servlet.ModelAndView;
@@ -49,18 +54,26 @@ import java.util.Map;
 @Slf4j
 public class AdwebSiteController extends JeecgController<AdwebSite, IAdwebSiteService> {
 
-    @Autowired
+    @Resource
     private IAdwebSiteService adwebSiteService;
 
-    @Autowired
+    @Resource
     private SysAdwebApi sysAdwebApi;
 
-    @Autowired
+    @Resource
     private ISiteUserPermissionService siteUserPermissionService;
 
     @Resource
+    private ISitePermissionService sitePermissionService;
+
+    @Resource
     private SeoPlanSubscriptionMapper seoPlanSubscriptionMapper;
 
+    @Resource
+    private SelfWebSiteService selfWebSiteService;
+
+    @Resource
+    private BaseCommonService baseCommonService;
 
     /**
      * 分页列表查询
@@ -148,10 +161,24 @@ public class AdwebSiteController extends JeecgController<AdwebSite, IAdwebSiteSe
     @PreAuthorize("@jps.requiresPermissions('adweb:adweb_site:delete')")
     @DeleteMapping(value = "/delete")
     public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
-//        adwebSiteService.removeById(id);
-
         AdwebSite adwebSite = adwebSiteService.getById(id);
-        return Result.error("该站点资源已经不存在, 站点信息将从系统中删除!");
+
+        // 删除站点权限
+        QueryWrapper<AdwebSitePermission> queryWrapper = new QueryWrapper<AdwebSitePermission>();
+        queryWrapper.eq("site_code", adwebSite.getCode());
+        sitePermissionService.remove(queryWrapper);
+
+        // 远程删除并备份站点资源
+        LoginUser user = SecureUtil.currentUser();
+        selfWebSiteService.removeSite(user, adwebSite);
+
+        // 删除该站点数据
+        adwebSiteService.removeById(id);
+
+        // 记录删除站点操作日志
+        baseCommonService.addLog("站点" + adwebSite.getDomain() + "资源已被删除,将在服务器自动备份15天,之后将自动清空:", CommonConstant.LOG_TYPE_2, 3);
+
+        return Result.ok("该站点资源已经不存在, 站点信息将从系统中删除!");
     }
 
     /**

+ 23 - 18
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/site/service/SelfWebSiteService.java

@@ -118,7 +118,7 @@ public class SelfWebSiteService {
                         String[] userIds = {user.getId()};
                         // 给该站点所属的用户发送消息
                         log.info("发送创建站点通知");
-                        webSocketService.sendMessage(userIds, "您的站点已经创建成功,请在站点管理中查看该站点详细信息", WebsocketConst.CMD_CREATE_SITE);
+                        webSocketService.sendMessage(userIds, "站点创建完成通知", "您的站点已经创建成功,请在站点管理中查看该站点详细信息", WebsocketConst.CMD_MANAGE_SITE);
                     }
                 }
 
@@ -139,11 +139,12 @@ public class SelfWebSiteService {
         }
     }
 
-    public void removeSite(AdwebSite adwebSite) {
+    @Async
+    public void removeSite(LoginUser user, AdwebSite adwebSite) {
         try {
 
             // 执行临时服务器shell脚本,生成临时站点
-            String cmd = "sh /opt/adweb3/shell/remove-and-bak-wpsite " + adwebSite.getCode();
+            String cmd = "sh /opt/adweb3/shell/remove-and-bak-wpsite.sh " + adwebSite.getCode();
 
             AdwebSite finalAdwebSite = adwebSite;
             shellService.createShareSiteByPwd(cmd, host, port, username, password, new ShellSSH2Util.StdoutListener() {
@@ -152,19 +153,12 @@ public class SelfWebSiteService {
                     log.info("标准 :{}", line);
 
                     if (line.startsWith("执行命令成功")) {
-                        log.info("站点创建成功!更新站点状态");
-
-                        // 更新站点流程状态
-                        siteService.updateSiteFlow(finalAdwebSite.getCode());
-
-                        // 临时站点创建成功
-                        finalAdwebSite.setStatus(2);
-                        siteService.updateById(finalAdwebSite);
+                        log.info("站点资源删除成功!");
 
-//                        String[] userIds = {user.getId()};
-//                        // 给该站点所属的用户发送消息
-//                        log.info("发送创建站点通知");
-//                        webSocketService.sendMessage(userIds, "您的站点已经创建成功,请在站点管理中查看该站点详细信息", WebsocketConst.CMD_CREATE_SITE);
+                        String[] userIds = {user.getId()};
+                        // 给该站点所属的用户发送消息
+                        log.info("发送删除站点资源通知");
+                        webSocketService.sendMessage(userIds, "站点删除通知", "站点资源" + finalAdwebSite.getDomain() + "已经从系统删除!", WebsocketConst.CMD_MANAGE_SITE);
                     }
                 }
 
@@ -177,14 +171,25 @@ public class SelfWebSiteService {
 
 
             if (StringUtils.isNotBlank(errorMsg)) {
-                createSiteFailed(adwebSite, errorMsg);
+                exceShellFailed("删除站点资源", adwebSite, errorMsg);
             }
         } catch (Exception e) {
-            log.error("在wp服务器上生成站点文件失败");
-            createSiteFailed(adwebSite, e.getMessage());
+            log.error("在wp服务器上删除站点资源失败");
+            exceShellFailed("删除站点资源", adwebSite, e.getMessage());
         }
     }
 
+    private void exceShellFailed(String cmd, AdwebSite adwebSite, String errorMsg) {
+        SysException sysException = new SysException();
+
+        sysException.setType(1);
+        sysException.setFunctionModule(cmd);
+        sysException.setExceptionDetail(String.format("站点code:%s, 站点名称:%s,临时连接:%s", adwebSite.getCode(), adwebSite.getName(), adwebSite.getDomain()));
+        sysException.setExceptionDescription(errorMsg);
+
+        sysExceptionService.save(sysException);
+    }
+
     private void createSiteFailed(AdwebSite adwebSite, String errorMsg) {
         adwebSite.setStatus(4); // 临时站点创建失败
         siteService.updateById(adwebSite);