quality_api.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * @description: rpc - 质量巡检
  3. * @Author: LanJianRong
  4. * @Date: 2020-11-18
  5. * @FilePath: \construction_management\web\api\quality_api.go
  6. */
  7. package api
  8. import (
  9. "fmt"
  10. "time"
  11. "github.com/kataras/iris/v12"
  12. "go.mod/conf"
  13. "go.mod/models"
  14. "go.mod/services"
  15. "go.mod/web/utils"
  16. )
  17. type QualityApi struct {
  18. //框架-web应用上下文环境
  19. Ctx iris.Context
  20. // 需要用的service
  21. ServiceQuality services.QualityService
  22. }
  23. // @Summary 质量巡检列表
  24. // @Tags 质量巡检
  25. // @Description 获得列表数据
  26. // @Accept json
  27. // @Produce json
  28. // @Security ApiKeyAuth
  29. // @Param bidsectionId path string true "标段ID"
  30. // @Param pageNo path int true "页码" eg:1
  31. // @Param pageSize path int true "页数" eg:15
  32. // @Success 200 {object} viewmodels.Quality "{code:0成功,data:viewmodels.Quality,msg:}"
  33. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  34. // @Router /api/quality [get]
  35. func (c *QualityApi) Get() {
  36. // 1.规则验证
  37. qualityData, err := c.ServiceQuality.ValidRule(c.Ctx)
  38. if err != nil {
  39. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  40. return
  41. }
  42. pid, err := utils.GetProjectId(c.Ctx)
  43. if err != nil {
  44. c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目id不存在, 请重新登录"})
  45. return
  46. }
  47. bidsectionId, err := utils.GetDecryptId(qualityData.BidsectionId)
  48. if err != nil {
  49. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  50. return
  51. }
  52. QualityData, total := c.ServiceQuality.Get(bidsectionId, pid, qualityData.PageNo, qualityData.PageSize)
  53. c.Ctx.JSON(iris.Map{
  54. "code": 0,
  55. "msg": "请求成功",
  56. "data": QualityData,
  57. "total": total,
  58. })
  59. }
  60. // @Summary 创建新的质量巡检记录
  61. // @Tags 质量巡检
  62. // @Description 创建新的质量巡检记录
  63. // @Accept json
  64. // @Produce json
  65. // @Security ApiKeyAuth
  66. // @Param bidsectionId body string true "标段ID"
  67. // @Param code body string true "编号"
  68. // @Param createTime body string true "日期"
  69. // @Param inspection body string true "检查部位"
  70. // @Param position body string true "部位"
  71. // @Success 200 {object} viewmodels.Quality "{code:0成功,msg:}"
  72. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  73. // @Router /api/quality [post]
  74. func (c *QualityApi) Post() {
  75. // 1.规则验证
  76. qualityData, err := c.ServiceQuality.ValidRule(c.Ctx)
  77. // fmt.Println("-------------------------------", err)
  78. if err != nil {
  79. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  80. return
  81. }
  82. bidsectionId, err := utils.GetDecryptId(qualityData.BidsectionId)
  83. if err != nil {
  84. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  85. return
  86. }
  87. data := models.CmQuality{}
  88. data.BidsectionId = bidsectionId
  89. data.Code = qualityData.Code
  90. data.Inspection = qualityData.Inspection
  91. data.Times = 1
  92. uid, err := utils.GetProjectAccountId(c.Ctx)
  93. if err != nil {
  94. c.Ctx.JSON(iris.Map{"code": -1, "msg": "未登录或账号失效,请重新登录"})
  95. return
  96. }
  97. data.Uid = uid
  98. createTime, err := time.Parse(conf.SysTimeform, qualityData.CreateTime)
  99. if err != nil {
  100. c.Ctx.JSON(iris.Map{"code": -1, "msg": "日期转换异常,请检查参数"})
  101. return
  102. }
  103. // fmt.Println(createTime)
  104. data.CreateTime = createTime
  105. err = c.ServiceQuality.Post(data)
  106. if err != nil {
  107. c.Ctx.JSON(iris.Map{
  108. "code": -1,
  109. "msg": fmt.Sprintf("%s", err),
  110. })
  111. return
  112. }
  113. c.Ctx.JSON(iris.Map{
  114. "code": 0,
  115. "msg": "插入成功",
  116. })
  117. }
  118. // @Summary 删除记录
  119. // @Tags 质量巡检
  120. // @Description 删除质量巡检记录
  121. // @Accept json
  122. // @Produce json
  123. // @Security ApiKeyAuth
  124. // @Param id body string true "质量巡检ID"
  125. // @Success 200 {object} viewmodels.Quality "{code:0成功,msg:}"
  126. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  127. // @Router /api/quality [delete]
  128. func (c *QualityApi) Delete() {
  129. queryId := c.Ctx.URLParam("id")
  130. if queryId == "" {
  131. c.Ctx.JSON(iris.Map{"code": -1, "msg": "id不存在"})
  132. return
  133. }
  134. id, err := utils.GetDecryptId(queryId)
  135. if err != nil {
  136. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  137. return
  138. }
  139. err = c.ServiceQuality.Del(id)
  140. if err != nil {
  141. c.Ctx.JSON(iris.Map{
  142. "code": -1,
  143. "msg": fmt.Sprintf("%s", err),
  144. })
  145. return
  146. }
  147. c.Ctx.JSON(iris.Map{
  148. "code": 0,
  149. "msg": "删除成功",
  150. })
  151. }
  152. // @Summary 获取质量巡检详情
  153. // @Tags 质量巡检
  154. // @Description 获得质量巡检详情页面数据
  155. // @Accept json
  156. // @Produce json
  157. // @Security ApiKeyAuth
  158. // @Param id path string true "巡检ID"
  159. // @Success 200 {object} viewmodels.QualityDetail "{code:0成功,data:viewmodels.QualityDetail,msg:}"
  160. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  161. // @Router /api/quality/detail [get]
  162. func (c *QualityApi) GetDetail() {
  163. // 1.规则验证
  164. qualityData, err := c.ServiceQuality.ValidRule(c.Ctx)
  165. if err != nil {
  166. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  167. return
  168. }
  169. id, err := utils.GetDecryptId(qualityData.Id)
  170. if err != nil {
  171. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadForm转换异常,请检查参数"})
  172. return
  173. }
  174. pid, _ := utils.GetProjectId(c.Ctx)
  175. quality := c.ServiceQuality.GetDetail(id, pid)
  176. c.Ctx.JSON(iris.Map{
  177. "code": 0,
  178. "msg": "请求成功",
  179. "data": quality,
  180. })
  181. }
  182. // @Summary 质量概述
  183. // @Tags 质量巡检
  184. // @Description 质量概述
  185. // @Accept json
  186. // @Produce json
  187. // @Security ApiKeyAuth
  188. // @Param bidsectionId path string true "标段ID"
  189. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  190. // @Router /api/quality/survey [get]
  191. func (c *QualityApi) GetSurvey() {
  192. // sectionData := viewmodels.Quality{}
  193. // err := c.Ctx.ReadForm(&sectionData)
  194. // if err != nil {
  195. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  196. // return
  197. // }
  198. // err = sectionData.ValidateBidsectionId()
  199. // if err != nil {
  200. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  201. // return
  202. // }
  203. // 标段ID
  204. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  205. // if err != nil {
  206. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  207. // return
  208. // }
  209. // 项目ID
  210. // projectId, err := utils.GetProjectId(c.Ctx)
  211. // if err != nil {
  212. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  213. // return
  214. // }
  215. // QualityData := c.ServiceQuality.GetSurvey(projectId, bidsectionId)
  216. // c.Ctx.JSON(iris.Map{
  217. // "code": 0,
  218. // "msg": "",
  219. // "data": QualityData,
  220. // })
  221. }