parse_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package survey_test
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "testing"
  6. "gogs.uu.mdfitnesscao.com/cuiguohai/sdk"
  7. "gogs.uu.mdfitnesscao.com/cuiguohai/sdk/survey"
  8. )
  9. func TestTranslateDate(t *testing.T) {
  10. // 年龄
  11. age := survey.TranslateDate("1996-01-02 14:00:00", survey.DATE_TYPE_AGE, "")
  12. fmt.Println("当前年龄", age)
  13. age = survey.TranslateDate("2023-05-05 14:00:00", survey.DATE_TYPE_DATE, "")
  14. fmt.Println("当前时间", age)
  15. age = survey.TranslateDate("2023-05-05 14:00:00", survey.DATE_TYPE_DATETIME, "")
  16. fmt.Println("当前时间分钟", age)
  17. age = survey.TranslateDate("2023-05-05 14:00:00", survey.DATE_TYPE_DAY, "2000-01-01 00:00:00")
  18. fmt.Println("距离天数", age)
  19. age = survey.TranslateDate("2023-05-05 14:00:00", survey.DATE_TYPE_HOUR, "2000-01-01 00:00:00")
  20. fmt.Println("距离小时", age)
  21. }
  22. func TestMockData(t *testing.T) {
  23. var questions = map[string]sdk.SurveyAnswer{
  24. "QUName": {
  25. Type: survey.TYPE_INPUT,
  26. QuestionNo: "QUName",
  27. MultipleAnswers: true,
  28. InputAnswers: sdk.QuestionInputAnswerModel{
  29. Value: []string{"张三", "李四"},
  30. Key: "name",
  31. },
  32. },
  33. "QUAddress": {
  34. Type: survey.TYPE_INPUT,
  35. QuestionNo: "QUAddress",
  36. MultipleAnswers: false,
  37. InputAnswers: sdk.QuestionInputAnswerModel{
  38. Value: []string{"北京市朝阳区"},
  39. Key: "address",
  40. },
  41. },
  42. "QUGender": {
  43. Type: survey.TYPE_RADIO,
  44. QuestionNo: "QUGender",
  45. MultipleAnswers: false,
  46. Answer: sdk.QuestionAnswerModel{
  47. Value: "男",
  48. Key: "gender",
  49. },
  50. },
  51. "QUBirthday": {
  52. Type: survey.TYPE_DATE,
  53. QuestionNo: "QUBirthday",
  54. MultipleAnswers: false,
  55. Answer: sdk.QuestionAnswerModel{
  56. Value: "1990-01-01",
  57. Key: "birthday",
  58. },
  59. },
  60. "QUDisease": {
  61. Type: survey.TYPE_CHECKBOX,
  62. QuestionNo: "QUDisease",
  63. MultipleAnswers: false,
  64. CheckboxAnswers: []sdk.QuestionAnswerModel{
  65. {
  66. Value: "高血压",
  67. Key: "hypertension",
  68. },
  69. {
  70. Value: "糖尿病",
  71. Key: "diabetes",
  72. },
  73. },
  74. },
  75. "QUDiseaseFamily": {
  76. Type: survey.TYPE_MATRIX_CHECKBOX,
  77. QuestionNo: "QUDiseaseFamily",
  78. MultipleAnswers: false,
  79. MatrixAnswers: []sdk.QuestionMatrixAnswerModel{
  80. {
  81. XKey: "dad",
  82. XText: "父亲",
  83. YKey: "hypertension",
  84. YText: "高血压",
  85. },
  86. {
  87. XKey: "dad",
  88. XText: "父亲",
  89. YKey: "diabetes",
  90. YText: "糖尿病",
  91. },
  92. {
  93. XKey: "mom",
  94. XText: "母亲",
  95. YKey: "hypertension",
  96. YText: "高血压",
  97. },
  98. },
  99. },
  100. "QUDiseaseHistory": {
  101. Type: survey.TYPE_GROUP,
  102. QuestionNo: "QUDiseaseHistory",
  103. MultipleAnswers: true,
  104. GroupAnswers: [][]sdk.SurveyAnswer{
  105. {
  106. {
  107. Type: survey.TYPE_RADIO,
  108. QuestionNo: "QUDisease",
  109. Answer: sdk.QuestionAnswerModel{
  110. Value: "高血压",
  111. Key: "hypertension",
  112. },
  113. },
  114. {
  115. Type: survey.TYPE_DATE,
  116. QuestionNo: "QUDiseaseDate",
  117. Answer: sdk.QuestionAnswerModel{
  118. Value: "2020-01-01",
  119. Key: "hypertensionDate",
  120. },
  121. },
  122. },
  123. {
  124. {
  125. Type: survey.TYPE_RADIO,
  126. QuestionNo: "QUDisease",
  127. Answer: sdk.QuestionAnswerModel{
  128. Value: "糖尿病",
  129. Key: "diabetes",
  130. },
  131. },
  132. {
  133. Type: survey.TYPE_DATE,
  134. QuestionNo: "QUDiseaseDate",
  135. Answer: sdk.QuestionAnswerModel{
  136. Value: "2019-01-01",
  137. Key: "diabetesDate",
  138. },
  139. },
  140. },
  141. },
  142. },
  143. }
  144. jsonText, _ := json.Marshal(questions)
  145. fmt.Println(jsonText)
  146. }