123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package biapprove
- import (
- "eta_gn/eta_api/global"
- "fmt"
- "strings"
- "time"
- )
- type BiApproveNode struct {
- BiApproveNodeId int `gorm:"column:bi_approve_node_id;primaryKey"`
- BiApproveFlowId int `gorm:"column:bi_approve_flow_id"`
- PrevNodeId int `gorm:"column:prev_node_id"`
- NextNodeId int `gorm:"column:next_node_id"`
- NodeType int `gorm:"column:node_type"`
- ApproveType int `gorm:"column:approve_type"`
- Users string `gorm:"column:users"`
- CurrVersion int `gorm:"column:curr_version"`
- CreatedTime time.Time `gorm:"column:created_time"`
- }
- var BiApproveNodeCols = struct {
- BiApproveNodeId string
- BiApproveFlowId string
- PrevNodeId string
- NextNodeId string
- NodeType string
- ApproveType string
- Users string
- CurrVersion string
- CreatedTime string
- }{
- BiApproveNodeId: "bi_approve_node_id",
- BiApproveFlowId: "bi_approve_flow_id",
- PrevNodeId: "prev_node_id",
- NextNodeId: "next_node_id",
- NodeType: "node_type",
- ApproveType: "approve_type",
- Users: "users",
- CurrVersion: "curr_version",
- CreatedTime: "created_time",
- }
- func (b *BiApproveNode) TableName() string {
- return "bi_approve_node"
- }
- func (m *BiApproveNode) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BiApproveNode, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY created_time DESC, bi_approve_node_id ASC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
- return
- }
- func UpdateNextNodes(nodes []*BiApproveNode) (err error) {
- if len(nodes) == 0 {
- return
- }
- updateCols := []string{"NextNodeId"}
- for _, v := range nodes {
- e := global.DmSQL["rddp"].Select(updateCols).Updates(v).Error
- if e != nil {
- err = fmt.Errorf("prev node update err: %v", e)
- return
- }
- }
- return
- }
- func GetBiApproveNodeByCondition(condition string, pars []interface{}) (node []*BiApproveNode, err error) {
- o := global.DmSQL["rddp"]
- sql := "SELECT * FROM bi_approve_node WHERE 1=1 "
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars...).Find(&node).Error
- return
- }
- func GetBiApproveNodeByFlowIdAndVersionId(flowId int, versionId int) (node []*BiApproveNode, err error) {
- err = global.DmSQL["rddp"].Model(&BiApproveNode{}).Where("bi_approve_flow_id =? AND curr_version =?", flowId, versionId).Scan(&node).Error
- return
- }
|