|
|
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
|
|
|
} |
...
|
...
|
|