|
|
package web_client
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
|
...
|
...
|
@@ -105,18 +103,23 @@ func (controller ExcelDataController) ImportDividendsOrder() { |
|
|
}
|
|
|
|
|
|
func importDividendsOrder(controller ExcelDataController) {
|
|
|
excelFile, fileHeader, err := controller.GetFile("file")
|
|
|
// excelFile, fileHeader, err := controller.GetFile("file")
|
|
|
// if err != nil {
|
|
|
// log.Logger.Error("接收文件失败," + err.Error())
|
|
|
// controller.Response(nil, err)
|
|
|
// return
|
|
|
// }
|
|
|
// if filepath.Ext(fileHeader.Filename) != ".xlsx" {
|
|
|
//TODO 判断文件类型
|
|
|
// log.Logger.Error("获取到的文件:" + fileHeader.Filename)
|
|
|
// controller.Response(nil, errors.New("上传到的文件类型错误"))
|
|
|
// return
|
|
|
// }
|
|
|
fileReader, err := controller.GetExcelFile()
|
|
|
if err != nil {
|
|
|
log.Logger.Error("接收文件失败," + err.Error())
|
|
|
controller.Response(nil, err)
|
|
|
return
|
|
|
}
|
|
|
if filepath.Ext(fileHeader.Filename) != ".xlsx" {
|
|
|
//TODO 判断文件类型
|
|
|
log.Logger.Error("获取到的文件:" + fileHeader.Filename)
|
|
|
controller.Response(nil, errors.New("上传到的文件类型错误"))
|
|
|
return
|
|
|
}
|
|
|
excelImport := excel.NewExcelImport()
|
|
|
excelImport.RowBegin = 2 //第2行开始读取
|
|
|
excelImport.DataFields = []excel.DataField{
|
...
|
...
|
@@ -130,7 +133,7 @@ func importDividendsOrder(controller ExcelDataController) { |
|
|
{EnName: "Expense", CnName: "费用"},
|
|
|
{EnName: "CooperationContractNumber", CnName: "项目合约编号"},
|
|
|
}
|
|
|
excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
|
|
|
excelData, err := excelImport.OpenExcelFromIoReader(fileReader)
|
|
|
if err != nil {
|
|
|
log.Logger.Error("解析excel文件失败," + err.Error())
|
|
|
controller.Response(nil, err)
|
...
|
...
|
@@ -174,18 +177,23 @@ func (controller ExcelDataController) ImportDividendsReturnedOrder() { |
|
|
}
|
|
|
|
|
|
func importDividendsReturnedOrder(controller ExcelDataController) {
|
|
|
excelFile, fileHeader, err := controller.GetFile("file")
|
|
|
// excelFile, fileHeader, err := controller.GetFile("file")
|
|
|
// if err != nil {
|
|
|
// log.Logger.Error("接收文件失败," + err.Error())
|
|
|
// controller.Response(nil, err)
|
|
|
// return
|
|
|
// }
|
|
|
// if filepath.Ext(fileHeader.Filename) != ".xlsx" {
|
|
|
//TODO 判断文件类型
|
|
|
// log.Logger.Error("获取到的文件:" + filepath.Ext(fileHeader.Filename))
|
|
|
// controller.Response(nil, errors.New("上传的文件类型错误"))
|
|
|
// return
|
|
|
// }
|
|
|
fileReader, err := controller.GetExcelFile()
|
|
|
if err != nil {
|
|
|
log.Logger.Error("接收文件失败," + err.Error())
|
|
|
controller.Response(nil, err)
|
|
|
return
|
|
|
}
|
|
|
if filepath.Ext(fileHeader.Filename) != ".xlsx" {
|
|
|
//TODO 判断文件类型
|
|
|
log.Logger.Error("获取到的文件:" + filepath.Ext(fileHeader.Filename))
|
|
|
controller.Response(nil, errors.New("上传的文件类型错误"))
|
|
|
return
|
|
|
}
|
|
|
excelImport := excel.NewExcelImport()
|
|
|
excelImport.RowBegin = 2 //第2行表头开始读取
|
|
|
excelImport.DataFields = []excel.DataField{
|
...
|
...
|
@@ -199,7 +207,7 @@ func importDividendsReturnedOrder(controller ExcelDataController) { |
|
|
{EnName: "OrderGoodPrice", CnName: "*退货价格"},
|
|
|
{EnName: "CooperationContractNumber", CnName: "项目合约编号"},
|
|
|
}
|
|
|
excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
|
|
|
excelData, err := excelImport.OpenExcelFromIoReader(fileReader)
|
|
|
if err != nil {
|
|
|
log.Logger.Error("解析excel文件失败," + err.Error())
|
|
|
controller.Response(nil, err)
|
...
|
...
|
@@ -296,12 +304,10 @@ func (controller ExcelDataController) FileImport() { |
|
|
case domain.ImportCompanyUser:
|
|
|
data, err = excelService.ImportCompanyUser(cmd)
|
|
|
case domain.ImportCooperationUser:
|
|
|
// data,err = excelService.ExportCooperationUser()
|
|
|
case domain.ImportDividendsOrders:
|
|
|
importDividendsOrder(controller)
|
|
|
case domain.ImportOrganization:
|
|
|
importDividendsReturnedOrder(controller)
|
|
|
|
|
|
}
|
|
|
controller.Response(data, err)
|
|
|
}
|
...
|
...
|
|