123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- package report
- import (
- "eta/eta_api/utils"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type ReportChapterPermissionMapping struct {
- ReportChapterPermissionMappingId int `orm:"column(report_chapter_permission_mapping_id)"`
- ReportChapterId int `description:"报告章节的id"`
- ChartPermissionId int `description:"权限id"`
- CreateTime time.Time
- }
- func (m ReportChapterPermissionMapping) MultiAddReportChapterPermissionMappingPermission(reportChapterId int, list []*ReportChapterPermissionMapping) (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_permission_mapping 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 ReportChapterPermissionMapping) GetPermissionListById(reportChapterId int) (list []*ReportChapterPermissionMapping, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM report_chapter_permission_mapping WHERE report_chapter_id=? `
- _, err = o.Raw(sql, reportChapterId).QueryRows(&list)
- return
- }
- type ReportChapterPermissionItem struct {
- ReportChapterPermissionMappingId int `orm:"column(report_chapter_permission_mapping_id)"`
- ReportChapterId int `description:"报告章节的id"`
- ChartPermissionId int `description:"权限id"`
- ChartPermissionName string `description:"品种名称"`
- CreateTime time.Time
- }
- func (m ReportChapterPermissionMapping) GetPermissionItemListById(reportChapterId int) (list []*ReportChapterPermissionItem, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT a.*,b.chart_permission_name FROM report_chapter_permission_mapping AS a
- JOIN chart_permission AS b on a.chart_permission_id=b.chart_permission_id WHERE report_chapter_id=? `
- _, err = o.Raw(sql, reportChapterId).QueryRows(&list)
- return
- }
- func (m ReportChapterPermissionMapping) GetPermissionListByIdList(reportChapterIdList []int) (list []*ReportChapterPermissionMapping, err error) {
- num := len(reportChapterIdList)
- if num <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM report_chapter_permission_mapping WHERE report_chapter_id in (` + utils.GetOrmInReplace(num) + `) `
- _, err = o.Raw(sql, reportChapterIdList).QueryRows(&list)
- return
- }
- func (m ReportChapterPermissionMapping) MultiAdd(list []*ReportChapterPermissionMapping) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
-
- if len(list) > 0 {
- _, err = to.InsertMulti(500, list)
- if err != nil {
- return
- }
- }
- return
- }
|