Browse Source

update:修改码上放心公共接口及处理逻辑

zoie 6 months ago
parent
commit
d10d59773e
6 changed files with 114 additions and 104 deletions
  1. 1 3
      conf/app.conf
  2. 2 13
      conf/app_prov.conf
  3. 37 53
      controllers/medicine.go
  4. 4 4
      dto/stock_template.go
  5. 55 0
      models/msfx.go
  6. 15 31
      services/stock_template.go

+ 1 - 3
conf/app.conf

@@ -58,9 +58,7 @@ Service_Host = "http://127.0.0.1:8110"
 Service_RoleApiUrl = "/api/role-api"
 
 # 码上放心
-MSFX_baseUrl = "http://ykm.fjxtj.com/query.aspx"
-MSFX_user = "POCU9VN"
-MSFX_mock = false
+MSFX_baseUrl = "https://public.coldbaozhida.com/Ali_msfx/codedetail"
 
 # 七牛云静态资源
 Qiniu_AccessKey = "-8ezB_d-8-eUFTMvhOGbGzgeQRPeKQnaQ3DBcUxo"

+ 2 - 13
conf/app_prov.conf

@@ -6,13 +6,6 @@ copyrequestbody = true
 EnableDocs = true
 
 # 数据库配置(Mysql)
-# mysqlUrlPort = "192.168.11.77:3306"
-# mysqlDB = "medical_erp"
-# mysqlUser = "medical_erp"
-# mysqlPass= "XMzTDthD4By3ArjG"
-# mysqlMaxConns = 100
-# MysqlMaxOpen = 200
-# 数据库配置(Mysql)
 mysqlUrlPort = "127.0.0.1:40306"
 mysqlDB = "godown"
 mysqlUser = "godown"
@@ -35,7 +28,6 @@ slow_threshold = 200
 maxlines = 10000
 
 #redis
-# Redis_address = "192.168.11.77:6379"
 Redis_address = "127.0.0.1:43379"
 Redis_password = ""
 Redis_dbNum = "3"
@@ -48,8 +40,7 @@ FilterOnlyLoginCheckURL = "/api/role-api"
 FilterNotEnterDeptURL = "/api/medicine-template/init"
 
 # 统一身份认证
-OAuth_baseUrl = "http://192.168.11.77:8100"
-# OAuth_baseUrl = "http://127.0.0.1:6400"
+OAuth_baseUrl = "http://127.0.0.1:6400"
 # 服务发现服务信息
 Service_number = "q9YeglML"
 Service_authCode = "3EDJRaagFTVVo2Ilo80nHJfLVN1O1234"
@@ -58,9 +49,7 @@ Service_Host = "http://127.0.0.1:8110"
 Service_RoleApiUrl = "/api/role-api"
 
 # 码上放心
-MSFX_baseUrl = "http://ykm.fjxtj.com/query.aspx"
-MSFX_user = "POCU9VN"
-MSFX_mock = false
+MSFX_baseUrl = "https://public.coldbaozhida.com/Ali_msfx/codedetail"
 
 # 七牛云静态资源
 Qiniu_AccessKey = "-8ezB_d-8-eUFTMvhOGbGzgeQRPeKQnaQ3DBcUxo"

+ 37 - 53
controllers/medicine.go

@@ -6,8 +6,8 @@ import (
 	_ "Medical_ERP/common/response"
 	"Medical_ERP/conf"
 	"Medical_ERP/dto"
+	"Medical_ERP/models"
 	"Medical_ERP/services"
-	"Medical_ERP/utils"
 	"encoding/json"
 	"errors"
 	"fmt"
@@ -40,6 +40,10 @@ func (c MedicineController) BatchNumber() {
 	}
 
 	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())
@@ -115,51 +119,16 @@ func (c MedicineController) MSFXQuery() {
 	}
 
 	MSFX_baseUrl, _ := beego.AppConfig.String("MSFX_baseUrl")
