mirror of
https://github.com/ProudMuBai/GoFilm.git
synced 2026-02-15 06:54:41 +08:00
add film delete and recover function
This commit is contained in:
@@ -87,7 +87,7 @@ const (
|
||||
|
||||
//mysql服务配置信息 root:root 设置mysql账户的用户名和密码
|
||||
|
||||
MysqlDsn = "root:root@(192.168.20.7:3306)/FilmSite?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
MysqlDsn = "root:root@(192.168.20.5:3306)/FilmSite?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
|
||||
// MysqlDsn docker compose 环境下的链接信息 mysql:3306 为 docker compose 中 mysql服务对应的网络名称和端口
|
||||
//MysqlDsn = "root:root@(mysql:3306)/FilmSite?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
@@ -98,7 +98,7 @@ const (
|
||||
RedisPassword redis访问密码
|
||||
RedisDBNo 使用第几号库
|
||||
*/
|
||||
RedisAddr = `192.168.20.7:6379`
|
||||
RedisAddr = `192.168.20.5:6379`
|
||||
RedisPassword = `root`
|
||||
RedisDBNo = 0
|
||||
|
||||
|
||||
@@ -104,6 +104,27 @@ func FilmAdd(c *gin.Context) {
|
||||
system.SuccessOnlyMsg("影片信息添加成功", c)
|
||||
}
|
||||
|
||||
// FilmDelete 删除影片检索信息, 逻辑删除
|
||||
func FilmDelete(c *gin.Context) {
|
||||
// 获取影片ID
|
||||
idStr := c.DefaultQuery("id", "")
|
||||
if idStr == "" {
|
||||
system.Failed("删除失败,缺少ID参数", c)
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
system.Failed("删除失败,参数类型异常", c)
|
||||
return
|
||||
}
|
||||
// 通过ID删除对应影片检索信息
|
||||
if err = logic.FL.DelFilm(id); err != nil {
|
||||
system.Failed(fmt.Sprintln("删除失败: ", err.Error()), c)
|
||||
return
|
||||
}
|
||||
system.SuccessOnlyMsg("影片删除成功", c)
|
||||
}
|
||||
|
||||
//----------------------------------------------------影片分类处理----------------------------------------------------
|
||||
|
||||
// FilmClassTree 影片分类树数据
|
||||
|
||||
@@ -19,10 +19,10 @@ var FL *FilmLogic
|
||||
|
||||
//----------------------------------------------------影片管理业务逻辑----------------------------------------------------
|
||||
|
||||
// GetFilmPage 获取影片检索信息分页数据
|
||||
func (fl *FilmLogic) GetFilmPage(s system.SearchVo) []system.SearchInfo {
|
||||
// 获取影片检索信息分页数据
|
||||
sl := system.GetSearchPage(s)
|
||||
//
|
||||
return sl
|
||||
}
|
||||
|
||||
@@ -70,6 +70,17 @@ func (fl *FilmLogic) SaveFilmDetail(fd system.FilmDetailVo) error {
|
||||
return system.SaveDetail(detail)
|
||||
}
|
||||
|
||||
// DelFilm 删除分类影片
|
||||
func (fl *FilmLogic) DelFilm(id int64) error {
|
||||
// 通过id查询对应影片信息是否存在
|
||||
s := system.GetSearchInfoById(id)
|
||||
if s == nil {
|
||||
return errors.New("影片信息不存在")
|
||||
}
|
||||
// 通过id删除对应影片信息
|
||||
return system.DelFilmSearch(id)
|
||||
}
|
||||
|
||||
//----------------------------------------------------影片分类业务逻辑----------------------------------------------------
|
||||
|
||||
// GetFilmClassTree 获取影片分类信息
|
||||
@@ -78,6 +89,7 @@ func (fl *FilmLogic) GetFilmClassTree() system.CategoryTree {
|
||||
return system.GetCategoryTree()
|
||||
}
|
||||
|
||||
// GetFilmClassById 通过ID获取影片分类信息
|
||||
func (fl *FilmLogic) GetFilmClassById(id int64) *system.CategoryTree {
|
||||
tree := system.GetCategoryTree()
|
||||
for _, c := range tree.Children {
|
||||
@@ -120,6 +132,18 @@ func (fl *FilmLogic) UpdateClass(class system.CategoryTree) error {
|
||||
if class.Name != "" {
|
||||
subC.Name = class.Name
|
||||
}
|
||||
// 如果所属分类为二级分类且show属性进行了变化
|
||||
if class.Show {
|
||||
// 如果show为ture则将其分类下的影片信息进行恢复
|
||||
if err := system.RecoverFilmSearch(class.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// 如果show为false则将其分类下的影片信息进行屏蔽
|
||||
if err := system.ShieldFilmSearch(class.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
subC.Show = class.Show
|
||||
if err := system.SaveCategoryTree(&tree); err != nil {
|
||||
return fmt.Errorf("影片分类信息更新失败: %s", err.Error())
|
||||
|
||||
@@ -694,6 +694,7 @@ func GetMovieListBySort(t int, pid int64, page *Page) []MovieBasicInfo {
|
||||
|
||||
// ================================= Manage 管理后台 =================================
|
||||
|
||||
// GetSearchPage 获取影片检索分页数据
|
||||
func GetSearchPage(s SearchVo) []SearchInfo {
|
||||
// 构建 query查询条件
|
||||
query := db.Mdb.Model(&SearchInfo{})
|
||||
@@ -762,6 +763,46 @@ func GetSearchOptions(pid int64) map[string]interface{} {
|
||||
return tagMap
|
||||
}
|
||||
|
||||
// GetSearchInfoById 查询id对应的检索信息
|
||||
func GetSearchInfoById(id int64) *SearchInfo {
|
||||
s := SearchInfo{}
|
||||
if err := db.Mdb.First(&s, id).Error; err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
// DelFilmSearch 删除影片检索信息, (不影响后续更新, 逻辑删除)
|
||||
func DelFilmSearch(id int64) error {
|
||||
// 通过检索id对影片检索信息进行删除
|
||||
if err := db.Mdb.Delete(&SearchInfo{}, id).Error; err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ShieldFilmSearch 删除所属分类下的所有影片检索信息
|
||||
func ShieldFilmSearch(cid int64) error {
|
||||
// 通过检索id对影片检索信息进行删除
|
||||
if err := db.Mdb.Where("cid = ?", cid).Delete(&SearchInfo{}).Error; err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RecoverFilmSearch 恢复所属分类下的影片检索信息状态
|
||||
func RecoverFilmSearch(cid int64) error {
|
||||
// 通过检索id对影片检索信息进行删除
|
||||
if err := db.Mdb.Model(&SearchInfo{}).Unscoped().Where("cid = ?", cid).Update("deleted_at", nil).Error; err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ================================= 接口数据缓存 =================================
|
||||
|
||||
// DataCache API请求 数据缓存
|
||||
|
||||
@@ -84,6 +84,7 @@ func SetupRouter() *gin.Engine {
|
||||
{
|
||||
filmRoute.POST(`/add`, controller.FilmAdd)
|
||||
filmRoute.GET(`/search/list`, controller.FilmSearchPage)
|
||||
filmRoute.GET(`/search/del`, controller.FilmDelete)
|
||||
|
||||
filmRoute.GET(`/class/tree`, controller.FilmClassTree)
|
||||
filmRoute.GET(`/class/find`, controller.FindFilmClass)
|
||||
|
||||
Reference in New Issue
Block a user