Эх сурвалжийг харах

soc-modules-deploy模块后台代码迁移-白令海注册及批量升级接口

humingshi-7@163.com 1 жил өмнө
parent
commit
b00a0c4627
19 өөрчлөгдсөн 930 нэмэгдсэн , 75 устгасан
  1. 99 14
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/BeringController.java
  2. 245 3
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/DataController.java
  3. 59 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/SysConfController.java
  4. 1 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/dao/HostInfoDao.java
  5. 26 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/enums/EncryptionServiceEnum.java
  6. 30 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/enums/TaskStatus.java
  7. 11 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/FrontTaskService.java
  8. 4 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/HostInfoService.java
  9. 11 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/SysConfService.java
  10. 95 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/impl/FrontTaskServiceImpl.java
  11. 107 47
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/impl/HostInfoServiceImpl.java
  12. 128 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/impl/SysConfServicesImpl.java
  13. 6 10
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/impl/UpgradeBatchInfoServiceImpl.java
  14. 12 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/util/UTCTimeUtils.java
  15. 1 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/vo/HostInfoVo.java
  16. 19 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/vo/RegisterVo.java
  17. 22 0
      soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/vo/TaskVo.java
  18. 51 0
      soc-modules/soc-modules-deploy/src/main/resources/bootstrap.yml
  19. 3 1
      soc-modules/soc-modules-deploy/src/main/resources/mapper/HostInfoDao.xml

+ 99 - 14
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/BeringController.java

@@ -7,11 +7,11 @@ import com.xunmei.common.core.utils.StringUtils;
 import com.xunmei.deploy.domain.AppInfoExtend;
 import com.xunmei.deploy.domain.HostInfo;
 import com.xunmei.deploy.domain.UpgradeTask;
+import com.xunmei.deploy.domain.UploadAppInfo;
 import com.xunmei.deploy.service.*;
-import com.xunmei.deploy.util.CommonUtils;
-import com.xunmei.deploy.util.RedisPrefix;
-import com.xunmei.deploy.util.RedisTemplateUtil;
-import com.xunmei.deploy.util.UTCTimeUtils;
+import com.xunmei.deploy.util.*;
+import com.xunmei.deploy.vo.RegisterVo;
+import com.xunmei.deploy.vo.TaskVo;
 import com.xunmei.deploy.vo.TokenCache;
 import com.xunmei.deploy.vo.TokenVo;
 import com.xunmei.deploy.vo.appinfo.AppInfoVo;
