123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type PptV2GroupMapping struct {
- GroupPptId int64 `orm:"column(group_ppt_id);pk;auto" description:"自增序号"`
- GroupId int64 `description:"ppt目录ID"`
- PptSort int64 `description:"Ppt的排序"`
- PptId int64 `description:"ppt ID"`
- CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"`
- ModifyTime time.Time `orm:"auto_now;type(datetime)" description:"修改时间"`
- AdminId int `description:"移动ppt到该目录的系统用户id"`
- AdminRealName string `description:"系统用户名称"`
- ChildGroupPptId int64 `description:"设置共享后的新映射ID"`
- }
- func AddPptGroupMapping(item *PptV2GroupMapping) (lastId int64, err error) {
- o := orm.NewOrmUsingDB("rddp")
- lastId, err = o.Insert(item)
- return
- }
- func GetPptMappingCountByGroupId(groupId int64) (total int64, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `select count(*) from ppt_v2_group_mapping where group_id=?`
- err = o.Raw(sql, groupId).QueryRow(&total)
- return
- }
- func GetPptMappingListByGroupId(groupId int64) (list []*PptV2GroupMapping, err error) {
- o := orm.NewOrmUsingDB("rddp")
- 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 = o.Raw(sql, groupId).QueryRows(&list)
- return
- }
- func GetPptMappingListByGroupIds(groupIds []int64) (list []*PptV2GroupMapping, err error) {
- _, err = orm.NewOrmUsingDB("rddp").
- QueryTable("ppt_v2_group_mapping").
- Filter("group_id__in", groupIds).
- OrderBy("-ppt_sort", "group_ppt_id").
- All(&list)
- return
- }
- func GetPptMappingByGroupPptId(groupPptId int64, adminId int) (item *PptV2GroupMapping, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `select * from ppt_v2_group_mapping where group_ppt_id=? and admin_id=?`
- err = o.Raw(sql, groupPptId, adminId).QueryRow(&item)
- return
- }
- func (item *PptV2GroupMapping) Update(cols []string) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- _, err = o.Update(item, cols...)
- return
- }
- func AddPptGroupMappingMulti(list []*PptV2GroupMapping) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- _, err = o.InsertMulti(1, list)
- return
- }
- func UpdatePptGroupMappingSortMulti(groupPptIds []int64) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- p, err := o.Raw("UPDATE ppt_v2_group_mapping SET ppt_sort = group_ppt_id WHERE group_ppt_id = ?").Prepare()
- if err != nil {
- return
- }
- defer func() {
- _ = p.Close()
- }()
- for _, v := range groupPptIds {
- _, err = p.Exec(v)
- if err != nil {
- return
- }
- }
- return
- }
- func DeletePptGroupMapping(groupId int64, adminId int) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `DELETE FROM ppt_v2_group_mapping WHERE group_ppt_id=? and admin_id=? `
- _, err = o.Raw(sql, groupId, adminId).Exec()
- return
- }
- func DeletePptGroupMappingByPptId(pptId int) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `DELETE FROM ppt_v2_group_mapping WHERE ppt_id=?`
- _, err = o.Raw(sql, pptId).Exec()
- return
- }
- func MoveUpGroupPptBySort(groupId, nextSort, currentSort int64) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `update ppt_v2_group_mapping set ppt_sort = ppt_sort + 1 where group_id=? and ppt_sort >= ? and ppt_sort< ?`
- _, err = o.Raw(sql, groupId, nextSort, currentSort).Exec()
- return
- }
- func MoveDownGroupPptBySort(groupId, prevSort, currentSort int64) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `update ppt_v2_group_mapping set ppt_sort = ppt_sort - 1 where group_id=? and ppt_sort <= ? and ppt_sort> ? `
- _, err = o.Raw(sql, groupId, prevSort, currentSort).Exec()
- return
- }
- func GetGroupPptByPptId(pptId int) (list []*PptV2GroupMapping, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `select * from ppt_v2_group_mapping where ppt_id=?`
- _, err = o.Raw(sql, pptId).QueryRows(&list)
- 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()
-
- o := orm.NewOrmUsingDB("rddp")
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
|