report_approve.go 17 KB

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