report_approve_node.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package report_approve
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "strings"
  8. "time"
  9. )
  10. // ReportApproveNode 报告审批节点表
  11. type ReportApproveNode struct {
  12. ReportApproveNodeId int `orm:"column(report_approve_node_id);pk" description:"报告审批节点ID"`
  13. ReportApproveFlowId int `description:"报告审批流ID"`
  14. PrevNodeId int `description:"上一个节点ID(0为开始节点)"`
  15. NextNodeId int `description:"下一个节点ID(0为结束节点)"`
  16. NodeType int `description:"节点类型:0-审批;1-抄送"`
  17. ApproveType int `description:"审批类型:1-依次审批;2-会签;3-或签"`
  18. Users string `description:"审批人信息-JSON,user_type:user-用户;role-角色,user_id:用户/角色ID"`
  19. CurrVersion int `description:"当前版本号"`
  20. CreateTime time.Time `description:"创建时间"`
  21. }
  22. var ReportApproveNodeCols = struct {
  23. ReportApproveNodeId string
  24. ReportApproveFlowId string
  25. PrevNodeId string
  26. NextNodeId string
  27. NodeType string
  28. ApproveType string
  29. Users string
  30. CurrVersion string
  31. CreateTime string
  32. }{
  33. ReportApproveNodeId: "report_approve_node_id",
  34. ReportApproveFlowId: "report_approve_flow_id",
  35. PrevNodeId: "prev_node_id",
  36. NextNodeId: "next_node_id",
  37. NodeType: "node_type",
  38. ApproveType: "approve_type",
  39. Users: "users",
  40. CurrVersion: "curr_version",
  41. CreateTime: "create_time",
  42. }
  43. func (m *ReportApproveNode) TableName() string {
  44. return "report_approve_node"
  45. }
  46. func (m *ReportApproveNode) PrimaryId() string {
  47. return "report_approve_node_id"
  48. }
  49. func (m *ReportApproveNode) Create() (err error) {
  50. o := orm.NewOrmUsingDB("rddp")
  51. id, err := o.Insert(m)
  52. if err != nil {
  53. return
  54. }
  55. m.ReportApproveNodeId = int(id)
  56. return
  57. }
  58. func (m *ReportApproveNode) CreateMulti(items []*ReportApproveNode) (err error) {
  59. if len(items) == 0 {
  60. return
  61. }
  62. o := orm.NewOrmUsingDB("rddp")
  63. _, err = o.InsertMulti(len(items), items)
  64. return
  65. }
  66. func (m *ReportApproveNode) Update(cols []string) (err error) {
  67. o := orm.NewOrmUsingDB("rddp")
  68. _, err = o.Update(m, cols...)
  69. return
  70. }
  71. func (m *ReportApproveNode) Del() (err error) {
  72. o := orm.NewOrmUsingDB("rddp")
  73. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  74. _, err = o.Raw(sql, m.ReportApproveNodeId).Exec()
  75. return
  76. }
  77. func (m *ReportApproveNode) MultiDel(menuIds []int) (err error) {
  78. if len(menuIds) == 0 {
  79. return
  80. }
  81. o := orm.NewOrmUsingDB("rddp")
  82. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  83. _, err = o.Raw(sql, menuIds).Exec()
  84. return
  85. }
  86. func (m *ReportApproveNode) GetItemById(id int) (item *ReportApproveNode, err error) {
  87. o := orm.NewOrmUsingDB("rddp")
  88. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  89. err = o.Raw(sql, id).QueryRow(&item)
  90. return
  91. }
  92. func (m *ReportApproveNode) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *ReportApproveNode, err error) {
  93. o := orm.NewOrmUsingDB("rddp")
  94. order := ``
  95. if orderRule != "" {
  96. order = ` ORDER BY ` + orderRule
  97. }
  98. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  99. err = o.Raw(sql, pars).QueryRow(&item)
  100. return
  101. }
  102. func (m *ReportApproveNode) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  103. o := orm.NewOrmUsingDB("rddp")
  104. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  105. err = o.Raw(sql, pars).QueryRow(&count)
  106. return
  107. }
  108. func (m *ReportApproveNode) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ReportApproveNode, err error) {
  109. o := orm.NewOrmUsingDB("rddp")
  110. fields := strings.Join(fieldArr, ",")
  111. if len(fieldArr) == 0 {
  112. fields = `*`
  113. }
  114. order := `ORDER BY create_time DESC, report_approve_node_id ASC`
  115. if orderRule != "" {
  116. order = ` ORDER BY ` + orderRule
  117. }
  118. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  119. _, err = o.Raw(sql, pars).QueryRows(&items)
  120. return
  121. }
  122. func (m *ReportApproveNode) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*ReportApproveNode, err error) {
  123. o := orm.NewOrmUsingDB("rddp")
  124. fields := strings.Join(fieldArr, ",")
  125. if len(fieldArr) == 0 {
  126. fields = `*`
  127. }
  128. order := `ORDER BY create_time DESC`
  129. if orderRule != "" {
  130. order = ` ORDER BY ` + orderRule
  131. }
  132. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  133. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  134. return
  135. }
  136. // ReportApproveNodeSaveReq 报告审批节点保存请求体
  137. type ReportApproveNodeSaveReq struct {
  138. ApproveType int `description:"审批类型:1-依次审批;2-会签;3-或签"`
  139. Users []ReportApproveNodeUserReq `description:"审批人信息"`
  140. }
  141. // ReportApproveNodeUserReq 报告审批节点用户请求体
  142. type ReportApproveNodeUserReq struct {
  143. UserType string `description:"审批人类型: user-用户; role-角色"`
  144. UserId int `description:"用户/角色ID"`
  145. UserName string `description:"用户/角色姓名"`
  146. Sort int `description:"排序"`
  147. }
  148. // ReportApproveNodeItem 报告审批节点详情信息
  149. type ReportApproveNodeItem struct {
  150. ReportApproveNodeId int `description:"报告审批节点ID"`
  151. ReportApproveFlowId int `description:"报告审批流ID"`
  152. PrevNodeId int `description:"上一个节点ID(0为开始节点)"`
  153. NextNodeId int `description:"下一个节点ID(0为结束节点)"`
  154. NodeType int `description:"节点类型:0-审批;1-抄送"`
  155. ApproveType int `description:"审批类型:1-依次审批;2-会签;3-或签"`
  156. Users []*ReportApproveNodeUserReq `description:"审批人信息"`
  157. }
  158. // ReportApproveDetailNodes 审批详情-节点信息
  159. type ReportApproveDetailNodes struct {
  160. ReportApproveNodeId int `description:"报告审批节点ID"`
  161. ReportApproveFlowId int `description:"报告审批流ID"`
  162. PrevNodeId int `description:"上一个节点ID(0为开始节点)"`
  163. NextNodeId int `description:"下一个节点ID(0为结束节点)"`
  164. NodeType int `description:"节点类型:0-审批;1-抄送"`
  165. ApproveType int `description:"审批类型:1-依次审批;2-会签;3-或签"`
  166. Users []*ReportApproveDetailNodeUser `description:"审批人信息"`
  167. }
  168. // ReportApproveDetailNodeUser 审批详情-节点用户信息
  169. type ReportApproveDetailNodeUser struct {
  170. ReportApproveNodeUserReq
  171. ApproveRecord *ReportApproveDetailNodeUserRecord `description:"用户审批记录"`
  172. }
  173. // FormatReportApproveNode2Item 格式化报告审批节点信息
  174. func FormatReportApproveNode2Item(origin *ReportApproveNode) (item *ReportApproveNodeItem, err error) {
  175. if origin == nil {
  176. return
  177. }
  178. item = new(ReportApproveNodeItem)
  179. item.ReportApproveNodeId = origin.ReportApproveNodeId
  180. item.ReportApproveFlowId = origin.ReportApproveFlowId
  181. item.PrevNodeId = origin.PrevNodeId
  182. item.NextNodeId = origin.NextNodeId
  183. item.NodeType = origin.NodeType
  184. item.ApproveType = origin.ApproveType
  185. item.Users = make([]*ReportApproveNodeUserReq, 0)
  186. if origin.Users != "" {
  187. e := json.Unmarshal([]byte(origin.Users), &item.Users)
  188. if e != nil {
  189. err = fmt.Errorf("node users unmarshal err: %s", e.Error())
  190. return
  191. }
  192. }
  193. return
  194. }