projects.go 4.8 KB

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