-	MSFX_user, _ := beego.AppConfig.String("MSFX_user")
-	MSFX_mock := beego.AppConfig.DefaultBool("MSFX_mock", true)
-
-	info := make([]map[string]interface{}, 0)
-	if MSFX_mock {
-		mock := map[string]interface{}{
-			"名称":     "替硝唑片" + strings.ToUpper(utils.GenerateAppKey(2)),
-			"批号":     strings.ToUpper(utils.GenerateAppKey(4)),
-			"有效期至": "20250619",
-			"包装数量": "1",
-			"生产日期": "2023-06-20",
-			"批准文号": "国药准字H20033090",
-			"效期":     "24月",
-			"药品类别": "普通药品",
-			"规格":     "8片/盒",
-			"规格摘要": "0.5g",
-			"类型":     "片剂",
-			"厂家":     "山东鲁抗医药集团赛特有限责任公司",
-		}
-		mock_ := make(map[string]interface{})
-		mock_["product_name"] = mock["名称"]
-		mock_["enterprise_name"] = mock["厂家"]
-		mock_["quantity"] = mock["包装数量"]
-		mock_["spec_name"] = fmt.Sprintf("%s×%s", mock["规格摘要"], mock["规格"])
-		mock_["dosage_form_name"] = mock["类型"]
-		mock_["batch_number"] = mock["批号"]
-		date := mock["有效期至"].(string)
-		mock_["expiry_date"] = fmt.Sprintf("%s-%s-%s", date[0:4], date[4:6], date[6:8])
-		mock_["produced_date"] = mock["生产日期"]
-		mock_["approval_number"] = mock["批准文号"]
-
-		info = append(info, mock_)
-		c.OK(info, "查询成功")
-		return
-	}
 
-	err := redis.GetJson(global.RedisMSFXMedicineInfo+code, &info)
+	var res models.MSFXResponse
+	err := redis.GetJson(global.RedisMSFXMedicineInfo+code, &res)
 	if err == nil {
-		c.OK(info, "查询成功")
+		c.OK(res, "查询成功")
 		return
 	}
 	client := resty.New()
 	resp, err := client.R().
 		SetQueryParams(map[string]string{
-			"user": MSFX_user,
 			"code": code,
 		}).
 		Get(MSFX_baseUrl)
@@ -168,28 +137,43 @@ func (c MedicineController) MSFXQuery() {
 		c.Error(400, err, "获取药品扫码信息失败")
 		return
 	}
-
-	if err = json.Unmarshal(resp.Body(), &info); err != nil {
+	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, "药品信息不存在")
+		//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
 		}
-		info_[i]["product_name"] = info[i]["名称"]
-		info_[i]["enterprise_name"] = info[i]["厂家"]
-		info_[i]["quantity"] = info[i]["包装数量"]
-		info_[i]["spec_name"] = fmt.Sprintf("%s×%s", info[i]["规格摘要"], info[i]["规格"])
-		info_[i]["dosage_form_name"] = info[i]["类型"]
-		info_[i]["batch_number"] = info[i]["批号"]
-		date := info[i]["有效期至"].(string)
-		info_[i]["expiry_date"] = fmt.Sprintf("%s-%s-%s", date[0:4], date[4:6], date[6:8])
-		info_[i]["produced_date"] = info[i]["生产日期"]
-		info_[i]["approval_number"] = info[i]["批准文号"]
 	}
 
 	redis.SetJson(global.RedisMSFXMedicineInfo+code, info_, 7*24*time.Hour)

+ 4 - 4
dto/stock_template.go

