作者 Your Name

更新产能导入

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
}
... ...
... ... @@ -9,7 +9,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter"
)
// ImportProductRecord 导入生产记录
// ImportProductRecord 导入二级品生产记录
func (srv ExcelDataService) ImportProductRecord(importDataCommand *command.ImportDataCommand) (interface{}, error) {
excelImport := excel.NewExcelImport()
excelImport.RowBegin = 3 //第二行开始读取
... ...
... ... @@ -64,6 +64,8 @@ func (controller *ExcelDataController) FileImport() {
data, err = excelService.ImportProductRecord(cmd)
case "ImportAttendance":
data, err = excelService.ImportDataAttendance(cmd)
case "ImportProductCapacities":
data, err = excelService.ImportDataAttendance(cmd)
default:
err = application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("导入不存在 Code:%v", cmd.Code))
}
... ...
... ... @@ -132,7 +132,7 @@ func (controller *ProductRecordController) SearchWorkshopProductRecord() {
// 产能管理 添加产能
func (controller *ProductRecordController) CreateProductCapacities() {
productRecordService := service.NewProductRecordService(nil)
saveCommand := &command.SaveProductRecordCmd{}
saveCommand := &command.SaveProductCapacitiesCmd{}
controller.Unmarshal(saveCommand)
operateInfo := ParseOperateInfo(controller.BaseController)
data, err := productRecordService.SaveProductCapacities(operateInfo, saveCommand)
... ... @@ -142,7 +142,7 @@ func (controller *ProductRecordController) CreateProductCapacities() {
// 产能管理 编辑产能
func (controller *ProductRecordController) UpdateProductCapacities() {
productRecordService := service.NewProductRecordService(nil)
saveCommand := &command.SaveProductRecordCmd{}
saveCommand := &command.SaveProductCapacitiesCmd{}
controller.Unmarshal(saveCommand)
productRecordId, _ := controller.GetInt(":productRecordId")
saveCommand.ProductRecordId = productRecordId
... ...