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