diff --git a/features/cm/license.go b/features/cm/license.go index 30b2e1f1..ffee447b 100644 --- a/features/cm/license.go +++ b/features/cm/license.go @@ -8,11 +8,13 @@ import ( "os/exec" "strings" + "be.ems/lib/core/utils/ctx" "be.ems/lib/dborm" "be.ems/lib/log" "be.ems/lib/services" "be.ems/restagent/config" - + neModel "be.ems/src/modules/network_element/model" + neService "be.ems/src/modules/network_element/service" "github.com/gorilla/mux" ) @@ -503,22 +505,54 @@ func UploadLicenseFileData(w http.ResponseWriter, r *http.Request) { } } */ - neLicense := dborm.NeLicense{ - NeType: neTypeUpper, - NeID: neId, - Status: "ACTIVE", - Path: licensePath, - FileName: licenseFileName, - Comment: comment, + + // neLicense := dborm.NeLicense{ + // NeType: neTypeUpper, + // NeID: neId, + // Status: "ACTIVE", + // Path: licensePath, + // FileName: licenseFileName, + // Comment: comment, + // } + + // log.Debug("neLicense:", neLicense) + // _, err = dborm.XormInsertTableOne("ne_license", neLicense) + // if err != nil { + // log.Error("Faile to XormInsertTableOne:", err) + // services.ResponseInternalServerError500ProcessError(w, err) + // } + + neLicense := neModel.NeLicense{ + NeType: neTypeUpper, + NeId: neId, + Status: "0", + LicensePath: neFilePath, + Remark: comment, } log.Debug("neLicense:", neLicense) - _, err = dborm.XormInsertTableOne("ne_license", neLicense) - if err != nil { - log.Error("Faile to XormInsertTableOne:", err) - services.ResponseInternalServerError500ProcessError(w, err) - return + + // 检查是否存在授权记录 + neLicense2 := neService.NewNeLicenseImpl.SelectByNeTypeAndNeID(neTypeUpper, neId) + if neLicense2.NeId != neId { + // 读取授权码 + code, _ := neService.NewNeLicenseImpl.ReadLicenseInfo(neLicense) + neLicense.ActivationRequestCode = code + + neLicense.CreateBy = ctx.LoginUserToUserName(r) + insertId := neService.NewNeLicenseImpl.Insert(neLicense) + if insertId != "" { + services.ResponseStatusOK204NoContent(w) + return + } + } else { + neLicense2.UpdateBy = ctx.LoginUserToUserName(r) + upRows := neService.NewNeLicenseImpl.Update(neLicense2) + if upRows > 0 { + services.ResponseStatusOK204NoContent(w) + return + } } - services.ResponseStatusOK204NoContent(w) + services.ResponseInternalServerError500ProcessError(w, err) }