bi_approve.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package biapprove
  2. import (
  3. "eta_gn/eta_api/global"
  4. "fmt"
  5. "time"
  6. )
  7. type BiApprove struct {
  8. BiApproveId int `gorm:"column:bi_approve_id;primary_key"`
  9. BiId int `gorm:"column:bi_id"`
  10. BiTitle string `gorm:"column:bi_title"`
  11. ClassifyId int `gorm:"column:classify_id"`
  12. State int `gorm:"column:state"` // '审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回'
  13. FlowId int `gorm:"column:flow_id"`
  14. FlowVersion int `gorm:"column:flow_version"`
  15. StartNodeId int `gorm:"column:start_node_id"`
  16. CurrNodeId int `gorm:"column:curr_node_id"`
  17. ApplyUserId int `gorm:"column:apply_user_id"`
  18. ApplyUserName string `gorm:"column:apply_user_name"`
  19. ApproveRemark string `gorm:"column:approve_remark"`
  20. ApproveTime time.Time `gorm:"column:approve_time"`
  21. CreateTime time.Time `gorm:"column:create_time"`
  22. ModifyTime time.Time `gorm:"column:update_time"`
  23. }
  24. var BiApproveCols = struct {
  25. BiApproveId string
  26. BiId string
  27. BiTitle string
  28. ClassifyId string
  29. State string // '审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回'
  30. FlowId string
  31. FlowVersion string
  32. StartNodeId string
  33. CurrNodeId string
  34. ApplyUserId string
  35. ApplyUserName string
  36. ApproveRemark string
  37. ApproveTime string
  38. CreateTime string
  39. ModifyTime string
  40. }{
  41. BiApproveId: "bi_approve_id",
  42. BiId: "bi_id",
  43. BiTitle: "bi_title",
  44. ClassifyId: "classify_id",
  45. State: "state",
  46. FlowId: "flow_id",
  47. FlowVersion: "flow_version",
  48. StartNodeId: "start_node_id",
  49. CurrNodeId: "curr_node_id",
  50. ApplyUserId: "apply_user_id",
  51. ApplyUserName: "apply_user_name",
  52. ApproveRemark: "approve_remark",
  53. ApproveTime: "approve_time",
  54. CreateTime: "create_time",
  55. ModifyTime: "modify_time",
  56. }
  57. type BiApproveItemOrm struct {
  58. BiApproveId int `description:"审批ID"`
  59. BiApproveRecordId int `description:"审批记录ID"`
  60. BiId int `description:"报告ID"`
  61. BiTitle string `description:"报告标题"`
  62. ClassifyId int `description:"分类ID"`
  63. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  64. RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
  65. FlowId int `description:"审批流ID"`
  66. FlowVersion int `description:"审批流版本"`
  67. StartNodeId int `description:"开始节点ID"`
  68. CurrNodeId int `description:"当前节点ID"`
  69. ApplyUserId int `description:"申请人ID"`
  70. ApplyUserName string `description:"申请人姓名"`
  71. ApproveRemark string `description:"审批备注"`
  72. ApproveTime time.Time `description:"审批时间"`
  73. HandleTime time.Time `description:"处理时间"`
  74. CreateTime time.Time `description:"创建时间"`
  75. ModifyTime time.Time `description:"修改时间"`
  76. NodeState int `description:"当前节点审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回" json:"-"`
  77. NodeApproveTime time.Time `description:"当前节点审批时间" json:"-"`
  78. }
  79. func (b *BiApprove) TableName() string {
  80. return "bi_approve"
  81. }
  82. func (b *BiApprove) Update(cols []string) (err error) {
  83. db := global.DmSQL["rddp"]
  84. err = db.Model(b).Select(cols).Updates(b).Error
  85. return
  86. }
  87. func (b *BiApprove) Create() (err error) {
  88. db := global.DmSQL["rddp"]
  89. err = db.Create(b).Error
  90. return
  91. }
  92. func GetBiApproveByFlowIdAndVersionId(biFlowId int, flowVersion int) (item []*BiApprove, err error) {
  93. db := global.DmSQL["rddp"]
  94. err = db.Where("flow_id = ? AND flow_version = ?", biFlowId, flowVersion).Find(&item).Error
  95. return
  96. }
  97. func GetBiApproveById(biApproveId int) (item *BiApprove, err error) {
  98. db := global.DmSQL["rddp"]
  99. err = db.Where("bi_approve_id = ?", biApproveId).First(&item).Error
  100. return
  101. }
  102. // GetApprovingBiApproveCount 获取待处理的审批分页列表总数
  103. func GetApprovingBiApproveCount(cond string, pars []interface{}) (count int, err error) {
  104. base := fmt.Sprintf(`SELECT a.bi_approve_record_id
  105. FROM bi_approve_record AS a
  106. JOIN bi_approve AS b ON a.bi_approve_id = b.bi_approve_id AND a.node_id = b.curr_node_id
  107. WHERE 1 = 1 %s`, cond)
  108. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  109. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  110. return
  111. }
  112. // GetApprovingBiApprovePageList 获取待处理的审批列表-分页
  113. func GetApprovingBiApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*BiApproveItemOrm, err error) {
  114. order := `ORDER BY a.create_time DESC`
  115. if orderRule != "" {
  116. order = ` ORDER BY ` + orderRule
  117. }
  118. sql := fmt.Sprintf(`SELECT a.bi_approve_record_id, a.state AS record_state, b.*
  119. FROM bi_approve_record AS a
  120. JOIN bi_approve AS b ON a.bi_approve_id = b.bi_approve_id AND a.node_id = b.curr_node_id
  121. WHERE 1 = 1 %s %s
  122. LIMIT ?,?`, cond, order)
  123. pars = append(pars, startSize, pageSize)
  124. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  125. return
  126. }
  127. // GetApprovedBiApproveCount 获取已处理的审批分页列表总数
  128. func GetApprovedBiApproveCount(cond string, pars []interface{}) (count int, err error) {
  129. base := fmt.Sprintf(`SELECT a.bi_approve_record_id
  130. FROM bi_approve_record AS a
  131. JOIN bi_approve AS b ON a.bi_approve_id = b.bi_approve_id
  132. WHERE 1 = 1 %s`, cond)
  133. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  134. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  135. return
  136. }
  137. // GetApprovedBiApprovePageList 获取已处理的审批列表-分页
  138. func GetApprovedBiApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*BiApproveItemOrm, err error) {
  139. order := `ORDER BY a.create_time DESC`
  140. if orderRule != "" {
  141. order = ` ORDER BY ` + orderRule
  142. }
  143. sql := fmt.Sprintf(`SELECT a.bi_approve_record_id, a.node_state AS record_state,a.node_state,a.node_approve_time, a.node_approve_time AS handle_time, b.*
  144. FROM bi_approve_record AS a
  145. JOIN bi_approve AS b ON a.bi_approve_id = b.bi_approve_id
  146. WHERE 1 = 1 %s %s
  147. LIMIT ?,?`, cond, order)
  148. pars = append(pars, startSize, pageSize)
  149. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  150. return
  151. }
  152. // GetApplyBiApproveCount 获取我发起的审批分页列表总数
  153. func GetApplyBiApproveCount(cond string, pars []interface{}) (count int, err error) {
  154. base := fmt.Sprintf(`SELECT a.* FROM bi_approve AS a WHERE 1 = 1 %s`, cond)
  155. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  156. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  157. return
  158. }
  159. // GetApplyBiApprovePageList 获取我发起的审批列表-分页
  160. func GetApplyBiApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*BiApproveItemOrm, err error) {
  161. order := `ORDER BY a.create_time DESC`
  162. if orderRule != "" {
  163. order = ` ORDER BY ` + orderRule
  164. }
  165. sql := fmt.Sprintf(`SELECT a.* FROM bi_approve AS a WHERE 1 = 1 %s %s LIMIT ?,?`, cond, order)
  166. pars = append(pars, startSize, pageSize)
  167. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  168. return
  169. }
  170. func GetBiApproveByBoardId(biApproveId int) (item *BiApprove, err error) {
  171. db := global.DmSQL["rddp"]
  172. err = db.Where("bi_id = ?", biApproveId).Order("create_time DESC").First(&item).Error
  173. return
  174. }
  175. func GetBiApproveCountByState(state int) (count int, err error) {
  176. db := global.DmSQL["rddp"]
  177. sql := `SELECT COUNT(*) FROM bi_approve WHERE state = ?`
  178. err = db.Raw(sql, state).Scan(&count).Error
  179. return
  180. }