import_product_trouble.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
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"
productTroubleCommand "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/command"
productTroubleService "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter"
)
// ImportProductTrouble 导入事故记录
func (srv ExcelDataService) ImportProductTrouble(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: "WorkerName", CnName: "姓名"},
{EnName: "TypesName", CnName: "事故类型"},
{EnName: "AmountLoss", CnName: "损失金额"},
}
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([]productTroubleCommand.BatchAddProductTroubleCommand, 0, len(excelData))
item := productTroubleCommand.BatchAddProductTroubleCommand{}
for _, v := range excelData {
item = productTroubleCommand.BatchAddProductTroubleCommand{
RecordDate: v["RecordDate"],
WorkshopName: v["WorkshopName"],
LineName: v["LineName"],
SectionName: v["SectionName"],
WorkerName: v["WorkerName"],
AmountLoss: v["AmountLoss"],
TypesName: v["TypesName"],
FailReason: "",
}
items = append(items, item)
}
svr := productTroubleService.NewProductTroubleService(nil)
failRows, err := svr.BatchAddProductTrouble(importDataCommand.Operator, items)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return srv.importResultWithHeader(excelImport.DataFields, failRows, len(items)), nil
}