contract_approval_record.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package contract
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. //合同审批单
  7. type ContractApprovalRecord struct {
  8. ContractApprovalRecordId int `orm:"column(contract_approval_record_id);pk"`
  9. ContractApprovalId int `orm:"column(contract_approval_id)" description:"审批单id"`
  10. Status string `description:"合同状态,枚举值:待审批','已审批','已驳回','已撤回',默认待审批"`
  11. ApproveRemark string `description:"审批人备注,可以是驳回理由,长度128位"`
  12. ApproveRoleTypeCode string `description:"审批人角色类型,长度36位"`
  13. ApproveUserId int `description:"审批人id"`
  14. ApproveUserName string `description:"审批人名称"`
  15. NodeId int `description:"当前审批节点id"`
  16. NodeType string `description:"节点类型,审批人:check;抄送人:cc(Carbon Copy)"`
  17. PrevNodeId int `description:"上级节点id"`
  18. NextNodeId int `description:"下级节点id"`
  19. AuditType int `description:"多人审批时,1:或签(一名审批人同意即可),2:会签(需所有审批人同意)"`
  20. ApproveTime time.Time `description:"审批时间"`
  21. ModifyTime time.Time `description:"发起申请时间"`
  22. CreateTime time.Time `description:"最近一次审批单修改时间"`
  23. }
  24. //根据合同审批记录id获取合同流程记录信息
  25. func GetContractApprovalRecordById(contractApprovalRecordId int) (contractApprovalRecordInfo *ContractApprovalRecord, err error) {
  26. o := orm.NewOrm()
  27. sql := `select * from contract_approval_record where contract_approval_record_id = ? `
  28. err = o.Raw(sql, contractApprovalRecordId).QueryRow(&contractApprovalRecordInfo)
  29. return
  30. }
  31. //根据审批单id获取当前待审批的合同审批流信息
  32. func GetCurrContractApprovalRecordByContractId(contractApprovalId int) (contractApprovalRecordInfo *ContractApprovalRecord, err error) {
  33. o := orm.NewOrm()
  34. sql := `select a.* from contract_approval_record a
  35. left join contract_approval b on a.contract_approval_id=b.contract_approval_id and a.node_id=b.curr_node_id
  36. where a.status = "待审批"
  37. AND a.contract_approval_id=? order by a.node_id asc`
  38. err = o.Raw(sql, contractApprovalId).QueryRow(&contractApprovalRecordInfo)
  39. return
  40. }
  41. //根据审批单id和节点id获取当前待审批的合同审批流信息列表
  42. func GetPendingContractApprovalRecordListByContractId(contractApprovalId, nodeId int) (contractApprovalRecordList []*ContractApprovalRecord, err error) {
  43. o := orm.NewOrm()
  44. sql := `select a.* from contract_approval_record a
  45. left join contract_approval b on a.contract_approval_id=b.contract_approval_id
  46. where a.status = "待审批"
  47. AND a.contract_approval_id=? AND node_id >= ? order by a.node_id asc`
  48. _, err = o.Raw(sql, contractApprovalId, nodeId).QueryRows(&contractApprovalRecordList)
  49. return
  50. }
  51. //根据审批单id和节点id获取当前节点的合同审批流信息列表
  52. func GetContractApprovalRecordListByContractIdAndNode(contractApprovalId, nodeId int) (contractApprovalRecordList []*ContractApprovalRecord, err error) {
  53. o := orm.NewOrm()
  54. sql := `select a.* from contract_approval_record a
  55. join contract_approval b on a.contract_approval_id=b.contract_approval_id
  56. where 1=1
  57. AND a.contract_approval_id=? AND node_id = ? order by a.node_id asc`
  58. _, err = o.Raw(sql, contractApprovalId, nodeId).QueryRows(&contractApprovalRecordList)
  59. return
  60. }
  61. //根据审批单id和节点id获取当前节点的合同审批流信息列表
  62. func GetContractApprovalRecordListByContractApprovalId(contractApprovalId int) (contractApprovalRecordList []*ContractApprovalRecord, err error) {
  63. o := orm.NewOrm()
  64. sql := `select a.* from contract_approval_record a
  65. join contract_approval b on a.contract_approval_id=b.contract_approval_id
  66. AND a.contract_approval_id=? AND node_type = "cc" order by a.node_id asc`
  67. _, err = o.Raw(sql, contractApprovalId).QueryRows(&contractApprovalRecordList)
  68. return
  69. }
  70. //根据审批单id获取最近一次待审批的合同审批流信息
  71. func GetLastPendingContractApprovalRecordByContractId(contractApprovalId int) (contractApprovalRecordInfo *ContractApprovalRecord, err error) {
  72. o := orm.NewOrm()
  73. sql := `select * from contract_approval_record where status = "待审批"
  74. AND contract_approval_id=? order by contract_approval_record_id desc`
  75. err = o.Raw(sql, contractApprovalId).QueryRow(&contractApprovalRecordInfo)
  76. return
  77. }
  78. //根据审批单id批量获取最新的审批流列表数据
  79. func GetContractApprovalRecordListOld(contractApprovalIds string) (list []*ContractApprovalRecord, err error) {
  80. o := orm.NewOrm()
  81. sql := `
  82. SELECT
  83. a.* from contract_approval_record a
  84. join
  85. ( SELECT max( contract_approval_record_id ) max_id,contract_approval_id FROM contract_approval_record where contract_approval_id in (` + contractApprovalIds + `) GROUP BY contract_approval_id `
  86. sql += ` ) b on a.contract_approval_record_id=b.max_id
  87. WHERE a.contract_approval_id in (` + contractApprovalIds + `) `
  88. sql += ` order by contract_approval_record_id desc `
  89. _, err = o.Raw(sql).QueryRows(&list)
  90. return
  91. }
  92. func GetContractApprovalRecordList(contractApprovalIds string, approveUserId int) (list []*ContractApprovalRecord, err error) {
  93. o := orm.NewOrm()
  94. sql := `
  95. SELECT
  96. a.* from contract_approval_record a
  97. join contract_approval b on a.contract_approval_id = b.contract_approval_id and a.node_id=b.curr_node_id
  98. WHERE a.contract_approval_id in (` + contractApprovalIds + `) AND (approve_user_id = ? or approve_user_id=0)`
  99. sql += ` order by contract_approval_record_id desc `
  100. _, err = o.Raw(sql, approveUserId).QueryRows(&list)
  101. return
  102. }
  103. // GetContractApprovalRecordListByContractApprovalIds 根据审批单IDs获取审批节点列表
  104. func GetContractApprovalRecordListByContractApprovalIds(contractApprovalIds string) (contractApprovalRecordList []*ContractApprovalRecord, err error) {
  105. o := orm.NewOrm()
  106. sql := `SELECT * FROM contract_approval_record WHERE contract_approval_id IN (` + contractApprovalIds + `)`
  107. _, err = o.Raw(sql).QueryRows(&contractApprovalRecordList)
  108. return
  109. }
  110. // GetApprovalRecordListByApprovalId 获取指定ID审批单下的审批节点列表
  111. func GetApprovalRecordListByApprovalId(contractApprovalId int) (contractApprovalRecordList []*ContractApprovalRecord, err error) {
  112. o := orm.NewOrm()
  113. sql := `select * from contract_approval_record where contract_approval_id=? order by node_id,contract_approval_record_id asc`
  114. _, err = o.Raw(sql, contractApprovalId).QueryRows(&contractApprovalRecordList)
  115. return
  116. }
  117. // GetSelfContractApprovalRecordList 根据审批单id批量获取自己的审批流列表数据
  118. func GetSelfContractApprovalRecordList(contractApprovalIds string, approveUserId int) (list []*ContractApprovalRecord, err error) {
  119. o := orm.NewOrm()
  120. sql := `
  121. SELECT
  122. a.* from contract_approval_record a
  123. join contract_approval b on a.contract_approval_id = b.contract_approval_id
  124. WHERE a.contract_approval_id in (` + contractApprovalIds + `) AND (approve_user_id = ? or approve_user_id=?)
  125. and a.node_id<=b.curr_node_id`
  126. sql += ` order by contract_approval_record_id desc `
  127. _, err = o.Raw(sql, approveUserId, approveUserId).QueryRows(&list)
  128. return
  129. }