bidsection_api.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * @description: 标段相关的接口api
  3. * @Author: CP
  4. * @Date: 2020-09-28 10:26:49
  5. * @FilePath: \construction_management\web\api\bidsection_api.go
  6. */
  7. package api
  8. import (
  9. "fmt"
  10. "strconv"
  11. "github.com/kataras/iris/v12"
  12. "go.mod/services"
  13. "go.mod/web/utils"
  14. )
  15. type BidsectionApi struct {
  16. //框架-web应用上下文环境
  17. Ctx iris.Context
  18. // 需要用的service
  19. ServiceBidsection services.BidsectionService
  20. }
  21. // 获得项目目录结构
  22. func (c *BidsectionApi) Get() {
  23. }
  24. // @Summary 新增标段
  25. // @Tags 目录相关-管理员
  26. // @Description 新增标段
  27. // @Accept json
  28. // @Produce json
  29. // @Security ApiKeyAuth
  30. // @Param folderId body string true "目录ID"
  31. // @Param name body string true "名称"
  32. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  33. // @Router /api/bidsection/create [post]
  34. func (c *BidsectionApi) PostCreate() {
  35. ErrMsg := ""
  36. // 验证内容
  37. BidsectionData, err := c.ServiceBidsection.ValidRule(c.Ctx)
  38. if err != nil {
  39. ErrMsg = utils.FormValidError(err)
  40. c.Ctx.JSON(iris.Map{
  41. "code": -1,
  42. "msg": ErrMsg,
  43. })
  44. return
  45. } else {
  46. // 获得项目ID
  47. projectIdInt, err := utils.GetProjectId(c.Ctx)
  48. if err != nil {
  49. c.Ctx.JSON(iris.Map{
  50. "code": -1,
  51. "msg": fmt.Sprintf("%s", err),
  52. })
  53. return
  54. }
  55. BidsectionData.ProjectId = strconv.Itoa(projectIdInt)
  56. // 新增标段-新增树结构里的标段
  57. err = c.ServiceBidsection.Create(BidsectionData)
  58. if err != nil {
  59. c.Ctx.JSON(iris.Map{
  60. "code": -1,
  61. "msg": fmt.Sprintf("%s", err),
  62. })
  63. return
  64. }
  65. c.Ctx.JSON(iris.Map{
  66. "code": 0,
  67. "msg": "新增成功",
  68. })
  69. }
  70. }