wangpengfei
2023-07-04 1142bc88cebcfedac1617749bc195a2615799518
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package system
 
import (
    "aps_crm/model"
    "aps_crm/pkg/logx"
    "aps_crm/service"
    "context"
    "github.com/pkg/errors"
    "gorm.io/gorm"
)
 
type initMenu struct{}
 
// auto run
func init() {
    service.RegisterInit(initMenuSequence, &initMenu{})
}
 
func (i initMenu) InitializerName() string {
    return model.Menu{}.TableName()
}
 
func (i *initMenu) InitializeData(ctx context.Context) (next context.Context, err error) {
    entities := []*model.Menu{
        {ID: 1, Hidden: false, ParentId: 0, Path: "", Name: "", Title: "车间管理", Sort: 1, Icon: "home", Type: 0},
        {ID: 2, Hidden: false, ParentId: 1, Path: "/facilty", Name: "", Title: "设备管理", Sort: 2, Icon: "object-ungroup", Type: 1},
        {ID: 3, Hidden: false, ParentId: 1, Path: "/faciltyResource", Name: "", Title: "设备资源", Sort: 3, Icon: "object-group", Type: 1},
        {ID: 4, Hidden: false, ParentId: 1, Path: "/oricedureDiagram", Name: "", Title: "设备工序图", Sort: 4, Icon: "object-group", Type: 1},
 
        {ID: 5, Hidden: false, ParentId: 0, Path: "", Name: "", Title: "生产计划", Sort: 5, Icon: "paper-plane", Type: 0},
        {ID: 6, Hidden: false, ParentId: 5, Path: "/orderManagement", Name: "", Title: "订单管理", Sort: 6, Icon: "files-o", Type: 1},
        {ID: 7, Hidden: false, ParentId: 5, Path: "/plannedProduction", Name: "", Title: "计划生产", Sort: 7, Icon: "", Type: 1},
        {ID: 8, Hidden: false, ParentId: 5, Path: "/Scheduling", Name: "", Title: "生产排程", Sort: 8, Icon: "delicious", Type: 1},
        {ID: 9, Hidden: false, ParentId: 5, Path: "/productionProcess", Name: "", Title: "生产工序表", Sort: 9, Icon: "", Type: 1},
 
        {ID: 10, Hidden: false, ParentId: 0, Path: "", Name: "", Title: "基础数据", Sort: 10, Icon: "database", Type: 0},
        {ID: 11, Hidden: false, ParentId: 10, Path: "/inventory", Name: "", Title: "BOM管理", Sort: 11, Icon: "film", Type: 1},
        {ID: 12, Hidden: false, ParentId: 10, Path: "/bomCraft", Name: "", Title: "产品/工序", Sort: 12, Icon: "sliders", Type: 1},
        {ID: 13, Hidden: false, ParentId: 10, Path: "/humanResource", Name: "", Title: "人力资源", Sort: 13, Icon: "", Type: 1},
        {ID: 14, Hidden: false, ParentId: 10, Path: "/calendar", Name: "", Title: "生产日历", Sort: 14, Icon: "user", Type: 1},
        {ID: 15, Hidden: false, ParentId: 10, Path: "/abilityModel", Name: "", Title: "模板管理", Sort: 15, Icon: "connectdevelop", Type: 1},
        {ID: 16, Hidden: false, ParentId: 10, Path: "/mouldManagement", Name: "", Title: "模具管理", Sort: 16, Icon: "", Type: 1},
        {ID: 17, Hidden: false, ParentId: 10, Path: "/gauge", Name: "", Title: "检具管理", Sort: 17, Icon: "", Type: 1},
        {ID: 18, Hidden: false, ParentId: 10, Path: "/transportation", Name: "", Title: "规范管理", Sort: 18, Icon: "", Type: 1},
        {ID: 19, Hidden: false, ParentId: 10, Path: "/proccessModel", Name: "", Title: "工艺模型", Sort: 19, Icon: "", Type: 1},
        {ID: 20, Hidden: false, ParentId: 10, Path: "/dictionary", Name: "", Title: "数据配置", Sort: 20, Icon: "", Type: 1},
 
        {ID: 21, Hidden: false, ParentId: 0, Path: "", Name: "", Title: "系统设置", Sort: 21, Icon: "database", Type: 0},
        {ID: 22, Hidden: false, ParentId: 21, Path: "/system/userManage", Name: "", Title: "管理员管理", Sort: 22, Icon: "film", Type: 1},
    }
    if err = model.NewMenuSearch(nil).CreateBatch(entities); err != nil {
        return ctx, errors.Wrap(err, i.InitializerName()+"表数据初始化失败!")
    }
    next = context.WithValue(ctx, i.InitializerName(), entities)
    logx.Infof("InitializeData success initName:%v", i.InitializerName())
    return next, nil
}
 
func (i *initMenu) DataInserted(ctx context.Context) bool {
    _, err := model.NewMenuSearch(nil).SetId(22).First()
    if errors.Is(err, gorm.ErrRecordNotFound) { // 判断是否存在数据
        return false
    }
    return true
}