37 lines
1013 B
Go
37 lines
1013 B
Go
package preload
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"bj_power_mes/ent"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
// SeedProcessDict 首次启动时预置 12 道工序字典(Q9 种子数据),后续可在页面维护
|
||
|
|
func SeedProcessDict(entClient *ent.Client) {
|
||
|
|
ctx := context.Background()
|
||
|
|
n, err := entClient.ProcessDict.Query().Count(ctx)
|
||
|
|
if err != nil || n > 0 {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
names := [12]string{
|
||
|
|
"1序 上料", "2序 粗铣", "3序 精铣", "4序 钻孔", "5序 攻丝", "6序 去毛刺",
|
||
|
|
"7序 清洗", "8序 检验", "9序 打标", "10序 装配", "11序 拧紧", "12序 下线",
|
||
|
|
}
|
||
|
|
bulk := make([]*ent.ProcessDictCreate, 0, 12)
|
||
|
|
for i := 1; i <= 12; i++ {
|
||
|
|
bulk = append(bulk, entClient.ProcessDict.Create().
|
||
|
|
SetCode(i).
|
||
|
|
SetName(names[i-1]).
|
||
|
|
SetDescription("").
|
||
|
|
SetSortNum(i).
|
||
|
|
SetEnabled(true))
|
||
|
|
}
|
||
|
|
if _, err = entClient.ProcessDict.CreateBulk(bulk...).Save(ctx); err != nil {
|
||
|
|
logx.Errorf("seed process dict failed: %v", err)
|
||
|
|
} else {
|
||
|
|
logx.Info("seeded default 12 processes")
|
||
|
|
}
|
||
|
|
}
|