jiangshuai
2023-10-17 9e2b19b7336af1e58b7e3861f6cc3a28ad641326
初始化字段补充
3个文件已修改
72 ■■■■■ 已修改文件
model/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/quotationStatus.go 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/saleStage.go 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go
@@ -119,6 +119,8 @@
        NewTimelyRateSearch(),
        NewFaultTypeSearch(),
        NewRepositorySearch(),
        NewSaleStageSearch(),
        //NewQuotationStatusSearch(),
    }
    for _, model := range models {
model/quotationStatus.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -11,7 +12,7 @@
        Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name string `json:"name" gorm:"column:name;type:varchar(255);comment:商机阶段名称"`
    }
    QuotationStatusSearch struct {
        QuotationStatus
        Orm *gorm.DB
@@ -83,3 +84,35 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *QuotationStatusSearch) CreateBatch(records []*QuotationStatus) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *QuotationStatusSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*QuotationStatus{
        //{1, "顺丰"},
        //{2, "德邦"},
        //{3, "中远海运"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/saleStage.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -84,3 +85,37 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *SaleStageSearch) CreateBatch(records []*SaleStage) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *SaleStageSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*SaleStage{
        {1, "初期沟通"},
        {2, "需求分析"},
        {3, "商务谈判"},
        {4, "成功关闭"},
        {4, "成功结案"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}