@@ -217,10 +217,10 @@ type StockStatListReq struct {
 
 // StockStatListReq 列表或者搜索使用结构体
 type GetStockStatReq struct {
-	ProductID    int    `json:"productId"`    // 药品名称id
-	EnterpriseID int    `json:"enterpriseId"` // 生产企业id
-	SpecID       int    `json:"specId"`       // 规格id
-	BatchNumber  string `json:"batchNumber"`  // 批号
+	ProductID    int    `json:"product_id"`    // 药品名称id
+	EnterpriseID int    `json:"enterprise_id"` // 生产企业id
+	SpecID       int    `json:"spec_id"`       // 规格id
+	BatchNumber  string `json:"batch_number"`  // 批号
 }
 
 // StockStatReq 列表或者搜索使用结构体

+ 55 - 0
models/msfx.go

@@ -0,0 +1,55 @@
+package models
+
+// Define the struct types according to the JSON structure
+type MSFXResponse struct {
+	Data    string `json:"data"`
+	Message string `json:"message"`
+	Status  int    `json:"status"`
+}
+
+type MSFXResult struct {
+	Models          []MSFXModel `json:"models"`
+	MsgCode         string      `json:"msg_code"`
+	MsgInfo         string      `json:"msg_info"`
+	ResponseSuccess bool        `json:"response_success"`
+}
+
+type MSFXModel struct {
+	Code               string                 `json:"code"`
+	CodeProduceInfoDTO MSFXCodeProduceInfoDTO `json:"code_produce_info_d_t_o"`
+	CodeStatusTypeDTO  MSFXCodeStatusTypeDTO  `json:"code_status_type_d_t_o"`
+	DrugEntBaseDTO     MSFXDrugEntBaseDTO     `json:"drug_ent_base_d_t_o"`
+	PUserEntDTO        MSFXPUserEntDTO        `json:"p_user_ent_d_t_o"`
+	PackageLevel       string                 `json:"package_level"`
+}
+
+type MSFXCodeProduceInfoDTO struct {
+	ProduceInfoList []MSFXProduceInfo `json:"produce_info_list"`
+}
+
+type MSFXProduceInfo struct {
+	BatchNo        string `json:"batch_no"`
+	ExpireDate     string `json:"expire_date"`
+	PkgAmount      string `json:"pkg_amount"`
+	ProduceDateStr string `json:"produce_date_str"`
+}
+
+type MSFXCodeStatusTypeDTO struct {
+	CodeStatus string `json:"code_status"`
+}
+
+type MSFXDrugEntBaseDTO struct {
+	ApprovalLicenceNo string `json:"approval_licence_no"`
+	DrugEntBaseInfoID string `json:"drug_ent_base_info_id"`
+	Exprie            string `json:"exprie"`
+	PhysicName        string `json:"physic_name"`
+	PhysicTypeDesc    string `json:"physic_type_desc"`
+	PkgSpecCrit       string `json:"pkg_spec_crit"`
+	PrepnSpec         string `json:"prepn_spec"`
+	PrepnTypeDesc     string `json:"prepn_type_desc"`
+}
+
+type MSFXPUserEntDTO struct {
+	EntName  string `json:"ent_name"`
+	RefEntID string `json:"ref_ent_id"`
+}

+ 15 - 31
services/stock_template.go

@@ -1989,7 +1989,7 @@ func (e *StockTemplate) StockInquiryList(c *dto.StockStatListReq, deptId int) (l
 		whereSql += " AND m_info.enterprise_id = " + strconv.Itoa(c.EnterpriseID)
 	}
 	if len(c.BatchNumber) > 0 {
-		whereSql += " AND m_info.batch_number = '" + c.BatchNumber+ "'"
+		whereSql += " AND m_info.batch_number = '" + c.BatchNumber + "'"
 	}
 	if len(c.StartDate) > 0 {
 		whereSql += " AND m_info.expiry_date >= '" + c.StartDate + "'"
@@ -2060,17 +2060,16 @@ func (e *StockTemplate) GetStockInquiry(c *dto.GetStockStatReq, deptId int) (res
 		whereSql += " AND m_info.enterprise_id = " + strconv.Itoa(c.EnterpriseID)
 	}
 	if c.SpecID > 0 {
-		whereSql += " AND m_info.spec_id = '" + strconv.Itoa(c.SpecID)
+		whereSql += " AND m_info.spec_id = " + strconv.Itoa(c.SpecID)
 	}
 	if len(c.BatchNumber) > 0 {
-		whereSql += " AND m_info.batch_number = '" + c.BatchNumber+ "'"
+		whereSql += " AND m_info.batch_number = '" + c.BatchNumber + "'"
 	}
 
 	if len(whereSql) > 0 {
 		whereSql = " WHERE " + strings.TrimLeft(whereSql, " AND ")
 	}
 
-
 	sql := "SELECT mi.* FROM (SELECT medicine_id,MAX(id) AS latest_id FROM medicine_inventory WHERE dept_id = " + strconv.Itoa(deptId) + " AND deleted_at is null GROUP BY medicine_id) AS mi_latest " +
 		"JOIN medicine_inventory AS mi ON mi.medicine_id=mi_latest.medicine_id AND mi.id=mi_latest.latest_id " +
 		"LEFT JOIN " + mtable + " AS m_info ON mi.medicine_id=m_info.id" + whereSql + " order by m_info.expiry_date ;"
@@ -2078,33 +2077,18 @@ func (e *StockTemplate) GetStockInquiry(c *dto.GetStockStatReq, deptId int) (res
 	err = db.DB.Raw(sql).Last(&res).Error
 	if err != nil {
 		logs.Error("db error: %s ", err)
-		return res,  err
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			//return res, errors.New("药品信息不存在,查询药品库存失败!")
+			res = make(map[string]interface{})
+			res["balance"] = 0
+			return res, nil
+		}
+
+		return res, global.GetFailedErr
 	}
 
-	//models.InitBasicData(deptId)
-	//if id, ok := res[models.FieldProductID]; ok {
-	//	res[models.FieldProductName] = models.Read_Product_Get(utils.ToInt(id))
-	//}
-	//if id, ok := res[models.FieldEnterpriseID]; ok {
-	//	res[models.FieldEnterpriseName] = models.Read_Enterprise_Get(utils.ToInt(id))
-	//}
-	//if id, ok := res[models.FieldSpecID]; ok {
-	//	res[models.FieldSpecName] = models.Read_Spec_Get(utils.ToInt(id))
-	//}
-	//if id, ok := res[models.FieldUnitID]; ok {
-	//	res[models.FieldUnitName] = models.Read_Unit_Get(utils.ToInt(id))
-	//}
-	//if id, ok := res[models.FieldDosageFormID]; ok {
-	//	if utils.ToInt(id) == 0 {
-	//		res[models.FieldDosageFormID] = nil
-	//	} else {
-	//		res[models.FieldDosageFormName] = models.Read_DosageForm_Get(utils.ToInt(id))
-	//	}
-	//}
-	//res[models.FieldExpiryDate] = utils.ToDate(res[models.FieldExpiryDate])
-	//res[models.FieldProducedDate] = utils.ToDate(res[models.FieldProducedDate])
 
-	return res,  nil
+	return res, nil
 
 }
 
@@ -2138,7 +2122,7 @@ func (e *StockTemplate) StockInquiryExcel(c *dto.StockStatListReq, deptId int) (
 	err = db.DB.Raw(sql).Scan(&list).Error
 	if err != nil {
 		logs.Error("db error: %s ", err)
-		return list, err
+		return list, global.GetFailedErr
 	}
 
 	models.InitBasicData(deptId)
@@ -2189,7 +2173,7 @@ func (e *StockTemplate) StockStat(c *dto.StockStatReq, deptId int) (list []map[s
 	err = db.DB.Raw(sql).Scan(&result).Error
 	if err != nil {
 		logs.Error("db error: %s ", err)
-		return list, count, err
+		return list, count, global.GetFailedErr
 	}
 
 	models.InitBasicData(deptId)
@@ -2261,7 +2245,7 @@ func (e *StockTemplate) StockHomeStat(deptId int) (list map[string]interface{},
 	err = db.DB.Raw(sql).Scan(&result).Error
 	if err != nil {
 		logs.Error("db error: %s ", err)
-		return list, count, err
+		return list, count, global.GetFailedErr
 	}
 
 	inventoryQuantity := 0