增加续杯接口
This commit is contained in:
parent
df02280086
commit
6b8651af25
224
controllers/api_cursor_equipment.go
Normal file
224
controllers/api_cursor_equipment.go
Normal file
@ -0,0 +1,224 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// ApiCursorEquipmentController 开放接口:登录器上报 Cursor 设备信息(无需登录)
|
||||
type ApiCursorEquipmentController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
type cursorEquipmentReportPayload struct {
|
||||
DeviceInfo string `json:"deviceInfo"`
|
||||
DeviceInfoSnake string `json:"device_info"`
|
||||
MachineCode string `json:"machineCode"`
|
||||
MachineCodeSnake string `json:"machine_code"`
|
||||
Status *int8 `json:"status"`
|
||||
System string `json:"system"`
|
||||
Version string `json:"version"`
|
||||
BindAccount string `json:"bindAccount"`
|
||||
BindAccountSnake string `json:"bind_account"`
|
||||
OwnerUserID *uint64 `json:"ownerUserId"`
|
||||
OwnerUserIDSnake *uint64 `json:"owner_user_id"`
|
||||
OwnerUserName string `json:"ownerUserName"`
|
||||
OwnerUserNameSnake string `json:"owner_user_name"`
|
||||
ActivationTime string `json:"activationTime"`
|
||||
ActivationTimeSnake string `json:"activation_time"`
|
||||
ExpireTime string `json:"expireTime"`
|
||||
ExpireTimeSnake string `json:"expire_time"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
func cursorFirstNonEmpty(values ...string) string {
|
||||
for _, v := range values {
|
||||
if s := strings.TrimSpace(v); s != "" {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func cursorStringPtr(value string) *string {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
return &value
|
||||
}
|
||||
|
||||
func cursorParseTimePtr(value string) *time.Time {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
layouts := []string{
|
||||
time.RFC3339,
|
||||
"2006-01-02 15:04:05",
|
||||
"2006-01-02 15:04",
|
||||
"2006-01-02",
|
||||
}
|
||||
for _, layout := range layouts {
|
||||
if t, err := time.ParseInLocation(layout, value, time.Local); err == nil {
|
||||
return &t
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cursorValidStatus(status int8) bool {
|
||||
return status == 0 || status == 1 || status == 2 || status == 3
|
||||
}
|
||||
|
||||
func (c *ApiCursorEquipmentController) jsonResult(code int, msg string, data interface{}) {
|
||||
resp := map[string]interface{}{"code": code, "msg": msg}
|
||||
if data != nil {
|
||||
resp["data"] = data
|
||||
}
|
||||
c.Data["json"] = resp
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// Report POST /api/cursor/equipment/report
|
||||
//
|
||||
// JSON 示例:
|
||||
//
|
||||
// {
|
||||
// "machineCode": "ABC-123",
|
||||
// "deviceInfo": "CPU/RAM/磁盘等设备信息",
|
||||
// "system": "Windows",
|
||||
// "version": "1.0.0",
|
||||
// "bindAccount": "user@example.com",
|
||||
// "ownerUserId": 1,
|
||||
// "ownerUserName": "张三",
|
||||
// "activationTime": "2026-06-15 22:00:00",
|
||||
// "expireTime": "2026-07-15 22:00:00",
|
||||
// "remark": "登录器上报"
|
||||
// }
|
||||
//
|
||||
// 兼容 snake_case 字段,例如 machine_code、device_info、bind_account。
|
||||
func (c *ApiCursorEquipmentController) Report() {
|
||||
var p cursorEquipmentReportPayload
|
||||
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &p); err != nil {
|
||||
c.jsonResult(400, "参数错误", nil)
|
||||
return
|
||||
}
|
||||
|
||||
machineCode := cursorFirstNonEmpty(p.MachineCode, p.MachineCodeSnake)
|
||||
if machineCode == "" {
|
||||
c.jsonResult(400, "缺少参数 machineCode/machine_code(机器码)", nil)
|
||||
return
|
||||
}
|
||||
if len(machineCode) > 128 {
|
||||
c.jsonResult(400, "机器码长度不能超过 128 个字符", nil)
|
||||
return
|
||||
}
|
||||
|
||||
status := int8(0)
|
||||
statusProvided := p.Status != nil
|
||||
if statusProvided {
|
||||
status = *p.Status
|
||||
if !cursorValidStatus(status) {
|
||||
c.jsonResult(400, "状态不合法,支持:0 未激活、1 激活中、2 已过期、3 已禁用", nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
deviceInfo := cursorFirstNonEmpty(p.DeviceInfo, p.DeviceInfoSnake)
|
||||
system := cursorFirstNonEmpty(p.System)
|
||||
version := cursorFirstNonEmpty(p.Version)
|
||||
bindAccount := cursorFirstNonEmpty(p.BindAccount, p.BindAccountSnake)
|
||||
ownerUserID := p.OwnerUserID
|
||||
if ownerUserID == nil {
|
||||
ownerUserID = p.OwnerUserIDSnake
|
||||
}
|
||||
ownerUserName := cursorFirstNonEmpty(p.OwnerUserName, p.OwnerUserNameSnake)
|
||||
activationTime := cursorParseTimePtr(cursorFirstNonEmpty(p.ActivationTime, p.ActivationTimeSnake))
|
||||
expireTime := cursorParseTimePtr(cursorFirstNonEmpty(p.ExpireTime, p.ExpireTimeSnake))
|
||||
remark := cursorFirstNonEmpty(p.Remark)
|
||||
|
||||
now := time.Now()
|
||||
var row models.PlatformCursorEquipment
|
||||
err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
|
||||
Filter("machine_code", machineCode).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&row)
|
||||
|
||||
created := false
|
||||
if err == orm.ErrNoRows {
|
||||
row = models.PlatformCursorEquipment{
|
||||
MachineCode: machineCode,
|
||||
Status: status,
|
||||
DeviceInfo: cursorStringPtr(deviceInfo),
|
||||
System: cursorStringPtr(system),
|
||||
Version: cursorStringPtr(version),
|
||||
BindAccount: cursorStringPtr(bindAccount),
|
||||
OwnerUserID: ownerUserID,
|
||||
OwnerUserName: cursorStringPtr(ownerUserName),
|
||||
ActivationTime: activationTime,
|
||||
ExpireTime: expireTime,
|
||||
Remark: cursorStringPtr(remark),
|
||||
CreateTime: now,
|
||||
}
|
||||
id, insertErr := models.Orm.Insert(&row)
|
||||
if insertErr != nil {
|
||||
c.jsonResult(500, "设备信息保存失败", nil)
|
||||
return
|
||||
}
|
||||
row.ID = uint64(id)
|
||||
created = true
|
||||
} else if err != nil {
|
||||
c.jsonResult(500, "设备信息查询失败", nil)
|
||||
return
|
||||
} else {
|
||||
update := map[string]interface{}{
|
||||
"device_info": cursorStringPtr(deviceInfo),
|
||||
"system": cursorStringPtr(system),
|
||||
"version": cursorStringPtr(version),
|
||||
"bind_account": cursorStringPtr(bindAccount),
|
||||
"owner_user_id": ownerUserID,
|
||||
"owner_user_name": cursorStringPtr(ownerUserName),
|
||||
"activation_time": activationTime,
|
||||
"expire_time": expireTime,
|
||||
"remark": cursorStringPtr(remark),
|
||||
"update_time": now,
|
||||
}
|
||||
if statusProvided {
|
||||
update["status"] = status
|
||||
row.Status = status
|
||||
}
|
||||
|
||||
if _, updateErr := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
|
||||
Filter("id", row.ID).
|
||||
Update(update); updateErr != nil {
|
||||
c.jsonResult(500, "设备信息更新失败", nil)
|
||||
return
|
||||
}
|
||||
|
||||
row.DeviceInfo = cursorStringPtr(deviceInfo)
|
||||
row.System = cursorStringPtr(system)
|
||||
row.Version = cursorStringPtr(version)
|
||||
row.BindAccount = cursorStringPtr(bindAccount)
|
||||
row.OwnerUserID = ownerUserID
|
||||
row.OwnerUserName = cursorStringPtr(ownerUserName)
|
||||
row.ActivationTime = activationTime
|
||||
row.ExpireTime = expireTime
|
||||
row.Remark = cursorStringPtr(remark)
|
||||
row.UpdateTime = &now
|
||||
}
|
||||
|
||||
c.jsonResult(200, "success", map[string]interface{}{
|
||||
"id": row.ID,
|
||||
"machineCode": row.MachineCode,
|
||||
"status": row.Status,
|
||||
"created": created,
|
||||
})
|
||||
}
|
||||
492
controllers/platform_cursor_equipment.go
Normal file
492
controllers/platform_cursor_equipment.go
Normal file
@ -0,0 +1,492 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/jwtutil"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// PlatformCursorEquipmentController 平台端 Cursor 设备管理
|
||||
type PlatformCursorEquipmentController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *PlatformCursorEquipmentController) platformClaims() (*jwtutil.Claims, error) {
|
||||
auth := c.Ctx.Request.Header.Get("Authorization")
|
||||
if auth == "" {
|
||||
return nil, fmt.Errorf("未登录")
|
||||
}
|
||||
parts := strings.SplitN(auth, " ", 2)
|
||||
if len(parts) != 2 || parts[0] != "Bearer" {
|
||||
return nil, fmt.Errorf("认证信息格式错误")
|
||||
}
|
||||
claims, err := jwtutil.ParseToken(parts[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("无效的token")
|
||||
}
|
||||
if claims.UserType != "platform" {
|
||||
return nil, fmt.Errorf("无权访问")
|
||||
}
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func (c *PlatformCursorEquipmentController) jsonErr(httpStatus, bizCode int, msg string) {
|
||||
c.Ctx.Output.SetStatus(httpStatus)
|
||||
c.Data["json"] = map[string]interface{}{"code": bizCode, "msg": msg}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *PlatformCursorEquipmentController) ok(data interface{}) {
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": data}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func cursorEquipmentTrimPtr(value *string) *string {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
v := strings.TrimSpace(*value)
|
||||
if v == "" {
|
||||
return nil
|
||||
}
|
||||
return &v
|
||||
}
|
||||
|
||||
func cursorEquipmentTimePtr(value *string) *time.Time {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
v := strings.TrimSpace(*value)
|
||||
if v == "" {
|
||||
return nil
|
||||
}
|
||||
layouts := []string{
|
||||
time.RFC3339,
|
||||
"2006-01-02 15:04:05",
|
||||
"2006-01-02 15:04",
|
||||
"2006-01-02",
|
||||
}
|
||||
for _, layout := range layouts {
|
||||
if t, err := time.ParseInLocation(layout, v, time.Local); err == nil {
|
||||
return &t
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cursorEquipmentStatusValid(status int8) bool {
|
||||
return status == 0 || status == 1 || status == 2 || status == 3
|
||||
}
|
||||
|
||||
func (c *PlatformCursorEquipmentController) rowToMap(row *models.PlatformCursorEquipment) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": row.ID,
|
||||
"deviceInfo": row.DeviceInfo,
|
||||
"machineCode": row.MachineCode,
|
||||
"status": row.Status,
|
||||
"system": row.System,
|
||||
"version": row.Version,
|
||||
"bindAccount": row.BindAccount,
|
||||
"ownerUserId": row.OwnerUserID,
|
||||
"ownerUserName": row.OwnerUserName,
|
||||
"activationTime": row.ActivationTime,
|
||||
"expireTime": row.ExpireTime,
|
||||
"remark": row.Remark,
|
||||
"createTime": row.CreateTime,
|
||||
"updateTime": row.UpdateTime,
|
||||
}
|
||||
}
|
||||
|
||||
// List GET /platform/cursor/equipment/list
|
||||
func (c *PlatformCursorEquipmentController) List() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
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
|
||||
}
|
||||
|
||||
keyword := strings.TrimSpace(c.GetString("keyword"))
|
||||
statusText := strings.TrimSpace(c.GetString("status"))
|
||||
system := strings.TrimSpace(c.GetString("system"))
|
||||
if system == "" {
|
||||
system = strings.TrimSpace(c.GetString("os"))
|
||||
}
|
||||
|
||||
qs := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).Filter("delete_time__isnull", true)
|
||||
|
||||
if keyword != "" {
|
||||
cond := orm.NewCondition().
|
||||
Or("machine_code__icontains", keyword).
|
||||
Or("device_info__icontains", keyword).
|
||||
Or("bind_account__icontains", keyword).
|
||||
Or("owner_user_name__icontains", keyword).
|
||||
Or("remark__icontains", keyword)
|
||||
qs = qs.SetCond(cond)
|
||||
}
|
||||
|
||||
if statusText != "" {
|
||||
status, err := strconv.ParseInt(statusText, 10, 8)
|
||||
if err == nil && cursorEquipmentStatusValid(int8(status)) {
|
||||
qs = qs.Filter("status", int8(status))
|
||||
}
|
||||
}
|
||||
|
||||
if system != "" {
|
||||
qs = qs.Filter("system__icontains", system)
|
||||
}
|
||||
|
||||
total, _ := qs.Count()
|
||||
|
||||
var rows []models.PlatformCursorEquipment
|
||||
_, err := qs.OrderBy("-id").Limit(pageSize, (page-1)*pageSize).All(&rows)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "获取设备列表失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
list := make([]map[string]interface{}, 0, len(rows))
|
||||
for i := range rows {
|
||||
list = append(list, c.rowToMap(&rows[i]))
|
||||
}
|
||||
|
||||
c.ok(map[string]interface{}{
|
||||
"list": list,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
// Detail GET /platform/cursor/equipment/detail/:id
|
||||
func (c *PlatformCursorEquipmentController) Detail() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
|
||||
var row models.PlatformCursorEquipment
|
||||
err = models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&row)
|
||||
if err != nil {
|
||||
c.jsonErr(404, 404, "设备不存在")
|
||||
return
|
||||
}
|
||||
|
||||
c.ok(c.rowToMap(&row))
|
||||
}
|
||||
|
||||
type platformCursorEquipmentPayload struct {
|
||||
ID *uint64 `json:"id"`
|
||||
DeviceInfo *string `json:"deviceInfo"`
|
||||
MachineCode *string `json:"machineCode"`
|
||||
Status *int8 `json:"status"`
|
||||
System *string `json:"system"`
|
||||
Version *string `json:"version"`
|
||||
BindAccount *string `json:"bindAccount"`
|
||||
OwnerUserID *uint64 `json:"ownerUserId"`
|
||||
OwnerUserName *string `json:"ownerUserName"`
|
||||
ActivationTime *string `json:"activationTime"`
|
||||
ExpireTime *string `json:"expireTime"`
|
||||
Remark *string `json:"remark"`
|
||||
}
|
||||
|
||||
func (c *PlatformCursorEquipmentController) readPayload() (*platformCursorEquipmentPayload, error) {
|
||||
body, _ := io.ReadAll(c.Ctx.Request.Body)
|
||||
var p platformCursorEquipmentPayload
|
||||
if err := json.Unmarshal(body, &p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
func (c *PlatformCursorEquipmentController) payloadToUpdateMap(p *platformCursorEquipmentPayload, includeMachineCode bool) (map[string]interface{}, error) {
|
||||
up := map[string]interface{}{}
|
||||
|
||||
if includeMachineCode {
|
||||
if p.MachineCode == nil || strings.TrimSpace(*p.MachineCode) == "" {
|
||||
return nil, fmt.Errorf("机器码不能为空")
|
||||
}
|
||||
up["machine_code"] = strings.TrimSpace(*p.MachineCode)
|
||||
} else if p.MachineCode != nil {
|
||||
if strings.TrimSpace(*p.MachineCode) == "" {
|
||||
return nil, fmt.Errorf("机器码不能为空")
|
||||
}
|
||||
up["machine_code"] = strings.TrimSpace(*p.MachineCode)
|
||||
}
|
||||
|
||||
if p.DeviceInfo != nil {
|
||||
up["device_info"] = cursorEquipmentTrimPtr(p.DeviceInfo)
|
||||
}
|
||||
if p.Status != nil {
|
||||
if !cursorEquipmentStatusValid(*p.Status) {
|
||||
return nil, fmt.Errorf("状态不合法,支持:0 未激活、1 激活中、2 已过期、3 已禁用")
|
||||
}
|
||||
up["status"] = *p.Status
|
||||
}
|
||||
if p.System != nil {
|
||||
up["system"] = cursorEquipmentTrimPtr(p.System)
|
||||
}
|
||||
if p.Version != nil {
|
||||
up["version"] = cursorEquipmentTrimPtr(p.Version)
|
||||
}
|
||||
if p.BindAccount != nil {
|
||||
up["bind_account"] = cursorEquipmentTrimPtr(p.BindAccount)
|
||||
}
|
||||
if p.OwnerUserID != nil {
|
||||
if *p.OwnerUserID == 0 {
|
||||
up["owner_user_id"] = nil
|
||||
} else {
|
||||
up["owner_user_id"] = *p.OwnerUserID
|
||||
}
|
||||
}
|
||||
if p.OwnerUserName != nil {
|
||||
up["owner_user_name"] = cursorEquipmentTrimPtr(p.OwnerUserName)
|
||||
}
|
||||
if p.ActivationTime != nil {
|
||||
up["activation_time"] = cursorEquipmentTimePtr(p.ActivationTime)
|
||||
}
|
||||
if p.ExpireTime != nil {
|
||||
up["expire_time"] = cursorEquipmentTimePtr(p.ExpireTime)
|
||||
}
|
||||
if p.Remark != nil {
|
||||
up["remark"] = cursorEquipmentTrimPtr(p.Remark)
|
||||
}
|
||||
|
||||
return up, nil
|
||||
}
|
||||
|
||||
// Add POST /platform/cursor/equipment/add
|
||||
func (c *PlatformCursorEquipmentController) Add() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
p, err := c.readPayload()
|
||||
if err != nil {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
up, err := c.payloadToUpdateMap(p, true)
|
||||
if err != nil {
|
||||
c.jsonErr(400, 400, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
status := int8(0)
|
||||
if value, ok := up["status"]; ok {
|
||||
status = value.(int8)
|
||||
}
|
||||
|
||||
row := models.PlatformCursorEquipment{
|
||||
MachineCode: up["machine_code"].(string),
|
||||
Status: status,
|
||||
DeviceInfo: cursorEquipmentTrimPtr(p.DeviceInfo),
|
||||
System: cursorEquipmentTrimPtr(p.System),
|
||||
Version: cursorEquipmentTrimPtr(p.Version),
|
||||
BindAccount: cursorEquipmentTrimPtr(p.BindAccount),
|
||||
OwnerUserID: p.OwnerUserID,
|
||||
OwnerUserName: cursorEquipmentTrimPtr(p.OwnerUserName),
|
||||
ActivationTime: cursorEquipmentTimePtr(p.ActivationTime),
|
||||
ExpireTime: cursorEquipmentTimePtr(p.ExpireTime),
|
||||
Remark: cursorEquipmentTrimPtr(p.Remark),
|
||||
CreateTime: time.Now(),
|
||||
}
|
||||
|
||||
if row.OwnerUserID != nil && *row.OwnerUserID == 0 {
|
||||
row.OwnerUserID = nil
|
||||
}
|
||||
|
||||
id, err := models.Orm.Insert(&row)
|
||||
if err != nil {
|
||||
if strings.Contains(strings.ToLower(err.Error()), "duplicate") {
|
||||
c.jsonErr(400, 400, "机器码已存在")
|
||||
return
|
||||
}
|
||||
c.jsonErr(500, 500, "新增设备失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.ok(map[string]interface{}{"id": id})
|
||||
}
|
||||
|
||||
// Update POST /platform/cursor/equipment/update
|
||||
func (c *PlatformCursorEquipmentController) Update() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
p, err := c.readPayload()
|
||||
if err != nil {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
if p.ID == nil || *p.ID == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
|
||||
up, err := c.payloadToUpdateMap(p, false)
|
||||
if err != nil {
|
||||
c.jsonErr(400, 400, err.Error())
|
||||
return
|
||||
}
|
||||
if len(up) == 0 {
|
||||
c.jsonErr(400, 400, "无更新字段")
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
up["update_time"] = now
|
||||
|
||||
n, err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
|
||||
Filter("id", *p.ID).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(up)
|
||||
if err != nil {
|
||||
if strings.Contains(strings.ToLower(err.Error()), "duplicate") {
|
||||
c.jsonErr(400, 400, "机器码已存在")
|
||||
return
|
||||
}
|
||||
c.jsonErr(500, 500, "更新设备失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
c.jsonErr(404, 404, "设备不存在")
|
||||
return
|
||||
}
|
||||
|
||||
c.ok(nil)
|
||||
}
|
||||
|
||||
// Delete POST /platform/cursor/equipment/delete/:id
|
||||
func (c *PlatformCursorEquipmentController) Delete() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
n, err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(map[string]interface{}{"delete_time": now})
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "删除设备失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
c.jsonErr(404, 404, "设备不存在")
|
||||
return
|
||||
}
|
||||
|
||||
c.ok(nil)
|
||||
}
|
||||
|
||||
type platformCursorEquipmentActivatePayload struct {
|
||||
ID uint64 `json:"id"`
|
||||
}
|
||||
|
||||
// Activate POST /platform/cursor/equipment/activate
|
||||
func (c *PlatformCursorEquipmentController) Activate() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
body, _ := io.ReadAll(c.Ctx.Request.Body)
|
||||
var p platformCursorEquipmentActivatePayload
|
||||
if err := json.Unmarshal(body, &p); err != nil || p.ID == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
n, err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
|
||||
Filter("id", p.ID).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(map[string]interface{}{
|
||||
"status": int8(1),
|
||||
"activation_time": now,
|
||||
"update_time": now,
|
||||
})
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "激活设备失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
c.jsonErr(404, 404, "设备不存在")
|
||||
return
|
||||
}
|
||||
|
||||
c.ok(nil)
|
||||
}
|
||||
|
||||
// ActivationRecords GET /platform/cursor/equipment/activationRecords
|
||||
func (c *PlatformCursorEquipmentController) ActivationRecords() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
page, _ := c.GetInt("page", 1)
|
||||
pageSize, _ := c.GetInt("pageSize", 20)
|
||||
c.ok(map[string]interface{}{
|
||||
"list": []interface{}{},
|
||||
"total": 0,
|
||||
"page": page,
|
||||
"pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
// ExtractRecords GET /platform/cursor/equipment/extractRecords
|
||||
func (c *PlatformCursorEquipmentController) ExtractRecords() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
page, _ := c.GetInt("page", 1)
|
||||
pageSize, _ := c.GetInt("pageSize", 20)
|
||||
c.ok(map[string]interface{}{
|
||||
"list": []interface{}{},
|
||||
"total": 0,
|
||||
"page": page,
|
||||
"pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
@ -56,6 +56,7 @@ func Init(_ string) {
|
||||
new(ComplaintCategory),
|
||||
new(PlatformComplaint),
|
||||
new(SystemSoftwareUpgrade),
|
||||
new(PlatformCursorEquipment),
|
||||
new(PlatformAccountPoolKiro),
|
||||
new(PlatformAccountPoolWindsurf),
|
||||
new(PlatformAccountPoolCursor),
|
||||
|
||||
26
models/platform_cursor_equipment.go
Normal file
26
models/platform_cursor_equipment.go
Normal file
@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// PlatformCursorEquipment Cursor 设备管理 yz_platform_cursor_equipment
|
||||
type PlatformCursorEquipment struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
DeviceInfo *string `orm:"column(device_info);size(1000);null" json:"deviceInfo"`
|
||||
MachineCode string `orm:"column(machine_code);size(128);unique" json:"machineCode"`
|
||||
Status int8 `orm:"column(status);default(0)" json:"status"`
|
||||
System *string `orm:"column(system);size(64);null" json:"system"`
|
||||
Version *string `orm:"column(version);size(64);null" json:"version"`
|
||||
BindAccount *string `orm:"column(bind_account);size(128);null" json:"bindAccount"`
|
||||
OwnerUserID *uint64 `orm:"column(owner_user_id);null" json:"ownerUserId"`
|
||||
OwnerUserName *string `orm:"column(owner_user_name);size(128);null" json:"ownerUserName"`
|
||||
ActivationTime *time.Time `orm:"column(activation_time);type(datetime);null" json:"activationTime"`
|
||||
ExpireTime *time.Time `orm:"column(expire_time);type(datetime);null" json:"expireTime"`
|
||||
Remark *string `orm:"column(remark);size(1000);null" json:"remark"`
|
||||
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"createTime"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);auto_now;type(datetime);null" json:"updateTime"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"deleteTime"`
|
||||
}
|
||||
|
||||
func (m *PlatformCursorEquipment) TableName() string {
|
||||
return "yz_platform_cursor_equipment"
|
||||
}
|
||||
@ -11,6 +11,9 @@ func Register() {
|
||||
// 客户端检查更新(无需登录)
|
||||
beego.Router("/api/softwareupgrade/check", &controllers.ApiSoftwareUpgradeController{}, "get:Check")
|
||||
|
||||
// 登录器上报 Cursor 设备信息(无需登录)
|
||||
beego.Router("/api/cursor/equipment/report", &controllers.ApiCursorEquipmentController{}, "post:Report")
|
||||
|
||||
// 对外提卡接口(无需登录)
|
||||
// GET /api/getcard?type=xianyu&module=cursor&data_type=tk
|
||||
beego.Router("/api/getcard", &controllers.ApiGetCardController{}, "get:GetCard")
|
||||
|
||||
@ -162,6 +162,16 @@ func Register() {
|
||||
beego.Router("/platform/home/accountPoolDailyExtract", &controllers.PlatformHomeController{}, "get:AccountPoolDailyExtract")
|
||||
beego.Router("/platform/home/accountPoolInventoryTotals", &controllers.PlatformHomeController{}, "get:AccountPoolInventoryTotals")
|
||||
|
||||
// Cursor 设备管理(yz_platform_cursor_equipment)
|
||||
beego.Router("/platform/cursor/equipment/list", &controllers.PlatformCursorEquipmentController{}, "get:List")
|
||||
beego.Router("/platform/cursor/equipment/detail/:id", &controllers.PlatformCursorEquipmentController{}, "get:Detail")
|
||||
beego.Router("/platform/cursor/equipment/add", &controllers.PlatformCursorEquipmentController{}, "post:Add")
|
||||
beego.Router("/platform/cursor/equipment/update", &controllers.PlatformCursorEquipmentController{}, "post:Update")
|
||||
beego.Router("/platform/cursor/equipment/delete/:id", &controllers.PlatformCursorEquipmentController{}, "post:Delete")
|
||||
beego.Router("/platform/cursor/equipment/activate", &controllers.PlatformCursorEquipmentController{}, "post:Activate")
|
||||
beego.Router("/platform/cursor/equipment/activationRecords", &controllers.PlatformCursorEquipmentController{}, "get:ActivationRecords")
|
||||
beego.Router("/platform/cursor/equipment/extractRecords", &controllers.PlatformCursorEquipmentController{}, "get:ExtractRecords")
|
||||
|
||||
// 账号池管理(cursor/windsurf/krio)
|
||||
beego.Router("/platform/accountPool/cursor/list", &controllers.PlatformAccountPoolCursorController{}, "get:List")
|
||||
beego.Router("/platform/accountPool/cursor/add", &controllers.PlatformAccountPoolCursorController{}, "post:Add")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user