Explorar el Código

soc-modules-deploy模块后台代码迁移-管理类接口路径优化

humingshi-7@163.com hace 1 año
padre
commit
690dce5bdd

+ 65 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/AgentPackageController.java

@@ -0,0 +1,65 @@
+package com.xunmei.deploy.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.deploy.domain.PackageInfo;
+import com.xunmei.deploy.service.PackageInfoService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * 白令海管理-白令海版本管理
+ */
+@RestController
+@RequestMapping("/agentPackage")
+public class AgentPackageController   extends BaseController{
+
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private PackageInfoService packageInfoService;
+
+    /**
+     * 白令海管理-白令海版本管理-列表
+     */
+    @RequestMapping("/list")
+    public TableDataInfo list(Page<PackageInfo> page){
+        IPage<PackageInfo> result = packageInfoService.selectPage(page);
+
+        return getDataTable(result);
+    }
+
+    /**
+     * 白令海管理-白令海版本管理-上传升级包
+     */
+    @RequestMapping("/upload")
+    public AjaxResult upload(MultipartFile file){
+        try {
+            packageInfoService.uploadZip(file);
+            return AjaxResult.success("升级包上传成功");
+        }catch (Exception e){
+            logger.error("白令海管理-白令海版本管理:上传升级包出现异常{}",e);
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 白令海管理-白令海版本管理-删除升级包
+     */
+    @RequestMapping("/delete/{id}")
+    public AjaxResult delete(@PathVariable("id") String id){
+        try {
+            packageInfoService.delAgentZip(id);
+            return AjaxResult.success("删除成功!");
+        }catch (Exception e){
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+}

+ 89 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/AgentUpgradeStatusController.java

@@ -0,0 +1,89 @@
+package com.xunmei.deploy.controller;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.deploy.domain.HostInfo;
+import com.xunmei.deploy.domain.PackageInfo;
+import com.xunmei.deploy.service.HostInfoService;
+import com.xunmei.deploy.service.PackageInfoService;
+import com.xunmei.deploy.util.CommonUtils;
+import com.xunmei.deploy.vo.HostInfoVo;
+import com.xunmei.deploy.vo.UploadAgentVo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import java.util.List;
+
+/**
+ * 白令海管理-白令海版本升级
+ */
+@RestController
+@RequestMapping("/agentUpgrade")
+public class AgentUpgradeStatusController   extends BaseController{
+
+    private Logger logger = LoggerFactory.getLogger(getClass());
+    @Autowired
+    private HostInfoService hostInfoService;
+    @Autowired
+    private PackageInfoService packageInfoService;
+
+    /**
+     * 白令海管理-白令海版本升级-列表
+     */
+    @RequestMapping("/list")
+    public TableDataInfo list(Page<HostInfo> page, HostInfo info){
+        IPage<HostInfoVo> hostInfoIPage = hostInfoService.selectPage(page, info);
+
+        return getDataTable(hostInfoIPage);
+    }
+
+
+    /**
+     * 白令海管理-白令海版本升级-(升级、批量升级)下拉框
+     */
+    @RequestMapping("/selectPackages")
+    public AjaxResult selectPackages(){
+        List<PackageInfo> packageVersion = packageInfoService.getPackageVersion();
+
+        JSONArray array = new JSONArray();
+        JSONObject json;
+        for (PackageInfo packageInfo : packageVersion) {
+            json = new JSONObject();
+            json.put("id",String.valueOf(packageInfo.getId()));
+            json.put("text",packageInfo.getPackageVersion());
+            array.add(json);
+        }
+
+        return AjaxResult.success(array);
+    }
+
+
+    /**
+     * 白令海管理-白令海版本升级-(升级、批量升级)操作
+     */
+    @RequestMapping("/upload")
+    public AjaxResult upload(UploadAgentVo uploadAgentVo){
+        try {
+            String msg = packageInfoService.uploadAgentPackage(uploadAgentVo);
+            return AjaxResult.success(msg,null);
+        }catch (Exception e){
+            logger.error("白令海管理-白令海版本升级:升级操作出现异常{}",e);
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
+    /**
+     *  白令海管理-白令海版本升级-当前版本号、目标版本号下拉框
+     */
+    @RequestMapping("/selectAllVersions")
+    public AjaxResult selectAllVersions(){
+        List<String> list = packageInfoService.selectAgentVersion();
+        return AjaxResult.success(CommonUtils.sortVersion(list));
+    }
+}

+ 97 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/AppPackageController.java

@@ -0,0 +1,97 @@
+package com.xunmei.deploy.controller;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.deploy.domain.UploadAppInfo;
+import com.xunmei.deploy.domain.ZipPackInfo;
+import com.xunmei.deploy.service.UploadAppInfoService;
+import com.xunmei.deploy.service.ZipPackInfoService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * 升级包管理
+ */
+@RestController
+@RequestMapping("/appPackage")
+public class AppPackageController extends BaseController{
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private ZipPackInfoService zipPackInfoService;
+    @Autowired
+    private UploadAppInfoService uploadAppInfoService;
+
+
+    /**
+     * 升级包管理-列表
+     */
+    @PostMapping("/list")
+    public TableDataInfo list(Page<ZipPackInfo> page, ZipPackInfo info){
+        IPage<ZipPackInfo> result = zipPackInfoService.selectPage(page,info);
+        return getDataTable(result);
+    }
+
+    /**
+     * 升级包管理-适用主机下拉框
+     */
+    @PostMapping("/selectHostTypes")
+    public AjaxResult selectHostTypes(){
+        List<String> list = zipPackInfoService.getZipHostType();
+
+        JSONArray array = new JSONArray();
+        JSONObject json;
+        for(String name:list){
+            json = new JSONObject();
+            json.put("id",name);
+            json.put("text",name);
+            array.add(json);
+        }
+
+        return AjaxResult.success(array);
+    }
+
+    /**
+     * 升级包管理-详情页(升级包内应用列表)
+     */
+    @RequestMapping("/detail")
+    public AjaxResult detail(String id){
+        List<UploadAppInfo> list = uploadAppInfoService.getListByZipId(id);
+        return AjaxResult.success(list);
+    }
+
+    /**
+     * 升级包管理-上传升级包
+     */
+    @PostMapping("/upload")
+    public AjaxResult upload(MultipartFile file, HttpServletResponse response){
+        try {
+            uploadAppInfoService.uploadZip(file);
+            return AjaxResult.success("压缩包解压完成!");
+        } catch (Exception e) {
+            log.error("升级包管理:上传升级包出现异常:{}",e);
+            response.setStatus(500);
+            return AjaxResult.error("解析包错误:"+e.getMessage());
+        }
+
+    }
+
+    /**
+     * 升级包管理-删除
+     */
+    @RequestMapping("/delete")
+    public AjaxResult delete(String id){
+        return zipPackInfoService.delZip(id);
+    }
+}

+ 222 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/AppUpgradeStatusController.java

@@ -0,0 +1,222 @@
+package com.xunmei.deploy.controller;
+
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.utils.DateUtils;
+import com.xunmei.common.core.utils.StringUtils;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.deploy.domain.BatchHostInfo;
+import com.xunmei.deploy.domain.HostInfo;
+import com.xunmei.deploy.domain.UpgradeBatchInfo;
+import com.xunmei.deploy.domain.UpgradeTask;
+import com.xunmei.deploy.service.UpgradeBatchInfoService;
+import com.xunmei.deploy.service.UpgradeTaskService;
+import com.xunmei.deploy.util.CommonConstraint;
+import jxl.Workbook;
+import jxl.WorkbookSettings;
+import jxl.write.*;
+import jxl.write.biff.RowsExceededException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.util.List;
+
+/**
+ * 升级状态查询
+ */
+@RestController
+@RequestMapping("/appUpgrade")
+public class AppUpgradeStatusController  extends BaseController{
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private UpgradeBatchInfoService upgradeBatchInfoService;
+    @Autowired
+    private UpgradeTaskService upgradeTaskService;
+
+
+    /**
+     * 升级状态查询-列表
+     */
+    @PostMapping("/list")
+    public TableDataInfo list(Page<UpgradeBatchInfo> page, UpgradeBatchInfo info){
+        IPage<UpgradeBatchInfo> result = upgradeBatchInfoService.selectPage(page,info);
+        return getDataTable(result);
+    }
+
+    /**
+     * 升级状态查询-详情
+     */
+    @PostMapping("/detail")
+    public AjaxResult detail(String id, String orgName, Integer status){
+        List<BatchHostInfo> batchHosts = upgradeBatchInfoService.getBatchHosts(id,orgName,status);
+        return AjaxResult.success(batchHosts);
+    }
+    /**
+     * 升级状态查询-详情下的二级详情
+     */
+    @PostMapping("/appsDetail")
+    public AjaxResult appsDetail(String hostId, String batchNumber){
+        List<UpgradeTask> upgradeTasks = upgradeTaskService.batchTask(hostId, batchNumber);
+        for (UpgradeTask upgradeTask : upgradeTasks) {
+            String deployDescription = upgradeTask.getDeployDescription();
+            if (StringUtils.isNotEmpty(deployDescription)) {
+                try {
+                    String[] split = deployDescription.split(CommonConstraint.UpgradeDescriptionConstant.SPLIT);
+                    String desc1 = CommonConstraint.UpgradeDescriptionConstant.DESCRIPTION.get(split[0]);
+                    String desc2 = CommonConstraint.UpgradeDescriptionConstant.DESCRIPTION.get(split[1]);
+                    if (null == desc1 || "null".equals(desc1)) {
+                        desc1 = "";
+                    }
+                    if (null == desc2 || "null".equals(desc2)) {
+                        desc2 = "";
+                    }
+                    upgradeTask.setDeployDescription(desc1 + CommonConstraint.UpgradeDescriptionConstant.SPLIT + desc2);
+                } catch (Exception e) {
+                    log.error("升级状态查询: 详情下的二级详情出现异常{}",e);
+                }
+            }
+        }
+        return AjaxResult.success(upgradeTasks);
+    }
+    /**
+     * 升级状态查询-详情导出
+     */
+    @RequestMapping(value = "/detailExport")
+    public void detailExport(
+            String id,String orgName,Integer status,
+            HttpServletResponse response) throws Exception {
+        Page<HostInfo> page = new Page<>();
+        page.setSize(5000);
+        page.setCurrent(1);
+        List<BatchHostInfo> list = upgradeBatchInfoService.getBatchHosts(id,orgName,status);
+        Label label = null;
+        WritableSheet sheet = null;
+        WritableWorkbook workBook = null;
+        WorkbookSettings settings = new WorkbookSettings();
+        settings.setWriteAccess(null);
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        InputStream is = null;
+        OutputStream out = null;
+        try {
+            workBook = Workbook.createWorkbook(os, settings);
+            sheet = workBook.createSheet("sheet1", 0);
+            sheet.setColumnView(0, 30);//设置Excel的宽度
+            sheet.setColumnView(1, 30);
+            sheet.setColumnView(2, 30);
+            sheet.setColumnView(3, 30);
+            sheet.setColumnView(4, 30);
+            sheet.setColumnView(5, 30);
+            sheet.setColumnView(6, 30);
+            sheet.setColumnView(7, 30);
+            sheet.setColumnView(8, 30);
+            this.addBatchHostDetailToLabel(label, sheet);//向Excel添加标题
+            this.addBatchHostContentToLabel(label, sheet, list);//向Excel添加表格数据
+            workBook.write();
+        } catch (Exception e) {
+            log.error("升级状态查询:详情导出excel异常{}", e);
+        } finally {
+            workBook.close();
+        }
+
+        // 根据批次Id 获取批次code
+        UpgradeBatchInfo byId = upgradeBatchInfoService.getById(id);
+        String batchCode = byId.getBatchCode();
+
+        try {
+            is = new ByteArrayInputStream(os.toByteArray());
+            out = response.getOutputStream();
+            // 设置输出文件信息
+            response.setContentType("application/octet-stream;charset=UTF-8");
+            response.addHeader("Content-Disposition", "attachment;filename=" + new String(("升级主机详情" + batchCode + ".xls").getBytes("gb2312"), "ISO8859-1"));
+            // 写文件流
+            byte[] buffer = new byte[6 * 1024];
+            int len = 0;
+            while ((len = is.read(buffer, 0, buffer.length)) != -1) {
+                out.write(buffer, 0, len);
+            }
+        } catch (IOException e) {
+            log.error("excel导出异常:{}", e);
+        } finally {
+            is.close();
+            out.close();
+        }
+    }
+
+    /**
+     * 升级状态查询-详情导出(给Excel导出增加标题)
+     */
+    private WritableSheet addBatchHostDetailToLabel(Label label, WritableSheet sheet) throws RowsExceededException, WriteException {
+        //设置字体;
+        WritableFont font1 = new WritableFont(WritableFont.ARIAL, 12, WritableFont.BOLD);
+
+        WritableCellFormat cellFormat1 = new WritableCellFormat(font1);
+        label = new Label(0, 0, "序号", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(1, 0, "批次号", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(2, 0, "所属机构", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(3, 0, "版本号", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(4, 0, "状态", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(5, 0, "主机名称", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(6, 0, "主机IP", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(7, 0, "创建时间", cellFormat1);
+        sheet.addCell(label);
+
+        label = new Label(8, 0, "结束时间", cellFormat1);
+        sheet.addCell(label);
+        return sheet;
+    }
+
+    /**
+     * 升级状态查询-详情导出(往Excel中添加内容)
+     */
+    private void addBatchHostContentToLabel(Label label, WritableSheet sheet, List<BatchHostInfo> list) throws Exception {
+        WritableFont writableFont = new WritableFont(WritableFont.createFont("宋体"), 11, WritableFont.NO_BOLD, false);
+        WritableCellFormat writableCellFormat = new WritableCellFormat(writableFont);
+        writableCellFormat.setWrap(true);
+        for (int i = 0; i < list.size(); i++) {
+            BatchHostInfo vdso = list.get(i);
+            label = new Label(0, i + 1, i + 1 + "", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(1, i + 1, StringUtils.isNotEmpty(vdso.getBatchCode()) ? vdso.getBatchCode() : "-", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(2, i + 1, StringUtils.isNotEmpty(vdso.getOrgName()) ? vdso.getOrgName() : "-", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(3, i + 1, StringUtils.isNotEmpty(vdso.getZipVersion()) ? vdso.getZipVersion() : "-", writableCellFormat);
+            sheet.addCell(label);
+            String status = "-";
+            if (vdso.getStatus() == 0) {
+                status = "进行中";
+            } else if (vdso.getStatus() == 1) {
+                status = "成功";
+            } else if (vdso.getStatus() == 2) {
+                status = "失败";
+            } else if (vdso.getStatus() == 3) {
+                status = "重试中";
+            }
+            label = new Label(4, i + 1, status, writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(5, i + 1, StringUtils.isNotEmpty(vdso.getHostName()) ? vdso.getHostName() : "-", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(6, i + 1, StringUtils.isNotEmpty(vdso.getHostIp()) ? vdso.getHostIp() : "-", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(7, i + 1, null != vdso.getCreateTime() ? DateUtil.format(vdso.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS) : "-", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(8, i + 1, null != vdso.getFinishTime() ? DateUtil.format(vdso.getFinishTime(), DateUtils.YYYY_MM_DD_HH_MM_SS) : "-", writableCellFormat);
+            sheet.addCell(label);
+        }
+    }
+}

+ 1 - 4
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/DataController.java

@@ -189,10 +189,7 @@ public class DataController extends BaseController{
      **/
     @PostMapping("/deleteByHostId")
     @Transactional(rollbackFor = Exception.class)
-    public R deleteByHostId(String id,String userId,HttpServletRequest request){
-        if(StringUtils.isEmpty(userId)){
-            return R.fail("删除失败,操作用户为空或会话过期,请尝试重新登录!");
-        }
+    public AjaxResult deleteByHostId(String id,HttpServletRequest request){
         return hostInfoService.deleteByHostId(id);
     }
 

+ 365 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/HostInfoController.java

@@ -0,0 +1,365 @@
+package com.xunmei.deploy.controller;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.zafarkhaja.semver.Version;
+import com.xunmei.common.core.utils.StringUtils;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.deploy.domain.AppRunInfo;
+import com.xunmei.deploy.domain.HostInfo;
+import com.xunmei.deploy.domain.UpgradeTask;
+import com.xunmei.deploy.domain.ZipPackInfo;
+import com.xunmei.deploy.service.*;
+import com.xunmei.deploy.util.CommonUtils;
+import com.xunmei.deploy.vo.HostInfoVo;
+import jxl.Workbook;
+import jxl.WorkbookSettings;
+import jxl.write.*;
+import jxl.write.biff.RowsExceededException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * 主机管理
+ */
+@RestController
+@RequestMapping("/hostInfo")
+public class HostInfoController  extends BaseController{
+
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private HostInfoService hostInfoService;
+    @Autowired
+    private AppRunInfoService appRunInfoService;
+    @Autowired
+    private UpgradeBatchInfoService upgradeBatchInfoService;
+    @Autowired
+    private ZipPackInfoService zipPackInfoService;
+    @Autowired
+    private FrontTaskService frontTaskService;
+    @Autowired
+    private UpgradeTaskService upgradeTaskService;
+    @Autowired
+    private HostZipInfoService hostZipInfoService;
+
+    /**
+     * 主机管理-列表
+     * @param page
+     * @param hostInfoVo
+     * @return
+     */
+    @PostMapping("/list")
+    public TableDataInfo list(Page<HostInfo> page, HostInfoVo hostInfoVo){
+        IPage<HostInfoVo> result = hostInfoService.selectHostInfoPage(page, hostInfoVo);
+        return getDataTable(result);
+    }
+    /**
+     * 主机管理--详情页(应用列表)
+     * @param hostId
+     * @return
+     */
+    @PostMapping("/detail")
+    public AjaxResult detail(String hostId){
+        List<AppRunInfo> appRunningInfos = appRunInfoService.getByHostId(hostId);
+        return AjaxResult.success(appRunningInfos);
+    }
+
+    /**
+     * 主机管理--批量升级
+     */
+    @PostMapping("/batchUpgrade")
+    public AjaxResult batchUpgrade(String zipId, @RequestParam("hostIds") String[] hostIds){
+        try {
+            String msg = upgradeBatchInfoService.addHostUpgradeBatch(zipId, hostIds);
+            return AjaxResult.success(msg);
+        } catch (Exception e) {
+            log.error("主机管理:批量升级出现异常{}",e);
+            return AjaxResult.error("升级批次创建失败,"+e.getMessage());
+        }
+    }
+
+    /**
+     * 主机管理--批量升级-先获取已上传的升级包下拉框
+     * @return
+     */
+    @RequestMapping("/selectPackages")
+    public AjaxResult selectPackages(){
+        List<ZipPackInfo> list = zipPackInfoService.getList();
+        Collections.sort(list, new Comparator<ZipPackInfo>() {
+            @Override
+            public int compare(ZipPackInfo o1, ZipPackInfo o2) {
+                String o1ZipVersion = o1.getZipVersion();
+                String o2ZipVersion = o2.getZipVersion();
+                Version oldVersion,newVersion;
+                try {
+                    oldVersion = Version.valueOf(o1ZipVersion);
+                } catch (Exception e) {
+                    oldVersion = Version.valueOf("1.0.0");
+                }
+                try {
+                    newVersion = Version.valueOf(o2ZipVersion);
+                } catch (Exception e) {
+                    newVersion = Version.valueOf("1.0.0");
+                }
+                if (oldVersion.compareTo(newVersion) > 0){
+                    return -1;
+                } else if (oldVersion.compareTo(newVersion) < 0) {
+                    return 1;
+                } else {
+                    return 0;
+                }
+            }
+        });
+        JSONArray array = new JSONArray();
+        JSONObject json;
+        for (ZipPackInfo zipPackInfo : list) {
+            json = new JSONObject();
+            json.put("id",zipPackInfo.getId());
+            if (StringUtils.isEmpty(zipPackInfo.getHostTypeName())){
+                json.put("text",zipPackInfo.getZipVersion());
+            }else {
+                json.put("text",zipPackInfo.getZipVersion() + "-" + zipPackInfo.getHostTypeName());
+            }
+            array.add(json);
+        }
+        return AjaxResult.success(array);
+    }
+
+    /**
+     *  主机管理--批量升级-先根据页面勾选的主机筛选出可升级的主机hostIds,返回给页面操作升级
+     */
+    @PostMapping("/batchUpgradeValidate")
+    public AjaxResult batchUpgradeValidate(String upgradeZipId,@RequestParam("hostIds") String[] hostIds){
+        if(StringUtils.isEmpty(upgradeZipId)){
+            log.error("主机管理--批量升级:前置验证,传入参数upgradeZipId为空");
+            return AjaxResult.error("请选择升级包!");
+        }
+        if(hostIds == null || hostIds.length == 0){
+            log.error("主机管理--批量升级:前置验证,传入参数hostIds为空");
+            return AjaxResult.error("请选择需要升级的主机!");
+        }
+        try {
+            Map<String, Object> data = upgradeBatchInfoService.validateHostBatch(upgradeZipId, hostIds);
+            return AjaxResult.success(data);
+        } catch (Exception e) {
+            log.error("主机管理--批量升级:前置验证,出现异常{}",e);
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 主机管理--重启服务(创建任务)
+     * @param hostId
+     **/
+    @PostMapping("/restartApps")
+    public AjaxResult restartApps(String hostId){
+        try {
+            frontTaskService.createRestartAppTask(hostId);
+            return AjaxResult.success();
+        } catch (Exception e) {
+            log.error("主机管理-重启服务(创建任务)出现异常:{}",e);
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
+
+    /**
+     * 主机管理--删除主机
+     **/
+    @PostMapping("/delete")
+    @Transactional(rollbackFor = Exception.class)
+    public AjaxResult delete(String id, HttpServletRequest request){
+        return hostInfoService.deleteByHostId(id);
+    }
+
+    /**
+     * 主机管理--删除主机-先验证主机是否存在升级任务
+     * @param hostId
+     * @return
+     */
+    @RequestMapping("/deleteValidate")
+    @ResponseBody
+    public AjaxResult deleteValidate(String hostId){
+        try {
+            List<UpgradeTask> list = upgradeTaskService.getByHostId(hostId);
+            return AjaxResult.success(list);
+        } catch (Exception e) {
+            log.error("主机管理--删除主机-查询主机当前的升级任务出现异常:{}",e);
+            return AjaxResult.error("获取任务失败,"+e.getMessage());
+        }
+    }
+
+    /**
+     * 主机管理--当前版本号下拉框
+     **/
+    @RequestMapping("/selectCurrentVersions")
+    public AjaxResult selectCurrentVersions(){
+        List<String> list = hostZipInfoService.selectOldList();
+        return AjaxResult.success(CommonUtils.sortVersion(list));
+    }
+    /**
+     * 主机管理--目标版本号下拉框
+     **/
+    @RequestMapping("/selectTargetVersions")
+    public AjaxResult selectTargetVersions(){
+        List<String> list = hostZipInfoService.selectTargetList();
+        return AjaxResult.success(CommonUtils.sortVersion(list));
+    }
+
+    /**
+     *  主机管理--导出
+     */
+    @RequestMapping(value = "/export")
+    public void hostInfoListExport(
+            HostInfoVo hostInfoVo,
+            HttpServletResponse response) throws Exception {
+        Page<HostInfo> page = new Page<>();
+        page.setSize(5000);
+        page.setCurrent(1);
+        IPage<HostInfoVo> result = hostInfoService.selectHostInfoPage(page, hostInfoVo);
+
+        List<HostInfoVo> list = result.getRecords();
+        Label label = null;
+        WritableSheet sheet = null;
+        WritableWorkbook workBook = null;
+        WorkbookSettings settings = new WorkbookSettings();
+        settings.setWriteAccess(null);
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        InputStream is = null;
+        OutputStream out = null;
+        try {
+            workBook = Workbook.createWorkbook(os, settings);
+            sheet = workBook.createSheet("sheet1", 0);
+            sheet.setColumnView(0, 30);//设置Excel的宽度
+            sheet.setColumnView(1, 30);
+            sheet.setColumnView(2, 30);
+            sheet.setColumnView(3, 30);
+            sheet.setColumnView(4, 30);
+            sheet.setColumnView(5, 30);
+            sheet.setColumnView(6, 30);
+            sheet.setColumnView(7, 30);
+            sheet.setColumnView(8, 30);
+            sheet.setColumnView(9, 30);
+            sheet.setColumnView(10, 30);
+            sheet.setColumnView(11, 30);
+            this.addHostInfoToLabel(label, sheet);//向Excel添加标题
+            this.addHostContentInfoToLabel(label, sheet, list);//向Excel添加表格数据
+            workBook.write();
+        } catch (Exception e) {
+            log.error("主机管理:导出excel处理数据出现异常:{}", e);
+        } finally {
+            workBook.close();
+        }
+        try {
+            is = new ByteArrayInputStream(os.toByteArray());
+            out = response.getOutputStream();
+            // 设置输出文件信息
+            response.setContentType("application/octet-stream;charset=UTF-8");
+            response.addHeader("Content-Disposition", "attachment;filename=" + new String(("主机管理列表" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls").getBytes("gb2312"), "ISO8859-1"));
+            // 写文件流
+            byte[] buffer = new byte[6 * 1024];
+            int len = 0;
+            while ((len = is.read(buffer, 0, buffer.length)) != -1) {
+                out.write(buffer, 0, len);
+            }
+        } catch (IOException e) {
+            log.error("主机管理:导出excel处理流出现异常:{}", e);
+        } finally {
+            is.close();
+            out.close();
+        }
+    }
+
+    /**
+     * 主机管理-列表导出(给Excel导出增加标题)
+     */
+    private WritableSheet addHostInfoToLabel(Label label, WritableSheet sheet) throws RowsExceededException, WriteException {
+        WritableFont font1 = new WritableFont(WritableFont.ARIAL, 12, WritableFont.BOLD);
+        WritableCellFormat cellFormat1 = new WritableCellFormat(font1);
+        label = new Label(0, 0, "序号", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(1, 0, "所属机构", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(2, 0, "主机名称", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(3, 0, "主机IP", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(4, 0, "当前版本号", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(5, 0, "目标版本号", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(6, 0, "升级状态", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(7, 0, "服务状态", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(8, 0, "白令海状态", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(9, 0, "传输加密", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(10, 0, "白令海版本号", cellFormat1);
+        sheet.addCell(label);
+        label = new Label(11, 0, "注册时间", cellFormat1);
+        sheet.addCell(label);
+        return sheet;
+    }
+
+    /**
+     * 主机管理-列表导出(往Excel中添加内容)
+     */
+    private void addHostContentInfoToLabel(Label label, WritableSheet sheet, List<HostInfoVo> list) throws Exception {
+        WritableFont writableFont = new WritableFont(WritableFont.createFont("宋体"), 11, WritableFont.NO_BOLD, false);
+        WritableCellFormat writableCellFormat = new WritableCellFormat(writableFont);
+        writableCellFormat.setWrap(true);
+        for (int i = 0; i < list.size(); i++) {
+            HostInfoVo vdso = list.get(i);
+            label = new Label(0, i + 1, i + 1 + "", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(1, i + 1, StringUtils.isNotEmpty(vdso.getHostOrgName()) ? vdso.getHostOrgName() : "-", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(2, i + 1, StringUtils.isNotEmpty(vdso.getHostName()) ? vdso.getHostName() : "-", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(3, i + 1, StringUtils.isNotEmpty(vdso.getHostIp()) ? vdso.getHostIp() : "-", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(4, i + 1, StringUtils.isNotEmpty(vdso.getZipVersion()) ? vdso.getZipVersion() : "-", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(5, i + 1, StringUtils.isNotEmpty(vdso.getTargetVersion()) ? vdso.getTargetVersion() : "-", writableCellFormat);
+            sheet.addCell(label);
+            String updateStatusStr = "-";
+            if (vdso.getUpdateStatus() == null) {
+                updateStatusStr = "-";
+            } else if (vdso.getUpdateStatus() == 0) {
+                updateStatusStr = "进行中";
+            } else if (vdso.getUpdateStatus() == 1) {
+                updateStatusStr = "成功";
+            } else if (vdso.getUpdateStatus() == 2) {
+                updateStatusStr = "失败";
+            } else if (vdso.getUpdateStatus() == 3) {
+                updateStatusStr = "重试中";
+            }
+            label = new Label(6, i + 1, updateStatusStr, writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(7, i + 1, vdso.getServerStatus() == 1 ? "正常" : "异常", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(8, i + 1, vdso.getHostStatus() == 1 ? "在线" : "离线", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(9, i + 1, vdso.getEncryption() == 1 ? "是" : "否", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(10, i + 1, StringUtils.isNotEmpty(vdso.getAgentVersion()) ? vdso.getAgentVersion() : "-", writableCellFormat);
+            sheet.addCell(label);
+            label = new Label(11, i + 1, StringUtils.isNotEmpty(vdso.getRegisterDateTime()) ? vdso.getRegisterDateTime() : "-", writableCellFormat);
+            sheet.addCell(label);
+        }
+    }
+}

+ 2 - 2
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/HostInfoService.java

@@ -2,7 +2,7 @@ package com.xunmei.deploy.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.xunmei.common.core.domain.R;
+import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.deploy.domain.HostInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.xunmei.deploy.vo.HostInfoVo;
@@ -17,7 +17,7 @@ public interface HostInfoService extends IService<HostInfo> {
 
     IPage<HostInfoVo> selectHostInfoPage(Page<HostInfo> page, HostInfoVo hostInfoVo);
     HostInfoVo getInfoById(String id);
-    R deleteByHostId(String hostId);
+    AjaxResult deleteByHostId(String hostId);
 
     /**
      * 查询列表的所有主机

+ 4 - 4
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/impl/HostInfoServiceImpl.java

@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.OrderItem;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.xunmei.common.core.domain.R;
+import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.deploy.dao.*;
 import com.xunmei.deploy.domain.*;
@@ -141,7 +141,7 @@ public class HostInfoServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> impl
 
     @Override
     @Transactional
-    public  R  deleteByHostId(String hostId){
+    public AjaxResult deleteByHostId(String hostId){
         //todo:
         //SysUser sysUser = SecurityUtils.getLoginUser().getSysUser();
         SysUser sysUser = new SysUser();
@@ -166,9 +166,9 @@ public class HostInfoServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> impl
             OperationLog operationLog = handleLog(hostInfoVo,  userId, userName);
             operationLog.setOperaResult("失败");
             operationLogDao.insert(operationLog);
-            return R.fail("删除失败!");
+            return AjaxResult.error("删除失败!");
         }
-        return R.ok("删除成功!");
+        return AjaxResult.success("删除成功!");
     }
 
     @Override