package controllers import ( "Medical_ERP/common/global" "Medical_ERP/common/redis" _ "Medical_ERP/common/response" "Medical_ERP/conf" "Medical_ERP/dto" "Medical_ERP/models" "Medical_ERP/services" "encoding/json" "errors" "fmt" beego "github.com/beego/beego/v2/server/web" "github.com/go-resty/resty/v2" "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser" "strings" "time" ) type MedicineController struct { BaseController } // BatchNumber 批号列表 // @Summary 批号列表 // @Description 批号列表 // @Tags 药品 // @Param data body dto.MedicineBatchNumberReq true "body" // @Success 200 {object} response.Page "{"code": 200, "data": [...]}" // @Router /medicine/batch-number [post] // @Security Bearer func (c MedicineController) BatchNumber() { s := services.Medicine{} reqData := dto.MedicineBatchNumberReq{} if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil { err = errors.New("解析表单数据异常") c.Error(global.ParseFormErr, err, err.Error()) return } list := make([]string, 0) if reqData.SpecID == 0 || reqData.EnterpriseID == 0 || reqData.ProductID == 0 { c.OK(list, "查询成功") return } err := s.GetBatchNumber(&reqData, &list, beegouser.GetDeptId(c.Ctx)) if err != nil { c.Error(global.BadRequest, err, err.Error()) return } c.OK(list, "查询成功") } // BasicDataStat 基本数据统计 // @Summary 基本数据统计 // @Description 基本数据统计 // @Tags 药品 // @Success 200 {object} response.Page "{"code": 200, "data": [...]}" // @Router /medicine/basic-data-stat [post] // @Security Bearer func (c MedicineController) BasicDataStat() { s := services.Medicine{} list, err := s.BasicDataStat(beegouser.GetDeptId(c.Ctx)) if err != nil { c.Error(global.BadRequest, err, err.Error()) return } c.OK(list, "查询成功") } // 码上放心药品查询 func (c MedicineController) MSFXQuery() { code := c.GetString("code") if len(code) == 0 { err := errors.New("码上放心追溯码不能为空") c.Error(400, err, err.Error()) return } if strings.HasPrefix(code, "9") { // 宝智达溯码平台 type Res struct { Code int Msg string Data struct { CodeNum string CreateTime string Data map[string]interface{} } } var res Res client := resty.New() resp, err := client.R().Get(conf.BZD_pcodeUrl + code) if err != nil { c.Error(400, err, err.Error()) return } if err = json.Unmarshal(resp.Body(), &res); err != nil { c.Error(400, err, err.Error()) return } if res.Code != 200 { err = errors.New(res.Msg) c.Error(400, err, err.Error()) return } info_ := make([]map[string]interface{}, 0) info_ = append(info_, res.Data.Data) c.OK(info_, "查询成功") return } MSFX_baseUrl, _ := beego.AppConfig.String("MSFX_baseUrl") var res models.MSFXResponse err := redis.GetJson(global.RedisMSFXMedicineInfo+code, &res) if err == nil { c.OK(res, "查询成功") return } client := resty.New() resp, err := client.R(). SetQueryParams(map[string]string{ "code": code, }). Get(MSFX_baseUrl) if err != nil { c.Error(400, err, "获取药品扫码信息失败") return } if err = json.Unmarshal(resp.Body(), &res); err != nil { c.Error(400, err, "获取药品扫码信息失败") return } // Unmarshal the inner "data" field which is a string containing JSON var result struct { Result models.MSFXResult `json:"result"` } err = json.Unmarshal([]byte(res.Data), &result) if err != nil { fmt.Println("Error unmarshalling inner data:", err) return } info := result.Result.Models info_ := make([]map[string]interface{}, len(info)) for i := 0; i < len(info); i++ { info_[i] = make(map[string]interface{}) //if len(info[i]["名称"].(string)) == 0 { // c.Error(400, err, "药品信息不存在") //} info_[i]["product_name"] = info[i].DrugEntBaseDTO.PhysicName info_[i]["enterprise_name"] = info[i].PUserEntDTO.EntName info_[i]["spec_name"] = fmt.Sprintf("%s×%s", info[i].DrugEntBaseDTO.PrepnSpec, info[i].DrugEntBaseDTO.PkgSpecCrit) info_[i]["dosage_form_name"] = info[i].DrugEntBaseDTO.PrepnTypeDesc info_[i]["approval_number"] = info[i].DrugEntBaseDTO.ApprovalLicenceNo if len(info[i].CodeProduceInfoDTO.ProduceInfoList) > 0 { info_[i]["quantity"] = info[i].CodeProduceInfoDTO.ProduceInfoList[0].PkgAmount info_[i]["batch_number"] = info[i].CodeProduceInfoDTO.ProduceInfoList[0].BatchNo date := info[i].CodeProduceInfoDTO.ProduceInfoList[0].ExpireDate info_[i]["expiry_date"] = fmt.Sprintf("%s-%s-%s", date[0:4], date[4:6], date[6:8]) info_[i]["produced_date"] = info[i].CodeProduceInfoDTO.ProduceInfoList[0].ProduceDateStr } } redis.SetJson(global.RedisMSFXMedicineInfo+code, info_, 7*24*time.Hour) c.OK(info_, "查询成功") }