mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
feat(settings): 添加基础设置功能- 在数据库中增加更新基础信息和刷新间隔的配置项
- 实现根据配置定时更新数据的功能 - 添加启动时更新基础信息的逻辑 - 更新前端设置界面,增加基础设置选项
This commit is contained in:
parent
a653ef9fa8
commit
a376d1d92c
7
app.go
7
app.go
@ -51,7 +51,12 @@ func (a *App) domReady(ctx context.Context) {
|
|||||||
// Add your action here
|
// Add your action here
|
||||||
//定时更新数据
|
//定时更新数据
|
||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(time.Second * 1)
|
config := data.NewSettingsApi(&data.Settings{}).GetConfig()
|
||||||
|
interval := config.RefreshInterval
|
||||||
|
if interval <= 0 {
|
||||||
|
interval = 1
|
||||||
|
}
|
||||||
|
ticker := time.NewTicker(time.Second * time.Duration(interval))
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
if isTradingTime(time.Now()) {
|
if isTradingTime(time.Now()) {
|
||||||
|
@ -8,9 +8,11 @@ import (
|
|||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
LocalPushEnable bool `json:"localPushEnable"`
|
LocalPushEnable bool `json:"localPushEnable"`
|
||||||
DingPushEnable bool `json:"dingPushEnable"`
|
DingPushEnable bool `json:"dingPushEnable"`
|
||||||
DingRobot string `json:"dingRobot"`
|
DingRobot string `json:"dingRobot"`
|
||||||
|
UpdateBasicInfoOnStart bool `json:"updateBasicInfoOnStart"`
|
||||||
|
RefreshInterval int64 `json:"refreshInterval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver Settings) TableName() string {
|
func (receiver Settings) TableName() string {
|
||||||
@ -32,16 +34,20 @@ func (s SettingsApi) UpdateConfig() string {
|
|||||||
db.Dao.Model(s.Config).Count(&count)
|
db.Dao.Model(s.Config).Count(&count)
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
db.Dao.Model(s.Config).Where("id=?", s.Config.ID).Updates(map[string]any{
|
db.Dao.Model(s.Config).Where("id=?", s.Config.ID).Updates(map[string]any{
|
||||||
"local_push_enable": s.Config.LocalPushEnable,
|
"local_push_enable": s.Config.LocalPushEnable,
|
||||||
"ding_push_enable": s.Config.DingPushEnable,
|
"ding_push_enable": s.Config.DingPushEnable,
|
||||||
"ding_robot": s.Config.DingRobot,
|
"ding_robot": s.Config.DingRobot,
|
||||||
|
"update_basic_info_on_start": s.Config.UpdateBasicInfoOnStart,
|
||||||
|
"refresh_interval": s.Config.RefreshInterval,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
logger.SugaredLogger.Infof("未找到配置,创建默认配置:%+v", s.Config)
|
logger.SugaredLogger.Infof("未找到配置,创建默认配置:%+v", s.Config)
|
||||||
db.Dao.Model(s.Config).Create(&Settings{
|
db.Dao.Model(s.Config).Create(&Settings{
|
||||||
LocalPushEnable: s.Config.LocalPushEnable,
|
LocalPushEnable: s.Config.LocalPushEnable,
|
||||||
DingPushEnable: s.Config.DingPushEnable,
|
DingPushEnable: s.Config.DingPushEnable,
|
||||||
DingRobot: s.Config.DingRobot,
|
DingRobot: s.Config.DingRobot,
|
||||||
|
UpdateBasicInfoOnStart: s.Config.UpdateBasicInfoOnStart,
|
||||||
|
RefreshInterval: s.Config.RefreshInterval,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return "保存成功!"
|
return "保存成功!"
|
||||||
|
@ -8,14 +8,16 @@ const message = useMessage()
|
|||||||
|
|
||||||
const formRef = ref(null)
|
const formRef = ref(null)
|
||||||
const formValue = ref({
|
const formValue = ref({
|
||||||
ID:0,
|
ID:1,
|
||||||
dingPush:{
|
dingPush:{
|
||||||
enable:false,
|
enable:false,
|
||||||
dingRobot: ''
|
dingRobot: ''
|
||||||
},
|
},
|
||||||
localPush:{
|
localPush:{
|
||||||
enable:true,
|
enable:true,
|
||||||
}
|
},
|
||||||
|
updateBasicInfoOnStart:false,
|
||||||
|
refreshInterval:1
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(()=>{
|
onMounted(()=>{
|
||||||
@ -28,6 +30,8 @@ onMounted(()=>{
|
|||||||
formValue.value.localPush = {
|
formValue.value.localPush = {
|
||||||
enable:res.localPushEnable,
|
enable:res.localPushEnable,
|
||||||
}
|
}
|
||||||
|
formValue.value.updateBasicInfoOnStart = res.updateBasicInfoOnStart
|
||||||
|
formValue.value.refreshInterval = res.refreshInterval
|
||||||
console.log(res)
|
console.log(res)
|
||||||
})
|
})
|
||||||
//message.info("加载完成")
|
//message.info("加载完成")
|
||||||
@ -40,9 +44,11 @@ function saveConfig(){
|
|||||||
dingPushEnable:formValue.value.dingPush.enable,
|
dingPushEnable:formValue.value.dingPush.enable,
|
||||||
dingRobot:formValue.value.dingPush.dingRobot,
|
dingRobot:formValue.value.dingPush.dingRobot,
|
||||||
localPushEnable:formValue.value.localPush.enable,
|
localPushEnable:formValue.value.localPush.enable,
|
||||||
|
updateBasicInfoOnStart:formValue.value.updateBasicInfoOnStart,
|
||||||
|
refreshInterval:formValue.value.refreshInterval
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log("Settings",config)
|
//console.log("Settings",config)
|
||||||
UpdateConfig(config).then(res=>{
|
UpdateConfig(config).then(res=>{
|
||||||
message.success(res)
|
message.success(res)
|
||||||
})
|
})
|
||||||
@ -72,30 +78,44 @@ function sendTestNotice(){
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-card title="推送设置" style="height: 100%;">
|
<n-flex justify="left" style="margin-top: 12px;padding-left: 12px">
|
||||||
<n-form ref="formRef" :model="formValue" :label-placement="'left'" :label-align="'left'">
|
<n-form ref="formRef" :model="formValue" :label-placement="'left'" :label-align="'left'" style="width: 100%;height: 100%">
|
||||||
<n-grid :cols="24" :x-gap="24">
|
<n-grid :cols="24" :x-gap="24" style="text-align: left">
|
||||||
<n-form-item-gi :span="12" label="是否启用钉钉推送:" path="dingPush.enable" >
|
<n-gi :span="24">
|
||||||
<n-switch v-model:value="formValue.dingPush.enable" />
|
<n-text type="default" style="font-size: 25px;font-weight: bold">基础设置</n-text>
|
||||||
</n-form-item-gi>
|
</n-gi>
|
||||||
<n-form-item-gi :span="12" label="是否启用本地推送:" path="localPush.enable" >
|
<n-form-item-gi :span="6" label="启动时更新A股/指数信息:" path="updateBasicInfoOnStart" >
|
||||||
<n-switch v-model:value="formValue.localPush.enable" />
|
<n-switch v-model:value="formValue.updateBasicInfoOnStart" />
|
||||||
</n-form-item-gi>
|
</n-form-item-gi>
|
||||||
<n-form-item-gi :span="24" v-if="formValue.dingPush.enable" label="钉钉机器人接口地址:" path="dingPush.dingRobot" >
|
<n-form-item-gi :span="6" label="数据刷新间隔(重启生效):" path="refreshInterval" >
|
||||||
<n-input placeholder="请输入钉钉机器人接口地址" v-model:value="formValue.dingPush.dingRobot"/>
|
<n-input-number v-model:value="formValue.refreshInterval" />
|
||||||
<n-button type="primary" @click="sendTestNotice">发送测试通知</n-button>
|
</n-form-item-gi>
|
||||||
</n-form-item-gi>
|
</n-grid>
|
||||||
<n-gi :span="24">
|
|
||||||
<div style="display: flex; justify-content: flex-end">
|
|
||||||
<n-button round type="primary" @click="saveConfig">
|
|
||||||
保存
|
|
||||||
</n-button>
|
|
||||||
</div>
|
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
</n-form>
|
|
||||||
</n-card>
|
|
||||||
|
|
||||||
|
<n-grid :cols="24" :x-gap="24" style="text-align: left">
|
||||||
|
<n-gi :span="24">
|
||||||
|
<n-text type="default" style="font-size: 25px;font-weight: bold">通知设置</n-text>
|
||||||
|
</n-gi>
|
||||||
|
<n-form-item-gi :span="6" label="是否启用钉钉推送:" path="dingPush.enable" >
|
||||||
|
<n-switch v-model:value="formValue.dingPush.enable" />
|
||||||
|
</n-form-item-gi>
|
||||||
|
<n-form-item-gi :span="6" label="是否启用本地推送:" path="localPush.enable" >
|
||||||
|
<n-switch v-model:value="formValue.localPush.enable" />
|
||||||
|
</n-form-item-gi>
|
||||||
|
<n-form-item-gi :span="24" v-if="formValue.dingPush.enable" label="钉钉机器人接口地址:" path="dingPush.dingRobot" >
|
||||||
|
<n-input placeholder="请输入钉钉机器人接口地址" v-model:value="formValue.dingPush.dingRobot"/>
|
||||||
|
<n-button type="primary" @click="sendTestNotice">发送测试通知</n-button>
|
||||||
|
</n-form-item-gi>
|
||||||
|
</n-grid>
|
||||||
|
<n-gi :span="24">
|
||||||
|
<div style="display: flex; justify-content: center">
|
||||||
|
<n-button type="primary" @click="saveConfig">
|
||||||
|
保存
|
||||||
|
</n-button>
|
||||||
|
</div>
|
||||||
|
</n-gi>
|
||||||
|
</n-form>
|
||||||
|
</n-flex>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
@ -64,6 +64,8 @@ export namespace data {
|
|||||||
localPushEnable: boolean;
|
localPushEnable: boolean;
|
||||||
dingPushEnable: boolean;
|
dingPushEnable: boolean;
|
||||||
dingRobot: string;
|
dingRobot: string;
|
||||||
|
updateBasicInfoOnStart: boolean;
|
||||||
|
refreshInterval: number;
|
||||||
|
|
||||||
static createFrom(source: any = {}) {
|
static createFrom(source: any = {}) {
|
||||||
return new Settings(source);
|
return new Settings(source);
|
||||||
@ -78,6 +80,8 @@ export namespace data {
|
|||||||
this.localPushEnable = source["localPushEnable"];
|
this.localPushEnable = source["localPushEnable"];
|
||||||
this.dingPushEnable = source["dingPushEnable"];
|
this.dingPushEnable = source["dingPushEnable"];
|
||||||
this.dingRobot = source["dingRobot"];
|
this.dingRobot = source["dingRobot"];
|
||||||
|
this.updateBasicInfoOnStart = source["updateBasicInfoOnStart"];
|
||||||
|
this.refreshInterval = source["refreshInterval"];
|
||||||
}
|
}
|
||||||
|
|
||||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||||
|
11
main.go
11
main.go
@ -45,7 +45,7 @@ func main() {
|
|||||||
if stocksBin != nil && len(stocksBin) > 0 {
|
if stocksBin != nil && len(stocksBin) > 0 {
|
||||||
go initStockData()
|
go initStockData()
|
||||||
}
|
}
|
||||||
//updateBasicInfo()
|
updateBasicInfo()
|
||||||
|
|
||||||
// Create an instance of the app structure
|
// Create an instance of the app structure
|
||||||
app := NewApp()
|
app := NewApp()
|
||||||
@ -142,9 +142,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateBasicInfo() {
|
func updateBasicInfo() {
|
||||||
//更新基本信息
|
config := data.NewSettingsApi(&data.Settings{}).GetConfig()
|
||||||
go data.NewStockDataApi().GetStockBaseInfo()
|
if config.UpdateBasicInfoOnStart {
|
||||||
go data.NewStockDataApi().GetIndexBasic()
|
//更新基本信息
|
||||||
|
go data.NewStockDataApi().GetStockBaseInfo()
|
||||||
|
go data.NewStockDataApi().GetIndexBasic()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initStockData() {
|
func initStockData() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user