| | |
| | | LocomotiveNumber: arr[0], |
| | | TrainNumber: arr[1], |
| | | DriverNumber: arr[2], |
| | | StationNumber: arr[3], |
| | | Station: arr[3], |
| | | OccurrenceAt: t, |
| | | IsFollowed: 0, |
| | | } |
| | |
| | | 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, "添加成功") |
| | | } |
| | |
| | | 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(¶ms); 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 |
| | |
| | | SetLocomotiveNumber(params.LocomotiveNumber). |
| | | SetTrainNumber(params.TrainNumber). |
| | | SetDriverNumber(params.DriverNumber). |
| | | SetStationNumber(params.StationNumber). |
| | | SetStation(params.StationNumber). |
| | | Find() |
| | | |
| | | if err != nil { |