123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package bodycheck
-
- import (
- "encoding/json"
- "io/ioutil"
- "spaceofcheng/services/controllers"
- "spaceofcheng/services/models/model"
- "spaceofcheng/services/service/bodycheck"
- "spaceofcheng/services/utils"
- "sync"
-
- "github.com/astaxie/beego"
- )
-
- // 二维码不多次获取, 只获取一次即可
- // 临时的解决方案是放到全局单例对象中
- var qrCodes = make(map[string]string)
-
- var mtx = new(sync.Mutex)
-
- // BodyCheckController 商品
- type BodyCheckController struct {
- serv *bodycheck.BodyCheckServ
- controllers.BaseController
- }
-
- // Constructor 初始化 Controller
- // @Title Constructor
- // @Description 初始化 Controller, 系统自动调用
- func (c *BodyCheckController) Constructor() {
- c.serv = bodycheck.NewBodyCheckServ(c.Context)
- }
-
- // GetQrcodeURL 获取二维码信息
- func (c *BodyCheckController) GetQrcodeURL() {
- EquipmentID := c.GetString("EquipmentId")
- qrcodePrefix := beego.AppConfig.String("qrcodePrefix")
- org := c.Context.Get("org").(model.SysOrg)
-
- qrcode, has := qrCodes[qrcodePrefix+EquipmentID]
- if !has {
- var err error
- qrcode, err = utils.WxClientFor(org.OrgId).GetTempStrQRCode(qrcodePrefix + EquipmentID)
- if err != nil {
- utils.LogError("获取二维码失败: " + err.Error())
- // c.ResponseError(err)
- c.ResponseOtherEndPoint(map[string]interface{}{
- "Status": false,
- "Message": "获取二维码失败: " + err.Error(),
- })
- }
- // qrCodes[qrcodePrefix+EquipmentID] = qrcode
- }
-
- c.ResponseOtherEndPoint(map[string]interface{}{
- "Status": true,
- "Message": "",
- "QrcodeUrl": qrcode,
- })
- }
-
- // GetCheckByUser 根据用户获取体检报告
- func (c *BodyCheckController) GetCheckByUser() {
- info, err := c.serv.GetCheckByUser()
- if err != nil {
- c.ResponseError(err)
- }
- c.ResponseJSON(info)
- }
-
- // PostCheckResult 测量结果返回
- func (c *BodyCheckController) PostCheckResult() {
- // 防止并发
- mtx.Lock()
-
- r := c.Ctx.Request
- defer func() {
- r.Body.Close()
- mtx.Unlock()
- }()
-
- con, _ := ioutil.ReadAll(r.Body) //获取post的数据
-
- var formVal map[string]interface{}
- err := json.Unmarshal(con, &formVal)
- if err != nil {
- utils.LogError("参数错误:", err)
- c.ResponseOtherEndPoint(map[string]interface{}{
- "Status": false,
- "Message": err.Error(),
- })
- }
-
- err = c.serv.PostCheckResult(formVal)
- if err != nil {
- utils.LogError("操作错误:", err)
- c.ResponseOtherEndPoint(map[string]interface{}{
- "Status": false,
- "Message": err.Error(),
- })
- }
-
- c.ResponseOtherEndPoint(map[string]interface{}{
- "Status": true,
- "Message": "",
- })
- }
|