bodycheck.go 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package bodycheck
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "spaceofcheng/services/controllers"
  6. "spaceofcheng/services/models/model"
  7. "spaceofcheng/services/service/bodycheck"
  8. "spaceofcheng/services/utils"
  9. "sync"
  10. "github.com/astaxie/beego"
  11. )
  12. // 二维码不多次获取, 只获取一次即可
  13. // 临时的解决方案是放到全局单例对象中
  14. var qrCodes = make(map[string]string)
  15. var mtx = new(sync.Mutex)
  16. // BodyCheckController 商品
  17. type BodyCheckController struct {
  18. serv *bodycheck.BodyCheckServ
  19. controllers.BaseController
  20. }
  21. // Constructor 初始化 Controller
  22. // @Title Constructor
  23. // @Description 初始化 Controller, 系统自动调用
  24. func (c *BodyCheckController) Constructor() {
  25. c.serv = bodycheck.NewBodyCheckServ(c.Context)
  26. }
  27. // GetQrcodeURL 获取二维码信息
  28. func (c *BodyCheckController) GetQrcodeURL() {
  29. EquipmentID := c.GetString("EquipmentId")
  30. qrcodePrefix := beego.AppConfig.String("qrcodePrefix")
  31. org := c.Context.Get("org").(model.SysOrg)
  32. qrcode, has := qrCodes[qrcodePrefix+EquipmentID]
  33. if !has {
  34. var err error
  35. qrcode, err = utils.WxClientFor(org.OrgId).GetTempStrQRCode(qrcodePrefix + EquipmentID)
  36. if err != nil {
  37. utils.LogError("获取二维码失败: " + err.Error())
  38. // c.ResponseError(err)
  39. c.ResponseOtherEndPoint(map[string]interface{}{
  40. "Status": false,
  41. "Message": "获取二维码失败: " + err.Error(),
  42. })
  43. }
  44. // qrCodes[qrcodePrefix+EquipmentID] = qrcode
  45. }
  46. c.ResponseOtherEndPoint(map[string]interface{}{
  47. "Status": true,
  48. "Message": "",
  49. "QrcodeUrl": qrcode,
  50. })
  51. }
  52. // GetCheckByUser 根据用户获取体检报告
  53. func (c *BodyCheckController) GetCheckByUser() {
  54. info, err := c.serv.GetCheckByUser()
  55. if err != nil {
  56. c.ResponseError(err)
  57. }
  58. c.ResponseJSON(info)
  59. }
  60. // PostCheckResult 测量结果返回
  61. func (c *BodyCheckController) PostCheckResult() {
  62. // 防止并发
  63. mtx.Lock()
  64. r := c.Ctx.Request
  65. defer func() {
  66. r.Body.Close()
  67. mtx.Unlock()
  68. }()
  69. con, _ := ioutil.ReadAll(r.Body) //获取post的数据
  70. var formVal map[string]interface{}
  71. err := json.Unmarshal(con, &formVal)
  72. if err != nil {
  73. utils.LogError("参数错误:", err)
  74. c.ResponseOtherEndPoint(map[string]interface{}{
  75. "Status": false,
  76. "Message": err.Error(),
  77. })
  78. }
  79. err = c.serv.PostCheckResult(formVal)
  80. if err != nil {
  81. utils.LogError("操作错误:", err)
  82. c.ResponseOtherEndPoint(map[string]interface{}{
  83. "Status": false,
  84. "Message": err.Error(),
  85. })
  86. }
  87. c.ResponseOtherEndPoint(map[string]interface{}{
  88. "Status": true,
  89. "Message": "",
  90. })
  91. }