common_api_controller.go 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. "time"
  10. )
  11. type CommonApiController struct {
  12. controllers.BaseAuthAPIController
  13. }
  14. func (this *CommonApiController) GetInspectionMajor() {
  15. major, err := service.GetInspectionMajor(0)
  16. if err != nil {
  17. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  18. return
  19. }
  20. this.ServeSuccessJSON(map[string]interface{}{
  21. "inspection": major,
  22. })
  23. }
  24. func (this *CommonApiController) GetInspectionMinor() {
  25. id, _ := this.GetInt64("id")
  26. fmt.Println("id----------------------------------------", 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. fmt.Println(orgid)
  52. fmt.Println("触发-------------------0")
  53. dataBody := make(map[string]interface{}, 0)
  54. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  55. fmt.Println("err", err)
  56. inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
  57. fmt.Println("大项", inspectionmajor)
  58. inspectionMinor := int64(dataBody["inspectionMinor"].(float64))
  59. fmt.Println("小项", inspectionMinor)
  60. minrange := dataBody["min_range"].(string)
  61. fmt.Println("minragne", minrange)
  62. largerange := dataBody["large_range"].(string)
  63. fmt.Println("largerange", largerange)
  64. sort := dataBody["sort"].(string)
  65. fmt.Println("sort", sort)
  66. standard := models.XtQualityControlStandard{
  67. InspectionMajor: inspectionmajor,
  68. InspectionMinor: inspectionMinor,
  69. MinRange: minrange,
  70. LargeRange: largerange,
  71. Sort: sort,
  72. UserOrgId: orgid,
  73. Status: 1,
  74. CreatedTime: time.Now().Unix(),
  75. }
  76. fmt.Println(standard)
  77. err = service.SaveInspection(&standard)
  78. if err != nil {
  79. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  80. return
  81. }
  82. this.ServeSuccessJSON(map[string]interface{}{
  83. "standard": standard,
  84. })
  85. }
  86. func (this *CommonApiController) GetConfigurationlist() {
  87. adminUser := this.GetAdminUserInfo()
  88. orgid := adminUser.CurrentOrgId
  89. configurationlist, err := service.GetConfigurationlist(orgid)
  90. if err != nil {
  91. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  92. return
  93. }
  94. this.ServeSuccessJSON(map[string]interface{}{
  95. "configurationlist": configurationlist,
  96. })
  97. }