zhangqian
2024-05-13 7f91ff9dfa6d6ff8ec35dfea6d5195a20f631127
关注和取消关注接口
1个文件已添加
11个文件已修改
284 ■■■■■ 已修改文件
constvar/const.go 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/audio.go 35 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/audio.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/audio_text.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/audio.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
response/audio.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/audio.go 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/process.go 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constvar/const.go
@@ -17,3 +17,11 @@
    BoolTypeTrue  BoolType = 1 // true
    BoolTypeFalse BoolType = 2 // false
)
func (slf BoolType) IsValid() bool {
    return slf == BoolTypeTrue || slf == BoolTypeFalse
}
func (slf BoolType) Bool() bool {
    return slf == BoolTypeTrue
}
controllers/audio.go
@@ -11,6 +11,7 @@
    "speechAnalysis/models"
    "speechAnalysis/pkg/logx"
    "speechAnalysis/request"
    "speechAnalysis/response"
    "speechAnalysis/service"
    "speechAnalysis/utils/upload"
    "strings"
@@ -97,7 +98,7 @@
// @Tags      音频
// @Summary   音频分析检索
// @Produce   application/json
// @Param     object  query    request.GetAudioList true  "查询参数"
// @Param     object  query    request.GetAudioList true  "参数"
// @Success   200   {object}  util.ResponseList{data=[]models.Audio}  "成功"
// @Router    /api-sa/v1/audio/list [get]
func (slf AudioCtl) List(c *gin.Context) {
@@ -133,7 +134,7 @@
// @Tags      音频
// @Summary   处理音频
// @Produce   application/json
// @Param     object  body request.ProcessAudio true  "音频信息"
// @Param     object  body request.ProcessAudio true  "参数"
// @Success   200 {object} util.Response "成功"
// @Router    /api-sa/v1/audio/process [post]
func (slf AudioCtl) Process(c *gin.Context) {
@@ -156,7 +157,7 @@
// @Tags      音频
// @Summary   批量处理音频
// @Produce   application/json
// @Param     object  body request.BatchProcessAudio true  "音频信息"
// @Param     object  body request.BatchProcessAudio true  "参数"
// @Success   200 {object} util.Response "成功"
// @Router    /api-sa/v1/audio/batchProcess [post]
func (slf AudioCtl) BatchProcess(c *gin.Context) {
@@ -192,7 +193,7 @@
// @Tags      音频
// @Summary   删除音频
// @Produce   application/json
// @Param     object  body request.ProcessAudio true  "音频信息"
// @Param     object  body request.ProcessAudio true  "参数"
// @Success   200 {object} util.Response "成功"
// @Router    /api-sa/v1/audio/delete [post]
func (slf AudioCtl) Delete(c *gin.Context) {
@@ -215,7 +216,7 @@
// @Tags      音频
// @Summary   批量删除音频
// @Produce   application/json
// @Param     object  body request.BatchProcessAudio true  "音频信息"
// @Param     object  body request.BatchProcessAudio true  "参数"
// @Success   200 {object} util.Response "成功"
// @Router    /api-sa/v1/audio/batchDelete [post]
func (slf AudioCtl) BatchDelete(c *gin.Context) {
@@ -233,3 +234,27 @@
    util.ResponseFormat(c, code.DeleteSuccess, "成功")
}
// Follow
// @Tags      音频
// @Summary   关注/取消关注
// @Produce   application/json
// @Param     object  body request.FollowReq true  "参数"
// @Success   200 {object} util.Response{data=response.FollowResp} "成功"
// @Router    /api-sa/v1/audio/follow [post]
func (slf AudioCtl) Follow(c *gin.Context) {
    var params request.ProcessAudio
    if err := c.ShouldBind(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, err.Error())
        return
    }
    followStatus, err := service.Follow(params.ID)
    if err != nil {
        util.ResponseFormat(c, code.InternalError, err.Error())
        return
    }
    resp := response.FollowResp{FollowStatus: followStatus}
    util.ResponseFormat(c, code.UpdateSuccess, resp)
}
docs/docs.go
@@ -27,7 +27,7 @@
                "summary": "批量删除音频",
                "parameters": [
                    {
                        "description": "音频信息",
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
@@ -57,7 +57,7 @@
                "summary": "批量处理音频",
                "parameters": [
                    {
                        "description": "音频信息",
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
@@ -87,7 +87,7 @@
                "summary": "删除音频",
                "parameters": [
                    {
                        "description": "音频信息",
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
@@ -101,6 +101,48 @@
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-sa/v1/audio/follow": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "音频"
                ],
                "summary": "关注/取消关注",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.FollowReq"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.FollowResp"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
@@ -195,7 +237,7 @@
                "summary": "处理音频",
                "parameters": [
                    {
                        "description": "音频信息",
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
@@ -338,6 +380,10 @@
                "occurrenceTime": {
                    "type": "string"
                },
                "score": {
                    "description": "置信度",
                    "type": "number"
                },
                "size": {
                    "description": "音频大小",
                    "type": "integer"
@@ -369,6 +415,17 @@
                }
            }
        },
        "request.FollowReq": {
            "type": "object",
            "required": [
                "id"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                }
            }
        },
        "request.ProcessAudio": {
            "type": "object",
            "required": [
@@ -380,6 +437,14 @@
                }
            }
        },
        "response.FollowResp": {
            "type": "object",
            "properties": {
                "followStatus": {
                    "$ref": "#/definitions/constvar.BoolType"
                }
            }
        },
        "util.Response": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -15,7 +15,7 @@
                "summary": "批量删除音频",
                "parameters": [
                    {
                        "description": "音频信息",
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
@@ -45,7 +45,7 @@
                "summary": "批量处理音频",
                "parameters": [
                    {
                        "description": "音频信息",
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
@@ -75,7 +75,7 @@
                "summary": "删除音频",
                "parameters": [
                    {
                        "description": "音频信息",
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
@@ -89,6 +89,48 @@
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-sa/v1/audio/follow": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "音频"
                ],
                "summary": "关注/取消关注",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.FollowReq"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.FollowResp"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
@@ -183,7 +225,7 @@
                "summary": "处理音频",
                "parameters": [
                    {
                        "description": "音频信息",
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
@@ -326,6 +368,10 @@
                "occurrenceTime": {
                    "type": "string"
                },
                "score": {
                    "description": "置信度",
                    "type": "number"
                },
                "size": {
                    "description": "音频大小",
                    "type": "integer"
@@ -357,6 +403,17 @@
                }
            }
        },
        "request.FollowReq": {
            "type": "object",
            "required": [
                "id"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                }
            }
        },
        "request.ProcessAudio": {
            "type": "object",
            "required": [
@@ -368,6 +425,14 @@
                }
            }
        },
        "response.FollowResp": {
            "type": "object",
            "properties": {
                "followStatus": {
                    "$ref": "#/definitions/constvar.BoolType"
                }
            }
        },
        "util.Response": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -65,6 +65,9 @@
        type: string
      occurrenceTime:
        type: string
      score:
        description: 置信度
        type: number
      size:
        description: 音频大小
        type: integer
@@ -86,12 +89,24 @@
    required:
    - ids
    type: object
  request.FollowReq:
    properties:
      id:
        type: integer
    required:
    - id
    type: object
  request.ProcessAudio:
    properties:
      id:
        type: integer
    required:
    - id
    type: object
  response.FollowResp:
    properties:
      followStatus:
        $ref: '#/definitions/constvar.BoolType'
    type: object
  util.Response:
    properties:
@@ -121,7 +136,7 @@
  /api-sa/v1/audio/batchDelete:
    post:
      parameters:
      - description: 音频信息
      - description: 参数
        in: body
        name: object
        required: true
@@ -140,7 +155,7 @@
  /api-sa/v1/audio/batchProcess:
    post:
      parameters:
      - description: 音频信息
      - description: 参数
        in: body
        name: object
        required: true
@@ -159,7 +174,7 @@
  /api-sa/v1/audio/delete:
    post:
      parameters:
      - description: 音频信息
      - description: 参数
        in: body
        name: object
        required: true
@@ -173,6 +188,30 @@
          schema:
            $ref: '#/definitions/util.Response'
      summary: 删除音频
      tags:
      - 音频
  /api-sa/v1/audio/follow:
    post:
      parameters:
      - description: 参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.FollowReq'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/util.Response'
            - properties:
                data:
                  $ref: '#/definitions/response.FollowResp'
              type: object
      summary: 关注/取消关注
      tags:
      - 音频
  /api-sa/v1/audio/list:
@@ -226,7 +265,7 @@
  /api-sa/v1/audio/process:
    post:
      parameters:
      - description: 音频信息
      - description: 参数
        in: body
        name: object
        required: true
models/audio.go
@@ -23,6 +23,7 @@
        OccurrenceAt     time.Time            `json:"-"`
        OccurrenceTime   string               `json:"occurrenceTime" gorm:"-"`
        IsFollowed       constvar.BoolType    `gorm:"type:tinyint;not null;default:2;comment:是否关注"` //是否关注 1关注 2未关注
        Score            float64              `json:"score"`                                        // 置信度
    }
    AudioSearch struct {
models/audio_text.go
@@ -10,9 +10,8 @@
    // AudioText 音频文本
    AudioText struct {
        gorm.Model
        AudioID   uint    `gorm:"unique;type:int;not null;default:0;comment:音频id" json:"audioID"` // 音频id
        AudioText string  `json:"audioText"`                                                      // 音频文本
        Score     float64 `json:"score"`                                                          // 置信度
        AudioID   uint   `gorm:"unique;type:int;not null;default:0;comment:音频id" json:"audioID"` // 音频id
        AudioText string `json:"audioText"`                                                      // 音频文本
    }
    AudioTextSearch struct {
request/audio.go
@@ -16,3 +16,7 @@
type BatchProcessAudio struct {
    IDs []uint `json:"ids" binding:"required"`
}
type FollowReq struct {
    ID uint `json:"id" binding:"required"`
}
response/audio.go
New file
@@ -0,0 +1,7 @@
package response
import "speechAnalysis/constvar"
type FollowResp struct {
    FollowStatus constvar.BoolType `json:"followStatus"`
}
router/router.go
@@ -31,6 +31,7 @@
        organizeAPI.POST("batchProcess", AudioCtl.BatchProcess) // 音频批量处理
        organizeAPI.POST("delete", AudioCtl.Delete)             // 音频删除
        organizeAPI.POST("batchDelete", AudioCtl.BatchDelete)   // 音频批量删除
        organizeAPI.POST("follow", AudioCtl.Follow)             // 关注/取消关注
    }
    return r
service/audio.go
@@ -3,6 +3,7 @@
import (
    "errors"
    "gorm.io/gorm"
    "speechAnalysis/constvar"
    "speechAnalysis/models"
    "speechAnalysis/pkg/logx"
)
@@ -37,3 +38,26 @@
    }
    return nil
}
func Follow(audioId uint) (followStatus constvar.BoolType, err error) {
    if audioId == 0 {
        return
    }
    audio, err := models.NewAudioSearch().SetID(audioId).First()
    if err != nil {
        return followStatus, errors.New("DB错误")
    }
    if audio.IsFollowed.Bool() {
        followStatus = constvar.BoolTypeFalse
    } else {
        followStatus = constvar.BoolTypeTrue
    }
    err = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{
        "is_followed": followStatus,
    })
    if err != nil {
        logx.Errorf("follow audio err: %v", err)
        return followStatus, errors.New("DB错误")
    }
    return followStatus, nil
}
service/process.go
@@ -111,14 +111,16 @@
        }
        logx.Infof("AnalysisAudio result: %v", resp)
        err = models.WithTransaction(func(db *gorm.DB) error {
            err = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{"audio_status": constvar.AudioStatusFinish})
            err = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{
                "audio_status": constvar.AudioStatusFinish,
                "score":        resp.Score,
            })
            if err != nil {
                return err
            }
            err = models.NewAudioTextSearch().Save(&models.AudioText{
                AudioID:   audio.ID,
                AudioText: resp.Result,
                Score:     resp.Score,
            })
            return err
        })