quality_api.go 7.4 KB

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