From 8adde93b8f2af29fb8a6405efaa49a41a1c22f8d Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 15 五月 2024 20:15:31 +0800
Subject: [PATCH] 上传音频时保存车站号,车次,车站到火车信息表,提供火车信息查询接口

---
 controllers/audio.go |   62 ++++++++++++++++++++++++++++++-
 1 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/controllers/audio.go b/controllers/audio.go
index 94b0117..1326952 100644
--- a/controllers/audio.go
+++ b/controllers/audio.go
@@ -73,7 +73,7 @@
 		LocomotiveNumber: arr[0],
 		TrainNumber:      arr[1],
 		DriverNumber:     arr[2],
-		StationNumber:    arr[3],
+		Station:          arr[3],
 		OccurrenceAt:     t,
 		IsFollowed:       0,
 	}
@@ -82,6 +82,31 @@
 		util.ResponseFormat(c, code.SaveFail, "涓婁紶澶辫触")
 		return
 	}
+	go func() {
+
+		var trainInfoNames = []string{arr[0], arr[1], arr[3]}
+
+		var (
+			info   *models.TrainInfo
+			err    error
+			parent models.TrainInfo
+		)
+		for i := 0; i < 3; i++ {
+			name := trainInfoNames[i]
+			class := constvar.Class(i + 1)
+			info, err = models.NewTrainInfoSearch().SetName(name).SetClass(class).First()
+			if err == gorm.ErrRecordNotFound {
+				info = &models.TrainInfo{
+					Name:     name,
+					Class:    class,
+					ParentID: parent.ID,
+				}
+				_ = models.NewTrainInfoSearch().Create(info)
+			}
+			parent = *info
+		}
+
+	}()
 
 	util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛")
 }
@@ -92,6 +117,39 @@
 		return errors.New("鏂囦欢鏍煎紡閿欒")
 	}
 	return nil
+}
+
+// TrainInfoList
+// @Tags      闊抽
+// @Summary   鑾峰彇鐏溅淇℃伅
+// @Produce   application/json
+// @Param     object  query    request.GetTrainInfoList true  "鍙傛暟"
+// @Success   200   {object}  util.ResponseList{data=[]models.TrainInfo}  "鎴愬姛"
+// @Router    /api-sa/v1/audio/trainInfoList [get]
+func (slf AudioCtl) TrainInfoList(c *gin.Context) {
+	var params request.GetTrainInfoList
+	if err := c.ShouldBindQuery(&params); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, err.Error())
+		return
+	}
+
+	if !params.PageInfo.Check() {
+		util.ResponseFormat(c, code.RequestParamError, "鍒嗛〉鍙傛暟閿欒")
+		return
+	}
+
+	list, total, err := models.NewTrainInfoSearch().
+		SetPage(params.Page, params.PageSize).
+		SetClass(params.Class).
+		SetParentId(params.ParentID).
+		Find()
+
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
+		return
+	}
+
+	util.ResponseFormatList(c, code.Success, list, total)
 }
 
 // List
@@ -119,7 +177,7 @@
 		SetLocomotiveNumber(params.LocomotiveNumber).
 		SetTrainNumber(params.TrainNumber).
 		SetDriverNumber(params.DriverNumber).
-		SetStationNumber(params.StationNumber).
+		SetStation(params.StationNumber).
 		Find()
 
 	if err != nil {

--
Gitblit v1.8.0