From fc91703f3cbee4dac9e56c3da694fccb386f4ce3 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期三, 29 七月 2020 19:30:54 +0800
Subject: [PATCH] add showInstallInfo

---
 service/SdkInstall.go  |  107 ++++++++++++++++++++++++++++++-----
 service/SdkDownLoad.go |    3 +
 service/SysService.go  |    5 +
 controllers/sdk.go     |   20 ++++++
 router/router.go       |    1 
 5 files changed, 120 insertions(+), 16 deletions(-)

diff --git a/controllers/sdk.go b/controllers/sdk.go
index d51c02c..3327309 100644
--- a/controllers/sdk.go
+++ b/controllers/sdk.go
@@ -275,6 +275,26 @@
 }
 
 // @Security ApiKeyAuth
+// @Summary 涓婁紶瀹屾垚鑾峰彇瀹夎淇℃伅
+// @Description 涓婁紶瀹屾垚鑾峰彇瀹夎淇℃伅
+// @Produce json
+// @Tags 绠楁硶
+// @Param identifier formData string true "鏁翠釜鏂囦欢鐨勫敮涓�鏍囪瘑锛岀洰鍓嶆槸md5"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sdk/showInstallInfo [post]
+func (sc SdkController) ShowInstallInfo(c *gin.Context) {
+	identifier := c.Request.FormValue("identifier")
+	var sv service.SdkInstallService
+	b,d := sv.ShowInstallInfo(identifier)
+	if b {
+		util.ResponseFormat(c,code.Success, d)
+	} else {
+		util.ResponseFormat(c,code.ComError, "鑾峰彇澶辫触")
+	}
+}
+
+// @Security ApiKeyAuth
 // @Summary 涓婁紶瀹屾垚寮�濮嬪畨瑁�
 // @Description 涓婁紶瀹屾垚寮�濮嬪畨瑁�
 // @Produce json
diff --git a/router/router.go b/router/router.go
index 320484f..803da13 100644
--- a/router/router.go
+++ b/router/router.go
@@ -293,6 +293,7 @@
 		sdkApi.GET("/sdkDownload", sdkController.SdkDownLoad)
 		sdkApi.GET("/upload", sdkController.Upload)
 		sdkApi.POST("/upload", sdkController.UploadPack)
+		sdkApi.POST("/showInstallInfo", sdkController.ShowInstallInfo)
 		sdkApi.POST("/install", sdkController.Install)
 		sdkApi.GET("/active", sdkController.Active)
 	}
diff --git a/service/SdkDownLoad.go b/service/SdkDownLoad.go
index 1363024..ae0556e 100644
--- a/service/SdkDownLoad.go
+++ b/service/SdkDownLoad.go
@@ -383,6 +383,9 @@
 		logger.Debug("DownloadFile err:", err)
 		return false, err
 	}
+	if unPackB,unPackErr := unPackPatchPackage(resp.Md5, ext); !unPackB { //瑙e帇澶辫触
+		return false, unPackErr
+	}
 	b, err := installSdk(resp.Md5, ext)
 	if b {
 		return true, nil
diff --git a/service/SdkInstall.go b/service/SdkInstall.go
index edd704b..3c19e59 100644
--- a/service/SdkInstall.go
+++ b/service/SdkInstall.go
@@ -105,6 +105,87 @@
 	}
 }
 
