common_api_controller.go 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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) SaveInspectionTwo() {
  49. adminInfo := this.GetAdminUserInfo()
  50. orgid := adminInfo.CurrentOrgId
  51. fmt.Println("触发-------------------0")
  52. dataBody := make(map[string]interface{}, 0)
  53. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  54. fmt.Println("err", err)
  55. inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
  56. fmt.Println("大项", inspectionmajor)
  57. inspectionMinor := int64(dataBody["inspectionMinor"].(float64))
  58. fmt.Println("小项", inspectionMinor)
  59. minrange := dataBody["min_range"].(string)
  60. fmt.Println("minragne", minrange)
  61. largerange := dataBody["large_range"].(string)
  62. fmt.Println("largerange", largerange)
  63. sort := dataBody["sort"].(string)
  64. fmt.Println("sort", sort)
  65. standard := models.XtQualityControlStandard{
  66. InspectionMajor: inspectionmajor,
  67. InspectionMinor: inspectionMinor,
  68. MinRange: minrange,
  69. LargeRange: largerange,
  70. Sort: sort,
  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. }