医生银行卡列表-导出
This commit is contained in:
parent
a14d321ffa
commit
32112a3702
@ -116,3 +116,38 @@ func (r *Export) UserDoctor(c *gin.Context) {
|
|||||||
|
|
||||||
responses.OkWithData(ossAddress, c)
|
responses.OkWithData(ossAddress, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserDoctorBankCard 医生银行卡列表
|
||||||
|
func (r *Export) UserDoctorBankCard(c *gin.Context) {
|
||||||
|
userDoctorRequest := requests.UserDoctorRequest{}
|
||||||
|
req := userDoctorRequest.UserDoctorBankCardExportList
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取数据
|
||||||
|
doctorBankCardDao := dao.DoctorBankCardDao{}
|
||||||
|
doctorBankCards, err := doctorBankCardDao.GetDoctorBankCardExportListSearch(req)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 业务处理
|
||||||
|
exportService := service.ExportService{}
|
||||||
|
ossAddress, err := exportService.UserDoctorBankCard(doctorBankCards)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
responses.OkWithData(ossAddress, c)
|
||||||
|
}
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"hospital-admin-api/api/model"
|
"hospital-admin-api/api/model"
|
||||||
"hospital-admin-api/api/requests"
|
"hospital-admin-api/api/requests"
|
||||||
"hospital-admin-api/global"
|
"hospital-admin-api/global"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DoctorBankCardDao struct {
|
type DoctorBankCardDao struct {
|
||||||
@ -90,7 +92,7 @@ func (r *DoctorBankCardDao) AddDoctorBankCardByMap(tx *gorm.DB, data map[string]
|
|||||||
return userDoctorInfo, nil
|
return userDoctorInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDoctorBankCardPage 获取医生列表-分页
|
// GetDoctorBankCardPage 获取医生银行卡列表-分页
|
||||||
func (r *DoctorBankCardDao) GetDoctorBankCardPage(req requests.GetUserDoctorBankCardPage, page, pageSize int) (m []*model.DoctorBankCard, total int64, err error) {
|
func (r *DoctorBankCardDao) GetDoctorBankCardPage(req requests.GetUserDoctorBankCardPage, page, pageSize int) (m []*model.DoctorBankCard, total int64, err error) {
|
||||||
var totalRecords int64
|
var totalRecords int64
|
||||||
|
|
||||||
@ -163,3 +165,83 @@ func (r *DoctorBankCardDao) GetDoctorBankCardPage(req requests.GetUserDoctorBank
|
|||||||
}
|
}
|
||||||
return m, totalRecords, nil
|
return m, totalRecords, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDoctorBankCardExportListSearch 获取医生银行卡列表-分页
|
||||||
|
func (r *DoctorBankCardDao) GetDoctorBankCardExportListSearch(req requests.UserDoctorBankCardExportList) (m []*model.DoctorBankCard, err error) {
|
||||||
|
// 构建查询条件
|
||||||
|
query := global.Db.Model(&model.DoctorBankCard{})
|
||||||
|
|
||||||
|
// 医生
|
||||||
|
query = query.Preload("UserDoctor", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Omit("open_id", "union_id", "wx_session_key")
|
||||||
|
})
|
||||||
|
|
||||||
|
// 用户
|
||||||
|
query = query.Preload("UserDoctor.User", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Omit("user_password", "salt")
|
||||||
|
})
|
||||||
|
|
||||||
|
// 银行
|
||||||
|
query = query.Preload("BasicBank", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Select("bank_id,bank_code,bank_name")
|
||||||
|
})
|
||||||
|
|
||||||
|
// 当前搜索数据
|
||||||
|
if req.Type == 1 {
|
||||||
|
// 手机号
|
||||||
|
if req.Mobile != "" {
|
||||||
|
// 医生
|
||||||
|
doctorUserSubQuery := global.Db.Model(&model.User{}).
|
||||||
|
Select("user_id").
|
||||||
|
Where("mobile = ?", req.Mobile)
|
||||||
|
|
||||||
|
doctorSubQuery := global.Db.Model(&model.UserDoctor{}).
|
||||||
|
Select("doctor_id").
|
||||||
|
Where(gorm.Expr("user_id IN (?)", doctorUserSubQuery))
|
||||||
|
|
||||||
|
query = query.Where("doctor_id IN (?)", doctorSubQuery)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户名称
|
||||||
|
if req.UserName != "" {
|
||||||
|
subQuery := global.Db.Model(&model.User{}).
|
||||||
|
Select("doctor_id").
|
||||||
|
Where("user_name LIKE ?", "%"+req.UserName+"%")
|
||||||
|
|
||||||
|
query = query.Where(gorm.Expr("doctor_id IN (?)", subQuery))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 银行卡号
|
||||||
|
if req.BankCardCode != "" {
|
||||||
|
query = query.Where("bank_card_code = ?", req.BankCardCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 银行名称
|
||||||
|
if req.BankName != "" {
|
||||||
|
subQuery := global.Db.Model(&model.BasicBank{}).
|
||||||
|
Select("bank_id").
|
||||||
|
Where("bank_name LIKE ?", "%"+req.BankName+"%")
|
||||||
|
|
||||||
|
query = query.Where(gorm.Expr("bank_id IN (?)", subQuery))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 当前选择数据
|
||||||
|
if req.Type == 2 {
|
||||||
|
if req.Id == "" {
|
||||||
|
return nil, errors.New("未提供需导出数据编号")
|
||||||
|
}
|
||||||
|
|
||||||
|
id := strings.Split(req.Id, ",")
|
||||||
|
query = query.Where("bank_card_id IN (?)", id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 排序
|
||||||
|
query = query.Order("created_at desc")
|
||||||
|
|
||||||
|
err = query.Find(&m).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ type UserDoctorRequest struct {
|
|||||||
GetUserDoctorList // 获取医生列表
|
GetUserDoctorList // 获取医生列表
|
||||||
GetUserDoctorBankCardPage // 获取医生银行卡列表-分页
|
GetUserDoctorBankCardPage // 获取医生银行卡列表-分页
|
||||||
UserDoctorExportList // 医生列表-导出
|
UserDoctorExportList // 医生列表-导出
|
||||||
|
UserDoctorBankCardExportList // 医生银行卡列表-导出
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserDoctorPage 获取医生列表-分页
|
// GetUserDoctorPage 获取医生列表-分页
|
||||||
@ -172,3 +173,13 @@ type UserDoctorExportList struct {
|
|||||||
IsSysDiagnoCooperation *int `json:"is_sys_diagno_cooperation" form:"is_sys_diagno_cooperation" label:"是否先思达合作医生"` // (0:否 1:是)
|
IsSysDiagnoCooperation *int `json:"is_sys_diagno_cooperation" form:"is_sys_diagno_cooperation" label:"是否先思达合作医生"` // (0:否 1:是)
|
||||||
CreatedAt string `json:"created_at" form:"created_at" label:"注册时间"`
|
CreatedAt string `json:"created_at" form:"created_at" label:"注册时间"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserDoctorBankCardExportList 医生银行卡列表-导出
|
||||||
|
type UserDoctorBankCardExportList 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"`
|
||||||
|
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
|
||||||
|
UserName string `json:"user_name" form:"user_name" label:"用户名"`
|
||||||
|
BankCardCode string `json:"bank_card_code" form:"bank_card_code" label:"银行卡号"`
|
||||||
|
BankName string `json:"bank_name" form:"bank_name" label:"银行名称"`
|
||||||
|
}
|
||||||
|
|||||||
@ -611,8 +611,8 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
// 医生列表
|
// 医生列表
|
||||||
doctorGroup.POST("", api.Export.UserDoctor)
|
doctorGroup.POST("", api.Export.UserDoctor)
|
||||||
|
|
||||||
// 医生银行卡
|
// 医生银行卡列表
|
||||||
doctorGroup.POST("/bank/card", api.UserCaCert.RenewUserCloudCert)
|
doctorGroup.POST("/bank/card", api.Export.UserDoctorBankCard)
|
||||||
|
|
||||||
// 医生账户
|
// 医生账户
|
||||||
doctorGroup.POST("/account", api.UserCaCert.RenewUserCloudCert)
|
doctorGroup.POST("/account", api.UserCaCert.RenewUserCloudCert)
|
||||||
|
|||||||
@ -111,6 +111,17 @@ type UserDoctorData struct {
|
|||||||
BankCardAddress string // 开户银行地址
|
BankCardAddress string // 开户银行地址
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DoctorBankCardData struct {
|
||||||
|
DoctorName string // 医生姓名
|
||||||
|
DoctorMobile string // 医生手机号
|
||||||
|
BankName string // 银行名称
|
||||||
|
BankCardCode string // 银行卡号
|
||||||
|
Province string // 省份
|
||||||
|
City string // 城市
|
||||||
|
County string // 区县
|
||||||
|
CreatedAt time.Time // 创建时间
|
||||||
|
}
|
||||||
|
|
||||||
// DoctorWithdrawal 提现记录
|
// DoctorWithdrawal 提现记录
|
||||||
func (r *ExportService) DoctorWithdrawal(doctorWithdrawals []*model.DoctorWithdrawal) (string, error) {
|
func (r *ExportService) DoctorWithdrawal(doctorWithdrawals []*model.DoctorWithdrawal) (string, error) {
|
||||||
header := []utils.HeaderCellData{
|
header := []utils.HeaderCellData{
|
||||||
@ -682,3 +693,69 @@ func (r *ExportService) UserDoctor(userDoctors []*model.UserDoctor) (string, err
|
|||||||
ossPath = utils.AddOssDomain("/" + ossPath)
|
ossPath = utils.AddOssDomain("/" + ossPath)
|
||||||
return ossPath, nil
|
return ossPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserDoctorBankCard 医生银行卡列表
|
||||||
|
func (r *ExportService) UserDoctorBankCard(d []*model.DoctorBankCard) (string, error) {
|
||||||
|
header := []utils.HeaderCellData{
|
||||||
|
{Value: "医生姓名", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "医生手机号", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||||
|
{Value: "银行名称", CellType: "string", NumberFmt: "", ColWidth: 22},
|
||||||
|
{Value: "银行卡号", CellType: "string", NumberFmt: "", ColWidth: 25},
|
||||||
|
{Value: "省份", CellType: "string", NumberFmt: "", ColWidth: 20},
|
||||||
|
{Value: "城市", CellType: "string", NumberFmt: "", ColWidth: 22},
|
||||||
|
{Value: "区县", CellType: "string", NumberFmt: "", ColWidth: 25},
|
||||||
|
{Value: "创建时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||||||
|
}
|
||||||
|
|
||||||
|
var dataSlice []interface{}
|
||||||
|
for _, v := range d {
|
||||||
|
data := DoctorBankCardData{
|
||||||
|
BankCardCode: v.BankCardCode,
|
||||||
|
Province: v.Province,
|
||||||
|
City: v.City,
|
||||||
|
County: v.County,
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.UserDoctor != nil {
|
||||||
|
// 医生姓名
|
||||||
|
data.DoctorName = v.UserDoctor.UserName
|
||||||
|
|
||||||
|
if v.UserDoctor.User != nil {
|
||||||
|
// 手机号
|
||||||
|
data.DoctorMobile = v.UserDoctor.User.Mobile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.BasicBank != nil {
|
||||||
|
data.BankName = v.BasicBank.BankName
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建时间
|
||||||
|
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.Seed(time.Now().UnixNano()) // 设置随机数
|
||||||
|
ossPath := "admin/export/output" + 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
|
||||||
|
}
|
||||||
|
|||||||
BIN
output.xlsx
BIN
output.xlsx
Binary file not shown.
@ -2,6 +2,7 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/xuri/excelize/v2"
|
"github.com/xuri/excelize/v2"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -283,16 +284,16 @@ func Export(header []HeaderCellData, data []interface{}) (*bytes.Buffer, error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer, err := f.WriteToBuffer()
|
// buffer, err := f.WriteToBuffer()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer, nil
|
|
||||||
|
|
||||||
// 保存文件
|
|
||||||
// if err := f.SaveAs("output.xlsx"); err != nil {
|
|
||||||
// return nil, err
|
// return nil, err
|
||||||
// }
|
// }
|
||||||
// return nil, errors.New("已导出文件")
|
//
|
||||||
|
// return buffer, nil
|
||||||
|
|
||||||
|
// 保存文件
|
||||||
|
if err := f.SaveAs("output.xlsx"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return nil, errors.New("已导出文件")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user