package console import ( "yunyan/comm" "yunyan/lego/sys/postgres" ) // 应用×服务的「基础设施/运行配置」(app_service_config) 在 console 侧的 CRUD。 // 表结构与 seed/读取逻辑在 comm.AppServiceConfig / comm.LoadOrSeedServiceConfig(业务服务启动时用), // 本文件只做 console 后台的增查改删:列出某(应用,区域,服务)的配置项、按 id 批量删、逐项 upsert。 // listSvcRuntime 列出某(应用,区域,服务)的全部配置项(按 section+sort 稳定排序)。 func (this *modelComp) listSvcRuntime(app, region, service string) (models []*comm.AppServiceConfig, err error) { models = make([]*comm.AppServiceConfig, 0) err = postgres.Table(comm.TableAppServiceConfig). Where("app_name=? AND region=? AND service=?", app, region, service). Order("section ASC, sort ASC, key ASC"). Find(&models).Error return } // listSvcRuntimeServices 列出某(应用,区域)下已有配置的服务类型(去重),供前端标记哪些服务已上报。 func (this *modelComp) listSvcRuntimeServices(app, region string) (services []string, err error) { services = make([]string, 0) err = postgres.Table(comm.TableAppServiceConfig). Where("app_name=? AND region=?", app, region). Distinct("service"). Order("service ASC"). Pluck("service", &services).Error return } // getSvcRuntimeItem 按主键取一项(更新时保留旧密文/建时间用)。 func (this *modelComp) getSvcRuntimeItem(id uint64) (model *comm.AppServiceConfig, err error) { model = &comm.AppServiceConfig{} err = postgres.FindOne(comm.TableAppServiceConfig, model, "id=?", id) return } // addSvcRuntimeItem 新增一项。 func (this *modelComp) addSvcRuntimeItem(model *comm.AppServiceConfig) (err error) { return postgres.Insert(comm.TableAppServiceConfig, model) } // saveSvcRuntimeItem 更新一项(全字段保存)。 func (this *modelComp) saveSvcRuntimeItem(model *comm.AppServiceConfig) (err error) { return postgres.Save(comm.TableAppServiceConfig, model) } // delSvcRuntimeItems 按 id 批量删除。 func (this *modelComp) delSvcRuntimeItems(ids []uint64) (err error) { return postgres.Delete(comm.TableAppServiceConfig, "id IN ?", ids) }