check_api_controller.go 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "time"
  7. )
  8. type CheckApiController struct {
  9. MobileBaseAPIAuthController
  10. }
  11. func (c *CheckApiController) GetInspectionReference() {
  12. patient, _ := c.GetInt64("patient")
  13. if patient <= 0 {
  14. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  15. return
  16. }
  17. adminUserInfo := c.GetMobileAdminUserInfo()
  18. references, err := service.GetInspectionReference(adminUserInfo.Org.Id, 0)
  19. if err != nil {
  20. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  21. return
  22. }
  23. counts, err := service.GetPatientInspectionProjectCount(adminUserInfo.Org.Id, patient)
  24. if err != nil {
  25. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  26. return
  27. }
  28. countsMap := make(map[int64]int64, 0)
  29. for _, count := range counts {
  30. countsMap[count.ProjectId] = count.Count
  31. }
  32. referenceMap := make(map[string]*models.InspectionReferenceMap, 0)
  33. for _, reference := range references {
  34. if _, exist := referenceMap[reference.Project]; !exist {
  35. referenceMap[reference.Project] = new(models.InspectionReferenceMap)
  36. referenceMap[reference.Project].Project = reference.Project
  37. referenceMap[reference.Project].ProjectId = reference.ProjectId
  38. referenceMap[reference.Project].ProjectName = reference.ProjectName
  39. if _, cexit := countsMap[reference.ProjectId]; cexit {
  40. referenceMap[reference.Project].Count = countsMap[reference.ProjectId]
  41. }
  42. referenceMap[reference.Project].InspectionReference = make([]models.InspectionReference, 0)
  43. }
  44. referenceMap[reference.Project].InspectionReference = append(referenceMap[reference.Project].InspectionReference, *reference)
  45. }
  46. reference := make([]*models.InspectionReferenceMap, 0)
  47. for _, item := range referenceMap {
  48. reference = append(reference, item)
  49. }
  50. rl := len(reference)
  51. for index := 0; index < rl-1; index++ {
  52. for jndex := 0; jndex < rl-1-index; jndex++ {
  53. if reference[jndex].ProjectId > reference[jndex+1].ProjectId {
  54. var item models.InspectionReferenceMap
  55. item = *reference[jndex]
  56. reference[jndex] = reference[jndex+1]
  57. reference[jndex+1] = &item
  58. }
  59. }
  60. }
  61. c.ServeSuccessJSON(map[string]interface{}{
  62. "reference": reference,
  63. })
  64. return
  65. }
  66. func (c *CheckApiController) GetInspections() {
  67. patient, _ := c.GetInt64("patient_id", 0)
  68. projectId, _ := c.GetInt64("project_id", 0)
  69. if patient <= 0 || projectId <= 0 {
  70. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  71. return
  72. }
  73. page, _ := c.GetInt64("page", 0)
  74. if page <= 0 {
  75. page = 1
  76. }
  77. adminUserInfo := c.GetMobileAdminUserInfo()
  78. inspections, _, dateTime, err := service.GetPatientInspections(adminUserInfo.Org.Id, patient, projectId, page)
  79. if err != nil {
  80. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  81. return
  82. }
  83. date := ""
  84. if len(inspections) > 0 {
  85. date = time.Unix(dateTime, 0).Format("2006-01-02")
  86. }
  87. c.ServeSuccessJSON(map[string]interface{}{
  88. "inspections": inspections,
  89. "date": date,
  90. })
  91. return
  92. }