quality_api.go 7.0 KB

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