增加 系统药品导出
This commit is contained in:
parent
f1588a096e
commit
747dd0c306
@ -546,3 +546,51 @@ func (r *Export) OrderPrescription(c *gin.Context) {
|
||||
|
||||
responses.OkWithData(ossAddress, c)
|
||||
}
|
||||
|
||||
// Product 系统药品
|
||||
func (r *Export) Product(c *gin.Context) {
|
||||
productRequest := requests.ProductRequest{}
|
||||
req := productRequest.ProductExportList
|
||||
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
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
productDao := dao.ProductDao{}
|
||||
products, err := productDao.GetProductExportListSearch(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
exportService := service.ExportService{}
|
||||
ossAddress, err := exportService.Product(products)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取当前登陆用户id
|
||||
userId := c.GetInt64("UserId")
|
||||
if userId != 0 {
|
||||
// 记录日志
|
||||
logExport := &model.LogExport{
|
||||
AdminUserId: userId,
|
||||
ExportModule: "处方",
|
||||
ExportFile: utils.RemoveOssDomain(ossAddress),
|
||||
}
|
||||
|
||||
logExportDao := dao.LogExportDao{}
|
||||
_, _ = logExportDao.AddLogExportUnTransaction(logExport)
|
||||
}
|
||||
|
||||
responses.OkWithData(ossAddress, c)
|
||||
}
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/global"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ProductDao struct {
|
||||
@ -154,3 +156,92 @@ func (r *ProductDao) GetProductPageSearch(req requests.GetProductPage, page, pag
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetProductExportListSearch 获取商品列表-导出
|
||||
func (r *ProductDao) GetProductExportListSearch(req requests.ProductExportList) (m []*model.Product, err error) {
|
||||
// 构建查询条件
|
||||
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.Type == 1 {
|
||||
// 商品名称
|
||||
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+"%")
|
||||
}
|
||||
}
|
||||
|
||||
// 当前选中数据
|
||||
if req.Type == 2 {
|
||||
if req.Id == "" {
|
||||
return nil, errors.New("未提供需导出数据编号")
|
||||
}
|
||||
|
||||
id := strings.Split(req.Id, ",")
|
||||
query = query.Where("product_id IN (?)", id)
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
err = query.Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ type ProductRequest struct {
|
||||
PutProduct // 修改商品
|
||||
PutProductStatus // 修改商品状态(上/下架)
|
||||
GetPlatformProductList // 获取平台商品列表
|
||||
ProductExportList // 系统药品-导出
|
||||
}
|
||||
|
||||
// GetPlatformProductPage 获取平台商品列表-分页
|
||||
@ -89,3 +90,20 @@ type PutProduct struct {
|
||||
type PutProductStatus struct {
|
||||
ProductStatus *int `json:"product_status" form:"product_status" label:"商品状态" validate:"required,oneof=1 2"` // 商品状态(1:正常 2:下架)
|
||||
}
|
||||
|
||||
// ProductExportList 系统药品-导出
|
||||
type ProductExportList struct {
|
||||
Type int `json:"type" form:"type" label:"类型" validate:"required,oneof=1 2 3"` // 1:当前搜索数据 2:当前选择数据 3:全部数据
|
||||
Id string `json:"id" form:"id" label:"id"` // 选择数据的id,逗号分隔,当type为2时必填
|
||||
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:下架)
|
||||
}
|
||||
|
||||
@ -663,6 +663,13 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
// 处方
|
||||
prescriptionGroup.POST("", api.Export.OrderPrescription)
|
||||
}
|
||||
|
||||
// 药品
|
||||
productGroup := exportGroup.Group("/product")
|
||||
{
|
||||
// 系统药品
|
||||
productGroup.POST("", api.Export.Product)
|
||||
}
|
||||
}
|
||||
|
||||
// 商品管理
|
||||
|
||||
@ -308,6 +308,31 @@ type OrderPrescriptionData struct {
|
||||
CreatedAt time.Time // 创建时间
|
||||
}
|
||||
|
||||
// ProductData 系统商品
|
||||
type ProductData struct {
|
||||
ProductName string // 商品名称
|
||||
CommonName string // 商品通用名
|
||||
Stock string // 库存
|
||||
ProductStatus string // 商品状态(1:正常 2:下架)
|
||||
IsDelete string // 是否删除(0:否 1:是)
|
||||
PrescriptionNum string // 处方可开具的数量
|
||||
ProductPrice float64 // 商品价格
|
||||
MnemonicCode string // 商品助记码(首字母简拼)
|
||||
ProductType string // 药品类型(0:未知 1:中成药 2:西药)
|
||||
ProductPlatformCode string // 处方平台商品编码
|
||||
ProductPharmacyCode string // 第三方药店商品编码
|
||||
ProductSpec string // 商品规格
|
||||
LicenseNumber string // 批准文号
|
||||
Manufacturer string // 生产厂家
|
||||
SingleUnit string // 单次剂量(例:1次1包)
|
||||
SingleUse string // 单次用法(例:口服)
|
||||
PackagingUnit string // 基本包装单位(例:盒/瓶)
|
||||
FrequencyUse string // 使用频率(例:1天3次)
|
||||
AvailableDays float64 // 可用天数(3)
|
||||
ProductRemarks string // 商品备注
|
||||
CreatedAt time.Time // 创建时间
|
||||
}
|
||||
|
||||
// DoctorWithdrawal 提现记录
|
||||
func (r *ExportService) DoctorWithdrawal(doctorWithdrawals []*model.DoctorWithdrawal) (string, error) {
|
||||
header := []utils.HeaderCellData{
|
||||
@ -1748,3 +1773,87 @@ func (r *ExportService) OrderPrescription(d []*model.OrderPrescription) (string,
|
||||
ossPath = utils.AddOssDomain("/" + ossPath)
|
||||
return ossPath, nil
|
||||
}
|
||||
|
||||
// Product 系统药品
|
||||
func (r *ExportService) Product(d []*model.Product) (string, error) {
|
||||
header := []utils.HeaderCellData{
|
||||
{Value: "商品名称", CellType: "string", NumberFmt: "", ColWidth: 40},
|
||||
{Value: "商品通用名", CellType: "string", NumberFmt: "", ColWidth: 40},
|
||||
{Value: "库存", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "商品状态", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "是否删除", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "处方可开具的数量", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "商品价格", CellType: "float64", NumberFmt: "0.0000", ColWidth: 18},
|
||||
{Value: "商品助记码(首字母简拼)", CellType: "string", NumberFmt: "", ColWidth: 30},
|
||||
{Value: "药品类型", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "处方平台商品编码", CellType: "string", NumberFmt: "", ColWidth: 30},
|
||||
{Value: "第三方药店商品编码", CellType: "string", NumberFmt: "", ColWidth: 30},
|
||||
{Value: "商品规格", CellType: "string", NumberFmt: "", ColWidth: 30},
|
||||
{Value: "批准文号", CellType: "string", NumberFmt: "", ColWidth: 30},
|
||||
{Value: "生产厂家", CellType: "string", NumberFmt: "", ColWidth: 40},
|
||||
{Value: "单次剂量(例:1次1包)", CellType: "string", NumberFmt: "", ColWidth: 30},
|
||||
{Value: "单次用法(例:口服)", CellType: "string", NumberFmt: "", ColWidth: 30},
|
||||
{Value: "基本包装单位(例:盒/瓶)", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "使用频率(例:1天3次)", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "可用天数(3)", CellType: "float64", NumberFmt: "0.0000", ColWidth: 18},
|
||||
{Value: "商品备注", CellType: "string", NumberFmt: "", ColWidth: 40},
|
||||
{Value: "创建时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||||
}
|
||||
|
||||
var dataSlice []interface{}
|
||||
for _, v := range d {
|
||||
data := ProductData{
|
||||
ProductName: v.ProductName,
|
||||
CommonName: v.CommonName,
|
||||
Stock: "0",
|
||||
ProductStatus: utils.IsProductStatusToString(v.ProductStatus),
|
||||
IsDelete: utils.IsIsDeleteToString(v.IsDelete),
|
||||
PrescriptionNum: fmt.Sprintf("%d", v.PrescriptionNum),
|
||||
ProductPrice: v.ProductPrice,
|
||||
MnemonicCode: v.MnemonicCode,
|
||||
ProductType: utils.IsProductTypeToString(v.ProductType),
|
||||
ProductPlatformCode: v.ProductPlatformCode,
|
||||
ProductPharmacyCode: v.ProductPharmacyCode,
|
||||
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,
|
||||
}
|
||||
|
||||
if v.ProductPlatformAmount != nil {
|
||||
data.Stock = strconv.Itoa(int(v.ProductPlatformAmount.Stock))
|
||||
}
|
||||
|
||||
if v.CreatedAt != (model.LocalTime{}) {
|
||||
t := time.Time(v.CreatedAt)
|
||||
data.CreatedAt = t
|
||||
}
|
||||
|
||||
dataSlice = append(dataSlice, data)
|
||||
}
|
||||
|
||||
file, err := utils.Export(header, dataSlice)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 设置文件名字
|
||||
now := time.Now()
|
||||
dateTimeString := now.Format("20060102150405") // 当前时间字符串
|
||||
rand.New(rand.NewSource(time.Now().UnixNano())) // 设置随机数
|
||||
ossPath := "admin/export/系统药品" + dateTimeString + fmt.Sprintf("%d", rand.Intn(9000)+1000) + ".xlsx"
|
||||
|
||||
// 上传oss
|
||||
_, err = aliyun.PutObjectByte(ossPath, file.Bytes())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
ossPath = utils.AddOssDomain("/" + ossPath)
|
||||
return ossPath, nil
|
||||
}
|
||||
|
||||
@ -565,3 +565,41 @@ func IsAutoPharVerifyToString(i int) string {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// IsProductStatusToString 商品状态(1:正常 2:下架)
|
||||
func IsProductStatusToString(i int) string {
|
||||
switch i {
|
||||
case 0:
|
||||
return "下架"
|
||||
case 1:
|
||||
return "正常"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// IsIsDeleteToString 是否删除(0:否 1:是)
|
||||
func IsIsDeleteToString(i int) string {
|
||||
switch i {
|
||||
case 0:
|
||||
return "否"
|
||||
case 1:
|
||||
return "是"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// IsProductTypeToString 药品类型(0:未知 1:中成药 2:西药)
|
||||
func IsProductTypeToString(i int) string {
|
||||
switch i {
|
||||
case 0:
|
||||
return "未知"
|
||||
case 1:
|
||||
return "中成药"
|
||||
case 2:
|
||||
return "西药"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user