package models import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" "time" "github.com/beego/beego/v2/client/orm" ) type PptV2GroupMapping struct { GroupPptId int64 `gorm:"column:group_ppt_id;primaryKey;autoIncrement" description:"自增序号"` GroupId int64 `gorm:"column:group_id" description:"ppt目录ID"` PptSort int64 `gorm:"column:ppt_sort" description:"Ppt的排序"` PptId int64 `gorm:"column:ppt_id" description:"ppt ID"` CreateTime time.Time `gorm:"column:create_time;autoCreateTime" description:"创建时间"` ModifyTime time.Time `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"` AdminId int `gorm:"column:admin_id" description:"移动ppt到该目录的系统用户id"` AdminRealName string `gorm:"column:admin_real_name" description:"系统用户名称"` ChildGroupPptId int64 `gorm:"column:child_group_ppt_id" description:"设置共享后的新映射ID"` IsMoved bool `gorm:"column:is_moved" description:"true表示改PPT被人为移动过"` } func AddPptGroupMapping(item *PptV2GroupMapping) (lastId int64, err error) { err = global.DmSQL["rddp"].Create(item).Error lastId = item.GroupId return } func GetPptMappingCountByGroupId(groupId int64) (total int64, err error) { sql := `select count(*) from ppt_v2_group_mapping where group_id=?` err = global.DmSQL["rddp"].Raw(sql, groupId).Scan(&total).Error return } func GetPptMappingListByGroupId(groupId int64) (list []*PptV2GroupMapping, err error) { sql := `select group_ppt_id, group_id, ppt_id, ppt_sort, admin_id, admin_real_name, create_time from ppt_v2_group_mapping where group_id=? order by ppt_sort asc, group_ppt_id asc ` err = global.DmSQL["rddp"].Raw(sql, groupId).Find(&list).Error return } func GetPptMappingListByGroupIds(groupIds []int64) (list []*PptV2GroupMapping, err error) { err = global.DmSQL["rddp"].Table("ppt_v2_group_mapping").Where("group_id in ?", groupIds).Find(&list).Error return } func GetPptMappingByGroupPptId(groupPptId int64, adminId int) (item *PptV2GroupMapping, err error) { sql := `select * from ppt_v2_group_mapping where group_ppt_id=? and admin_id=?` err = global.DmSQL["rddp"].Raw(sql, groupPptId, adminId).First(&item).Error return } func GetPptMappingByGroupPptCountId(groupPptId int64, adminId int) (count int, err error) { sql := `select COUNT(*) AS count from ppt_v2_group_mapping where group_ppt_id=? and admin_id=?` err = global.DmSQL["rddp"].Raw(sql, groupPptId, adminId).Scan(&count).Error return } func GetPptMappingByPptId(pptId int64) (item *PptV2GroupMapping, err error) { sql := ` select * from ppt_v2_group_mapping where ppt_id=? ` err = global.DmSQL["rddp"].Raw(sql, pptId).First(&item).Error return } func (item *PptV2GroupMapping) Update(cols []string) (err error) { err = global.DmSQL["rddp"].Select(cols).Updates(item).Error return } func AddPptGroupMappingMulti(list []*PptV2GroupMapping) (err error) { err = global.DmSQL["rddp"].CreateInBatches(list, utils.MultiAddNum).Error return } func UpdatePptGroupMappingSortMulti(groupPptIds []int64) (err error) { tx := global.DmSQL["rddp"].Begin() for _, v := range groupPptIds { err = tx.Exec("UPDATE ppt_v2_group_mapping SET ppt_sort = group_ppt_id WHERE group_ppt_id = ?", v).Error if err != nil { tx.Rollback() return } } tx.Commit() return } func DeletePptGroupMapping(groupId int64, adminId int) (err error) { sql := `DELETE FROM ppt_v2_group_mapping WHERE group_ppt_id=? and admin_id=? ` err = global.DmSQL["rddp"].Exec(sql, groupId, adminId).Error return } func DeletePptGroupMappingByPptId(pptId int) (err error) { sql := `DELETE FROM ppt_v2_group_mapping WHERE ppt_id=?` err = global.DmSQL["rddp"].Exec(sql, pptId).Error return } func MoveUpGroupPptBySort(groupId, nextSort, currentSort int64) (err error) { sql := `update ppt_v2_group_mapping set ppt_sort = ppt_sort + 1 where group_id=? and ppt_sort >= ? and ppt_sort< ?` err = global.DmSQL["rddp"].Exec(sql, groupId, nextSort, currentSort).Error return } func MoveDownGroupPptBySort(groupId, prevSort, currentSort int64) (err error) { sql := `update ppt_v2_group_mapping set ppt_sort = ppt_sort - 1 where group_id=? and ppt_sort <= ? and ppt_sort> ? ` err = global.DmSQL["rddp"].Exec(sql, groupId, prevSort, currentSort).Error return } func GetGroupPptByPptId(pptId int) (list []*PptV2GroupMapping, err error) { sql := `select * from ppt_v2_group_mapping where ppt_id=?` err = global.DmSQL["rddp"].Raw(sql, pptId).Find(&list).Error return } func GetPublicGroupPptByPptIds(pptIds []string) (list []*PptV2GroupMapping, err error) { qb, _ := orm.NewQueryBuilder("mysql") qb.Select("p.*"). From("ppt_v2_group as g"). InnerJoin("ppt_v2_group_mapping as p").On("g.group_id = p.group_id"). Where("g.is_share = 1 and p.ppt_id").In(pptIds...). OrderBy("g.share_time asc, p.ppt_sort asc") sql := qb.String() err = global.DmSQL["rddp"].Raw(sql).Find(&list).Error return }