report_approve.go 18 KB

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