瀏覽代碼

feat: 地图续扫提醒

HeWang 8 月之前
父節點
當前提交
47fd1fe831

+ 44 - 0
biz/dal/mysql/map_update.go

@@ -6,6 +6,7 @@ import (
 	"gorm.io/gen"
 	"pji_desktop_http/biz/dal/query"
 	"pji_desktop_http/biz/model"
+	"pji_desktop_http/common/config"
 )
 
 func AddMapUpdateOneRecord(ctx context.Context, record model.MapUpdate) error {
@@ -63,3 +64,46 @@ func QueryMapUpdateRecords(ctx context.Context, record *model.MapUpdate, pageFla
 	fmt.Println("Query map update records successfully:", len(records))
 	return records, count, err
 }
+
+func QueryMapUpdateRecordsByRescanFlag(ctx context.Context, flag int32) ([]*model.MapUpdate, error) {
+	r := query.MapUpdate
+
+	var records []*model.MapUpdate
+	records, err := r.WithContext(ctx).Where(r.RescanNotifyFlag.Eq(flag)).Find()
+	if err != nil {
+		return records, err
+	}
+
+	fmt.Println("Query map update records successfully:", len(records))
+	return records, err
+}
+
+func QueryMapRescanList(ctx context.Context, record *model.MapUpdate, pageFlag bool, page, pageSize int) ([]*model.MapUpdate, int64, error) {
+	r := query.MapUpdate
+	q := r.WithContext(ctx)
+	var records []*model.MapUpdate
+	var count int64
+	var err error
+	q = q.Where(r.RescanNotifyFlag.Eq(config.MAP_RESCAN_FLAG))
+	if record.DeviceName != "" {
+		q = q.Where(r.DeviceName.Like("%" + record.DeviceName + "%"))
+	}
+	if record.DeviceType != "" {
+		q = q.Where(r.DeviceType.Eq(record.DeviceType))
+	}
+
+	if pageFlag {
+		offset := (page - 1) * pageSize
+		records, count, err = q.Order(r.UpdateTime.Desc()).FindByPage(offset, pageSize)
+	} else {
+		records, err = q.Order(r.UpdateTime.Desc()).Find()
+	}
+
+	if err != nil {
+		fmt.Println("Query map rescan records failed:", err.Error())
+		return nil, 0, err
+	}
+
+	fmt.Println("Query map rescan records successfully:", len(records))
+	return records, count, err
+}

+ 31 - 23
biz/dal/query/map_update.gen.go

@@ -48,6 +48,8 @@ func newMapUpdate(db *gorm.DB, opts ...gen.DOOption) mapUpdate {
 	_mapUpdate.UpdateMapURL = field.NewString(tableName, "update_map_url")
 	_mapUpdate.UploadVersion = field.NewString(tableName, "upload_version")
 	_mapUpdate.UploadedAt = field.NewTime(tableName, "uploaded_at")
+	_mapUpdate.RescanNotifyFlag = field.NewInt32(tableName, "rescan_notify_flag")
+	_mapUpdate.RescanNotifyThreshold = field.NewString(tableName, "rescan_notify_threshold")
 
 	_mapUpdate.fillFieldMap()
 
@@ -57,28 +59,30 @@ func newMapUpdate(db *gorm.DB, opts ...gen.DOOption) mapUpdate {
 type mapUpdate struct {
 	mapUpdateDo mapUpdateDo
 
-	ALL                  field.Asterisk
-	ID                   field.String
-	MapID                field.String
-	DeviceID             field.String
-	DeviceSn             field.String
-	DeviceName           field.String
-	DeviceType           field.String
-	PrePgmURL            field.String
-	CurrentPgmURL        field.String
-	PrePngURL            field.String
-	CurrentPngURL        field.String
-	UpdateRate           field.String
-	CumulativeUpdateRate field.String
-	UpdateTime           field.String
-	FromSceneList        field.String
-	UpdateFlag           field.Int32
-	CreatedAt            field.Time
-	UpdatedAt            field.Time
-	DeletedAt            field.Field
-	UpdateMapURL         field.String
-	UploadVersion        field.String
-	UploadedAt           field.Time
+	ALL                   field.Asterisk
+	ID                    field.String
+	MapID                 field.String
+	DeviceID              field.String
+	DeviceSn              field.String
+	DeviceName            field.String
+	DeviceType            field.String
+	PrePgmURL             field.String
+	CurrentPgmURL         field.String
+	PrePngURL             field.String
+	CurrentPngURL         field.String
+	UpdateRate            field.String
+	CumulativeUpdateRate  field.String
+	UpdateTime            field.String
+	FromSceneList         field.String
+	UpdateFlag            field.Int32
+	CreatedAt             field.Time
+	UpdatedAt             field.Time
+	DeletedAt             field.Field
+	UpdateMapURL          field.String
+	UploadVersion         field.String
+	UploadedAt            field.Time
+	RescanNotifyFlag      field.Int32
+	RescanNotifyThreshold field.String
 
 	fieldMap map[string]field.Expr
 }
@@ -116,6 +120,8 @@ func (m *mapUpdate) updateTableName(table string) *mapUpdate {
 	m.UpdateMapURL = field.NewString(table, "update_map_url")
 	m.UploadVersion = field.NewString(table, "upload_version")
 	m.UploadedAt = field.NewTime(table, "uploaded_at")
+	m.RescanNotifyFlag = field.NewInt32(table, "rescan_notify_flag")
+	m.RescanNotifyThreshold = field.NewString(table, "rescan_notify_threshold")
 
 	m.fillFieldMap()
 
@@ -142,7 +148,7 @@ func (m *mapUpdate) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
 }
 
 func (m *mapUpdate) fillFieldMap() {
-	m.fieldMap = make(map[string]field.Expr, 21)
+	m.fieldMap = make(map[string]field.Expr, 23)
 	m.fieldMap["id"] = m.ID
 	m.fieldMap["map_id"] = m.MapID
 	m.fieldMap["device_id"] = m.DeviceID
@@ -164,6 +170,8 @@ func (m *mapUpdate) fillFieldMap() {
 	m.fieldMap["update_map_url"] = m.UpdateMapURL
 	m.fieldMap["upload_version"] = m.UploadVersion
 	m.fieldMap["uploaded_at"] = m.UploadedAt
+	m.fieldMap["rescan_notify_flag"] = m.RescanNotifyFlag
+	m.fieldMap["rescan_notify_threshold"] = m.RescanNotifyThreshold
 }
 
 func (m mapUpdate) clone(db *gorm.DB) mapUpdate {

+ 3 - 3
biz/handler/config_service/config_service.go

@@ -13,12 +13,12 @@ import (
 // QueryRescanReminderThreshold 查询续扫阈值
 // @router /config/query/rescanReminderThreshold [GET]
 func QueryRescanReminderThreshold(ctx context.Context, c *app.RequestContext) {
-	config, err := mysql.QuerySystemConfig(ctx)
+	systemConfig, err := mysql.QuerySystemConfig(ctx)
 	if err != nil {
-		c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "1002", Message: "获取系统配置失败"})
+		c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取系统配置失败"})
 		return
 	}
-	c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "获取续扫阈值成功", Data: strconv.FormatFloat(float64(config.RescanReminderThreshold), 'f', 2, 32)})
+	c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "获取续扫阈值成功", Data: strconv.FormatFloat(float64(systemConfig.RescanReminderThreshold), 'f', 2, 32)})
 }
 
 // UpdateRescanReminderThreshold 更新续扫阈值

