import_product_capacities.go
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package service
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/excel"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/ecelData/command"
productRecordCommand "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/command"
productRecordService "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter"
)
// ImportProductCapacities 导入产能数据
func (srv ExcelDataService) ImportProductCapacities(importDataCommand *command.ImportDataCommand) (interface{}, error) {
excelImport := excel.NewExcelImport()
excelImport.RowBegin = 3 //第二行开始读取
excelImport.DataFields = []excel.DataField{
{EnName: "recordDate", CnName: "日期"},
{EnName: "workshopName", CnName: "车间"},
{EnName: "lineName", CnName: "线别"},
{EnName: "sectionName", CnName: "工段"},
{EnName: "workOn", CnName: "班别"},
{EnName: "workerName", CnName: "姓名"},
{EnName: "batchNumber", CnName: "批次号"},
{EnName: "weigh", CnName: "产量(kg)"},
}
excelData, err := converter.OpenImportFileFromIoReader(excelImport, importDataCommand.Reader, importDataCommand.FileExt) //excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
items := make([]productRecordCommand.BatchAddProductCapacitiesCmd, 0, len(excelData))
item := productRecordCommand.BatchAddProductCapacitiesCmd{}
for _, v := range excelData {
item = productRecordCommand.BatchAddProductCapacitiesCmd{
RecordDate: v["recordDate"],
WorkshopName: v["workshopName"],
LineName: v["lineName"],
SectionName: v["sectionName"],
WorkerName: v["workerName"],
BatchNumber: v["batchNumber"],
WorkOn: v["workOn"],
Weigh: v["weigh"],
FailReason: "",
}
items = append(items, item)
}
svr := productRecordService.NewProductRecordService(nil)
failRows, err := svr.BatchAddProductCapacities(importDataCommand.Operator, items)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return srv.importResultWithHeader(excelImport.DataFields, failRows, len(items)), nil
}