Merge remote-tracking branch 'origin/main' into practical-training
This commit is contained in:
@@ -50,11 +50,11 @@ func (c *ConnTelnet) NewClient() (*ConnTelnet, error) {
|
||||
// fmt.Fprintln(client, c.User)
|
||||
// fmt.Fprintln(client, c.Password)
|
||||
|
||||
// 需要确保接收方理解并正确处理发送窗口大小设置命令
|
||||
client.Write([]byte{255, 251, 31}) // 发送窗口大小选项
|
||||
client.Write([]byte{255, 250, 31, 0, 120, 0, 128, 255, 240}) // 发送窗口行和列的大小 (120 列 x 128 行)
|
||||
c.Client = &client
|
||||
|
||||
// 调整窗口大小 (120 列 x 128 行)
|
||||
requestPty(c.Client, 120, 128)
|
||||
|
||||
// 排空连接登录的信息
|
||||
c.RunCMD("")
|
||||
return c, nil
|
||||
@@ -107,15 +107,24 @@ func (c *ConnTelnet) RunCMD(cmd string) (string, error) {
|
||||
}
|
||||
|
||||
// NewClient 创建Telnet客户端会话对象
|
||||
func (c *ConnTelnet) NewClientSession(cols, rows uint8) (*TelnetClientSession, error) {
|
||||
func (c *ConnTelnet) NewClientSession(cols, rows int) (*TelnetClientSession, error) {
|
||||
if c.Client == nil {
|
||||
return nil, fmt.Errorf("telnet client not connected")
|
||||
}
|
||||
conn := *c.Client
|
||||
// 调整窗口
|
||||
conn.Write([]byte{255, 251, 31})
|
||||
conn.Write([]byte{255, 250, 31, 0, cols, 0, rows, 255, 240})
|
||||
requestPty(c.Client, cols, rows)
|
||||
return &TelnetClientSession{
|
||||
Client: conn,
|
||||
Client: *c.Client,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// requestPty 调整终端窗口大小
|
||||
func requestPty(client *net.Conn, cols, rows int) error {
|
||||
if client == nil {
|
||||
return fmt.Errorf("telnet client not connected")
|
||||
}
|
||||
conn := *client
|
||||
// 需要确保接收方理解并正确处理发送窗口大小设置命令
|
||||
conn.Write([]byte{255, 251, 31})
|
||||
conn.Write([]byte{255, 250, 31, byte(cols >> 8), byte(cols & 0xFF), byte(rows >> 8), byte(rows & 0xFF), 255, 240})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -96,19 +96,47 @@ func (r *PerfKPIImpl) SelectKpiReport(query model.GoldKPIQuery, kpiIds []string)
|
||||
params = append(params, query.RmUID)
|
||||
}
|
||||
if query.NeType != "" {
|
||||
conditions = append(conditions, "gk.ne_type = ?")
|
||||
params = append(params, query.NeType)
|
||||
//conditions = append(conditions, "gk.ne_type = ?")
|
||||
// params = append(params, query.NeType)
|
||||
tableName += strings.ToLower(query.NeType)
|
||||
}
|
||||
var dateTimeStr string = "CONCAT(gk.`date`, \" \", gk.start_time)"
|
||||
|
||||
var dateStr1, dateStr2, timeStr1, timeStr2 string
|
||||
if query.StartTime != "" {
|
||||
conditions = append(conditions, dateTimeStr+" >= ?")
|
||||
params = append(params, query.StartTime)
|
||||
dateStr1 = query.StartTime[:10]
|
||||
timeStr1 = query.StartTime[11:]
|
||||
}
|
||||
if query.EndTime != "" {
|
||||
conditions = append(conditions, dateTimeStr+" <= ?")
|
||||
params = append(params, query.EndTime)
|
||||
dateStr2 = query.EndTime[:10]
|
||||
timeStr2 = query.EndTime[11:]
|
||||
}
|
||||
if dateStr1 == dateStr2 && dateStr1 != "" {
|
||||
conditions = append(conditions, "gk.`date` = ?")
|
||||
params = append(params, dateStr1)
|
||||
conditions = append(conditions, "gk.`start_time` >= ?")
|
||||
params = append(params, timeStr1)
|
||||
conditions = append(conditions, "gk.`start_time` <= ?")
|
||||
params = append(params, timeStr2)
|
||||
} else {
|
||||
if dateStr1 != "" {
|
||||
conditions = append(conditions, "(gk.`date` > ? OR (gk.`date` = ? AND gk.`start_time` >= ?))")
|
||||
params = append(params, dateStr1, dateStr1, timeStr1)
|
||||
}
|
||||
if dateStr2 != "" {
|
||||
conditions = append(conditions, "(gk.`date` < ? OR (gk.`date` = ? AND gk.`start_time` <= ?))")
|
||||
params = append(params, dateStr2, dateStr2, timeStr2)
|
||||
}
|
||||
}
|
||||
|
||||
// var dateTimeStr string = "CONCAT(gk.`date`, \" \", gk.start_time)"
|
||||
// if query.StartTime != "" {
|
||||
// conditions = append(conditions, dateTimeStr+" >= ?")
|
||||
// params = append(params, query.StartTime)
|
||||
// }
|
||||
// if query.EndTime != "" {
|
||||
// conditions = append(conditions, dateTimeStr+" <= ?")
|
||||
// params = append(params, query.EndTime)
|
||||
// }
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
@@ -116,6 +144,7 @@ func (r *PerfKPIImpl) SelectKpiReport(query model.GoldKPIQuery, kpiIds []string)
|
||||
}
|
||||
|
||||
// 查询字段列
|
||||
var dateTimeStr string = "CONCAT(gk.`date`, \" \", gk.start_time)"
|
||||
timeFormat := "DATE_FORMAT(" + dateTimeStr + ", '%Y-%m-%d %H:%i:')"
|
||||
secondGroup := fmt.Sprintf("LPAD(FLOOR(SECOND(gk.start_time) / %d) * %d, 2, '0')", query.Interval, query.Interval)
|
||||
groupByField := fmt.Sprintf("CONCAT( %s, %s ) AS timeGroup", timeFormat, secondGroup)
|
||||
|
||||
@@ -198,7 +198,7 @@ func (s *NeLicenseController) State(c *gin.Context) {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
if neState, err := neService.NeState(neInfo); err == nil {
|
||||
if neState, err := neService.NeState(neInfo); err == nil && neState["sn"] != nil {
|
||||
neLicense.Status = "1"
|
||||
neLicense.SerialNum = fmt.Sprint(neState["sn"])
|
||||
neLicense.ExpiryDate = fmt.Sprint(neState["expire"])
|
||||
|
||||
@@ -257,18 +257,18 @@ func (s *WSController) Telnet(c *gin.Context) {
|
||||
defer client.Close()
|
||||
|
||||
// 终端单行字符数
|
||||
cols, err := strconv.Atoi(c.Query("cols"))
|
||||
if err != nil || cols > 254 {
|
||||
cols, err := strconv.Atoi(c.DefaultQuery("cols", "120"))
|
||||
if err != nil {
|
||||
cols = 120
|
||||
}
|
||||
// 终端显示行数
|
||||
rows, err := strconv.Atoi(c.Query("rows"))
|
||||
if err != nil || cols > rows {
|
||||
rows, err := strconv.Atoi(c.DefaultQuery("rows", "128"))
|
||||
if err != nil {
|
||||
rows = 128
|
||||
}
|
||||
|
||||
// 创建Telnet客户端会话
|
||||
clientSession, err := client.NewClientSession(uint8(cols), uint8(rows))
|
||||
clientSession, err := client.NewClientSession(cols, rows)
|
||||
if err != nil {
|
||||
// 连接主机失败,请检查连接参数后重试
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
||||
|
||||
Reference in New Issue
Block a user