12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package report
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "time"
- )
- type ReportGrant struct {
- GrantId int `gorm:"primaryKey;column:grant_id;type:int(9) unsigned;not null"` // 授权id
- ReportId int `gorm:"index:idx_reportid;column:report_id;type:int(9) unsigned;not null;default:0"` // 报告id
- AdminId int `gorm:"column:admin_id;type:int(9) unsigned;default:0"` // 授权的用户id
- CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP"` // 授权时间
- }
- func (m ReportGrant) MultiAddReportGrantGrant(reportId int, list []*ReportGrant) (err error) {
- tx := global.DmSQL["rddp"].Begin()
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- return
- }
- _ = tx.Commit()
- }()
- sql := "DELETE from report_grant where report_id=?"
- err = tx.Exec(sql, reportId).Error
- if err != nil {
- return
- }
- if len(list) > 0 {
- e := tx.CreateInBatches(list, utils.MultiAddNum).Error
- if e != nil {
- err = e
- return
- }
- }
- return
- }
- func (m ReportGrant) GetGrantListById(reportId int) (list []*ReportGrant, err error) {
- sql := `SELECT * FROM report_grant WHERE report_id=? `
- err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
- return
- }
- func (m ReportGrant) GetGrantListByIdList(reportIdList []int) (list []*ReportGrant, err error) {
- num := len(reportIdList)
- if num <= 0 {
- return
- }
- sql := `SELECT * FROM report_grant WHERE report_id in (` + utils.GetOrmInReplace(num) + `) `
- err = global.DmSQL["rddp"].Raw(sql, reportIdList).Find(&list).Error
- return
- }
- func (m ReportGrant) GetGrantByIdAndAdmin(reportId, sysUserId int) (item *ReportGrant, err error) {
- sql := `SELECT * FROM report_grant WHERE report_id = ? AND admin_id = ? `
- err = global.DmSQL["rddp"].Raw(sql, reportId, sysUserId).First(&item).Error
- return
- }
- func (m ReportGrant) GetGrantListByAdminId(adminId int) (list []*ReportGrant, err error) {
- sql := `SELECT * FROM report_grant WHERE admin_id=? `
- err = global.DmSQL["rddp"].Raw(sql, adminId).Find(&list).Error
- return
- }
|