report_approve.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. package report_approve
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "strings"
  8. "time"
  9. )
  10. // ReportApprove 报告审批表
  11. type ReportApprove struct {
  12. ReportApproveId int `orm:"column(report_approve_id);pk" description:"审批ID"`
  13. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  14. ReportId int `description:"报告ID"`
  15. ReportTitle string `description:"报告标题"`
  16. ClassifyFirstId int `description:"一级分类ID"`
  17. ClassifySecondId int `description:"二级分类ID"`
  18. ClassifyThirdId int `description:"三级分类ID"`
  19. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  20. FlowId int `description:"审批流ID"`
  21. FlowVersion int `description:"审批流版本"`
  22. StartNodeId int `description:"开始节点ID"`
  23. CurrNodeId int `description:"当前节点ID"`
  24. ApplyUserId int `description:"申请人ID"`
  25. ApplyUserName string `description:"申请人姓名"`
  26. ApproveRemark string `description:"审批备注"`
  27. ApproveTime time.Time `description:"审批时间"`
  28. CreateTime time.Time `description:"创建时间"`
  29. ModifyTime time.Time `description:"修改时间"`
  30. }
  31. var ReportApproveCols = struct {
  32. ReportApproveId string
  33. ReportType string
  34. ReportId string
  35. ReportTitle string `description:"报告标题"`
  36. ClassifyFirstId string `description:"一级分类ID"`
  37. ClassifySecondId string `description:"二级分类ID"`
  38. ClassifyThirdId string `description:"三级分类ID"`
  39. State string
  40. FlowId string
  41. FlowVersion string
  42. StartNodeId string
  43. CurrNodeId string
  44. ApplyUserId string `description:"申请人ID"`
  45. ApplyUserName string `description:"申请人姓名"`
  46. ApproveRemark string `description:"审批备注"`
  47. ApproveTime string `description:"审批时间"`
  48. CreateTime string
  49. ModifyTime string
  50. }{
  51. ReportApproveId: "report_approve_id",
  52. ReportType: "report_type",
  53. ReportId: "report_id",
  54. ReportTitle: "report_title",
  55. ClassifyFirstId: "classify_first_id",
  56. ClassifySecondId: "classify_second_id",
  57. ClassifyThirdId: "classify_third_id",
  58. State: "state",
  59. FlowId: "flow_id",
  60. FlowVersion: "flow_version",
  61. StartNodeId: "start_node_id",
  62. CurrNodeId: "curr_node_id",
  63. ApplyUserId: "apply_user_id",
  64. ApplyUserName: "apply_user_name",
  65. ApproveRemark: "approve_remark",
  66. ApproveTime: "approve_time",
  67. CreateTime: "create_time",
  68. ModifyTime: "modify_time",
  69. }
  70. func (m *ReportApprove) TableName() string {
  71. return "report_approve"
  72. }
  73. func (m *ReportApprove) PrimaryId() string {
  74. return ReportApproveCols.ReportApproveId
  75. }
  76. func (m *ReportApprove) Create() (err error) {
  77. o := orm.NewOrmUsingDB("rddp")
  78. id, err := o.Insert(m)
  79. if err != nil {
  80. return
  81. }
  82. m.ReportApproveId = int(id)
  83. return
  84. }
  85. func (m *ReportApprove) CreateMulti(items []*ReportApprove) (err error) {
  86. if len(items) == 0 {
  87. return
  88. }
  89. o := orm.NewOrmUsingDB("rddp")
  90. _, err = o.InsertMulti(len(items), items)
  91. return
  92. }
  93. func (m *ReportApprove) Update(cols []string) (err error) {
  94. o := orm.NewOrmUsingDB("rddp")
  95. _, err = o.Update(m, cols...)
  96. return
  97. }
  98. func (m *ReportApprove) Del() (err error) {
  99. o := orm.NewOrmUsingDB("rddp")
  100. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  101. _, err = o.Raw(sql, m.ReportApproveId).Exec()
  102. return
  103. }
  104. func (m *ReportApprove) MultiDel(menuIds []int) (err error) {
  105. if len(menuIds) == 0 {
  106. return
  107. }
  108. o := orm.NewOrmUsingDB("rddp")
  109. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  110. _, err = o.Raw(sql, menuIds).Exec()
  111. return
  112. }
  113. func (m *ReportApprove) GetItemById(id int) (item *ReportApprove, err error) {
  114. o := orm.NewOrmUsingDB("rddp")
  115. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  116. err = o.Raw(sql, id).QueryRow(&item)
  117. return
  118. }
  119. func (m *ReportApprove) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *ReportApprove, err error) {
  120. o := orm.NewOrmUsingDB("rddp")
  121. order := ``
  122. if orderRule != "" {
  123. order = ` ORDER BY ` + orderRule
  124. }
  125. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  126. err = o.Raw(sql, pars).QueryRow(&item)
  127. return
  128. }
  129. func (m *ReportApprove) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  130. o := orm.NewOrmUsingDB("rddp")
  131. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  132. err = o.Raw(sql, pars).QueryRow(&count)
  133. return
  134. }
  135. func (m *ReportApprove) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ReportApprove, err error) {
  136. o := orm.NewOrmUsingDB("rddp")
  137. fields := strings.Join(fieldArr, ",")
  138. if len(fieldArr) == 0 {
  139. fields = `*`
  140. }
  141. order := `ORDER BY create_time DESC`
  142. if orderRule != "" {
  143. order = ` ORDER BY ` + orderRule
  144. }
  145. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  146. _, err = o.Raw(sql, pars).QueryRows(&items)
  147. return
  148. }
  149. func (m *ReportApprove) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*ReportApprove, err error) {
  150. o := orm.NewOrmUsingDB("rddp")
  151. fields := strings.Join(fieldArr, ",")
  152. if len(fieldArr) == 0 {
  153. fields = `*`
  154. }
  155. order := `ORDER BY create_time DESC`
  156. if orderRule != "" {
  157. order = ` ORDER BY ` + orderRule
  158. }
  159. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  160. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  161. return
  162. }
  163. // ReportApproveItem 报告审批信息
  164. type ReportApproveItem struct {
  165. ReportApproveId int `description:"审批ID"`
  166. ReportApproveRecordId int `description:"审批记录ID"`
  167. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  168. ReportId int `description:"报告ID"`
  169. ReportTitle string `description:"报告标题"`
  170. ReportClassify string `description:"报告分类"`
  171. ClassifyFirstId int `description:"一级分类ID"`
  172. ClassifySecondId int `description:"二级分类ID"`
  173. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  174. RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
  175. FlowId int `description:"审批流ID"`
  176. FlowVersion int `description:"审批流版本"`
  177. StartNodeId int `description:"开始节点ID"`
  178. CurrNodeId int `description:"当前节点ID"`
  179. ApplyUserId int `description:"申请人ID"`
  180. ApplyUserName string `description:"申请人姓名"`
  181. ApproveRemark string `description:"审批备注"`
  182. ApproveTime string `description:"审批时间"`
  183. HandleTime string `description:"处理时间"`
  184. CreateTime string `description:"创建时间"`
  185. ModifyTime string `description:"修改时间"`
  186. DetailImgUrl string `description:"报告详情长图地址"`
  187. DetailPdfUrl string `description:"报告详情PDF地址"`
  188. }
  189. // FormatReportApproveOrm2Item 格式化报告审批
  190. func FormatReportApproveOrm2Item(origin *ReportApproveItemOrm) (item *ReportApproveItem) {
  191. item = new(ReportApproveItem)
  192. if origin == nil {
  193. return
  194. }
  195. item.ReportApproveId = origin.ReportApproveId
  196. item.ReportApproveRecordId = origin.ReportApproveRecordId
  197. item.ReportType = origin.ReportType
  198. item.ReportId = origin.ReportId
  199. item.ReportTitle = origin.ReportTitle
  200. item.ClassifyFirstId = origin.ClassifyFirstId
  201. item.ClassifySecondId = origin.ClassifySecondId
  202. item.State = origin.State
  203. item.RecordState = origin.RecordState
  204. item.FlowId = origin.FlowId
  205. item.FlowVersion = origin.FlowVersion
  206. item.StartNodeId = origin.StartNodeId
  207. item.CurrNodeId = origin.CurrNodeId
  208. item.ApplyUserId = origin.ApplyUserId
  209. item.ApplyUserName = origin.ApplyUserName
  210. item.ApproveRemark = origin.ApproveRemark
  211. item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
  212. item.HandleTime = utils.TimeTransferString(utils.FormatDateTime, origin.HandleTime)
  213. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  214. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  215. return
  216. }
  217. // ReportApproveListReq 审批列表请求体
  218. type ReportApproveListReq struct {
  219. PageSize int `form:"PageSize"`
  220. CurrentIndex int `form:"CurrentIndex"`
  221. ListType int `form:"ListType" description:"列表类型:1-待处理;2-已处理;3-我发起的"`
  222. ReportType int `form:"ReportType" description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  223. ClassifyFirstId int `form:"ClassifyFirstId" description:"一级分类ID"`
  224. ClassifySecondId int `form:"ClassifySecondId" description:"二级分类ID"`
  225. Keyword string `form:"Keyword" description:"关键词:报告标题"`
  226. ApproveState int `form:"ApproveState" description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  227. TimeType int `form:"TimeType" description:"时间类型:1-提交时间;2-处理时间;3-审批时间"`
  228. StartTime string `form:"StartTime" description:"开始时间"`
  229. EndTime string `form:"EndTime" description:"结束时间"`
  230. SortField int `form:"SortField" description:"排序字段:1-提交时间;2-处理时间;3-审批时间"`
  231. SortRule int `form:"SortRule" description:"排序方式: 1-正序; 2-倒序(默认)"`
  232. }
  233. // ReportApproveListResp 审批列表响应体
  234. type ReportApproveListResp struct {
  235. List []*ReportApproveItem
  236. Paging *paging.PagingItem `description:"分页数据"`
  237. }
  238. type ReportApproveItemOrm struct {
  239. ReportApproveId int `description:"审批ID"`
  240. ReportApproveRecordId int `description:"审批记录ID"`
  241. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  242. ReportId int `description:"报告ID"`
  243. ReportTitle string `description:"报告标题"`
  244. ClassifyFirstId int `description:"一级分类ID"`
  245. ClassifySecondId int `description:"二级分类ID"`
  246. ClassifyThirdId int `description:"二级分类ID"`
  247. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  248. RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
  249. FlowId int `description:"审批流ID"`
  250. FlowVersion int `description:"审批流版本"`
  251. StartNodeId int `description:"开始节点ID"`
  252. CurrNodeId int `description:"当前节点ID"`
  253. ApplyUserId int `description:"申请人ID"`
  254. ApplyUserName string `description:"申请人姓名"`
  255. ApproveRemark string `description:"审批备注"`
  256. ApproveTime time.Time `description:"审批时间"`
  257. HandleTime time.Time `description:"处理时间"`
  258. CreateTime time.Time `description:"创建时间"`
  259. ModifyTime time.Time `description:"修改时间"`
  260. NodeState int `description:"当前节点审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回" json:"-"`
  261. NodeApproveTime time.Time `description:"当前节点审批时间" json:"-"`
  262. }
  263. // GetApprovingReportApproveCount 获取待处理的审批分页列表总数
  264. func GetApprovingReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  265. o := orm.NewOrmUsingDB("rddp")
  266. base := fmt.Sprintf(`SELECT a.report_approve_record_id
  267. FROM report_approve_record AS a
  268. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id AND a.node_id = b.curr_node_id
  269. WHERE 1 = 1 %s`, cond)
  270. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  271. err = o.Raw(sql, pars).QueryRow(&count)
  272. return
  273. }
  274. // GetApprovingReportApprovePageList 获取待处理的审批列表-分页
  275. func GetApprovingReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  276. o := orm.NewOrmUsingDB("rddp")
  277. order := `ORDER BY a.create_time DESC`
  278. if orderRule != "" {
  279. order = ` ORDER BY ` + orderRule
  280. }
  281. sql := fmt.Sprintf(`SELECT a.report_approve_record_id, a.state AS record_state, b.*
  282. FROM report_approve_record AS a
  283. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id AND a.node_id = b.curr_node_id
  284. WHERE 1 = 1 %s %s
  285. LIMIT ?,?`, cond, order)
  286. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  287. return
  288. }
  289. // GetApprovedReportApproveCount 获取已处理的审批分页列表总数
  290. func GetApprovedReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  291. o := orm.NewOrmUsingDB("rddp")
  292. base := fmt.Sprintf(`SELECT a.report_approve_record_id
  293. FROM report_approve_record AS a
  294. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
  295. WHERE 1 = 1 %s`, cond)
  296. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  297. err = o.Raw(sql, pars).QueryRow(&count)
  298. return
  299. }
  300. // GetApprovedReportApprovePageList 获取已处理的审批列表-分页
  301. func GetApprovedReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  302. o := orm.NewOrmUsingDB("rddp")
  303. order := `ORDER BY a.create_time DESC`
  304. if orderRule != "" {
  305. order = ` ORDER BY ` + orderRule
  306. }
  307. sql := fmt.Sprintf(`SELECT a.report_approve_record_id, a.node_state AS record_state,a.node_state,a.node_approve_time, a.node_approve_time AS handle_time, b.*
  308. FROM report_approve_record AS a
  309. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
  310. WHERE 1 = 1 %s %s
  311. LIMIT ?,?`, cond, order)
  312. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  313. return
  314. }
  315. // GetApplyReportApproveCount 获取我发起的审批分页列表总数
  316. func GetApplyReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  317. o := orm.NewOrmUsingDB("rddp")
  318. base := fmt.Sprintf(`SELECT a.* FROM report_approve AS a WHERE 1 = 1 %s`, cond)
  319. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  320. err = o.Raw(sql, pars).QueryRow(&count)
  321. return
  322. }
  323. // GetApplyReportApprovePageList 获取我发起的审批列表-分页
  324. func GetApplyReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  325. o := orm.NewOrmUsingDB("rddp")
  326. order := `ORDER BY a.create_time DESC`
  327. if orderRule != "" {
  328. order = ` ORDER BY ` + orderRule
  329. }
  330. sql := fmt.Sprintf(`SELECT a.* FROM report_approve AS a WHERE 1 = 1 %s %s LIMIT ?,?`, cond, order)
  331. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  332. return
  333. }
  334. // ReportApproveDetail 审批详情信息
  335. type ReportApproveDetail struct {
  336. Report *ReportApproveDetailReport `description:"报告信息"`
  337. Approve *ReportApproveDetailItem `description:"审批信息"`
  338. ApproveFlowNodes []*ReportApproveDetailNodes `description:"审批节点信息"`
  339. //ApproveFlow *ReportApproveFlowItem `description:"审批流信息"`
  340. }
  341. // ReportApproveDetailItem 审批详情-审批信息
  342. type ReportApproveDetailItem struct {
  343. ReportApproveId int `description:"审批ID"`
  344. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  345. FlowId int `description:"审批流ID"`
  346. FlowVersion int `description:"审批流版本"`
  347. StartNodeId int `description:"开始节点ID"`
  348. CurrNodeId int `description:"当前节点ID"`
  349. ApplyUserId int `description:"申请人ID"`
  350. ApplyUserName string `description:"申请人姓名"`
  351. ApproveTime string `description:"审批时间"`
  352. CreateTime string `description:"创建时间"`
  353. ModifyTime string `description:"修改时间"`
  354. }
  355. // ReportApproveDetailReport 审批详情-报告信息
  356. type ReportApproveDetailReport struct {
  357. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  358. ReportId int `description:"报告ID"`
  359. ReportTitle string `description:"报告标题"`
  360. ReportCode string `description:"报告code"`
  361. ReportClassify string `description:"报告分类"`
  362. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  363. //ClassifyFirstId int `description:"一级分类ID"`
  364. //ClassifySecondId int `description:"二级分类ID"`
  365. //Content string `description:"报告内容"`
  366. }
  367. // CreateApproveAndRecord 新增审批和记录
  368. func (m *ReportApprove) CreateApproveAndRecord(approveItem *ReportApprove, recordItems []*ReportApproveRecord) (err error) {
  369. if approveItem == nil {
  370. err = fmt.Errorf("approve is nil")
  371. return
  372. }
  373. o := orm.NewOrmUsingDB("rddp")
  374. tx, e := o.Begin()
  375. if e != nil {
  376. err = fmt.Errorf("orm begin err: %s", e.Error())
  377. return
  378. }
  379. defer func() {
  380. if err != nil {
  381. _ = tx.Rollback()
  382. return
  383. }
  384. _ = tx.Commit()
  385. }()
  386. lastId, e := tx.Insert(approveItem)
  387. if e != nil {
  388. err = fmt.Errorf("insert approve err: %s", e.Error())
  389. return
  390. }
  391. approveItem.ReportApproveId = int(lastId)
  392. if len(recordItems) > 0 {
  393. for _, v := range recordItems {
  394. v.ReportApproveId = approveItem.ReportApproveId
  395. }
  396. _, e = tx.InsertMulti(len(recordItems), recordItems)
  397. if e != nil {
  398. err = fmt.Errorf("insert records err: %s", e.Error())
  399. return
  400. }
  401. }
  402. return
  403. }
  404. // ReportApprovePassReq 审批通过请求体
  405. type ReportApprovePassReq struct {
  406. ReportApproveId int `description:"审批ID"`
  407. ReportUrl string `description:"报告URL"`
  408. }
  409. // ReportApproveRefuseReq 审批驳回请求体
  410. type ReportApproveRefuseReq struct {
  411. ReportApproveId int `description:"审批ID"`
  412. ApproveRemark string `description:"驳回理由"`
  413. }
  414. // ReportApproveCancelReq 撤销审批请求体
  415. type ReportApproveCancelReq struct {
  416. ReportApproveId int `description:"审批ID"`
  417. }
  418. // ReportApproveCheckApproveOpenReq 校验分类是否打开审批请求体
  419. type ReportApproveCheckApproveOpenReq struct {
  420. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  421. ClassifyFirstId int `description:"一级分类ID"`
  422. ClassifySecondId int `description:"二级分类ID"`
  423. ClassifyThirdId int `description:"三级分类ID"`
  424. }