report_v2.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. package models
  2. import (
  3. "eta/eta_api/models/report"
  4. "eta/eta_api/utils"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. // EditReportAndPermission
  8. // @Description: 修改报告的基础信息、授权用户权限
  9. // @author: Roc
  10. // @datetime 2024-06-06 17:11:12
  11. // @param reportInfo *Report
  12. // @param updateCols []string
  13. // @param addReportGrantList []*report.ReportGrant
  14. // @param delReportGrantIdList []int
  15. // @return err error
  16. func EditReportAndPermission(reportInfo *Report, updateCols []string, addReportGrantList []*report.ReportGrant, delReportGrantIdList []int) (err error) {
  17. o := orm.NewOrmUsingDB("rddp")
  18. to, err := o.Begin()
  19. if err != nil {
  20. return
  21. }
  22. defer func() {
  23. if err != nil {
  24. _ = to.Rollback()
  25. } else {
  26. _ = to.Commit()
  27. }
  28. }()
  29. // 变更报告章节信息
  30. if len(updateCols) > 0 {
  31. _, err = to.Update(reportInfo, updateCols...)
  32. if err != nil {
  33. return
  34. }
  35. }
  36. // 新增报告授权用户
  37. if len(addReportGrantList) > 0 {
  38. _, err = to.InsertMulti(500, addReportGrantList)
  39. if err != nil {
  40. return
  41. }
  42. }
  43. // 删除报告授权用户
  44. delNum := len(delReportGrantIdList)
  45. if delNum > 0 {
  46. sql := `DELETE FROM report_grant WHERE grant_id IN (` + utils.GetOrmInReplace(delNum) + `)`
  47. _, err = to.Raw(sql, delReportGrantIdList).Exec()
  48. if err != nil {
  49. return
  50. }
  51. }
  52. return
  53. }
  54. // EditChapterBaseInfoAndPermission
  55. // @Description: 修改报告章节的基础信息、授权用户权限、品种权限
  56. // @author: Roc
  57. // @datetime 2024-06-05 11:45:04
  58. // @param reportChapterInfo *ReportChapter
  59. // @param updateCols []string
  60. // @param addReportChapterGrantList []report.ReportChapterGrant
  61. // @param addChapterPermissionMap []*report.ReportChapterPermissionMapping
  62. // @param delReportChapterGrantIdList []int
  63. // @param delChapterPermissionMappingIdList []int
  64. // @return err error
  65. func EditChapterBaseInfoAndPermission(reportChapterInfo *ReportChapter, updateCols []string, addReportChapterGrantList []*report.ReportChapterGrant, addChapterPermissionMap []*report.ReportChapterPermissionMapping, delReportChapterGrantIdList, delChapterPermissionMappingIdList []int) (err error) {
  66. o := orm.NewOrmUsingDB("rddp")
  67. to, err := o.Begin()
  68. if err != nil {
  69. return
  70. }
  71. defer func() {
  72. if err != nil {
  73. _ = to.Rollback()
  74. } else {
  75. _ = to.Commit()
  76. }
  77. }()
  78. // 变更报告章节信息
  79. if len(updateCols) > 0 {
  80. _, err = to.Update(reportChapterInfo, updateCols...)
  81. if err != nil {
  82. return
  83. }
  84. }
  85. // 新增报告章节授权用户
  86. if len(addReportChapterGrantList) > 0 {
  87. _, err = to.InsertMulti(500, addReportChapterGrantList)
  88. if err != nil {
  89. return
  90. }
  91. }
  92. // 删除报告章节授权用户
  93. delNum := len(delReportChapterGrantIdList)
  94. if delNum > 0 {
  95. sql := `DELETE FROM report_chapter_grant WHERE grant_id IN (` + utils.GetOrmInReplace(delNum) + `)`
  96. _, err = to.Raw(sql, delReportChapterGrantIdList).Exec()
  97. if err != nil {
  98. return
  99. }
  100. }
  101. // 新增报告章节的品种配置
  102. if len(addChapterPermissionMap) > 0 {
  103. _, err = to.InsertMulti(500, addChapterPermissionMap)
  104. if err != nil {
  105. return
  106. }
  107. }
  108. // 删除报告章节的品种配置
  109. delNum = len(delChapterPermissionMappingIdList)
  110. if delNum > 0 {
  111. sql := `DELETE FROM report_chapter_permission_mapping WHERE report_chapter_permission_mapping_id IN (` + utils.GetOrmInReplace(delNum) + `)`
  112. _, err = to.Raw(sql, delChapterPermissionMappingIdList).Exec()
  113. if err != nil {
  114. return
  115. }
  116. }
  117. return
  118. }
  119. // DelChapterAndPermission
  120. // @Description: 删除报告章节、授权用户权限、品种权限
  121. // @author: Roc
  122. // @datetime 2024-06-06 17:25:47
  123. // @param reportInfo *Report
  124. // @param updateReportCols []string
  125. // @param reportChapterInfo *ReportChapter
  126. // @return err error
  127. func DelChapterAndPermission(reportInfo *Report, updateReportCols []string, reportChapterInfo *ReportChapter) (err error) {
  128. o := orm.NewOrmUsingDB("rddp")
  129. to, err := o.Begin()
  130. if err != nil {
  131. return
  132. }
  133. defer func() {
  134. if err != nil {
  135. _ = to.Rollback()
  136. } else {
  137. _ = to.Commit()
  138. }
  139. }()
  140. // 变更报告信息
  141. if len(updateReportCols) > 0 {
  142. _, err = to.Update(reportInfo, updateReportCols...)
  143. if err != nil {
  144. return
  145. }
  146. }
  147. // 删除报告对应章节
  148. {
  149. _, err = to.Delete(reportChapterInfo)
  150. if err != nil {
  151. return
  152. }
  153. }
  154. // 删除报告章节的授权用户权限
  155. {
  156. sql := `DELETE FROM report_chapter_grant WHERE report_chapter_id = ? `
  157. _, err = to.Raw(sql, reportChapterInfo.ReportChapterId).Exec()
  158. if err != nil {
  159. return
  160. }
  161. }
  162. // 删除报告章节的品种配置
  163. {
  164. sql := `DELETE FROM report_chapter_permission_mapping WHERE report_chapter_id = ? `
  165. _, err = to.Raw(sql, reportChapterInfo.ReportChapterId).Exec()
  166. if err != nil {
  167. return
  168. }
  169. }
  170. return
  171. }
  172. // GetReportListCountByAuthorized
  173. // @Description: 获取有权限的报告列表的报告数量
  174. // @author: Roc
  175. // @datetime 2024-05-30 15:14:01
  176. // @param condition string
  177. // @param pars []interface{}
  178. // @return count int
  179. // @return err error
  180. func GetReportListCountByAuthorized(condition string, pars []interface{}) (count int, err error) {
  181. o := orm.NewOrmUsingDB("rddp")
  182. sql := `SELECT COUNT(1) AS count FROM report as a
  183. WHERE 1=1 `
  184. if condition != "" {
  185. sql += condition
  186. }
  187. err = o.Raw(sql, pars).QueryRow(&count)
  188. return
  189. }
  190. // GetReportListByAuthorized
  191. // @Description: 获取有权限的报告列表的数据
  192. // @author: Roc
  193. // @datetime 2024-05-30 15:15:07
  194. // @param condition string
  195. // @param pars []interface{}
  196. // @param startSize int
  197. // @param pageSize int
  198. // @return items []*ReportList
  199. // @return err error
  200. func GetReportListByAuthorized(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  201. o := orm.NewOrmUsingDB("rddp")
  202. 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 `
  203. if condition != "" {
  204. sql += condition
  205. }
  206. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  207. sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  208. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  209. return
  210. }