|
@@ -55,6 +55,51 @@ func UploadWorldFile(ctx context.Context, c *app.RequestContext) {
|
|
|
mysql.AddWorld(ctx, world)
|
|
|
}
|
|
|
|
|
|
+// UploadSTLFile 将map.stl文件上传到oss
|
|
|
+// @router /world/upload/stlfile [GET]
|
|
|
+func UploadSTLFile(ctx context.Context, c *app.RequestContext) {
|
|
|
+
|
|
|
+ equipmentNo := c.Query("equipmentNo")
|
|
|
+ fmt.Println("equipmentNo", equipmentNo)
|
|
|
+
|
|
|
+ sceneNo := c.Query("sceneNo")
|
|
|
+ fmt.Println("sceneNo", sceneNo)
|
|
|
+
|
|
|
+ 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)
|
|
|
+
|
|
|
+ ossSTLObjectKey := config.WorldOssBasePrefix + "/" + equipmentNo + "/" + sceneNo + "/" + "map.stl"
|
|
|
+ fmt.Println("ossSTLObjectKey", ossSTLObjectKey)
|
|
|
+
|
|
|
+ f, _ := header.Open()
|
|
|
+ defer f.Close()
|
|
|
+
|
|
|
+ config.OssMutex.Lock()
|
|
|
+ err = config.OssBucket.PutObject(ossSTLObjectKey, f)
|
|
|
+ config.OssMutex.Unlock()
|
|
|
+ if err != nil {
|
|
|
+ c_log.GlobalLogger.Error("程序异常退出。上传stl文件", fileName, "->", ossSTLObjectKey, "出错:", err)
|
|
|
+ c.JSON(consts.StatusOK, entity.HttpResult{Status: false, Code: "", Message: "上传stl文件失败"})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c_log.GlobalLogger.Info("上传stl文件", fileName, "->", ossSTLObjectKey, "成功。")
|
|
|
+ c.JSON(consts.StatusOK, entity.HttpResult{Status: true, Code: "", Message: "上传stl文件成功"})
|
|
|
+
|
|
|
+ // 更新stl记录到world数据库
|
|
|
+ updateValue := model.World{SceneID: sceneNo, StlURL: &ossSTLObjectKey}
|
|
|
+ //world := model.World{ID: uuid.NewV1().String(), SceneID: sceneNo, WorldURL: ossSTLObjectKey}
|
|
|
+ err = mysql.UpdateWorld(ctx, updateValue)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// CheckWorldFileStatus 检查world文件在oss中是否存在
|
|
|
// @router /world/check/file/world/status [GET]
|
|
|
func CheckWorldFileStatus(ctx context.Context, c *app.RequestContext) {
|