+ 192 - 0
biz/handler/map_service/map_service.go

@@ -924,6 +924,198 @@ func UploadPjiMapAndNotify(ctx context.Context, c *app.RequestContext) {
 
 }
 
+// AddMapRescanNotifyWithHttp 查询累积地图更新率低于续扫阈值的记录,并通知运维人员
+// @router /map/rescan/notify/add [GET]
+func AddMapRescanNotifyWithHttp(ctx context.Context, c *app.RequestContext) {
+	// 查询朴津地图列表
+	mapInfoList, err := getMapInfoList()
+	if err != nil || mapInfoList == nil {
+		c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取地图列表数据失败"})
+		return
+	}
+
+	// 查询地图续扫阈值
+	systemConfig, err := mysql.QuerySystemConfig(ctx)
+	if err != nil {
+		c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取系统配置失败"})
+		return
+	}
+	threshold := systemConfig.RescanReminderThreshold
+
+	fmt.Println("threshold", threshold)
+	// 查询地图更新表中未发送续扫提醒通知的记录(续扫提醒标志为0)
+	mapUpdates, err := mysql.QueryMapUpdateRecordsByRescanFlag(ctx, config.MAP_NOT_RESCAN_FLAG)
+	if err != nil {
+		c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询地图更新列表失败"})
+		return
+	}
+	// 记录已发送通知的地图id
+	// 对于同一地图id的多个符合续扫通知提醒的记录,只允许发送一次续扫通知,但相关记录均会被标记为已发送续扫提醒
+	mapIdList := make(map[string]bool)
+
+	for _, mapUpdate := range mapUpdates {
+		// 查询地图id是否存在于地图列表中
+		exist, record := checkMapIdExist(mapUpdate.MapID, mapInfoList)
+		fmt.Println("exist", exist)
+		fmt.Println("record", record)
+		if !exist {
+			fmt.Println("地图列表中不存在该地图id,跳过...")
+			continue
+		}
+		//fmt.Println("mapUpdate", mapUpdate)
+		updatePercentage, err := getUpdatePercentage(mapUpdate.CumulativeUpdateRate)
+		if err != nil {
+			c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: err.Error()})
+		}
+		fmt.Println("updatePercentage", updatePercentage)
+
+		if updatePercentage >= threshold {
+			mapId := mapUpdate.MapID
+			if _, exits := mapIdList[mapId]; !exits {
+				// 发送续扫通知
+				paramMap := make(map[string]interface{})
+				paramMap["mapId"] = mapId
+				paramMap["type"] = "1" // 0代表修图通知,1代表续扫通知
+				paramMap["customAreaId"] = record.CustomAreaId
+				resp, err := pji_client.ApiClient.JsonPostRequest(c_pji.PjiApiSitBaseUrl+"sendMsg", paramMap, pji_client.MapSecretId)
+				if err != nil {
+					continue
+				}
+				fmt.Println(string(resp.Body()))
+				mapIdList[mapId] = true
+			}
+			// 修改续扫提醒标志
+			mapUpdate.RescanNotifyFlag = config.MAP_RESCAN_FLAG
+			thresholdStr := strconv.FormatFloat(float64(threshold), 'f', 2, 32) + "%"
+			fmt.Println("thresholdStr", thresholdStr)
+			mapUpdate.RescanNotifyThreshold = &thresholdStr
+			_, err := mysql.UpdateMapUpdateOneRecord(ctx, *mapUpdate)
+			if err != nil {
+				continue
+			}
+		}
+	}
+	c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "更新地图续扫提醒成功"})
+}
+
+// AddMapRescanNotifyWithoutHttp 查询累积地图更新率低于续扫阈值的记录,并通知运维人员
+func AddMapRescanNotifyWithoutHttp(ctx context.Context) bool {
+	// 查询朴津地图列表
+	mapInfoList, err := getMapInfoList()
+	if err != nil || mapInfoList == nil {
+		fmt.Println("获取地图列表数据失败")
+		return false
+	}
+
+	// 查询地图续扫阈值
+	systemConfig, err := mysql.QuerySystemConfig(ctx)
+	if err != nil {
+		fmt.Println("获取系统配置失败")
+		return false
+	}
+	threshold := systemConfig.RescanReminderThreshold
+
+	fmt.Println("threshold", threshold)
+	// 查询地图更新表中未发送续扫提醒通知的记录(续扫提醒标志为0)
+	mapUpdates, err := mysql.QueryMapUpdateRecordsByRescanFlag(ctx, config.MAP_NOT_RESCAN_FLAG)
+	if err != nil {
+		fmt.Println("查询地图更新列表失败")
+		return false
+	}
+	// 记录已发送通知的地图id
+	// 对于同一地图id的多个符合续扫通知提醒的记录,只允许发送一次续扫通知,但相关记录均会被标记为已发送续扫提醒
+	mapIdList := make(map[string]bool)
+
+	for _, mapUpdate := range mapUpdates {
+		// 查询地图id是否存在于地图列表中
+		exist, record := checkMapIdExist(mapUpdate.MapID, mapInfoList)
+		fmt.Println("exist", exist)
+		fmt.Println("record", record)
+		if !exist {
+			fmt.Println("地图列表中不存在该地图id,跳过...")
+			continue
+		}
+		//fmt.Println("mapUpdate", mapUpdate)
+		updatePercentage, err := getUpdatePercentage(mapUpdate.CumulativeUpdateRate)
+		if err != nil {
+			fmt.Println("error:", err)
+		}
+		fmt.Println("updatePercentage", updatePercentage)
+
+		if updatePercentage >= threshold {
+			mapId := mapUpdate.MapID
+			if _, exits := mapIdList[mapId]; !exits {
+				// 发送续扫通知
+				//paramMap := make(map[string]interface{})
+				//paramMap["mapId"] = mapId
+				//paramMap["type"] = "1" // 0代表修图通知,1代表续扫通知
+				//paramMap["customAreaId"] = record.CustomAreaId
+				//resp, err := pji_client.ApiClient.JsonPostRequest(c_pji.PjiApiSitBaseUrl+"sendMsg", paramMap, pji_client.MapSecretId)
+				//if err != nil {
+				//	continue
+				//}
+				//fmt.Println(string(resp.Body()))
+				mapIdList[mapId] = true
+			}
+			// 修改续扫提醒标志
+			mapUpdate.RescanNotifyFlag = config.MAP_RESCAN_FLAG
+			// 记录发送通知时的续扫提醒阈值
+			thresholdStr := strconv.FormatFloat(float64(threshold), 'f', 2, 32) + "%"
+			mapUpdate.RescanNotifyThreshold = &thresholdStr
+			_, err := mysql.UpdateMapUpdateOneRecord(ctx, *mapUpdate)
+			if err != nil {
+				continue
+			}
+		}
+	}
+	fmt.Println("更新地图续扫提醒成功")
+	return true
+}
+
+// QueryMapRescanNotifyList 查询地图续扫提醒列表
+// @router /map/rescan/notify/list [GET]
+func QueryMapRescanNotifyList(ctx context.Context, c *app.RequestContext) {
+	var record model.MapUpdate
+	err := c.BindAndValidate(&record)
+	fmt.Println("record", record)
+
+	var pageFlag bool
+	if c.Query("page") != "" && c.Query("pageSize") != "" {
+		pageFlag = true
+	} else {
+		pageFlag = false
+	}
+
+	page, _ := strconv.Atoi(c.Query("page"))
+	pageSize, _ := strconv.Atoi(c.Query("pageSize"))
+
+	records, count, err := mysql.QueryMapRescanList(ctx, &record, pageFlag, page, pageSize)
+	if err != nil {
+		c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "地图续扫提醒记录查询失败", Total: 0})
+		return
+	}
+
+	output, err := json.Marshal(records)
+	if err != nil {
+		c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "地图续扫提醒记录查询失败", Total: 0})
+		return
+	}
+	c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "地图续扫提醒记录查询成功", Data: string(output), Total: int(count)})
+}
+
+func getUpdatePercentage(percentageStr string) (float32, error) {
+	// 去掉末尾的%
+	valueStr := percentageStr[:len(percentageStr)-1]
+	//fmt.Println("valueStr", valueStr)
+	// 将字符串转为float32
+	value, err := strconv.ParseFloat(valueStr, 32)
+	if err != nil {
+		fmt.Println("err", err)
+		return 0, err
+	}
+	return float32(value), nil
+}
+
 // 计算oss中文件列表的总大小
 func calculateTotalFileSize(fileList []string) int {
 	var totalSize int

+ 23 - 21
biz/model/map_update.go

@@ -14,27 +14,29 @@ const TableNameMapUpdate = "map_update"
 
 // MapUpdate mapped from table <map_update>
 type MapUpdate struct {
-	ID                   string         `gorm:"column:id;type:varchar(100);primaryKey" json:"id"`
-	MapID                string         `gorm:"column:map_id;type:varchar(100);not null" json:"map_id"`
-	DeviceID             string         `gorm:"column:device_id;type:varchar(100);not null" json:"device_id"`
-	DeviceSn             string         `gorm:"column:device_sn;type:varchar(100);not null" json:"device_sn"`
-	DeviceName           string         `gorm:"column:device_name;type:varchar(100);not null" json:"device_name"`
-	DeviceType           string         `gorm:"column:device_type;type:varchar(100);not null" json:"device_type"`
-	PrePgmURL            string         `gorm:"column:pre_pgm_url;type:varchar(255);not null" json:"pre_pgm_url"`
-	CurrentPgmURL        string         `gorm:"column:current_pgm_url;type:varchar(255);not null" json:"current_pgm_url"`
-	PrePngURL            string         `gorm:"column:pre_png_url;type:varchar(255);not null" json:"pre_png_url"`
-	CurrentPngURL        string         `gorm:"column:current_png_url;type:varchar(255);not null" json:"current_png_url"`
-	UpdateRate           string         `gorm:"column:update_rate;type:varchar(50);not null" json:"update_rate"`
-	CumulativeUpdateRate string         `gorm:"column:cumulative_update_rate;type:varchar(50);not null" json:"cumulative_update_rate"`
-	UpdateTime           string         `gorm:"column:update_time;type:varchar(50);not null" json:"update_time"`
-	FromSceneList        *string        `gorm:"column:from_scene_list;type:varchar(255)" json:"from_scene_list"`
-	UpdateFlag           int32          `gorm:"column:update_flag;type:int(11);not null" json:"update_flag"`
-	CreatedAt            time.Time      `gorm:"column:created_at;type:datetime;not null" json:"created_at"`
-	UpdatedAt            *time.Time     `gorm:"column:updated_at;type:datetime" json:"updated_at"`
-	DeletedAt            gorm.DeletedAt `gorm:"column:deleted_at;type:datetime" json:"deleted_at"`
-	UpdateMapURL         string         `gorm:"column:update_map_url;type:varchar(255);not null" json:"update_map_url"`
-	UploadVersion        *string        `gorm:"column:upload_version;type:varchar(50)" json:"upload_version"`
-	UploadedAt           *time.Time     `gorm:"column:uploaded_at;type:datetime" json:"uploaded_at"`
+	ID                    string         `gorm:"column:id;type:varchar(100);primaryKey" json:"id"`
+	MapID                 string         `gorm:"column:map_id;type:varchar(100);not null" json:"map_id"`
+	DeviceID              string         `gorm:"column:device_id;type:varchar(100);not null" json:"device_id"`
+	DeviceSn              string         `gorm:"column:device_sn;type:varchar(100);not null" json:"device_sn"`
+	DeviceName            string         `gorm:"column:device_name;type:varchar(100);not null" json:"device_name"`
+	DeviceType            string         `gorm:"column:device_type;type:varchar(100);not null" json:"device_type"`
+	PrePgmURL             string         `gorm:"column:pre_pgm_url;type:varchar(255);not null" json:"pre_pgm_url"`
+	CurrentPgmURL         string         `gorm:"column:current_pgm_url;type:varchar(255);not null" json:"current_pgm_url"`
+	PrePngURL             string         `gorm:"column:pre_png_url;type:varchar(255);not null" json:"pre_png_url"`
+	CurrentPngURL         string         `gorm:"column:current_png_url;type:varchar(255);not null" json:"current_png_url"`
+	UpdateRate            string         `gorm:"column:update_rate;type:varchar(50);not null" json:"update_rate"`
+	CumulativeUpdateRate  string         `gorm:"column:cumulative_update_rate;type:varchar(50);not null" json:"cumulative_update_rate"`
+	UpdateTime            string         `gorm:"column:update_time;type:varchar(50);not null" json:"update_time"`
+	FromSceneList         *string        `gorm:"column:from_scene_list;type:varchar(255)" json:"from_scene_list"`
+	UpdateFlag            int32          `gorm:"column:update_flag;type:int(11);not null" json:"update_flag"`
+	CreatedAt             time.Time      `gorm:"column:created_at;type:datetime;not null" json:"created_at"`
+	UpdatedAt             *time.Time     `gorm:"column:updated_at;type:datetime" json:"updated_at"`
+	DeletedAt             gorm.DeletedAt `gorm:"column:deleted_at;type:datetime" json:"deleted_at"`
+	UpdateMapURL          string         `gorm:"column:update_map_url;type:varchar(255);not null" json:"update_map_url"`
+	UploadVersion         *string        `gorm:"column:upload_version;type:varchar(50)" json:"upload_version"`
+	UploadedAt            *time.Time     `gorm:"column:uploaded_at;type:datetime" json:"uploaded_at"`
+	RescanNotifyFlag      int32          `gorm:"column:rescan_notify_flag;type:int(11);not null" json:"rescan_notify_flag"`
+	RescanNotifyThreshold *string        `gorm:"column:rescan_notify_threshold;type:varchar(100)" json:"rescan_notify_threshold"`
 }
 
 // TableName MapUpdate's table name

+ 4 - 2
common/config/c_map.go

@@ -11,6 +11,8 @@ var (
 )
 
 const (
-	MAP_VALID_FLAG     = 1
-	MAP_NOT_VALID_FLAG = 0
+	MAP_VALID_FLAG      = 1
+	MAP_NOT_VALID_FLAG  = 0
+	MAP_RESCAN_FLAG     = 1
+	MAP_NOT_RESCAN_FLAG = 0
 )

+ 1 - 1
gen/main.go

@@ -19,7 +19,7 @@ func main() {
 	// 生成实例
 	g := gen.NewGenerator(gen.Config{
 		// 相对执行`go run`时的路径, 会自动创建目录
-		OutPath: "dal/query",
+		OutPath: "gen/dal/query",
 
 		// WithDefaultQuery 生成默认查询结构体(作为全局变量使用), 即`Q`结构体和其字段(各表模型)
 		// WithoutContext 生成没有context调用限制的代码供查询

+ 1 - 0
go.mod

@@ -50,6 +50,7 @@ require (
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/nyaruka/phonenumbers v1.0.55 // indirect
 	github.com/pelletier/go-toml/v2 v2.2.2 // indirect
+	github.com/robfig/cron/v3 v3.0.1 // indirect
 	github.com/tidwall/gjson v1.14.4 // indirect
 	github.com/tidwall/match v1.1.1 // indirect
 	github.com/tidwall/pretty v1.2.0 // indirect

+ 2 - 0
go.sum

@@ -119,6 +119,8 @@ github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6
 github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
+github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
 github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
 github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
 github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=

+ 22 - 1
main.go

@@ -3,9 +3,13 @@
 package main
 
 import (
+	"context"
+	"fmt"
 	"github.com/cloudwego/hertz/pkg/app/server"
 	"github.com/hertz-contrib/cors"
+	"github.com/robfig/cron/v3"
 	"pji_desktop_http/biz/dal"
+	"pji_desktop_http/biz/handler/map_service"
 	"pji_desktop_http/common/config"
 	"pji_desktop_http/common/config/c_log"
 	"pji_desktop_http/pji_client"
@@ -13,11 +17,28 @@ import (
 )
 
 func main() {
+	// 初始化数据库
 	dal.Init()
+	// 初始化日志
 	c_log.InitLog("logs/", "desktop_http")
+	// 初始化oss
 	config.InitOssConfig()
+	// 初始化朴津sdk
 	pji_client.InitApiClient()
-	//h := server.Default()
+	// 添加调度器
+	c := cron.New()
+	// 添加定时任务
+	ctx := context.Background()
+	_, err := c.AddFunc("@every 30m", func() {
+		// 发送地图续扫通知
+		flag := map_service.AddMapRescanNotifyWithoutHttp(ctx)
+		fmt.Println("flag", flag)
+	})
+	if err != nil {
+		return
+	}
+	// 启动调度器
+	c.Start()
 	h := server.New(
 		server.WithStreamBody(true),
 		server.WithIdleTimeout(time.Minute*10),

+ 4 - 1
router.go

@@ -38,9 +38,12 @@ func customizedRegister(r *server.Hertz) {
 
 	r.GET("/map/update/deviceMap/test", map_service.UpdateDeviceMapById)
 	r.GET("/map/update/deviceMap/record", map_service.UpdateDeviceMap)
-
 	r.GET("/map/update/pji/upload", map_service.UploadPjiMapAndNotify)
 
+	r.GET("/map/rescan/notify/add", map_service.AddMapRescanNotifyWithHttp)
+	r.GET("/map/rescan/notify/list", map_service.QueryMapRescanNotifyList)
+	r.POST("/map/rescan/notify/list", map_service.QueryMapRescanNotifyList)
+
 	r.GET("/world/upload/world", world_service.UploadWorldFile)
 	r.POST("/world/upload/world", world_service.UploadWorldFile)