修复导出 excel 错乱
This commit is contained in:
@@ -246,6 +246,8 @@ type OrderInquiry struct {
|
|||||||
// OrderProductData 药品订单
|
// OrderProductData 药品订单
|
||||||
type OrderProductData struct {
|
type OrderProductData struct {
|
||||||
OrderProductNo string // 订单编号
|
OrderProductNo string // 订单编号
|
||||||
|
PharmacyName string // 发货药房
|
||||||
|
PharmacyCode string // 药房代码
|
||||||
OrderProductStatus string // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
OrderProductStatus string // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||||
AmountTotal float64 // 订单金额
|
AmountTotal float64 // 订单金额
|
||||||
CouponAmountTotal float64 // 优惠卷总金额
|
CouponAmountTotal float64 // 优惠卷总金额
|
||||||
@@ -283,8 +285,6 @@ type OrderProductData struct {
|
|||||||
City string // 城市
|
City string // 城市
|
||||||
County string // 区县
|
County string // 区县
|
||||||
Address string // 详细地址
|
Address string // 详细地址
|
||||||
PharmacyName string // 发货药房
|
|
||||||
PharmacyCode string // 药房代码
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderProductItemData 药品订单-药品列表
|
// OrderProductItemData 药品订单-药品列表
|
||||||
@@ -327,6 +327,8 @@ type OrderServicePackageDto struct {
|
|||||||
|
|
||||||
// OrderPrescriptionData 处方
|
// OrderPrescriptionData 处方
|
||||||
type OrderPrescriptionData struct {
|
type OrderPrescriptionData struct {
|
||||||
|
PharmacyName string // 开方药房
|
||||||
|
PharmacyCode string // 药房代码
|
||||||
DoctorName string // 医生姓名
|
DoctorName string // 医生姓名
|
||||||
PharmacistName string // 药师姓名
|
PharmacistName string // 药师姓名
|
||||||
PrescriptionStatus string // 处方状态(1:待审核 2:待使用 3:已失效 4:已使用)
|
PrescriptionStatus string // 处方状态(1:待审核 2:待使用 3:已失效 4:已使用)
|
||||||
@@ -348,8 +350,6 @@ type OrderPrescriptionData struct {
|
|||||||
PatientMobile string // 患者电话
|
PatientMobile string // 患者电话
|
||||||
DoctorAdvice string // 医嘱
|
DoctorAdvice string // 医嘱
|
||||||
OrderPrescriptionIcd string // 处方诊断疾病
|
OrderPrescriptionIcd string // 处方诊断疾病
|
||||||
PharmacyName string // 开方药房
|
|
||||||
PharmacyCode string // 药房代码
|
|
||||||
CreatedAt string // 创建时间
|
CreatedAt string // 创建时间
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1662,11 +1662,15 @@ func (r *ExportService) OrderProduct(d []*model.OrderProduct) (string, error) {
|
|||||||
|
|
||||||
// 处理药品列表
|
// 处理药品列表
|
||||||
for _, item := range v.OrderProductItem {
|
for _, item := range v.OrderProductItem {
|
||||||
|
var availableDays float64
|
||||||
|
if item.Product != nil {
|
||||||
|
availableDays = item.Product.AvailableDays
|
||||||
|
}
|
||||||
productItem := OrderProductItemData{
|
productItem := OrderProductItemData{
|
||||||
ProductName: item.ProductName,
|
ProductName: item.ProductName,
|
||||||
ProductPlatformCode: item.ProductPlatformCode,
|
ProductPlatformCode: item.ProductPlatformCode,
|
||||||
ProductSpec: item.ProductSpec,
|
ProductSpec: item.ProductSpec,
|
||||||
AvailableDays: item.Product.AvailableDays,
|
AvailableDays: availableDays,
|
||||||
ProductAmount: fmt.Sprintf("%d", item.Amount),
|
ProductAmount: fmt.Sprintf("%d", item.Amount),
|
||||||
ProductPrice: item.ProductPrice,
|
ProductPrice: item.ProductPrice,
|
||||||
}
|
}
|
||||||
|
|||||||
+39
-11
@@ -199,10 +199,12 @@ func fillDataWithMerge(f *excelize.File, sheetName string, header []HeaderCellDa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置单元格样式
|
// 设置单元格样式
|
||||||
err = setCellStyle(f, sheetName, axis, header[i], alignment)
|
if colOffset < len(header) {
|
||||||
|
err = setCellStyle(f, sheetName, axis, header[colOffset], alignment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 设置行高 35-第一行
|
// 设置行高 35-第一行
|
||||||
err = f.SetRowHeight(sheetName, row+1, 35)
|
err = f.SetRowHeight(sheetName, row+1, 35)
|
||||||
@@ -214,23 +216,33 @@ func fillDataWithMerge(f *excelize.File, sheetName string, header []HeaderCellDa
|
|||||||
mergeNum = mergeNum + 1
|
mergeNum = mergeNum + 1
|
||||||
mergeNumSlice = append(mergeNumSlice, colName)
|
mergeNumSlice = append(mergeNumSlice, colName)
|
||||||
} else {
|
} else {
|
||||||
var sliceFieldNum int // 切片字段数量
|
|
||||||
|
|
||||||
// 最大切片数量,此数量为其余需合并的数量
|
// 最大切片数量,此数量为其余需合并的数量
|
||||||
if filedNumSlice < field.Len() {
|
if filedNumSlice < field.Len() {
|
||||||
filedNumSlice = field.Len()
|
filedNumSlice = field.Len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
elemType := field.Type().Elem()
|
||||||
|
if elemType.Kind() == reflect.Ptr {
|
||||||
|
elemType = elemType.Elem()
|
||||||
|
}
|
||||||
|
numSliceFields := 0
|
||||||
|
if elemType.Kind() == reflect.Struct {
|
||||||
|
numSliceFields = elemType.NumField()
|
||||||
|
}
|
||||||
|
|
||||||
for j := 0; j < field.Len(); j++ {
|
for j := 0; j < field.Len(); j++ {
|
||||||
item := field.Index(j).Interface()
|
item := field.Index(j).Interface()
|
||||||
v1 := reflect.ValueOf(item)
|
v1 := reflect.ValueOf(item)
|
||||||
|
if v1.Kind() == reflect.Ptr {
|
||||||
|
v1 = v1.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
for i2 := 0; i2 < field.Index(j).NumField(); i2++ {
|
for i2 := 0; i2 < v1.NumField(); i2++ {
|
||||||
// 获取字段值
|
// 获取字段值
|
||||||
cellValue := v1.Field(i2).Interface()
|
cellValue := v1.Field(i2).Interface()
|
||||||
|
|
||||||
// 获取列名
|
// 获取列名
|
||||||
colName, err := excelize.ColumnNumberToName(i + i2 + 1)
|
colName, err := excelize.ColumnNumberToName(colOffset + i2 + 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@@ -245,24 +257,40 @@ func fillDataWithMerge(f *excelize.File, sheetName string, header []HeaderCellDa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置单元格样式
|
// 设置单元格样式
|
||||||
err = setCellStyle(f, sheetName, axis, header[i+i2], alignment)
|
if colOffset+i2 < len(header) {
|
||||||
|
err = setCellStyle(f, sheetName, axis, header[colOffset+i2], alignment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return row, err
|
return row, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 设置行高 35-第一行
|
// 设置行高 35-第一行
|
||||||
err = f.SetRowHeight(sheetName, row+j+1, 35)
|
err = f.SetRowHeight(sheetName, row+j+1, 35)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return row, err
|
return row, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sliceFieldNum = i2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列偏移量需增加上切片字段数量
|
if field.Len() == 0 {
|
||||||
colOffset = colOffset + sliceFieldNum
|
for i2 := 0; i2 < numSliceFields; i2++ {
|
||||||
|
colName, err := excelize.ColumnNumberToName(colOffset + i2 + 1)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
axis = colName + fmt.Sprintf("%d", row+1)
|
||||||
|
if colOffset+i2 < len(header) {
|
||||||
|
_ = setCellStyle(f, sheetName, axis, header[colOffset+i2], alignment)
|
||||||
|
}
|
||||||
|
_ = f.SetRowHeight(sheetName, row+1, 35)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 列偏移量需增加上切片字段数量(减1是因为循环末尾有colOffset++)
|
||||||
|
if numSliceFields > 0 {
|
||||||
|
colOffset = colOffset + numSliceFields - 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
colOffset++
|
colOffset++
|
||||||
@@ -325,7 +353,7 @@ func setCellStyle(f *excelize.File, sheetName, axis string, header HeaderCellDat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if header.CellType == "float" {
|
if header.CellType == "float" || header.CellType == "float64" {
|
||||||
style.NumFmt = 2
|
style.NumFmt = 2
|
||||||
customNumFmt := "0.000"
|
customNumFmt := "0.000"
|
||||||
style.CustomNumFmt = &customNumFmt
|
style.CustomNumFmt = &customNumFmt
|
||||||
|
|||||||
Reference in New Issue
Block a user