quality_api.go 7.5 KB

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