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
}