新增平台商品
This commit is contained in:
parent
a92ac8262f
commit
b38c3f17cd
@ -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
|
||||
}
|
||||
|
||||
131
api/controller/product.go
Normal file
131
api/controller/product.go
Normal file
@ -0,0 +1,131 @@
|
||||
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)
|
||||
}
|
||||
|
||||
// GetPlatformProduct 平台商品详情
|
||||
func (r *Product) GetPlatformProduct(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.GetPlatformProduct(productPlatformId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(getPlatformProductResponses, c)
|
||||
}
|
||||
|
||||
// GetSystemProductPage 获取系统商品列表-分页
|
||||
func (r *Product) GetSystemProductPage(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)
|
||||
}
|
||||
116
api/dao/productPlatform.go
Normal file
116
api/dao/productPlatform.go
Normal file
@ -0,0 +1,116 @@
|
||||
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
|
||||
}
|
||||
78
api/dto/PlatformProduct.go
Normal file
78
api/dto/PlatformProduct.go
Normal file
@ -0,0 +1,78 @@
|
||||
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"` // 更新时间
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
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
|
||||
}
|
||||
17
api/requests/product.go
Normal file
17
api/requests/product.go
Normal file
@ -0,0 +1,17 @@
|
||||
package requests
|
||||
|
||||
type ProductRequest struct {
|
||||
GetPlatformProductPage // 获取平台商品列表-分页
|
||||
}
|
||||
|
||||
// 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:"生产厂家"` // 生产厂家
|
||||
}
|
||||
@ -651,4 +651,37 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
prescriptionGroup.POST("", api.Export.OrderPrescription)
|
||||
}
|
||||
}
|
||||
|
||||
// 商品管理
|
||||
productGroup := adminGroup.Group("/product")
|
||||
{
|
||||
// 平台商品
|
||||
platformGroup := productGroup.Group("/platform")
|
||||
{
|
||||
// 获取平台商品列表-分页
|
||||
platformGroup.GET("", api.Product.GetPlatformProductPage)
|
||||
|
||||
// 平台商品详情
|
||||
platformGroup.GET("/:product_platform_id", api.Product.GetPlatformProduct)
|
||||
}
|
||||
|
||||
// 系统商品
|
||||
systemGroup := productGroup.Group("/system")
|
||||
{
|
||||
// 获取系统商品列表-分页
|
||||
systemGroup.GET("", api.Product.GetSystemProductPage)
|
||||
|
||||
// 系统商品详情
|
||||
systemGroup.GET("/:product_id", api.OrderProduct.GetOrderProduct)
|
||||
|
||||
// 新增系统商品
|
||||
systemGroup.POST("", api.Dept.AddDept)
|
||||
|
||||
// 删除系统商品
|
||||
systemGroup.DELETE("", api.Dept.DeleteDept)
|
||||
|
||||
// 修改系统商品
|
||||
systemGroup.PUT("/:product_id", api.Dept.PutDept)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
25
api/service/product.go
Normal file
25
api/service/product.go
Normal file
@ -0,0 +1,25 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
)
|
||||
|
||||
type ProductService struct {
|
||||
}
|
||||
|
||||
// GetPlatformProduct 平台商品详情
|
||||
func (r *ProductService) GetPlatformProduct(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())
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g = dto.GetProductPlatformDto(productPlatform)
|
||||
|
||||
return g, nil
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user