Browse Source

新增entity和srvice

developer
appolli 5 months ago
parent
commit
13490f2914
  1. 3
      main_program/common/Constant.go
  2. 11
      main_program/entity/KetWord.go
  3. 17
      main_program/entity/SrtFile.go
  4. 16
      main_program/entity/WorldResultSet.go
  5. 20
      main_program/keyword_analyse/KeywordAnalyseService.go
  6. 9
      main_program/main.go
  7. 5
      main_program/service/KeyWordService.go
  8. 23
      main_program/service/SrtFileService.go

3
main_program/common/Constant.go

@ -2,6 +2,8 @@ package common
import ( import (
config "main_program/config" config "main_program/config"
"gorm.io/gorm"
) )
var ConfigFile string var ConfigFile string
@ -10,3 +12,4 @@ var Command string
var Table string var Table string
var Dbpath string var Dbpath string
var XlsxPath string var XlsxPath string
var MysqlDB *gorm.DB

11
main_program/entity/KetWord.go

@ -0,0 +1,11 @@
package entity
type Keyword struct {
Id uint `gorm:"column:id;primaryKey;autoIncrement"`
Region string `gorm:"column:region;type:varchar(255);not null"`
Word string `gorm:"column:word;type:varchar(255);not null"`
}
func (Keyword) TableName() string {
return "Keyword"
}

17
main_program/entity/SrtFile.go

@ -0,0 +1,17 @@
package entity
type Srtfile struct {
Id uint `gorm:"column:id;primaryKey;autoIncrement"`
VideoId string `gorm:"column:videoId;type:varchar(255);not null"`
ChannelId string `gorm:"column:channelId;type:varchar(255);not null"`
Ordinal int `gorm:"column:ordinal;type:int(11);not null"`
SrtStartTime string `gorm:"column:srtStartTime;type:varchar(255);not null"`
SrtEndTime string `gorm:"column:srtEndTime;type:varchar(255);not null"`
SrtText string `gorm:"column:srtText;type:varchar(255);not null"`
IsScan int `gorm:"column:isScan;type:int(11);default:null"`
}
// TableName sets the insert table name for this struct type
func (Srtfile) TableName() string {
return "Srtfile"
}

16
main_program/entity/WorldResultSet.go

@ -0,0 +1,16 @@
package entity
type WorldResultSet struct {
Id uint `gorm:"column:id;primaryKey;autoIncrement"`
KeyWordId int `gorm:"column:keyWordId"`
WordText string `gorm:"column:wordText"`
SrtId int `gorm:"column:srtId"`
SrtOrdinal int `gorm:"column:srtOrdinal"`
SrtText string `gorm:"column:srtText"`
VideoId string `gorm:"column:videoId"`
}
// TableName 设置 WorldResultSet 表名
func (WorldResultSet) TableName() string {
return "World_Result_Set"
}

20
main_program/keyword_analyse/KeywordAnalyseService.go

@ -0,0 +1,20 @@
package keywordanalyse
import (
"main_program/config"
service "main_program/service"
)
type keywordAnalyse struct{}
var KeywordAnalyseService keywordAnalyse
func (m *keywordAnalyse) Start() {
config.Logger.Info("开始逐句解析...")
videoId, err := service.SrtFileService.QueryOneNotScanVideoId()
if err != nil {
config.Logger.Info("没有需要解析的SrtFile...")
}
config.Logger.Infof("VideoId:%s", videoId)
}

9
main_program/main.go

@ -7,9 +7,12 @@ import (
common "main_program/common" common "main_program/common"
"main_program/config" "main_program/config"
keywordanalyse "main_program/keyword_analyse"
move_data "main_program/moveData" move_data "main_program/moveData"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"gorm.io/driver/mysql"
"gorm.io/gorm"
) )
func init() { func init() {
@ -31,6 +34,10 @@ func main() {
} }
config.InitConfig(common.MyEnv.Log.LogEnv, common.MyEnv.Log.LogPath) config.InitConfig(common.MyEnv.Log.LogEnv, common.MyEnv.Log.LogPath)
config.Logger.Info("初始化Logger成功...") config.Logger.Info("初始化Logger成功...")
// 初始化myslq
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", common.MyEnv.Mysql.User, common.MyEnv.Mysql.Password, common.MyEnv.Mysql.Host, common.MyEnv.Mysql.Database)
common.MysqlDB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
// 判断command // 判断command
command := common.MyEnv.Command command := common.MyEnv.Command
if common.Command != "" { if common.Command != "" {
@ -58,6 +65,8 @@ func main() {
config.Logger.Infof("开始调用move_data方法") config.Logger.Infof("开始调用move_data方法")
config.Logger.Infof("table:%s dbPath:%s xlsxPath:%s", table, dbPath, xlsxPath) config.Logger.Infof("table:%s dbPath:%s xlsxPath:%s", table, dbPath, xlsxPath)
move_data.MoveDataService.Start(table, dbPath, common.MyEnv.Mysql, xlsxPath) move_data.MoveDataService.Start(table, dbPath, common.MyEnv.Mysql, xlsxPath)
} else if command == "keyword_analyse" {
keywordanalyse.KeywordAnalyseService.Start()
} }
} }

5
main_program/service/KeyWordService.go

@ -0,0 +1,5 @@
package service
type keywordService struct{}
var KeywordService keywordService

23
main_program/service/SrtFileService.go

@ -0,0 +1,23 @@
package service
import (
"errors"
"main_program/common"
"main_program/entity"
"gorm.io/gorm"
)
type srtFileService struct{}
var SrtFileService srtFileService
func (srt *srtFileService) QueryOneNotScanVideoId() (videoId string, err error) {
var srtFile entity.Srtfile
result := common.MysqlDB.Where(&entity.Srtfile{IsScan: 0}).First(&srtFile)
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return "", errors.New("no srtFile")
} else {
return srtFile.VideoId, nil
}
}
Loading…
Cancel
Save