map_service.go 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698
  1. package map_service
  2. import (
  3. "archive/zip"
  4. "context"
  5. "encoding/json"
  6. "fmt"
  7. "github.com/cloudwego/hertz/pkg/app"
  8. "github.com/cloudwego/hertz/pkg/protocol/consts"
  9. uuid "github.com/satori/go.uuid"
  10. "io"
  11. "io/ioutil"
  12. "net/http"
  13. "os"
  14. "path/filepath"
  15. "pji_desktop_http/biz/dal/mysql"
  16. "pji_desktop_http/biz/model"
  17. "pji_desktop_http/common/config"
  18. "pji_desktop_http/common/config/c_log"
  19. "pji_desktop_http/common/config/c_pji"
  20. "pji_desktop_http/common/entity"
  21. "pji_desktop_http/common/util"
  22. "pji_desktop_http/pji_client"
  23. "strconv"
  24. "strings"
  25. "time"
  26. )
  27. // CheckMapBufConsistency 检查请求id对应的mapBuf文件夹的一致性
  28. // @router /map/checkmapbuf [POST]
  29. func CheckMapBufConsistency(ctx context.Context, c *app.RequestContext) {
  30. var req []string
  31. err := c.BindAndValidate(&req)
  32. if err != nil {
  33. c.String(consts.StatusBadRequest, err.Error())
  34. return
  35. }
  36. fmt.Println(req)
  37. if len(req) == 0 { // 请求数据为空
  38. c.JSON(consts.StatusBadRequest, entity.HttpResult{Status: false, Code: "", Message: "请求数据为空。"})
  39. } else if len(req) == 1 { // 只有一条数据则直接返回
  40. c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "mapBuf文件夹数据一致。"})
  41. } else {
  42. var firstValue int
  43. for i, id := range req {
  44. // 根据id获取对应的oss文件列表
  45. fileList, err := util.GetExactedMapFileById(id)
  46. // 过滤特定后缀的文件列表
  47. fileList = util.FilterBySuffixes(fileList, config.MapBufFiltersuffixes...)
  48. //fmt.Println("Filtered Strings:", fileList)
  49. if err != nil {
  50. c.String(consts.StatusBadRequest, err.Error())
  51. return
  52. }
  53. // 获取文件列表的总大小
  54. totalSize := calculateTotalFileSize(fileList)
  55. fmt.Println("Total Size:", totalSize)
  56. // 判断不同文件列表(mapBuf)中文件的总大小是否一致
  57. if i == 0 {
  58. firstValue = totalSize
  59. } else {
  60. if totalSize != firstValue {
  61. c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "mapBuf文件夹数据不一致。"})
  62. return
  63. }
  64. }
  65. }
  66. c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "mapBuf文件夹数据一致。"})
  67. }
  68. }
  69. // DownloadOSSFile 根据objectKey下载指定的oss文件
  70. // @router /map/downloadossfile [GET]
  71. func DownloadOSSFile(ctx context.Context, c *app.RequestContext) {
  72. objectKey := c.Query("objectKey")
  73. // 从OSS下载文件
  74. reader, err := config.OssBucket.GetObject(objectKey)
  75. if err != nil {
  76. c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
  77. return
  78. }
  79. defer reader.Close()
  80. // 设置响应头
  81. c.Response.Header.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filepath.Base(objectKey)))
  82. c.Response.Header.Set("Content-Type", "binary/octet-stream")
  83. // 将文件流式传输回客户端
  84. data, err := io.ReadAll(reader)
  85. if err != nil {
  86. panic(err)
  87. }
  88. if _, err := c.Write(data); err != nil {
  89. c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
  90. return
  91. }
  92. }
  93. // DownloadMapZipFile 根据请求id从oss拉取并打包下载建图所需要的文件
  94. // @router /map/download/map/zip [GET]
  95. func DownloadMapZipFile(ctx context.Context, c *app.RequestContext) {
  96. id := c.Query("id")
  97. fmt.Println("id", id)
  98. deviceNo := c.Query("deviceNo")
  99. fmt.Println("deviceNo", deviceNo)
  100. ids := strings.Split(id, ",")
  101. fmt.Println("ids", ids)
  102. sceneId := ids[0]
  103. // 根据场景id查询地图id
  104. mapId, err := getMapIdById(sceneId)
  105. if err != nil || mapId == "" {
  106. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取mapId失败"})
  107. return
  108. }
  109. fmt.Println("mapId", mapId)
  110. // 获取朴津地图压缩包url
  111. //originUrl
  112. deviceMaps, err := mysql.QueryValidDeviceMapByMapIdAndDeviceNo(ctx, mapId, deviceNo)
  113. if err != nil {
  114. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询设备地图失败"})
  115. return
  116. }
  117. if len(deviceMaps) == 0 {
  118. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "未查询到对应设备地图"})
  119. return
  120. }
  121. deviceMap := deviceMaps[0]
  122. originUrl := deviceMap.PjiMapZipURL
  123. fmt.Println("originUrl", originUrl)
  124. // 获取原始地图map.pgm url
  125. originalMaps, err := mysql.QueryOriginalMapByMapIdAndDeviceNo(ctx, mapId, deviceNo)
  126. if err != nil {
  127. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询原始地图失败"})
  128. return
  129. }
  130. if len(originalMaps) == 0 {
  131. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "未查询到对应原始备地图"})
  132. return
  133. }
  134. originalMap := originalMaps[0]
  135. mapPgmUrl := *originalMap.CicvMapPgmURL
  136. // 根据id生成用于地图更新的压缩包
  137. filePath, tmpDir, err := generateMapZipById(ids, originUrl, mapPgmUrl)
  138. if err != nil {
  139. c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
  140. }
  141. fmt.Println("filePath", filePath)
  142. // 检查文件是否存在
  143. if _, err := os.Stat(filePath); os.IsNotExist(err) {
  144. c.JSON(http.StatusNotFound, map[string]string{"error": "File not found"})
  145. return
  146. }
  147. // 打开文件
  148. f, err := os.Open(filePath)
  149. if err != nil {
  150. c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to open file"})
  151. return
  152. }
  153. defer f.Close()
  154. // 设置响应头
  155. c.Response.Header.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filepath.Base(filePath)))
  156. c.Response.Header.Set("Content-Type", "binary/octet-stream")
  157. // 将文件流式传输回客户端
  158. data, err := io.ReadAll(f)
  159. if err != nil {
  160. panic(err)
  161. }
  162. if _, err := c.Write(data); err != nil {
  163. c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
  164. return
  165. }
  166. defer os.RemoveAll(tmpDir)
  167. }
  168. // DownloadMapBagFile 根据请求id从oss拉取并下载解析后的map.bag文件
  169. // @router /map/downloadmapbagfile [GET]
  170. func DownloadMapBagFile(ctx context.Context, c *app.RequestContext) {
  171. id := c.Query("id")
  172. fmt.Println("id: ", id)
  173. // 根据id获取对应的oss文件列表
  174. fileList, err := util.GetExactedMapFileById(id)
  175. // 过滤特定后缀的文件列表
  176. fileList = util.FilterBySuffixes(fileList, config.MapBagFiltersuffixes...)
  177. //fmt.Println("fileList", fileList)
  178. objectKey := fileList[0]
  179. // 从OSS下载文件
  180. reader, err := config.OssBucket.GetObject(objectKey)
  181. if err != nil {
  182. c.JSON(consts.StatusInternalServerError, entity.HttpResult{Status: false, Code: "", Message: "解析地图Bag下载失败。"})
  183. return
  184. }
  185. defer reader.Close()
  186. // 设置响应头
  187. c.Response.Header.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filepath.Base(objectKey)))
  188. c.Response.Header.Set("Content-Type", "binary/octet-stream")
  189. // 将文件流式传输回客户端
  190. data, err := io.ReadAll(reader)
  191. if err != nil {
  192. panic(err)
  193. }
  194. if _, err := c.Write(data); err != nil {
  195. c.JSON(consts.StatusInternalServerError, entity.HttpResult{Status: false, Code: "", Message: "解析地图Bag下载失败。"})
  196. return
  197. }
  198. c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "解析地图Bag下载成功。"})
  199. }
  200. // 根据id生成用于地图更新的压缩包
  201. func generateMapZipById(ids []string, mapZipUrl string, mapPgmUrl string) (file string, tmpDir string, err error) {
  202. // 根据id获取对应的oss文件列表
  203. allFileList, err := util.GetExactedMapFileByIds(ids)
  204. //fmt.Println("allFileList", allFileList)
  205. // 过滤特定后缀的文件列表
  206. mapBufFileList := util.FilterBySuffixes(allFileList, config.MapBufFiltersuffixes...)
  207. //fmt.Println("Filtered Strings:", fileList)
  208. if err != nil {
  209. return
  210. }
  211. // 创建临时文件夹
  212. tmpDir, err = os.MkdirTemp("", "temp-download-*")
  213. fmt.Println("tmpDir:", tmpDir)
  214. if err != nil {
  215. fmt.Println("Error creating temporary directory:", err)
  216. return "", "", err
  217. }
  218. c_log.GlobalLogger.Info("创建下载-临时文件夹:", tmpDir)
  219. // 创建根文件夹(文件打包的根目录)
  220. baseDir := filepath.Join(tmpDir, "data")
  221. if err := os.Mkdir(baseDir, 0755); err != nil {
  222. fmt.Println("Error creating subdirectory:", err)
  223. return "", "", err
  224. }
  225. c_log.GlobalLogger.Info("创建文件打包根目录:", baseDir)
  226. // 根目录创建子文件夹 bag_folder
  227. bagFolderDir := filepath.Join(baseDir, "bag_folder")
  228. if err := os.Mkdir(bagFolderDir, 0755); err != nil {
  229. fmt.Println("Error creating subdirectory:", err)
  230. return "", "", err
  231. }
  232. c_log.GlobalLogger.Info("根目录下创建bag_folder子文件夹:", bagFolderDir)
  233. // 根目录创建子文件夹 origin_map_folder
  234. originMapFolderDir := filepath.Join(baseDir, "origin_map_folder")
  235. if err := os.Mkdir(originMapFolderDir, 0755); err != nil {
  236. fmt.Println("Error creating subdirectory:", err)
  237. return "", "", err
  238. }
  239. c_log.GlobalLogger.Info("根目录下创建origin_map_folder子文件夹:", originMapFolderDir)
  240. // 子文件夹 bag_folder 创建子文件夹 mapBuf
  241. mapBufDir := filepath.Join(bagFolderDir, "mapBuf")
  242. if err := os.Mkdir(mapBufDir, 0755); err != nil {
  243. fmt.Println("Error creating subdirectory:", err)
  244. return "", "", err
  245. }
  246. c_log.GlobalLogger.Info("bag_folder创建mapBuf子文件夹 :", mapBufDir)
  247. // 从oss下载build_map.bag文件到 bag_folder 文件夹
  248. // 过滤特定后缀的文件列表
  249. buildMapBagFileList := util.FilterBySuffixes(allFileList, config.BuildMapBagFiltersuffixes...)
  250. fmt.Println("buildMapBagFileList", buildMapBagFileList)
  251. //buildMapBagFile := buildMapBagFileList[0]
  252. //err = config.OssBucket.GetObjectToFile(buildMapBagFile, filepath.Join(bagFolderDir, filepath.Base(buildMapBagFile)))
  253. for i, file := range buildMapBagFileList {
  254. fileName := "build_map" + "-" + strconv.Itoa(i) + ".bag"
  255. err = config.OssBucket.GetObjectToFile(file, filepath.Join(bagFolderDir, fileName))
  256. if err != nil {
  257. fmt.Println("Error downloading build map file:", err)
  258. return "", "", err
  259. }
  260. }
  261. c_log.GlobalLogger.Info("下载文件到bag_folder文件夹 - 成功")
  262. // 从oss下载文件到 mapBuf 文件夹
  263. for _, file := range mapBufFileList {
  264. err = config.OssBucket.GetObjectToFile(file, filepath.Join(mapBufDir, filepath.Base(file)))
  265. if err != nil {
  266. fmt.Println("Error downloading mapBuf file:", err)
  267. return "", "", err
  268. }
  269. }
  270. c_log.GlobalLogger.Info("下载文件到mapBuf子文件夹 - 成功")
  271. // 从oss下载bag文件到 origin_map_folder 文件夹
  272. // 过滤特定后缀的文件列表
  273. //originMapFileList := util.FilterBySuffixes(allFileList, config.OriginMapFiltersuffixes...)
  274. //for _, file := range originMapFileList {
  275. // err = config.OssBucket.GetObjectToFile(file, filepath.Join(originMapFolderDir, filepath.Base(file)))
  276. // if err != nil {
  277. // fmt.Println("Error downloading origin_map file:", err)
  278. // return "", "", err
  279. // }
  280. //}
  281. //err = config.OssBucket.GetObjectToFile(originUrl, filepath.Join(originMapFolderDir, filepath.Base(originUrl)))
  282. err = util.Downloadfile(mapZipUrl, filepath.Join(originMapFolderDir, filepath.Base(mapZipUrl)))
  283. if err != nil {
  284. fmt.Println("Error downloading origin_map file:", err)
  285. return "", "", err
  286. }
  287. err = config.OssBucket.GetObjectToFile(mapPgmUrl, filepath.Join(originMapFolderDir, filepath.Base(mapPgmUrl)))
  288. if err != nil {
  289. fmt.Println("Error downloading map.pgm file:", err)
  290. return "", "", err
  291. }
  292. c_log.GlobalLogger.Info("下载文件到origin_map_folder文件夹 - 成功")
  293. // 创建压缩文件
  294. zipPath := filepath.Join(tmpDir, "mapFile-"+ids[0]+".zip")
  295. zipFile, err := os.Create(zipPath)
  296. if err != nil {
  297. fmt.Println("Error creating ZIP file:", err)
  298. return "", "", err
  299. }
  300. defer zipFile.Close()
  301. zipWriter := zip.NewWriter(zipFile)
  302. defer zipWriter.Close()
  303. // 压缩文件夹
  304. if err := util.AddDirToZip(baseDir, zipWriter); err != nil {
  305. fmt.Println("Error adding directory to ZIP:", err)
  306. return "", "", err
  307. }
  308. fmt.Println("ZIP file created successfully.")
  309. c_log.GlobalLogger.Info("创建压缩文件 - 成功")
  310. return zipPath, tmpDir, nil
  311. }
  312. // UploadMapFile 将地图更新相关文件上传到oss
  313. // @router /map/upload/map [GET]
  314. func UploadMapFile(ctx context.Context, c *app.RequestContext) {
  315. equipmentNo := c.Query("equipmentNo")
  316. fmt.Println("equipmentNo", equipmentNo)
  317. mapId := c.Query("mapId")
  318. fmt.Println("mapId", mapId)
  319. timeStamp := c.Query("timeStamp")
  320. fmt.Println("timeStamp", timeStamp)
  321. header, err := c.FormFile("file")
  322. if err != nil {
  323. c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
  324. return
  325. }
  326. fileName := header.Filename
  327. fmt.Println("filename", fileName)
  328. ossObjectKey := config.UpdateMapOssBasePrefix + "/" + equipmentNo + "/" + mapId + "/" + timeStamp + "/" + fileName
  329. fmt.Println("ossObjectKey", ossObjectKey)
  330. f, _ := header.Open()
  331. defer f.Close()
  332. config.OssMutex.Lock()
  333. err = config.OssBucket.PutObject(ossObjectKey, f)
  334. config.OssMutex.Unlock()
  335. if err != nil {
  336. c_log.GlobalLogger.Error("程序异常退出。上传文件", fileName, "->", ossObjectKey, "出错:", err)
  337. c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "上传文件失败", Details: ""})
  338. return
  339. }
  340. c_log.GlobalLogger.Info("上传文件", fileName, "->", ossObjectKey, "成功。")
  341. c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "上传文件成功", Details: ossObjectKey})
  342. }
  343. // AddMapUpdateRecord 添加仿真测试记录
  344. // @router /map/add/record [GET]
  345. func AddMapUpdateRecord(ctx context.Context, c *app.RequestContext) {
  346. var record model.MapUpdate
  347. err := c.BindAndValidate(&record)
  348. record.ID = uuid.NewV1().String()
  349. fmt.Println("record", record)
  350. if err != nil {
  351. c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
  352. return
  353. }
  354. err = mysql.AddMapUpdateOneRecord(ctx, record)
  355. if err != nil {
  356. c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "地图更新记录添加失败"})
  357. return
  358. }
  359. c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "地图更新记录添加成功"})
  360. }
  361. // QueryMapUpdateRecord 根据条件查询地图更新记录
  362. // @router /map/query/update/record [GET]
  363. func QueryMapUpdateRecord(ctx context.Context, c *app.RequestContext) {
  364. var record model.MapUpdate
  365. err := c.BindAndValidate(&record)
  366. fmt.Println("record", record)
  367. var pageFlag bool
  368. if c.Query("page") != "" && c.Query("pageSize") != "" {
  369. pageFlag = true
  370. } else {
  371. pageFlag = false
  372. }
  373. page, _ := strconv.Atoi(c.Query("page"))
  374. pageSize, _ := strconv.Atoi(c.Query("pageSize"))
  375. records, count, err := mysql.QueryMapUpdateRecords(ctx, &record, pageFlag, page, pageSize)
  376. if err != nil {
  377. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "地图更新记录查询失败", Total: 0})
  378. return
  379. }
  380. output, err := json.Marshal(records)
  381. if err != nil {
  382. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "地图更新记录查询失败", Total: 0})
  383. return
  384. }
  385. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "地图更新查询成功", Data: string(output), Total: int(count)})
  386. }
  387. // TestUploadUpdateMap 测试朴津地图上传接口
  388. // @router /map/upload/update/map [GET]
  389. func TestUploadUpdateMap(ctx context.Context, c *app.RequestContext) {
  390. header, err := c.FormFile("file")
  391. if err != nil {
  392. c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
  393. return
  394. }
  395. fileName := header.Filename
  396. fmt.Println("filename", fileName)
  397. f, _ := header.Open()
  398. defer f.Close()
  399. paramMap := make(map[string]interface{})
  400. // Map<String, String> paramMap=new HashMap<>();
  401. // paramMap.put("mapId","2247aeb31ad34wwddfd9c3ba24536e52859");
  402. // paramMap.put("mapName","合肥演示");
  403. // paramMap.put("buildId"," 7b4e8d01c08f472fabf7ccff2b2336s");
  404. // paramMap.put("floorId"," 695abbcfdf99471sdfff3b9b1d0818164e7");
  405. // paramMap.put("updateType"," 7b4e8d01c08f472fabf7ccff2b2336s");
  406. // paramMap.put("floor","1");
  407. // paramMap.put("buildName"," 2");
  408. // paramMap.put("customAreaId"," 355");
  409. // paramMap.put("snCode","P1YTYD1M233M00224");
  410. // paramMap.put("fileName","1702284791385137152.zip");
  411. // paramMap.put("mapType","0");
  412. paramMap["snCode"] = "P1YNYD1M225000112"
  413. paramMap["mapId"] = "8068197000f84a5483dabf5a6ad3707c"
  414. paramMap["mapName"] = "智慧楼"
  415. paramMap["buildId"] = "8afb5463ad9140aa9e0e42b9ca93e075"
  416. paramMap["buildName"] = "智慧楼"
  417. paramMap["floorId"] = "fc86319a04824122b63719b062811106"
  418. paramMap["floor"] = "1"
  419. paramMap["customAreaId"] = "334"
  420. paramMap["updateType"] = "0"
  421. paramMap["mapType"] = "0"
  422. paramMap["filename"] = ""
  423. bytes, err := io.ReadAll(f)
  424. if err != nil {
  425. return
  426. }
  427. // 调用 朴津地图上传 接口
  428. resp, err := pji_client.ApiClient.UploadRequest(c_pji.PjiApiBaseUrl+"mapUpload", paramMap, pji_client.MapSecretId, bytes)
  429. fmt.Println(string(resp.Body()))
  430. c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "上传地图测试"})
  431. }
  432. // UpdateDeviceMapById 根据场景id维护设备地图表
  433. // @router /map/update/deviceMap/record [GET]
  434. func UpdateDeviceMapById(ctx context.Context, c *app.RequestContext) {
  435. sceneId := c.Query("sceneId")
  436. fmt.Println("sceneId", sceneId)
  437. deviceNo := c.Query("deviceNo")
  438. fmt.Println("deviceNo", deviceNo)
  439. deviceName := c.Query("deviceName")
  440. fmt.Println("deviceName", deviceName)
  441. deviceType := c.Query("deviceType")
  442. fmt.Println("deviceType", deviceType)
  443. // 根据场景id查询地图id
  444. mapId, err := getMapIdById(sceneId)
  445. if err != nil || mapId == "" {
  446. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取mapId失败"})
  447. return
  448. }
  449. fmt.Println("mapId", mapId)
  450. // 查询朴津地图列表
  451. mapInfoList, err := getMapInfoList()
  452. if err != nil || mapInfoList == nil {
  453. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取地图列表数据失败"})
  454. return
  455. }
  456. fmt.Println("mapInfoList", mapInfoList)
  457. // 判断map id是否存在于朴津地图列表中
  458. mapId = "fee84db56d254d79b85971cb4ab2e7f1" // 存在
  459. //mapId = "553d9d47f8404734997e11175f0e63f5" // 不存在
  460. exist, record := checkMapIdExist(mapId, mapInfoList)
  461. fmt.Println("exist", exist)
  462. fmt.Println("record", record)
  463. if !exist { // map id不存在于朴津地图列表中
  464. // 查询地图设备表中是否存在对应map id且有效的记录
  465. records, err := mysql.QueryValidDeviceMapByMapId(ctx, mapId)
  466. if err != nil {
  467. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: " 查询设备地图失败"})
  468. return
  469. }
  470. fmt.Println("records", records)
  471. if len(records) > 0 { // 存在,
  472. fmt.Println("设置无效")
  473. // 将对应的map id的记录设置为无效
  474. update, err := mysql.UpdateDeviceMapValidFlagByMapId(ctx, mapId, config.MAP_NOT_VALID_FLAG)
  475. if err != nil {
  476. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图状态失败"})
  477. return
  478. }
  479. fmt.Println("update", update)
  480. }
  481. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "1001", Message: "map id不存在地图列表中"})
  482. } else { // map id存在于朴津地图列表中
  483. snCodeList := record.SnCodeList
  484. for _, snCode := range snCodeList { // snCodeList 代表配置了对应map id地图的机器人sn码列表, 上限为机器人数量
  485. fmt.Println("snCode", snCode)
  486. deviceMap := model.DeviceMap{DeviceNo: snCode, DeviceName: deviceName,
  487. DeviceType: deviceType, MapID: record.MapId, MapType: record.MapType, MapName: record.MapName, FloorID: record.FloorId,
  488. Floor: strconv.Itoa(record.Floor), BuildID: record.BuildId, BuildName: record.BuildName, MapCreateTime: record.CreateTime, MapUpdateTime: record.UpdateTime,
  489. MapVersion: strconv.Itoa(record.Version), MapValidFlag: config.MAP_VALID_FLAG, PjiMapZipURL: record.ZipUrl, CustomAreaID: int32(record.CustomAreaId)}
  490. fmt.Println("deviceMap", deviceMap)
  491. deviceMap.MapVersion = "123456"
  492. // 查询[对应设备]是否存在对应map id且有效的记录
  493. records, err := mysql.QueryValidDeviceMapByMapIdAndDeviceNo(ctx, mapId, snCode)
  494. if err != nil {
  495. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: " 查询设备地图失败"})
  496. return
  497. }
  498. fmt.Println("records", records)
  499. if len(records) == 0 { // 对应设备不存在对应map id且有效的记录, 说明该设备部署了新的地图(重采或新的区域地图)
  500. // 添加记录
  501. deviceMap.ID = uuid.NewV1().String()
  502. err = mysql.AddDeviceMapOneRecord(ctx, deviceMap)
  503. if err != nil {
  504. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "添加设备地图记录失败"})
  505. return
  506. }
  507. } else if len(records) == 1 { // 对应设备存在1个对应map id且有效的记录, 说明该设备之前部署过该地图, 需要检测版本号来判断更新记录(版本号一致)还是添加记录(版本号不一致)
  508. fmt.Println("record", record)
  509. if deviceMap.MapVersion == records[0].MapVersion { // 地图列表查询到的版本与设备地图表中版本一致, 则更新记录
  510. // 更新记录
  511. deviceMap.ID = records[0].ID
  512. update, err := mysql.UpdateDeviceMapOneRecord(ctx, deviceMap)
  513. if err != nil {
  514. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图记录失败"})
  515. return
  516. }
  517. fmt.Println("update", update)
  518. } else { // 地图列表查询到的版本与设备地图表中版本不一致, 则先将之前的记录状态设置为无效, 然后添加记录
  519. // 将对应设备存在的对应map id的记录设置为无效
  520. update, err := mysql.UpdateDeviceMapValidFlagByMapIdAndDevice(ctx, mapId, snCode, config.MAP_NOT_VALID_FLAG)
  521. if err != nil {
  522. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图状态失败"})
  523. return
  524. }
  525. fmt.Println("update", update)
  526. // 添加记录
  527. deviceMap.ID = uuid.NewV1().String()
  528. err = mysql.AddDeviceMapOneRecord(ctx, deviceMap)
  529. if err != nil {
  530. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "添加设备地图记录失败"})
  531. return
  532. }
  533. }
  534. }
  535. }
  536. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "设备地图数据更新成功"})
  537. }
  538. }
  539. // CheckDeviceMapStatus 根据设备号及map id查询地图状态
  540. // @router /map/check/deviceMap/status [GET]
  541. func CheckDeviceMapStatus(ctx context.Context, c *app.RequestContext) {
  542. sceneId := c.Query("sceneId")
  543. fmt.Println("sceneId", sceneId)
  544. deviceNo := c.Query("deviceNo")
  545. fmt.Println("deviceNo", deviceNo)
  546. deviceName := c.Query("deviceName")
  547. fmt.Println("deviceName", deviceName)
  548. deviceType := c.Query("deviceType")
  549. fmt.Println("deviceType", deviceType)
  550. recordTime := c.Query("recordTime")
  551. fmt.Println("recordTime", recordTime)
  552. // 根据场景id查询地图id
  553. mapId, err := getMapIdById(sceneId)
  554. if err != nil || mapId == "" {
  555. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取mapId失败"})
  556. return
  557. }
  558. fmt.Println("mapId", mapId)
  559. // 查询 设备sn码 是否存在于 设备表中
  560. device, err := mysql.QueryDeviceByDeviceNo(ctx, deviceNo)
  561. if err != nil {
  562. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询设备记录失败"})
  563. return
  564. }
  565. fmt.Println("device", device)
  566. if device == nil { // 设备sn码 不在 设备表中
  567. record := model.Device{DeviceNo: deviceNo, DeviceName: deviceName, DeviceType: deviceType}
  568. err := mysql.AddDeviceOneRecord(ctx, record)
  569. if err != nil {
  570. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "添加设备记录失败"})
  571. return
  572. }
  573. }
  574. // 查询[对应设备]是否存在对应map id且有效的记录
  575. records, err := mysql.QueryValidDeviceMapByMapIdAndDeviceNo(ctx, mapId, deviceNo)
  576. if err != nil {
  577. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询设备地图失败"})
  578. return
  579. }
  580. fmt.Println("records", records)
  581. if len(records) == 0 { // [对应设备]不存在对应map id且有效的记录
  582. // 地图已重采/删除
  583. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "1001", Message: "地图已重采/删除, 不符合地图更新条件"})
  584. return
  585. }
  586. // 判断记录时间戳(多个记录取最晚时间戳)是否晚于地图版本时间戳,即判断记录采集后,地图是否发生更新
  587. record := records[0]
  588. versionTimeVal, _ := strconv.Atoi(record.MapVersion)
  589. fmt.Println("versionTimeVal", versionTimeVal)
  590. recordTimeVal, _ := strconv.Atoi(recordTime)
  591. fmt.Println("recordTimeVal", recordTimeVal)
  592. if versionTimeVal > recordTimeVal { // 地图已更新
  593. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "1003", Message: "数据采集后地图已更新版本, 不符合地图更新条件"})
  594. return
  595. }
  596. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "1000", Message: "记录存在,符合地图更新条件"})
  597. }
  598. // CheckUpdateMapStatus 根据设备号及map id查询地图状态
  599. // @router /map/check/updateMap/status [GET]
  600. func CheckUpdateMapStatus(ctx context.Context, c *app.RequestContext) {
  601. deviceNo := c.Query("deviceNo")
  602. fmt.Println("deviceNo", deviceNo)
  603. mapId := c.Query("mapId")
  604. fmt.Println("mapId", mapId)
  605. updateTime := c.Query("updateTime")
  606. fmt.Println("updateTime", updateTime)
  607. // 查询 设备sn码 是否存在于 设备表中
  608. device, err := mysql.QueryDeviceByDeviceNo(ctx, deviceNo)
  609. if err != nil {
  610. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询设备记录失败"})
  611. return
  612. }
  613. fmt.Println("device", device)
  614. // 查询[对应设备]是否存在对应map id且有效的记录
  615. records, err := mysql.QueryValidDeviceMapByMapIdAndDeviceNo(ctx, mapId, deviceNo)
  616. if err != nil {
  617. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询设备地图失败"})
  618. return
  619. }
  620. fmt.Println("records", records)
  621. if len(records) == 0 { // [对应设备]不存在对应map id且有效的记录
  622. // 地图已重采/删除
  623. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "1--001", Message: "地图已重采/删除, 不符合地图上传条件"})
  624. return
  625. }
  626. // 判断记录时间戳(多个记录取最晚时间戳)是否晚于地图版本时间戳,即判断记录采集后,地图是否发生更新
  627. record := records[0]
  628. versionTimeVal, _ := strconv.Atoi(record.MapVersion)
  629. fmt.Println("versionTimeVal", versionTimeVal)
  630. updateTimeVal, _ := strconv.Atoi(updateTime)
  631. fmt.Println("updateTimeVal", updateTimeVal)
  632. if versionTimeVal > updateTimeVal { // 地图已更新
  633. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "1003", Message: "数据采集后地图已更新版本, 不符合地图上传条件"})
  634. return
  635. }
  636. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "1000", Message: "记录存在,符合地图上传条件"})
  637. }
  638. // UpdateDeviceMap 根据地图列表及设备列表维护设备地图表
  639. // @router /map/update/deviceMap/record [GET]
  640. func UpdateDeviceMap(ctx context.Context, c *app.RequestContext) {
  641. // 查询朴津地图列表
  642. mapInfoList, err := getMapInfoList()
  643. if err != nil || mapInfoList == nil {
  644. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取地图列表数据失败"})
  645. return
  646. }
  647. //fmt.Println("mapInfoList", mapInfoList)
  648. snCodeMap := groupMapListByDevice(mapInfoList)
  649. fmt.Println("snCodeMap", snCodeMap)
  650. // 查询设备表
  651. devices, err := mysql.QueryAllDevices(ctx)
  652. for _, device := range devices {
  653. //fmt.Println("device", device)
  654. deviceNo := device.DeviceNo
  655. fmt.Println("deviceNo", deviceNo)
  656. if _, exist := snCodeMap[deviceNo]; !exist { // 设备不存在于朴津地图列表中, 在地图接口列表区域权限配置正确的前提下, 说明该设备没有部署地图
  657. // 查询设备地图表中是否存在有效的记录
  658. deviceMaps, err := mysql.QueryValidDeviceMapByDeviceNo(ctx, deviceNo)
  659. if err != nil {
  660. return
  661. }
  662. if len(deviceMaps) > 0 { // 之前存在有效记录
  663. // 将之前的记录有效标志设置为无效
  664. updates, err := mysql.UpdateDeviceMapValidFlagByDeviceNo(ctx, deviceNo, config.MAP_NOT_VALID_FLAG)
  665. if err != nil {
  666. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图状态失败"})
  667. return
  668. }
  669. fmt.Println("updates", updates)
  670. }
  671. } else { // 设备存在于朴津地图列表中,说明该设备当前有部署地图
  672. mapList := snCodeMap[deviceNo]
  673. fmt.Println("mapList", mapList)
  674. for _, mapInfo := range mapList {
  675. // 判断该设备对应map id是否在设备地图表中存在有效记录
  676. records, err := mysql.QueryValidDeviceMapByMapIdAndDeviceNo(ctx, mapInfo.MapId, deviceNo)
  677. if err != nil {
  678. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: " 查询设备地图失败"})
  679. return
  680. }
  681. fmt.Println("records", records)
  682. deviceMap := model.DeviceMap{DeviceNo: device.DeviceNo, DeviceName: device.DeviceName,
  683. DeviceType: device.DeviceType, MapID: mapInfo.MapId, MapType: mapInfo.MapType, MapName: mapInfo.MapName, FloorID: mapInfo.FloorId,
  684. Floor: strconv.Itoa(mapInfo.Floor), BuildID: mapInfo.BuildId, BuildName: mapInfo.BuildName, MapCreateTime: mapInfo.CreateTime, MapUpdateTime: mapInfo.UpdateTime,
  685. MapVersion: strconv.Itoa(mapInfo.Version), MapValidFlag: config.MAP_VALID_FLAG, PjiMapZipURL: mapInfo.ZipUrl, CustomAreaID: int32(mapInfo.CustomAreaId)}
  686. if len(records) == 0 { // 该设备对应map id是否在设备地图表中不存在有效记录
  687. // 添加记录
  688. deviceMap.ID = uuid.NewV1().String()
  689. fmt.Println("deviceMap", deviceMap)
  690. err = mysql.AddDeviceMapOneRecord(ctx, deviceMap)
  691. if err != nil {
  692. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "添加设备地图记录失败"})
  693. return
  694. }
  695. } else { // 该设备对应map id是否在设备地图表中存在有效记录
  696. // 判断版本号是否一致
  697. record := records[0]
  698. fmt.Println("record", record)
  699. if record.MapVersion == strconv.Itoa(mapInfo.Version) { // 版本号一致
  700. // 更新记录
  701. deviceMap.ID = record.ID
  702. update, err := mysql.UpdateDeviceMapOneRecord(ctx, deviceMap)
  703. if err != nil {
  704. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图记录失败"})
  705. return
  706. }
  707. fmt.Println("update", update)
  708. } else { // 版本号不一致
  709. // 将之前的记录有效标志设置为无效
  710. updates, err := mysql.UpdateDeviceMapValidFlagByDeviceNo(ctx, deviceNo, config.MAP_NOT_VALID_FLAG)
  711. if err != nil {
  712. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新设备地图状态失败"})
  713. return
  714. }
  715. fmt.Println("updates", updates)
  716. // 添加记录
  717. deviceMap.ID = uuid.NewV1().String()
  718. fmt.Println("deviceMap", deviceMap)
  719. err = mysql.AddDeviceMapOneRecord(ctx, deviceMap)
  720. if err != nil {
  721. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "添加设备地图记录失败"})
  722. return
  723. }
  724. }
  725. }
  726. }
  727. }
  728. }
  729. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "设备地图数据更新成功"})
  730. }
  731. // UpdateOriginalMap 根据地图列表及设备列表维护原始地图表
  732. // @router /map/update/originalMap/record [GET]
  733. func UpdateOriginalMap(ctx context.Context, c *app.RequestContext) {
  734. // 查询朴津地图列表
  735. mapInfoList, err := getMapInfoList()
  736. if err != nil || mapInfoList == nil {
  737. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取地图列表数据失败"})
  738. return
  739. }
  740. //fmt.Println("mapInfoList", mapInfoList)
  741. snCodeMap := groupMapListByDevice(mapInfoList)
  742. fmt.Println("snCodeMap", snCodeMap)
  743. // 查询设备表
  744. devices, err := mysql.QueryAllDevices(ctx)
  745. for _, device := range devices {
  746. //fmt.Println("device", device)
  747. deviceNo := device.DeviceNo
  748. fmt.Println("deviceNo", deviceNo)
  749. if _, exist := snCodeMap[deviceNo]; exist { // 设备存在于朴津地图列表中,说明该设备当前有部署地图
  750. mapList := snCodeMap[deviceNo]
  751. fmt.Println("mapList", mapList)
  752. for _, mapInfo := range mapList {
  753. records, err := mysql.QueryOriginalMapByMapIdAndDeviceNo(ctx, mapInfo.MapId, deviceNo)
  754. if err != nil {
  755. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: " 查询原始地图失败"})
  756. }
  757. fmt.Println("records", records)
  758. originalMap := model.OriginalMap{DeviceNo: device.DeviceNo, DeviceName: device.DeviceName,
  759. DeviceType: device.DeviceType, MapID: mapInfo.MapId, MapType: mapInfo.MapType, MapName: mapInfo.MapName, FloorID: mapInfo.FloorId,
  760. Floor: strconv.Itoa(mapInfo.Floor), BuildID: mapInfo.BuildId, BuildName: mapInfo.BuildName, MapCreateTime: mapInfo.CreateTime, MapUpdateTime: mapInfo.UpdateTime,
  761. MapVersion: strconv.Itoa(mapInfo.Version), PjiMapZipURL: mapInfo.ZipUrl, CustomAreaID: int32(mapInfo.CustomAreaId)}
  762. if len(records) == 0 { // 该设备对应map id是否在原始地图表中不存在记录
  763. // 添加记录
  764. originalMap.ID = uuid.NewV1().String()
  765. fmt.Println("originalMap", originalMap)
  766. err = mysql.AddOriginalMapOneRecord(ctx, originalMap)
  767. if err != nil {
  768. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "添加原始地图记录失败"})
  769. return
  770. }
  771. }
  772. }
  773. }
  774. }
  775. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "原始地图数据更新成功"})
  776. }
  777. // UploadOriginalMapById 根据id,将原始地图朴津压缩包(及其中的map.pgm)上传到oss
  778. // @router /map/upload/originalMap/oneRecord [GET]
  779. func UploadOriginalMapById(ctx context.Context, c *app.RequestContext) {
  780. sceneId := c.Query("sceneId")
  781. fmt.Println("sceneId", sceneId)
  782. deviceNo := c.Query("deviceNo")
  783. fmt.Println("deviceNo", deviceNo)
  784. // 根据场景id查询地图id
  785. mapId, err := getMapIdById(sceneId)
  786. if err != nil || mapId == "" {
  787. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取mapId失败"})
  788. return
  789. }
  790. fmt.Println("mapId", mapId)
  791. // 查询原始地图对应记录
  792. records, err := mysql.QueryOriginalMapByMapIdAndDeviceNo(ctx, mapId, deviceNo)
  793. if err != nil {
  794. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询原始地图失败"})
  795. return
  796. }
  797. fmt.Println("records", len(records))
  798. for _, record := range records {
  799. fmt.Println("record", record)
  800. var zipName string
  801. var zipPath string
  802. var destPath string
  803. updateFlag := false
  804. if record.CicvMapZipURL == nil || *record.CicvMapZipURL == "" || record.CicvMapPgmURL == nil || *record.CicvMapPgmURL == "" {
  805. updateFlag = true
  806. // 创建临时文件夹
  807. tmpDir, err := os.MkdirTemp("", "temp-download-*")
  808. fmt.Println("tmpDir:", tmpDir)
  809. if err != nil {
  810. fmt.Println("Error creating temporary directory:", err)
  811. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "创建临时文件夹失败"})
  812. return
  813. }
  814. // 下载朴津地图压缩包
  815. zipName = filepath.Base(record.PjiMapZipURL)
  816. zipPath = filepath.Join(tmpDir, zipName)
  817. destPath = filepath.Join(tmpDir, "map")
  818. err = util.Downloadfile(record.PjiMapZipURL, zipPath)
  819. if err != nil {
  820. fmt.Println("Error downloading origin_map file:", err)
  821. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "下载原始地图文件失败"})
  822. return
  823. }
  824. c_log.GlobalLogger.Info("创建下载-临时文件夹:", tmpDir)
  825. // 检查文件是否存在
  826. if _, err := os.Stat(zipPath); os.IsNotExist(err) {
  827. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "下载原始地图文件失败"})
  828. return
  829. }
  830. }
  831. // 上传朴津地图压缩包到oss
  832. if record.CicvMapZipURL == nil || *record.CicvMapZipURL == "" {
  833. ossObjectKey := config.OriginalMapOssBasePrefix + "/" + record.DeviceNo + "/" + record.MapID + "/" + record.MapVersion + "/" + zipName
  834. fmt.Println("ossObjectKey", ossObjectKey)
  835. // 打开文件
  836. f, err := os.Open(zipPath)
  837. if err != nil {
  838. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "打开原始地图文件失败"})
  839. fmt.Println("Failed to open file")
  840. return
  841. }
  842. defer f.Close()
  843. config.OssMutex.Lock()
  844. err = config.OssBucket.PutObject(ossObjectKey, f)
  845. config.OssMutex.Unlock()
  846. if err != nil {
  847. c_log.GlobalLogger.Error("程序异常退出。上传文件", zipName, "->", ossObjectKey, "出错:", err)
  848. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "上传原始地图文件失败"})
  849. return
  850. }
  851. c_log.GlobalLogger.Info("上传文件", zipName, "->", ossObjectKey, "成功。")
  852. record.CicvMapZipURL = &ossObjectKey
  853. }
  854. // 上传朴津原始地图到oss
  855. if record.CicvMapPgmURL == nil || *record.CicvMapPgmURL == "" {
  856. ossObjectKey := config.OriginalMapOssBasePrefix + "/" + record.DeviceNo + "/" + record.MapID + "/" + record.MapVersion + "/" + "map.pgm"
  857. // 压缩包解压
  858. err := Unzip(zipPath, destPath)
  859. if err != nil {
  860. fmt.Println("Error unzipping file:", err)
  861. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "解压原始地图文件失败"})
  862. return
  863. }
  864. // 文件 - map.pgm
  865. pgmPath := filepath.Join(destPath, "map.pgm")
  866. // 检查文件是否存在
  867. if _, err := os.Stat(pgmPath); os.IsNotExist(err) {
  868. fmt.Println("解压目录中map.pgm不存在")
  869. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "解压目录中map.pgm不存在"})
  870. return
  871. }
  872. // 打开文件
  873. f, err := os.Open(pgmPath)
  874. if err != nil {
  875. fmt.Println("Failed to open file")
  876. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "打开map.pgm失败"})
  877. return
  878. }
  879. defer f.Close()
  880. config.OssMutex.Lock()
  881. err = config.OssBucket.PutObject(ossObjectKey, f)
  882. config.OssMutex.Unlock()
  883. if err != nil {
  884. c_log.GlobalLogger.Error("程序异常退出。上传文件", "map.pgm", "->", ossObjectKey, "出错:", err)
  885. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "上传map.pgm失败"})
  886. return
  887. }
  888. c_log.GlobalLogger.Info("上传文件", "map.pgm", "->", ossObjectKey, "成功。")
  889. record.CicvMapPgmURL = &ossObjectKey
  890. }
  891. if updateFlag {
  892. _, err = mysql.UpdateOriginalMapOneRecord(ctx, *record)
  893. if err != nil {
  894. fmt.Println("更新原始地图失败")
  895. return
  896. }
  897. }
  898. }
  899. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "原始地图文件上传成功"})
  900. }
  901. // UploadOriginalMapWithoutHttp 将原始地图朴津压缩包(及其中的map.pgm)上传到oss
  902. func UploadOriginalMapWithoutHttp(ctx context.Context) bool {
  903. // 查询原始地图压缩包/pgm为空的记录
  904. records, err := mysql.QueryOriginalMapWithoutCicvMap(ctx)
  905. if err != nil {
  906. fmt.Println("查询原始地图失败")
  907. return false
  908. }
  909. fmt.Println("records", len(records))
  910. for _, record := range records {
  911. fmt.Println("record", record)
  912. var zipName string
  913. var zipPath string
  914. var destPath string
  915. updateFlag := false
  916. if record.CicvMapZipURL == nil || *record.CicvMapZipURL == "" || record.CicvMapPgmURL == nil || *record.CicvMapPgmURL == "" {
  917. updateFlag = true
  918. // 创建临时文件夹
  919. tmpDir, err := os.MkdirTemp("", "temp-download-*")
  920. fmt.Println("tmpDir:", tmpDir)
  921. if err != nil {
  922. fmt.Println("Error creating temporary directory:", err)
  923. return false
  924. }
  925. // 下载朴津地图压缩包
  926. zipName = filepath.Base(record.PjiMapZipURL)
  927. zipPath = filepath.Join(tmpDir, zipName)
  928. destPath = filepath.Join(tmpDir, "map")
  929. err = util.Downloadfile(record.PjiMapZipURL, zipPath)
  930. if err != nil {
  931. fmt.Println("Error downloading origin_map file:", err)
  932. return false
  933. }
  934. c_log.GlobalLogger.Info("创建下载-临时文件夹:", tmpDir)
  935. // 检查文件是否存在
  936. if _, err := os.Stat(zipPath); os.IsNotExist(err) {
  937. return false
  938. }
  939. }
  940. // 上传朴津地图压缩包到oss
  941. if record.CicvMapZipURL == nil || *record.CicvMapZipURL == "" {
  942. ossObjectKey := config.OriginalMapOssBasePrefix + "/" + record.DeviceNo + "/" + record.MapID + "/" + record.MapVersion + "/" + zipName
  943. fmt.Println("ossObjectKey", ossObjectKey)
  944. // 打开文件
  945. f, err := os.Open(zipPath)
  946. if err != nil {
  947. fmt.Println("Failed to open file")
  948. return false
  949. }
  950. defer f.Close()
  951. config.OssMutex.Lock()
  952. err = config.OssBucket.PutObject(ossObjectKey, f)
  953. config.OssMutex.Unlock()
  954. if err != nil {
  955. c_log.GlobalLogger.Error("程序异常退出。上传文件", zipName, "->", ossObjectKey, "出错:", err)
  956. return false
  957. }
  958. c_log.GlobalLogger.Info("上传文件", zipName, "->", ossObjectKey, "成功。")
  959. record.CicvMapZipURL = &ossObjectKey
  960. }
  961. // 上传朴津原始地图到oss
  962. if record.CicvMapPgmURL == nil || *record.CicvMapPgmURL == "" {
  963. ossObjectKey := config.OriginalMapOssBasePrefix + "/" + record.DeviceNo + "/" + record.MapID + "/" + record.MapVersion + "/" + "map.pgm"
  964. // 压缩包解压
  965. err := Unzip(zipPath, destPath)
  966. if err != nil {
  967. fmt.Println("Error unzipping file:", err)
  968. return false
  969. }
  970. // 文件 - map.pgm
  971. pgmPath := filepath.Join(destPath, "map.pgm")
  972. // 检查文件是否存在
  973. if _, err := os.Stat(pgmPath); os.IsNotExist(err) {
  974. fmt.Println("解压目录中map.pgm不存在")
  975. return false
  976. }
  977. // 打开文件
  978. f, err := os.Open(pgmPath)
  979. if err != nil {
  980. fmt.Println("Failed to open file")
  981. return false
  982. }
  983. defer f.Close()
  984. config.OssMutex.Lock()
  985. err = config.OssBucket.PutObject(ossObjectKey, f)
  986. config.OssMutex.Unlock()
  987. if err != nil {
  988. c_log.GlobalLogger.Error("程序异常退出。上传文件", "map.pgm", "->", ossObjectKey, "出错:", err)
  989. return false
  990. }
  991. c_log.GlobalLogger.Info("上传文件", "map.pgm", "->", ossObjectKey, "成功。")
  992. record.CicvMapPgmURL = &ossObjectKey
  993. }
  994. if updateFlag {
  995. _, err = mysql.UpdateOriginalMapOneRecord(ctx, *record)
  996. if err != nil {
  997. fmt.Println("更新原始地图失败")
  998. return false
  999. }
  1000. }
  1001. }
  1002. return true
  1003. }
  1004. // UploadPjiMapAndNotify 上传oss更新地图压缩包到朴津,并通知运维人员
  1005. // @router /map/update/pji/upload [GET]
  1006. func UploadPjiMapAndNotify(ctx context.Context, c *app.RequestContext) {
  1007. id := c.Query("id")
  1008. fmt.Println("id", id)
  1009. // 根据id查询更新地图
  1010. mapUpdate, err := mysql.QueryMapUpdateRecordById(ctx, id)
  1011. if err != nil {
  1012. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取地图更新列表失败"})
  1013. return
  1014. }
  1015. mapId := mapUpdate.MapID
  1016. fmt.Println("mapId", mapId)
  1017. deviceNo := mapUpdate.DeviceSn
  1018. fmt.Println("deviceNo", deviceNo)
  1019. UpdateMapUrl := mapUpdate.UpdateMapURL
  1020. fmt.Println("UpdateMapUrl", UpdateMapUrl)
  1021. // 查询朴津地图列表
  1022. mapInfoList, err := getMapInfoList()
  1023. if err != nil || mapInfoList == nil {
  1024. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取地图列表数据失败"})
  1025. return
  1026. }
  1027. // 查询地图id是否存在于地图列表中
  1028. exist, record := checkMapIdExist(mapId, mapInfoList)
  1029. fmt.Println("exist", exist)
  1030. fmt.Println("record", record)
  1031. if !exist {
  1032. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "1002", Message: "地图已重采/删除,不符合地图上传条件"})
  1033. return
  1034. }
  1035. // 拉取oss文件流
  1036. // 获取对象
  1037. body, err := config.OssBucket.GetObject(UpdateMapUrl)
  1038. if err != nil {
  1039. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新地图文件获取失败"})
  1040. return
  1041. }
  1042. // 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
  1043. defer body.Close()
  1044. file, err := ioutil.ReadAll(body)
  1045. if err != nil {
  1046. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新地图文件获取失败"})
  1047. return
  1048. }
  1049. paramMap := make(map[string]interface{})
  1050. //paramMap["snCode"] = "P1YNYD1M225000112"
  1051. //paramMap["mapId"] = "8068197000f84a5483dabf5a6ad3707c"
  1052. //paramMap["mapName"] = "智慧楼"
  1053. //paramMap["buildId"] = "8afb5463ad9140aa9e0e42b9ca93e075"
  1054. //paramMap["buildName"] = "智慧楼"
  1055. //paramMap["floorId"] = "fc86319a04824122b63719b062811106"
  1056. //paramMap["floor"] = "1"
  1057. //paramMap["customAreaId"] = "334"
  1058. //paramMap["updateType"] = "0"
  1059. //paramMap["mapType"] = "0"
  1060. //paramMap["filename"] = ""
  1061. paramMap["snCode"] = deviceNo
  1062. paramMap["mapId"] = mapId
  1063. paramMap["mapName"] = record.MapName
  1064. paramMap["buildId"] = record.BuildId
  1065. paramMap["buildName"] = record.BuildName
  1066. paramMap["floorId"] = record.FloorId
  1067. paramMap["floor"] = strconv.Itoa(record.Floor)
  1068. paramMap["customAreaId"] = strconv.Itoa(record.CustomAreaId)
  1069. paramMap["updateType"] = "0"
  1070. paramMap["mapType"] = record.MapType
  1071. paramMap["filename"] = ""
  1072. // 调用 朴津地图上传 接口
  1073. resp, err := pji_client.ApiClient.UploadRequest(c_pji.PjiApiBaseUrl+"mapUpload", paramMap, pji_client.MapSecretId, file)
  1074. fmt.Println(string(resp.Body()))
  1075. if err != nil {
  1076. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "上传朴津地图失败"})
  1077. return
  1078. }
  1079. // 解析结果
  1080. var mapUploadRes model.MapUploadRes
  1081. // Json转换为map
  1082. err = json.Unmarshal(resp.Body(), &mapUploadRes)
  1083. if err != nil {
  1084. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "解析响应数据失败"})
  1085. return
  1086. }
  1087. fmt.Println("mapUploadRes:", mapUploadRes)
  1088. if mapUploadRes.Code != 200 {
  1089. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "上传朴津地图失败"})
  1090. return
  1091. }
  1092. version := strconv.Itoa(mapUploadRes.Data.Version)
  1093. mapUpdate.UploadVersion = &version
  1094. mapUpdate.UpdateFlag = 1
  1095. info, err := mysql.UpdateMapUpdateOneRecord(ctx, *mapUpdate)
  1096. if err != nil {
  1097. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "修改地图更新数据失败"})
  1098. return
  1099. }
  1100. fmt.Println("info", info)
  1101. //发送修图通知
  1102. paramMap = make(map[string]interface{})
  1103. paramMap["mapId"] = mapId
  1104. paramMap["type"] = "0" // 0代表修图通知,1代表续扫通知
  1105. paramMap["customAreaId"] = record.CustomAreaId
  1106. resp, err = pji_client.ApiClient.JsonPostRequest(c_pji.PjiApiBaseUrl+"sendMsg", paramMap, pji_client.MapSecretId)
  1107. if err != nil {
  1108. return
  1109. }
  1110. fmt.Println(string(resp.Body()))
  1111. c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "上传朴津地图成功并已通知运维人员"})
  1112. }
  1113. // AddMapRescanNotifyWithHttp 查询累积地图更新率大于等于续扫阈值的记录,并通知运维人员
  1114. // @router /map/rescan/notify/add [GET]
  1115. func AddMapRescanNotifyWithHttp(ctx context.Context, c *app.RequestContext) {
  1116. // 查询朴津地图列表
  1117. mapInfoList, err := getMapInfoList()
  1118. if err != nil || mapInfoList == nil {
  1119. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取地图列表数据失败"})
  1120. return
  1121. }
  1122. // 查询地图续扫阈值
  1123. systemConfig, err := mysql.QuerySystemConfig(ctx)
  1124. if err != nil {
  1125. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取系统配置失败"})
  1126. return
  1127. }
  1128. threshold := systemConfig.RescanReminderThreshold
  1129. fmt.Println("threshold", threshold)
  1130. // 查询地图更新表中未发送续扫提醒通知的记录(续扫提醒标志为0)
  1131. mapUpdates, err := mysql.QueryMapUpdateRecordsByRescanFlag(ctx, config.MAP_NOT_RESCAN_FLAG)
  1132. if err != nil {
  1133. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "查询地图更新列表失败"})
  1134. return
  1135. }
  1136. // 记录已发送通知的地图id
  1137. // 对于同一地图id的多个符合续扫通知提醒的记录,只允许发送一次续扫通知,但相关记录均会被标记为已发送续扫提醒
  1138. mapIdList := make(map[string]bool)
  1139. for _, mapUpdate := range mapUpdates {
  1140. // 查询地图id是否存在于地图列表中
  1141. exist, record := checkMapIdExist(mapUpdate.MapID, mapInfoList)
  1142. fmt.Println("exist", exist)
  1143. fmt.Println("record", record)
  1144. if !exist {
  1145. fmt.Println("地图列表中不存在该地图id,跳过...")
  1146. continue
  1147. }
  1148. //fmt.Println("mapUpdate", mapUpdate)
  1149. updatePercentage, err := getUpdatePercentage(mapUpdate.CumulativeUpdateRate)
  1150. if err != nil {
  1151. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: err.Error()})
  1152. }
  1153. fmt.Println("updatePercentage", updatePercentage)
  1154. if updatePercentage >= threshold {
  1155. mapId := mapUpdate.MapID
  1156. if _, exits := mapIdList[mapId]; !exits {
  1157. // 发送续扫通知
  1158. paramMap := make(map[string]interface{})
  1159. paramMap["mapId"] = mapId
  1160. paramMap["type"] = "1" // 0代表修图通知,1代表续扫通知
  1161. paramMap["customAreaId"] = record.CustomAreaId
  1162. resp, err := pji_client.ApiClient.JsonPostRequest(c_pji.PjiApiBaseUrl+"sendMsg", paramMap, pji_client.MapSecretId)
  1163. if err != nil {
  1164. continue
  1165. }
  1166. fmt.Println(string(resp.Body()))
  1167. mapIdList[mapId] = true
  1168. }
  1169. // 修改续扫提醒标志
  1170. mapUpdate.RescanNotifyFlag = config.MAP_RESCAN_FLAG
  1171. thresholdStr := strconv.FormatFloat(float64(threshold), 'f', 2, 32) + "%"
  1172. fmt.Println("thresholdStr", thresholdStr)
  1173. mapUpdate.RescanNotifyThreshold = &thresholdStr
  1174. _, err := mysql.UpdateMapUpdateOneRecord(ctx, *mapUpdate)
  1175. if err != nil {
  1176. continue
  1177. }
  1178. }
  1179. }
  1180. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "更新地图续扫提醒成功"})
  1181. }
  1182. // AddMapRescanNotifyWithoutHttp 查询累积地图更新率大于等于续扫阈值的记录,并通知运维人员
  1183. func AddMapRescanNotifyWithoutHttp(ctx context.Context) bool {
  1184. // 查询朴津地图列表
  1185. mapInfoList, err := getMapInfoList()
  1186. if err != nil || mapInfoList == nil {
  1187. fmt.Println("获取地图列表数据失败")
  1188. return false
  1189. }
  1190. // 查询地图续扫阈值
  1191. systemConfig, err := mysql.QuerySystemConfig(ctx)
  1192. if err != nil {
  1193. fmt.Println("获取系统配置失败")
  1194. return false
  1195. }
  1196. threshold := systemConfig.RescanReminderThreshold
  1197. fmt.Println("threshold", threshold)
  1198. // 查询地图更新表中未发送续扫提醒通知的记录(续扫提醒标志为0)
  1199. mapUpdates, err := mysql.QueryMapUpdateRecordsByRescanFlag(ctx, config.MAP_NOT_RESCAN_FLAG)
  1200. if err != nil {
  1201. fmt.Println("查询地图更新列表失败")
  1202. return false
  1203. }
  1204. // 记录已发送通知的地图id
  1205. // 对于同一地图id的多个符合续扫通知提醒的记录,只允许发送一次续扫通知,但相关记录均会被标记为已发送续扫提醒
  1206. mapIdList := make(map[string]bool)
  1207. for _, mapUpdate := range mapUpdates {
  1208. // 查询地图id是否存在于地图列表中
  1209. exist, record := checkMapIdExist(mapUpdate.MapID, mapInfoList)
  1210. fmt.Println("exist", exist)
  1211. fmt.Println("record", record)
  1212. if !exist {
  1213. fmt.Println("地图列表中不存在该地图id,跳过...")
  1214. continue
  1215. }
  1216. //fmt.Println("mapUpdate", mapUpdate)
  1217. updatePercentage, err := getUpdatePercentage(mapUpdate.CumulativeUpdateRate)
  1218. if err != nil {
  1219. fmt.Println("error:", err)
  1220. }
  1221. fmt.Println("updatePercentage", updatePercentage)
  1222. if updatePercentage >= threshold {
  1223. mapId := mapUpdate.MapID
  1224. if _, exits := mapIdList[mapId]; !exits {
  1225. // 发送续扫通知
  1226. paramMap := make(map[string]interface{})
  1227. paramMap["mapId"] = mapId
  1228. paramMap["type"] = "1" // 0代表修图通知,1代表续扫通知
  1229. paramMap["customAreaId"] = record.CustomAreaId
  1230. resp, err := pji_client.ApiClient.JsonPostRequest(c_pji.PjiApiBaseUrl+"sendMsg", paramMap, pji_client.MapSecretId)
  1231. if err != nil {
  1232. continue
  1233. }
  1234. fmt.Println(string(resp.Body()))
  1235. mapIdList[mapId] = true
  1236. }
  1237. // 修改续扫提醒标志
  1238. mapUpdate.RescanNotifyFlag = config.MAP_RESCAN_FLAG
  1239. // 记录发送通知时的续扫提醒阈值
  1240. thresholdStr := strconv.FormatFloat(float64(threshold), 'f', 2, 32) + "%"
  1241. mapUpdate.RescanNotifyThreshold = &thresholdStr
  1242. _, err := mysql.UpdateMapUpdateOneRecord(ctx, *mapUpdate)
  1243. if err != nil {
  1244. continue
  1245. }
  1246. }
  1247. }
  1248. fmt.Println("更新地图续扫提醒成功")
  1249. return true
  1250. }
  1251. // UpdateMapDeployStatusWithoutHttp 根据地图id和版本号查询朴津地图下发情况,并更新对应地图状态
  1252. func UpdateMapDeployStatusWithoutHttp(ctx context.Context) bool {
  1253. // 查询 update_flag 为1的更新地图列表
  1254. mapUpdates, err := mysql.QueryMapUpdateRecordsByUpdateFlag(ctx, config.UPDATE_MAP_UPLOAD_FLAG)
  1255. if err != nil {
  1256. fmt.Println("获取更新地图列表失败")
  1257. return false
  1258. }
  1259. for _, mapUpdate := range mapUpdates {
  1260. //// 查询地图id是否存在于地图列表中
  1261. //exist, record := checkMapIdExist(mapUpdate.MapID, mapInfoList)
  1262. //fmt.Println("exist", exist)
  1263. //fmt.Println("record", record)
  1264. //if !exist {
  1265. // fmt.Println("地图列表中不存在该地图id,跳过...")
  1266. // continue
  1267. //}
  1268. mapDeployRes, err := checkMapDeployStatus(mapUpdate.MapID, *mapUpdate.UploadVersion)
  1269. if err != nil {
  1270. return false
  1271. }
  1272. fmt.Println("mapDeployRes", mapDeployRes)
  1273. changeFlag := false
  1274. if mapDeployRes.Code == 500 { // 地图不存在,将更新地图状态标记为无效
  1275. mapUpdate.UpdateFlag = config.UPDATE_MAP_NOT_VALID_FLAG
  1276. changeFlag = true
  1277. } else if mapDeployRes.Code == 200 {
  1278. if mapDeployRes.Data.Status == 1 {
  1279. mapUpdate.UpdateFlag = config.UPDATE_MAP_DEPLOY_FLAG
  1280. changeFlag = true
  1281. }
  1282. }
  1283. if changeFlag {
  1284. _, err := mysql.UpdateMapUpdateOneRecord(ctx, *mapUpdate)
  1285. if err != nil {
  1286. fmt.Println("修改更新地图状态失败")
  1287. return false
  1288. }
  1289. }
  1290. time.Sleep(2 * time.Second)
  1291. }
  1292. return true
  1293. }
  1294. // QueryMapRescanNotifyList 查询地图续扫提醒列表
  1295. // @router /map/rescan/notify/list [GET]
  1296. func QueryMapRescanNotifyList(ctx context.Context, c *app.RequestContext) {
  1297. var record model.MapUpdate
  1298. err := c.BindAndValidate(&record)
  1299. fmt.Println("record", record)
  1300. var pageFlag bool
  1301. if c.Query("page") != "" && c.Query("pageSize") != "" {
  1302. pageFlag = true
  1303. } else {
  1304. pageFlag = false
  1305. }
  1306. page, _ := strconv.Atoi(c.Query("page"))
  1307. pageSize, _ := strconv.Atoi(c.Query("pageSize"))
  1308. records, count, err := mysql.QueryMapRescanList(ctx, &record, pageFlag, page, pageSize)
  1309. if err != nil {
  1310. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "地图续扫提醒记录查询失败", Total: 0})
  1311. return
  1312. }
  1313. output, err := json.Marshal(records)
  1314. if err != nil {
  1315. c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "地图续扫提醒记录查询失败", Total: 0})
  1316. return
  1317. }
  1318. c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "地图续扫提醒记录查询成功", Data: string(output), Total: int(count)})
  1319. }
  1320. func getUpdatePercentage(percentageStr string) (float32, error) {
  1321. // 去掉末尾的%
  1322. valueStr := percentageStr[:len(percentageStr)-1]
  1323. //fmt.Println("valueStr", valueStr)
  1324. // 将字符串转为float32
  1325. value, err := strconv.ParseFloat(valueStr, 32)
  1326. if err != nil {
  1327. fmt.Println("err", err)
  1328. return 0, err
  1329. }
  1330. return float32(value), nil
  1331. }
  1332. // 计算oss中文件列表的总大小
  1333. func calculateTotalFileSize(fileList []string) int {
  1334. var totalSize int
  1335. for _, file := range fileList {
  1336. size, err := util.GetOSSFileSize(config.OssBucket, file) // 获取oss中单个文件的大小
  1337. if err != nil {
  1338. return 0
  1339. }
  1340. totalSize += size
  1341. }
  1342. return totalSize
  1343. }
  1344. func getTime(timeStr string, layout string) (time.Time, error) {
  1345. t, err := time.Parse(layout, timeStr)
  1346. if err != nil {
  1347. return time.Time{}, err
  1348. }
  1349. return t, nil
  1350. }
  1351. // 调用 朴津地图列表查询 接口
  1352. func getMapInfoList() ([]model.MapInfo, error) {
  1353. paramMap := make(map[string]interface{})
  1354. paramMap["mapType"] = "0"
  1355. resp, err := pji_client.ApiClient.GetRequest(c_pji.PjiApiBaseUrl+"mapList?mapType=0", paramMap, pji_client.MapSecretId)
  1356. if err != nil {
  1357. return nil, err
  1358. }
  1359. fmt.Println("resp", resp)
  1360. // 解析json响应
  1361. body := resp.Body()
  1362. //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}")
  1363. //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}")
  1364. fmt.Println("body", body)
  1365. var mapRes model.MapInfoRes
  1366. err = json.Unmarshal([]byte(body), &mapRes)
  1367. if err != nil || mapRes.Code != 200 {
  1368. return nil, err
  1369. }
  1370. //fmt.Println("mapRes", mapRes)
  1371. return mapRes.Data, nil
  1372. }
  1373. // 调用 朴津地图下发状态查询 接口
  1374. func checkMapDeployStatus(mapId string, version string) (model.MapDeployRes, error) {
  1375. paramMap := make(map[string]interface{})
  1376. paramMap["mapId"] = mapId
  1377. paramMap["version"] = version
  1378. fmt.Println("paramMap", paramMap)
  1379. resp, err := pji_client.ApiClient.GetRequestWithForm(c_pji.PjiApiBaseUrl+"getMapVersionStatus?mapId="+mapId+"&version="+version, paramMap, pji_client.MapSecretId)
  1380. if err != nil {
  1381. return model.MapDeployRes{}, err
  1382. }
  1383. //fmt.Println("resp", resp)
  1384. // 解析json响应
  1385. body := resp.Body()
  1386. //fmt.Println("body", body)
  1387. var mapRes model.MapDeployRes
  1388. err = json.Unmarshal([]byte(body), &mapRes)
  1389. fmt.Println("mapRes", mapRes)
  1390. if err != nil {
  1391. return mapRes, err
  1392. }
  1393. return mapRes, nil
  1394. }
  1395. // 查询地图id是否存在于地图列表中
  1396. func checkMapIdExist(mapId string, mapInfoList []model.MapInfo) (bool, model.MapInfo) {
  1397. // 转为map
  1398. IdMap := make(map[string]model.MapInfo)
  1399. for _, info := range mapInfoList {
  1400. IdMap[info.MapId] = info
  1401. }
  1402. record, exist := IdMap[mapId]
  1403. return exist, record
  1404. }
  1405. func groupMapListByDevice(mapInfoList []model.MapInfo) map[string][]model.MapInfo {
  1406. // 转为map
  1407. snCodeMap := make(map[string][]model.MapInfo)
  1408. for _, info := range mapInfoList {
  1409. for _, snCode := range info.SnCodeList {
  1410. if _, exist := snCodeMap[snCode]; !exist {
  1411. snCodeMap[snCode] = make([]model.MapInfo, 0)
  1412. snCodeMap[snCode] = append(snCodeMap[snCode], info)
  1413. } else {
  1414. // 判断buildId及floorId是否与snCodeMap[snCode]已记录的数据相同
  1415. for index, record := range snCodeMap[snCode] {
  1416. if record.BuildId == info.BuildId && record.FloorId == info.FloorId { // 相同则说明为同一区域的地图有多个版本,只保留一个版本
  1417. // 取最近的版本号(当前版本号为时间戳,即取时间戳最大的作为最近的版本号)
  1418. if record.Version < info.Version {
  1419. snCodeMap[snCode][index] = info
  1420. break
  1421. }
  1422. }
  1423. }
  1424. // snCodeMap[snCode]已记录的数据未找到相同区域的地图,则添加记录
  1425. snCodeMap[snCode] = append(snCodeMap[snCode], info)
  1426. }
  1427. }
  1428. }
  1429. return snCodeMap
  1430. }
  1431. // 根据场景id获取数据采集时的地图id
  1432. func getMapIdById(id string) (string, error) {
  1433. var mapId string
  1434. // 下载map.json
  1435. // 根据id获取对应的oss文件列表
  1436. allFileList, err := util.GetExactedMapFileById(id)
  1437. //fmt.Println("allFileList", allFileList)
  1438. // 过滤特定后缀的文件列表
  1439. fileList := util.FilterBySuffixes(allFileList, config.MapJsonFiltersuffixes...)
  1440. fmt.Println("fileList", fileList)
  1441. // 创建临时文件夹
  1442. tmpDir, err := os.MkdirTemp("", "temp-download-*")
  1443. fmt.Println("tmpDir:", tmpDir)
  1444. if err != nil {
  1445. fmt.Println("Error creating temporary directory:", err)
  1446. return "", err
  1447. }
  1448. c_log.GlobalLogger.Info("创建下载-临时文件夹:", tmpDir)
  1449. for _, file := range fileList {
  1450. path := filepath.Join(tmpDir, filepath.Base(file))
  1451. err = config.OssBucket.GetObjectToFile(file, path)
  1452. if err != nil {
  1453. fmt.Println("Error downloading file:", err)
  1454. return "", err
  1455. }
  1456. c_log.GlobalLogger.Info("下载map.json文件 - 成功")
  1457. // 读取json文件 - mapId
  1458. // 打开文件
  1459. file, err := os.Open(path)
  1460. if err != nil {
  1461. fmt.Println("Error opening file:", err)
  1462. return "", err
  1463. }
  1464. defer file.Close()
  1465. // 读取文件内容
  1466. fileData, err := ioutil.ReadAll(file)
  1467. if err != nil {
  1468. fmt.Println("Error reading file:", err)
  1469. return "", err
  1470. }
  1471. // Json转换为map
  1472. var mapData map[string]interface{}
  1473. err = json.Unmarshal(fileData, &mapData)
  1474. data := mapData["map"].(map[string]interface{})
  1475. // 读取mapId
  1476. mapId = data["mapId"].(string)
  1477. fmt.Println("mapId:", mapId)
  1478. }
  1479. return mapId, err
  1480. }
  1481. func Unzip(zipPath, destPath string) error {
  1482. r, err := zip.OpenReader(zipPath)
  1483. if err != nil {
  1484. fmt.Println("压缩包读取失败")
  1485. return err
  1486. }
  1487. defer r.Close()
  1488. // 遍历zip文件中的每个文件和目录
  1489. for _, f := range r.File {
  1490. // 获取文件路径信息
  1491. fileDestPath := filepath.Join(destPath, f.Name)
  1492. // 创建目标文件或目录的父目录(如果不存在的话)
  1493. if err := os.MkdirAll(filepath.Dir(fileDestPath), 0755); err != nil {
  1494. fmt.Println("创建目录失败:", err)
  1495. }
  1496. // 如果是目录,则创建对应的目录结构
  1497. if f.FileInfo().IsDir() {
  1498. continue
  1499. }
  1500. // 打开要写入的目标文件
  1501. out, err := os.OpenFile(fileDestPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
  1502. if err != nil {
  1503. return err
  1504. }
  1505. defer out.Close()
  1506. // 读取zip中的文件内容并写入到目标文件
  1507. in, err := f.Open()
  1508. if err != nil {
  1509. return err
  1510. }
  1511. defer in.Close()
  1512. _, err = io.Copy(out, in)
  1513. if err != nil {
  1514. return err
  1515. }
  1516. }
  1517. return nil
  1518. }