report_approve.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. package report_approve
  2. import (
  3. "eta/eta_mobile/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. ClassifyThirdId int `description:"二级分类ID"`
  245. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  246. RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
  247. FlowId int `description:"审批流ID"`
  248. FlowVersion int `description:"审批流版本"`
  249. StartNodeId int `description:"开始节点ID"`
  250. CurrNodeId int `description:"当前节点ID"`
  251. ApplyUserId int `description:"申请人ID"`
  252. ApplyUserName string `description:"申请人姓名"`
  253. ApproveRemark string `description:"审批备注"`
  254. ApproveTime time.Time `description:"审批时间"`
  255. HandleTime time.Time `description:"处理时间"`
  256. CreateTime time.Time `description:"创建时间"`
  257. ModifyTime time.Time `description:"修改时间"`
  258. NodeState int `description:"当前节点审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回" json:"-"`
  259. NodeApproveTime time.Time `description:"当前节点审批时间" json:"-"`
  260. }
  261. // GetApprovingReportApproveCount 获取待处理的审批分页列表总数
  262. func GetApprovingReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  263. o := orm.NewOrmUsingDB("rddp")
  264. base := fmt.Sprintf(`SELECT a.report_approve_record_id
  265. FROM report_approve_record AS a
  266. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id AND a.node_id = b.curr_node_id
  267. WHERE 1 = 1 %s`, cond)
  268. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  269. err = o.Raw(sql, pars).QueryRow(&count)
  270. return
  271. }
  272. // GetApprovingReportApprovePageList 获取待处理的审批列表-分页
  273. func GetApprovingReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  274. o := orm.NewOrmUsingDB("rddp")
  275. order := `ORDER BY a.create_time DESC`
  276. if orderRule != "" {
  277. order = ` ORDER BY ` + orderRule
  278. }
  279. sql := fmt.Sprintf(`SELECT a.report_approve_record_id, a.state AS record_state, b.*
  280. FROM report_approve_record AS a
  281. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id AND a.node_id = b.curr_node_id
  282. WHERE 1 = 1 %s %s
  283. LIMIT ?,?`, cond, order)
  284. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  285. return
  286. }
  287. // GetApprovedReportApproveCount 获取已处理的审批分页列表总数
  288. func GetApprovedReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  289. o := orm.NewOrmUsingDB("rddp")
  290. base := fmt.Sprintf(`SELECT a.report_approve_record_id
  291. FROM report_approve_record AS a
  292. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
  293. WHERE 1 = 1 %s`, cond)
  294. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  295. err = o.Raw(sql, pars).QueryRow(&count)
  296. return
  297. }
  298. // GetApprovedReportApprovePageList 获取已处理的审批列表-分页
  299. func GetApprovedReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  300. o := orm.NewOrmUsingDB("rddp")
  301. order := `ORDER BY a.create_time DESC`
  302. if orderRule != "" {
  303. order = ` ORDER BY ` + orderRule
  304. }
  305. sql := fmt.Sprintf(`SELECT a.report_approve_record_id, a.node_state AS record_state,a.node_state,a.node_approve_time, a.approve_time AS handle_time, b.*
  306. FROM report_approve_record AS a
  307. JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
  308. WHERE 1 = 1 %s %s
  309. LIMIT ?,?`, cond, order)
  310. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  311. return
  312. }
  313. // GetApplyReportApproveCount 获取我发起的审批分页列表总数
  314. func GetApplyReportApproveCount(cond string, pars []interface{}) (count int, err error) {
  315. o := orm.NewOrmUsingDB("rddp")
  316. base := fmt.Sprintf(`SELECT a.* FROM report_approve AS a WHERE 1 = 1 %s`, cond)
  317. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  318. err = o.Raw(sql, pars).QueryRow(&count)
  319. return
  320. }
  321. // GetApplyReportApprovePageList 获取我发起的审批列表-分页
  322. func GetApplyReportApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*ReportApproveItemOrm, err error) {
  323. o := orm.NewOrmUsingDB("rddp")
  324. order := `ORDER BY a.create_time DESC`
  325. if orderRule != "" {
  326. order = ` ORDER BY ` + orderRule
  327. }
  328. sql := fmt.Sprintf(`SELECT a.* FROM report_approve AS a WHERE 1 = 1 %s %s LIMIT ?,?`, cond, order)
  329. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  330. return
  331. }
  332. // ReportApproveDetail 审批详情信息
  333. type ReportApproveDetail struct {
  334. Report *ReportApproveDetailReport `description:"报告信息"`
  335. Approve *ReportApproveDetailItem `description:"审批信息"`
  336. ApproveFlowNodes []*ReportApproveDetailNodes `description:"审批节点信息"`
  337. //ApproveFlow *ReportApproveFlowItem `description:"审批流信息"`
  338. }
  339. // ReportApproveDetailItem 审批详情-审批信息
  340. type ReportApproveDetailItem struct {
  341. ReportApproveId int `description:"审批ID"`
  342. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  343. FlowId int `description:"审批流ID"`
  344. FlowVersion int `description:"审批流版本"`
  345. StartNodeId int `description:"开始节点ID"`
  346. CurrNodeId int `description:"当前节点ID"`
  347. ApplyUserId int `description:"申请人ID"`
  348. ApplyUserName string `description:"申请人姓名"`
  349. ApproveTime string `description:"审批时间"`
  350. CreateTime string `description:"创建时间"`
  351. ModifyTime string `description:"修改时间"`
  352. }
  353. // ReportApproveDetailReport 审批详情-报告信息
  354. type ReportApproveDetailReport struct {
  355. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  356. ReportId int `description:"报告ID"`
  357. ReportTitle string `description:"报告标题"`
  358. ReportCode string `description:"报告code"`
  359. ReportClassify string `description:"报告分类"`
  360. //ClassifyFirstId int `description:"一级分类ID"`
  361. //ClassifySecondId int `description:"二级分类ID"`
  362. //Content string `description:"报告内容"`
  363. }
  364. // CreateApproveAndRecord 新增审批和记录
  365. func (m *ReportApprove) CreateApproveAndRecord(approveItem *ReportApprove, recordItems []*ReportApproveRecord) (err error) {
  366. if approveItem == nil {
  367. err = fmt.Errorf("approve is nil")
  368. return
  369. }
  370. o := orm.NewOrmUsingDB("rddp")
  371. tx, e := o.Begin()
  372. if e != nil {
  373. err = fmt.Errorf("orm begin err: %s", e.Error())
  374. return
  375. }
  376. defer func() {
  377. if err != nil {
  378. _ = tx.Rollback()
  379. return
  380. }
  381. _ = tx.Commit()
  382. }()
  383. lastId, e := tx.Insert(approveItem)
  384. if e != nil {
  385. err = fmt.Errorf("insert approve err: %s", e.Error())
  386. return
  387. }
  388. approveItem.ReportApproveId = int(lastId)
  389. if len(recordItems) > 0 {
  390. for _, v := range recordItems {
  391. v.ReportApproveId = approveItem.ReportApproveId
  392. }
  393. _, e = tx.InsertMulti(len(recordItems), recordItems)
  394. if e != nil {
  395. err = fmt.Errorf("insert records err: %s", e.Error())
  396. return
  397. }
  398. }
  399. return
  400. }
  401. // ReportApprovePassReq 审批通过请求体
  402. type ReportApprovePassReq struct {
  403. ReportApproveId int `description:"审批ID"`
  404. ReportUrl string `description:"报告URL"`
  405. }
  406. // ReportApproveRefuseReq 审批驳回请求体
  407. type ReportApproveRefuseReq struct {
  408. ReportApproveId int `description:"审批ID"`
  409. ApproveRemark string `description:"驳回理由"`
  410. }
  411. // ReportApproveCancelReq 撤销审批请求体
  412. type ReportApproveCancelReq struct {
  413. ReportApproveId int `description:"审批ID"`
  414. }
  415. // ReportApproveCheckApproveOpenReq 校验分类是否打开审批请求体
  416. type ReportApproveCheckApproveOpenReq struct {
  417. ReportType int `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
  418. ClassifyFirstId int `description:"一级分类ID"`
  419. ClassifySecondId int `description:"二级分类ID"`
  420. ClassifyThirdId int `description:"三级分类ID"`
  421. }