Browse Source

add:查询单个产品库存信息

zoie 5 months ago
parent
commit
fccc30274b

+ 3 - 3
controllers/medicine_template.go

@@ -195,9 +195,9 @@ func (c MedicineTemplateController) ListForStock() {
 	c.PageOK(list, int(count), 0, 0, "查询成功")
 }
 
-// ListForStockOut 获取入库列表
-// @Summary 获取入库列表
-// @Description 获取入库列表
+// ListForStockOut 获取出库品名、生产企业、规格
+// @Summary 获取出库品名、生产企业、规格
+// @Description 获取出库品名、生产企业、规格
 // @Tags 药品信息模板
 // @Success 200 {object} response.Page{list=[]models.MedicineTemplate} "{"code": 200, "data": [...]}"
 // @Router /medicine-template/list-for-stock [post]

+ 26 - 0
controllers/stock_template.go

@@ -2426,6 +2426,32 @@ func (c StockTemplateController) StockInquiryList() {
 	c.PageOK(list, int(cnt), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
 }
 
+// GetStockInquiry 单个产品库存查询
+// @Summary 库存查询-商品、生产企业、规格、批号
+// @Description 单个产品库存查询
+// @Tags 库存
+// @Param body body dto.StockStatListReq true "body"
+// @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
+// @Router /stock/inquiry/list [post]
+// @Security Bearer
+func (c StockTemplateController) GetStockInquiry() {
+	s := services.StockTemplate{}
+	reqData := dto.GetStockStatReq{}
+	if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
+		err = errors.New("解析表单数据异常")
+		c.Error(global.ParseFormErr, err, err.Error())
+		return
+	}
+
+	deptId := beegouser.GetDeptId(c.Ctx)
+	res, err := s.GetStockInquiry(&reqData, deptId)
+	if err != nil {
+		c.Error(500, err, err.Error())
+		return
+	}
+	c.OK(res, "查询成功")
+}
+
 // StockInquiryExcel 导出库存信息表
 // @Summary 库存信息表-每个商品、生产企业、规格、批号数量
 // @Description 库存信息表

+ 1 - 0
dto/medicine.go

@@ -4,5 +4,6 @@ package dto
 type MedicineBatchNumberReq struct {
 	ProductID    int    `json:"productId"`    // 药品名称id
 	EnterpriseID int    `json:"enterpriseId"` // 生产企业id
+	SpecID       int    `json:"specId"`       // 规格id
 	BatchNumber  string `json:"batchNumber"`  // 批号
 }

+ 8 - 0
dto/stock_template.go

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

+ 1 - 0
routers/stock.go

@@ -48,6 +48,7 @@ func init() {
 		beego.NSRouter("/unit/list", &controllers.StockTemplateController{}, "*:StockUnitList"),         // 收/发货单位列表
 		beego.NSRouter("/operator/list", &controllers.StockTemplateController{}, "*:StockOperatorList"), // 经办人列表
 		beego.NSRouter("/inquiry/list", &controllers.StockTemplateController{}, "*:StockInquiryList"),   // 库存查询
+		beego.NSRouter("/inquiry/get", &controllers.StockTemplateController{}, "*:GetStockInquiry"),   // 库存查询-单个产品
 		beego.NSRouter("/inquiry/excel", &controllers.StockTemplateController{}, "*:StockInquiryExcel"), // 库存查询 - excel
 		beego.NSRouter("/stat", &controllers.StockTemplateController{}, "*:StockStat"),
 		beego.NSRouter("/home-stat", &controllers.StockTemplateController{}, "*:StockHomeStat"),

+ 3 - 0
services/medicine.go

@@ -21,6 +21,9 @@ func (e *Medicine) GetBatchNumber(c *dto.MedicineBatchNumberReq, list *[]string,
 	if c.EnterpriseID > 0 {
 		whereSql += " AND enterprise_id = " + strconv.Itoa(c.EnterpriseID)
 	}
+	if c.SpecID > 0 {
+		whereSql += " AND spec_id = " + strconv.Itoa(c.SpecID)
+	}
 	if len(c.BatchNumber) > 0 {
 		whereSql += " AND batch_number like '%" + c.BatchNumber + "%'"
 	}

+ 59 - 1
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 + "'"
@@ -2049,6 +2049,64 @@ func (e *StockTemplate) StockInquiryList(c *dto.StockStatListReq, deptId int) (l
 	return list, count, nil
 
 }
+func (e *StockTemplate) GetStockInquiry(c *dto.GetStockStatReq, deptId int) (res map[string]interface{}, err error) {
+
+	mtable := models.GetMedicineInfoTableName(deptId)
+	whereSql := ""
+	if c.ProductID > 0 {
+		whereSql += " AND m_info.product_id = " + strconv.Itoa(c.ProductID)
+	}
+	if c.EnterpriseID > 0 {
+		whereSql += " AND m_info.enterprise_id = " + strconv.Itoa(c.EnterpriseID)
+	}
+	if c.SpecID > 0 {
+		whereSql += " AND m_info.spec_id = '" + strconv.Itoa(c.SpecID)
+	}
+	if len(c.BatchNumber) > 0 {
+		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 ;"
+
+	err = db.DB.Raw(sql).Last(&res).Error
+	if err != nil {
+		logs.Error("db error: %s ", err)
+		return res,  err
+	}
+
+	//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
+
+}
 
 // 库存查询excel
 func (e *StockTemplate) StockInquiryExcel(c *dto.StockStatListReq, deptId int) (list []map[string]interface{}, err error) {