123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- package models
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "time"
- )
- // PptV2Grant Ppt授权表
- type PptV2Grant struct {
- GrantId int64 `gorm:"column:grant_id;primaryKey;autoIncrement" description:"自增序号"`
- PptId int64 `gorm:"column:ppt_id" description:"ppt ID"`
- DepartmentId int64 `gorm:"column:department_id" description:"授权部门id"`
- GrantAdminId int64 `gorm:"column:grant_admin_id" description:"授权管理员id"`
- CreateTime time.Time `gorm:"column:create_time;autoCreateTime" description:"创建时间"`
- }
- // GetPPtGrantInfo 获取已经有权限的ppt列表
- func GetPPtGrantInfo(pptId int) (list []*PptV2Grant, err error) {
- sql := `SELECT * FROM ppt_v2_grant WHERE ppt_id=? `
- err = global.DmSQL["rddp"].Raw(sql, pptId).Find(&list).Error
- return
- }
- // GrantInfoResp ppt权限配置返回数据
- type GrantInfoResp struct {
- PptId int `description:"PptId" `
- GrantType int `description:"分配类型;1:全部ficc研究员;2:指定成员"`
- AdminIdStr string `description:"指定成员id,多个成员用英文,隔开"`
- }
- // GrantPptReq 分配ppt权限
- type GrantPptReq struct {
- PptId int `description:"PptId" `
- GrantType int `description:"分配类型;1:全部ficc研究员;2:指定成员"`
- AdminIdStr string `description:"指定成员id,多个成员用英文,隔开"`
- }
- // MultiAddPptV2Grant 批量添加授权记录
- func MultiAddPptV2Grant(pptId int, list []*PptV2Grant) (err error) {
- to := global.DmSQL["rddp"].Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- sql := "DELETE from ppt_v2_grant where ppt_id=?"
- err = to.Exec(sql, pptId).Error
- if err != nil {
- return
- }
- // 新增授权记录
- if len(list) > 0 {
- tmpErr := to.CreateInBatches(list, utils.MultiAddNum).Error
- if tmpErr != nil {
- err = tmpErr
- return
- }
- }
- return
- }
- // DeletePptV2Grant 移除授权记录
- func DeletePptV2Grant(pptId int) (err error) {
- sql := "DELETE from ppt_v2_grant where ppt_id=?"
- err = global.DmSQL["rddp"].Exec(sql, pptId).Error
- return
- }
- type PptV2InfoGrantItem struct {
- PptId int `gorm:"column:ppt_id;primaryKey;autoIncrement" description:"ppt的Id"`
- TemplateType int `gorm:"column:template_type" description:"模版类型"`
- BackgroundImg string `gorm:"column:background_img" description:"背景图片"`
- Title string `gorm:"column:title" description:"标题"`
- ReportType string `gorm:"column:report_type" description:"报告类型"`
- PptDate string `gorm:"column:ppt_date" description:"选择日期"`
- Content string `gorm:"column:content" description:"ppt内容"`
- PptUrl string `gorm:"column:ppt_url" description:"ppt下载地址"`
- PptxUrl string `gorm:"column:pptx_url" description:"pptx下载地址"`
- CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
- ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
- AdminId int `gorm:"column:admin_id" description:"系统用户id"`
- AdminRealName string `gorm:"column:admin_real_name" description:"系统用户名称"`
- PptVersion int8 `gorm:"column:ppt_version" description:"是否ppt的旧版本;1:旧的,2:新的"`
- ReportId int `gorm:"column:report_id" description:"关联的报告ID"`
- ReportCode string `gorm:"column:report_code" description:"关联的报告code"`
- IsShare int8 `gorm:"column:is_share" description:"是否分享,0:不分享,1:分享"`
- PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
- PptPage int `gorm:"column:ppt_page" description:"PPT页数"`
- }
- // GetAllGrantList 获取已经有权限的ppt列表
- func GetAllGrantList(sysUserId int) (list []*PptV2InfoGrantItem, err error) {
- sql := `SELECT a.ppt_id,a.template_type,a.background_img,a.title,a.report_type,a.ppt_date,a.ppt_url,a.pptx_url,a.content,a.create_time,a.modify_time,
- a.admin_id,a.admin_real_name,a.ppt_version,a.report_id,a.report_code,a.is_share,a.publish_time,a.cover_content,a.ppt_page,a.title_setting FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
- WHERE a.admin_id=? OR b.department_id=1 OR b.grant_admin_id=? GROUP BY a.ppt_id,a.template_type,a.background_img,a.title,a.report_type,a.ppt_date,a.ppt_url,a.pptx_url,a.content,a.create_time,a.modify_time,
- a.admin_id,a.admin_real_name,a.ppt_version,a.report_id,a.report_code,a.is_share,a.publish_time,a.cover_content,a.ppt_page,a.title_setting`
- err = global.DmSQL["rddp"].Raw(sql, sysUserId, sysUserId).Find(&list).Error
- return
- }
- // GetGrantList 获取我共享出去/别人共享给我的的ppt列表
- func GetGrantList(condition string, pars []interface{}) (list []*PptV2InfoGrantItem, err error) {
- sql := `SELECT a.ppt_id,a.template_type,a.background_img,a.title,a.report_type,a.ppt_date,a.ppt_url,a.pptx_url,a.create_time,a.modify_time,
- a.admin_id,a.admin_real_name,a.ppt_version,a.report_id,a.report_code,a.is_share,a.publish_time,a.ppt_page,a.title_setting
- FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
- WHERE 1=1 `
- sql += condition
- sql += ` GROUP BY a.ppt_id,a.template_type,a.background_img,a.title,a.report_type,a.ppt_date,a.ppt_url,a.pptx_url,a.create_time,a.modify_time,
- a.admin_id,a.admin_real_name,a.ppt_version,a.report_id,a.report_code,a.is_share,a.publish_time,a.ppt_page,a.title_setting ORDER BY a.modify_time DESC `
- err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&list).Error
- return
- }
- // GetPPtGrantConf 根据ppt_id和操作人获取ppt权限配置
- func GetPPtGrantConf(pptId, sysUserId int) (item *PptV2InfoGrantItem, err error) {
- sql := `SELECT a.* FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
- WHERE a.ppt_id=? AND (b.department_id=1 OR b.grant_admin_id=?) GROUP BY a.ppt_id`
- err = global.DmSQL["rddp"].Raw(sql, pptId, sysUserId).First(&item).Error
- return
- }
|