+//瑙e帇涓婁紶鐨勭畻娉曞畨瑁呭寘
+func unPackPatchPackage(identifier string, ext string) (bool,error) {
+	configPatchPath := ""
+	if config.Server.PatchPath != "" {
+		configPatchPath = config.Server.PatchPath
+	} else {
+		configPatchPath = "../patch"
+	}
+	//1.瑙e帇缂╂洿鏂板寘
+	unPackTargetPath := configPatchPath+"/"+identifier+"_basic/"
+	unPackFilePath := configPatchPath+"/"+identifier+ext
+
+	if util.Exists(unPackTargetPath) {
+		//姝ょ増鏈凡缁忔洿鏂拌繃
+		rmErr := os.RemoveAll(unPackTargetPath)
+		if rmErr !=nil {
+			return false,rmErr
+		}
+	}
+	if !util.CreateDirectory(unPackTargetPath) {
+		return false, errors.New("鍒涘缓鍘嬬缉鏂囦欢澶瑰け璐�")
+	}
+	logger.Debug("unPackFilePath:", unPackFilePath, "unPackPath:", unPackTargetPath)
+	_,err := util.UnTarGzByCmd(unPackFilePath, unPackTargetPath)
+	if err !=nil {
+		logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath)
+		return false, err
+	}
+	return true, nil
+}
+
+func (sv SdkInstallService) ShowInstallInfo(identifier string) (bool, map[string]interface{}) {
+	configPatchPath := ""
+	if config.Server.PatchPath != "" {
+		configPatchPath = config.Server.PatchPath
+	} else {
+		configPatchPath = "../patch"
+	}
+	unPackTargetPath := configPatchPath+"/"+identifier+"_basic/"
+	if util.Exists(unPackTargetPath) {
+		targetFileName := ""
+		err := filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error {
+			if f == nil {
+				return err
+			}
+			if f.IsDir() {
+				targetFileName = f.Name()
+			}
+			return nil
+		})
+		if err != nil {
+			return false, nil
+		} else {
+			unPackPath := unPackTargetPath + targetFileName +"/"
+			//瑙e帇瀹屾垚锛岃幏鍙栧畨瑁呭寘涓殑鏂囦欢锛屽紑濮嬪畨瑁�
+			//1.瑙f瀽瀹夎璇存槑ins.inc
+			incPath := unPackPath+"ins.inc"
+			if util.Exists(incPath) {
+				if incB, err := ioutil.ReadFile(incPath); err == nil {
+					var ins InsInc
+					if err = json.Unmarshal(incB, &ins); err == nil {
+						return true, map[string]interface{} {
+							"sdkName": ins.ProductName,
+							"installVersion": ins.InstallVersion,
+							"installContent": ins.InstallContent,
+						}
+					} else {
+						return false, nil
+					}
+				} else {
+					return false, nil
+				}
+			} else {
+				return false, nil
+			}
+		}
+	} else {
+		return false, nil
+	}
+}
+
 //瀹夎sdk
 func installSdk(identifier string, ext string) (bool, error) {
 	configPatchPath := ""
@@ -129,25 +210,12 @@
 		}
 	}()
 
-	if util.Exists(unPackTargetPath) {
-		//姝ょ増鏈凡缁忔洿鏂拌繃
-		rmErr := os.RemoveAll(unPackTargetPath)
-		if rmErr !=nil {
-			return false,rmErr
-		}
-	}
-	if !util.CreateDirectory(unPackTargetPath) {
-		return false, errors.New("鍒涘缓鍘嬬缉鏂囦欢澶瑰け璐�")
+	if !util.Exists(unPackTargetPath) {//瀹夎鍖呬笉瀛樺湪
+		return false, errors.New("瀹夎鏂囦欢宸蹭笉瀛樺湪")
 	}
 
-	logger.Debug("unPackFilePath:", unPackFilePath, "unPackPath:", unPackTargetPath)
-	_,err := util.UnTarGzByCmd(unPackFilePath, unPackTargetPath)
-	if err !=nil {
-		logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath)
-		return false, err
-	}
 	targetFileName := ""
-	err = filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error {
+	err := filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error {
 		if f == nil {
 			return err
 		}
@@ -160,6 +228,9 @@
 		return false, err
 	}
 	unPackPath := unPackTargetPath + targetFileName +"/"
+	if !util.Exists(unPackPath) {
+		return false, errors.New("瀹夎鏂囦欢宸蹭笉瀛樺湪")
+	}
 	//瑙e帇瀹屾垚锛岃幏鍙栧畨瑁呭寘涓殑鏂囦欢锛屽紑濮嬪畨瑁�
 	//1.瑙f瀽瀹夎璇存槑ins.inc
 	incPath := unPackPath+"ins.inc"
@@ -362,6 +433,10 @@
 	ChCount 			int 		`json:"chCount"`
 	AuthCount 			int 		`json:"authCount"`
 	ServeYear			int 		`json:"serveYear"`
+
+	ProductName 		string 		`json:"productName"`
+	InstallVersion 		string 		`json:"installVersion"`
+	InstallContent 		string 		`json:"installContent"`
 }
 
 //绠楁硶鍜屽弬鏁板畾涔�
diff --git a/service/SysService.go b/service/SysService.go
index 62c1d04..c4139b2 100644
--- a/service/SysService.go
+++ b/service/SysService.go
@@ -145,6 +145,11 @@
 	if isComplete {
 		if MergeChunks(fileTmpPath,fileTmpPath + subfix) {
 			logger.Debug("merge all chunks success,identifier:",MD5Str,"fileName:",arg.FileName)
+			unPackB, unPackErr := unPackPatchPackage(MD5Str, subfix)
+			logger.Debug("unPackB:", unPackB, "unPackErr:", unPackErr)
+			if unPackB {
+				return true, isComplete
+			}
 		} else {
 			return false, isComplete
 		}

--
Gitblit v1.8.0