projects.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package v1
  2. import (
  3. "encoding/json"
  4. "log"
  5. "sfbase/global"
  6. "sfis/middleware"
  7. "sfis/model/response"
  8. "sfis/service"
  9. "sfis/utils"
  10. "github.com/gin-gonic/gin"
  11. "go.uber.org/zap"
  12. )
  13. /**
  14. 项目相关接口服务
  15. */
  16. func ProjectApiRegister(router *gin.Engine) {
  17. routerGroup := router.Group("/sfis/api/v1/")
  18. routerGroup.Use(middleware.TokenAuth())
  19. {
  20. routerGroup.POST("/projectList", getProjectsList)
  21. routerGroup.POST("/projectDetail", getProjectDetail)
  22. routerGroup.POST("/projectListDetail", getProjectsListDetail)
  23. routerGroup.POST("/callLog", callLog)
  24. routerGroup.POST("/biddingInfoList", biddingInfoList)
  25. routerGroup.POST("/healthInfoList", healthInfoList)
  26. routerGroup.POST("/healthinfo", healthinfo)
  27. }
  28. }
  29. //获取项目列表接口
  30. func getProjectsList(c *gin.Context) {
  31. productID := c.MustGet("productID").(int)
  32. appID := c.MustGet("appID").(string)
  33. requestIP := c.MustGet("requestIP").(string)
  34. projectName := c.PostForm("project_name")
  35. winner := c.PostForm("winner")
  36. bidTime := c.PostForm("bid_time")
  37. p := gin.H{
  38. "project_name": projectName,
  39. "winner": winner,
  40. "bid_time": bidTime,
  41. }
  42. bs, _ := json.Marshal(p)
  43. param := string(bs)
  44. global.Logger.Info("api getProjectList:", zap.Any("productID:", productID), zap.Any("appID", appID), zap.Any("param:", param))
  45. if projectName != "" || winner != "" {
  46. utils.Check(appID, productID, c, func() ([]map[string]interface{}, int, error) {
  47. return service.ProjectListData(productID, appID, projectName, winner, bidTime, false)
  48. }, param, requestIP, false)
  49. } else {
  50. response.FailWithDetailed(response.ParamError, nil, "参数错误", c)
  51. }
  52. }
  53. //获取项目列表及详情接口
  54. func getProjectsListDetail(c *gin.Context) {
  55. productID := c.MustGet("productID").(int)
  56. appID := c.MustGet("appID").(string)
  57. requestIP := c.MustGet("requestIP").(string)
  58. winner := c.PostForm("winner")
  59. p := gin.H{
  60. "winner": winner,
  61. }
  62. bs, _ := json.Marshal(p)
  63. param := string(bs)
  64. global.Logger.Info("api getProjectList:", zap.Any("productID:", productID), zap.Any("appID", appID), zap.Any("param:", param))
  65. if winner != "" {
  66. utils.Check(appID, productID, c, func() ([]map[string]interface{}, int, error) {
  67. return service.ProjectListData(productID, appID, "", winner, "", true)
  68. }, param, requestIP, false)
  69. }
  70. }
  71. //获取项目详情
  72. func getProjectDetail(c *gin.Context) {
  73. productID := c.MustGet("productID").(int)
  74. appID := c.MustGet("appID").(string)
  75. requestIP := c.MustGet("requestIP").(string)
  76. _id := c.PostForm("project_id")
  77. id := service.SE.DecodeString(_id)
  78. p := gin.H{
  79. "project_id": _id,
  80. }
  81. bs, _ := json.Marshal(p)
  82. param := string(bs)
  83. global.Logger.Info("api getProjectDetail:", zap.Any("productID:", productID), zap.Any("appID", appID), zap.Any("param:", param))
  84. log.Println("项目id:", id)
  85. if id != "" {
  86. utils.Check(appID, productID, c, func() ([]map[string]interface{}, int, error) {
  87. return service.ProjectDetailData(id)
  88. }, param, requestIP, false)
  89. } else {
  90. response.FailWithMessage("参数缺失,或者参数格式不正确", c)
  91. }
  92. }
  93. //调用日志
  94. func callLog(c *gin.Context) {
  95. appID := c.PostForm("app_id")
  96. productId := c.PostForm("product_id")
  97. startTime := c.PostForm("start_time")
  98. endTime := c.PostForm("end_time")
  99. isSelf := c.PostForm("isSelf")
  100. isSelfs := false
  101. if isSelf != "" {
  102. isSelfs = true
  103. }
  104. datas := []map[string]interface{}{}
  105. var err error
  106. p := gin.H{
  107. "app_id": appID,
  108. "start_time": startTime,
  109. "end_time": endTime,
  110. "product_id": productId,
  111. "isSelf": isSelf,
  112. }
  113. global.Logger.Info("api callLog:", zap.Any("param:", p))
  114. datas, err = service.CallLog(appID, productId, startTime, endTime, isSelfs)
  115. if err == nil {
  116. response.FailWithDetailed(response.SUCCESS, datas, "", c)
  117. } else {
  118. response.FailWithDetailed(response.QueryError, datas, "系统查询异常", c)
  119. }
  120. }
  121. func biddingInfoList(c *gin.Context) {
  122. productID := c.MustGet("productID").(int)
  123. appID := c.MustGet("appID").(string)
  124. requestIP := c.MustGet("requestIP").(string)
  125. p := gin.H{}
  126. bs, _ := json.Marshal(p)
  127. param := string(bs)
  128. utils.Check(appID, productID, c, func() ([]map[string]interface{}, int, error) {
  129. return []map[string]interface{}{}, 200, nil
  130. }, param, requestIP, false)
  131. }
  132. func healthInfoList(c *gin.Context) {
  133. productID := c.MustGet("productID").(int)
  134. appID := c.MustGet("appID").(string)
  135. requestIP := c.MustGet("requestIP").(string)
  136. p := gin.H{}
  137. bs, _ := json.Marshal(p)
  138. param := string(bs)
  139. utils.Check(appID, productID, c, func() ([]map[string]interface{}, int, error) {
  140. return []map[string]interface{}{}, 200, nil
  141. }, param, requestIP, false)
  142. }
  143. func healthinfo(c *gin.Context) {
  144. productID := c.MustGet("productID").(int)
  145. appID := c.MustGet("appID").(string)
  146. requestIP := c.MustGet("requestIP").(string)
  147. p := gin.H{}
  148. bs, _ := json.Marshal(p)
  149. param := string(bs)
  150. utils.Check(appID, productID, c, func() ([]map[string]interface{}, int, error) {
  151. return []map[string]interface{}{}, 200, nil
  152. }, param, requestIP, false)
  153. }