123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- package report
- import (
- "eta/eta_api/utils"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type ReportGrant struct {
- GrantId int `orm:"column(grant_id)"`
- ReportId int `description:"报告id"`
- AdminId int `description:"授权的用户id"`
- CreateTime time.Time `description:"授权时间"`
- }
- func (m ReportGrant) MultiAddReportGrantGrant(reportId int, list []*ReportGrant) (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 report_grant where report_id=?"
- _, err = to.Raw(sql, reportId).Exec()
- if err != nil {
- return
- }
-
- if len(list) > 0 {
- _, tmpErr := to.InsertMulti(500, list)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- }
- return
- }
- func (m ReportGrant) GetGrantListById(reportId int) (list []*ReportGrant, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM report_grant WHERE report_id=? `
- _, err = o.Raw(sql, reportId).QueryRows(&list)
- return
- }
- func (m ReportGrant) GetGrantListByIdList(reportIdList []int) (list []*ReportGrant, err error) {
- num := len(reportIdList)
- if num <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM report_grant WHERE report_id in (` + utils.GetOrmInReplace(num) + `) `
- _, err = o.Raw(sql, reportIdList).QueryRows(&list)
- return
- }
- func (m ReportGrant) GetGrantByIdAndAdmin(reportId, sysUserId int) (item *ReportGrant, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM report_grant WHERE report_id = ? AND admin_id = ? `
- err = o.Raw(sql, reportId, sysUserId).QueryRow(&item)
- return
- }
- func (m ReportGrant) GetGrantListByAdminId(adminId int) (list []*ReportGrant, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM report_grant WHERE admin_id=? `
- _, err = o.Raw(sql, adminId).QueryRows(&list)
- return
- }
|