quality_api.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. // fmt.Println(createTime)
  106. data.CreateTime = createTime
  107. err = c.ServiceQuality.Post(data)
  108. if err != nil {
  109. c.Ctx.JSON(iris.Map{
  110. "code": -1,
  111. "msg": fmt.Sprintf("%s", err),
  112. })
  113. return
  114. }
  115. c.Ctx.JSON(iris.Map{
  116. "code": 0,
  117. "msg": "插入成功",
  118. })
  119. }
  120. // @Summary 删除记录
  121. // @Tags 质量巡检
  122. // @Description 删除质量巡检记录
  123. // @Accept json
  124. // @Produce json
  125. // @Security ApiKeyAuth
  126. // @Param id body string true "质量巡检ID"
  127. // @Success 200 {object} viewmodels.Quality "{code:0成功,msg:}"
  128. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  129. // @Router /api/quality [delete]
  130. func (c *QualityApi) Delete() {
  131. queryId := c.Ctx.URLParam("id")
  132. if queryId == "" {
  133. c.Ctx.JSON(iris.Map{"code": -1, "msg": "id不存在"})
  134. return
  135. }
  136. id, err := utils.GetDecryptId(queryId)
  137. if err != nil {
  138. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  139. return
  140. }
  141. err = c.ServiceQuality.Del(id)
  142. if err != nil {
  143. c.Ctx.JSON(iris.Map{
  144. "code": -1,
  145. "msg": fmt.Sprintf("%s", err),
  146. })
  147. return
  148. }
  149. c.Ctx.JSON(iris.Map{
  150. "code": 0,
  151. "msg": "删除成功",
  152. })
  153. }
  154. // @Summary 获取质量巡检详情
  155. // @Tags 质量巡检
  156. // @Description 获得质量巡检详情页面数据
  157. // @Accept json
  158. // @Produce json
  159. // @Security ApiKeyAuth
  160. // @Param id path string true "巡检ID"
  161. // @Success 200 {object} viewmodels.QualityDetail "{code:0成功,data:viewmodels.QualityDetail,msg:}"
  162. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  163. // @Router /api/quality/detail [get]
  164. func (c *QualityApi) GetDetail() {
  165. // 1.规则验证
  166. qualityData, err := c.ServiceQuality.ValidRule(c.Ctx)
  167. if err != nil {
  168. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  169. return
  170. }
  171. id, err := utils.GetDecryptId(qualityData.Id)
  172. if err != nil {
  173. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadForm转换异常,请检查参数"})
  174. return
  175. }
  176. pid, _ := utils.GetProjectId(c.Ctx)
  177. quality := c.ServiceQuality.GetDetail(id, pid)
  178. c.Ctx.JSON(iris.Map{
  179. "code": 0,
  180. "msg": "请求成功",
  181. "data": quality,
  182. })
  183. }
  184. // @Summary 质量概述
  185. // @Tags 质量巡检
  186. // @Description 质量概述
  187. // @Accept json
  188. // @Produce json
  189. // @Security ApiKeyAuth
  190. // @Param bidsectionId path string true "标段ID"
  191. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  192. // @Router /api/quality/survey [get]
  193. func (c *QualityApi) GetSurvey() {
  194. sectionData := viewmodels.Quality{}
  195. err := c.Ctx.ReadForm(&sectionData)
  196. if err != nil {
  197. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  198. return
  199. }
  200. err = sectionData.ValidateBidsectionId()
  201. if err != nil {
  202. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  203. return
  204. }
  205. // 标段ID
  206. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  207. if err != nil {
  208. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  209. return
  210. }
  211. // 项目ID
  212. projectId, err := utils.GetProjectId(c.Ctx)
  213. if err != nil {
  214. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  215. return
  216. }
  217. // 账号ID
  218. accountId, err := utils.GetProjectAccountId(c.Ctx)
  219. if err != nil {
  220. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  221. return
  222. }
  223. // 缓存标段ID-用于权限
  224. key := fmt.Sprintf("pm_%d_%d", projectId, accountId)
  225. lib.NewRedis().SetBidsectionIdByCache(key, bidsectionId)
  226. QualityData := c.ServiceQuality.GetSurvey(projectId, bidsectionId)
  227. c.Ctx.JSON(iris.Map{
  228. "code": 0,
  229. "msg": "",
  230. "bidsectionId": sectionData.BidsectionId,
  231. "data": QualityData,
  232. })
  233. }