mirror of
https://github.com/ProudMuBai/GoFilm.git
synced 2026-03-04 02:17:29 +08:00
add BAM
This commit is contained in:
99
server/logic/CronLogic.go
Normal file
99
server/logic/CronLogic.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"server/model/system"
|
||||
"server/plugin/common/util"
|
||||
"server/plugin/spider"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CronLogic struct {
|
||||
}
|
||||
|
||||
var CL *CronLogic
|
||||
|
||||
// AddFilmCrontab 添加影片更新任务
|
||||
func (cl *CronLogic) AddFilmCrontab(cv system.FilmCronVo) error {
|
||||
// 如果 spec 表达式校验失败则直接返回错误信息并终止
|
||||
if err := spider.ValidSpec(cv.Spec); err != nil {
|
||||
return err
|
||||
}
|
||||
// 生成任务信息 生成一个唯一ID 作为Task唯一标识
|
||||
task := system.FilmCollectTask{Id: util.GenerateSalt(), Ids: cv.Ids, Time: cv.Time, Spec: cv.Spec, Model: cv.Model, State: cv.State, Remark: cv.Remark}
|
||||
// 添加一条定时任务
|
||||
switch task.Model {
|
||||
case 0:
|
||||
cid, err := spider.AddAutoUpdateCron(task.Id, task.Spec)
|
||||
// 如果任务添加失败则直接返回错误信息
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprint("影视自动更新任务添加失败: ", err.Error()))
|
||||
}
|
||||
// 将定时任务Id记录到Task中
|
||||
task.Cid = cid
|
||||
case 1:
|
||||
cid, err := spider.AddFilmUpdateCron(task.Id, task.Spec)
|
||||
// 如果任务添加失败则直接返回错误信息
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprint("影视更新定时任务添加失败: ", err.Error()))
|
||||
}
|
||||
// 将定时任务Id记录到Task中
|
||||
task.Cid = cid
|
||||
}
|
||||
// 如果没有异常则将当前定时任务信息记录到redis中
|
||||
system.SaveFilmTask(task)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetFilmCrontab 获取所有定时任务信息
|
||||
func (cl *CronLogic) GetFilmCrontab() []system.CronTaskVo {
|
||||
var l []system.CronTaskVo
|
||||
tl := system.GetAllFilmTask()
|
||||
for _, t := range tl {
|
||||
e := spider.GetEntryById(t.Cid)
|
||||
taskVo := system.CronTaskVo{FilmCollectTask: t, PreV: e.Prev.Format(time.DateTime), Next: e.Next.Format(time.DateTime)}
|
||||
l = append(l, taskVo)
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// GetFilmCrontabById 通过ID获取对应的定时任务信息
|
||||
func (cl *CronLogic) GetFilmCrontabById(id string) (system.FilmCollectTask, error) {
|
||||
t, err := system.GetFilmTaskById(id)
|
||||
//e := spider.GetEntryById(t.Cid)
|
||||
//taskVo := system.CronTaskVo{FilmCollectTask: t, PreV: e.Prev.Format(time.DateTime), Next: e.Next.Format(time.DateTime)}
|
||||
return t, err
|
||||
}
|
||||
|
||||
// ChangeFilmCrontab 改变定时任务的状态 开启 | 停止
|
||||
func (cl *CronLogic) ChangeFilmCrontab(id string, state bool) error {
|
||||
// 通过定时任务信息的唯一标识获取对应的定时任务信息
|
||||
ft, err := system.GetFilmTaskById(id)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("定时任务停止失败: %s", err.Error()))
|
||||
}
|
||||
// 修改当前定时任务的状态为 false, 则在定时执行方法时不会执行具体逻辑
|
||||
ft.State = state
|
||||
system.UpdateFilmTask(ft)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateFilmCron 更新定时任务的状态信息
|
||||
func (cl *CronLogic) UpdateFilmCron(t system.FilmCollectTask) {
|
||||
system.UpdateFilmTask(t)
|
||||
}
|
||||
|
||||
// DelFilmCrontab 删除定时任务
|
||||
func (cl *CronLogic) DelFilmCrontab(id string) error {
|
||||
// 通过定时任务信息的唯一Id标识获取对应的定时任务信息
|
||||
ft, err := system.GetFilmTaskById(id)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("定时任务删除失败: %s", err.Error()))
|
||||
}
|
||||
// 通过定时任务EntryID移出对应的定时任务
|
||||
spider.RemoveCron(ft.Cid)
|
||||
// 将定时任务相关信息删除
|
||||
system.DelFilmTask(id)
|
||||
return nil
|
||||
}
|
||||
29
server/logic/FileLogic.go
Normal file
29
server/logic/FileLogic.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"server/config"
|
||||
"server/model/system"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type FileLogic struct {
|
||||
}
|
||||
|
||||
var FileL FileLogic
|
||||
|
||||
func (fl *FileLogic) SingleFileUpload(fileName string, uid int) string {
|
||||
// 生成图片信息
|
||||
var p = system.Picture{Link: fmt.Sprint(config.FilmPictureAccess, filepath.Base(fileName)), Uid: uid, PicType: 0}
|
||||
p.PicUid = strings.TrimSuffix(filepath.Base(fileName), filepath.Ext(fileName))
|
||||
// 记录图片信息到系统表中
|
||||
system.SaveGallery(p)
|
||||
return p.Link
|
||||
}
|
||||
|
||||
// GetPhotoPage 获取系统内的图片分页信息
|
||||
func (fl *FileLogic) GetPhotoPage(page *system.Page) []system.Picture {
|
||||
return system.GetPicturePage(page)
|
||||
|
||||
}
|
||||
161
server/logic/FilmLogic.go
Normal file
161
server/logic/FilmLogic.go
Normal file
@@ -0,0 +1,161 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"server/model/system"
|
||||
"server/plugin/common/conver"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
处理影片管理相关业务
|
||||
*/
|
||||
|
||||
type FilmLogic struct {
|
||||
}
|
||||
|
||||
var FL *FilmLogic
|
||||
|
||||
//----------------------------------------------------影片管理业务逻辑----------------------------------------------------
|
||||
|
||||
func (fl *FilmLogic) GetFilmPage(s system.SearchVo) []system.SearchInfo {
|
||||
// 获取影片检索信息分页数据
|
||||
sl := system.GetSearchPage(s)
|
||||
//
|
||||
return sl
|
||||
}
|
||||
|
||||
// GetSearchOptions 获取影片检索的select的选项options
|
||||
func (fl *FilmLogic) GetSearchOptions() map[string]any {
|
||||
var options = make(map[string]any)
|
||||
// 获取分类 options
|
||||
tree := system.GetCategoryTree()
|
||||
tree.Name = "全部分类"
|
||||
options["class"] = conver.ConvertCategoryList(tree)
|
||||
options["remarks"] = []map[string]string{{"Name": `全部`, "Value": ``}, {"Name": `完结`, "Value": `完结`}, {"Name": `未完结`, "Value": `未完结`}}
|
||||
// 获取 剧情,地区,语言, 年份 组信息 (每个分类对应的检索信息并不相同)
|
||||
var tagGroup = make(map[int64]map[string]any)
|
||||
// 遍历一级分类获取对应的标签组信息
|
||||
for _, t := range tree.Children {
|
||||
option := system.GetSearchOptions(t.Id)
|
||||
if len(option) > 0 {
|
||||
tagGroup[t.Id] = system.GetSearchOptions(t.Id)
|
||||
// 如果年份信息不存在则独立一份年份信息
|
||||
if _, ok := options["year"]; !ok {
|
||||
options["year"] = tagGroup[t.Id]["Year"]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
options["tags"] = tagGroup
|
||||
return options
|
||||
}
|
||||
|
||||
// SaveFilmDetail 自定义上传保存影片信息
|
||||
func (fl *FilmLogic) SaveFilmDetail(fd system.FilmDetailVo) error {
|
||||
// 补全影片信息
|
||||
now := time.Now()
|
||||
fd.UpdateTime = now.Format(time.DateTime)
|
||||
fd.AddTime = fd.UpdateTime
|
||||
// 生成ID, 由于是自定义上传的影片, 避免和采集站点的影片冲突, 以当前时间时间戳作为ID
|
||||
fd.Id = now.Unix()
|
||||
// 生成影片详情信息
|
||||
detail, err := conver.CovertFilmDetailVo(fd)
|
||||
if err != nil || detail.PlayList == nil {
|
||||
return errors.New("影片参数格式异常或缺少关键信息")
|
||||
}
|
||||
|
||||
// 保存影片信息
|
||||
return system.SaveDetail(detail)
|
||||
}
|
||||
|
||||
//----------------------------------------------------影片分类业务逻辑----------------------------------------------------
|
||||
|
||||
// GetFilmClassTree 获取影片分类信息
|
||||
func (fl *FilmLogic) GetFilmClassTree() system.CategoryTree {
|
||||
// 获取原本的影片分类信息
|
||||
return system.GetCategoryTree()
|
||||
}
|
||||
|
||||
func (fl *FilmLogic) GetFilmClassById(id int64) *system.CategoryTree {
|
||||
tree := system.GetCategoryTree()
|
||||
for _, c := range tree.Children {
|
||||
// 如果是一级分类, 则相等时直接返回
|
||||
if c.Id == id {
|
||||
return c
|
||||
}
|
||||
// 如果当前分类含有子分类, 则继续遍历匹配
|
||||
if c.Children != nil {
|
||||
for _, subC := range c.Children {
|
||||
if subC.Id == id {
|
||||
return subC
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateClass 更新分类信息
|
||||
func (fl *FilmLogic) UpdateClass(class system.CategoryTree) error {
|
||||
// 遍历影片分类信息
|
||||
tree := system.GetCategoryTree()
|
||||
for _, c := range tree.Children {
|
||||
// 如果是一级分类, 则相等时直接修改对应的name和show属性
|
||||
if c.Id == class.Id {
|
||||
if class.Name != "" {
|
||||
c.Name = class.Name
|
||||
}
|
||||
c.Show = class.Show
|
||||
if err := system.SaveCategoryTree(&tree); err != nil {
|
||||
return fmt.Errorf("影片分类信息更新失败: %s", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// 如果当前分类含有子分类, 则继续遍历匹配
|
||||
if c.Children != nil {
|
||||
for _, subC := range c.Children {
|
||||
if subC.Id == class.Id {
|
||||
if class.Name != "" {
|
||||
subC.Name = class.Name
|
||||
}
|
||||
subC.Show = class.Show
|
||||
if err := system.SaveCategoryTree(&tree); err != nil {
|
||||
return fmt.Errorf("影片分类信息更新失败: %s", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors.New("需要更新的分类信息不存在")
|
||||
}
|
||||
|
||||
// DelClass 删除分类信息
|
||||
func (fl *FilmLogic) DelClass(id int64) error {
|
||||
tree := system.GetCategoryTree()
|
||||
for i, c := range tree.Children {
|
||||
// 如果是一级分类, 则相等时直接返回
|
||||
if c.Id == id {
|
||||
tree.Children = append(tree.Children[:i], tree.Children[i+1:]...)
|
||||
if err := system.SaveCategoryTree(&tree); err != nil {
|
||||
return fmt.Errorf("影片分类信息删除失败: %s", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// 如果当前分类含有子分类, 则继续遍历匹配
|
||||
if c.Children != nil {
|
||||
for j, subC := range c.Children {
|
||||
if subC.Id == id {
|
||||
c.Children = append(c.Children[:j], c.Children[j+1:]...)
|
||||
if err := system.SaveCategoryTree(&tree); err != nil {
|
||||
return fmt.Errorf("影片分类信息删除失败: %s", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors.New("需要删除的分类信息不存在")
|
||||
}
|
||||
@@ -5,9 +5,8 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"regexp"
|
||||
"server/config"
|
||||
"server/model"
|
||||
"server/model/system"
|
||||
"server/plugin/db"
|
||||
"server/plugin/spider"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -27,45 +26,53 @@ func (i *IndexLogic) IndexPage() map[string]interface{} {
|
||||
//Info := make(map[string]interface{})
|
||||
// 首页请求时长较高, 采用redis进行缓存, 在定时任务更新影片时清除对应缓存
|
||||
// 判断是否存在缓存数据, 存在则直接将数据返回
|
||||
Info := model.GetCacheData(config.IndexCacheKey)
|
||||
Info := system.GetCacheData(config.IndexCacheKey)
|
||||
if Info != nil {
|
||||
return Info
|
||||
}
|
||||
Info = make(map[string]interface{})
|
||||
// 1. 首页分类数据处理 导航分类数据处理, 只提供 电影 电视剧 综艺 动漫 四大顶级分类和其子分类
|
||||
tree := model.CategoryTree{Category: &model.Category{Id: 0, Name: "分类信息"}}
|
||||
sysTree := model.GetCategoryTree()
|
||||
tree := system.CategoryTree{Category: &system.Category{Id: 0, Name: "分类信息"}}
|
||||
sysTree := system.GetCategoryTree()
|
||||
// 由于采集源数据格式不一,因此采用名称匹配
|
||||
//for _, c := range sysTree.Children {
|
||||
// switch c.Category.Name {
|
||||
// case "电影", "电影片", "连续剧", "电视剧", "综艺", "综艺片", "动漫", "动漫片":
|
||||
// tree.Children = append(tree.Children, c)
|
||||
// }
|
||||
//}
|
||||
|
||||
for _, c := range sysTree.Children {
|
||||
switch c.Category.Name {
|
||||
case "电影", "电影片", "连续剧", "电视剧", "综艺", "综艺片", "动漫", "动漫片":
|
||||
// 只针对一级分类进行处理
|
||||
if c.Show {
|
||||
tree.Children = append(tree.Children, c)
|
||||
}
|
||||
}
|
||||
|
||||
Info["category"] = tree
|
||||
// 2. 提供用于首页展示的顶级分类影片信息, 每分类 14条数据
|
||||
var list []map[string]interface{}
|
||||
for _, c := range tree.Children {
|
||||
page := model.Page{PageSize: 14, Current: 1}
|
||||
movies := model.GetMovieListByPid(c.Id, &page)
|
||||
page := system.Page{PageSize: 14, Current: 1}
|
||||
movies := system.GetMovieListByPid(c.Id, &page)
|
||||
// 获取当前分类的本月热门影片
|
||||
HotMovies := model.GetHotMovieByPid(c.Id, &page)
|
||||
HotMovies := system.GetHotMovieByPid(c.Id, &page)
|
||||
item := map[string]interface{}{"nav": c, "movies": movies, "hot": HotMovies}
|
||||
list = append(list, item)
|
||||
}
|
||||
Info["content"] = list
|
||||
// 不存在首页数据缓存时将查询数据缓存到redis中
|
||||
model.DataCache(config.IndexCacheKey, Info)
|
||||
//system.DataCache(config.IndexCacheKey, Info)
|
||||
return Info
|
||||
}
|
||||
|
||||
// GetFilmDetail 影片详情信息页面处理
|
||||
func (i *IndexLogic) GetFilmDetail(id int) model.MovieDetail {
|
||||
func (i *IndexLogic) GetFilmDetail(id int) system.MovieDetail {
|
||||
// 通过Id 获取影片search信息
|
||||
search := model.SearchInfo{}
|
||||
search := system.SearchInfo{}
|
||||
db.Mdb.Where("mid", id).First(&search)
|
||||
// 获取redis中的完整影视信息 MovieDetail:Cid11:Id24676
|
||||
movieDetail := model.GetDetailByKey(fmt.Sprintf(config.MovieDetailKey, search.Cid, search.Mid))
|
||||
movieDetail := system.GetDetailByKey(fmt.Sprintf(config.MovieDetailKey, search.Cid, search.Mid))
|
||||
//查找其他站点是否存在影片对应的播放源
|
||||
multipleSource(&movieDetail)
|
||||
return movieDetail
|
||||
@@ -76,7 +83,7 @@ func (i *IndexLogic) GetCategoryInfo() gin.H {
|
||||
// 组装nav导航所需的信息
|
||||
nav := gin.H{}
|
||||
// 1.获取所有分类信息
|
||||
tree := model.GetCategoryTree()
|
||||
tree := system.GetCategoryTree()
|
||||
// 2. 过滤出主页四大分类的tree信息
|
||||
for _, t := range tree.Children {
|
||||
switch t.Category.Name {
|
||||
@@ -94,34 +101,48 @@ func (i *IndexLogic) GetCategoryInfo() gin.H {
|
||||
return nav
|
||||
}
|
||||
|
||||
func (i *IndexLogic) GetNavCategory() []*system.Category {
|
||||
// 1.获取所有分类信息
|
||||
tree := system.GetCategoryTree()
|
||||
// 遍历一级分类返回可展示的分类数据
|
||||
var cl []*system.Category
|
||||
for _, c := range tree.Children {
|
||||
if c.Show {
|
||||
cl = append(cl, c.Category)
|
||||
}
|
||||
}
|
||||
// 返回一级分类列表数据
|
||||
return cl
|
||||
}
|
||||
|
||||
// SearchFilmInfo 获取关键字匹配的影片信息
|
||||
func (i *IndexLogic) SearchFilmInfo(key string, page *model.Page) []model.MovieBasicInfo {
|
||||
func (i *IndexLogic) SearchFilmInfo(key string, page *system.Page) []system.MovieBasicInfo {
|
||||
// 1. 从mysql中获取满足条件的数据, 每页10条
|
||||
sl := model.SearchFilmKeyword(key, page)
|
||||
sl := system.SearchFilmKeyword(key, page)
|
||||
// 2. 获取redis中的basicMovieInfo信息
|
||||
var bl []model.MovieBasicInfo
|
||||
var bl []system.MovieBasicInfo
|
||||
for _, s := range sl {
|
||||
bl = append(bl, model.GetBasicInfoByKey(fmt.Sprintf(config.MovieBasicInfoKey, s.Cid, s.Mid)))
|
||||
bl = append(bl, system.GetBasicInfoByKey(fmt.Sprintf(config.MovieBasicInfoKey, s.Cid, s.Mid)))
|
||||
}
|
||||
return bl
|
||||
}
|
||||
|
||||
// GetFilmCategory 根据Pid或Cid获取指定的分页数据
|
||||
func (i *IndexLogic) GetFilmCategory(id int64, idType string, page *model.Page) []model.MovieBasicInfo {
|
||||
func (i *IndexLogic) GetFilmCategory(id int64, idType string, page *system.Page) []system.MovieBasicInfo {
|
||||
// 1. 根据不同类型进不同的查找
|
||||
var basicList []model.MovieBasicInfo
|
||||
var basicList []system.MovieBasicInfo
|
||||
switch idType {
|
||||
case "pid":
|
||||
basicList = model.GetMovieListByPid(id, page)
|
||||
basicList = system.GetMovieListByPid(id, page)
|
||||
case "cid":
|
||||
basicList = model.GetMovieListByCid(id, page)
|
||||
basicList = system.GetMovieListByCid(id, page)
|
||||
}
|
||||
return basicList
|
||||
}
|
||||
|
||||
// GetPidCategory 获取pid对应的分类信息
|
||||
func (i *IndexLogic) GetPidCategory(pid int64) *model.CategoryTree {
|
||||
tree := model.GetCategoryTree()
|
||||
func (i *IndexLogic) GetPidCategory(pid int64) *system.CategoryTree {
|
||||
tree := system.GetCategoryTree()
|
||||
for _, t := range tree.Children {
|
||||
if t.Id == pid {
|
||||
return t
|
||||
@@ -131,7 +152,7 @@ func (i *IndexLogic) GetPidCategory(pid int64) *model.CategoryTree {
|
||||
}
|
||||
|
||||
// RelateMovie 根据当前影片信息匹配相关的影片
|
||||
func (i *IndexLogic) RelateMovie(detail model.MovieDetail, page *model.Page) []model.MovieBasicInfo {
|
||||
func (i *IndexLogic) RelateMovie(detail system.MovieDetail, page *system.Page) []system.MovieBasicInfo {
|
||||
/*
|
||||
根据当前影片信息匹配相关的影片
|
||||
1. 分类Cid,
|
||||
@@ -140,20 +161,20 @@ func (i *IndexLogic) RelateMovie(detail model.MovieDetail, page *model.Page) []m
|
||||
4. 地区 area
|
||||
5. 语言 Language
|
||||
*/
|
||||
search := model.SearchInfo{
|
||||
search := system.SearchInfo{
|
||||
Cid: detail.Cid,
|
||||
Name: detail.Name,
|
||||
ClassTag: detail.ClassTag,
|
||||
Area: detail.Area,
|
||||
Language: detail.Language,
|
||||
}
|
||||
return model.GetRelateMovieBasicInfo(search, page)
|
||||
return system.GetRelateMovieBasicInfo(search, page)
|
||||
}
|
||||
|
||||
// SearchTags 整合对应分类的搜索tag
|
||||
func (i *IndexLogic) SearchTags(pid int64) map[string]interface{} {
|
||||
// 通过pid 获取对应分类的 tags
|
||||
return model.GetSearchTag(pid)
|
||||
return system.GetSearchTag(pid)
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -162,33 +183,34 @@ func (i *IndexLogic) SearchTags(pid int64) map[string]interface{} {
|
||||
2. 仅对主站点影片name进行映射关系处理并将结果添加到map中
|
||||
例如: xxx第一季 xxx
|
||||
*/
|
||||
func multipleSource(detail *model.MovieDetail) {
|
||||
func multipleSource(detail *system.MovieDetail) {
|
||||
// 整合多播放源, 初始化存储key map
|
||||
names := make(map[string]int)
|
||||
// 1. 判断detail的dbId是否存在, 存在则添加到names中作为匹配条件
|
||||
if detail.DbId > 0 {
|
||||
names[model.GenerateHashKey(detail.DbId)] = 0
|
||||
names[system.GenerateHashKey(detail.DbId)] = 0
|
||||
}
|
||||
// 2. 对name进行去除特殊格式处理
|
||||
names[model.GenerateHashKey(detail.Name)] = 0
|
||||
names[system.GenerateHashKey(detail.Name)] = 0
|
||||
// 3. 对包含第一季的name进行处理
|
||||
names[model.GenerateHashKey(regexp.MustCompile(`第一季$`).ReplaceAllString(detail.Name, ""))] = 0
|
||||
names[system.GenerateHashKey(regexp.MustCompile(`第一季$`).ReplaceAllString(detail.Name, ""))] = 0
|
||||
|
||||
// 4. 将subtitle进行切分,放入names中
|
||||
if len(detail.SubTitle) > 0 && strings.Contains(detail.SubTitle, ",") {
|
||||
for _, v := range strings.Split(detail.SubTitle, ",") {
|
||||
names[model.GenerateHashKey(v)] = 0
|
||||
names[system.GenerateHashKey(v)] = 0
|
||||
}
|
||||
}
|
||||
if len(detail.SubTitle) > 0 && strings.Contains(detail.SubTitle, "/") {
|
||||
for _, v := range strings.Split(detail.SubTitle, "/") {
|
||||
names[model.GenerateHashKey(v)] = 0
|
||||
names[system.GenerateHashKey(v)] = 0
|
||||
}
|
||||
}
|
||||
// 遍历站点列表
|
||||
for _, s := range spider.SiteList {
|
||||
sc := system.GetCollectSourceListByGrade(system.SlaveCollect)
|
||||
for _, s := range sc {
|
||||
for k, _ := range names {
|
||||
pl := model.GetMultiplePlay(s.Name, k)
|
||||
pl := system.GetMultiplePlay(s.Name, k)
|
||||
if len(pl) > 0 {
|
||||
// 如果当前站点已经匹配到数据则直接退出当前循环
|
||||
detail.PlayList = append(detail.PlayList, pl)
|
||||
@@ -196,26 +218,25 @@ func multipleSource(detail *model.MovieDetail) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// GetFilmsByTags 通过searchTag 返回满足条件的分页影片信息
|
||||
func (i *IndexLogic) GetFilmsByTags(st model.SearchTagsVO, page *model.Page) []model.MovieBasicInfo {
|
||||
func (i *IndexLogic) GetFilmsByTags(st system.SearchTagsVO, page *system.Page) []system.MovieBasicInfo {
|
||||
// 获取满足条件的影片id 列表
|
||||
sl := model.GetSearchInfosByTags(st, page)
|
||||
sl := system.GetSearchInfosByTags(st, page)
|
||||
// 通过key 获取对应影片的基本信息
|
||||
return model.GetBasicInfoBySearchInfos(sl...)
|
||||
return system.GetBasicInfoBySearchInfos(sl...)
|
||||
}
|
||||
|
||||
// GetFilmClassify 通过Pid返回当前所属分类下的首页展示数据
|
||||
func (i *IndexLogic) GetFilmClassify(pid int64, page *model.Page) map[string]interface{} {
|
||||
func (i *IndexLogic) GetFilmClassify(pid int64, page *system.Page) map[string]interface{} {
|
||||
res := make(map[string]interface{})
|
||||
// 最新上映 (上映时间)
|
||||
res["news"] = model.GetMovieListBySort(0, pid, page)
|
||||
res["news"] = system.GetMovieListBySort(0, pid, page)
|
||||
// 排行榜 (暂定为热度排行)
|
||||
res["top"] = model.GetMovieListBySort(1, pid, page)
|
||||
res["top"] = system.GetMovieListBySort(1, pid, page)
|
||||
// 最近更新 (更新时间)
|
||||
res["recent"] = model.GetMovieListBySort(2, pid, page)
|
||||
res["recent"] = system.GetMovieListBySort(2, pid, page)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
53
server/logic/ManageLogic.go
Normal file
53
server/logic/ManageLogic.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"server/model/system"
|
||||
)
|
||||
|
||||
type ManageLogic struct {
|
||||
}
|
||||
|
||||
var ML *ManageLogic
|
||||
|
||||
// GetFilmSourceList 获取采集站列表数据
|
||||
func (ml *ManageLogic) GetFilmSourceList() []system.FilmSource {
|
||||
// 返回当前已添加的采集站列表信息
|
||||
return system.GetCollectSourceList()
|
||||
}
|
||||
|
||||
func (ml *ManageLogic) GetFilmSource(id string) *system.FilmSource {
|
||||
return system.FindCollectSourceById(id)
|
||||
}
|
||||
|
||||
func (ml *ManageLogic) UpdateFilmSource(s system.FilmSource) error {
|
||||
return system.UpdateCollectSource(s)
|
||||
}
|
||||
|
||||
func (ml *ManageLogic) SaveFilmSource(s system.FilmSource) error {
|
||||
return system.AddCollectSource(s)
|
||||
}
|
||||
|
||||
func (ml *ManageLogic) DelFilmSource(id string) error {
|
||||
// 先查找是否存在对应ID的站点信息
|
||||
s := system.FindCollectSourceById(id)
|
||||
if s == nil {
|
||||
return errors.New("当前资源站信息不存在, 请勿重复操作")
|
||||
}
|
||||
// 如果是主站点则返回提示禁止直接删除
|
||||
if s.Grade == system.MasterCollect {
|
||||
return errors.New("主站点无法直接删除, 请先降级为附属站点再进行删除")
|
||||
}
|
||||
system.DelCollectResource(id)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSiteBasicConfig 获取网站基本配置信息
|
||||
func (ml *ManageLogic) GetSiteBasicConfig() system.BasicConfig {
|
||||
return system.GetSiteBasic()
|
||||
}
|
||||
|
||||
// UpdateSiteBasic 更新网站配置信息
|
||||
func (ml *ManageLogic) UpdateSiteBasic(c system.BasicConfig) error {
|
||||
return system.SaveSiteBasic(c)
|
||||
}
|
||||
114
server/logic/ProvideLogic.go
Normal file
114
server/logic/ProvideLogic.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"server/config"
|
||||
"server/model/collect"
|
||||
"server/model/system"
|
||||
"server/plugin/common/conver"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ProvideLogic struct {
|
||||
}
|
||||
|
||||
var PL *ProvideLogic
|
||||
|
||||
// GetFilmDetailPage 处理请求参数, 返回filmDetail数据
|
||||
func (pl *ProvideLogic) GetFilmDetailPage(params map[string]string, page *system.Page) collect.FilmDetailLPage {
|
||||
return filmDetailPage(params, page)
|
||||
}
|
||||
|
||||
// GetFilmListPage 处理请求参数, 返回filmList数据
|
||||
func (pl *ProvideLogic) GetFilmListPage(params map[string]string, page *system.Page) collect.FilmListPage {
|
||||
dp := filmDetailPage(params, page)
|
||||
var p collect.FilmListPage = collect.FilmListPage{
|
||||
Code: dp.Code,
|
||||
Msg: dp.Msg,
|
||||
Page: dp.Page,
|
||||
PageCount: dp.PageCount,
|
||||
Limit: dp.Limit,
|
||||
Total: dp.Total,
|
||||
List: conver.DetailCovertList(dp.List),
|
||||
Class: collect.GetFilmClass(),
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (pl *ProvideLogic) GetFilmDetailXmlPage(params map[string]string, page *system.Page) collect.RssD {
|
||||
dp := filmDetailPage(params, page)
|
||||
var dxp = collect.RssD{
|
||||
Version: config.RssVersion,
|
||||
List: collect.FilmDetailPageX{
|
||||
Page: fmt.Sprint(dp.Page),
|
||||
PageCount: dp.PageCount,
|
||||
PageSize: fmt.Sprint(dp.Limit),
|
||||
RecordCount: len(dp.List),
|
||||
Videos: conver.DetailCovertXml(dp.List),
|
||||
},
|
||||
}
|
||||
return dxp
|
||||
}
|
||||
|
||||
func (pl *ProvideLogic) GetFilmListXmlPage(params map[string]string, page *system.Page) collect.RssL {
|
||||
dp := filmDetailPage(params, page)
|
||||
cl := collect.GetFilmClass()
|
||||
var dxp = collect.RssL{
|
||||
Version: config.RssVersion,
|
||||
List: collect.FilmListPageX{
|
||||
Page: dp.Page,
|
||||
PageCount: dp.PageCount,
|
||||
PageSize: dp.Limit,
|
||||
RecordCount: len(dp.List),
|
||||
Videos: conver.DetailCovertListXml(dp.List),
|
||||
},
|
||||
ClassXL: conver.ClassListCovertXml(cl),
|
||||
}
|
||||
return dxp
|
||||
}
|
||||
|
||||
func filmDetailPage(params map[string]string, page *system.Page) collect.FilmDetailLPage {
|
||||
var p collect.FilmDetailLPage = collect.FilmDetailLPage{
|
||||
Code: 1,
|
||||
Msg: "数据列表",
|
||||
Page: fmt.Sprint(page.Current),
|
||||
}
|
||||
// 如果params中的ids不为空, 则直接返回ids对应的数据
|
||||
if len(params["ids"]) > 0 {
|
||||
var ids []int64
|
||||
for _, idStr := range strings.Split(params["ids"], ",") {
|
||||
if id, err := strconv.ParseInt(idStr, 10, 64); err == nil {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
page.Total = len(ids)
|
||||
page.PageCount = int((len(ids) + page.PageSize - 1) / page.PageSize)
|
||||
// 获取id对应的数据
|
||||
for i := 0; i >= (page.Current-1)*page.PageSize && i < page.Total && i < page.Current*page.PageSize; i++ {
|
||||
if fd, err := collect.GetOriginalDetailById(ids[i]); err == nil {
|
||||
p.List = append(p.List, conver.FilterFilmDetail(fd, 0))
|
||||
}
|
||||
}
|
||||
p.PageCount = page.PageCount
|
||||
p.Limit = fmt.Sprint(page.PageSize)
|
||||
p.Total = page.Total
|
||||
return p
|
||||
}
|
||||
|
||||
// 如果请求参数中不包含 ids, 则通过条件进行对应查找
|
||||
l, err := system.FindFilmIds(params, page)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
for _, id := range l {
|
||||
if fd, e := collect.GetOriginalDetailById(id); e == nil {
|
||||
p.List = append(p.List, conver.FilterFilmDetail(fd, 0))
|
||||
}
|
||||
}
|
||||
p.PageCount = page.PageCount
|
||||
p.Limit = fmt.Sprint(page.PageSize)
|
||||
p.Total = page.Total
|
||||
return p
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"log"
|
||||
"server/config"
|
||||
"server/model"
|
||||
"server/model/system"
|
||||
"server/plugin/spider"
|
||||
)
|
||||
|
||||
@@ -13,32 +12,49 @@ type SpiderLogic struct {
|
||||
|
||||
var SL *SpiderLogic
|
||||
|
||||
// ReZero 清空所有数据从零开始拉取
|
||||
func (sl *SpiderLogic) ReZero() {
|
||||
// 如果指令正确,则执行重制
|
||||
spider.StartSpiderRe()
|
||||
// BatchCollect 批量采集
|
||||
func (sl *SpiderLogic) BatchCollect(time int, ids []string) {
|
||||
go spider.BatchCollect(time, ids...)
|
||||
}
|
||||
|
||||
// FixDetail 重新获取主站点数据信息
|
||||
func (sl *SpiderLogic) FixDetail() {
|
||||
spider.MainSiteSpider()
|
||||
log.Println("FilmDetail 重制完成!!!")
|
||||
// 先截断表中的数据
|
||||
model.TunCateSearchTable()
|
||||
// 重新扫描完整的信息到mysql中
|
||||
spider.SearchInfoToMdb()
|
||||
log.Println("SearchInfo 重制完成!!!")
|
||||
}
|
||||
|
||||
// SpiderMtPlayRe 多站点播放数据清空重新获取
|
||||
func (sl *SpiderLogic) SpiderMtPlayRe() {
|
||||
// 先清空有所附加播放源
|
||||
var keys []string
|
||||
for _, site := range spider.SiteList {
|
||||
keys = append(keys, fmt.Sprintf(config.MultipleSiteDetail, site.Name))
|
||||
// StartCollect 执行对指定站点的采集任务
|
||||
func (sl *SpiderLogic) StartCollect(id string, h int) error {
|
||||
// 先判断采集站是否存在于系统数据中
|
||||
if fs := system.FindCollectSourceById(id); fs == nil {
|
||||
return errors.New("采集任务开启失败采集站信息不存在")
|
||||
}
|
||||
model.DelMtPlay(keys)
|
||||
// 如果指令正确,则执行详情数据获取
|
||||
spider.MtSiteSpider()
|
||||
log.Println("MtSiteSpider 重制完成!!!")
|
||||
// 存在则开启协程执行采集方法
|
||||
go func() {
|
||||
err := spider.HandleCollect(id, h)
|
||||
if err != nil {
|
||||
log.Printf("资源站[%s]采集任务执行失败: %s", id, err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
// AutoCollect 自动采集
|
||||
func (sl *SpiderLogic) AutoCollect(time int) {
|
||||
go spider.AutoCollect(time)
|
||||
}
|
||||
|
||||
// ZeroCollect 数据清除从零开始采集
|
||||
func (sl *SpiderLogic) ZeroCollect(time int) {
|
||||
go spider.StarZero(time)
|
||||
}
|
||||
|
||||
// FilmClassCollect 影视分类采集, 直接覆盖当前分类数据
|
||||
func (sl *SpiderLogic) FilmClassCollect() error {
|
||||
l := system.GetCollectSourceListByGrade(system.MasterCollect)
|
||||
if l == nil {
|
||||
return errors.New("未获取到主采集站信息")
|
||||
}
|
||||
// 获取主站点信息, 只取第一条有效
|
||||
for _, fs := range l {
|
||||
if fs.State {
|
||||
go spider.CollectCategory(&fs)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("未获取到已启用的主采集站信息")
|
||||
}
|
||||
|
||||
66
server/logic/UserLogic.go
Normal file
66
server/logic/UserLogic.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"server/model/system"
|
||||
"server/plugin/common/util"
|
||||
)
|
||||
|
||||
type UserLogic struct {
|
||||
}
|
||||
|
||||
var UL *UserLogic
|
||||
|
||||
// UserLogin 用户登录
|
||||
func (ul *UserLogic) UserLogin(account, password string) (token string, err error) {
|
||||
// 根据 username 或 email 查询用户信息
|
||||
var u *system.User = system.GetUserByNameOrEmail(account)
|
||||
// 用户信息不存在则返回提示信息
|
||||
if u == nil {
|
||||
return "", errors.New(" 用户信息不存在!!!")
|
||||
}
|
||||
// 校验用户信息, 执行账号密码校验逻辑
|
||||
if util.PasswordEncrypt(password, u.Salt) != u.Password {
|
||||
return "", errors.New("用户名或密码错误")
|
||||
}
|
||||
// 密码校验成功后下发token
|
||||
token, err = system.GenToken(u.ID, u.UserName)
|
||||
err = system.SaveUserToken(token, u.ID)
|
||||
return
|
||||
}
|
||||
|
||||
// UserLogout 用户退出登录 注销
|
||||
func (ul *UserLogic) UserLogout() {
|
||||
// 通过用户ID清除Redis中的token信息
|
||||
|
||||
}
|
||||
|
||||
// ChangePassword 修改密码
|
||||
func (ul *UserLogic) ChangePassword(account, password, newPassword string) error {
|
||||
// 根据 username 或 email 查询用户信息
|
||||
var u *system.User = system.GetUserByNameOrEmail(account)
|
||||
// 用户信息不存在则返回提示信息
|
||||
if u == nil {
|
||||
return errors.New(" 用户信息不存在!!!")
|
||||
}
|
||||
// 首先校验用户的旧密码是否正确
|
||||
if util.PasswordEncrypt(password, u.Salt) != u.Password {
|
||||
return errors.New("原密码校验失败")
|
||||
}
|
||||
// 密码校验正确则生成新的用户信息
|
||||
newUser := system.User{}
|
||||
newUser.ID = u.ID
|
||||
// 将新密码进行加密
|
||||
newUser.Password = util.PasswordEncrypt(newPassword, u.Salt)
|
||||
// 更新用户信息
|
||||
system.UpdateUserInfo(newUser)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ul *UserLogic) GetUserInfo(id uint) system.UserInfoVo {
|
||||
// 通过用户ID查询对应的用户信息
|
||||
u := system.GetUserById(id)
|
||||
// 去除user信息中的不必要信息
|
||||
var vo = system.UserInfoVo{Id: u.ID, UserName: u.UserName, Email: u.Email, Gender: u.Gender, NickName: u.NickName, Avatar: u.Avatar, Status: u.Status}
|
||||
return vo
|
||||
}
|
||||
Reference in New Issue
Block a user