gengxin
This commit is contained in:
@@ -143,6 +143,40 @@ func (c *PlatformCursorEquipmentController) rowToMap(row *models.PlatformCursorE
|
||||
lastExtractedAt = latestExtract.ExtractedTime
|
||||
}
|
||||
|
||||
// 查询该设备最近一条 IP 日志
|
||||
var lastLoginIp interface{}
|
||||
var lastLoginIpInfo interface{}
|
||||
var latestIpLog models.PlatformCursorEquipmentIpLog
|
||||
ipCond := orm.NewCondition().
|
||||
AndCond(orm.NewCondition().
|
||||
Or("equipment_id", row.ID).
|
||||
Or("machine_code", row.MachineCode))
|
||||
if err := models.Orm.QueryTable(new(models.PlatformCursorEquipmentIpLog)).
|
||||
SetCond(ipCond).
|
||||
OrderBy("-id").
|
||||
One(&latestIpLog); err == nil {
|
||||
lastLoginIp = latestIpLog.Query
|
||||
lastLoginIpInfo = map[string]interface{}{
|
||||
"id": latestIpLog.ID,
|
||||
"source": latestIpLog.Source,
|
||||
"status": latestIpLog.Status,
|
||||
"country": latestIpLog.Country,
|
||||
"countryCode": latestIpLog.CountryCode,
|
||||
"region": latestIpLog.Region,
|
||||
"regionName": latestIpLog.RegionName,
|
||||
"city": latestIpLog.City,
|
||||
"zip": latestIpLog.Zip,
|
||||
"lat": latestIpLog.Lat,
|
||||
"lon": latestIpLog.Lon,
|
||||
"timezone": latestIpLog.Timezone,
|
||||
"isp": latestIpLog.ISP,
|
||||
"org": latestIpLog.Org,
|
||||
"asInfo": latestIpLog.AsInfo,
|
||||
"query": latestIpLog.Query,
|
||||
"createTime": latestIpLog.CreateTime,
|
||||
}
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"id": row.ID,
|
||||
"deviceInfo": row.DeviceInfo,
|
||||
@@ -164,6 +198,8 @@ func (c *PlatformCursorEquipmentController) rowToMap(row *models.PlatformCursorE
|
||||
"activationCount": activationCount,
|
||||
"extractCount": extractCount,
|
||||
"lastExtractedAt": lastExtractedAt,
|
||||
"lastLoginIp": lastLoginIp,
|
||||
"lastLoginIpInfo": lastLoginIpInfo,
|
||||
"remark": row.Remark,
|
||||
"createTime": row.CreateTime,
|
||||
"updateTime": row.UpdateTime,
|
||||
@@ -679,3 +715,85 @@ func (c *PlatformCursorEquipmentController) ExtractRecords() {
|
||||
"pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
// IpLogs GET /platform/cursor/equipment/ipLogs?equipmentId=1
|
||||
func (c *PlatformCursorEquipmentController) IpLogs() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
equipmentID, _ := c.GetUint64("equipmentId")
|
||||
if equipmentID == 0 {
|
||||
equipmentID, _ = c.GetUint64("id")
|
||||
}
|
||||
if equipmentID == 0 {
|
||||
c.jsonErr(400, 400, "缺少设备ID")
|
||||
return
|
||||
}
|
||||
|
||||
var equipment models.PlatformCursorEquipment
|
||||
if err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
|
||||
Filter("id", equipmentID).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&equipment); err != nil {
|
||||
c.jsonErr(404, 404, "设备不存在")
|
||||
return
|
||||
}
|
||||
|
||||
page, _ := c.GetInt("page", 1)
|
||||
pageSize, _ := c.GetInt("pageSize", 20)
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize < 1 {
|
||||
pageSize = 20
|
||||
}
|
||||
if pageSize > 200 {
|
||||
pageSize = 200
|
||||
}
|
||||
|
||||
ipCond := orm.NewCondition().
|
||||
AndCond(orm.NewCondition().
|
||||
Or("equipment_id", equipment.ID).
|
||||
Or("machine_code", equipment.MachineCode))
|
||||
|
||||
qs := models.Orm.QueryTable(new(models.PlatformCursorEquipmentIpLog)).SetCond(ipCond)
|
||||
total, _ := qs.Count()
|
||||
|
||||
var rows []models.PlatformCursorEquipmentIpLog
|
||||
if _, err := qs.OrderBy("-id").Limit(pageSize, (page-1)*pageSize).All(&rows); err != nil {
|
||||
c.jsonErr(500, 500, "获取 IP 日志失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
list := make([]map[string]interface{}, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": row.ID,
|
||||
"source": row.Source,
|
||||
"status": row.Status,
|
||||
"country": row.Country,
|
||||
"countryCode": row.CountryCode,
|
||||
"region": row.Region,
|
||||
"regionName": row.RegionName,
|
||||
"city": row.City,
|
||||
"zip": row.Zip,
|
||||
"lat": row.Lat,
|
||||
"lon": row.Lon,
|
||||
"timezone": row.Timezone,
|
||||
"isp": row.ISP,
|
||||
"org": row.Org,
|
||||
"asInfo": row.AsInfo,
|
||||
"query": row.Query,
|
||||
"createTime": row.CreateTime,
|
||||
})
|
||||
}
|
||||
|
||||
c.ok(map[string]interface{}{
|
||||
"list": list,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user