优化智能气阀生产商关联展示
智能气阀列表改为显示生产商名称,并提供生产商唯一标识复制入口;无关联数据时显示‘未填写’。修复未来 Mock 数据生成时缺少生产商关联的问题,但不执行 Mock、迁移或 SQL,不修改当前数据库及历史数据。补充种子测试、操作日志和项目文档。
This commit is contained in:
@@ -120,6 +120,17 @@ func MockData(database *gorm.DB) error {
|
||||
return err
|
||||
}
|
||||
|
||||
producer := models.ProducerAccount{
|
||||
Entity: entity(49, common.StatusEnable), ProducerCode: "MOCK-PRODUCER-001",
|
||||
Name: "和气示例生产企业", CreditCode: "91310000MOCKPROD01",
|
||||
Principal: "周厂长", Phone: "13600000001", Address: "上海市示例工业路 6 号",
|
||||
Username: "mock_producer_admin", DisplayName: "示例生产管理员",
|
||||
PasswordHash: string(passwordHash), RoleCode: "admin", Remark: "仅用于开发联调",
|
||||
}
|
||||
if err := put(tx, &producer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
enabledAt := yesterday
|
||||
productInfo := models.ProductInfo{
|
||||
Entity: entity(12, common.StatusEnable), Code: "MOCK-CYLINDER-001", Name: "示例液化气钢瓶",
|
||||
@@ -127,6 +138,9 @@ func MockData(database *gorm.DB) error {
|
||||
ProductTypeID: productType.ID, Params: `{"weight":"15kg","medium":"LPG"}`,
|
||||
WarehouseID: warehouse.ID, ProducedAt: now.AddDate(-1, 0, 0), EnabledAt: &enabledAt,
|
||||
}
|
||||
if err := linkMockProductProducer(&productInfo, producer); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := put(tx, &productInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -446,17 +460,6 @@ func MockData(database *gorm.DB) error {
|
||||
return err
|
||||
}
|
||||
|
||||
producer := models.ProducerAccount{
|
||||
Entity: entity(49, common.StatusEnable), ProducerCode: "MOCK-PRODUCER-001",
|
||||
Name: "和气示例生产企业", CreditCode: "91310000MOCKPROD01",
|
||||
Principal: "周厂长", Phone: "13600000001", Address: "上海市示例工业路 6 号",
|
||||
Username: "mock_producer_admin", DisplayName: "示例生产管理员",
|
||||
PasswordHash: string(passwordHash), RoleCode: "admin", Remark: "仅用于开发联调",
|
||||
}
|
||||
if err := put(tx, &producer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
recharge := models.WalletRechargeOrder{
|
||||
Entity: entity(50, common.StatusEnable), RechargeStatus: common.StatusCompleted,
|
||||
WalletBasicID: wallet.ID, RechargeNo: "MOCK-RECHARGE-001",
|
||||
@@ -622,12 +625,27 @@ func seedAdditionalCoreScenarios(database *gorm.DB, passwordHash string, now tim
|
||||
return err
|
||||
}
|
||||
|
||||
producer := models.ProducerAccount{
|
||||
Entity: entity(sequence+20, common.StatusEnable), ProducerCode: "MOCK-PRODUCER-" + suffix,
|
||||
Name: fmt.Sprintf("示例生产企业 %d", scenario), CreditCode: "91310000MOCKPROD" + suffix,
|
||||
Principal: fmt.Sprintf("示例厂长%d", scenario), Phone: "136" + phoneSuffix,
|
||||
Address: fmt.Sprintf("上海市工业路 %d 号", scenario), Username: "mock_producer_" + suffix,
|
||||
DisplayName: fmt.Sprintf("示例生产管理员%d", scenario), PasswordHash: passwordHash,
|
||||
RoleCode: "admin", Remark: "仅用于开发联调",
|
||||
}
|
||||
if err := put(database, &producer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
product := models.ProductInfo{
|
||||
Entity: entity(sequence+9, common.StatusEnable), Code: "MOCK-CYLINDER-" + suffix,
|
||||
Name: fmt.Sprintf("示例智能瓶阀 %d", scenario), ProductStatus: common.StatusInStock,
|
||||
ProductTypeID: productType.ID, Params: `{"source":"mock-data"}`,
|
||||
WarehouseID: warehouse.ID, ProducedAt: now.AddDate(-1, 0, scenario),
|
||||
}
|
||||
if err := linkMockProductProducer(&product, producer); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := put(database, &product); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -734,21 +752,19 @@ func seedAdditionalCoreScenarios(database *gorm.DB, passwordHash string, now tim
|
||||
return err
|
||||
}
|
||||
|
||||
producer := models.ProducerAccount{
|
||||
Entity: entity(sequence+20, common.StatusEnable), ProducerCode: "MOCK-PRODUCER-" + suffix,
|
||||
Name: fmt.Sprintf("示例生产企业 %d", scenario), CreditCode: "91310000MOCKPROD" + suffix,
|
||||
Principal: fmt.Sprintf("示例厂长%d", scenario), Phone: "136" + phoneSuffix,
|
||||
Address: fmt.Sprintf("上海市工业路 %d 号", scenario), Username: "mock_producer_" + suffix,
|
||||
DisplayName: fmt.Sprintf("示例生产管理员%d", scenario), PasswordHash: passwordHash,
|
||||
RoleCode: "admin", Remark: "仅用于开发联调",
|
||||
}
|
||||
if err := put(database, &producer); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// linkMockProductProducer 为未来生成的 Mock 智能气阀建立真实生产商关联。
|
||||
func linkMockProductProducer(product *models.ProductInfo, producer models.ProducerAccount) error {
|
||||
if product == nil || producer.ID == 0 {
|
||||
return errors.New("mock product producer is missing")
|
||||
}
|
||||
product.ProducerAccountID = producer.ID
|
||||
return nil
|
||||
}
|
||||
|
||||
// ensureMockRoot 复用已有 root 账号,仅在账号不存在时写入默认 root 用户。
|
||||
func ensureMockRoot(database *gorm.DB, passwordHash string) error {
|
||||
role := models.PlatformRole{
|
||||
|
||||
Reference in New Issue
Block a user