You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
2.1 KiB
53 lines
2.1 KiB
package console
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
"yunyan/lego/sys/mysql"
|
|
)
|
|
|
|
// 应用「业务功能配置」(app_module_config) 的数据访问:直接落到**应用业务库**(由 registry 按 appId 取的连接),
|
|
// 不进 console 公共库。db 句柄可能是 mysql 或 postgres(openDriver 已按 DSN 前缀选驱动,均实现 mysql.ISys)。
|
|
|
|
// ensureModuleConfigTable 幂等在业务库建表(首次访问时调用)。
|
|
func ensureModuleConfigTable(db mysql.ISys) error {
|
|
return db.CreateTable(comm.TableAppModuleConfig, &comm.AppModuleConfig{})
|
|
}
|
|
|
|
// listModuleConfig 列出业务库里的配置项;module 非空则只列该模块,空则全部(按 module+key 稳定排序)。
|
|
func listModuleConfig(db mysql.ISys, module string) (rows []*comm.AppModuleConfig, err error) {
|
|
rows = make([]*comm.AppModuleConfig, 0)
|
|
if module != "" {
|
|
err = db.Find(comm.TableAppModuleConfig, &rows, "module=?", module)
|
|
} else {
|
|
err = db.Find(comm.TableAppModuleConfig, &rows, "")
|
|
}
|
|
return
|
|
}
|
|
|
|
// getModuleConfigItem 按 (module,key) 取一项(更新时保留旧密文/建时间)。不存在返回 (nil,nil)。
|
|
func getModuleConfigItem(db mysql.ISys, module, key string) (*comm.AppModuleConfig, error) {
|
|
m := &comm.AppModuleConfig{}
|
|
// 用 map 条件而非原始字符串:"key" 是 MySQL 保留字,raw where 里 `key=?` 会触发 1064;
|
|
// map 条件让 gorm 按方言自动给列名加引号(MySQL 反引号 / PG 双引号),跨库安全。
|
|
err := db.FindOne(comm.TableAppModuleConfig, m, map[string]interface{}{"module": module, "key": key})
|
|
if err == mysql.ErrNoDocuments {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// upsertModuleConfigItem 按 (module,key) upsert:存在则带 Id 更新,否则新增。
|
|
func upsertModuleConfigItem(db mysql.ISys, m *comm.AppModuleConfig) error {
|
|
if m.Id != 0 {
|
|
return db.Save(comm.TableAppModuleConfig, m)
|
|
}
|
|
return db.Insert(comm.TableAppModuleConfig, m)
|
|
}
|
|
|
|
// delModuleConfig 删除某模块的全部配置项。
|
|
func delModuleConfig(db mysql.ISys, module string) error {
|
|
return db.Delete(comm.TableAppModuleConfig, "module=?", module)
|
|
}
|
|
|