1. 通用优化: - 统一系统标题为"库房客户端"/"MES产线控制",移除北自所前缀 - 调整内置账号密码为统一123456,优化密码校验逻辑 - 新增数据库自动创建逻辑,简化部署流程 - 修复日志时间格式配置,优化日志输出 - 新增纯数字密码安全提示 2. MES系统优化: - 新增日排产管理功能,支持增删改查与自动算料生成备料单 - 重构BOM模块,改为按产品编码维护而非工单维度 - 新增工艺参数模板配置与手动报工页面 - 新增产品类型自动编码功能 - 优化菜单结构,调整工单管理、扫码报工等页面名称与路由 - 新增删除日排产接口与权限保护 - 修复物料清单查询逻辑,适配新BOM结构 - 新增refreshToken支持,优化登录会话管理 3. WMS系统优化: - 新增基础数据维护页面,支持区域与物料档案管理 - 新增工单列表下拉接口,对接MES获取未完成工单优先展示 - 优化入库管理提示文案,替换英文提示为中文 - 修复精密件入库校验逻辑,优化错误提示 - 优化Excel导入功能,新增备注字段支持 - 优化登录页面与菜单文案,统一备料台账名称 - 新增自动打开浏览器功能,优化客户端启动体验 - 修复备料出库页面查询提示文案 - 新增WMS与MES对接配置,完善内部API调用逻辑 4. 其他优化: - 删除冗余的旧版静态资源文件,更新资源引用路径 - 新增帮助文档,完善基础数据模块说明 - 修复多处文案不统一、英文残留问题
101 lines
3.7 KiB
Go
101 lines
3.7 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"bj_power_mes/ent/permission"
|
|
"bj_power_mes/ent/processstep"
|
|
"bj_power_mes/ent/role"
|
|
"bj_power_mes/ent/stationprocess"
|
|
"bj_power_mes/ent/user"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
// Seed 初始化:超级管理员、默认角色、默认菜单权限、12 道工序与工位派工
|
|
func (s *Service) Seed(ctx context.Context) error {
|
|
// 1. 默认角色
|
|
roles := []struct{ name, code string }{
|
|
{"超级管理员", "SUPER_ADMIN"},
|
|
{"生产操作员", "OPERATOR"},
|
|
{"质检员", "INSPECTOR"},
|
|
}
|
|
for _, r := range roles {
|
|
if s.ctx.EntClient.Role.Query().Where(role.Code(r.code)).ExistX(ctx) {
|
|
continue
|
|
}
|
|
codes := []string{"*"}
|
|
if r.code == "OPERATOR" {
|
|
codes = []string{"produce.workorder", "produce.bom", "produce.material", "produce.scan", "produce.trace", "produce.torque", "produce.plc", "produce.product"}
|
|
} else if r.code == "INSPECTOR" {
|
|
codes = []string{"produce.trace", "produce.torque", "sys.eventlog"}
|
|
}
|
|
_ = s.ctx.EntClient.Role.Create().SetName(r.name).SetCode(r.code).SetPermissionCodes(codes).Exec(ctx)
|
|
}
|
|
|
|
// 2. 超级管理员账号 admin / 123456(对已存在的旧行做对齐,避免残留禁用状态)
|
|
hash, _ := bcrypt.GenerateFromPassword([]byte("123456"), bcrypt.DefaultCost)
|
|
adminRole, _ := s.ctx.EntClient.Role.Query().Where(role.Code("SUPER_ADMIN")).First(ctx)
|
|
roleId := 0
|
|
if adminRole != nil {
|
|
roleId = adminRole.ID
|
|
}
|
|
if s.ctx.EntClient.User.Query().Where(user.Username("admin")).ExistX(ctx) {
|
|
_ = s.ctx.EntClient.User.Update().
|
|
Where(user.Username("admin")).
|
|
SetPassword(string(hash)).SetStatus("ENABLED").SetRoleId(roleId).Exec(ctx)
|
|
} else {
|
|
_ = s.ctx.EntClient.User.Create().
|
|
SetUsername("admin").SetPassword(string(hash)).SetName("系统管理员").
|
|
SetRoleId(roleId).SetStatus("ENABLED").Exec(ctx)
|
|
}
|
|
|
|
// 3. 默认菜单权限
|
|
menus := []struct{ code, name, typ, path string }{
|
|
{"produce.workorder", "工单管理", "MENU", "/work-order"},
|
|
{"produce.bom", "BOM", "MENU", "/bom"},
|
|
{"produce.material", "备料单", "MENU", "/material-request"},
|
|
{"produce.plc", "PLC工序下发", "MENU", "/plc-send"},
|
|
{"produce.torque", "拧紧查询", "MENU", "/torque"},
|
|
{"produce.scan", "扫码报工", "MENU", "/scan"},
|
|
{"produce.trace", "工件追溯", "MENU", "/trace"},
|
|
{"produce.product", "产品类型", "MENU", "/product-type"},
|
|
{"sys.eventlog", "操作日志", "MENU", "/event-log"},
|
|
{"sys.rbac", "角色权限管理", "MENU", "/rbac"},
|
|
}
|
|
for _, m := range menus {
|
|
if s.ctx.EntClient.Permission.Query().Where(permission.Code(m.code)).ExistX(ctx) {
|
|
continue
|
|
}
|
|
_ = s.ctx.EntClient.Permission.Create().
|
|
SetCode(m.code).SetName(m.name).SetType(m.typ).SetPath(m.path).Exec(ctx)
|
|
}
|
|
|
|
// 4. 12 道工序步骤模板(每道工序一个"装配完成"步骤 + 拧紧台阶步骤)
|
|
seedProcessSteps(ctx, s)
|
|
// 5. 12 工位 ↔ 工序 派工(工位N 默认做工序N)
|
|
for i := 1; i <= 12; i++ {
|
|
if s.ctx.EntClient.StationProcess.Query().Where(stationprocess.StationNo(i), stationprocess.ProcessCode(i)).ExistX(ctx) {
|
|
continue
|
|
}
|
|
_ = s.ctx.EntClient.StationProcess.Create().
|
|
SetStationNo(i).SetProcessCode(i).SetEffectDate("").Exec(ctx)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func seedProcessSteps(ctx context.Context, s *Service) {
|
|
for i := 1; i <= 12; i++ {
|
|
cnt, _ := s.ctx.EntClient.ProcessStep.Query().Where(processstep.ProcessCode(i)).Count(ctx)
|
|
if cnt > 0 {
|
|
continue
|
|
}
|
|
_ = s.ctx.EntClient.ProcessStep.Create().
|
|
SetProcessCode(i).SetSeq(1).SetName("装配完成").SetCollectType("NONE").Exec(ctx)
|
|
if i == 3 { // 示例:工序3 增加一个拧紧采集步骤
|
|
_ = s.ctx.EntClient.ProcessStep.Create().
|
|
SetProcessCode(3).SetSeq(2).SetName("拧紧扭矩").SetCollectType("AUTO").SetIsTorque(true).Exec(ctx)
|
|
}
|
|
}
|
|
}
|