123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package knowledge_approve
- import (
- "eta_gn/eta_api/global"
- "fmt"
- "time"
- )
- type KnowledgeResourceApproveFlow struct {
- KnowledgeResourceApproveFlowId int `gorm:"column:knowledge_resource_approve_flow_id;primaryKey"`
- FlowName string `gorm:"column:flow_name"`
- ClassifyId int `gorm:"column:classify_id"`
- CurrVersion int `gorm:"column:curr_version"`
- CreateTime time.Time `gorm:"column:create_time"`
- ModifyTime time.Time `gorm:"column:modify_time"`
- }
- var KnowledgeResourceApproveFlowCols = struct {
- KnowledgeResourceApproveFlowId string
- FlowName string
- ClassifyId string
- CurrVersion string
- CreateTime string
- ModifyTime string
- }{
- KnowledgeResourceApproveFlowId: "knowledge_resource_approve_flow_id",
- FlowName: "flow_name",
- ClassifyId: "classify_id",
- CurrVersion: "curr_version",
- CreateTime: "create_time",
- ModifyTime: "modify_time",
- }
- func (b *KnowledgeResourceApproveFlow) TableName() string {
- return "knowledge_resource_approve_flow"
- }
- func (b *KnowledgeResourceApproveFlow) Add(node []*KnowledgeResourceApproveNode) (err error) {
- prevNodes := make([]*KnowledgeResourceApproveNode, 0)
- o := global.DmSQL["rddp"].Begin()
- defer func() {
- if err != nil {
- o.Rollback()
- } else {
- o.Commit()
- }
- // 更新每个节点的下一个节点信息, 放在事务中会更新失败
- if e := UpdateNextNodes(prevNodes); e != nil {
- err = fmt.Errorf("UpdatePrevNodes err: %s", e.Error())
- return
- }
- }()
- err = o.Create(b).Error
- if err != nil {
- err = fmt.Errorf("insert approve err: %v", err)
- return
- }
- nodesLen := len(node)
- if nodesLen == 0 {
- return
- }
- prevId := 0
- prevNode := new(KnowledgeResourceApproveNode)
- for k, v := range node {
- v.KnowledgeResourceApproveFlowId = b.KnowledgeResourceApproveFlowId
- v.PrevNodeId = prevId
- err = o.Create(v).Error
- if err != nil {
- err = fmt.Errorf("insert node err: %v", err)
- return
- }
- prevId = v.KnowledgeResourceApproveNodeId
- // 下一个节点
- if prevNode != nil && k > 0 && k < nodesLen {
- prevNode.NextNodeId = v.KnowledgeResourceApproveNodeId
- prevNodes = append(prevNodes, prevNode)
- }
- prevNode = v
- }
- return
- }
- func (b *KnowledgeResourceApproveFlow) Update(cols []string, node []*KnowledgeResourceApproveNode) (err error) {
- prevNodes := make([]*KnowledgeResourceApproveNode, 0)
- o := global.DmSQL["rddp"].Begin()
- defer func() {
- if err != nil {
- o.Rollback()
- } else {
- o.Commit()
- }
- // 更新每个节点的下一个节点信息, 放在事务中会更新失败
- if e := UpdateNextNodes(prevNodes); e != nil {
- err = fmt.Errorf("UpdatePrevNodes err: %s", e.Error())
- return
- }
- }()
- err = o.Model(b).Select(cols).Updates(b).Error
- if err != nil {
- return
- }
- nodesLen := len(node)
- if nodesLen == 0 {
- return
- }
- prevId := 0
- prevNode := new(KnowledgeResourceApproveNode)
- for k, v := range node {
- v.KnowledgeResourceApproveFlowId = b.KnowledgeResourceApproveFlowId
- v.PrevNodeId = prevId
- err = o.Create(v).Error
- if err != nil {
- err = fmt.Errorf("insert node err: %v", err)
- return
- }
- prevId = v.KnowledgeResourceApproveNodeId
- // 下一个节点
- if prevNode != nil && k > 0 && k < nodesLen {
- prevNode.NextNodeId = v.KnowledgeResourceApproveNodeId
- prevNodes = append(prevNodes, prevNode)
- }
- prevNode = v
- }
- return
- }
- func (b *KnowledgeResourceApproveFlow) Delete() error {
- return global.DmSQL["rddp"].Delete(b).Error
- }
- func (m *KnowledgeResourceApproveFlow) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *KnowledgeResourceApproveFlow, err error) {
- order := ``
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s `, m.TableName(), condition, order)
- err = global.DmSQL["rddp"].Raw(sql, pars...).First(&item).Error
- return
- }
- func GetKnowledgeResourceApproveFlowById(KnowledgeResourceApproveFlowId int) (item *KnowledgeResourceApproveFlow, err error) {
- err = global.DmSQL["rddp"].Where("knowledge_resource_approve_flow_id = ?", KnowledgeResourceApproveFlowId).First(&item).Error
- return
- }
- func GetKnowledgeResourceApproveFlowByClassifyId(classifyId int) (item *KnowledgeResourceApproveFlow, err error) {
- err = global.DmSQL["rddp"].Where("classify_id = ?", classifyId).First(&item).Error
- return
- }
- func GetKnowledgeResourceApproveFlowByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*KnowledgeResourceApproveFlow, err error) {
- o := global.DmSQL["rddp"]
- sql := "SELECT * FROM knowledge_resource_approve_flow WHERE 1=1 "
- if condition != "" {
- sql += condition
- }
- sql += " LIMIT ?,?"
- pars = append(pars, startSize, pageSize)
- err = o.Raw(sql, pars...).Scan(&items).Error
- return
- }
- func GetKnowledgeResourceApproveFlowCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := global.DmSQL["rddp"]
- sql := "SELECT COUNT(*) AS count FROM knowledge_resource_approve_flow WHERE 1=1 "
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars...).Scan(&count).Error
- return
- }
- func UpdateFlowClassifyName(classifyId int, classifyName string) (err error) {
- o := global.DmSQL["rddp"]
- err = o.Model(&KnowledgeResourceApproveFlow{}).Where("classify_id = ?", classifyId).Update("classify_name", classifyName).Error
- return
- }
|