zhangqian
2023-11-01 530fed8ec225453572d57b15c200ab062c335457
source/menu.go
@@ -1,65 +1,53 @@
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
}
//
//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, ParentId: 0, Path: "", Name: "", Title: "客户管理"},
//      {ID: 2, ParentId: 1, Path: "/client", Name: "", Title: "客户管理"},
//
//      {ID: 3, ParentId: 0, Path: "", Name: "", Title: "销售管理"},
//      {ID: 4, ParentId: 3, Path: "/saleChance", Name: "", Title: "销售机会"},
//
//      {ID: 5, ParentId: 0, Path: "", Name: "", Title: "服务管理"},
//      {ID: 6, ParentId: 5, Path: "/serviceContract", Name: "", Title: "服务合同"},
//
//      {ID: 7, ParentId: 0, Path: "", Name: "", Title: "后台设置"},
//      {ID: 8, ParentId: 7, Path: "/member", Name: "", Title: "成员管理"},
//      {ID: 9, ParentId: 7, Path: "/role", Name: "", Title: "角色管理"},
//   }
//   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
//}