Commit 0ea19b5c authored by shajiaiming's avatar shajiaiming

优化

parent 57dfa249
...@@ -2,40 +2,28 @@ package models ...@@ -2,40 +2,28 @@ package models
import ( import (
"bwallet/pkg/setting" "bwallet/pkg/setting"
"fmt"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
) )
type LiveTitleRecord struct { type LiveTitleRecord struct {
Model Model
LiveId int `json:"live_id"` LiveId int `json:"live_id"`
CurrentTitle string `json:"current_title"` CurrentTitle string `json:"current_title"`
NewTitle string `json:"new_title"` NewTitle string `json:"new_title"`
Status uint8 `json:"status"` Status uint8 `json:"status"`
PlatformId int64 `gorm:"not null;default:0" json:"platform_id"` PlatformId int64 `json:"platform_id,omitempty"`
CreateTime int64 `json:"create_time,omitempty"`
LiveInfo *LiveInfo `gorm:"foreignkey:LiveId" json:"live"` CreatedTime string `json:"created_time,omitempty"`
ApplyId uint32 `json:"apply_id"`
LiveInfo *LiveInfo `gorm:"foreignkey:LiveId" json:"live,omitempty"`
} }
func (w LiveTitleRecord) TableName() string { func (w LiveTitleRecord) TableName() string {
return setting.DatabaseSetting.Name_Sources + ".wallet_live_title_record" return setting.DatabaseSetting.Name_Sources + ".wallet_live_title_record"
} }
func GetOneLiveTitleRecord(id int) (*LiveTitleRecord, error) {
var live LiveTitleRecord
err := db.Where("id = ?", id).First(&live).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, err
}
err = db.Model(&live).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, err
}
return &live, nil
}
func ExistLiveTitleRecordById(id int) (bool, error) { func ExistLiveTitleRecordById(id int) (bool, error) {
var live LiveTitleRecord var live LiveTitleRecord
err := db.Select("id").Where("id = ?", id).First(&live).Error err := db.Select("id").Where("id = ?", id).First(&live).Error
...@@ -62,8 +50,8 @@ func GetLiveTitleRecordTotal(maps interface{}) (int, error) { ...@@ -62,8 +50,8 @@ func GetLiveTitleRecordTotal(maps interface{}) (int, error) {
func GetLiveTitleRecord(pageNum, pageSize int, maps interface{}) ([]*LiveTitleRecord, error) { func GetLiveTitleRecord(pageNum, pageSize int, maps interface{}) ([]*LiveTitleRecord, error) {
var live []*LiveTitleRecord var live []*LiveTitleRecord
fmt.Println(maps)
err := db.Where(maps).Preload("LiveInfo").Order("create_time desc").Offset(pageNum).Limit(pageSize).Find(&live).Error err := db.Debug().Where(maps).Preload("LiveInfo").Order("create_time desc").Offset(pageNum).Limit(pageSize).Find(&live).Error
if err != nil && err != gorm.ErrRecordNotFound { if err != nil && err != gorm.ErrRecordNotFound {
return nil, err return nil, err
} }
...@@ -78,6 +66,7 @@ func AddLiveTitleRecord(data map[string]interface{}) (error) { ...@@ -78,6 +66,7 @@ func AddLiveTitleRecord(data map[string]interface{}) (error) {
NewTitle: data["new_title"].(string), NewTitle: data["new_title"].(string),
Status: data["sort"].(uint8), Status: data["sort"].(uint8),
PlatformId: data["platform_id"].(int64), PlatformId: data["platform_id"].(int64),
CreateTime: data["create_time"].(int64),
} }
if err := db.Create(&live).Error; err != nil { if err := db.Create(&live).Error; err != nil {
...@@ -93,4 +82,4 @@ func EditLiveTitleRecord(id int, data interface{}) error { ...@@ -93,4 +82,4 @@ func EditLiveTitleRecord(id int, data interface{}) error {
} }
return nil return nil
} }
\ No newline at end of file
...@@ -115,13 +115,12 @@ func (l *LiveInfo) getMaps() (map[string]interface{}) { ...@@ -115,13 +115,12 @@ func (l *LiveInfo) getMaps() (map[string]interface{}) {
maps["category_id"] = l.CategoryId maps["category_id"] = l.CategoryId
} }
if l.Status != 0 {
maps["status"] = l.Status
}
if l.PlatformId != 0 { if l.PlatformId != 0 {
maps["platform_id"] = l.PlatformId maps["platform_id"] = l.PlatformId
} }
maps["status"] = l.Status
return maps return maps
} }
...@@ -2,6 +2,8 @@ package live_title_record_service ...@@ -2,6 +2,8 @@ package live_title_record_service
import ( import (
"bwallet/models" "bwallet/models"
"fmt"
"time"
) )
type LiveTitleRecord struct { type LiveTitleRecord struct {
...@@ -18,13 +20,27 @@ type LiveTitleRecord struct { ...@@ -18,13 +20,27 @@ type LiveTitleRecord struct {
func (l *LiveTitleRecord) GetAll() ([]*models.LiveTitleRecord, error) { func (l *LiveTitleRecord) GetAll() ([]*models.LiveTitleRecord, error) {
var live []*models.LiveTitleRecord var live []*models.LiveTitleRecord
fmt.Println(l.getMaps())
live, err := models.GetLiveTitleRecord(l.PageNum, l.PageSize, l.getMaps()) live, err := models.GetLiveTitleRecord(l.PageNum, l.PageSize, l.getMaps())
if err != nil { if err != nil {
return nil, err return nil, err
} }
return live, nil var records []*models.LiveTitleRecord
for _, value := range live {
record := &models.LiveTitleRecord{}
record.ID = value.ID
record.CurrentTitle = value.CurrentTitle
record.NewTitle = value.NewTitle
record.Status = value.Status
record.LiveId = value.LiveId
record.CreatedTime = time.Unix(value.CreateTime, 0).Format("2006-01-02 15:04:05")
record.ApplyId = value.LiveInfo.ApplyId
records = append(records, record)
}
return records, nil
} }
func (l *LiveTitleRecord) Add() error { func (l *LiveTitleRecord) Add() error {
...@@ -69,14 +85,12 @@ func (l *LiveTitleRecord) getMaps() (map[string]interface{}) { ...@@ -69,14 +85,12 @@ func (l *LiveTitleRecord) getMaps() (map[string]interface{}) {
maps["id"] = l.Id maps["id"] = l.Id
} }
if l.Status != 0 {
maps["status"] = l.Status
}
if l.PlatformId != 0 { if l.PlatformId != 0 {
maps["platform_id"] = l.PlatformId maps["platform_id"] = l.PlatformId
} }
maps["status"] = l.Status
return maps return maps
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment