Merge branch 'dev'
This commit is contained in:
commit
01eda96f23
@ -15,6 +15,7 @@ type Api struct {
|
||||
caManage // ca管理
|
||||
financeManage // 财务管理
|
||||
exportManage // 导出管理
|
||||
productManage // 商品管理
|
||||
}
|
||||
|
||||
// SysSetting 系统设置
|
||||
@ -84,3 +85,8 @@ type financeManage struct {
|
||||
type exportManage struct {
|
||||
Export
|
||||
}
|
||||
|
||||
// 商品管理
|
||||
type productManage struct {
|
||||
Product
|
||||
}
|
||||
|
||||
302
api/controller/product.go
Normal file
302
api/controller/product.go
Normal file
@ -0,0 +1,302 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/service"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Product struct{}
|
||||
|
||||
// GetPlatformProductPage 获取平台商品列表-分页
|
||||
func (r *Product) GetPlatformProductPage(c *gin.Context) {
|
||||
productRequest := requests.ProductRequest{}
|
||||
req := productRequest.GetPlatformProductPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
productPlatformDao := dao.ProductPlatformDao{}
|
||||
productPlatform, total, err := productPlatformDao.GetPlatformProductPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
GetProductPlatformPageResponses := dto.GetProductPlatformListDto(productPlatform)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = GetProductPlatformPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetProductPlatform 平台商品详情
|
||||
func (r *Product) GetProductPlatform(c *gin.Context) {
|
||||
id := c.Param("product_platform_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
productPlatformId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
productService := service.ProductService{}
|
||||
getPlatformProductResponses, err := productService.GetProductPlatform(productPlatformId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(getPlatformProductResponses, c)
|
||||
}
|
||||
|
||||
// GetProductPage 获取商品列表-分页
|
||||
func (r *Product) GetProductPage(c *gin.Context) {
|
||||
productRequest := requests.ProductRequest{}
|
||||
req := productRequest.GetProductPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
productDao := dao.ProductDao{}
|
||||
product, total, err := productDao.GetProductPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
GetProductPageResponses := dto.GetProductListDto(product)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = GetProductPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetProduct 商品详情
|
||||
func (r *Product) GetProduct(c *gin.Context) {
|
||||
id := c.Param("product_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
productId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
productService := service.ProductService{}
|
||||
getPlatformProductResponses, err := productService.GetProduct(productId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(getPlatformProductResponses, c)
|
||||
}
|
||||
|
||||
// AddProduct 新增商品
|
||||
func (r *Product) AddProduct(c *gin.Context) {
|
||||
productRequest := requests.ProductRequest{}
|
||||
req := productRequest.AddProduct
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取当前登陆用户id
|
||||
userId := c.GetInt64("UserId")
|
||||
if userId == 0 {
|
||||
responses.FailWithMessage("角色错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
userIdStr := strconv.FormatInt(userId, 10)
|
||||
|
||||
// 业务处理
|
||||
productService := service.ProductService{}
|
||||
_, err := productService.AddProduct(userIdStr, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutProduct 修改商品
|
||||
func (r *Product) PutProduct(c *gin.Context) {
|
||||
productRequest := requests.ProductRequest{}
|
||||
req := productRequest.PutProduct
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("product_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
productId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
productService := service.ProductService{}
|
||||
_, err = productService.PutProduct(productId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutProductStatus 修改商品状态(上/下架)
|
||||
func (r *Product) PutProductStatus(c *gin.Context) {
|
||||
productRequest := requests.ProductRequest{}
|
||||
req := productRequest.PutProductStatus
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("product_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
productId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
productService := service.ProductService{}
|
||||
_, err = productService.PutProductStatus(productId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// GetPlatformProductList 获取平台商品列表
|
||||
func (r *Product) GetPlatformProductList(c *gin.Context) {
|
||||
productRequest := requests.ProductRequest{}
|
||||
req := productRequest.GetPlatformProductList
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
productPlatformDao := dao.ProductPlatformDao{}
|
||||
productPlatform, err := productPlatformDao.GetPlatformProductListSearch(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
productPlatforms := dto.GetProductPlatformListDto(productPlatform)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(productPlatforms, c)
|
||||
}
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
@ -71,3 +72,85 @@ func (r *ProductDao) AddProduct(tx *gorm.DB, model *model.Product) (*model.Produ
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetProductPageSearch 获取商品列表-分页
|
||||
func (r *ProductDao) GetProductPageSearch(req requests.GetProductPage, page, pageSize int) (m []*model.Product, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.Product{})
|
||||
|
||||
// 库存表
|
||||
query = query.Preload("ProductPlatformAmount", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("amount_id", "product_platform_id", "product_platform_code", "stock")
|
||||
})
|
||||
|
||||
// 商品名称
|
||||
if req.ProductName != "" {
|
||||
query = query.Where("product_name LIKE ?", "%"+req.ProductName+"%")
|
||||
}
|
||||
|
||||
// 商品通用名
|
||||
if req.CommonName != "" {
|
||||
query = query.Where("common_name LIKE ?", "%"+req.CommonName+"%")
|
||||
}
|
||||
|
||||
// 商品助记码
|
||||
if req.MnemonicCode != "" {
|
||||
query = query.Where("mnemonic_code LIKE ?", "%"+req.MnemonicCode+"%")
|
||||
}
|
||||
|
||||
// 药品类型
|
||||
if req.ProductType != nil {
|
||||
query = query.Where("product_type = ?", req.ProductType)
|
||||
}
|
||||
|
||||
// 商品状态
|
||||
if req.ProductStatus != nil {
|
||||
query = query.Where("product_status = ?", req.ProductStatus)
|
||||
}
|
||||
|
||||
// 平台商品id
|
||||
if req.ProductPlatformId != "" {
|
||||
query = query.Where("product_platform_id = ?", req.ProductPlatformId)
|
||||
}
|
||||
|
||||
// 处方平台编码
|
||||
if req.ProductPlatformCode != "" {
|
||||
query = query.Where("product_platform_code LIKE ?", "%"+req.ProductPlatformCode+"%")
|
||||
}
|
||||
|
||||
// 药店编码
|
||||
if req.ProductPharmacyCode != "" {
|
||||
query = query.Where("product_pharmacy_code LIKE ?", "%"+req.ProductPharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 批准文号
|
||||
if req.LicenseNumber != "" {
|
||||
query = query.Where("license_number LIKE ?", "%"+req.LicenseNumber+"%")
|
||||
}
|
||||
|
||||
// 生产厂家
|
||||
if req.Manufacturer != "" {
|
||||
query = query.Where("manufacturer LIKE ?", "%"+req.Manufacturer+"%")
|
||||
}
|
||||
|
||||
// 商品备注
|
||||
if req.ProductRemarks != "" {
|
||||
query = query.Where("product_remarks LIKE ?", "%"+req.ProductRemarks+"%")
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
161
api/dao/productPlatform.go
Normal file
161
api/dao/productPlatform.go
Normal file
@ -0,0 +1,161 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type ProductPlatformDao struct {
|
||||
}
|
||||
|
||||
// GetProductPlatformById 获取平台商品数据-平台商品id
|
||||
func (r *ProductPlatformDao) GetProductPlatformById(productPlatformId int64) (m *model.ProductPlatform, err error) {
|
||||
err = global.Db.First(&m, productPlatformId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetProductPlatformList 获取平台商品列表
|
||||
func (r *ProductPlatformDao) GetProductPlatformList(maps interface{}) (m []*model.ProductPlatform, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteProductPlatform 删除平台商品
|
||||
func (r *ProductPlatformDao) DeleteProductPlatform(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.ProductPlatform{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditProductPlatform 修改平台商品
|
||||
func (r *ProductPlatformDao) EditProductPlatform(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.ProductPlatform{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditProductPlatformByUserId 修改平台商品-平台商品id
|
||||
func (r *ProductPlatformDao) EditProductPlatformByUserId(tx *gorm.DB, productPlatformId int64, data interface{}) error {
|
||||
err := tx.Model(&model.ProductPlatform{}).Where("product_platform_id = ?", productPlatformId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddProductPlatform 新增平台商品
|
||||
func (r *ProductPlatformDao) AddProductPlatform(tx *gorm.DB, model *model.ProductPlatform) (*model.ProductPlatform, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetPlatformProductPageSearch 获取平台商品列表-分页
|
||||
func (r *ProductPlatformDao) GetPlatformProductPageSearch(req requests.GetPlatformProductPage, page, pageSize int) (m []*model.ProductPlatform, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.ProductPlatform{})
|
||||
|
||||
// 商品名称
|
||||
if req.ProductName != "" {
|
||||
query = query.Where("product_name LIKE ?", "%"+req.ProductName+"%")
|
||||
}
|
||||
|
||||
// 药品类型
|
||||
if req.ProductType != nil {
|
||||
query = query.Where("product_type = ?", req.ProductType)
|
||||
}
|
||||
|
||||
// 处方平台编码
|
||||
if req.ProductPlatformCode != "" {
|
||||
query = query.Where("product_platform_code LIKE ?", "%"+req.ProductPlatformCode+"%")
|
||||
}
|
||||
|
||||
// 药店编码
|
||||
if req.ProductPharmacyCode != "" {
|
||||
query = query.Where("product_pharmacy_code LIKE ?", "%"+req.ProductPharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 批准文号
|
||||
if req.LicenseNumber != "" {
|
||||
query = query.Where("license_number LIKE ?", "%"+req.LicenseNumber+"%")
|
||||
}
|
||||
|
||||
// 生产厂家
|
||||
if req.Manufacturer != "" {
|
||||
query = query.Where("manufacturer LIKE ?", "%"+req.Manufacturer+"%")
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetPlatformProductListSearch 获取平台商品列表
|
||||
func (r *ProductPlatformDao) GetPlatformProductListSearch(req requests.GetPlatformProductList) (m []*model.ProductPlatform, err error) {
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.ProductPlatform{})
|
||||
|
||||
// 商品名称
|
||||
if req.ProductName != "" {
|
||||
query = query.Where("product_name LIKE ?", "%"+req.ProductName+"%")
|
||||
}
|
||||
|
||||
// 药品类型
|
||||
if req.ProductType != nil {
|
||||
query = query.Where("product_type = ?", req.ProductType)
|
||||
}
|
||||
|
||||
// 处方平台编码
|
||||
if req.ProductPlatformCode != "" {
|
||||
query = query.Where("product_platform_code LIKE ?", "%"+req.ProductPlatformCode+"%")
|
||||
}
|
||||
|
||||
// 药店编码
|
||||
if req.ProductPharmacyCode != "" {
|
||||
query = query.Where("product_pharmacy_code LIKE ?", "%"+req.ProductPharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 批准文号
|
||||
if req.LicenseNumber != "" {
|
||||
query = query.Where("license_number LIKE ?", "%"+req.LicenseNumber+"%")
|
||||
}
|
||||
|
||||
// 生产厂家
|
||||
if req.Manufacturer != "" {
|
||||
query = query.Where("manufacturer LIKE ?", "%"+req.Manufacturer+"%")
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
err = query.Scopes(model.Paginate(1, 10)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
72
api/dao/productPlatformAmount.go
Normal file
72
api/dao/productPlatformAmount.go
Normal file
@ -0,0 +1,72 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type ProductPlatformAmountDao struct {
|
||||
}
|
||||
|
||||
// GetProductPlatformAmountById 获取商品库存数据-商品库存id
|
||||
func (r *ProductPlatformAmountDao) GetProductPlatformAmountById(amountId int64) (m *model.ProductPlatformAmount, err error) {
|
||||
err = global.Db.First(&m, amountId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetProductPlatformAmountByProductPlatformId 获取商品库存数据-平台商品id
|
||||
func (r *ProductPlatformAmountDao) GetProductPlatformAmountByProductPlatformId(productPlatformId int64) (m *model.ProductPlatformAmount, err error) {
|
||||
err = global.Db.Where("product_platform_id = ?", productPlatformId).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteProductPlatformAmount 删除商品库存
|
||||
func (r *ProductPlatformAmountDao) DeleteProductPlatformAmount(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.ProductPlatformAmount{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditProductPlatformAmount 修改商品库存
|
||||
func (r *ProductPlatformAmountDao) EditProductPlatformAmount(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.ProductPlatformAmount{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditProductPlatformAmountByUserId 修改商品库存-商品库存id
|
||||
func (r *ProductPlatformAmountDao) EditProductPlatformAmountByUserId(tx *gorm.DB, amountId int64, data interface{}) error {
|
||||
err := tx.Model(&model.ProductPlatformAmount{}).Where("amount_id = ?", amountId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetProductPlatformAmountList 获取商品库存列表
|
||||
func (r *ProductPlatformAmountDao) GetProductPlatformAmountList(maps interface{}) (m []*model.ProductPlatformAmount, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddProductPlatformAmount 新增商品K库存
|
||||
func (r *ProductPlatformAmountDao) AddProductPlatformAmount(tx *gorm.DB, model *model.ProductPlatformAmount) (*model.ProductPlatformAmount, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
120
api/dto/Product.go
Normal file
120
api/dto/Product.go
Normal file
@ -0,0 +1,120 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/utils"
|
||||
)
|
||||
|
||||
type ProductDto struct {
|
||||
ProductId string `json:"product_id"` // 主键id
|
||||
ProductPlatformId string `json:"product_platform_id"` // 处方平台商品id
|
||||
ProductStatus int `json:"product_status"` // 商品状态(1:正常 2:下架)
|
||||
IsDelete int `json:"is_delete"` // 是否删除(0:否 1:是)
|
||||
PrescriptionNum int `json:"prescription_num"` // 处方可开具的数量
|
||||
ProductName string `json:"product_name"` // 商品名称
|
||||
CommonName string `json:"common_name"` // 商品通用名
|
||||
ProductPrice float64 `json:"product_price"` // 商品价格
|
||||
MnemonicCode string `json:"mnemonic_code"` // 商品助记码(首字母简拼)
|
||||
ProductType int `json:"product_type"` // 药品类型(0:未知 1:中成药 2:西药)
|
||||
ProductPlatformCode string `json:"product_platform_code"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code"` // 第三方药店商品编码
|
||||
ProductCoverImg string `json:"product_cover_img"` // 商品封面图
|
||||
ProductSpec string `json:"product_spec"` // 商品规格
|
||||
LicenseNumber string `json:"license_number"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer"` // 生产厂家
|
||||
SingleUnit string `json:"single_unit"` // 单次剂量(例:1次1包)
|
||||
SingleUse string `json:"single_use"` // 单次用法(例:口服)
|
||||
PackagingUnit string `json:"packaging_unit"` // 基本包装单位(例:盒/瓶)
|
||||
FrequencyUse string `json:"frequency_use"` // 使用频率(例:1天3次)
|
||||
AvailableDays float64 `json:"available_days"` // 可用天数(3)
|
||||
ProductRemarks string `json:"product_remarks"` // 商品备注
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
Stock uint `json:"stock"` // 现有库存
|
||||
}
|
||||
|
||||
// GetProductDto 商品详情
|
||||
func GetProductDto(m *model.Product) *ProductDto {
|
||||
return &ProductDto{
|
||||
ProductId: fmt.Sprintf("%d", m.ProductId),
|
||||
ProductPlatformId: fmt.Sprintf("%d", m.ProductPlatformId),
|
||||
ProductStatus: m.ProductStatus,
|
||||
IsDelete: m.IsDelete,
|
||||
PrescriptionNum: m.PrescriptionNum,
|
||||
ProductName: m.ProductName,
|
||||
CommonName: m.ProductName,
|
||||
ProductPrice: m.ProductPrice,
|
||||
MnemonicCode: m.MnemonicCode,
|
||||
ProductType: m.ProductType,
|
||||
ProductPlatformCode: m.ProductPlatformCode,
|
||||
ProductPharmacyCode: m.ProductPharmacyCode,
|
||||
ProductCoverImg: utils.AddOssDomain(m.ProductCoverImg),
|
||||
ProductSpec: m.ProductSpec,
|
||||
LicenseNumber: m.LicenseNumber,
|
||||
Manufacturer: m.Manufacturer,
|
||||
SingleUnit: m.SingleUnit,
|
||||
SingleUse: m.SingleUse,
|
||||
PackagingUnit: m.PackagingUnit,
|
||||
FrequencyUse: m.FrequencyUse,
|
||||
AvailableDays: m.AvailableDays,
|
||||
ProductRemarks: m.ProductRemarks,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetProductListDto 商品列表
|
||||
func GetProductListDto(m []*model.Product) []*ProductDto {
|
||||
// 处理返回值
|
||||
responses := make([]*ProductDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &ProductDto{
|
||||
ProductId: fmt.Sprintf("%d", v.ProductId),
|
||||
ProductPlatformId: fmt.Sprintf("%d", v.ProductPlatformId),
|
||||
ProductStatus: v.ProductStatus,
|
||||
IsDelete: v.IsDelete,
|
||||
PrescriptionNum: v.PrescriptionNum,
|
||||
ProductName: v.ProductName,
|
||||
CommonName: v.ProductName,
|
||||
ProductPrice: v.ProductPrice,
|
||||
MnemonicCode: v.MnemonicCode,
|
||||
ProductType: v.ProductType,
|
||||
ProductPlatformCode: v.ProductPlatformCode,
|
||||
ProductPharmacyCode: v.ProductPharmacyCode,
|
||||
ProductCoverImg: utils.AddOssDomain(v.ProductCoverImg),
|
||||
ProductSpec: v.ProductSpec,
|
||||
LicenseNumber: v.LicenseNumber,
|
||||
Manufacturer: v.Manufacturer,
|
||||
SingleUnit: v.SingleUnit,
|
||||
SingleUse: v.SingleUse,
|
||||
PackagingUnit: v.PackagingUnit,
|
||||
FrequencyUse: v.FrequencyUse,
|
||||
AvailableDays: v.AvailableDays,
|
||||
ProductRemarks: v.ProductRemarks,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 加载商品库存
|
||||
if v.ProductPlatformAmount != nil {
|
||||
response = response.LoadProductAmount(v.ProductPlatformAmount)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadProductAmount 加载商品库存
|
||||
func (r *ProductDto) LoadProductAmount(m *model.ProductPlatformAmount) *ProductDto {
|
||||
if m != nil {
|
||||
r.Stock = m.Stock
|
||||
}
|
||||
return r
|
||||
}
|
||||
88
api/dto/ProductPlatform.go
Normal file
88
api/dto/ProductPlatform.go
Normal file
@ -0,0 +1,88 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hospital-admin-api/api/model"
|
||||
)
|
||||
|
||||
type ProductPlatformDto struct {
|
||||
ProductPlatformId string `json:"product_platform_id"` // 主键id
|
||||
ProductName string `json:"product_name"` // 商品名称
|
||||
ProductPrice float64 `json:"product_price"` // 商品价格
|
||||
ProductType int `json:"product_type"` // 药品类型(0:未知 1:中成药 2:西药)
|
||||
ProductPlatformCode string `json:"product_platform_code"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code"` // 第三方药店商品编码
|
||||
ProductSpec string `json:"product_spec"` // 商品规格
|
||||
LicenseNumber string `json:"license_number"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer"` // 生产厂家
|
||||
SingleUnit string `json:"single_unit"` // 单次剂量单位
|
||||
PackagingUnit string `json:"packaging_unit"` // 基本包装单位
|
||||
PackagingCount string `json:"packaging_count"` // 基本包装数量
|
||||
RetailUnit string `json:"retail_unit"` // 零售单位
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
Stock uint `json:"stock"` // 现有库存
|
||||
}
|
||||
|
||||
// GetProductPlatformDto 平台商品详情
|
||||
func GetProductPlatformDto(m *model.ProductPlatform) *ProductPlatformDto {
|
||||
return &ProductPlatformDto{
|
||||
ProductPlatformId: fmt.Sprintf("%d", m.ProductPlatformId),
|
||||
ProductName: m.ProductName,
|
||||
ProductPrice: m.ProductPrice,
|
||||
ProductType: m.ProductType,
|
||||
ProductPlatformCode: m.ProductPlatformCode,
|
||||
ProductPharmacyCode: m.ProductPharmacyCode,
|
||||
ProductSpec: m.ProductSpec,
|
||||
LicenseNumber: m.LicenseNumber,
|
||||
Manufacturer: m.Manufacturer,
|
||||
SingleUnit: m.SingleUnit,
|
||||
PackagingUnit: m.PackagingUnit,
|
||||
PackagingCount: m.PackagingCount,
|
||||
RetailUnit: m.RetailUnit,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetProductPlatformListDto 平台商品列表
|
||||
func GetProductPlatformListDto(m []*model.ProductPlatform) []*ProductPlatformDto {
|
||||
// 处理返回值
|
||||
responses := make([]*ProductPlatformDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &ProductPlatformDto{
|
||||
ProductPlatformId: fmt.Sprintf("%d", v.ProductPlatformId),
|
||||
ProductName: v.ProductName,
|
||||
ProductPrice: v.ProductPrice,
|
||||
ProductType: v.ProductType,
|
||||
ProductPlatformCode: v.ProductPlatformCode,
|
||||
ProductPharmacyCode: v.ProductPharmacyCode,
|
||||
ProductSpec: v.ProductSpec,
|
||||
LicenseNumber: v.LicenseNumber,
|
||||
Manufacturer: v.Manufacturer,
|
||||
SingleUnit: v.SingleUnit,
|
||||
PackagingUnit: v.PackagingUnit,
|
||||
PackagingCount: v.PackagingCount,
|
||||
RetailUnit: v.RetailUnit,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadProductAmount 加载商品库存
|
||||
func (r *ProductPlatformDto) LoadProductAmount(quantity int) *ProductPlatformDto {
|
||||
if quantity > 0 {
|
||||
r.Stock = uint(quantity)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
@ -8,25 +8,29 @@ import (
|
||||
|
||||
// Product 商品表
|
||||
type Product struct {
|
||||
ProductId int64 `gorm:"column:product_id;type:bigint(19);primary_key;comment:主键id" json:"product_id"`
|
||||
ProductPlatformId int64 `gorm:"column:product_platform_id;type:bigint(19);comment:处方平台商品id" json:"product_platform_id"`
|
||||
ProductName string `gorm:"column:product_name;type:varchar(255);comment:商品名称" json:"product_name"`
|
||||
CommonName string `gorm:"column:common_name;type:varchar(100);comment:商品通用名" json:"common_name"`
|
||||
ProductPrice float64 `gorm:"column:product_price;type:decimal(10,2);comment:商品价格" json:"product_price"`
|
||||
MnemonicCode string `gorm:"column:mnemonic_code;type:varchar(50);comment:商品助记码(首字母简拼)" json:"mnemonic_code"`
|
||||
ProductType int `gorm:"column:product_type;type:tinyint(4);default:1;comment:药品类型(0:未知 1:中成药 2:西药)" json:"product_type"`
|
||||
ProductPlatformCode string `gorm:"column:product_platform_code;type:varchar(100);comment:处方平台商品编码" json:"product_platform_code"`
|
||||
ProductPharmacyCode string `gorm:"column:product_pharmacy_code;type:varchar(100);comment:第三方药店商品编码" json:"product_pharmacy_code"`
|
||||
ProductCoverImg string `gorm:"column:product_cover_img;type:varchar(255);comment:商品封面图" json:"product_cover_img"`
|
||||
ProductSpec string `gorm:"column:product_spec;type:varchar(255);comment:商品规格" json:"product_spec"`
|
||||
LicenseNumber string `gorm:"column:license_number;type:varchar(30);comment:批准文号" json:"license_number"`
|
||||
Manufacturer string `gorm:"column:manufacturer;type:varchar(255);comment:生产厂家" json:"manufacturer"`
|
||||
SingleUnit string `gorm:"column:single_unit;type:varchar(50);comment:单次剂量(例:1次1包)" json:"single_unit"`
|
||||
SingleUse string `gorm:"column:single_use;type:varchar(50);comment:单次用法(例:口服)" json:"single_use"`
|
||||
PackagingUnit string `gorm:"column:packaging_unit;type:varchar(20);comment:基本包装单位(例:盒/瓶)" json:"packaging_unit"`
|
||||
FrequencyUse string `gorm:"column:frequency_use;type:varchar(50);comment:使用频率(例:1天3次)" json:"frequency_use"`
|
||||
AvailableDays float64 `gorm:"column:available_days;type:float(10,2);comment:可用天数(3)" json:"available_days"`
|
||||
ProductRemarks string `gorm:"column:product_remarks;type:varchar(255);comment:商品备注" json:"product_remarks"`
|
||||
ProductId int64 `gorm:"column:product_id;type:bigint(19);primary_key;comment:主键id" json:"product_id"`
|
||||
ProductPlatformId int64 `gorm:"column:product_platform_id;type:bigint(19);comment:处方平台商品id" json:"product_platform_id"`
|
||||
ProductStatus int `gorm:"column:product_status;type:tinyint(1);default:1;comment:商品状态(1:正常 2:下架)" json:"product_status"`
|
||||
IsDelete int `gorm:"column:is_delete;type:tinyint(1);default:0;comment:是否删除(0:否 1:是)" json:"is_delete"`
|
||||
PrescriptionNum int `gorm:"column:prescription_num;type:int(11);default:5;comment:处方可开具的数量" json:"prescription_num"`
|
||||
ProductName string `gorm:"column:product_name;type:varchar(255);comment:商品名称" json:"product_name"`
|
||||
CommonName string `gorm:"column:common_name;type:varchar(100);comment:商品通用名" json:"common_name"`
|
||||
ProductPrice float64 `gorm:"column:product_price;type:decimal(10,2);comment:商品价格" json:"product_price"`
|
||||
MnemonicCode string `gorm:"column:mnemonic_code;type:varchar(50);comment:商品助记码(首字母简拼)" json:"mnemonic_code"`
|
||||
ProductType int `gorm:"column:product_type;type:tinyint(4);default:1;comment:药品类型(0:未知 1:中成药 2:西药)" json:"product_type"`
|
||||
ProductPlatformCode string `gorm:"column:product_platform_code;type:varchar(100);comment:处方平台商品编码" json:"product_platform_code"`
|
||||
ProductPharmacyCode string `gorm:"column:product_pharmacy_code;type:varchar(100);comment:第三方药店商品编码" json:"product_pharmacy_code"`
|
||||
ProductCoverImg string `gorm:"column:product_cover_img;type:varchar(255);comment:商品封面图" json:"product_cover_img"`
|
||||
ProductSpec string `gorm:"column:product_spec;type:varchar(255);comment:商品规格" json:"product_spec"`
|
||||
LicenseNumber string `gorm:"column:license_number;type:varchar(30);comment:批准文号" json:"license_number"`
|
||||
Manufacturer string `gorm:"column:manufacturer;type:varchar(255);comment:生产厂家" json:"manufacturer"`
|
||||
SingleUnit string `gorm:"column:single_unit;type:varchar(50);comment:单次剂量(例:1次1包)" json:"single_unit"`
|
||||
SingleUse string `gorm:"column:single_use;type:varchar(50);comment:单次用法(例:口服)" json:"single_use"`
|
||||
PackagingUnit string `gorm:"column:packaging_unit;type:varchar(20);comment:基本包装单位(例:盒/瓶)" json:"packaging_unit"`
|
||||
FrequencyUse string `gorm:"column:frequency_use;type:varchar(50);comment:使用频率(例:1天3次)" json:"frequency_use"`
|
||||
AvailableDays float64 `gorm:"column:available_days;type:float(10,2);comment:可用天数(3)" json:"available_days"`
|
||||
ProductRemarks string `gorm:"column:product_remarks;type:varchar(255);comment:商品备注" json:"product_remarks"`
|
||||
ProductPlatformAmount *ProductPlatformAmount `gorm:"foreignKey:ProductPlatformId;references:product_platform_id" json:"product_platform_amount"` // 库存
|
||||
Model
|
||||
}
|
||||
|
||||
|
||||
43
api/model/productPlatform.go
Normal file
43
api/model/productPlatform.go
Normal file
@ -0,0 +1,43 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ProductPlatform 商品表-处方平台
|
||||
type ProductPlatform struct {
|
||||
ProductPlatformId int64 `gorm:"column:product_platform_id;type:bigint(19);primary_key;comment:主键id" json:"product_platform_id"`
|
||||
ProductName string `gorm:"column:product_name;type:varchar(255);comment:商品名称" json:"product_name"`
|
||||
ProductPrice float64 `gorm:"column:product_price;type:decimal(10,2);comment:商品价格" json:"product_price"`
|
||||
ProductType int `gorm:"column:product_type;type:tinyint(4);default:1;comment:药品类型(0:未知 1:中成药 2:西药)" json:"product_type"`
|
||||
ProductPlatformCode string `gorm:"column:product_platform_code;type:varchar(100);comment:处方平台商品编码" json:"product_platform_code"`
|
||||
ProductPharmacyCode string `gorm:"column:product_pharmacy_code;type:varchar(100);comment:第三方药店商品编码" json:"product_pharmacy_code"`
|
||||
ProductSpec string `gorm:"column:product_spec;type:varchar(255);comment:商品规格" json:"product_spec"`
|
||||
LicenseNumber string `gorm:"column:license_number;type:varchar(255);comment:批准文号" json:"license_number"`
|
||||
Manufacturer string `gorm:"column:manufacturer;type:varchar(255);comment:生产厂家" json:"manufacturer"`
|
||||
SingleUnit string `gorm:"column:single_unit;type:varchar(50);comment:单次剂量单位" json:"single_unit"`
|
||||
PackagingUnit string `gorm:"column:packaging_unit;type:varchar(20);comment:基本包装单位" json:"packaging_unit"`
|
||||
PackagingCount string `gorm:"column:packaging_count;type:varchar(20);comment:基本包装数量" json:"packaging_count"`
|
||||
RetailUnit string `gorm:"column:retail_unit;type:varchar(20);comment:零售单位" json:"retail_unit"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *ProductPlatform) TableName() string {
|
||||
return "gdxz_product_platform"
|
||||
}
|
||||
|
||||
func (m *ProductPlatform) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.ProductPlatformId == 0 {
|
||||
m.ProductPlatformId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
34
api/model/productPlatformAmount.go
Normal file
34
api/model/productPlatformAmount.go
Normal file
@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ProductPlatformAmount 商品-库存表-处方平台
|
||||
type ProductPlatformAmount struct {
|
||||
AmountId int64 `gorm:"column:amount_id;type:bigint(19);primary_key;comment:主键id" json:"amount_id"`
|
||||
ProductPlatformId int64 `gorm:"column:product_platform_id;type:bigint(19);comment:处方平台商品id" json:"product_platform_id"`
|
||||
ProductPlatformCode string `gorm:"column:product_platform_code;type:varchar(100);comment:处方平台商品编码" json:"product_platform_code"`
|
||||
Stock uint `gorm:"column:stock;type:int(11) unsigned;default:0;comment:现有库存" json:"stock"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *ProductPlatformAmount) TableName() string {
|
||||
return "gdxz_product_platform_amount"
|
||||
}
|
||||
|
||||
func (m *ProductPlatformAmount) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.AmountId == 0 {
|
||||
m.AmountId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
89
api/requests/product.go
Normal file
89
api/requests/product.go
Normal file
@ -0,0 +1,89 @@
|
||||
package requests
|
||||
|
||||
type ProductRequest struct {
|
||||
GetPlatformProductPage // 获取平台商品列表-分页
|
||||
GetProductPage // 获取系统商品列表-分页
|
||||
AddProduct // 新增商品
|
||||
PutProduct // 修改商品
|
||||
PutProductStatus // 修改商品状态(上/下架)
|
||||
GetPlatformProductList // 获取平台商品列表
|
||||
}
|
||||
|
||||
// GetPlatformProductPage 获取平台商品列表-分页
|
||||
type GetPlatformProductPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
ProductName string `json:"product_name" form:"product_name" label:"商品名称"` // 商品名称
|
||||
ProductType *int `json:"product_type" form:"product_type" label:"药品类型"` // 药品类型(0:未知 1:中成药 2:西药)
|
||||
ProductPlatformCode string `json:"product_platform_code" form:"product_platform_code" label:"处方平台编码"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code" form:"product_pharmacy_code" label:"药店编码"` // 第三方药店商品编码
|
||||
LicenseNumber string `json:"license_number" form:"license_number" label:"批准文号"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer" form:"manufacturer" label:"生产厂家"` // 生产厂家
|
||||
}
|
||||
|
||||
// GetPlatformProductList 获取平台商品列表
|
||||
type GetPlatformProductList struct {
|
||||
ProductName string `json:"product_name" form:"product_name" label:"商品名称"` // 商品名称
|
||||
ProductType *int `json:"product_type" form:"product_type" label:"药品类型"` // 药品类型(0:未知 1:中成药 2:西药)
|
||||
ProductPlatformCode string `json:"product_platform_code" form:"product_platform_code" label:"处方平台编码"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code" form:"product_pharmacy_code" label:"药店编码"` // 第三方药店商品编码
|
||||
LicenseNumber string `json:"license_number" form:"license_number" label:"批准文号"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer" form:"manufacturer" label:"生产厂家"` // 生产厂家
|
||||
}
|
||||
|
||||
// GetProductPage 获取系统商品列表-分页
|
||||
type GetProductPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
ProductName string `json:"product_name" form:"product_name" label:"商品名称"` // 商品名称
|
||||
CommonName string `json:"common_name" form:"common_name" label:"商品通用名"` // 商品通用名
|
||||
MnemonicCode string `json:"mnemonic_code" form:"mnemonic_code" label:"商品助记码"` // 商品助记码(首字母简拼)
|
||||
ProductType *int `json:"product_type" form:"product_type" label:"药品类型"` // 药品类型(0:未知 1:中成药 2:西药)
|
||||
ProductPlatformId string `json:"product_platform_id" form:"product_platform_id" label:"平台商品id"` // 处方平台商品id
|
||||
ProductPlatformCode string `json:"product_platform_code" form:"product_platform_code" label:"处方平台编码"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code" form:"product_pharmacy_code" label:"药店编码"` // 第三方药店商品编码
|
||||
LicenseNumber string `json:"license_number" form:"license_number" label:"批准文号"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer" form:"manufacturer" label:"生产厂家"` // 生产厂家
|
||||
ProductRemarks string `json:"product_remarks" form:"product_remarks" label:"商品备注"` // 商品备注
|
||||
ProductStatus *int `json:"product_status" form:"product_status" label:"商品状态"` // 商品状态(1:正常 2:下架)
|
||||
}
|
||||
|
||||
// AddProduct 新增商品
|
||||
type AddProduct struct {
|
||||
ProductPlatformId string `json:"product_platform_id" form:"product_platform_id" label:"平台商品id" validate:"required"` // 处方平台商品id
|
||||
ProductName string `json:"product_name" form:"product_name" label:"商品名称" validate:"required"` // 商品名称
|
||||
CommonName string `json:"common_name" form:"common_name" label:"商品通用名" validate:"required"` // 商品通用名
|
||||
ProductPrice float64 `json:"product_price" form:"product_price" label:"商品价格" validate:"required"` // 商品价格
|
||||
MnemonicCode string `json:"mnemonic_code" form:"mnemonic_code" label:"商品助记码"` // 商品助记码(首字母简拼)
|
||||
ProductType *int `json:"product_type" form:"product_type" label:"药品类型" validate:"oneof=0 1 2"` // 药品类型(0:未知 1:中成药 2:西药)
|
||||
ProductPlatformCode string `json:"product_platform_code" form:"product_platform_code" label:"处方平台商品编码" validate:"required"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code" form:"product_pharmacy_code" label:"第三方药店商品编码" validate:"required"` // 第三方药店商品编码
|
||||
ProductCoverImg string `json:"product_cover_img" form:"product_cover_img" label:"商品封面图"` // 商品封面图
|
||||
ProductSpec string `json:"product_spec" form:"product_spec" label:"商品规格" validate:"required"` // 商品规格
|
||||
LicenseNumber string `json:"license_number" form:"license_number" label:"批准文号" validate:"required"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer" form:"manufacturer" label:"生产厂家" validate:"required"` // 生产厂家
|
||||
SingleUnit string `json:"single_unit" form:"single_unit" label:"单次剂量" validate:"required"` // 单次剂量(例:1次1包)
|
||||
SingleUse string `json:"single_use" form:"single_use" label:"单次用法" validate:"required"` // 单次用法(例:口服)
|
||||
PackagingUnit string `json:"packaging_unit" form:"packaging_unit" label:"基本包装单位" validate:"required"` // 基本包装单位(例:盒/瓶)
|
||||
FrequencyUse string `json:"frequency_use" form:"frequency_use" label:"使用频率" validate:"required"` // 使用频率(例:1天3次)
|
||||
AvailableDays float64 `json:"available_days" form:"available_days" label:"可用天数" validate:"required"` // 可用天数(3)
|
||||
ProductRemarks string `json:"product_remarks" form:"product_remarks" label:"商品备注" validate:"required"` // 商品备注
|
||||
ProductStatus *int `json:"product_status" form:"product_status" label:"商品状态" validate:"required,oneof=1 2"` // 商品状态(1:正常 2:下架)
|
||||
}
|
||||
|
||||
// PutProduct 修改商品
|
||||
type PutProduct struct {
|
||||
MnemonicCode string `json:"mnemonic_code" form:"mnemonic_code" label:"商品助记码"` // 商品助记码(首字母简拼)
|
||||
ProductCoverImg string `json:"product_cover_img" form:"product_cover_img" label:"商品封面图"` // 商品封面图
|
||||
SingleUnit string `json:"single_unit" form:"single_unit" label:"单次剂量" validate:"required"` // 单次剂量(例:1次1包)
|
||||
SingleUse string `json:"single_use" form:"single_use" label:"单次用法" validate:"required"` // 单次用法(例:口服)
|
||||
PackagingUnit string `json:"packaging_unit" form:"packaging_unit" label:"基本包装单位" validate:"required"` // 基本包装单位(例:盒/瓶)
|
||||
FrequencyUse string `json:"frequency_use" form:"frequency_use" label:"使用频率" validate:"required"` // 使用频率(例:1天3次)
|
||||
AvailableDays float64 `json:"available_days" form:"available_days" label:"可用天数" validate:"required"` // 可用天数(3)
|
||||
ProductRemarks string `json:"product_remarks" form:"product_remarks" label:"商品备注" validate:"required"` // 商品备注
|
||||
}
|
||||
|
||||
// PutProductStatus 修改商品状态(上/下架)
|
||||
type PutProductStatus struct {
|
||||
ProductStatus *int `json:"product_status" form:"product_status" label:"商品状态" validate:"required,oneof=1 2"` // 商品状态(1:正常 2:下架)
|
||||
}
|
||||
@ -651,4 +651,36 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
prescriptionGroup.POST("", api.Export.OrderPrescription)
|
||||
}
|
||||
}
|
||||
|
||||
// 商品管理
|
||||
productGroup := adminGroup.Group("/product")
|
||||
{
|
||||
// 获取系统商品列表-分页
|
||||
productGroup.GET("", api.Product.GetProductPage)
|
||||
|
||||
// 系统商品详情
|
||||
productGroup.GET("/:product_id", api.Product.GetProduct)
|
||||
|
||||
// 新增商品
|
||||
productGroup.POST("", api.Product.AddProduct)
|
||||
|
||||
// 修改商品
|
||||
productGroup.PUT("/:product_id", api.Product.PutProduct)
|
||||
|
||||
// 修改商品状态(上/下架)
|
||||
productGroup.PUT("/status/:product_id", api.Product.PutProductStatus)
|
||||
|
||||
// 平台商品
|
||||
platformGroup := productGroup.Group("/platform")
|
||||
{
|
||||
// 获取平台商品列表-分页
|
||||
platformGroup.GET("", api.Product.GetPlatformProductPage)
|
||||
|
||||
// 平台商品详情
|
||||
platformGroup.GET("/:product_platform_id", api.Product.GetProductPlatform)
|
||||
|
||||
// 获取平台商品列表
|
||||
platformGroup.GET("/list", api.Product.GetPlatformProductList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,8 +163,8 @@ func (r *OrderService) ReportPreProduct(orderProductId, adminUserId int64) (bool
|
||||
icdNameStr := strings.Join(icdNameSlice, ";")
|
||||
|
||||
// 处理上传数据-药品数据
|
||||
drugRequests := make([]prescription.DrugRequest, len(orderProductItems))
|
||||
orderDrugRequests := make([]prescription.OrderDrugRequest, len(orderProductItems))
|
||||
drugListRequests := make([]prescription.DrugListRequest, len(orderProductItems))
|
||||
orderDrugListRequests := make([]prescription.OrderDrugListRequest, len(orderProductItems))
|
||||
for i, o := range orderProductItems {
|
||||
// 获取商品数据
|
||||
productDao := dao.ProductDao{}
|
||||
@ -179,7 +179,7 @@ func (r *OrderService) ReportPreProduct(orderProductId, adminUserId int64) (bool
|
||||
}
|
||||
|
||||
// 药品数据1
|
||||
drugRequest := prescription.DrugRequest{
|
||||
drugRequest := prescription.DrugListRequest{
|
||||
DrugCode: product.ProductPlatformCode, // 药品编码
|
||||
ApprovalNumber: product.LicenseNumber, // 批准文号
|
||||
DrugName: product.ProductName, // 药品名称
|
||||
@ -194,10 +194,10 @@ func (r *OrderService) ReportPreProduct(orderProductId, adminUserId int64) (bool
|
||||
FrequencyName: product.FrequencyUse, // 频次名称
|
||||
UseDays: useDays, // 使用天数
|
||||
}
|
||||
drugRequests[i] = drugRequest
|
||||
drugListRequests[i] = drugRequest
|
||||
|
||||
// 药品数据2
|
||||
orderDrugRequest := prescription.OrderDrugRequest{
|
||||
orderDrugRequest := prescription.OrderDrugListRequest{
|
||||
DrugCode: product.ProductPlatformCode, // 药品编码
|
||||
ApprovalNumber: product.LicenseNumber, // 批准文号
|
||||
DrugName: product.ProductName, // 药品名称
|
||||
@ -206,7 +206,7 @@ func (r *OrderService) ReportPreProduct(orderProductId, adminUserId int64) (bool
|
||||
DrugCount: o.Amount, // 药品数量
|
||||
PackingUnit: product.PackagingUnit, // 药品单位
|
||||
}
|
||||
orderDrugRequests[i] = orderDrugRequest
|
||||
orderDrugListRequests[i] = orderDrugRequest
|
||||
}
|
||||
|
||||
// 处理上传数据-处方数据
|
||||
@ -237,8 +237,8 @@ func (r *OrderService) ReportPreProduct(orderProductId, adminUserId int64) (bool
|
||||
PhysicalExamination: "无",
|
||||
SupplementaryExamination: "无",
|
||||
AllergicHistory: orderInquiryCase.AllergyHistory,
|
||||
DrugList: drugRequests,
|
||||
OrderDrugList: orderDrugRequests,
|
||||
DrugList: drugListRequests,
|
||||
OrderDrugList: orderDrugListRequests,
|
||||
}
|
||||
|
||||
presRequests[0] = presRequest
|
||||
|
||||
297
api/service/product.go
Normal file
297
api/service/product.go
Normal file
@ -0,0 +1,297 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/extend/prescription"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ProductService struct {
|
||||
}
|
||||
|
||||
// GetProductPlatform 平台商品详情
|
||||
func (r *ProductService) GetProductPlatform(productPlatformId int64) (g *dto.ProductPlatformDto, err error) {
|
||||
// 获取平台商品数据
|
||||
productPlatformDao := dao.ProductPlatformDao{}
|
||||
productPlatform, err := productPlatformDao.GetProductPlatformById(productPlatformId)
|
||||
if err != nil || productPlatform == nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 获取商品库存
|
||||
var quantity int
|
||||
|
||||
ReportPreRequest := prescription.GetProdStockRequest{
|
||||
DrugCode: productPlatform.ProductPharmacyCode,
|
||||
}
|
||||
|
||||
result, err := ReportPreRequest.GetProdStock()
|
||||
if err != nil {
|
||||
quantity = 0
|
||||
}
|
||||
|
||||
if result != nil {
|
||||
if result.Quantity != "" {
|
||||
quantity, err = strconv.Atoi(result.Quantity)
|
||||
if err != nil {
|
||||
quantity = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g = dto.GetProductPlatformDto(productPlatform)
|
||||
|
||||
// 加载商品库存
|
||||
g.LoadProductAmount(quantity)
|
||||
return g, nil
|
||||
}
|
||||
|
||||
// GetProduct 商品详情
|
||||
func (r *ProductService) GetProduct(productId int64) (g *dto.ProductDto, err error) {
|
||||
// 获取商品数据
|
||||
productDao := dao.ProductDao{}
|
||||
product, err := productDao.GetProductById(productId)
|
||||
if err != nil || product == nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 获取商品库存数据
|
||||
productPlatformAmountDao := dao.ProductPlatformAmountDao{}
|
||||
productPlatformAmount, err := productPlatformAmountDao.GetProductPlatformAmountByProductPlatformId(product.ProductPlatformId)
|
||||
|
||||
// 处理返回值
|
||||
g = dto.GetProductDto(product)
|
||||
|
||||
if productPlatformAmount != nil {
|
||||
// 加载库存
|
||||
g.LoadProductAmount(productPlatformAmount)
|
||||
}
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
// AddProduct 新增商品
|
||||
func (r *ProductService) AddProduct(userId string, req requests.AddProduct) (bool, error) {
|
||||
productDao := dao.ProductDao{}
|
||||
productPlatformAmountDao := dao.ProductPlatformAmountDao{}
|
||||
|
||||
productPlatformId, err := strconv.ParseInt(req.ProductPlatformId, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.New("新增失败")
|
||||
}
|
||||
|
||||
// 检测平台商品是否存在
|
||||
productPlatformDao := dao.ProductPlatformDao{}
|
||||
productPlatform, err := productPlatformDao.GetProductPlatformById(productPlatformId)
|
||||
if err != nil || productPlatform == nil {
|
||||
return false, errors.New("平台商品不存在")
|
||||
}
|
||||
|
||||
// 检测商品是否重复
|
||||
maps := make(map[string]interface{})
|
||||
maps["product_platform_id"] = req.ProductPlatformId
|
||||
products, err := productDao.GetProductList(maps)
|
||||
if err != nil {
|
||||
return false, errors.New("商品重复添加")
|
||||
}
|
||||
|
||||
if len(products) != 0 {
|
||||
return false, errors.New("商品重复添加")
|
||||
}
|
||||
|
||||
// 处理图片
|
||||
productCoverImg := utils.RemoveOssDomain(req.ProductCoverImg)
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 新增商品表
|
||||
product := &model.Product{
|
||||
ProductPlatformId: productPlatform.ProductPlatformId,
|
||||
ProductStatus: *req.ProductStatus,
|
||||
ProductName: req.ProductName,
|
||||
CommonName: req.CommonName,
|
||||
ProductPrice: req.ProductPrice,
|
||||
MnemonicCode: req.MnemonicCode,
|
||||
ProductType: *req.ProductType,
|
||||
ProductPlatformCode: req.ProductPlatformCode,
|
||||
ProductPharmacyCode: req.ProductPharmacyCode,
|
||||
ProductCoverImg: productCoverImg,
|
||||
ProductSpec: req.ProductSpec,
|
||||
LicenseNumber: req.LicenseNumber,
|
||||
Manufacturer: req.Manufacturer,
|
||||
SingleUnit: req.SingleUnit,
|
||||
SingleUse: req.SingleUse,
|
||||
PackagingUnit: req.PackagingUnit,
|
||||
FrequencyUse: req.FrequencyUse,
|
||||
AvailableDays: req.AvailableDays,
|
||||
ProductRemarks: req.ProductRemarks,
|
||||
}
|
||||
|
||||
product, err = productDao.AddProduct(tx, product)
|
||||
if err != nil || product == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 获取商品库存
|
||||
ReportPreRequest := prescription.GetProdStockRequest{
|
||||
DrugCode: product.ProductPharmacyCode,
|
||||
}
|
||||
|
||||
result, err := ReportPreRequest.GetProdStock()
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("获取商品库存失败")
|
||||
}
|
||||
|
||||
var quantity int
|
||||
if result.Quantity != "" {
|
||||
quantity, err = strconv.Atoi(result.Quantity)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("获取商品库存失败")
|
||||
}
|
||||
}
|
||||
|
||||
// 新增商品库存
|
||||
productPlatformAmount := &model.ProductPlatformAmount{
|
||||
ProductPlatformId: product.ProductPlatformId,
|
||||
ProductPlatformCode: product.ProductPlatformCode,
|
||||
Stock: uint(quantity),
|
||||
}
|
||||
|
||||
productPlatformAmount, err = productPlatformAmountDao.AddProductPlatformAmount(tx, productPlatformAmount)
|
||||
if err != nil || productPlatformAmount == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// PutProduct 修改商品
|
||||
func (r *ProductService) PutProduct(productId int64, req requests.PutProduct) (bool, error) {
|
||||
// 获取商品数据
|
||||
productDao := dao.ProductDao{}
|
||||
product, err := productDao.GetProductById(productId)
|
||||
if err != nil || product == nil {
|
||||
return false, errors.New("商品数据错误")
|
||||
}
|
||||
|
||||
productData := make(map[string]interface{}) // 医生数据
|
||||
|
||||
// 商品助记码
|
||||
if product.MnemonicCode != req.MnemonicCode {
|
||||
productData["mnemonic_code"] = req.MnemonicCode
|
||||
}
|
||||
|
||||
// 单次剂量
|
||||
if product.SingleUnit != req.SingleUnit {
|
||||
productData["single_unit"] = req.SingleUnit
|
||||
}
|
||||
|
||||
// 单次用法
|
||||
if product.SingleUse != req.SingleUse {
|
||||
productData["single_use"] = req.SingleUse
|
||||
}
|
||||
|
||||
// 基本包装单位
|
||||
if product.PackagingUnit != req.PackagingUnit {
|
||||
productData["packaging_unit"] = req.PackagingUnit
|
||||
}
|
||||
|
||||
// 使用频率
|
||||
if product.FrequencyUse != req.FrequencyUse {
|
||||
productData["frequency_use"] = req.FrequencyUse
|
||||
}
|
||||
|
||||
// 可用天数
|
||||
if product.AvailableDays != req.AvailableDays {
|
||||
productData["available_days"] = req.AvailableDays
|
||||
}
|
||||
|
||||
// 商品备注
|
||||
if product.ProductRemarks != req.ProductRemarks {
|
||||
productData["product_remarks"] = req.ProductRemarks
|
||||
}
|
||||
|
||||
// 商品封面
|
||||
if req.ProductCoverImg != "" {
|
||||
productCoverImg := utils.RemoveOssDomain(req.ProductCoverImg)
|
||||
if product.ProductCoverImg != productCoverImg {
|
||||
productData["product_cover_img"] = productCoverImg
|
||||
}
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 修改商品数据
|
||||
if len(productData) != 0 {
|
||||
err = productDao.EditProductByUserId(tx, productId, productData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("修改失败")
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// PutProductStatus 修改商品状态(上/下架)
|
||||
func (r *ProductService) PutProductStatus(productId int64, req requests.PutProductStatus) (bool, error) {
|
||||
// 获取商品数据
|
||||
productDao := dao.ProductDao{}
|
||||
product, err := productDao.GetProductById(productId)
|
||||
if err != nil || product == nil {
|
||||
return false, errors.New("商品数据错误")
|
||||
}
|
||||
|
||||
if product.ProductStatus == *req.ProductStatus {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// 商品数据
|
||||
productData := make(map[string]interface{}) // 医生数据
|
||||
productData["product_status"] = req.ProductStatus
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 修改商品数据
|
||||
if len(productData) != 0 {
|
||||
err = productDao.EditProductByUserId(tx, productId, productData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("操作失败")
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
@ -90,4 +90,4 @@ pre:
|
||||
pre-plat-client-id: ZD-004
|
||||
pre-plat-client-secret: 0baa5927164710b9f800bf33546b6da3
|
||||
pre-plat-app-url: http://49.233.3.200:6304/api/thridapi/
|
||||
pre-plat-pharmacy-code: ZD-10003
|
||||
pre-plat-pharmacy-code: JG-10009
|
||||
@ -56,37 +56,37 @@ type ReportPreRequest struct {
|
||||
|
||||
// PresRequest 上报处方请求值-处方数据
|
||||
type PresRequest struct {
|
||||
PrescriptionNo string `json:"prescriptionNo"` // 处方编号
|
||||
PrescriptionSubType int `json:"prescriptionSubType"` // 处方类型 0:无类型 1:普通处方 2:儿科处方
|
||||
PatientName string `json:"patientName"` // 就诊人姓名
|
||||
PatientPhone string `json:"patientPhone"` // 就诊人联系方式
|
||||
IdCard string `json:"idCard"` // 身份证号
|
||||
Advice string `json:"advice"` // 医嘱
|
||||
DiagnosisName string `json:"diagnosisName"` // 诊断
|
||||
ThirdDoctorName string `json:"thirdDoctorName"` // 开方医生姓名
|
||||
ThirdDeptName string `json:"thirdDeptName"` // 开方科室名称
|
||||
ThirdDoctorNameImg string `json:"thirdDoctorNameImg"` // 开方医生签名链接
|
||||
PrescriptionTime string `json:"prescriptionTime"` // 开方时间
|
||||
ThirdFirstPharmacist string `json:"thirdFirstPharmacist"` // 初审药师姓名
|
||||
ThirdFirstPharmacistImg string `json:"thirdFirstPharmacistImg"` // 初审药师签名链接
|
||||
ThirdFirstTime string `json:"thirdFirstTime"` // 初审时间
|
||||
ThirdLastPharmacist string `json:"thirdLastPharmacist"` // 终审药师姓名
|
||||
ThirdLastPharmacistImg string `json:"thirdLastPharmacistImg"` // 终审药师签名链接
|
||||
ThirdLastTime string `json:"ThirdLastTime"` // 终审时间
|
||||
ThirdSignImg string `json:"thirdSignImg"` // 处方签章链接
|
||||
ReferenceCharge float64 `json:"referenceCharge"` // 处方费用(不包含运费)
|
||||
ChiefComplaint string `json:"chiefComplaint"` // 主诉
|
||||
HistoryPresent string `json:"historyPresent"` // 现病史
|
||||
PastHistory string `json:"pastHistory"` // 既往史
|
||||
PhysicalExamination string `json:"physicalExamination"` // 体格检查
|
||||
SupplementaryExamination string `json:"supplementaryExamination"` // 辅助检查
|
||||
AllergicHistory string `json:"allergicHistory"` // 过敏史
|
||||
DrugList []DrugRequest `json:"drugList"` // 药品列表
|
||||
OrderDrugList []OrderDrugRequest `json:"orderDrugList"` // 订单药品列表
|
||||
PrescriptionNo string `json:"prescriptionNo"` // 处方编号
|
||||
PrescriptionSubType int `json:"prescriptionSubType"` // 处方类型 0:无类型 1:普通处方 2:儿科处方
|
||||
PatientName string `json:"patientName"` // 就诊人姓名
|
||||
PatientPhone string `json:"patientPhone"` // 就诊人联系方式
|
||||
IdCard string `json:"idCard"` // 身份证号
|
||||
Advice string `json:"advice"` // 医嘱
|
||||
DiagnosisName string `json:"diagnosisName"` // 诊断
|
||||
ThirdDoctorName string `json:"thirdDoctorName"` // 开方医生姓名
|
||||
ThirdDeptName string `json:"thirdDeptName"` // 开方科室名称
|
||||
ThirdDoctorNameImg string `json:"thirdDoctorNameImg"` // 开方医生签名链接
|
||||
PrescriptionTime string `json:"prescriptionTime"` // 开方时间
|
||||
ThirdFirstPharmacist string `json:"thirdFirstPharmacist"` // 初审药师姓名
|
||||
ThirdFirstPharmacistImg string `json:"thirdFirstPharmacistImg"` // 初审药师签名链接
|
||||
ThirdFirstTime string `json:"thirdFirstTime"` // 初审时间
|
||||
ThirdLastPharmacist string `json:"thirdLastPharmacist"` // 终审药师姓名
|
||||
ThirdLastPharmacistImg string `json:"thirdLastPharmacistImg"` // 终审药师签名链接
|
||||
ThirdLastTime string `json:"ThirdLastTime"` // 终审时间
|
||||
ThirdSignImg string `json:"thirdSignImg"` // 处方签章链接
|
||||
ReferenceCharge float64 `json:"referenceCharge"` // 处方费用(不包含运费)
|
||||
ChiefComplaint string `json:"chiefComplaint"` // 主诉
|
||||
HistoryPresent string `json:"historyPresent"` // 现病史
|
||||
PastHistory string `json:"pastHistory"` // 既往史
|
||||
PhysicalExamination string `json:"physicalExamination"` // 体格检查
|
||||
SupplementaryExamination string `json:"supplementaryExamination"` // 辅助检查
|
||||
AllergicHistory string `json:"allergicHistory"` // 过敏史
|
||||
DrugList []DrugListRequest `json:"drugList"` // 药品列表
|
||||
OrderDrugList []OrderDrugListRequest `json:"orderDrugList"` // 订单药品列表
|
||||
}
|
||||
|
||||
// DrugRequest 上报处方请求值-药品数据1
|
||||
type DrugRequest struct {
|
||||
// DrugListRequest 上报处方请求值-药品数据1
|
||||
type DrugListRequest struct {
|
||||
DrugCode string `json:"drugCode"` // 药品编码
|
||||
ApprovalNumber string `json:"approvalNumber"` // 批准文号
|
||||
DrugName string `json:"drugName"` // 药品名称
|
||||
@ -102,8 +102,8 @@ type DrugRequest struct {
|
||||
UseDays int `json:"useDays"` // 使用天数
|
||||
}
|
||||
|
||||
// OrderDrugRequest 上报处方请求值-药品数据2
|
||||
type OrderDrugRequest struct {
|
||||
// OrderDrugListRequest 上报处方请求值-药品数据2
|
||||
type OrderDrugListRequest struct {
|
||||
DrugCode string `json:"drugCode"` // 药品编码
|
||||
ApprovalNumber string `json:"approvalNumber"` // 批准文号
|
||||
DrugName string `json:"drugName"` // 药品名称
|
||||
@ -113,12 +113,30 @@ type OrderDrugRequest struct {
|
||||
PackingUnit string `json:"packingUnit"` // 药品单位
|
||||
}
|
||||
|
||||
// GetProdStockRequest 获取商品库存请求值
|
||||
type GetProdStockRequest struct {
|
||||
PharmacyCode string `json:"pharmacyCode"` // 药房编码
|
||||
DrugCode string `json:"drugCode"` // 三方药房药品编码
|
||||
}
|
||||
|
||||
// 上报处方返回数据
|
||||
type reportPreResponse struct {
|
||||
ResultCode string `json:"resultCode"` // 操作编码
|
||||
ResultDesc string `json:"resultDesc"` // 描述
|
||||
}
|
||||
|
||||
// 获取商品库存返回数据
|
||||
type getProdStockResponse struct {
|
||||
ResultCode string `json:"resultCode"` // 操作编码
|
||||
ResultDesc string `json:"resultDesc"` // 描述
|
||||
Data []GetProdStockDataResponse `json:"data"` // 具体内容
|
||||
}
|
||||
|
||||
type GetProdStockDataResponse struct {
|
||||
Quantity string `json:"quantity"` // 库存
|
||||
Threshold string `json:"threshold"` // 库存阈值
|
||||
}
|
||||
|
||||
// GetToken 获取token
|
||||
func GetToken() (string, error) {
|
||||
// 准备要发送的 JSON 数据
|
||||
@ -328,3 +346,68 @@ func (r ReportPreRequest) ReportPre() (bool, error) {
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// GetProdStock 获取商品库存
|
||||
func (r GetProdStockRequest) GetProdStock() (*GetProdStockDataResponse, error) {
|
||||
r.PharmacyCode = config.C.Pre.PrePlatPharmacyCode
|
||||
jsonData, err := json.Marshal(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 准备请求体
|
||||
requestBody := bytes.NewBuffer(jsonData)
|
||||
|
||||
// 设置请求 URL
|
||||
url := config.C.Pre.PrePlatAppUrl + "v1/pharmacy/pharmacyInventory"
|
||||
|
||||
// 创建 POST 请求
|
||||
req, err := http.NewRequest("POST", url, requestBody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 设置请求头,指定 Content-Type 为 application/json
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
token, _ := global.Redis.Get(context.Background(), "prescription_token").Result()
|
||||
if token == "" {
|
||||
token, err = GetToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
// 发送请求
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
_ = Body.Close()
|
||||
}(resp.Body)
|
||||
|
||||
// 检查响应状态码
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, errors.New("返回数据错误")
|
||||
}
|
||||
|
||||
var response getProdStockResponse
|
||||
err = json.NewDecoder(resp.Body).Decode(&response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if response.ResultCode != "1000" {
|
||||
if response.ResultDesc != "" {
|
||||
return nil, errors.New(response.ResultDesc)
|
||||
}
|
||||
return nil, errors.New("获取商品库存失败")
|
||||
}
|
||||
|
||||
return &response.Data[0], nil
|
||||
}
|
||||
|
||||
@ -7,7 +7,10 @@ import (
|
||||
|
||||
// RemoveOssDomain 去除oss地址中的前缀
|
||||
func RemoveOssDomain(url string) string {
|
||||
return strings.Replace(url, config.C.Oss.OssCustomDomainName, "", 1)
|
||||
if url != "" {
|
||||
url = strings.Replace(url, config.C.Oss.OssCustomDomainName, "", 1)
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
// AddOssDomain 去除oss地址中的前缀
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user