@@ -23,19 +23,14 @@ import com.xunmei.deploy.vo.heart.ResponeError;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.rmi.ServerException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 @RestController
 public class BeringController {
@@ -51,12 +46,33 @@ public class BeringController {
     @Autowired
     private UpgradeTaskService upgradeTaskService;
     @Autowired
-    private AppInfoExtendService extendService;
+    private AppInfoExtendService appInfoExtendService;
+    @Autowired
+    private UploadAppInfoService uploadAppInfoService;
+    @Autowired
+    private FrontTaskService frontTaskService;
 
     @Resource
     private RedisTemplateUtil redisTemplateUtil;
 
     /**
+     * 白令海Rest接口-推送主机的注册码及机器设备序列号信息,并返回应用秘钥
+     */
+    @PostMapping("/api/deploy/register")
+    public Object register(@RequestBody RegisterVo registerVo){
+        Map<String,Object> map = new HashMap<>();
+        try {
+            HostInfo register = hostInfoService.register(registerVo);
+            //注册成功返回信息
+            map.put("clientId",register.getId());
+            map.put("secretKey",register.getId());
+        } catch (Exception e) {
+            logger.error("白令海Rest接口-register出现异常:{}",e);
+            map.put("message",e.getMessage());
+        }
+        return map;
+    }
+    /**
      * 白令海Rest接口-获取token
      */
     @PostMapping("/api/deploy/accesstoken")
@@ -188,7 +204,7 @@ public class BeringController {
             hostInfo.setCoreTimeStamp(coreTime);
             hostInfoService.updateById(hostInfo);
 
-            List<AppInfoExtend> infoList = extendService.getByHostInfoId(clientId);
+            List<AppInfoExtend> infoList = appInfoExtendService.getByHostInfoId(clientId);
             List<AppInfoVo> avs = new ArrayList<>();
             AppInfoVo av = null;
             /**
@@ -260,6 +276,75 @@ public class BeringController {
         return null;
     }
 
+    /**
+     * 白令海Rest接口-下载服务升级包
+     */
+    @GetMapping("/api/deploy/package/download/{id}")
+    public void getAgentPackage(HttpServletResponse response, HttpServletRequest request, @PathVariable @Value("id") String id){
+        UploadAppInfo uploadAppInfo = uploadAppInfoService.getById(id);
+        if (null == uploadAppInfo){
+            logger.error("未找到对应升级文件:{}",id);
+            return;
+        }
+        //升级包物理下载路径
+        String downPath = uploadAppInfo.getDownPath();
+        logger.info("安装包下载地址:{},安装包存放地址:{}",uploadAppInfo.getDownloadUrl(),downPath);
+        AgentFileUtil.downloadFile(downPath,uploadAppInfo.getAppName()+"_"+uploadAppInfo.getVersion(),request,response);
+    }
+
+    /**
+     * 白令海Rest接口-获取任务
+     */
+    @GetMapping("/api/deploy/task")
+    public Object getTask(HttpServletRequest request, HttpServletResponse response){
+        String authorization = request.getHeader("Authorization");
+        authorization = StringUtils.replace(authorization,"Bearer ","");
+
+        List<TaskVo> tasks = null;
+        try {
+            tasks = frontTaskService.getTasks(authorization);
+        } catch (Exception e) {
+            response.setStatus(500);
+            logger.error("白令海Rest接口-获取任务出现异常",e);
+        }
+        return tasks;
+    }
+    /**
+     * 白令海Rest接口-上送任务执行状态
+     */
+    @PostMapping("/api/deploy/taskReport")
+    public Object taskReport(HttpServletRequest request, HttpServletResponse response, @RequestBody List<TaskVo> tasks){
+        //获取令牌
+        String authorization = request.getHeader("Authorization");
+        authorization = StringUtils.replace(authorization,"Bearer ","");
+        try {
+            frontTaskService.updateTask(authorization,tasks);
+            return null;
+        } catch (Exception e) {
+            response.setStatus(500);
+            logger.error("白令海Rest接口-上送任务执行状态出现异常",e);
+        }
+        return null;
+    }
+    /**
+     * 主机iot服务Rest接口-3100主机获取部署中心系统时间并同步到本地
+     * @return
+     */
+    @PostMapping(value = "/api/deploy/frontend/synchronDate")
+    public JSONObject synchronDate(){
+        Date date= new Date();
+        logger.info("x86心跳,收到来自前置机的同步时钟心跳信息,中心系统时间:"+date);
+        //构建返回信息,当前只要返回时间,VGS管理暂不考虑
+        JSONObject result = new JSONObject();
+        result.put("success","true");
+        result.put("errorMessage","");
+        JSONObject data = new JSONObject();
+        data.put("timeNow",UTCTimeUtils.convertDateToStringByFormat(date,"yyyy-MM-dd HH:mm:ss"));
+        result.put("result",data);
+        return result;
+    }
+
+
     //推送应用清单:验证请求参数
     private boolean checkParam(PutAppInfoVo putAppInfoVo){
         List<AppInfoVo> apps = putAppInfoVo.getApps();

+ 245 - 3
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/DataController.java

@@ -5,6 +5,7 @@ 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.domain.R;
 import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.core.utils.StringUtils;
@@ -24,9 +25,7 @@ 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.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -87,6 +86,87 @@ public class DataController extends BaseController{
     }
 
     /**
+     * 主机管理--批量升级
+     */
+    @PostMapping("/addHostBatch")
+    public AjaxResult addHostBatch(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("/getZipInfos")
+    public Message getZipInfos(){
+        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 Message.success(null,array);
+    }
+
+    /**
+     *  主机管理--批量升级-先根据页面勾选的主机筛选出可升级的主机hostIds,返回给页面操作升级
+     */
+    @PostMapping("/validateHostBatch")
+    public AjaxResult validateHostBatch(String upgradeZipId,@RequestParam("hostIds[]") String[] hostIds){
+        if(StringUtils.isEmpty(upgradeZipId)){
+            return AjaxResult.error("请选择升级包!");
+        }
+        if(hostIds == null || hostIds.length == 0){
+            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
      **/
@@ -115,6 +195,23 @@ public class DataController extends BaseController{
     }
 
     /**
+     * 主机管理--删除主机-先验证主机是否存在升级任务
+     * @param hostId
+     * @return
+     */
+    @RequestMapping("/getUpgradeTaskByHostId")
+    @ResponseBody
+    public Message getUpgradeTaskByHostId(String hostId){
+        try {
+            List<UpgradeTask> list = upgradeTaskService.getByHostId(hostId);
+            return Message.success("获取获取任务成功!",list);
+        } catch (Exception e) {
+            log.error("主机管理--删除主机-查询主机当前的升级任务出现异常:{}",e);
+            return Message.error("获取任务失败,"+e.getMessage());
+        }
+    }
+
+    /**
      * 主机管理--当前版本号下拉框
      **/
     @RequestMapping("/getZipInfos3")
@@ -140,6 +237,71 @@ public class DataController extends BaseController{
     }
 
     /**
+     *  主机管理--导出
+     */
+    @RequestMapping(value = "/hostInfoListExport")
+    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();
+        }
+    }
+
+
+    /**
      * 升级包管理-列表
      */
     @PostMapping("/zipList")
@@ -310,6 +472,39 @@ public class DataController extends BaseController{
     }
 
     /**
+     * 主机管理-列表导出(给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 WritableSheet addBatchHostDetailToLabel(Label label, WritableSheet sheet) throws RowsExceededException, WriteException {
@@ -340,6 +535,53 @@ public class DataController extends BaseController{
     }
 
     /**
+     * 主机管理-列表导出(往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);
+        }
+    }
+    /**
      * 升级状态查询-详情导出(往Excel中添加内容)
      */
     private void addBatchHostContentToLabel(Label label, WritableSheet sheet, List<BatchHostInfo> list) throws Exception {

+ 59 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/controller/SysConfController.java

@@ -0,0 +1,59 @@
+package com.xunmei.deploy.controller;
+
+import com.xunmei.deploy.domain.SysConf;
+import com.xunmei.deploy.util.Message;
+import com.xunmei.deploy.service.SysConfService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+@RequestMapping("/sysConf")
+public class SysConfController {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private SysConfService sysConfService;
+
+    /**
+     * 配置 “允许主机重复注册”、“数据传输加密”、“删除主机前先验证关闭允许主机重复注册”-获取当前配置
+     */
+    @GetMapping("/getByCode")
+    @ResponseBody
+    public Message getByCode(String code){
+        try {
+            SysConf sysConf = sysConfService.getByCode(code);
+            return Message.success("获取数据成功!",sysConf);
+        }catch (Exception e){
+            logger.error("配置是否运行主机重复注册、数据传输加密获取数据出现异常:{}",e);
+            return Message.error("获取数据失败!");
+        }
+    }
+
+    /**
+     * 配置 “允许主机重复注册”、“数据传输加密”-保存修改配置
+     */
+    @RequestMapping("/saveOrUpdate")
+    @ResponseBody
+    public Message saveOrUpdate(@RequestBody SysConf sysConf){
+        try {
+            if (null != sysConf.getId()){
+                SysConf conf = sysConfService.getById(sysConf.getId());
+                //数据库值和前台值相同,直接返回
+                if (conf.getCode().equals(sysConf.getCode()) && conf.getValue().equals(sysConf.getValue())){
+                    return Message.success("保存成功!",null);
+                }
+            }
+            sysConfService.updateSysConfig(sysConf);
+            return Message.success("保存成功!",null);
+        }catch (Exception e){
+            logger.error("配置是否运行主机重复注册、数据传输加密保存修改配置出现异常:{}",e);
+            return Message.error("保存失败!");
+        }
+    }
+}

+ 1 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/dao/HostInfoDao.java

@@ -25,6 +25,7 @@ public interface HostInfoDao extends BaseMapper<HostInfo> {
     int deleteAppInfoExtend(String hostId);
     int deleteAppRunInfo(String hostId);
     int deleteAppRunInfoExtend(String hostId);
+    int deleteBatchHostInfo(String hostId);
 
 
     /**

+ 26 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/enums/EncryptionServiceEnum.java

@@ -0,0 +1,26 @@
+package com.xunmei.deploy.enums;
+
+/**
+ * 加密应用enum
+ */
+public enum EncryptionServiceEnum {
+    //c3m
+    C3M("services-c3m"),
+    //vgs
+    VGS("services-vgs"),
+    //video
+    VIDEO("services-video"),
+    //north
+    NORTH("services-north");
+
+    private String serviceName;
+
+    EncryptionServiceEnum(String serviceName){
+        this.serviceName = serviceName;
+    }
+
+
+    public String getServiceName(){
+        return serviceName;
+    }
+}

+ 30 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/enums/TaskStatus.java

@@ -0,0 +1,30 @@
+package com.xunmei.deploy.enums;
+
+/**
+ * 任务状态
+ */
+public enum TaskStatus {
+
+    FAIL(2,"Fail"),//失败
+    SUCCESS(1,"Success"),//成功
+    EXECUTING(3,"Executing"),//执行中
+    QUEUING(0,"Queuing"), //待执行
+    SEND_OUT(4,"sendOut");//已发送
+
+    private int status;
+
+    private String statusDesc;
+
+    TaskStatus(int status, String statusDesc){
+        this.status = status;
+        this.statusDesc = statusDesc;
+    }
+
+    public int getStatus(){
+        return status;
+    }
+
+    public String getStatusDesc(){
+        return statusDesc;
+    }
+}

+ 11 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/FrontTaskService.java

@@ -2,6 +2,9 @@ package com.xunmei.deploy.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.xunmei.deploy.domain.FrontTask;
+import com.xunmei.deploy.vo.TaskVo;
+
+import java.util.List;
 
 public interface FrontTaskService  extends IService<FrontTask> {
 
@@ -13,4 +16,12 @@ public interface FrontTaskService  extends IService<FrontTask> {
      * 验证是否需要生成清单任务,如果需要则在数据库添加记录
      **/
     void validateAppInfoList(String hostId,String version)throws Exception;
+    /**
+     * 白令海获取执行的任务
+     */
+    List<TaskVo> getTasks(String authorization)throws Exception;
+    /**
+     * 白令海上送任务执行结果
+     */
+    void updateTask(String authorization,List<TaskVo> list)throws Exception;
 }

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

@@ -6,11 +6,15 @@ import com.xunmei.common.core.domain.R;
 import com.xunmei.deploy.domain.HostInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.xunmei.deploy.vo.HostInfoVo;
+import com.xunmei.deploy.vo.RegisterVo;
 import com.xunmei.deploy.vo.UploadAgentVo;
 
 import java.util.List;
 
 public interface HostInfoService extends IService<HostInfo> {
+    //主机的注册码及机器设备序列号信息,并返回应用秘钥
+    HostInfo register(RegisterVo registerVo)throws Exception;
+
     IPage<HostInfoVo> selectHostInfoPage(Page<HostInfo> page, HostInfoVo hostInfoVo);
     HostInfoVo getInfoById(String id);
     R deleteByHostId(String hostId);

+ 11 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/SysConfService.java

@@ -0,0 +1,11 @@
+package com.xunmei.deploy.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.xunmei.deploy.domain.SysConf;
+
+public interface SysConfService extends IService<SysConf> {
+
+    SysConf getByCode(String code);
+
+    void updateSysConfig(SysConf sysConf);
+}

+ 95 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/impl/FrontTaskServiceImpl.java

@@ -9,16 +9,20 @@ import com.xunmei.deploy.dao.HostInfoDao;
 import com.xunmei.deploy.domain.AppInfo;
 import com.xunmei.deploy.domain.FrontTask;
 import com.xunmei.deploy.domain.HostInfo;
+import com.xunmei.deploy.enums.TaskStatus;
 import com.xunmei.deploy.enums.TaskType;
 import com.xunmei.deploy.dao.FrontTaskDao;
 import com.xunmei.deploy.service.FrontTaskService;
 import com.xunmei.deploy.util.RedisPrefix;
 import com.xunmei.deploy.util.RedisTemplateUtil;
+import com.xunmei.deploy.vo.TaskVo;
+import com.xunmei.deploy.vo.TokenCache;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.*;
@@ -152,6 +156,84 @@ public class FrontTaskServiceImpl  extends ServiceImpl<FrontTaskDao, FrontTask>
         }
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public List<TaskVo> getTasks(String authorization) throws Exception{
+        List<TaskVo> list = new ArrayList<>();
+        //获取秘钥
+        String hostId = this.getHostId(authorization);
+        logger.info("获取前置机:{},开始获取任务清单",hostId);
+
+        //获取指定的任务清单
+        QueryWrapper<FrontTask> qw = new QueryWrapper<>();
+        qw.eq("host_id",hostId);
+        qw.eq("task_status",TaskStatus.QUEUING.getStatus());
+        qw.orderByAsc("sort_app");
+        List<FrontTask> frontTasks = baseMapper.selectList(qw);
+        TaskVo tv;
+        for (FrontTask frontTask : frontTasks) {
+            tv = new TaskVo();
+            tv.setId(frontTask.getId());
+            tv.setType(frontTask.getTaskType());
+            tv.setArguments(frontTask.getArguments());
+            list.add(tv);
+            frontTask.setTaskStatus(4);
+            frontTask.setTaskStartTime(new Date());
+            baseMapper.updateById(frontTask);
+        }
+        logger.info("获取前置机:{},任务清单:{}",hostId, JSON.toJSONString(list));
+        return list;
+    }
+
+    @Override
+    @Async("asyncServiceExecutor")
+    public void updateTask(String authorization, List<TaskVo> list) throws Exception {
+        String hostId = getHostId(authorization);
+        logger.info("前置机hostId={},任务执行状态数据={}",hostId,JSON.toJSONString(list));
+        for (TaskVo taskVo : list) {
+            logger.info("前置机hostId={},任务id:{},任务状态{}",hostId,taskVo.getId(),taskVo.getState());
+            FrontTask frontTask = baseMapper.selectById(taskVo.getId());
+            if(TaskStatus.FAIL.getStatus() == frontTask.getTaskStatus() ||
+                    TaskStatus.SUCCESS.getStatus() == frontTask.getTaskStatus()){
+                logger.info("前置机hostId={},任务id:{},任务已经成功或失败,不能继续修改任务状态!",hostId,taskVo.getId());
+                continue;
+            }
+            if(TaskStatus.FAIL.getStatusDesc().equals(taskVo.getState())){
+                frontTask.setTaskStatus(TaskStatus.FAIL.getStatus());
+                frontTask.setTaskEndTime(new Date());
+                frontTask.setTaskStatusDesc(taskVo.getDescription());
+                //如果是获取应用清单任务失败 需要删除相关任务数据
+                if(TaskType.UPLOAD_APP_LIST.getStatus().equals(taskVo.getType())){
+                    baseMapper.deleteById(frontTask);
+                    continue;
+                }
+            }
+
+            if(TaskStatus.SUCCESS.getStatusDesc().equals(taskVo.getState())){
+                frontTask.setTaskStatus(TaskStatus.SUCCESS.getStatus());
+                frontTask.setTaskEndTime(new Date());
+                frontTask.setTaskStatusDesc(taskVo.getDescription());
+            }
+
+            if(TaskStatus.EXECUTING.getStatusDesc().equals(taskVo.getState())){
+                frontTask.setTaskStatus(TaskStatus.EXECUTING.getStatus());
+                frontTask.setTaskStatusDesc(taskVo.getDescription());
+            }
+
+            if(TaskStatus.QUEUING.getStatusDesc().equals(taskVo.getState())){
+                frontTask.setTaskStatus(TaskStatus.QUEUING.getStatus());
+                frontTask.setTaskStatusDesc(taskVo.getDescription());
+            }
+
+            baseMapper.updateById(frontTask);
+        }
+        //查询待执行的任务 放到缓存中覆盖之前的缓存
+        QueryWrapper<FrontTask> wrapper = new QueryWrapper<>();
+        wrapper.eq("task_status",TaskStatus.QUEUING.getStatusDesc());
+        List<FrontTask> tasks = baseMapper.selectList(wrapper);
+        redisTemplateUtil.set(RedisPrefix.CACHE_FRONT_TASKS + ":" + hostId,JSON.toJSONString(tasks),2 * 60 * 60);
+    }
+
     private List<FrontTask> handleTaskCaches(String hostId, List<FrontTask> taskCaches) {
         if (null != taskCaches && taskCaches.size() > 0){
             Iterator<FrontTask> iterator = taskCaches.iterator();
@@ -165,4 +247,17 @@ public class FrontTaskServiceImpl  extends ServiceImpl<FrontTaskDao, FrontTask>
         }
         return taskCaches;
     }
+
+    //获取缓存中hostId
+    private String getHostId(String authorization){
+        //根据token获取主机信息
+        TokenCache tokenCache = null;
+        String result = redisTemplateUtil.get(RedisPrefix.CACHE_TOKEN_TIMES + ":" + authorization);
+        if (org.apache.commons.lang3.StringUtils.isNotBlank(result)){
+            tokenCache =  JSON.parseObject(result, TokenCache.class);
+        }
+        //获取秘钥
+        String hostId = tokenCache.getClientId();
+        return hostId;
+    }
 }

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

@@ -12,8 +12,7 @@ import com.xunmei.deploy.service.HostInfoService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.deploy.util.RedisPrefix;
 import com.xunmei.deploy.util.RedisTemplateUtil;
-import com.xunmei.deploy.vo.HostInfoVo;
-import com.xunmei.deploy.vo.UploadAgentVo;
+import com.xunmei.deploy.vo.*;
 import com.xunmei.system.api.domain.SysUser;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.annotations.Param;
@@ -22,11 +21,10 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.DigestUtils;
+
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -43,6 +41,74 @@ public class HostInfoServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> impl
     @Resource
     private RedisTemplateUtil redisTemplateUtil;
 
+    //主机的注册码及机器设备序列号信息,并返回应用秘钥
+    @Override
+    @Transactional
+    public HostInfo register(RegisterVo registerVo) throws Exception {
+        //1.先判断请求参数是否合法
+        if(registerVo == null){
+            logger.error("主机节点注册失败:参数不能为空!");
+            throw new RuntimeException("主机节点注册失败:参数不能为空!");
+        }
+        if(StringUtils.isEmpty(registerVo.getCode())){
+            logger.error("主机节点注册失败:注册码不能为空!");
+            throw new RuntimeException("主机节点注册失败:注册码不能为空!");
+        }
+        MachineInfo machineInfo = registerVo.getMachineInfo();
+        if(machineInfo == null){
+            logger.error("主机节点注册失败:计算机信息不能为空!");
+            throw new RuntimeException("主机节点注册失败:计算机信息不能为空!");
+        }
+        List<String> macs = machineInfo.getMacs();
+        if(macs.size() == 0){
+            logger.error("主机节点注册失败:MAC地址不能为空!");
+            throw new RuntimeException("主机节点注册失败:MAC地址不能为空!");
+        }
+        //2.验证注册码是否在数据库中已经存在
+        HostInfo hostInfo = baseMapper.selectById(registerVo.getCode());
+        if(hostInfo != null){
+            logger.error("数据库已有主机注册数据,主机内注册数据丢失,删除部署中心主机相关数据!");
+            //已注册  代表主机注册数据丢失   删除部署中心主机所有数据
+            try{
+                this.deleteTableDataByHostId(hostInfo.getId(),true);
+            }catch (Exception e){
+                logger.error("主机节点注册删除主机相关表出错:{}",e);
+            }
+        }
+        //3.不存在,验证注册码是否合法
+        //排序mac
+        Collections.sort(macs);
+        String macss = StringUtils.join(macs.toArray(), "");
+        String str = macss + "zmoon";
+        String code = DigestUtils.md5DigestAsHex(str.getBytes());
+        if(!code.equals(registerVo.getCode())){
+            logger.error("主机节点注册失败:无效的注册码!");
+            throw new RuntimeException("主机节点注册失败:无效的注册码!");
+        }
+        // 4. 注册码合法,合法后保存数据库,且更新缓存数据
+        hostInfo = new HostInfo();
+        hostInfo.setId(code);
+        hostInfo.setHostName(machineInfo.getMachineName());
+        hostInfo.setHostIp(StringUtils.join(machineInfo.getIpAddresses().toArray(),","));
+        hostInfo.setHostSystem(machineInfo.getOsPlatform());
+        hostInfo.setHostFrame(machineInfo.getOsArchitecture());
+        hostInfo.setHostMac(StringUtils.join(macs.toArray(),","));
+        hostInfo.setHostOrg(null);
+        hostInfo.setHostStatus(1);
+        hostInfo.setIsPush(0);
+        try {
+            baseMapper.insert(hostInfo);
+        }catch (Exception e){
+            throw e;
+        }
+        //添加缓存信息
+        TokenCache tc = new TokenCache();
+        tc.setClientId(hostInfo.getId());
+        tc.setClientSecret(hostInfo.getId());
+        redisTemplateUtil.set(RedisPrefix.CACHE_TOKENS + ":" + hostInfo.getId(),tc,2 * 60 * 60);
+        return hostInfo;
+    }
+
     @Override
     public IPage<HostInfoVo> selectHostInfoPage(Page<HostInfo> page, HostInfoVo hostInfoVo) {
         // 设置排序字段
@@ -84,35 +150,7 @@ public class HostInfoServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> impl
         //拿到id查询主机信息
         HostInfoVo hostInfoVo = this.getInfoById(hostId);
         try {
-            this.deleteTableDataByHostId(hostId);
-
-            HashMap<String, Object> hashMap = new HashMap<>();
-            hashMap.put("host_id",hostId);
-
-            //删除 t_batch_host_info 表数据
-            List<BatchHostInfo> batchHostInfos = batchHostInfoDao.selectList((new QueryWrapper<BatchHostInfo>())
-                    .eq("host_id", hostId));
-            batchHostInfoDao.deleteByMap(hashMap);
-            logger.info("删除BatchHostInfo表数据");
-
-            for (BatchHostInfo info : batchHostInfos) {
-                String batchId = info.getBatchId();
-                //如果batchHostInfoDao表中还有该批次的信息 则不删除 反之删除
-                List<BatchHostInfo> hostInfos = batchHostInfoDao.selectList((new QueryWrapper<BatchHostInfo>())
-                        .eq("batch_id", batchId));
-                //如果批次下没有主机 就删除批次信息 如果有主机 就更新批次数量
-                if (hostInfos.isEmpty()) {
-                    upgradeBatchInfoDao.deleteById(batchId);
-                } else {
-                    UpgradeBatchInfo upgradeBatchInfo = upgradeBatchInfoDao.selectById(batchId);
-                    if (null != upgradeBatchInfo){
-                        upgradeBatchInfo.setHostSize(hostInfos.size());
-                        upgradeBatchInfo.setOrgSize(hostInfos.stream().map(e -> e.getOrgId()).distinct().collect(Collectors.toList()).size());
-                        upgradeBatchInfoDao.updateById(upgradeBatchInfo);
-                    }
-                }
-            }
-
+            this.deleteTableDataByHostId(hostId,false);
             //todo:
             logger.info("用户:{} 进行删除主机操作,主机信息:名称:{},机构:{},ip:{}",
                     userName, hostInfoVo.getHostName(), hostInfoVo.getHostOrg(), hostInfoVo.getHostIp());
@@ -146,52 +184,73 @@ public class HostInfoServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> impl
         return baseMapper.selectPage(page,hostInfo);
     }
 
-
-    private void deleteTableDataByHostId(String hostId){
-
+    //删除主机相关记录表
+    private void deleteTableDataByHostId(String hostId,boolean isRegister){
+        //1.删除单表类
         baseMapper.deleteAppInfo(hostId);
         logger.info("删除AppInfo表数据");
-
         baseMapper.deleteFrontTask(hostId);
         logger.info("删除FrontTask表数据");
-
         baseMapper.deleteHostZipInfo(hostId);
         logger.info("删除HostZipInfo表数据");
-
         baseMapper.deleteUpgradeTask(hostId);
         logger.info("删除UpgradeTask表数据");
         baseMapper.deleteUpgradeTaskHis(hostId);
         logger.info("删除UpgradeTaskHis表数据");
-
         baseMapper.deleteById(hostId);
         logger.info("删除 t_host_info 表数据");
-
         baseMapper.deleteAppInfoExtend(hostId);
         logger.info("删除 t_app_info_extend 表数据");
-
         baseMapper.deleteAppRunInfo(hostId);
         logger.info("删除 t_app_run_info 表数据");
         baseMapper.deleteAppRunInfoExtend(hostId);
         logger.info("删除t_app_run_info_extend 表数据");
 
-
         //todo:
         //deleteZongmuData(hostId);
-
         //清除缓存
 //        String result = redisTemplateUtil.get(RedisPrefix.CACHE_TOKENS + ":" + hostId);
 //        if (StringUtils.isNotBlank(result)){
 //            TokenCache tokenCache =  JSON.parseObject(result, TokenCache.class);
 //            redisTemplateUtil.del(RedisPrefix.CACHE_TOKEN_TIMES + ":" + tokenCache.getAccessToken());
 //        }
-
         redisTemplateUtil.del(RedisPrefix.CACHE_TOKENS + ":" + hostId);
         redisTemplateUtil.del(RedisPrefix.CACHE_HEARTS + ":" + hostId);
         redisTemplateUtil.del(RedisPrefix.CACHE_FRONT_TASKS + ":" + hostId);
         redisTemplateUtil.del(RedisPrefix.CACHE_APP_RUN_INFO + ":" + hostId);
         redisTemplateUtil.del(RedisPrefix.CACHE_APP_RUN_INFO_EXTEND + ":" + hostId);
+
+        //2.删除关联表类
+        List<BatchHostInfo> batchHostInfos = batchHostInfoDao.selectList((new QueryWrapper<BatchHostInfo>())
+                .eq("host_id", hostId));
+        baseMapper.deleteBatchHostInfo(hostId);
+        logger.info("删除BatchHostInfo表数据");
+
+        for (BatchHostInfo info : batchHostInfos) {
+            String batchId = info.getBatchId();
+            //如果batchHostInfoDao表中还有该批次的信息 则不删除 反之删除
+            List<BatchHostInfo> hostInfos = batchHostInfoDao.selectList((new QueryWrapper<BatchHostInfo>())
+                    .eq("batch_id", batchId));
+            //如果批次下没有主机 就删除批次信息 如果有主机 就更新批次数量
+            if (hostInfos.isEmpty()) {
+                upgradeBatchInfoDao.deleteById(batchId);
+                logger.info("删除UpgradeBatchInfo表数据");
+            } else {
+                //a.删除主机-更新批次信息;b.注册-不执行此操作
+                if(!isRegister) {
+                    UpgradeBatchInfo upgradeBatchInfo = upgradeBatchInfoDao.selectById(batchId);
+                    if (null != upgradeBatchInfo) {
+                        upgradeBatchInfo.setHostSize(hostInfos.size());
+                        upgradeBatchInfo.setOrgSize(hostInfos.stream().map(e -> e.getOrgId()).distinct().collect(Collectors.toList()).size());
+                        upgradeBatchInfoDao.updateById(upgradeBatchInfo);
+                    }
+                }
+            }
+        }
+
     }
 
+    //记录删除主机操作日志
     private OperationLog handleLog(HostInfoVo hostInfoVo,Long userId,String userName) {
         OperationLog operationLog = new OperationLog();
         operationLog.setUserId(userId);
@@ -212,4 +271,5 @@ public class HostInfoServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> impl
         operationLog.setOperaResult("成功");
         return operationLog;
     }
+
 }

+ 128 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/impl/SysConfServicesImpl.java

@@ -0,0 +1,128 @@
+package com.xunmei.deploy.service.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.common.core.utils.StringUtils;
+import com.xunmei.deploy.dao.AppInfoDao;
+import com.xunmei.deploy.dao.AppInfoExtendDao;
+import com.xunmei.deploy.dao.HostInfoDao;
+import com.xunmei.deploy.dao.SysConfDao;
+import com.xunmei.deploy.domain.AppInfo;
+import com.xunmei.deploy.domain.AppInfoExtend;
+import com.xunmei.deploy.domain.HostInfo;
+import com.xunmei.deploy.domain.SysConf;
+import com.xunmei.deploy.enums.EncryptionServiceEnum;
+import com.xunmei.deploy.service.SysConfService;
+import com.xunmei.deploy.util.UTCTimeUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import java.util.List;
+
+@Service
+public class SysConfServicesImpl extends ServiceImpl<SysConfDao, SysConf> implements SysConfService {
+
+    private final static String MQCode = "--mqP=";
+
+    @Autowired
+    private HostInfoDao hostInfoDao;
+    @Autowired
+    private AppInfoDao appInfoDao;
+    @Autowired
+    private AppInfoExtendDao appInfoExtendDao;
+
+
+    @Override
+    public SysConf getByCode(String code) {
+        return baseMapper.getByCode(code);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void updateSysConfig(SysConf sysConf) {
+        if (null != sysConf){
+            super.saveOrUpdate(sysConf);
+            if ("encryption_port".equals(sysConf.getCode())){
+                //修改已经加密传输主机启动参数中的mq端口
+                QueryWrapper<HostInfo> wrapper = new QueryWrapper<>();
+                wrapper.eq("encryption",1);
+                List<HostInfo> hostInfoList = hostInfoDao.selectList(wrapper);
+                if (null != hostInfoList && hostInfoList.size() > 0){
+                    for (HostInfo hostInfo: hostInfoList) {
+                        //获取对应主机的应用清单
+                        List<AppInfo> appInfoList = appInfoDao.getByHostInfoId(hostInfo.getId());
+                        if (null != appInfoList && appInfoList.size() > 0){
+                            for (AppInfo appInfo:appInfoList) {
+                                //修改对应应用的启动参数
+                                if (appInfo.getAppId().equals(EncryptionServiceEnum.C3M.getServiceName())
+                                        || appInfo.getAppId().equals(EncryptionServiceEnum.VGS.getServiceName())
+                                        || appInfo.getAppId().equals(EncryptionServiceEnum.NORTH.getServiceName())
+                                        || appInfo.getAppId().equals(EncryptionServiceEnum.VIDEO.getServiceName())){
+
+                                    String appInfoStart = this.updateAppInfoStart(appInfo.getStart(),sysConf.getValue());
+                                    appInfo.setStart(appInfoStart);
+                                    appInfoDao.updateById(appInfo);
+                                }
+                            }
+                        }
+                        //查询appInfoExtend
+                        List<AppInfoExtend> extendList = appInfoExtendDao.getByHostId(hostInfo.getId());
+                        if (null != extendList && extendList.size() > 0){
+                            for (AppInfoExtend extend:extendList) {
+                                //修改对应应用的启动参数
+                                if (extend.getAppId().equals(EncryptionServiceEnum.C3M.getServiceName())
+                                        || extend.getAppId().equals(EncryptionServiceEnum.VIDEO.getServiceName())
+                                        || extend.getAppId().equals(EncryptionServiceEnum.NORTH.getServiceName())
+                                        || extend.getAppId().equals(EncryptionServiceEnum.VGS.getServiceName())){
+
+                                    String appInfoStart = this.updateAppInfoStart(extend.getStart(),sysConf.getValue());
+                                    extend.setStart(appInfoStart);
+                                    appInfoExtendDao.updateById(extend);
+                                }
+                            }
+                        }
+
+                        //修改主机两个时间戳
+                        if (hostInfo.getFrontTimeStamp() != 0 && hostInfo.getCoreTimeStamp() != 0){
+                            long utcStr2Long = UTCTimeUtils.getUtcStr2Long(UTCTimeUtils.getUTCTimeStr());
+                            hostInfo.setFrontTimeStamp(utcStr2Long);
+                            hostInfo.setCoreTimeStamp(utcStr2Long);
+                            hostInfoDao.updateById(hostInfo);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    private String updateAppInfoStart(String startStr,String encryptionPort) {
+        JSONObject jsonObject = (JSONObject) JSONObject.parse(startStr);
+        String jsonStr = jsonObject.getString("command");
+        List<String> commandList = JSONArray.parseArray(jsonStr, String.class);
+
+        //启动参数中是否有相同参数
+        boolean paramFlag = false;
+        //相同参数的index
+        int index = 0;
+
+        for (int j = 0; j < commandList.size(); j++) {
+            String str = commandList.get(j);
+            if (StringUtils.isNotEmpty(str) && str.indexOf(MQCode) != -1){
+                paramFlag = true;
+                index = j;
+            }
+        }
+
+        //有相同的就修改,没有就添加
+        if (paramFlag){
+            commandList.set(index,MQCode+encryptionPort);
+        }else {
+            commandList.add(MQCode+encryptionPort);
+        }
+        jsonObject.put("command",commandList);
+
+        return jsonObject.toJSONString();
+    }
+}

+ 6 - 10
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/impl/UpgradeBatchInfoServiceImpl.java

@@ -478,9 +478,7 @@ public class UpgradeBatchInfoServiceImpl extends ServiceImpl<UpgradeBatchInfoDao
 
     @Override
     public Map<String,Object> validateHostBatch(String zipId, String[] hostIds) throws Exception {
-
         Map<String,Object> map = new HashMap<>();
-
         /**
          * 第一步:获取升级包和包中应用信息
          */
@@ -488,7 +486,6 @@ public class UpgradeBatchInfoServiceImpl extends ServiceImpl<UpgradeBatchInfoDao
         if (null == zipPackInfo){
             throw new RuntimeException("未找到对应升级包!");
         }
-
         if (StringUtils.isEmpty(zipPackInfo.getHostType())){
             throw new RuntimeException("该升级包信息不完整,请删除后重新上传!");
         }
@@ -500,10 +497,7 @@ public class UpgradeBatchInfoServiceImpl extends ServiceImpl<UpgradeBatchInfoDao
         qhw.in("host_id",hostIds);
         List<HostZipInfo> hostZipInfos = hostZipInfoDao.selectList(qhw);
 
-        /**
-         * hostType 除YCAF外的都视为讯美主机
-         */
-        //升级包适用的主机
+        //升级包适用的主机(除YCAF外的都视为讯美主机)
         String hostType = zipPackInfo.getHostType();
         int hostCount = 0;
 
@@ -524,7 +518,6 @@ public class UpgradeBatchInfoServiceImpl extends ServiceImpl<UpgradeBatchInfoDao
         if (hostCount != hostZipInfos.size()){
             throw new RuntimeException("该升级包只适用" + zipPackInfo.getHostTypeName() + "主机升级,升级主机中存在其他主机。请重新选择需要升级的主机!");
         }
-
         //所有机器版本和升级版本号一致
         boolean versionOk = true;
 
@@ -533,6 +526,7 @@ public class UpgradeBatchInfoServiceImpl extends ServiceImpl<UpgradeBatchInfoDao
             HostInfo hostInfo = hostInfoDao.selectById(hostZipInfo.getHostId());
             if(hostInfo.getIsPush() == 0){
                 //该主机未推送应用清单
+                logger.info("主机hostId={}放弃本次升级,原因:未推送应用清单",hostZipInfo.getHostId());
                 continue;
             }
 
@@ -547,10 +541,12 @@ public class UpgradeBatchInfoServiceImpl extends ServiceImpl<UpgradeBatchInfoDao
                     String version = CommonUtils.compareToVersion(zipVersion, nowVersion);
                     if(!version.equals(zipVersion)){
                         //升级版本号小于当前版本号,不作任何处理
+                        logger.info("主机hostId={}放弃本次升级,原因:升级版本号小于当前版本号",hostZipInfo.getHostId());
                         continue;
                     }
                 }else{
                     //版本相同,不作任何处理
+                    logger.info("主机hostId={}放弃本次升级,原因:升级版本号与当前版本号一致",hostZipInfo.getHostId());
                     continue;
                 }
             }else{
@@ -566,15 +562,15 @@ public class UpgradeBatchInfoServiceImpl extends ServiceImpl<UpgradeBatchInfoDao
                  */
                 String version = CommonUtils.compareToVersion(zipVersion, targetVersion);
                 if(version.equals(targetVersion)){
+                    logger.info("主机hostId={}放弃本次升级,原因:升级版本号与主机已在进行的升级目标版本号一致",hostZipInfo.getHostId());
                     continue;
                 }
             }
-
-
             hosts.add(hostInfo.getId());
         }
 
         if(versionOk){
+            logger.info("选择的主机hostIds={}放弃本次升级,原因:选择的主机均已升级至此版本,无需进行升级!",hostIds);
             throw new RuntimeException("选择的主机均已升级至此版本,无需进行升级!");
         }
 

+ 12 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/util/UTCTimeUtils.java

@@ -98,4 +98,16 @@ public class UTCTimeUtils {
         return format;
     }
 
+
+    /**
+     * 根据时间格式格式化时间对象
+     *
+     * @param date   时间对象
+     * @param format 格式化格式
+     * @return 返回时间字符串
+     */
+    public static String convertDateToStringByFormat(Date date, String format) {
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        return sdf.format(date);
+    }
 }

+ 1 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/vo/HostInfoVo.java

@@ -21,5 +21,6 @@ public class HostInfoVo {
     private String showNoOrgNameFlag;
     private String hostOrgName;
     private String id;
+    private String registerDateTime;
 }
 

+ 19 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/vo/RegisterVo.java

@@ -0,0 +1,19 @@
+package com.xunmei.deploy.vo;
+
+import lombok.Data;
+
+/**
+ * 主机的注册码及机器设备序列号信息
+ */
+@Data
+public class RegisterVo {
+
+    /**注册码**/
+    private String code;
+
+    /**安装Agent的计算机信息**/
+    private MachineInfo machineInfo;
+
+    /**安装Agent的设备序列号,并非所有设备都有序列号。**/
+    private String sn;
+}

+ 22 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/vo/TaskVo.java

@@ -0,0 +1,22 @@
+package com.xunmei.deploy.vo;
+
+import lombok.Data;
+
+@Data
+public class TaskVo {
+
+    /**部署中心生成的任务唯一ID**/
+    private String id;
+
+    /**任务类型**/
+    private String type;
+
+    /**任务参数Json字符串,由Task自行解析。**/
+    private String arguments;
+
+    /**前置机报告任务状态**/
+    private String state;
+
+    /**前置机返回的描述**/
+    private String description;
+}

+ 51 - 0
soc-modules/soc-modules-deploy/src/main/resources/bootstrap.yml

@@ -0,0 +1,51 @@
+# Tomcat
+server:
+  port: 8098
+
+# Spring
+spring: 
+  application:
+    # 应用名称
+    name: soc-deploy
+  profiles:
+    # 环境配置
+    active: dev
+  cloud:
+    nacos:
+      discovery:
+        namespace: c2fe98f1-97c0-4c1a-9df8-4d63e5b625de
+        # 服务注册地址
+        server-addr: 10.87.23.39:8848
+      config:
+        namespace: c2fe98f1-97c0-4c1a-9df8-4d63e5b625de
+        # 配置中心地址
+        server-addr: 10.87.23.39:8848
+        # 配置文件格式
+        file-extension: yml
+        # 共享配置
+        shared-configs:
+          - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+  servlet:
+    multipart:
+      file-size-threshold: 2048MB
+      max-request-size: 2048MB
+      max-file-size: 2048MB
+
+logging:
+  file:
+    name: logs/${spring.application.name}/info.log
+
+package:
+  basePath:
+    linux: /home/zmoon/package
+    windows: D:\\zongmu\\app\\package
+sys:
+  linuxResolvePath: /home/zmoon/resolve/
+  linuxBasePath: /home/zmoon/zipApps/
+  linuxHttpPath: /home/zmoon/httpApps/
+  windowsResolvePath: D:\\resolve\\
+  windowsBasePath: D:\\zipApps\\
+  windowsHttpPath: D:\\httpApps\\
+apps:
+  version: init-version
+  list: VGSII,zm_mysql,nginx.exe,baseEnv,VIMD,IOTSERVER,BASEDATA

+ 3 - 1
soc-modules/soc-modules-deploy/src/main/resources/mapper/HostInfoDao.xml

@@ -110,7 +110,9 @@
     <delete id="deleteAppRunInfoExtend">
         delete from t_app_run_info_extend where host_id = #{hostId};
     </delete>
-
+    <delete id="deleteBatchHostInfo">
+        delete from t_batch_host_info where host_id = #{hostId};
+    </delete>
 
     <select id="selectByOrg" resultType="com.xunmei.deploy.domain.HostInfo">
         select h.id,h.hostName,h.hostIp,h.hostSystem,h.hostFrame,h.hostMac,h.hostOrg,