report_approve.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. package report_approve
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/beego/beego/v2/client/orm"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  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. ClassifyThirdId int `description:"三级分类ID"`
  174. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  175. RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
  176. FlowId int `description:"审批流ID"`
  177. FlowVersion int `description:"审批流版本"`
  178. StartNodeId int `description:"开始节点ID"`
  179. CurrNodeId int `description:"当前节点ID"`
  180. ApplyUserId int `description:"申请人ID"`
  181. ApplyUserName string `description:"申请人姓名"`
  182. ApproveRemark string `description:"审批备注"`
  183. ApproveTime string `description:"审批时间"`
  184. HandleTime string `description:"处理时间"`
  185. CreateTime string `description:"创建时间"`
  186. ModifyTime string `description:"修改时间"`
  187. DetailImgUrl string `description:"报告详情长图地址"`
  188. DetailPdfUrl string `description:"报告详情PDF地址"`
  189. }
  190. // FormatReportApproveOrm2Item 格式化报告审批
  191. func FormatReportApproveOrm2Item(origin *ReportApproveItemOrm) (item *ReportApproveItem) {
  192. item = new(ReportApproveItem)
  193. if origin == nil {
  194. return
  195. }
  196. item.ReportApproveId = origin.ReportApproveId
  197. item.ReportApproveRecordId = origin.ReportApproveRecordId
  198. item.ReportType = origin.ReportType
  199. item.ReportId = origin.ReportId
  200. item.ReportTitle = origin.ReportTitle
  201. item.ClassifyFirstId = origin.ClassifyFirstId
  202. item.ClassifySecondId = origin.ClassifySecondId
  203. item.ClassifyThirdId = origin.ClassifyThirdId
  204. item.State = origin.State
  205. item.RecordState = origin.RecordState
  206. item.FlowId = origin.FlowId
  207. item.FlowVersion = origin.FlowVersion
  208. item.StartNodeId = origin.StartNodeId
  209. item.CurrNodeId = origin.CurrNodeId
  210. item.ApplyUserId = origin.ApplyUserId
  211. item.ApplyUserName = origin.ApplyUserName
  212. item.ApproveRemark = origin.ApproveRemark
  213. item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
  214. item.HandleTime = utils.TimeTransferString(utils.FormatDateTime, origin.HandleTime)
  215. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  216. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  217. return
  218. }
  219. // ReportApproveListReq 审批列表请求体
  220. type ReportApproveListReq struct {
  221. PageSize int `form:"PageSize"`
  222. CurrentIndex int `form:"CurrentIndex"`
  223. ListType int `form:"ListType" description:"列表类型:1-待处理;2-已处理;3-我发起的"`
  224. ReportType int `form:"ReportType" description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  225. ClassifyFirstId int `form:"ClassifyFirstId" description:"一级分类ID"`
  226. ClassifySecondId int `form:"ClassifySecondId" description:"二级分类ID"`
  227. ClassifyThirdId int `form:"ClassifyThirdId" description:"三级级分类ID"`
  228. Keyword string `form:"Keyword" description:"关键词:报告标题"`
  229. ApproveState int `form:"ApproveState" description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  230. TimeType int `form:"TimeType" description:"时间类型:1-提交时间;2-处理时间;3-审批时间"`
  231. StartTime string `form:"StartTime" description:"开始时间"`
  232. EndTime string `form:"EndTime" description:"结束时间"`
  233. SortField int `form:"SortField" description:"排序字段:1-提交时间;2-处理时间;3-审批时间"`
  234. SortRule int `form:"SortRule" description:"排序方式: 1-正序; 2-倒序(默认)"`
  235. }
  236. // ReportApproveListResp 审批列表响应体
  237. type ReportApproveListResp struct {
  238. List []*ReportApproveItem
  239. Paging *paging.PagingItem `description:"分页数据"`
  240. }
  241. type ReportApproveItemOrm struct {
  242. ReportApproveId int `description:"审批ID"`
  243. ReportApproveRecordId int `description:"审批记录ID"`
  244. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  245. ReportId int `description:"报告ID"`
  246. ReportTitle string `description:"报告标题"`
  247. ClassifyFirstId int `description:"一级分类ID"`
  248. ClassifySecondId int `description:"二级分类ID"`
  249. ClassifyThirdId int `description:"三级分类ID"`
  250. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  251. RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
  252. FlowId int `description:"审批流ID"`
  253. FlowVersion int `description:"审批流版本"`
  254. StartNodeId int `description:"开始节点ID"`
  255. CurrNodeId int `description:"当前节点ID"`
  256. ApplyUserId int `description:"申请人ID"`
  257. ApplyUserName string `description:"申请人姓名"`
  258. ApproveRemark string `description:"审批备注"`
  259. ApproveTime time.Time `description:"审批时间"`
  260. HandleTime time.Time `description:"处理时间"`
  261. CreateTime time.Time `description:"创建时间"`
  262. ModifyTime time.Time `description:"修改时间"`
  263. NodeState int `description:"当前节点审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回" json:"-"`
  264. NodeApproveTime time.Time `description:"当前节点审批时间" json:"-"`
  265. }
  266. // GetApprovingReportApproveCount 获取待处理的审批分页列表总数
  267. func GetApprovingReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  268. o := orm.NewOrmUsingDB("rddp")
  269. base := fmt.Sprintf(`SELECT a.report_approve_record_id
  270. FROM report_approve_record AS a
  271. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id AND a.node_id = b.curr_node_id
  272. WHERE 1 = 1 %s`, cond)
  273. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  274. err = o.Raw(sql, pars).QueryRow(&count)
  275. return
  276. }
  277. // GetApprovingReportApprovePageList 获取待处理的审批列表-分页
  278. func GetApprovingReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  279. o := orm.NewOrmUsingDB("rddp")
  280. order := `ORDER BY a.create_time DESC`
  281. if orderRule != "" {
  282. order = ` ORDER BY ` + orderRule
  283. }
  284. sql := fmt.Sprintf(`SELECT a.report_approve_record_id, a.state AS record_state, b.*
  285. FROM report_approve_record AS a
  286. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id AND a.node_id = b.curr_node_id
  287. WHERE 1 = 1 %s %s
  288. LIMIT ?,?`, cond, order)
  289. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  290. return
  291. }
  292. // GetApprovedReportApproveCount 获取已处理的审批分页列表总数
  293. func GetApprovedReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  294. o := orm.NewOrmUsingDB("rddp")
  295. base := fmt.Sprintf(`SELECT a.report_approve_record_id
  296. FROM report_approve_record AS a
  297. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
  298. WHERE 1 = 1 %s`, cond)
  299. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  300. err = o.Raw(sql, pars).QueryRow(&count)
  301. return
  302. }
  303. // GetApprovedReportApprovePageList 获取已处理的审批列表-分页
  304. func GetApprovedReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  305. o := orm.NewOrmUsingDB("rddp")
  306. order := `ORDER BY a.create_time DESC`
  307. if orderRule != "" {
  308. order = ` ORDER BY ` + orderRule
  309. }
  310. 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.*
  311. FROM report_approve_record AS a
  312. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
  313. WHERE 1 = 1 %s %s
  314. LIMIT ?,?`, cond, order)
  315. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  316. return
  317. }
  318. // GetApplyReportApproveCount 获取我发起的审批分页列表总数
  319. func GetApplyReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  320. o := orm.NewOrmUsingDB("rddp")
  321. base := fmt.Sprintf(`SELECT a.* FROM report_approve AS a WHERE 1 = 1 %s`, cond)
  322. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  323. err = o.Raw(sql, pars).QueryRow(&count)
  324. return
  325. }
  326. // GetApplyReportApprovePageList 获取我发起的审批列表-分页
  327. func GetApplyReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  328. o := orm.NewOrmUsingDB("rddp")
  329. order := `ORDER BY a.create_time DESC`
  330. if orderRule != "" {
  331. order = ` ORDER BY ` + orderRule
  332. }
  333. sql := fmt.Sprintf(`SELECT a.* FROM report_approve AS a WHERE 1 = 1 %s %s LIMIT ?,?`, cond, order)
  334. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  335. return
  336. }
  337. // ReportApproveDetail 审批详情信息
  338. type ReportApproveDetail struct {
  339. Report *ReportApproveDetailReport `description:"报告信息"`
  340. Approve *ReportApproveDetailItem `description:"审批信息"`
  341. ApproveFlowNodes []*ReportApproveDetailNodes `description:"审批节点信息"`
  342. //ApproveFlow *ReportApproveFlowItem `description:"审批流信息"`
  343. }
  344. // ReportApproveDetailItem 审批详情-审批信息
  345. type ReportApproveDetailItem struct {
  346. ReportApproveId int `description:"审批ID"`
  347. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  348. FlowId int `description:"审批流ID"`
  349. FlowVersion int `description:"审批流版本"`
  350. StartNodeId int `description:"开始节点ID"`
  351. CurrNodeId int `description:"当前节点ID"`
  352. ApplyUserId int `description:"申请人ID"`
  353. ApplyUserName string `description:"申请人姓名"`
  354. ApproveTime string `description:"审批时间"`
  355. CreateTime string `description:"创建时间"`
  356. ModifyTime string `description:"修改时间"`
  357. }
  358. // ReportApproveDetailReport 审批详情-报告信息
  359. type ReportApproveDetailReport struct {
  360. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  361. ReportId int `description:"报告ID"`
  362. ReportTitle string `description:"报告标题"`
  363. ReportCode string `description:"报告code"`
  364. ReportClassify string `description:"报告分类"`
  365. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  366. //ClassifyFirstId int `description:"一级分类ID"`
  367. //ClassifySecondId int `description:"二级分类ID"`
  368. //Content string `description:"报告内容"`
  369. }
  370. // CreateApproveAndRecord 新增审批和记录
  371. func (m *ReportApprove) CreateApproveAndRecord(approveItem *ReportApprove, recordItems []*ReportApproveRecord) (err error) {
  372. if approveItem == nil {
  373. err = fmt.Errorf("approve is nil")
  374. return
  375. }
  376. o := orm.NewOrmUsingDB("rddp")
  377. tx, e := o.Begin()
  378. if e != nil {
  379. err = fmt.Errorf("orm begin err: %s", e.Error())
  380. return
  381. }
  382. defer func() {
  383. if err != nil {
  384. _ = tx.Rollback()
  385. return
  386. }
  387. _ = tx.Commit()
  388. }()
  389. lastId, e := tx.Insert(approveItem)
  390. if e != nil {
  391. err = fmt.Errorf("insert approve err: %s", e.Error())
  392. return
  393. }
  394. approveItem.ReportApproveId = int(lastId)
  395. if len(recordItems) > 0 {
  396. for _, v := range recordItems {
  397. v.ReportApproveId = approveItem.ReportApproveId
  398. }
  399. _, e = tx.InsertMulti(len(recordItems), recordItems)
  400. if e != nil {
  401. err = fmt.Errorf("insert records err: %s", e.Error())
  402. return
  403. }
  404. }
  405. return
  406. }
  407. // ReportApprovePassReq 审批通过请求体
  408. type ReportApprovePassReq struct {
  409. ReportApproveId int `description:"审批ID"`
  410. ReportUrl string `description:"报告URL"`
  411. }
  412. // ReportApproveRefuseReq 审批驳回请求体
  413. type ReportApproveRefuseReq struct {
  414. ReportApproveId int `description:"审批ID"`
  415. ApproveRemark string `description:"驳回理由"`
  416. }
  417. // ReportApproveCancelReq 撤销审批请求体
  418. type ReportApproveCancelReq struct {
  419. ReportApproveId int `description:"审批ID"`
  420. }
  421. // ReportApproveCheckApproveOpenReq 校验分类是否打开审批请求体
  422. type ReportApproveCheckApproveOpenReq struct {
  423. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  424. ClassifyFirstId int `description:"一级分类ID"`
  425. ClassifySecondId int `description:"二级分类ID"`
  426. ClassifyThirdId int `description:"三级分类ID"`
  427. }