合并分支 'dev' 到 'test'
导入增加文件名 查看合并请求 !18
正在显示
4 个修改的文件
包含
13 行增加
和
9 行删除
| @@ -16,6 +16,8 @@ type ImportDataCommand struct { | @@ -16,6 +16,8 @@ type ImportDataCommand struct { | ||
| 16 | Code string `form:"code"` | 16 | Code string `form:"code"` |
| 17 | // 条件 - 成本结构会增加条件 | 17 | // 条件 - 成本结构会增加条件 |
| 18 | Where string `form:"where"` | 18 | Where string `form:"where"` |
| 19 | + // 文件名 | ||
| 20 | + FileName string `json:"fileName"` | ||
| 19 | } | 21 | } |
| 20 | 22 | ||
| 21 | func (importDataCommand *ImportDataCommand) Valid(validation *validation.Validation) { | 23 | func (importDataCommand *ImportDataCommand) Valid(validation *validation.Validation) { |
| @@ -303,15 +303,12 @@ func (srv ExcelDataService) ImportCost(importDataCommand *command.ImportDataComm | @@ -303,15 +303,12 @@ func (srv ExcelDataService) ImportCost(importDataCommand *command.ImportDataComm | ||
| 303 | BatchCreateCostManagemant: &domain.BatchCreateCostManagemant{ | 303 | BatchCreateCostManagemant: &domain.BatchCreateCostManagemant{ |
| 304 | UserId: importDataCommand.Operator.UserId, | 304 | UserId: importDataCommand.Operator.UserId, |
| 305 | CompanyId: importDataCommand.Operator.CompanyId, | 305 | CompanyId: importDataCommand.Operator.CompanyId, |
| 306 | - ProjectName: "", | 306 | + ProjectName: importDataCommand.FileName, |
| 307 | Types: importCostCommand.Types, | 307 | Types: importCostCommand.Types, |
| 308 | CostManagemants: make([]*domain.CostManagemant, 0), | 308 | CostManagemants: make([]*domain.CostManagemant, 0), |
| 309 | }, | 309 | }, |
| 310 | } | 310 | } |
| 311 | for key, v := range excelData { | 311 | for key, v := range excelData { |
| 312 | - if key == 0 { | ||
| 313 | - createCostManagemant.ProjectName = strings.TrimSpace(v["itemName"]) | ||
| 314 | - } | ||
| 315 | _, mBytes, err := f.GetPicture(f.GetSheetName(index), "E"+fmt.Sprintf("%v", excelImport.RowBegin+key)) | 312 | _, mBytes, err := f.GetPicture(f.GetSheetName(index), "E"+fmt.Sprintf("%v", excelImport.RowBegin+key)) |
| 316 | if err != nil { | 313 | if err != nil { |
| 317 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "读取图片失败") | 314 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "读取图片失败") |
| @@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
| 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/middleware" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/middleware" |
| 12 | "io" | 12 | "io" |
| 13 | "path/filepath" | 13 | "path/filepath" |
| 14 | + "strings" | ||
| 14 | ) | 15 | ) |
| 15 | 16 | ||
| 16 | type BaseController struct { | 17 | type BaseController struct { |
| @@ -124,17 +125,19 @@ func (controller *BaseController) GetExcelFile() (io.Reader, error) { | @@ -124,17 +125,19 @@ func (controller *BaseController) GetExcelFile() (io.Reader, error) { | ||
| 124 | return excelFile, nil | 125 | return excelFile, nil |
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | -func (controller *BaseController) GetFileWithExt() (io.Reader, string, error) { | 128 | +func (controller *BaseController) GetFileWithExt() (io.Reader, string,string, error) { |
| 128 | excelFile, fileHeader, err := controller.GetFile("file") | 129 | excelFile, fileHeader, err := controller.GetFile("file") |
| 129 | if err != nil { | 130 | if err != nil { |
| 130 | log.Logger.Error(err.Error()) | 131 | log.Logger.Error(err.Error()) |
| 131 | - return nil, "", fmt.Errorf("上传文件不存在") | 132 | + return nil, "","", fmt.Errorf("上传文件不存在") |
| 132 | } | 133 | } |
| 133 | ext := filepath.Ext(fileHeader.Filename) | 134 | ext := filepath.Ext(fileHeader.Filename) |
| 134 | if !(ext == ".xlsx" || ext == ".xls" || ext == ".csv") { | 135 | if !(ext == ".xlsx" || ext == ".xls" || ext == ".csv") { |
| 135 | - return nil, "", fmt.Errorf("仅支持上传文件格式 xls/xlsx/csv") | 136 | + return nil, "","", fmt.Errorf("仅支持上传文件格式 xls/xlsx/csv") |
| 136 | } | 137 | } |
| 137 | - return excelFile, ext, nil | 138 | + fileName := filepath.Base(fileHeader.Filename) |
| 139 | + fileName = strings.TrimRight(fileName,ext) | ||
| 140 | + return excelFile, ext,fileName, nil | ||
| 138 | } | 141 | } |
| 139 | 142 | ||
| 140 | func Must(err error) { | 143 | func Must(err error) { |
| @@ -191,9 +191,10 @@ func defaultImport(controller *ExcelDataController) { | @@ -191,9 +191,10 @@ func defaultImport(controller *ExcelDataController) { | ||
| 191 | err error | 191 | err error |
| 192 | r io.Reader | 192 | r io.Reader |
| 193 | ext string | 193 | ext string |
| 194 | + fileName string | ||
| 194 | ) | 195 | ) |
| 195 | excelService := service.NewExcelDataService(nil) | 196 | excelService := service.NewExcelDataService(nil) |
| 196 | - r, ext, err = controller.GetFileWithExt() | 197 | + r, ext,fileName, err = controller.GetFileWithExt() |
| 197 | if err != nil { | 198 | if err != nil { |
| 198 | controller.Response(nil, err) | 199 | controller.Response(nil, err) |
| 199 | return | 200 | return |
| @@ -203,6 +204,7 @@ func defaultImport(controller *ExcelDataController) { | @@ -203,6 +204,7 @@ func defaultImport(controller *ExcelDataController) { | ||
| 203 | cmd.Operator = controller.GetOperator() | 204 | cmd.Operator = controller.GetOperator() |
| 204 | cmd.Reader = r | 205 | cmd.Reader = r |
| 205 | cmd.FileExt = ext | 206 | cmd.FileExt = ext |
| 207 | + cmd.FileName = fileName | ||
| 206 | switch cmd.Code { | 208 | switch cmd.Code { |
| 207 | case domain.ImportCompanyUser: | 209 | case domain.ImportCompanyUser: |
| 208 | data, err = excelService.ImportCompanyUser(cmd) | 210 | data, err = excelService.ImportCompanyUser(cmd) |
-
请 注册 或 登录 后发表评论