package ppt_english import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" "time" ) // PptEnglishGrant Ppt授权表 //type PptEnglishGrant struct { // GrantId int64 `orm:"column(grant_id);pk;auto" description:"自增序号"` // PptId int64 `description:"ppt ID"` // DepartmentId int64 `description:"授权部门id"` // GrantAdminId int64 `description:"授权部门id"` // CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"` //} type PptEnglishGrant struct { GrantId int64 `gorm:"primaryKey;column:grant_id;type:int(9) unsigned;not null"` // 授权id PptId int64 `gorm:"index:idx_pptid;column:ppt_id;type:int(9) unsigned;not null;default:0"` // ppt_id DepartmentId int64 `gorm:"column:department_id;type:int(10) unsigned;not null;default:0"` // 授权部门id GrantAdminId int64 `gorm:"column:grant_admin_id;type:int(9) unsigned;default:0"` // 授权的用户id CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP"` // 授权时间 } // GetPPtGrantInfo 获取已经有权限的ppt列表 func GetPPtGrantInfo(pptId int) (list []*PptEnglishGrant, err error) { //o := orm.NewOrmUsingDB("rddp") sql := `SELECT * FROM ppt_english_grant WHERE ppt_id=? ` //_, err = o.Raw(sql, pptId).QueryRows(&list) 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,多个成员用英文,隔开"` } // MultiAddPptEnglishGrant 批量添加授权记录 func MultiAddPptEnglishGrant(pptId int, list []*PptEnglishGrant) (err error) { //o := orm.NewOrmUsingDB("rddp") //to, err := o.Begin() //if err != nil { // return //} //defer func() { // if err != nil { // _ = to.Rollback() // } else { // _ = to.Commit() // } //}() // //sql := "DELETE from ppt_english_grant where ppt_id=?" //_, err = to.Raw(sql, pptId).Exec() //if err != nil { // return //} // //// 新增授权记录 //if len(list) > 0 { // _, tmpErr := to.InsertMulti(len(list), list) // if tmpErr != nil { // err = tmpErr // return // } //} tx := global.DmSQL["rddp"].Begin() defer func() { if err != nil { _ = tx.Rollback() return } _ = tx.Commit() }() sql := "DELETE from ppt_english_grant where ppt_id=?" err = tx.Exec(sql, pptId).Error if err != nil { return } // 新增授权记录 if len(list) > 0 { e := tx.CreateInBatches(list, utils.MultiAddNum).Error if e != nil { err = e return } } return } // DeletePptEnglishGrant 移除授权记录 func DeletePptEnglishGrant(pptId int) (err error) { //o := orm.NewOrmUsingDB("rddp") sql := "DELETE from ppt_english_grant where ppt_id=?" //_, err = o.Raw(sql, pptId).Exec() err = global.DmSQL["rddp"].Exec(sql, pptId).Error return } // PptEnglishInfoGrantItem Ppt信息记录(包含授权信息) //type PptEnglishInfoGrantItem struct { // PptId int `orm:"column(ppt_id);pk;auto" description:"ppt的Id"` // TemplateType int `description:"模版类型"` // BackgroundImg string `description:"背景图片"` // Title string `description:"标题"` // ReportType string `description:"报告类型"` // PptDate string `description:"选择日期"` // Content string `description:"ppt内容"` // PptUrl string `description:"ppt下载地址"` // PptxUrl string `description:"pptx下载地址"` // CreateTime time.Time `description:"创建时间"` // ModifyTime time.Time `description:"修改时间"` // AdminId int `description:"系统用户id"` // AdminRealName string `description:"系统用户名称"` // PptVersion int8 `description:"是否ppt的旧版本;1:旧的,2:新的"` // ReportId int `description:"关联的报告ID"` // ReportCode string `description:"关联的报告code"` // IsShare int8 `description:"是否分享,0:不分享,1:分享"` // PublishTime time.Time `description:"发布时间"` // PptPage int `description:"PPT页数"` // //GrantId int64 `orm:"column(grant_id);pk;auto" description:"自增序号"` // //PptId int64 `description:"ppt ID"` // //DepartmentId int64 `description:"授权部门id"` // //GrantAdminId int64 `description:"授权部门id"` // //CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"` //} type PptEnglishInfoGrantItem struct { PptId int `gorm:"column:ppt_id;type:int(11) unsigned;not null"` TemplateType int `gorm:"column:template_type;type:int(9) unsigned;default:1"` // 模板类型 BackgroundImg string `gorm:"column:background_img;type:varchar(255);default:''"` // 背景图 Title string `gorm:"column:title;type:varchar(255);default:''"` // 标题 ReportType string `gorm:"column:report_type;type:varchar(50);default:''"` // 报告类型 PptDate string `gorm:"column:ppt_date;type:varchar(20);default:''"` // 选择日期 PptUrl string `gorm:"column:ppt_url;type:varchar(255);default:''"` // ppt地址 PptxUrl string `gorm:"column:pptx_url;type:varchar(255);default:''"` // pptx地址 Content string `gorm:"column:content;type:mediumtext"` // ppt内容 CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP"` // 创建时间 ModifyTime time.Time `gorm:"column:modify_time;type:datetime;default:CURRENT_TIMESTAMP"` // 修改时间 AdminId int `gorm:"column:admin_id;type:int(11) unsigned;default:0"` // 系统用户id AdminRealName string `gorm:"column:admin_real_name;type:varchar(100);default:''"` // 系统用户名称 PptVersion int8 `gorm:"column:ppt_version;type:tinyint(9) unsigned;default:2"` // 是否ppt的旧版本;1:旧的,2:新的 ReportId int `gorm:"column:report_id;type:int(10) unsigned;not null;default:0"` // 关联的报告ID ReportCode string `gorm:"column:report_code;type:varchar(255);not null;default:''"` // 关联的报告code IsShare int8 `gorm:"column:is_share;type:tinyint(9) unsigned;default:0"` // 是否分享,0:不分享,1:分享 PublishTime time.Time `gorm:"column:publish_time;type:datetime"` // 发布时间 PptPage int `gorm:"column:ppt_page;type:int(10)"` // PPT总页数 } // GetAllGrantList 获取已经有权限的ppt列表 func GetAllGrantList(sysUserId int) (list []*PptEnglishInfoGrantItem, err error) { //o := orm.NewOrmUsingDB("rddp") sql := `SELECT a.* FROM ppt_english a JOIN ppt_english_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` //_, err = o.Raw(sql, sysUserId, sysUserId).QueryRows(&list) err = global.DmSQL["rddp"].Raw(sql, sysUserId, sysUserId).Find(&list).Error return } // GetGrantList 获取我共享出去/别人共享给我的的ppt列表 func GetGrantList(condition string, pars []interface{}) (list []*PptEnglishInfoGrantItem, err error) { //o := orm.NewOrmUsingDB("rddp") sql := `SELECT a.* FROM ppt_english a JOIN ppt_english_grant b on a.ppt_id=b.ppt_id WHERE 1=1 ` sql += condition sql += ` GROUP BY a.ppt_id ORDER BY a.modify_time DESC ` //_, err = o.Raw(sql, pars).QueryRows(&list) err = global.DmSQL["rddp"].Raw(sql, pars).Find(&list).Error return } // GetPPtGrantConf 根据ppt_id和操作人获取ppt权限配置 func GetPPtGrantConf(pptId, sysUserId int) (item *PptEnglishInfoGrantItem, err error) { //o := orm.NewOrmUsingDB("rddp") sql := `SELECT a.* FROM ppt_english a JOIN ppt_english_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 = o.Raw(sql, pptId, sysUserId).QueryRow(&item) err = global.DmSQL["rddp"].Raw(sql, pptId, sysUserId).First(&item).Error return }