|
@@ -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中文件列表的总大小
|
|
// 计算oss中文件列表的总大小
|
|
func calculateTotalFileSize(fileList []string) int {
|
|
func calculateTotalFileSize(fileList []string) int {
|
|
var totalSize int
|
|
var totalSize int
|