作者 庄敏学

导入增加文件名

... ... @@ -16,6 +16,8 @@ type ImportDataCommand struct {
Code string `form:"code"`
// 条件 - 成本结构会增加条件
Where string `form:"where"`
// 文件名
FileName string `json:"fileName"`
}
func (importDataCommand *ImportDataCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -303,15 +303,12 @@ func (srv ExcelDataService) ImportCost(importDataCommand *command.ImportDataComm
BatchCreateCostManagemant: &domain.BatchCreateCostManagemant{
UserId: importDataCommand.Operator.UserId,
CompanyId: importDataCommand.Operator.CompanyId,
ProjectName: "",
ProjectName: importDataCommand.FileName,
Types: importCostCommand.Types,
CostManagemants: make([]*domain.CostManagemant, 0),
},
}
for key, v := range excelData {
if key == 0 {
createCostManagemant.ProjectName = strings.TrimSpace(v["itemName"])
}
_, mBytes, err := f.GetPicture(f.GetSheetName(index), "E"+fmt.Sprintf("%v", excelImport.RowBegin+key))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "读取图片失败")
... ...
... ... @@ -11,6 +11,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/middleware"
"io"
"path/filepath"
"strings"
)
type BaseController struct {
... ... @@ -124,17 +125,19 @@ func (controller *BaseController) GetExcelFile() (io.Reader, error) {
return excelFile, nil
}
func (controller *BaseController) GetFileWithExt() (io.Reader, string, error) {
func (controller *BaseController) GetFileWithExt() (io.Reader, string,string, error) {
excelFile, fileHeader, err := controller.GetFile("file")
if err != nil {
log.Logger.Error(err.Error())
return nil, "", fmt.Errorf("上传文件不存在")
return nil, "","", fmt.Errorf("上传文件不存在")
}
ext := filepath.Ext(fileHeader.Filename)
if !(ext == ".xlsx" || ext == ".xls" || ext == ".csv") {
return nil, "", fmt.Errorf("仅支持上传文件格式 xls/xlsx/csv")
return nil, "","", fmt.Errorf("仅支持上传文件格式 xls/xlsx/csv")
}
return excelFile, ext, nil
fileName := filepath.Base(fileHeader.Filename)
fileName = strings.TrimRight(fileName,ext)
return excelFile, ext,fileName, nil
}
func Must(err error) {
... ...
... ... @@ -191,9 +191,10 @@ func defaultImport(controller *ExcelDataController) {
err error
r io.Reader
ext string
fileName string
)
excelService := service.NewExcelDataService(nil)
r, ext, err = controller.GetFileWithExt()
r, ext,fileName, err = controller.GetFileWithExt()
if err != nil {
controller.Response(nil, err)
return
... ... @@ -203,6 +204,7 @@ func defaultImport(controller *ExcelDataController) {
cmd.Operator = controller.GetOperator()
cmd.Reader = r
cmd.FileExt = ext
cmd.FileName = fileName
switch cmd.Code {
case domain.ImportCompanyUser:
data, err = excelService.ImportCompanyUser(cmd)
... ...