diff --git a/api/publishedGi.go b/api/publishedGi.go index 4e0e2ac..3a8adbe 100644 --- a/api/publishedGi.go +++ b/api/publishedGi.go @@ -167,7 +167,7 @@ func deletePublishedGiById(c *gin.Context) { // @Accept json // @Produce json // @Param id path int true "id" -// @Param PublishReqDto query dto.PublishReqDto true "要保存的名称" +// @Param PublishReqDto query dto.PublishToDraftReqDto true "参数" // @Success 200 {object} nil // @Failure 401 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto @@ -178,13 +178,16 @@ func saveAsDraftingFromPublish(c *gin.Context) { slog.Debug("用户拉取发布图形数据", "userId", user, "发布图数据id", idStr) id, err := strconv.Atoi(idStr) if err != nil { - panic(sys_error.New("另存为草稿失败,传入参数格式错误", err)) + panic(sys_error.New("另存为草稿失败,id解析错误", err)) } - req := dto.PublishReqDto{} + req := dto.PublishToDraftReqDto{} if err := c.ShouldBind(&req); err != nil { panic(sys_error.New("另存为草稿失败,传入参数格式错误", err)) } - service.SaveAsDraftingFromPublish(int32(id), user.(*model.User), req.Name) + var bErr *sys_error.BusinessError = service.SaveAsDraftingFromPublish(int32(id), user.(*model.User), req) + if bErr != nil { + panic(bErr) + } } // 根据Code查询发布地图数据 diff --git a/dto/published.go b/dto/published.go index c01d99a..d6b6b25 100644 --- a/dto/published.go +++ b/dto/published.go @@ -36,6 +36,12 @@ type PublishReqDto struct { Force bool `json:"force" form:"force"` } +// PublishToDraftReqDto 将发布数据另存为草稿请求 +type PublishToDraftReqDto struct { + DraftName string `json:"draftName" form:"draftName"` //草稿名称 + Category string `json:"category" form:"category"` //厂商 +} + type PublishChangeReqDto struct { Id int32 `json:"id" form:"id"` Name string `json:"name" form:"name"` diff --git a/service/publishedGi.go b/service/publishedGi.go index c48da57..8e597a0 100644 --- a/service/publishedGi.go +++ b/service/publishedGi.go @@ -175,22 +175,22 @@ func DeletePublishedById(id int32) { dbquery.ProjectPublishLink.Where(dbquery.ProjectPublishLink.Mid.In(id)).Delete() } -// 另存为草稿 -func SaveAsDraftingFromPublish(id int32, user *model.User, name string) { - num, _ := dbquery.Drafting.Where(dbquery.Drafting.Name.Eq(name)).Count() +// SaveAsDraftingFromPublish 另存为草稿 +func SaveAsDraftingFromPublish(id int32, user *model.User, req dto.PublishToDraftReqDto) *sys_error.BusinessError { + num, _ := dbquery.Drafting.Where(dbquery.Drafting.Name.Eq(req.DraftName)).Count() if num > 0 { // 处理重名情况 - panic(sys_error.New(fmt.Sprintf("草稿【%s】已存在", name))) + return sys_error.New(fmt.Sprintf("草稿【%s】已存在", req.DraftName)) } p, pv := dbquery.Published, dbquery.PublishedVersion - where := p.Select(p.Type, p.Category, pv.Proto).LeftJoin(pv, p.DataID.EqCol(pv.ID)).Where(p.ID.Eq(id), p.Status.Eq(1)) + where := p.Select(p.Type, p.Category, pv.Proto).LeftJoin(pv, p.DataID.EqCol(pv.ID)).Where(p.ID.Eq(id)) var record dto.PublishedDto err := where.Debug().Scan(&record) if err != nil { panic(sys_error.New("查询发布地图信息失败", err)) } err1 := dbquery.Drafting.Save(&model.Drafting{ - Name: name, - Category: record.Category, + Name: req.DraftName, + Category: req.Category, Proto: record.Proto, CreatorID: user.ID, CreatedAt: time.Now(), @@ -198,8 +198,9 @@ func SaveAsDraftingFromPublish(id int32, user *model.User, name string) { Type: record.Type, }) if err1 != nil { - panic(sys_error.New("保存草稿出错", err1)) + return sys_error.New("保存草稿出错", err1) } + return nil } // 查询项目关联的详细数据