common_api_controller.go 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package new_mobile_api_controllers
  2. import (
  3. "XT_New/controllers"
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "encoding/json"
  8. "fmt"
  9. "strconv"
  10. "time"
  11. )
  12. type CommonApiController struct {
  13. controllers.BaseAuthAPIController
  14. }
  15. func (this *CommonApiController) GetInspectionMajor() {
  16. major, err := service.GetInspectionMajor(0)
  17. if err != nil {
  18. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  19. return
  20. }
  21. this.ServeSuccessJSON(map[string]interface{}{
  22. "inspection": major,
  23. })
  24. }
  25. func (this *CommonApiController) GetInspectionMinor() {
  26. id, _ := this.GetInt64("id")
  27. minor, err := service.GetInspectionMinor(id)
  28. if err != nil {
  29. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  30. return
  31. }
  32. this.ServeSuccessJSON(map[string]interface{}{
  33. "inspection": minor,
  34. })
  35. }
  36. func (this *CommonApiController) GetInspectionRange() {
  37. id, _ := this.GetInt64("id")
  38. fmt.Println("id", id)
  39. inspectionRange, err := service.GetInspectionRange(id)
  40. if err != nil {
  41. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  42. return
  43. }
  44. this.ServeSuccessJSON(map[string]interface{}{
  45. "inspectionRange": inspectionRange,
  46. })
  47. }
  48. func (this *CommonApiController) SaveConfiguration() {
  49. adminInfo := this.GetAdminUserInfo()
  50. orgid := adminInfo.CurrentOrgId
  51. dataBody := make(map[string]interface{}, 0)
  52. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  53. fmt.Println("err", err)
  54. inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
  55. fmt.Println("大项", inspectionmajor)
  56. inspectionMinor := int64(dataBody["inspectionMinor"].(float64))
  57. fmt.Println("小项", inspectionMinor)
  58. minrange := dataBody["min_range"].(string)
  59. fmt.Println("minragne", minrange)
  60. largerange := dataBody["large_range"].(string)
  61. fmt.Println("largerange", largerange)
  62. sort := dataBody["sort"].(string)
  63. sorts, err := strconv.ParseInt(sort, 10, 64)
  64. fmt.Println("sort", sort)
  65. standard := models.XtQualityControlStandard{
  66. InspectionMajor: inspectionmajor,
  67. InspectionMinor: inspectionMinor,
  68. MinRange: minrange,
  69. LargeRange: largerange,
  70. Sort: sorts,
  71. UserOrgId: orgid,
  72. Status: 1,
  73. CreatedTime: time.Now().Unix(),
  74. }
  75. fmt.Println(standard)
  76. err = service.SaveInspection(&standard)
  77. if err != nil {
  78. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  79. return
  80. }
  81. this.ServeSuccessJSON(map[string]interface{}{
  82. "standard": standard,
  83. })
  84. }
  85. func (this *CommonApiController) GetConfigurationlist() {
  86. limit, _ := this.GetInt64("limit")
  87. page, _ := this.GetInt64("page")
  88. adminUser := this.GetAdminUserInfo()
  89. orgid := adminUser.CurrentOrgId
  90. configurationlist, total, err := service.GetConfigurationlist(orgid, limit, page)
  91. if err != nil {
  92. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  93. return
  94. }
  95. this.ServeSuccessJSON(map[string]interface{}{
  96. "configurationlist": configurationlist,
  97. "total": total,
  98. })
  99. }
  100. func (this *CommonApiController) GetConfigurationDetail() {
  101. id, _ := this.GetInt64("id")
  102. fmt.Println("id是", id)
  103. detail, err := service.GetConfigurationDetail(id)
  104. if err != nil {
  105. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  106. return
  107. }
  108. this.ServeSuccessJSON(map[string]interface{}{
  109. "configurationdetail": detail,
  110. })
  111. }
  112. func (this *CommonApiController) GetAllInspectionminor() {
  113. minor, err := service.GetAllInspectionMinor(0)
  114. if err != nil {
  115. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  116. return
  117. }
  118. this.ServeSuccessJSON(map[string]interface{}{
  119. "minor": minor,
  120. })
  121. }
  122. func (this *CommonApiController) UpdateConfiguration() {
  123. id, _ := this.GetInt64("id")
  124. fmt.Println("id", id)
  125. dataBody := make(map[string]interface{}, 0)
  126. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  127. fmt.Println("err", err)
  128. inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
  129. fmt.Println("大项", inspectionmajor)
  130. inspectionMinor := int64(dataBody["inspectionMinor"].(float64))
  131. fmt.Println("小项", inspectionMinor)
  132. minrange := dataBody["min_range"].(string)
  133. fmt.Println("minragne", minrange)
  134. largerange := dataBody["large_range"].(string)
  135. fmt.Println("largerange", largerange)
  136. sort := int64(dataBody["sort"].(float64))
  137. standard := models.XtQualityControlStandard{
  138. InspectionMajor: inspectionmajor,
  139. InspectionMinor: inspectionMinor,
  140. MinRange: minrange,
  141. LargeRange: largerange,
  142. Sort: sort,
  143. }
  144. err = service.UpdarteConfiguration(&standard, id)
  145. if err != nil {
  146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  147. return
  148. }
  149. this.ServeSuccessJSON(map[string]interface{}{
  150. "standard": standard,
  151. })
  152. }
  153. func (this *CommonApiController) DeleteConfiguration() {
  154. id, _ := this.GetInt64("id")
  155. err := service.DeleteConfiguration(id)
  156. if err != nil {
  157. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
  158. return
  159. }
  160. returnData := make(map[string]interface{}, 0)
  161. returnData["msg"] = "ok"
  162. this.ServeSuccessJSON(returnData)
  163. return
  164. }