report_approve.go 18 KB

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