package models import ( "eta/eta_api/models/report" "eta/eta_api/utils" "github.com/beego/beego/v2/client/orm" ) // EditReportAndPermission // @Description: 修改报告的基础信息、授权用户权限 // @author: Roc // @datetime 2024-06-06 17:11:12 // @param reportInfo *Report // @param updateCols []string // @param addReportGrantList []*report.ReportGrant // @param delReportGrantIdList []int // @return err error func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportGrantList []*report.ReportGrant, delReportGrantIdList []int) (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(updateCols) > 0 { _, err = to.Update(reportInfo, updateCols...) if err != nil { return } } // 新增报告授权用户 if len(addReportGrantList) > 0 { _, err = to.InsertMulti(500, addReportGrantList) if err != nil { return } } // 删除报告授权用户 delNum := len(delReportGrantIdList) if delNum > 0 { sql := `DELETE FROM report_grant WHERE grant_id IN (` + utils.GetOrmInReplace(delNum) + `)` _, err = to.Raw(sql, delReportGrantIdList).Exec() if err != nil { return } } return } // EditChapterBaseInfoAndPermission // @Description: 修改报告章节的基础信息、授权用户权限、品种权限 // @author: Roc // @datetime 2024-06-05 11:45:04 // @param reportChapterInfo *ReportChapter // @param updateCols []string // @param addReportChapterGrantList []report.ReportChapterGrant // @param addChapterPermissionMap []*report.ReportChapterPermissionMapping // @param delReportChapterGrantIdList []int // @param delChapterPermissionMappingIdList []int // @return err error func EditChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, updateCols []string, addReportChapterGrantList []*report.ReportChapterGrant, addChapterPermissionMap []*report.ReportChapterPermissionMapping, delReportChapterGrantIdList, delChapterPermissionMappingIdList []int) (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(updateCols) > 0 { _, err = to.Update(reportChapterInfo, updateCols...) if err != nil { return } } // 新增报告章节授权用户 if len(addReportChapterGrantList) > 0 { _, err = to.InsertMulti(500, addReportChapterGrantList) if err != nil { return } } // 删除报告章节授权用户 delNum := len(delReportChapterGrantIdList) if delNum > 0 { sql := `DELETE FROM report_chapter_grant WHERE grant_id IN (` + utils.GetOrmInReplace(delNum) + `)` _, err = to.Raw(sql, delReportChapterGrantIdList).Exec() if err != nil { return } } // 新增报告章节的品种配置 if len(addChapterPermissionMap) > 0 { _, err = to.InsertMulti(500, addChapterPermissionMap) if err != nil { return } } // 删除报告章节的品种配置 delNum = len(delChapterPermissionMappingIdList) if delNum > 0 { sql := `DELETE FROM report_chapter_permission_mapping WHERE report_chapter_permission_mapping_id IN (` + utils.GetOrmInReplace(delNum) + `)` _, err = to.Raw(sql, delChapterPermissionMappingIdList).Exec() if err != nil { return } } return } // DelChapterAndPermission // @Description: 删除报告章节、授权用户权限、品种权限 // @author: Roc // @datetime 2024-06-06 17:25:47 // @param reportInfo *Report // @param updateReportCols []string // @param reportChapterInfo *ReportChapter // @return err error func DelChapterAndPermission(reportInfo *Report, updateReportCols []string, reportChapterInfo *ReportChapter) (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(updateReportCols) > 0 { _, err = to.Update(reportInfo, updateReportCols...) if err != nil { return } } // 删除报告对应章节 { _, err = to.Delete(reportChapterInfo) if err != nil { return } } // 删除报告章节的授权用户权限 { sql := `DELETE FROM report_chapter_grant WHERE report_chapter_id = ? ` _, err = to.Raw(sql, reportChapterInfo.ReportChapterId).Exec() if err != nil { return } } // 删除报告章节的品种配置 { sql := `DELETE FROM report_chapter_permission_mapping WHERE report_chapter_id = ? ` _, err = to.Raw(sql, reportChapterInfo.ReportChapterId).Exec() if err != nil { return } } return } // GetReportListCountByAuthorized // @Description: 获取有权限的报告列表的报告数量 // @author: Roc // @datetime 2024-05-30 15:14:01 // @param condition string // @param pars []interface{} // @return count int // @return err error func GetReportListCountByAuthorized(condition string, pars []interface{}) (count int, err error) { o := orm.NewOrmUsingDB("rddp") sql := `SELECT COUNT(1) AS count FROM report as a WHERE 1=1 ` if condition != "" { sql += condition } err = o.Raw(sql, pars).QueryRow(&count) return } // GetReportListByAuthorized // @Description: 获取有权限的报告列表的数据 // @author: Roc // @datetime 2024-05-30 15:15:07 // @param condition string // @param pars []interface{} // @param startSize int // @param pageSize int // @return items []*ReportList // @return err error func GetReportListByAuthorized(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) { o := orm.NewOrmUsingDB("rddp") sql := `SELECT id,classify_id_first,classify_name_first,classify_id_second,classify_name_second,classify_id_third,classify_name_third,title,stage,create_time FROM report as a WHERE 1=1 ` if condition != "" { sql += condition } // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过 sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?` _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return }