knowledge_approve.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package knowledge_approve
  2. import (
  3. "eta_gn/eta_api/global"
  4. "fmt"
  5. "time"
  6. )
  7. type KnowledgeResourceApprove struct {
  8. KnowledgeResourceApproveId int `gorm:"column:knowledge_resource_approve_id;primary_key"`
  9. KnowledgeResourceId int `gorm:"column:knowledge_resource_id"`
  10. KnowledgeResourceTitle string `gorm:"column:knowledge_resource_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 KnowledgeResourceApproveCols = struct {
  25. KnowledgeResourceApproveId string
  26. KnowledgeResourceId string
  27. KnowledgeResourceTitle 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. KnowledgeResourceApproveId: "knowledge_resource_approve_id",
  42. KnowledgeResourceId: "knowledge_resource_id",
  43. KnowledgeResourceTitle: "knowledge_resource_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 KnowledgeResourceApproveItemOrm struct {
  58. KnowledgeResourceApproveId int `description:"审批ID"`
  59. KnowledgeResourceApproveRecordId int `description:"审批记录ID"`
  60. KnowledgeResourceId int `description:"报告ID"`
  61. KnowledgeResourceTitle 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 *KnowledgeResourceApprove) TableName() string {
  80. return "knowledge_resource_approve"
  81. }
  82. func (b *KnowledgeResourceApprove) 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 *KnowledgeResourceApprove) Create() (err error) {
  88. db := global.DmSQL["rddp"]
  89. err = db.Create(b).Error
  90. return
  91. }
  92. func GetKnowledgeResourceApproveByFlowIdAndVersionId(knowledgeFlowId int, flowVersion int) (item []*KnowledgeResourceApprove, err error) {
  93. db := global.DmSQL["rddp"]
  94. err = db.Where("flow_id = ? AND flow_version = ?", knowledgeFlowId, flowVersion).Find(&item).Error
  95. return
  96. }
  97. func GetKnowledgeResourceApproveById(KnowledgeResourceApproveId int) (item *KnowledgeResourceApprove, err error) {
  98. db := global.DmSQL["rddp"]
  99. err = db.Where("knowledge_resource_approve_id = ?", KnowledgeResourceApproveId).First(&item).Error
  100. return
  101. }
  102. // GetApprovingKnowledgeResourceApproveCount 获取待处理的审批分页列表总数
  103. func GetApprovingKnowledgeResourceApproveCount(cond string, pars []interface{}) (count int, err error) {
  104. base := fmt.Sprintf(`SELECT a.knowledge_resource_approve_record_id
  105. FROM knowledge_resource_approve_record AS a
  106. JOIN knowledge_resource_approve AS b ON a.knowledge_resource_approve_id = b.knowledge_resource_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. // GetApprovingKnowledgeResourceApprovePageList 获取待处理的审批列表-分页
  113. func GetApprovingKnowledgeResourceApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*KnowledgeResourceApproveItemOrm, 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.knowledge_resource_approve_record_id, a.state AS record_state, b.*
  119. FROM knowledge_resource_approve_record AS a
  120. JOIN knowledge_resource_approve AS b ON a.knowledge_resource_approve_id = b.knowledge_resource_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. // GetApprovedKnowledgeResourceApproveCount 获取已处理的审批分页列表总数
  128. func GetApprovedKnowledgeResourceApproveCount(cond string, pars []interface{}) (count int, err error) {
  129. base := fmt.Sprintf(`SELECT a.knowledge_resource_approve_record_id
  130. FROM knowledge_resource_approve_record AS a
  131. JOIN knowledge_resource_approve AS b ON a.knowledge_resource_approve_id = b.knowledge_resource_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. // GetApprovedKnowledgeResourceApprovePageList 获取已处理的审批列表-分页
  138. func GetApprovedKnowledgeResourceApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*KnowledgeResourceApproveItemOrm, 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.knowledge_resource_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 knowledge_resource_approve_record AS a
  145. JOIN knowledge_resource_approve AS b ON a.knowledge_resource_approve_id = b.knowledge_resource_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. // GetApplyKnowledgeResourceApproveCount 获取我发起的审批分页列表总数
  153. func GetApplyKnowledgeResourceApproveCount(cond string, pars []interface{}) (count int, err error) {
  154. base := fmt.Sprintf(`SELECT a.* FROM knowledge_resource_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. // GetApplyKnowledgeResourceApprovePageList 获取我发起的审批列表-分页
  160. func GetApplyKnowledgeResourceApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*KnowledgeResourceApproveItemOrm, 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 knowledge_resource_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 GetKnowledgeResourceApproveByBoardId(KnowledgeResourceApproveId int) (item *KnowledgeResourceApprove, err error) {
  171. db := global.DmSQL["rddp"]
  172. err = db.Where("knowledge_resource_id = ?", KnowledgeResourceApproveId).Order("create_time DESC").First(&item).Error
  173. return
  174. }
  175. func GetKnowledgeResourceApproveCountByState(state int) (count int, err error) {
  176. db := global.DmSQL["rddp"]
  177. sql := `SELECT COUNT(*) FROM knowledge_resource_approve WHERE state = ?`
  178. err = db.Raw(sql, state).Scan(&count).Error
  179. return
  180. }