report_approve.go 17 KB

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