data_approve.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package data_approve
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "time"
  7. )
  8. type DataApprove struct {
  9. DataApproveId int `gorm:"column:data_approve_id;primary_key"`
  10. Title string `gorm:"column:title"`
  11. DataType int `gorm:"column:data_type"`
  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 DataApproveCols = struct {
  25. DataApproveId string
  26. Title string
  27. DataType string // 资产类型:1:指标、2:图表
  28. State string // '审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回'
  29. FlowId string
  30. FlowVersion string
  31. StartNodeId string
  32. CurrNodeId string
  33. ApplyUserId string
  34. ApplyUserName string
  35. ApproveRemark string
  36. ApproveTime string
  37. CreateTime string
  38. ModifyTime string
  39. }{
  40. DataApproveId: "data_approve_id",
  41. Title: "title",
  42. DataType: "data_type",
  43. State: "state",
  44. FlowId: "flow_id",
  45. FlowVersion: "flow_version",
  46. StartNodeId: "start_node_id",
  47. CurrNodeId: "curr_node_id",
  48. ApplyUserId: "apply_user_id",
  49. ApplyUserName: "apply_user_name",
  50. ApproveRemark: "approve_remark",
  51. ApproveTime: "approve_time",
  52. CreateTime: "create_time",
  53. ModifyTime: "modify_time",
  54. }
  55. type DataApproveItemOrm struct {
  56. DataApproveId int `description:"审批ID"`
  57. DataApproveRecordId int `description:"审批记录ID"`
  58. Title string `description:"审批标题"`
  59. DataType int `description:"资产类型"`
  60. State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  61. RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
  62. FlowId int `description:"审批流ID"`
  63. FlowVersion int `description:"审批流版本"`
  64. StartNodeId int `description:"开始节点ID"`
  65. CurrNodeId int `description:"当前节点ID"`
  66. ApplyUserId int `description:"申请人ID"`
  67. ApplyUserName string `description:"申请人姓名"`
  68. ApproveRemark string `description:"审批备注"`
  69. ApproveTime time.Time `description:"审批时间"`
  70. HandleTime time.Time `description:"处理时间"`
  71. CreateTime time.Time `description:"创建时间"`
  72. ModifyTime time.Time `description:"修改时间"`
  73. NodeState int `description:"当前节点审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回" json:"-"`
  74. NodeApproveTime time.Time `description:"当前节点审批时间" json:"-"`
  75. }
  76. func (b *DataApprove) TableName() string {
  77. return "data_approve"
  78. }
  79. func (b *DataApprove) Update(cols []string) (err error) {
  80. db := global.DmSQL["data"]
  81. err = db.Model(b).Select(cols).Updates(b).Error
  82. return
  83. }
  84. func (b *DataApprove) Create() (err error) {
  85. db := global.DmSQL["data"]
  86. err = db.Create(b).Error
  87. return
  88. }
  89. // AddDataApprove
  90. // @Description: 添加审批单
  91. // @author: Roc
  92. // @datetime 2024-12-06 09:46:04
  93. // @param dataApprove *DataApprove
  94. // @param relationList []*DataApproveRelation
  95. // @return err error
  96. func AddDataApprove(dataApprove *DataApprove, relationList []*DataApproveRelation) (err error) {
  97. db := global.DmSQL["data"].Begin()
  98. defer func() {
  99. if err != nil {
  100. db.Rollback()
  101. } else {
  102. db.Commit()
  103. }
  104. }()
  105. err = db.Create(dataApprove).Error
  106. if err != nil {
  107. return
  108. }
  109. if len(relationList) > 0 {
  110. for _, v := range relationList {
  111. v.DataApproveId = dataApprove.DataApproveId
  112. }
  113. err = db.CreateInBatches(relationList, utils.MultiAddNum).Error
  114. if err != nil {
  115. return
  116. }
  117. }
  118. return
  119. }
  120. func GetDataApproveByFlowIdAndVersionId(dataFlowId int, flowVersion int) (item []*DataApprove, err error) {
  121. db := global.DmSQL["data"]
  122. err = db.Where("flow_id = ? AND flow_version = ?", dataFlowId, flowVersion).Find(&item).Error
  123. return
  124. }
  125. func GetDataApproveById(DataApproveId int) (item *DataApprove, err error) {
  126. db := global.DmSQL["data"]
  127. err = db.Where("data_approve_id = ?", DataApproveId).First(&item).Error
  128. return
  129. }
  130. // GetApprovingDataApproveCount 获取待处理的审批分页列表总数
  131. func GetApprovingDataApproveCount(cond string, pars []interface{}) (count int, err error) {
  132. base := fmt.Sprintf(`SELECT a.data_approve_record_id
  133. FROM data_approve_record AS a
  134. JOIN data_approve AS b ON a.data_approve_id = b.data_approve_id AND a.node_id = b.curr_node_id
  135. WHERE 1 = 1 %s`, cond)
  136. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  137. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
  138. return
  139. }
  140. // GetApprovingDataApprovePageList 获取待处理的审批列表-分页
  141. func GetApprovingDataApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*DataApproveItemOrm, err error) {
  142. order := `ORDER BY a.create_time DESC`
  143. if orderRule != "" {
  144. order = ` ORDER BY ` + orderRule
  145. }
  146. sql := fmt.Sprintf(`SELECT a.data_approve_record_id, a.state AS record_state, b.*
  147. FROM data_approve_record AS a
  148. JOIN data_approve AS b ON a.data_approve_id = b.data_approve_id AND a.node_id = b.curr_node_id
  149. WHERE 1 = 1 %s %s
  150. LIMIT ?,?`, cond, order)
  151. pars = append(pars, startSize, pageSize)
  152. err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
  153. return
  154. }
  155. // GetApprovedDataApproveCount 获取已处理的审批分页列表总数
  156. func GetApprovedDataApproveCount(cond string, pars []interface{}) (count int, err error) {
  157. base := fmt.Sprintf(`SELECT a.data_approve_record_id
  158. FROM data_approve_record AS a
  159. JOIN data_approve AS b ON a.data_approve_id = b.data_approve_id
  160. WHERE 1 = 1 %s`, cond)
  161. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  162. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
  163. return
  164. }
  165. // GetApprovedDataApprovePageList 获取已处理的审批列表-分页
  166. func GetApprovedDataApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*DataApproveItemOrm, err error) {
  167. order := `ORDER BY a.create_time DESC`
  168. if orderRule != "" {
  169. order = ` ORDER BY ` + orderRule
  170. }
  171. sql := fmt.Sprintf(`SELECT a.data_approve_record_id, a.node_state AS record_state,a.node_state,a.node_approve_time, a.node_approve_time AS handle_time, b.*
  172. FROM data_approve_record AS a
  173. JOIN data_approve AS b ON a.data_approve_id = b.data_approve_id
  174. WHERE 1 = 1 %s %s
  175. LIMIT ?,?`, cond, order)
  176. pars = append(pars, startSize, pageSize)
  177. err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
  178. return
  179. }
  180. // GetApplyDataApproveCount 获取我发起的审批分页列表总数
  181. func GetApplyDataApproveCount(cond string, pars []interface{}) (count int, err error) {
  182. base := fmt.Sprintf(`SELECT a.* FROM data_approve AS a WHERE 1 = 1 %s`, cond)
  183. sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
  184. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
  185. return
  186. }
  187. // GetApplyDataApprovePageList 获取我发起的审批列表-分页
  188. func GetApplyDataApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*DataApproveItemOrm, err error) {
  189. order := `ORDER BY a.create_time DESC`
  190. if orderRule != "" {
  191. order = ` ORDER BY ` + orderRule
  192. }
  193. sql := fmt.Sprintf(`SELECT a.* FROM data_approve AS a WHERE 1 = 1 %s %s LIMIT ?,?`, cond, order)
  194. pars = append(pars, startSize, pageSize)
  195. err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
  196. return
  197. }
  198. func GetDataApproveCountByState(state int) (count int, err error) {
  199. db := global.DmSQL["data"]
  200. sql := `SELECT COUNT(*) FROM data_approve WHERE state = ?`
  201. err = db.Raw(sql, state).Scan(&count).Error
  202. return
  203. }