diff --git a/main_program/common/Constant.go b/main_program/common/Constant.go index e6f5aa0..a67bafd 100644 --- a/main_program/common/Constant.go +++ b/main_program/common/Constant.go @@ -2,6 +2,8 @@ package common import ( config "main_program/config" + + "gorm.io/gorm" ) var ConfigFile string @@ -10,3 +12,4 @@ var Command string var Table string var Dbpath string var XlsxPath string +var MysqlDB *gorm.DB diff --git a/main_program/entity/KetWord.go b/main_program/entity/KetWord.go new file mode 100644 index 0000000..5c6ac10 --- /dev/null +++ b/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" +} diff --git a/main_program/entity/SrtFile.go b/main_program/entity/SrtFile.go new file mode 100644 index 0000000..e02263e --- /dev/null +++ b/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" +} diff --git a/main_program/entity/WorldResultSet.go b/main_program/entity/WorldResultSet.go new file mode 100644 index 0000000..1f02908 --- /dev/null +++ b/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" +} diff --git a/main_program/keyword_analyse/KeywordAnalyseService.go b/main_program/keyword_analyse/KeywordAnalyseService.go new file mode 100644 index 0000000..89b964e --- /dev/null +++ b/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) + +} diff --git a/main_program/main.go b/main_program/main.go index 602334d..8f4bee4 100644 --- a/main_program/main.go +++ b/main_program/main.go @@ -7,9 +7,12 @@ import ( common "main_program/common" "main_program/config" + keywordanalyse "main_program/keyword_analyse" move_data "main_program/moveData" "gopkg.in/yaml.v2" + "gorm.io/driver/mysql" + "gorm.io/gorm" ) func init() { @@ -31,6 +34,10 @@ func main() { } config.InitConfig(common.MyEnv.Log.LogEnv, common.MyEnv.Log.LogPath) 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 := common.MyEnv.Command if common.Command != "" { @@ -58,6 +65,8 @@ func main() { config.Logger.Infof("开始调用move_data方法") config.Logger.Infof("table:%s dbPath:%s xlsxPath:%s", table, dbPath, xlsxPath) move_data.MoveDataService.Start(table, dbPath, common.MyEnv.Mysql, xlsxPath) + } else if command == "keyword_analyse" { + keywordanalyse.KeywordAnalyseService.Start() } } diff --git a/main_program/service/KeyWordService.go b/main_program/service/KeyWordService.go new file mode 100644 index 0000000..301f81e --- /dev/null +++ b/main_program/service/KeyWordService.go @@ -0,0 +1,5 @@ +package service + +type keywordService struct{} + +var KeywordService keywordService diff --git a/main_program/service/SrtFileService.go b/main_program/service/SrtFileService.go new file mode 100644 index 0000000..b23a8f8 --- /dev/null +++ b/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 + } +}