merge: 合并OMC分支
This commit is contained in:
@@ -10,9 +10,9 @@ import (
|
||||
|
||||
"strings"
|
||||
|
||||
"nms_cxy/features/sys_role/model"
|
||||
"nms_cxy/lib/log"
|
||||
"nms_cxy/lib/oauth"
|
||||
"nms_cxy/src/modules/system/model"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"xorm.io/xorm"
|
||||
@@ -45,9 +45,9 @@ type DatabaseClient struct {
|
||||
|
||||
var DbClient DatabaseClient
|
||||
|
||||
func InitDbClient(dbType, dbUser, dbPassword, dbHost, dbPort, dbName string) error {
|
||||
DbClient.dbUrl = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=true&loc=Local",
|
||||
dbUser, dbPassword, dbHost, dbPort, dbName)
|
||||
func InitDbClient(dbType, dbUser, dbPassword, dbHost, dbPort, dbName, dbParam string) error {
|
||||
DbClient.dbUrl = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?%s",
|
||||
dbUser, dbPassword, dbHost, dbPort, dbName, dbParam)
|
||||
DbClient.dbType = dbType
|
||||
DbClient.dbConnMaxLifetime = 0
|
||||
DbClient.dbMaxIdleConns = 0
|
||||
@@ -55,8 +55,7 @@ func InitDbClient(dbType, dbUser, dbPassword, dbHost, dbPort, dbName string) err
|
||||
if log.GetLevel() == log.LOG_TRACE {
|
||||
DbClient.IsShowSQL = true
|
||||
}
|
||||
log.Debugf("dbType:%s dbUrl:%s:******@tcp(%s:%s)/%s??charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=true&loc=Local",
|
||||
dbType, dbUser, dbHost, dbPort, dbName)
|
||||
log.Debugf("dbType:%s dbUrl:%s:", dbType, DbClient.dbUrl)
|
||||
|
||||
var err error
|
||||
DbClient.XEngine, err = xorm.NewEngine(DbClient.dbType, DbClient.dbUrl)
|
||||
@@ -67,9 +66,12 @@ func InitDbClient(dbType, dbUser, dbPassword, dbHost, dbPort, dbName string) err
|
||||
DbClient.XEngine.SetConnMaxLifetime(DbClient.dbConnMaxLifetime)
|
||||
DbClient.XEngine.SetMaxIdleConns(DbClient.dbMaxIdleConns)
|
||||
DbClient.XEngine.SetMaxOpenConns(DbClient.dbMaxOpenConns)
|
||||
DbClient.XEngine.DatabaseTZ = time.Local // 必须
|
||||
DbClient.XEngine.TZLocation = time.Local // 必须
|
||||
if DbClient.IsShowSQL {
|
||||
DbClient.XEngine.ShowSQL(true)
|
||||
}
|
||||
|
||||
xEngine = DbClient.XEngine
|
||||
|
||||
return nil
|
||||
@@ -180,20 +182,20 @@ func InsertDataWithJson(insertData interface{}) (int64, error) {
|
||||
}
|
||||
|
||||
type NeInfo struct {
|
||||
Id int `json:"id" xorm:"pk 'id' autoincr"`
|
||||
NeType string `json:"neType" xorm:"ne_type"`
|
||||
NeId string `json:"neId" xorm:"ne_id"` // neUID/rmUID 网元唯一标识
|
||||
RmUID string `json:"rmUid" xorm:"rm_uid"` // neUID/rmUID网元UID
|
||||
NeName string `json:"neName" xorm:"ne_name"` // NeName/UserLabel 网元名称/网元设备友好名称
|
||||
Ip string `json:"ip" xorm:"ip"`
|
||||
Port string `json:"port" xorm:"port"`
|
||||
PvFlag string `json:"pvFlag" xorm:"pv_flag"` // 网元虚实性标识 VNF/PNF: 虚拟/物理
|
||||
NeAddress string `json:"neAddress" xorm:"ne_address"` // 只对PNF
|
||||
Province string `json:"province" xorm:"province"` // 网元所在省份
|
||||
VendorName string `json:"vendorName" xorm:"vendor_name"` // 厂商名称
|
||||
Dn string `json:"dn" xorm:"dn"` // 网络标识
|
||||
Status int `json:"status" xorm:"status"`
|
||||
UpdateTime string `json:"-" xorm:"-"`
|
||||
Id int `json:"id" xorm:"pk 'id' autoincr"`
|
||||
NeType string `json:"neType" xorm:"ne_type"`
|
||||
NeId string `json:"neId" xorm:"ne_id"` // neUID/rmUID 网元唯一标识
|
||||
RmUID string `json:"rmUid" xorm:"rm_uid"` // neUID/rmUID网元UID
|
||||
NeName string `json:"neName" xorm:"ne_name"` // NeName/UserLabel 网元名称/网元设备友好名称
|
||||
Ip string `json:"ip" xorm:"ip"`
|
||||
Port string `json:"port" xorm:"port"`
|
||||
PvFlag string `json:"pvFlag" xorm:"pv_flag"` // 网元虚实性标识 VNF/PNF: 虚拟/物理
|
||||
NeAddress string `json:"neAddress" xorm:"ne_address"` // 只对PNF
|
||||
Province string `json:"province" xorm:"province"` // 网元所在省份
|
||||
VendorName string `json:"vendorName" xorm:"vendor_name"` // 厂商名称
|
||||
Dn string `json:"dn" xorm:"dn"` // 网络标识
|
||||
Status int `json:"status" xorm:"status"`
|
||||
UpdateTime time.Time `json:"updateTime" xorm:"<-"`
|
||||
}
|
||||
|
||||
func XormGetMySQLVersion() (string, error) {
|
||||
@@ -1400,11 +1402,11 @@ type MeasureThreshold struct {
|
||||
type NeSoftware struct {
|
||||
Id int `json:"id" xorm:"pk 'id' autoincr"`
|
||||
NeType string `json:"neType" xorm:"ne_type"`
|
||||
FileName string `json:"neName" xorm:"file_name"`
|
||||
Path string `json:"path"`
|
||||
Version string `json:"version"`
|
||||
Md5Sum string `json:"md5Sum" xorm:"md5_sum"`
|
||||
Comment string `json:"comment"`
|
||||
FileName string `json:"fileName" xorm:"name"`
|
||||
Path string `json:"path" xorm:"path"`
|
||||
Version string `json:"version" `
|
||||
Md5Sum string `json:"md5Sum" xorm:"-"`
|
||||
Comment string `json:"comment" xorm:"description"`
|
||||
// Status string `json:"status"`
|
||||
UpdateTime string `json:"createTime" xorm:"-" `
|
||||
}
|
||||
@@ -1413,13 +1415,13 @@ type NeVersion struct {
|
||||
Id int `json:"id" xorm:"pk 'id' autoincr"`
|
||||
NeType string `json:"neType" xorm:"ne_type"`
|
||||
NeId string `json:"neId" xorm:"ne_id"`
|
||||
Version string `json:"version"`
|
||||
FilePath string `json:"filePath" xorm:"file_path"`
|
||||
Version string `json:"version" `
|
||||
FilePath string `json:"filePath" xorm:"path"`
|
||||
NewVersion string `json:"newVersion" xorm:"new_version"`
|
||||
NewFile string `json:"newFile" xorm:"new_file"`
|
||||
NewFile string `json:"newFile" xorm:"new_path"`
|
||||
PreVersion string `json:"preVersion" xorm:"pre_version"`
|
||||
PreFile string `json:"preFile" xorm:"pre_file"`
|
||||
Status string `json:"status"`
|
||||
PreFile string `json:"preFile" xorm:"pre_path"`
|
||||
Status string `json:"status" xorm:"status"`
|
||||
UpdateTime string `json:"createTime" xorm:"-" `
|
||||
}
|
||||
|
||||
@@ -1451,6 +1453,15 @@ func XormDeleteDataByWhere(where, table string) (int64, error) {
|
||||
return affected, nil
|
||||
}
|
||||
|
||||
func XormDeleteDataByWhereNoSession(where, table string) (int64, error) {
|
||||
affected, err := DbClient.XEngine.Table(table).Where(where).Delete()
|
||||
if err != nil {
|
||||
log.Error("Failed to Delete:", err)
|
||||
return 0, err
|
||||
}
|
||||
return affected, nil
|
||||
}
|
||||
|
||||
func XormDeleteDataById(id int, table string) (int64, error) {
|
||||
log.Debug("XormDeleteDataByWhere processing... ")
|
||||
|
||||
@@ -1632,9 +1643,10 @@ type AlarmForwardLog struct {
|
||||
AlarmTitle string `json:"alarmTitle" xorm:"alarm_title"`
|
||||
AlarmSeq int `json:"alarmSeq" xorm:"alarm_seq"`
|
||||
EventTime string `json:"eventTime" xorm:"event_time"`
|
||||
Interface string `json:"interface" xorm:"interface"`
|
||||
ToUser string `json:"toUser" xorm:"to_user"`
|
||||
OperResult string `json:"operResult" xorm:"oper_result"`
|
||||
LogTime string `json:"-" xorm:"-"`
|
||||
LogTime string `json:"logTime" xorm:"<-"`
|
||||
}
|
||||
|
||||
func XormInsertAlarmForwardLog(logData *AlarmForwardLog) (int64, error) {
|
||||
@@ -1669,7 +1681,7 @@ func XormInsertSystemLog(logData *SystemLog) (int64, error) {
|
||||
return affected, err
|
||||
}
|
||||
|
||||
type permission struct {
|
||||
type Permission struct {
|
||||
ID int `json:"-" xorm:"pk 'id' autoincr"`
|
||||
PermissionName string `json:"permissionName"`
|
||||
Method string `json:"method"`
|
||||
@@ -1696,25 +1708,26 @@ func IsPermissionAllowed(token, method, module, dbname, tbname, pack string) (bo
|
||||
type NeLicense struct {
|
||||
NeType string `json:"neType" xorm:"ne_type"`
|
||||
NeID string `json:"neID" xorm:"ne_id"`
|
||||
SerialNo string `json:"serialNo" xorm:"serial_no"`
|
||||
Capcity int `json:"capcity" xorm:"capcity"`
|
||||
Used int `json:"used" xorm:"used"`
|
||||
FeatureEnabled string `json:"featureEnabled" xorm:"feature_enabled"`
|
||||
ExpirationDate string `json:"expirationDate" xorm:"expiration_date"`
|
||||
SerialNo string `json:"serialNo" xorm:"serial_num"`
|
||||
Capcity int `json:"capcity" xorm:"-"`
|
||||
Used int `json:"used" xorm:"-"`
|
||||
FeatureEnabled string `json:"featureEnabled" xorm:"-"`
|
||||
ExpirationDate string `json:"expirationDate" xorm:"expiry_date"`
|
||||
Status string `json:"status" xorm:"status"`
|
||||
Path string `json:"path" xorm:"path"`
|
||||
FileName string `json:"file_name" xorm:"file_name"`
|
||||
Comment string `json:"comment" xorm:"comment"`
|
||||
Path string `json:"path" xorm:"license_path"`
|
||||
FileName string `json:"file_name" xorm:"-"`
|
||||
Comment string `json:"comment" xorm:"remark"`
|
||||
CreatedAt string `json:"createdAt" xorm:"-"`
|
||||
UpdatedAt string `json:"updatedAt" xorm:"-"`
|
||||
DeletedAt string `json:"deletedAt" xorm:"-"`
|
||||
}
|
||||
|
||||
func XormAdjustmentNeLicense(neType, neID string, value int) (int64, error) {
|
||||
return 1, nil
|
||||
//neLicense := NeLicense{NeType: neType, NeID: neID, Capability: value}
|
||||
// session.LogoutTime.Valid = true
|
||||
// session.LogoutTime.Time = time.Now()
|
||||
res, err := xEngine.Exec("update ne_license set capcity=capcity+? where IFNULL(ne_type, '')=? and IFNULL(ne_id, '')=?", value, neType, neID)
|
||||
// res, err := xEngine.Exec("update ne_license set capcity=capcity+? where IFNULL(ne_type, '')=? and IFNULL(ne_id, '')=?", value, neType, neID)
|
||||
// defer xSession.Close()
|
||||
|
||||
//affected, err := xSession.Table("ne_license").Where("ne_type=? and ne_id=?", neType, neID).Update(&neLicense)
|
||||
@@ -1722,25 +1735,26 @@ func XormAdjustmentNeLicense(neType, neID string, value int) (int64, error) {
|
||||
// //affected, err := xSession.Table("ne_license").SQL("ne_tye=? and ne_id=?", neType, neID).Update(session)
|
||||
// err := xSession.SQL("update ne_license set capability=capability+? where ne_type=? and ne_id=?", value, neType, neID)
|
||||
//xSession.Commit()
|
||||
affected, err := res.RowsAffected()
|
||||
return affected, err
|
||||
// affected, err := res.RowsAffected()
|
||||
// return affected, err
|
||||
}
|
||||
|
||||
func XormUpdateNeLicense(neType, neID string, capcity int) (int64, error) {
|
||||
var err error
|
||||
var res sql.Result
|
||||
if neType != "" && neID != "" {
|
||||
res, err = xEngine.Exec("update ne_license set capcity=? where ne_type=? and ne_id=?", capcity, neType, neID)
|
||||
} else if neType != "" && neID == "" {
|
||||
res, err = xEngine.Exec("update ne_license set capcity=? where ne_type=?", capcity, neType)
|
||||
} else if neType == "" && neID != "" {
|
||||
res, err = xEngine.Exec("update ne_license set capcity=? where ne_id=?", capcity, neID)
|
||||
} else {
|
||||
res, err = xEngine.Exec("update ne_license set capcity=?", capcity)
|
||||
}
|
||||
return 1, nil
|
||||
// var err error
|
||||
// var res sql.Result
|
||||
// if neType != "" && neID != "" {
|
||||
// res, err = xEngine.Exec("update ne_license set capcity=? where ne_type=? and ne_id=?", capcity, neType, neID)
|
||||
// } else if neType != "" && neID == "" {
|
||||
// res, err = xEngine.Exec("update ne_license set capcity=? where ne_type=?", capcity, neType)
|
||||
// } else if neType == "" && neID != "" {
|
||||
// res, err = xEngine.Exec("update ne_license set capcity=? where ne_id=?", capcity, neID)
|
||||
// } else {
|
||||
// res, err = xEngine.Exec("update ne_license set capcity=?", capcity)
|
||||
// }
|
||||
|
||||
affected, err := res.RowsAffected()
|
||||
return affected, err
|
||||
// affected, err := res.RowsAffected()
|
||||
// return affected, err
|
||||
}
|
||||
|
||||
type NorthboundCm struct {
|
||||
@@ -1765,21 +1779,21 @@ func XormGetNorthboundCm(neType string, cmResults *[]NorthboundCm) error {
|
||||
log.Info("XormGetNorthboundCm processing... ")
|
||||
|
||||
cmResult := new(NorthboundCm)
|
||||
rows, err := xEngine.Table("northbound_cm").
|
||||
rows, err := xEngine.Table("nbi_cm").
|
||||
Distinct("object_type").
|
||||
Where("`ne_type` = ?", neType).
|
||||
Desc("timestamp").
|
||||
Cols("*").
|
||||
Rows(cmResult)
|
||||
if err != nil {
|
||||
log.Error("Failed to get table northbound_cm:", err)
|
||||
log.Error("Failed to get table nbi_cm:", err)
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
err := rows.Scan(cmResult)
|
||||
if err != nil {
|
||||
log.Error("Failed to get table northbound_cm:", err)
|
||||
log.Error("Failed to get table nbi_cm:", err)
|
||||
return err
|
||||
}
|
||||
*cmResults = append(*cmResults, *cmResult)
|
||||
@@ -1791,14 +1805,14 @@ func XormGetNorthboundCmLatestObject(neType, neID, objectType string) (*Northbou
|
||||
log.Info("XormGetNorthboundCmLatestObject processing... ")
|
||||
|
||||
cmResult := new(NorthboundCm)
|
||||
_, err := xEngine.Table("northbound_cm").
|
||||
_, err := xEngine.Table("nbi_cm").
|
||||
Where("`ne_type`=? and `ne_id`=? and `object_type`=?", neType, neID, objectType).
|
||||
Desc("timestamp").
|
||||
Cols("*").
|
||||
Limit(1).
|
||||
Get(cmResult)
|
||||
if err != nil {
|
||||
log.Error("Failed to get table northbound_cm:", err)
|
||||
log.Error("Failed to get table nbi_cm:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user