1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246 |
- package map_service
- import (
- "archive/zip"
- "context"
- "encoding/json"
- "fmt"
- "github.com/cloudwego/hertz/pkg/app"
- "github.com/cloudwego/hertz/pkg/protocol/consts"
- uuid "github.com/satori/go.uuid"
- "io"
- "io/ioutil"
- "net/http"
- "os"
- "path/filepath"
- "pji_desktop_http/biz/dal/mysql"
- "pji_desktop_http/biz/model"
- "pji_desktop_http/common/config"
- "pji_desktop_http/common/config/c_log"
- "pji_desktop_http/common/config/c_pji"
- "pji_desktop_http/common/entity"
- "pji_desktop_http/common/util"
- "pji_desktop_http/pji_client"
- "strconv"
- "strings"
- "time"
- )
- // CheckMapBufConsistency 检查请求id对应的mapBuf文件夹的一致性
- // @router /map/checkmapbuf [POST]
- func CheckMapBufConsistency(ctx context.Context, c *app.RequestContext) {
- var req []string
- err := c.BindAndValidate(&req)
- if err != nil {
- c.String(consts.StatusBadRequest, err.Error())
- return
- }
- fmt.Println(req)
- if len(req) == 0 { // 请求数据为空
- c.JSON(consts.StatusBadRequest, entity.HttpResult{Status: false, Code: "", Message: "请求数据为空。"})
- } else if len(req) == 1 { // 只有一条数据则直接返回
- c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "mapBuf文件夹数据一致。"})
- } else {
- var firstValue int
- for i, id := range req {
- // 根据id获取对应的oss文件列表
- fileList, err := util.GetExactedMapFileById(id)
- // 过滤特定后缀的文件列表
- fileList = util.FilterBySuffixes(fileList, config.MapBufFiltersuffixes...)
- //fmt.Println("Filtered Strings:", fileList)
- if err != nil {
- c.String(consts.StatusBadRequest, err.Error())
- return
- }
- // 获取文件列表的总大小
- totalSize := calculateTotalFileSize(fileList)
- fmt.Println("Total Size:", totalSize)
- // 判断不同文件列表(mapBuf)中文件的总大小是否一致
- if i == 0 {
- firstValue = totalSize
- } else {
- if totalSize != firstValue {
- c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "mapBuf文件夹数据不一致。"})
- return
- }
- }
- }
- c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "mapBuf文件夹数据一致。"})
- }
- }
- // DownloadOSSFile 根据objectKey下载指定的oss文件
- // @router /map/downloadossfile [GET]
- func DownloadOSSFile(ctx context.Context, c *app.RequestContext) {
- objectKey := c.Query("objectKey")
- // 从OSS下载文件
- reader, err := config.OssBucket.GetObject(objectKey)
- if err != nil {
- c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- defer reader.Close()
- // 设置响应头
- c.Response.Header.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filepath.Base(objectKey)))
- c.Response.Header.Set("Content-Type", "binary/octet-stream")
- // 将文件流式传输回客户端
- data, err := io.ReadAll(reader)
- if err != nil {
- panic(err)
- }
- if _, err := c.Write(data); err != nil {
- c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- }
- // DownloadMapZipFile 根据请求id从oss拉取并打包下载建图所需要的文件
- // @router /map/download/map/zip [GET]
- func DownloadMapZipFile(ctx context.Context, c *app.RequestContext) {
- id := c.Query("id")
- fmt.Println("id", id)
- deviceNo := c.Query("deviceNo")
- fmt.Println("deviceNo", deviceNo)
- ids := strings.Split(id, ",")
- fmt.Println("ids", ids)
- sceneId := ids[0]
- // 根据场景id查询地图id
- mapId, err := getMapIdById(sceneId)
- if err != nil || mapId == "" {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取mapId失败"})
- return
- }
- fmt.Println("mapId", mapId)
- // 获取朴津地图压缩包url
- //originUrl
- deviceMaps, err := mysql.QueryValidDeviceMapByMapIdAndDeviceNo(ctx, mapId, deviceNo)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询设备地图失败"})
- return
- }
- if len(deviceMaps) == 0 {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "未查询到对应设备地图"})
- return
- }
- deviceMap := deviceMaps[0]
- originUrl := deviceMap.PjiMapZipURL
- fmt.Println("originUrl", originUrl)
- // 根据id生成用于地图更新的压缩包
- filePath, tmpDir, err := generateMapZipById(ids, originUrl)
- if err != nil {
- c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
- }
- fmt.Println("filePath", filePath)
- // 检查文件是否存在
- if _, err := os.Stat(filePath); os.IsNotExist(err) {
- c.JSON(http.StatusNotFound, map[string]string{"error": "File not found"})
- return
- }
- // 打开文件
- f, err := os.Open(filePath)
- if err != nil {
- c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to open file"})
- return
- }
- defer f.Close()
- // 设置响应头
- c.Response.Header.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filepath.Base(filePath)))
- c.Response.Header.Set("Content-Type", "binary/octet-stream")
- // 将文件流式传输回客户端
- data, err := io.ReadAll(f)
- if err != nil {
- panic(err)
- }
- if _, err := c.Write(data); err != nil {
- c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- defer os.RemoveAll(tmpDir)
- }
- // DownloadMapBagFile 根据请求id从oss拉取并下载解析后的map.bag文件
- // @router /map/downloadmapbagfile [GET]
- func DownloadMapBagFile(ctx context.Context, c *app.RequestContext) {
- id := c.Query("id")
- fmt.Println("id: ", id)
- // 根据id获取对应的oss文件列表
- fileList, err := util.GetExactedMapFileById(id)
- // 过滤特定后缀的文件列表
- fileList = util.FilterBySuffixes(fileList, config.MapBagFiltersuffixes...)
- //fmt.Println("fileList", fileList)
- objectKey := fileList[0]
- // 从OSS下载文件
- reader, err := config.OssBucket.GetObject(objectKey)
- if err != nil {
- c.JSON(consts.StatusInternalServerError, entity.HttpResult{Status: false, Code: "", Message: "解析地图Bag下载失败。"})
- return
- }
- defer reader.Close()
- // 设置响应头
- c.Response.Header.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filepath.Base(objectKey)))
- c.Response.Header.Set("Content-Type", "binary/octet-stream")
- // 将文件流式传输回客户端
- data, err := io.ReadAll(reader)
- if err != nil {
- panic(err)
- }
- if _, err := c.Write(data); err != nil {
- c.JSON(consts.StatusInternalServerError, entity.HttpResult{Status: false, Code: "", Message: "解析地图Bag下载失败。"})
- return
- }
- c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "解析地图Bag下载成功。"})
- }
- // 根据id生成用于地图更新的压缩包
- func generateMapZipById(ids []string, originUrl string) (file string, tmpDir string, err error) {
- // 根据id获取对应的oss文件列表
- allFileList, err := util.GetExactedMapFileByIds(ids)
- //fmt.Println("allFileList", allFileList)
- // 过滤特定后缀的文件列表
- mapBufFileList := util.FilterBySuffixes(allFileList, config.MapBufFiltersuffixes...)
- //fmt.Println("Filtered Strings:", fileList)
- if err != nil {
- return
- }
- // 创建临时文件夹
- tmpDir, err = os.MkdirTemp("", "temp-download-*")
- fmt.Println("tmpDir:", tmpDir)
- if err != nil {
- fmt.Println("Error creating temporary directory:", err)
- return "", "", err
- }
- c_log.GlobalLogger.Info("创建下载-临时文件夹:", tmpDir)
- // 创建根文件夹(文件打包的根目录)
- baseDir := filepath.Join(tmpDir, "data")
- if err := os.Mkdir(baseDir, 0755); err != nil {
- fmt.Println("Error creating subdirectory:", err)
- return "", "", err
- }
- c_log.GlobalLogger.Info("创建文件打包根目录:", baseDir)
- // 根目录创建子文件夹 bag_folder
- bagFolderDir := filepath.Join(baseDir, "bag_folder")
- if err := os.Mkdir(bagFolderDir, 0755); err != nil {
- fmt.Println("Error creating subdirectory:", err)
- return "", "", err
- }
- c_log.GlobalLogger.Info("根目录下创建bag_folder子文件夹:", bagFolderDir)
- // 根目录创建子文件夹 origin_map_folder
- originMapFolderDir := filepath.Join(baseDir, "origin_map_folder")
- if err := os.Mkdir(originMapFolderDir, 0755); err != nil {
- fmt.Println("Error creating subdirectory:", err)
- return "", "", err
- }
- c_log.GlobalLogger.Info("根目录下创建origin_map_folder子文件夹:", originMapFolderDir)
- // 子文件夹 bag_folder 创建子文件夹 mapBuf
- mapBufDir := filepath.Join(bagFolderDir, "mapBuf")
- if err := os.Mkdir(mapBufDir, 0755); err != nil {
- fmt.Println("Error creating subdirectory:", err)
- return "", "", err
- }
- c_log.GlobalLogger.Info("bag_folder创建mapBuf子文件夹 :", mapBufDir)
- // 从oss下载build_map.bag文件到 bag_folder 文件夹
- // 过滤特定后缀的文件列表
- buildMapBagFileList := util.FilterBySuffixes(allFileList, config.BuildMapBagFiltersuffixes...)
- fmt.Println("buildMapBagFileList", buildMapBagFileList)
- //buildMapBagFile := buildMapBagFileList[0]
- //err = config.OssBucket.GetObjectToFile(buildMapBagFile, filepath.Join(bagFolderDir, filepath.Base(buildMapBagFile)))
- for i, file := range buildMapBagFileList {
- fileName := "build_map" + "-" + strconv.Itoa(i) + ".bag"
- err = config.OssBucket.GetObjectToFile(file, filepath.Join(bagFolderDir, fileName))
- if err != nil {
- fmt.Println("Error downloading build map file:", err)
- return "", "", err
- }
- }
- if err != nil {
- fmt.Println("Error downloading Bag file:", err)
- return "", "", err
- }
- c_log.GlobalLogger.Info("下载文件到bag_folder文件夹 - 成功")
- // 从oss下载文件到 mapBuf 文件夹
- for _, file := range mapBufFileList {
- err = config.OssBucket.GetObjectToFile(file, filepath.Join(mapBufDir, filepath.Base(file)))
- if err != nil {
- fmt.Println("Error downloading mapBuf file:", err)
- return "", "", err
- }
- }
- c_log.GlobalLogger.Info("下载文件到mapBuf子文件夹 - 成功")
- // 从oss下载bag文件到 origin_map_folder 文件夹
- // 过滤特定后缀的文件列表
- //originMapFileList := util.FilterBySuffixes(allFileList, config.OriginMapFiltersuffixes...)
- //for _, file := range originMapFileList {
- // err = config.OssBucket.GetObjectToFile(file, filepath.Join(originMapFolderDir, filepath.Base(file)))
- // if err != nil {
- // fmt.Println("Error downloading origin_map file:", err)
- // return "", "", err
- // }
- //}
- //err = config.OssBucket.GetObjectToFile(originUrl, filepath.Join(originMapFolderDir, filepath.Base(originUrl)))
- err = util.Downloadfile(originUrl, filepath.Join(originMapFolderDir, filepath.Base(originUrl)))
- if err != nil {
- fmt.Println("Error downloading origin_map file:", err)
- return "", "", err
- }
- c_log.GlobalLogger.Info("下载文件到origin_map_folder文件夹 - 成功")
- // 创建压缩文件
- zipPath := filepath.Join(tmpDir, "mapFile-"+ids[0]+".zip")
- zipFile, err := os.Create(zipPath)
- if err != nil {
- fmt.Println("Error creating ZIP file:", err)
- return "", "", err
- }
- defer zipFile.Close()
- zipWriter := zip.NewWriter(zipFile)
- defer zipWriter.Close()
- // 压缩文件夹
- if err := util.AddDirToZip(baseDir, zipWriter); err != nil {
- fmt.Println("Error adding directory to ZIP:", err)
- return "", "", err
- }
- fmt.Println("ZIP file created successfully.")
- c_log.GlobalLogger.Info("创建压缩文件 - 成功")
- return zipPath, tmpDir, nil
- }
- // UploadMapFile 将地图更新相关文件上传到oss
- // @router /map/upload/map [GET]
- func UploadMapFile(ctx context.Context, c *app.RequestContext) {
- equipmentNo := c.Query("equipmentNo")
- fmt.Println("equipmentNo", equipmentNo)
- mapId := c.Query("mapId")
- fmt.Println("mapId", mapId)
- timeStamp := c.Query("timeStamp")
- fmt.Println("timeStamp", timeStamp)
- header, err := c.FormFile("file")
- if err != nil {
- c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
- return
- }
- fileName := header.Filename
- fmt.Println("filename", fileName)
- ossObjectKey := config.UpdateMapOssBasePrefix + "/" + equipmentNo + "/" + mapId + "/" + timeStamp + "/" + fileName
- fmt.Println("ossObjectKey", ossObjectKey)
- f, _ := header.Open()
- defer f.Close()
- config.OssMutex.Lock()
- err = config.OssBucket.PutObject(ossObjectKey, f)
- config.OssMutex.Unlock()
- if err != nil {
- c_log.GlobalLogger.Error("程序异常退出。上传文件", fileName, "->", ossObjectKey, "出错:", err)
- c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "上传文件失败", Details: ""})
- return
- }
- c_log.GlobalLogger.Info("上传文件", fileName, "->", ossObjectKey, "成功。")
- c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "上传文件成功", Details: ossObjectKey})
- }
- // AddMapUpdateRecord 添加仿真测试记录
- // @router /map/add/record [GET]
- func AddMapUpdateRecord(ctx context.Context, c *app.RequestContext) {
- var record model.MapUpdate
- err := c.BindAndValidate(&record)
- record.ID = uuid.NewV1().String()
- fmt.Println("record", record)
- if err != nil {
- c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
- return
- }
- err = mysql.AddMapUpdateOneRecord(ctx, record)
- if err != nil {
- c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "地图更新记录添加失败"})
- return
- }
- c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "地图更新记录添加成功"})
- }
- // QueryMapUpdateRecord 根据条件查询地图更新记录
- // @router /map/query/update/record [GET]
- func QueryMapUpdateRecord(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.QueryMapUpdateRecords(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)})
- }
- // TestUploadUpdateMap 测试朴津地图上传接口
- // @router /map/upload/update/map [GET]
- func TestUploadUpdateMap(ctx context.Context, c *app.RequestContext) {
- header, err := c.FormFile("file")
- if err != nil {
- c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
- return
- }
- fileName := header.Filename
- fmt.Println("filename", fileName)
- f, _ := header.Open()
- defer f.Close()
- paramMap := make(map[string]interface{})
- // Map<String, String> paramMap=new HashMap<>();
- // paramMap.put("mapId","2247aeb31ad34wwddfd9c3ba24536e52859");
- // paramMap.put("mapName","合肥演示");
- // paramMap.put("buildId"," 7b4e8d01c08f472fabf7ccff2b2336s");
- // paramMap.put("floorId"," 695abbcfdf99471sdfff3b9b1d0818164e7");
- // paramMap.put("updateType"," 7b4e8d01c08f472fabf7ccff2b2336s");
- // paramMap.put("floor","1");
- // paramMap.put("buildName"," 2");
- // paramMap.put("customAreaId"," 355");
- // paramMap.put("snCode","P1YTYD1M233M00224");
- // paramMap.put("fileName","1702284791385137152.zip");
- // paramMap.put("mapType","0");
- paramMap["snCode"] = "P1YNYD1M225000112"
- paramMap["mapId"] = "8068197000f84a5483dabf5a6ad3707c"
- paramMap["mapName"] = "智慧楼"
- paramMap["buildId"] = "8afb5463ad9140aa9e0e42b9ca93e075"
- paramMap["buildName"] = "智慧楼"
- paramMap["floorId"] = "fc86319a04824122b63719b062811106"
- paramMap["floor"] = "1"
- paramMap["customAreaId"] = "334"
- paramMap["updateType"] = "0"
- paramMap["mapType"] = "0"
- paramMap["filename"] = ""
- bytes, err := io.ReadAll(f)
- if err != nil {
- return
- }
- // 调用 朴津地图上传 接口
- resp, err := pji_client.ApiClient.UploadRequest(c_pji.PjiApiSitBaseUrl+"mapUpload", paramMap, pji_client.MapSecretId, bytes)
- fmt.Println(string(resp.Body()))
- c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "上传地图测试"})
- }
- // UpdateDeviceMapById 根据场景id维护设备地图表
- // @router /map/update/deviceMap/record [GET]
- func UpdateDeviceMapById(ctx context.Context, c *app.RequestContext) {
- sceneId := c.Query("sceneId")
- fmt.Println("sceneId", sceneId)
- deviceNo := c.Query("deviceNo")
- fmt.Println("deviceNo", deviceNo)
- deviceName := c.Query("deviceName")
- fmt.Println("deviceName", deviceName)
- deviceType := c.Query("deviceType")
- fmt.Println("deviceType", deviceType)
- // 根据场景id查询地图id
- mapId, err := getMapIdById(sceneId)
- if err != nil || mapId == "" {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取mapId失败"})
- return
- }
- fmt.Println("mapId", mapId)
- // 查询朴津地图列表
- mapInfoList, err := getMapInfoList()
- if err != nil || mapInfoList == nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取地图列表数据失败"})
- return
- }
- fmt.Println("mapInfoList", mapInfoList)
- // 判断map id是否存在于朴津地图列表中
- mapId = "fee84db56d254d79b85971cb4ab2e7f1" // 存在
- //mapId = "553d9d47f8404734997e11175f0e63f5" // 不存在
- exist, record := checkMapIdExist(mapId, mapInfoList)
- fmt.Println("exist", exist)
- fmt.Println("record", record)
- if !exist { // map id不存在于朴津地图列表中
- // 查询地图设备表中是否存在对应map id且有效的记录
- records, err := mysql.QueryValidDeviceMapByMapId(ctx, mapId)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: " 查询设备地图失败"})
- return
- }
- fmt.Println("records", records)
- if len(records) > 0 { // 存在,
- fmt.Println("设置无效")
- // 将对应的map id的记录设置为无效
- update, err := mysql.UpdateDeviceMapValidFlagByMapId(ctx, mapId, config.MAP_NOT_VALID_FLAG)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图状态失败"})
- return
- }
- fmt.Println("update", update)
- }
- c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "1001", Message: "map id不存在地图列表中"})
- } else { // map id存在于朴津地图列表中
- snCodeList := record.SnCodeList
- for _, snCode := range snCodeList { // snCodeList 代表配置了对应map id地图的机器人sn码列表, 上限为机器人数量
- fmt.Println("snCode", snCode)
- deviceMap := model.DeviceMap{DeviceNo: snCode, DeviceName: deviceName,
- DeviceType: deviceType, MapID: record.MapId, MapType: record.MapType, MapName: record.MapName, FloorID: record.FloorId,
- Floor: strconv.Itoa(record.Floor), BuildID: record.BuildId, BuildName: record.BuildName, MapCreateTime: record.CreateTime, MapUpdateTime: record.UpdateTime,
- MapVersion: strconv.Itoa(record.Version), MapValidFlag: config.MAP_VALID_FLAG, PjiMapZipURL: record.ZipUrl, CustomAreaID: int32(record.CustomAreaId)}
- fmt.Println("deviceMap", deviceMap)
- deviceMap.MapVersion = "123456"
- // 查询[对应设备]是否存在对应map id且有效的记录
- records, err := mysql.QueryValidDeviceMapByMapIdAndDeviceNo(ctx, mapId, snCode)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: " 查询设备地图失败"})
- return
- }
- fmt.Println("records", records)
- if len(records) == 0 { // 对应设备不存在对应map id且有效的记录, 说明该设备部署了新的地图(重采或新的区域地图)
- // 添加记录
- deviceMap.ID = uuid.NewV1().String()
- err = mysql.AddDeviceMapOneRecord(ctx, deviceMap)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "添加设备地图记录失败"})
- return
- }
- } else if len(records) == 1 { // 对应设备存在1个对应map id且有效的记录, 说明该设备之前部署过该地图, 需要检测版本号来判断更新记录(版本号一致)还是添加记录(版本号不一致)
- fmt.Println("record", record)
- if deviceMap.MapVersion == records[0].MapVersion { // 地图列表查询到的版本与设备地图表中版本一致, 则更新记录
- // 更新记录
- deviceMap.ID = records[0].ID
- update, err := mysql.UpdateDeviceMapOneRecord(ctx, deviceMap)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图记录失败"})
- return
- }
- fmt.Println("update", update)
- } else { // 地图列表查询到的版本与设备地图表中版本不一致, 则先将之前的记录状态设置为无效, 然后添加记录
- // 将对应设备存在的对应map id的记录设置为无效
- update, err := mysql.UpdateDeviceMapValidFlagByMapIdAndDevice(ctx, mapId, snCode, config.MAP_NOT_VALID_FLAG)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图状态失败"})
- return
- }
- fmt.Println("update", update)
- // 添加记录
- deviceMap.ID = uuid.NewV1().String()
- err = mysql.AddDeviceMapOneRecord(ctx, deviceMap)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "添加设备地图记录失败"})
- return
- }
- }
- }
- }
- c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "设备地图数据更新成功"})
- }
- }
- // CheckDeviceMapStatus 根据设备号及map id查询地图状态
- // @router /map/check/deviceMap/status [GET]
- func CheckDeviceMapStatus(ctx context.Context, c *app.RequestContext) {
- sceneId := c.Query("sceneId")
- fmt.Println("sceneId", sceneId)
- deviceNo := c.Query("deviceNo")
- fmt.Println("deviceNo", deviceNo)
- deviceName := c.Query("deviceName")
- fmt.Println("deviceName", deviceName)
- deviceType := c.Query("deviceType")
- fmt.Println("deviceType", deviceType)
- // 根据场景id查询地图id
- mapId, err := getMapIdById(sceneId)
- if err != nil || mapId == "" {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取mapId失败"})
- return
- }
- fmt.Println("mapId", mapId)
- // 查询 设备sn码 是否存在于 设备表中
- device, err := mysql.QueryDeviceByDeviceNo(ctx, deviceNo)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询设备记录失败"})
- return
- }
- fmt.Println("device", device)
- if device == nil { // 设备sn码 不在 设备表中
- record := model.Device{DeviceNo: deviceNo, DeviceName: deviceName, DeviceType: deviceType}
- err := mysql.AddDeviceOneRecord(ctx, record)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "添加设备记录失败"})
- return
- }
- }
- // 查询[对应设备]是否存在对应map id且有效的记录
- records, err := mysql.QueryValidDeviceMapByMapIdAndDeviceNo(ctx, mapId, deviceNo)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询设备地图失败"})
- return
- }
- fmt.Println("records", records)
- if len(records) == 0 { // [对应设备]不存在对应map id且有效的记录
- // 地图已重采/删除
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "1001", Message: "地图已重采/删除, 不符合地图更新条件"})
- return
- }
- c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "1000", Message: "记录存在,符合地图更新条件"})
- }
- // UpdateDeviceMap 根据地图列表及设备列表维护设备地图表
- // @router /map/update/deviceMap/record [GET]
- func UpdateDeviceMap(ctx context.Context, c *app.RequestContext) {
- //sceneId := c.Query("sceneId")
- //fmt.Println("sceneId", sceneId)
- //deviceNo := c.Query("deviceNo")
- //fmt.Println("deviceNo", deviceNo)
- //deviceName := c.Query("deviceName")
- //fmt.Println("deviceName", deviceName)
- //deviceType := c.Query("deviceType")
- //fmt.Println("deviceType", deviceType)
- // 查询朴津地图列表
- mapInfoList, err := getMapInfoList()
- if err != nil || mapInfoList == nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取地图列表数据失败"})
- return
- }
- //fmt.Println("mapInfoList", mapInfoList)
- snCodeMap := groupMapListByDevice(mapInfoList)
- fmt.Println("snCodeMap", snCodeMap)
- // 查询设备表
- devices, err := mysql.QueryAllDevices(ctx)
- for _, device := range devices {
- //fmt.Println("device", device)
- deviceNo := device.DeviceNo
- fmt.Println("deviceNo", deviceNo)
- if _, exist := snCodeMap[deviceNo]; !exist { // 设备不存在于朴津地图列表中, 在地图接口列表区域权限配置正确的前提下, 说明该设备没有部署地图
- // 查询设备地图表中是否存在有效的记录
- deviceMaps, err := mysql.QueryValidDeviceMapByDeviceNo(ctx, deviceNo) // 设备数量有限
- if err != nil {
- return
- }
- if len(deviceMaps) > 0 { // 之前存在有效记录
- // 将之前的记录有效标志设置为无效
- updates, err := mysql.UpdateDeviceMapValidFlagByDeviceNo(ctx, deviceNo, config.MAP_NOT_VALID_FLAG)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图状态失败"})
- return
- }
- fmt.Println("updates", updates)
- }
- } else { // 设备存在于朴津地图列表中,说明该设备当前有部署地图
- mapList := snCodeMap[deviceNo]
- fmt.Println("mapList", mapList)
- // 判断该设备对应地图的数量
- var mapInfo model.MapInfo
- if len(mapList) == 1 {
- mapInfo = mapList[0]
- } else {
- var latestMap *model.MapInfo
- layout := "2006-01-02 15:04:05"
- // 查找地图更新时间最近的记录
- for _, info := range mapList {
- if latestMap == nil {
- latestMap = &info
- } else {
- updateTime, err := getTime(info.UpdateTime, layout)
- if err != nil {
- fmt.Println(err)
- continue
- }
- latestTime, err := getTime(latestMap.UpdateTime, layout)
- if err != nil {
- fmt.Println(err)
- continue
- }
- if updateTime.After(latestTime) {
- latestMap = &info
- }
- }
- }
- mapInfo = *latestMap
- }
- // 判断该设备对应map id是否在设备地图表中存在有效记录
- records, err := mysql.QueryValidDeviceMapByMapIdAndDeviceNo(ctx, mapInfo.MapId, deviceNo)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: " 查询设备地图失败"})
- return
- }
- fmt.Println("records", records)
- deviceMap := model.DeviceMap{DeviceNo: device.DeviceNo, DeviceName: device.DeviceName,
- DeviceType: device.DeviceType, MapID: mapInfo.MapId, MapType: mapInfo.MapType, MapName: mapInfo.MapName, FloorID: mapInfo.FloorId,
- Floor: strconv.Itoa(mapInfo.Floor), BuildID: mapInfo.BuildId, BuildName: mapInfo.BuildName, MapCreateTime: mapInfo.CreateTime, MapUpdateTime: mapInfo.UpdateTime,
- MapVersion: strconv.Itoa(mapInfo.Version), MapValidFlag: config.MAP_VALID_FLAG, PjiMapZipURL: mapInfo.ZipUrl, CustomAreaID: int32(mapInfo.CustomAreaId)}
- if len(records) == 0 { // 该设备对应map id是否在设备地图表中不存在有效记录
- // 将之前的记录有效标志设置为无效
- updates, err := mysql.UpdateDeviceMapValidFlagByDeviceNo(ctx, deviceNo, config.MAP_NOT_VALID_FLAG)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图状态失败"})
- return
- }
- fmt.Println("updates", updates)
- // 添加记录
- deviceMap.ID = uuid.NewV1().String()
- fmt.Println("deviceMap", deviceMap)
- err = mysql.AddDeviceMapOneRecord(ctx, deviceMap)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "添加设备地图记录失败"})
- return
- }
- } else { // 该设备对应map id是否在设备地图表中存在有效记录
- // 判断版本号是否一致
- record := records[0]
- fmt.Println("record", record)
- if record.MapVersion == strconv.Itoa(mapInfo.Version) { // 版本号一致
- // 更新记录
- deviceMap.ID = records[0].ID
- update, err := mysql.UpdateDeviceMapOneRecord(ctx, deviceMap)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图记录失败"})
- return
- }
- fmt.Println("update", update)
- } else { // 版本号不一致
- // 将之前的记录有效标志设置为无效
- updates, err := mysql.UpdateDeviceMapValidFlagByDeviceNo(ctx, deviceNo, config.MAP_NOT_VALID_FLAG)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图状态失败"})
- return
- }
- fmt.Println("updates", updates)
- // 添加记录
- deviceMap.ID = uuid.NewV1().String()
- fmt.Println("deviceMap", deviceMap)
- err = mysql.AddDeviceMapOneRecord(ctx, deviceMap)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "添加设备地图记录失败"})
- return
- }
- }
- }
- }
- }
- c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "设备地图数据更新成功"})
- }
- // UploadPjiMapAndNotify 上传oss更新地图压缩包到朴津,并通知运维人员
- // @router /map/update/pji/upload [GET]
- func UploadPjiMapAndNotify(ctx context.Context, c *app.RequestContext) {
- id := c.Query("id")
- fmt.Println("id", id)
- // 根据id查询更新地图
- mapUpdate, err := mysql.QueryMapUpdateRecordById(ctx, id)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取地图更新列表失败"})
- return
- }
- mapId := mapUpdate.MapID
- fmt.Println("mapId", mapId)
- deviceNo := mapUpdate.DeviceSn
- fmt.Println("deviceNo", deviceNo)
- UpdateMapUrl := mapUpdate.UpdateMapURL
- fmt.Println("UpdateMapUrl", UpdateMapUrl)
- // 查询朴津地图列表
- mapInfoList, err := getMapInfoList()
- if err != nil || mapInfoList == nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取地图列表数据失败"})
- return
- }
- // 查询地图id是否存在于地图列表中
- exist, record := checkMapIdExist(mapId, mapInfoList)
- fmt.Println("exist", exist)
- fmt.Println("record", record)
- if !exist {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "1002", Message: "地图已重采/删除,不符合地图上传条件"})
- return
- }
- // 拉取oss文件流
- // 获取对象
- body, err := config.OssBucket.GetObject(UpdateMapUrl)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新地图文件获取失败"})
- return
- }
- // 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
- defer body.Close()
- file, err := ioutil.ReadAll(body)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新地图文件获取失败"})
- return
- }
- paramMap := make(map[string]interface{})
- //paramMap["snCode"] = "P1YNYD1M225000112"
- //paramMap["mapId"] = "8068197000f84a5483dabf5a6ad3707c"
- //paramMap["mapName"] = "智慧楼"
- //paramMap["buildId"] = "8afb5463ad9140aa9e0e42b9ca93e075"
- //paramMap["buildName"] = "智慧楼"
- //paramMap["floorId"] = "fc86319a04824122b63719b062811106"
- //paramMap["floor"] = "1"
- //paramMap["customAreaId"] = "334"
- //paramMap["updateType"] = "0"
- //paramMap["mapType"] = "0"
- //paramMap["filename"] = ""
- paramMap["snCode"] = deviceNo
- paramMap["mapId"] = mapId
- paramMap["mapName"] = record.MapName
- paramMap["buildId"] = record.BuildId
- paramMap["buildName"] = record.BuildName
- paramMap["floorId"] = record.FloorId
- paramMap["floor"] = strconv.Itoa(record.Floor)
- paramMap["customAreaId"] = strconv.Itoa(record.CustomAreaId)
- paramMap["updateType"] = "0"
- paramMap["mapType"] = record.MapType
- paramMap["filename"] = ""
- // 调用 朴津地图上传 接口
- resp, err := pji_client.ApiClient.UploadRequest(c_pji.PjiApiSitBaseUrl+"mapUpload", paramMap, pji_client.MapSecretId, file)
- fmt.Println(string(resp.Body()))
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "上传朴津地图失败"})
- return
- }
- // 解析结果
- var mapUploadRes model.MapUploadRes
- // Json转换为map
- err = json.Unmarshal(resp.Body(), &mapUploadRes)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "解析响应数据失败"})
- return
- }
- fmt.Println("mapUploadRes:", mapUploadRes)
- if mapUploadRes.Code != 200 {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "上传朴津地图失败"})
- return
- }
- version := strconv.Itoa(mapUploadRes.Data.Version)
- mapUpdate.UploadVersion = &version
- mapUpdate.UpdateFlag = 1
- info, err := mysql.UpdateMapUpdateOneRecord(ctx, *mapUpdate)
- if err != nil {
- c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "修改地图更新数据失败"})
- return
- }
- fmt.Println("info", info)
- //发送修图通知
- //paramMap = make(map[string]interface{})
- //paramMap["mapId"] = mapId
- //paramMap["type"] = "0" // 0代表修图通知,1代表续扫通知
- //paramMap["customAreaId"] = record.CustomAreaId
- //resp, err = pji_client.ApiClient.JsonPostRequest(c_pji.PjiApiSitBaseUrl+"sendMsg", paramMap, pji_client.MapSecretId)
- //if err != nil {
- // return
- //}
- //fmt.Println(string(resp.Body()))
- c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "上传朴津地图成功并已通知运维人员"})
- }
- // 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
- for _, file := range fileList {
- size, err := util.GetOSSFileSize(config.OssBucket, file) // 获取oss中单个文件的大小
- if err != nil {
- return 0
- }
- totalSize += size
- }
- return totalSize
- }
- func getTime(timeStr string, layout string) (time.Time, error) {
- t, err := time.Parse(layout, timeStr)
- if err != nil {
- return time.Time{}, err
- }
- return t, nil
- }
- // 调用 朴津地图列表查询 接口
- func getMapInfoList() ([]model.MapInfo, error) {
- paramMap := make(map[string]interface{})
- paramMap["mapType"] = "0"
- _, err := pji_client.ApiClient.GetRequest(c_pji.PjiApiSitBaseUrl+"mapList?mapType=0", paramMap, pji_client.MapSecretId)
- if err != nil {
- return nil, err
- }
- // 解析json响应
- //body := resp.Body()
- //body := string("{\n\t\"msg\": \"操作成功\",\n\t\"code\": 200,\n\t\"data\": [\n\t\t{\n\t\t\t\"mapType\": \"1\",\n\t\t\t\"mapId\": \"fee84db56d254d79b85971cb4ab2e7f1\",\n\t\t\t\"mapName\": \"太和桥办公室20221115\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"c976c8c5cf5249f8adb89c478a56ea8a\",\n\t\t\t\"buildId\": \"70c8574ad80248f6a90cd6fc5f2e11bf\",\n\t\t\t\"buildName\": \"日新楼\",\n\t\t\t\"createTime\": \"2023-05-30 15:09:34\",\n\t\t\t\"updateTime\": \"2024-01-09 14:21:02\",\n\t\t\t\"version\": 1699948169228,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1669241329772306432.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": [\n\t\t\t\t\"P1YTXS1M22AM00001\"\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"1965f3dbd1924f32b1031a471ea9f63c\",\n\t\t\t\"mapName\": \"充电图\",\n\t\t\t\"floor\": 0,\n\t\t\t\"floorId\": \"52798b3b8c1f4b2d9dd33ccec27c499a\",\n\t\t\t\"buildId\": \"736fe900d6484370a868ce8af49e4280\",\n\t\t\t\"buildName\": \"1\",\n\t\t\t\"createTime\": \"2023-06-21 21:27:59\",\n\t\t\t\"updateTime\": \"2023-11-01 23:07:08\",\n\t\t\t\"version\": 1687354079376,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1671510275657474048.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"207c7618965d4875b0d6b10382929e21\",\n\t\t\t\"mapName\": \"温泉\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"ad2239dc409c418688575edbfac0cd01\",\n\t\t\t\"buildId\": \"01928c7726cd461b902625780b0c64a5\",\n\t\t\t\"buildName\": \"1324\",\n\t\t\t\"createTime\": \"2023-07-05 13:57:17\",\n\t\t\t\"updateTime\": \"2023-11-30 09:21:59\",\n\t\t\t\"version\": 1691545587368,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1676470285395206144.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": [\n\t\t\t\t\"P1YTXS1M22AM00001\"\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"611028da8815415c9f7c93caf4625707\",\n\t\t\t\"mapName\": \"大厅建图测试\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"f2eda7e4022e4dbcacba56ee206c07f9\",\n\t\t\t\"buildId\": \"8cf1bdfdde7f465cbb893dba8e9a3500\",\n\t\t\t\"buildName\": \"日小楼1\",\n\t\t\t\"createTime\": \"2023-08-07 14:05:17\",\n\t\t\t\"updateTime\": \"2024-04-15 13:45:01\",\n\t\t\t\"version\": 1697632909852,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1688431099182227456.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": [\n\t\t\t\t\"P1YTXS1M22AM00002\"\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"da516324d8fc4de7a85c6c90d731f0ba\",\n\t\t\t\"mapName\": \"北京鑫雷晟星途4S店\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"458bb51e42ce4b98bc518626bb6b7c43\",\n\t\t\t\"buildId\": \"50df97f353dd49c59779ddfabdd89b66\",\n\t\t\t\"buildName\": \"北京鑫雷晟星途4S店\",\n\t\t\t\"createTime\": \"2023-08-10 11:12:18\",\n\t\t\t\"updateTime\": \"2023-09-13 18:20:46\",\n\t\t\t\"version\": 1692175845494,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1691723397236170752.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"0db5f09b8afc4a69bb095de8fb7312d8\",\n\t\t\t\"mapName\": \"8.14采集地图\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"761e1d04fa5242338f5b4ae4044fe8f0\",\n\t\t\t\"buildId\": \"0db7b180bc9b4f7599d3fc8737c73698\",\n\t\t\t\"buildName\": \"星途店\",\n\t\t\t\"createTime\": \"2023-08-14 10:37:50\",\n\t\t\t\"updateTime\": \"2024-01-18 14:41:16\",\n\t\t\t\"version\": 1705560075636,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/mapPackage/1747445238371164160.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"4518d2ae484448749753f102794328cd\",\n\t\t\t\"mapName\": \"食堂二楼\",\n\t\t\t\"floor\": 2,\n\t\t\t\"floorId\": \"24ec39c051cd41748e03988aff264aea\",\n\t\t\t\"buildId\": \"017a3f3304f041158e28107fc3fe30a3\",\n\t\t\t\"buildName\": \"怡沁楼\",\n\t\t\t\"createTime\": \"2023-08-15 17:10:53\",\n\t\t\t\"updateTime\": \"2024-04-10 16:07:47\",\n\t\t\t\"version\": 1692090653814,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1691376917866520576.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"1349a648005b445798653f186b635b58\",\n\t\t\t\"mapName\": \"北京捷奥泰星途体验中心\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"eb6c129a9c3248198e8300abf2a001a9\",\n\t\t\t\"buildId\": \"e37daecac1e74d5f8f0138a6a187c735\",\n\t\t\t\"buildName\": \"北京捷奥泰星途体验中心\",\n\t\t\t\"createTime\": \"2023-09-12 09:17:29\",\n\t\t\t\"updateTime\": \"2023-10-26 17:26:48\",\n\t\t\t\"version\": 1694770614834,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1702556497806860288.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"25118252d6024a48b2df128100dd4416\",\n\t\t\t\"mapName\": \"新定位地图\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"a61842ae220d4f9792780a8767ff7bea\",\n\t\t\t\"buildId\": \"1931d525d5b04f399dd7554c7cc48c8c\",\n\t\t\t\"buildName\": \"新新楼\",\n\t\t\t\"createTime\": \"2023-09-13 11:42:26\",\n\t\t\t\"updateTime\": \"2023-09-13 11:42:26\",\n\t\t\t\"version\": 1694576546472,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1701803497835110400.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"4f8c3a790ba6488ebcbf94c4a621a111\",\n\t\t\t\"mapName\": \"系统集成专用安庆2楼\",\n\t\t\t\"floor\": 2,\n\t\t\t\"floorId\": \"abb15b8c7bc94c21a21ee8b3f09c0111\",\n\t\t\t\"buildId\": \"d700b0ebbcfc4345ae0553364114b111\",\n\t\t\t\"buildName\": \"系统集成专用安庆\",\n\t\t\t\"createTime\": \"2023-11-13 10:53:25\",\n\t\t\t\"updateTime\": \"2023-11-22 10:09:05\",\n\t\t\t\"version\": 1699844005614,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1723896825847455744.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"8068197000f84a5483dabf5a6ad3707c\",\n\t\t\t\"mapName\": \"智慧楼\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"fc86319a04824122b63719b062811106\",\n\t\t\t\"buildId\": \"8afb5463ad9140aa9e0e42b9ca93e075\",\n\t\t\t\"buildName\": \"智慧楼\",\n\t\t\t\"createTime\": \"2024-03-21 10:59:27\",\n\t\t\t\"updateTime\": \"2024-04-19 18:15:07\",\n\t\t\t\"version\": 1713521707438,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/mapPackage/20240411/1778341656103198720.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t}\n\t]\n}")
- body := string("{\n\t\"msg\": \"操作成功\",\n\t\"code\": 200,\n\t\"data\": [\n\t\t{\n\t\t\t\"mapType\": \"1\",\n\t\t\t\"mapId\": \"2247aeb31ad34wwddfd9c3ba24536e52859\",\n\t\t\t\"mapName\": \"合肥演示\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"695abbcfdf99471sdfff3b9b1d0818164e7\",\n\t\t\t\"buildId\": \"7b4e8d01c08f472fabf7ccff2b2336s\",\n\t\t\t\"buildName\": \"2\",\n\t\t\t\"createTime\": \"2023-05-30 15:09:34\",\n\t\t\t\"updateTime\": \"2024-01-09 14:21:02\",\n\t\t\t\"version\": 1699948169228,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1669241329772306432.zip\",\n\t\t\t\"customAreaId\": 355,\n\t\t\t\"snCodeList\": [\n\t\t\t\t\"P1YTXS1M22AM00001\",\n\t\t\t\t\"P1YTYD1M233M00224\"\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"1965f3dbd1924f32b1031a471ea9f63c\",\n\t\t\t\"mapName\": \"充电图\",\n\t\t\t\"floor\": 0,\n\t\t\t\"floorId\": \"52798b3b8c1f4b2d9dd33ccec27c499a\",\n\t\t\t\"buildId\": \"736fe900d6484370a868ce8af49e4280\",\n\t\t\t\"buildName\": \"1\",\n\t\t\t\"createTime\": \"2023-06-21 21:27:59\",\n\t\t\t\"updateTime\": \"2023-11-01 23:07:08\",\n\t\t\t\"version\": 1687354079376,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1671510275657474048.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"207c7618965d4875b0d6b10382929e21\",\n\t\t\t\"mapName\": \"温泉\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"ad2239dc409c418688575edbfac0cd01\",\n\t\t\t\"buildId\": \"01928c7726cd461b902625780b0c64a5\",\n\t\t\t\"buildName\": \"1324\",\n\t\t\t\"createTime\": \"2023-07-05 13:57:17\",\n\t\t\t\"updateTime\": \"2023-11-30 09:21:59\",\n\t\t\t\"version\": 1691545587368,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1676470285395206144.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": [\n\t\t\t\t\"P1YTXS1M22AM00003\"\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"611028da8815415c9f7c93caf4625707\",\n\t\t\t\"mapName\": \"大厅建图测试\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"f2eda7e4022e4dbcacba56ee206c07f9\",\n\t\t\t\"buildId\": \"8cf1bdfdde7f465cbb893dba8e9a3500\",\n\t\t\t\"buildName\": \"日小楼1\",\n\t\t\t\"createTime\": \"2023-08-07 14:05:17\",\n\t\t\t\"updateTime\": \"2024-04-15 13:45:01\",\n\t\t\t\"version\": 1697632909852,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1688431099182227456.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": [\n\t\t\t\t\"P1YTXS1M22AM00002\"\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"da516324d8fc4de7a85c6c90d731f0ba\",\n\t\t\t\"mapName\": \"北京鑫雷晟星途4S店\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"458bb51e42ce4b98bc518626bb6b7c43\",\n\t\t\t\"buildId\": \"50df97f353dd49c59779ddfabdd89b66\",\n\t\t\t\"buildName\": \"北京鑫雷晟星途4S店\",\n\t\t\t\"createTime\": \"2023-08-10 11:12:18\",\n\t\t\t\"updateTime\": \"2023-09-13 18:20:46\",\n\t\t\t\"version\": 1692175845494,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1691723397236170752.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"0db5f09b8afc4a69bb095de8fb7312d8\",\n\t\t\t\"mapName\": \"8.14采集地图\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"761e1d04fa5242338f5b4ae4044fe8f0\",\n\t\t\t\"buildId\": \"0db7b180bc9b4f7599d3fc8737c73698\",\n\t\t\t\"buildName\": \"星途店\",\n\t\t\t\"createTime\": \"2023-08-14 10:37:50\",\n\t\t\t\"updateTime\": \"2024-01-18 14:41:16\",\n\t\t\t\"version\": 1705560075636,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/mapPackage/1747445238371164160.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"4518d2ae484448749753f102794328cd\",\n\t\t\t\"mapName\": \"食堂二楼\",\n\t\t\t\"floor\": 2,\n\t\t\t\"floorId\": \"24ec39c051cd41748e03988aff264aea\",\n\t\t\t\"buildId\": \"017a3f3304f041158e28107fc3fe30a3\",\n\t\t\t\"buildName\": \"怡沁楼\",\n\t\t\t\"createTime\": \"2023-08-15 17:10:53\",\n\t\t\t\"updateTime\": \"2024-04-10 16:07:47\",\n\t\t\t\"version\": 1692090653814,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1691376917866520576.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"1349a648005b445798653f186b635b58\",\n\t\t\t\"mapName\": \"北京捷奥泰星途体验中心\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"eb6c129a9c3248198e8300abf2a001a9\",\n\t\t\t\"buildId\": \"e37daecac1e74d5f8f0138a6a187c735\",\n\t\t\t\"buildName\": \"北京捷奥泰星途体验中心\",\n\t\t\t\"createTime\": \"2023-09-12 09:17:29\",\n\t\t\t\"updateTime\": \"2023-10-26 17:26:48\",\n\t\t\t\"version\": 1694770614834,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1702556497806860288.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"25118252d6024a48b2df128100dd4416\",\n\t\t\t\"mapName\": \"新定位地图\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"a61842ae220d4f9792780a8767ff7bea\",\n\t\t\t\"buildId\": \"1931d525d5b04f399dd7554c7cc48c8c\",\n\t\t\t\"buildName\": \"新新楼\",\n\t\t\t\"createTime\": \"2023-09-13 11:42:26\",\n\t\t\t\"updateTime\": \"2023-09-13 11:42:26\",\n\t\t\t\"version\": 1694576546472,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1701803497835110400.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"4f8c3a790ba6488ebcbf94c4a621a111\",\n\t\t\t\"mapName\": \"系统集成专用安庆2楼\",\n\t\t\t\"floor\": 2,\n\t\t\t\"floorId\": \"abb15b8c7bc94c21a21ee8b3f09c0111\",\n\t\t\t\"buildId\": \"d700b0ebbcfc4345ae0553364114b111\",\n\t\t\t\"buildName\": \"系统集成专用安庆\",\n\t\t\t\"createTime\": \"2023-11-13 10:53:25\",\n\t\t\t\"updateTime\": \"2023-11-22 10:09:05\",\n\t\t\t\"version\": 1699844005614,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/public/1723896825847455744.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": null\n\t\t},\n\t\t{\n\t\t\t\"mapType\": \"0\",\n\t\t\t\"mapId\": \"8068197000f84a5483dabf5a6ad3707c\",\n\t\t\t\"mapName\": \"智慧楼\",\n\t\t\t\"floor\": 1,\n\t\t\t\"floorId\": \"fc86319a04824122b63719b062811106\",\n\t\t\t\"buildId\": \"8afb5463ad9140aa9e0e42b9ca93e075\",\n\t\t\t\"buildName\": \"智慧楼\",\n\t\t\t\"createTime\": \"2024-03-21 10:59:27\",\n\t\t\t\"updateTime\": \"2024-04-19 18:15:07\",\n\t\t\t\"version\": 1713521707438,\n\t\t\t\"zipUrl\": \"https://sitfile.chinapji.com/pjicloud/mapPackage/20240411/1778341656103198720.zip\",\n\t\t\t\"customAreaId\": 334,\n\t\t\t\"snCodeList\": [\"P1YNYD1M225000112\"]\n\t\t}\n\t]\n}")
- //fmt.Println("body", body)
- var mapRes model.MapInfoRes
- err = json.Unmarshal([]byte(body), &mapRes)
- if err != nil || mapRes.Code != 200 {
- return nil, err
- }
- //fmt.Println("mapRes", mapRes)
- return mapRes.Data, nil
- }
- // 查询地图id是否存在于地图列表中
- func checkMapIdExist(mapId string, mapInfoList []model.MapInfo) (bool, model.MapInfo) {
- // 转为map
- IdMap := make(map[string]model.MapInfo)
- for _, info := range mapInfoList {
- IdMap[info.MapId] = info
- }
- record, exist := IdMap[mapId]
- return exist, record
- }
- func groupMapListByDevice(mapInfoList []model.MapInfo) map[string][]model.MapInfo {
- // 转为map
- snCodeMap := make(map[string][]model.MapInfo)
- for _, info := range mapInfoList {
- for _, snCode := range info.SnCodeList {
- if _, exist := snCodeMap[snCode]; !exist {
- snCodeMap[snCode] = make([]model.MapInfo, 0)
- snCodeMap[snCode] = append(snCodeMap[snCode], info)
- } else {
- snCodeMap[snCode] = append(snCodeMap[snCode], info)
- }
- }
- }
- return snCodeMap
- }
- // 根据场景id获取数据采集时的地图id
- func getMapIdById(id string) (string, error) {
- var mapId string
- // 下载map.json
- // 根据id获取对应的oss文件列表
- allFileList, err := util.GetExactedMapFileById(id)
- //fmt.Println("allFileList", allFileList)
- // 过滤特定后缀的文件列表
- fileList := util.FilterBySuffixes(allFileList, config.MapJsonFiltersuffixes...)
- fmt.Println("fileList", fileList)
- // 创建临时文件夹
- tmpDir, err := os.MkdirTemp("", "temp-download-*")
- fmt.Println("tmpDir:", tmpDir)
- if err != nil {
- fmt.Println("Error creating temporary directory:", err)
- return "", err
- }
- c_log.GlobalLogger.Info("创建下载-临时文件夹:", tmpDir)
- for _, file := range fileList {
- path := filepath.Join(tmpDir, filepath.Base(file))
- err = config.OssBucket.GetObjectToFile(file, path)
- if err != nil {
- fmt.Println("Error downloading file:", err)
- return "", err
- }
- c_log.GlobalLogger.Info("下载map.json文件 - 成功")
- // 读取json文件 - mapId
- // 打开文件
- file, err := os.Open(path)
- if err != nil {
- fmt.Println("Error opening file:", err)
- return "", err
- }
- defer file.Close()
- // 读取文件内容
- fileData, err := ioutil.ReadAll(file)
- if err != nil {
- fmt.Println("Error reading file:", err)
- return "", err
- }
- // Json转换为map
- var mapData map[string]interface{}
- err = json.Unmarshal(fileData, &mapData)
- data := mapData["map"].(map[string]interface{})
- // 读取mapId
- mapId = data["mapId"].(string)
- fmt.Println("mapId:", mapId)
- }
- return mapId, err
- }
|