From 80a9433667270e033cadd19410de75458794090d Mon Sep 17 00:00:00 2001 From: zhangxin Date: Thu, 23 Dec 2021 09:48:30 +0800 Subject: [PATCH] =?UTF-8?q?product=E5=88=A0=E9=99=A4worklineid=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=80=9A=E8=BF=87excel=E5=AF=BC=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- meta/me/Product.meta.go | 4 +- models/me/Product.model.go | 1 - services/me/BomHead.service.go | 19 +++ services/me/ProductFamily.service.go | 19 +++ services/me/ProductFamilyRelate.service.go | 19 +++ services/me/implments/BomHead.service.impl.go | 10 +- services/me/implments/Product.service.impl.go | 1 - .../implments/ProductFamily.service.impl.go | 112 +++++++++++++++ .../ProductFamilyRelate.service.impl.go | 131 ++++++++++++++++++ web/controllers/me/BomHead.rest.go | 57 +++++++- web/controllers/me/ProductFamily.rest.go | 55 ++++++++ .../me/ProductFamilyRelate.rest.go | 55 ++++++++ web/controllers/me/me.go | 6 + 13 files changed, 480 insertions(+), 9 deletions(-) diff --git a/meta/me/Product.meta.go b/meta/me/Product.meta.go index 11ae229..272923f 100644 --- a/meta/me/Product.meta.go +++ b/meta/me/Product.meta.go @@ -40,7 +40,6 @@ var Product_CreatePackOrderToggle = grmi.NewField("CreatePackOrderToggle", "[ME_ var Product_PackSize = grmi.NewField("PackSize", "[ME_Product].PackSize", "packsize", grmi.TypeInt) var PackOrderItemSize = grmi.NewField("PackOrderItemSize", "[ME_Product].PackOrderItemSize", "packorderitemsize", grmi.TypeInt) var Product_Jph = grmi.NewField("Jph", "[ME_Product].Jph", "jph", grmi.TypeFloat64) -var Product_WorkLineId = grmi.NewField("WorkLineId", "[ME_Product].WorkLineId", "worklineid", grmi.TypeString) var Product_PlanPriority = grmi.NewField("PlanPriority", "[ME_Product].PlanPriority", "planpriority", grmi.TypeInt) var Product_BatchSize = grmi.NewField("BatchSize", "[ME_Product].BatchSize", "batchsize", grmi.TypeInt) var Product_LeadTimeInSecond = grmi.NewField("LeadTimeInSecond", "[ME_Product].LeadTimeInSecond", "leadtimeinsecond", grmi.TypeInt) @@ -95,7 +94,6 @@ var Product = grmi.NewEntity( Product_PackSize.Name: Product_PackSize, PackOrderItemSize.Name: PackOrderItemSize, Product_Jph.Name: Product_Jph, - Product_WorkLineId.Name: Product_WorkLineId, Product_PlanPriority.Name: Product_PlanPriority, Product_BatchSize.Name: Product_BatchSize, Product_LeadTimeInSecond.Name: Product_LeadTimeInSecond, @@ -114,4 +112,4 @@ var Product = grmi.NewEntity( Product_CreateTime.Name: Product_CreateTime, }, []string{"PlantNr"}, - []string{"Descr", "Descr1", "Descr2", "PartId", "DefaultWorkLineId", "MultiWorkLineToggle", "CustPartId", "IntPartId", "PlanType", "PlanMode", "ProductType", "ProductType1", "ProductType2", "ProductSpec", "ProductSpec1", "ProductSpec2", "AllowPackToggle", "CreateWorkOrderToggle", "CreatePackOrderToggle", "PackSize", "PackOrderItemSize", "Jph", "WorkLineId", "PlanPriority", "BatchSize", "LeadTimeInSecond", "PickingFlag", "MachineCode", "ColorValue", "PrintTemplateId", "CtrlPara1", "CtrlPara2", "CtrlStr1", "CtrlStr2", "CtrlTime1", "CtrlTime2", "LastUser"}) + []string{"Descr", "Descr1", "Descr2", "PartId", "DefaultWorkLineId", "MultiWorkLineToggle", "CustPartId", "IntPartId", "PlanType", "PlanMode", "ProductType", "ProductType1", "ProductType2", "ProductSpec", "ProductSpec1", "ProductSpec2", "AllowPackToggle", "CreateWorkOrderToggle", "CreatePackOrderToggle", "PackSize", "PackOrderItemSize", "Jph", "PlanPriority", "BatchSize", "LeadTimeInSecond", "PickingFlag", "MachineCode", "ColorValue", "PrintTemplateId", "CtrlPara1", "CtrlPara2", "CtrlStr1", "CtrlStr2", "CtrlTime1", "CtrlTime2", "LastUser"}) diff --git a/models/me/Product.model.go b/models/me/Product.model.go index 56bc770..6a8a42f 100644 --- a/models/me/Product.model.go +++ b/models/me/Product.model.go @@ -46,7 +46,6 @@ type Product struct { PackSize int `xorm:"int 'PackSize' not null" json:"ME_Product-PackSize"` PackOrderItemSize int `xorm:"int 'PackOrderItemSize' not null" json:"ME_Product-PackOrderItemSize"` Jph float64 `xorm:"float 'Jph' not null" json:"ME_Product-Jph"` - WorkLineId string `xorm:"nvarchar(40) 'WorkLineId' not null" json:"ME_Product-WorkLineId"` PlanPriority int `xorm:"int 'PlanPriority' not null" json:"ME_Product-PlanPriority"` BatchSize int `xorm:"int 'BatchSize' not null" json:"ME_Product-BatchSize"` LeadTimeInSecond int `xorm:"int 'LeadTimeInSecond' not null" json:"ME_Product-LeadTimeInSecond"` diff --git a/services/me/BomHead.service.go b/services/me/BomHead.service.go index 3aa404c..a0ed182 100644 --- a/services/me/BomHead.service.go +++ b/services/me/BomHead.service.go @@ -194,6 +194,25 @@ type BomHeadService interface { * ******************************************************************************/ Copy(user *global.User, sourceArtId string, targetArtIdLi []string) error + /****************************************************************************** + * + * @Function Name : ImportFromExcel + *----------------------------------------------------------------------------- + * + * @Description : 复制 + * + * @Function Parameters : 当前访问人员信息 + * + * @Function Parameters : 文件路径 + * + * @Return Value : 执行时发生的错误 + * + * @Author : zhangxin + * + * @Date : 2021-12-22 + * + ******************************************************************************/ + ImportFromExcel(user *global.User, filepath string) error } /****************************************************************************** diff --git a/services/me/ProductFamily.service.go b/services/me/ProductFamily.service.go index 1a1ec77..0055983 100644 --- a/services/me/ProductFamily.service.go +++ b/services/me/ProductFamily.service.go @@ -233,6 +233,25 @@ type ProductFamilyService interface { * ******************************************************************************/ Association(user *global.User, entity *model.ProductFamily) error + /****************************************************************************** + * + * @Function Name : ImportFromExcel + *----------------------------------------------------------------------------- + * + * @Description : 复制 + * + * @Function Parameters : 当前访问人员信息 + * + * @Function Parameters : 文件路径 + * + * @Return Value : 执行时发生的错误 + * + * @Author : zhangxin + * + * @Date : 2021-12-22 + * + ******************************************************************************/ + ImportFromExcel(user *global.User, filepath string) error } /****************************************************************************** diff --git a/services/me/ProductFamilyRelate.service.go b/services/me/ProductFamilyRelate.service.go index 886d0fc..1e60b3d 100644 --- a/services/me/ProductFamilyRelate.service.go +++ b/services/me/ProductFamilyRelate.service.go @@ -203,6 +203,25 @@ type ProductFamilyRelateService interface { * ******************************************************************************/ Update(*global.User, *[]model.ProductFamilyRelate) error + /****************************************************************************** + * + * @Function Name : ImportFromExcel + *----------------------------------------------------------------------------- + * + * @Description : 复制 + * + * @Function Parameters : 当前访问人员信息 + * + * @Function Parameters : 文件路径 + * + * @Return Value : 执行时发生的错误 + * + * @Author : zhangxin + * + * @Date : 2021-12-22 + * + ******************************************************************************/ + ImportFromExcel(user *global.User, filepath string) error } /****************************************************************************** diff --git a/services/me/implments/BomHead.service.impl.go b/services/me/implments/BomHead.service.impl.go index aa05a9d..e770427 100644 --- a/services/me/implments/BomHead.service.impl.go +++ b/services/me/implments/BomHead.service.impl.go @@ -478,6 +478,10 @@ func (impl *BomHeadServiceImplement) ImportFromExcel(user *global.User, filepath for rowsIterator.Next() { rowIndex++ if rowIndex == 1 { + _, err = rowsIterator.Columns() + if err != nil { + return grmi.NewBusinessError("去读excel行数据失败, error:" + err.Error()) + } continue } row, err := rowsIterator.Columns() @@ -485,15 +489,15 @@ func (impl *BomHeadServiceImplement) ImportFromExcel(user *global.User, filepath return grmi.NewBusinessError("去读excel行数据失败, error:" + err.Error()) } if len(row) != 5 { - return grmi.NewBusinessError("excel数据不合规, 行数:" + strconv.Itoa(rowIndex)) + return grmi.NewBusinessError("excel数据列数不合规, 行数:" + strconv.Itoa(rowIndex)) } fmatQty, err := strconv.Atoi(row[2]) if err != nil { - return grmi.NewBusinessError("excel数据不合规, 行数:" + strconv.Itoa(rowIndex)) + return grmi.NewBusinessError("excel数据fmatQty不合规, 行数:" + strconv.Itoa(rowIndex)) } cmatQty, err := strconv.Atoi(row[4]) if err != nil { - return grmi.NewBusinessError("excel数据不合规, 行数:" + strconv.Itoa(rowIndex)) + return grmi.NewBusinessError("excel数据cmatQty不合规, 行数:" + strconv.Itoa(rowIndex)) } fmatDesc, exist := articleMap[row[1]] if !exist { diff --git a/services/me/implments/Product.service.impl.go b/services/me/implments/Product.service.impl.go index 14e4c55..cabea4f 100644 --- a/services/me/implments/Product.service.impl.go +++ b/services/me/implments/Product.service.impl.go @@ -45,7 +45,6 @@ var DefaultConditionOfProduct = grmi.NewCondition( meta.Product_PackSize.UrlParameterName: grmi.NewConditionItem(meta.Product_PackSize, grmi.Equal, false), meta.PackOrderItemSize.UrlParameterName: grmi.NewConditionItem(meta.PackOrderItemSize, grmi.Equal, false), meta.Product_Jph.UrlParameterName: grmi.NewConditionItem(meta.Product_Jph, grmi.Equal, false), - meta.Product_WorkLineId.UrlParameterName: grmi.NewConditionItem(meta.Product_WorkLineId, grmi.Equal, false), meta.Product_PlanPriority.UrlParameterName: grmi.NewConditionItem(meta.Product_PlanPriority, grmi.Equal, false), meta.Product_BatchSize.UrlParameterName: grmi.NewConditionItem(meta.Product_BatchSize, grmi.Equal, false), meta.Product_LeadTimeInSecond.UrlParameterName: grmi.NewConditionItem(meta.Product_LeadTimeInSecond, grmi.Equal, false), diff --git a/services/me/implments/ProductFamily.service.impl.go b/services/me/implments/ProductFamily.service.impl.go index 2226798..5c72bdd 100644 --- a/services/me/implments/ProductFamily.service.impl.go +++ b/services/me/implments/ProductFamily.service.impl.go @@ -13,6 +13,8 @@ import ( jitModel "LAPP_ACURA_MOM_BACKEND/models/jit" model "LAPP_ACURA_MOM_BACKEND/models/me" "fmt" + "github.com/360EntSecGroup-Skylar/excelize/v2" + "strconv" ) /****************************************************************************** @@ -520,3 +522,113 @@ func (impl *ProductFamilyServiceImplement) GeneratePackTemplate(user *global.Use _ = session.Commit() return nil } + +// ImportFromExcel 从excel导入数据 +func (impl *ProductFamilyServiceImplement) ImportFromExcel(user *global.User, filepath string) error { + grmi.Log(user, "/services/me/implments/ProductFamily.service.impl.go", "ImportFromExcel", "Copy复制Bom") + + engine := db.Eloquent.Master() + session := engine.NewSession() + defer session.Close() + daoProject := dal.NewProjectDAO(session, user.PlantNr, user.UserId) + daoProductFamily := dal.NewProductFamilyDAO(session, user.PlantNr, user.UserId) + file, err := excelize.OpenFile(filepath) + if err != nil { + return grmi.NewBusinessError("读取文件失败, error:" + err.Error()) + } + rowsIterator, err := file.Rows("Sheet1") + if err != nil { + return grmi.NewBusinessError("读取Sheet1页失败, error:" + err.Error()) + } + rowIndex := 0 + projectMap := make(map[string]interface{}) + productFamilyLi := make([]model.ProductFamily, 0) + for rowsIterator.Next() { + rowIndex++ + if rowIndex == 1 { + _, err = rowsIterator.Columns() + if err != nil { + return grmi.NewBusinessError("去读excel行数据失败, error:" + err.Error()) + } + continue + } + row, err := rowsIterator.Columns() + if err != nil { + return grmi.NewBusinessError("去读excel行数据失败, error:" + err.Error()) + } + if len(row) != 11 { + return grmi.NewBusinessError("excel数据不合规, 行数:" + strconv.Itoa(rowIndex)) + } + _, exist := projectMap[row[2]] + if !exist { + project, err := daoProject.SelectOne(row[2]) + if err != nil { + return grmi.NewBusinessError("查询车型项目数据失败, error:" + err.Error()) + } + if project == nil { + return grmi.NewBusinessError("车型项目不存在, 车型项目ID:" + row[2]) + } + projectMap[row[2]] = nil + } + var autoGenPackToggle bool + if row[6] == "0" { + autoGenPackToggle = false + } else if row[6] == "1" { + autoGenPackToggle = true + } else { + return grmi.NewBusinessError("excel数据不合规, 行数:" + strconv.Itoa(rowIndex)) + } + + jph, err := strconv.Atoi(row[7]) + if err != nil { + return grmi.NewBusinessError("excel数据不合规, 行数:" + strconv.Itoa(rowIndex)) + } + var checkSynKey bool + if row[10] == "0" { + checkSynKey = false + } else if row[10] == "1" { + checkSynKey = true + } else { + return grmi.NewBusinessError("excel数据不合规, 行数:" + strconv.Itoa(rowIndex)) + } + productFamily := model.ProductFamily{ + ProductFamilyId: row[0], + Descr: row[1], + ProjectId: row[2], + ConfigValue: row[3], + ModelValue: row[4], + ColorValue: row[5], + AutoGenPackToggle: autoGenPackToggle, + Jph: float64(jph), + WorkLineId: row[8], + PackTypeId: row[9], + CheckSyncKey: checkSynKey, + } + productFamilyLi = append(productFamilyLi, productFamily) + } + if err = session.Begin(); err != nil { + return err + } + fmt.Println("productFamilyLi:", productFamilyLi) + tempProductFamilyLi := make([]model.ProductFamily, 0, 20) + for index, productFamily := range productFamilyLi { + if index != 0 && index % 20 == 0 { + err = daoProductFamily.Insert(&tempProductFamilyLi) + if err != nil { + _ = session.Rollback() + return grmi.NewBusinessError("写入派生数据失败, error:" + err.Error()) + } + tempProductFamilyLi = make([]model.ProductFamily, 0, 20) + } + tempProductFamilyLi = append(tempProductFamilyLi, productFamily) + } + if len(tempProductFamilyLi) != 0 { + err = daoProductFamily.Insert(&tempProductFamilyLi) + if err != nil { + _ = session.Rollback() + return grmi.NewBusinessError("写入派生数据失败, error:" + err.Error()) + } + } + _ = session.Commit() + return nil +} diff --git a/services/me/implments/ProductFamilyRelate.service.impl.go b/services/me/implments/ProductFamilyRelate.service.impl.go index d357b50..e4dede9 100644 --- a/services/me/implments/ProductFamilyRelate.service.impl.go +++ b/services/me/implments/ProductFamilyRelate.service.impl.go @@ -9,6 +9,8 @@ import ( "LAPP_ACURA_MOM_BACKEND/grmi" meta "LAPP_ACURA_MOM_BACKEND/meta/me" model "LAPP_ACURA_MOM_BACKEND/models/me" + "github.com/360EntSecGroup-Skylar/excelize/v2" + "strconv" ) /****************************************************************************** @@ -326,3 +328,132 @@ func (impl *ProductFamilyRelateServiceImplement) Update(user *global.User, entit } return nil } + +// ImportFromExcel 从excel导入数据 +func (impl *ProductFamilyRelateServiceImplement) ImportFromExcel(user *global.User, filepath string) error { + grmi.Log(user, "/services/me/implments/ProductFamilyRelate.service.impl.go", "ImportFromExcel", "Copy复制Bom") + + engine := db.Eloquent.Master() + session := engine.NewSession() + defer session.Close() + daoProject := dal.NewProjectDAO(session, user.PlantNr, user.UserId) + daoProductFamily := dal.NewProductFamilyDAO(session, user.PlantNr, user.UserId) + daoProduct := dal.NewProductDAO(session, user.PlantNr, user.UserId) + daoProductFamilyRelate := dal.NewProductFamilyRelateDAO(session, user.PlantNr, user.UserId) + file, err := excelize.OpenFile(filepath) + if err != nil { + return grmi.NewBusinessError("读取文件失败, error:" + err.Error()) + } + rowsIterator, err := file.Rows("Sheet1") + if err != nil { + return grmi.NewBusinessError("读取Sheet1页失败, error:" + err.Error()) + } + rowIndex := 0 + projectMap := make(map[string]interface{}) + productMap := make(map[string]string) + productFamilyMap := make(map[string]interface{}) + productFamilyRelateMap := make(map[string][]model.ProductFamilyRelate) + for rowsIterator.Next() { + rowIndex++ + if rowIndex == 1 { + _, err = rowsIterator.Columns() + if err != nil { + return grmi.NewBusinessError("去读excel行数据失败, error:" + err.Error()) + } + continue + } + row, err := rowsIterator.Columns() + if err != nil { + return grmi.NewBusinessError("去读excel行数据失败, error:" + err.Error()) + } + if len(row) != 4 { + return grmi.NewBusinessError("excel数据不合规, 行数:" + strconv.Itoa(rowIndex)) + } + _, exist := projectMap[row[1]] + if !exist { + project, err := daoProject.SelectOne(row[1]) + if err != nil { + return grmi.NewBusinessError("查询车型项目数据失败, error:" + err.Error()) + } + if project == nil { + return grmi.NewBusinessError("车型项目不存在, 车型项目ID:" + row[1]) + } + projectMap[row[1]] = nil + } + desc, exist := productMap[row[2]] + if !exist { + product, err := daoProduct.SelectOne(row[2]) + if err != nil { + return grmi.NewBusinessError("查询产品总成数据失败, error:" + err.Error()) + } + if product == nil { + return grmi.NewBusinessError("产品总成不存在, 总成ID:" + row[2]) + } + productMap[row[2]] = product.Descr + desc = product.Descr + } + _, exist = productFamilyMap[row[0]] + if !exist { + productFamily, err := daoProductFamily.SelectOne(row[0]) + if err != nil { + return grmi.NewBusinessError("查询派生数据失败, error:" + err.Error()) + } + if productFamily == nil { + return grmi.NewBusinessError("派生数据不存在, 派生ID:" + row[0]) + } + productFamilyMap[row[0]] = nil + } + count, err := strconv.Atoi(row[3]) + if err != nil { + return grmi.NewBusinessError("excel数据不合规, 行数:" + strconv.Itoa(rowIndex)) + } + relate := model.ProductFamilyRelate{ + ProductFamilyId: row[0], + ProjectId: row[1], + ProductId: row[2], + ProductDescr: desc, + Count: count, + } + _, exist = productFamilyRelateMap[row[0]] + if !exist { + productFamilyRelateMap[row[0]] = make([]model.ProductFamilyRelate, 0) + } + productFamilyRelateMap[row[0]] = append(productFamilyRelateMap[row[0]], relate) + } + if err = session.Begin(); err != nil { + return err + } + tempProductFamilyRelateLi := make([]model.ProductFamilyRelate, 0, 20) + for productFamilyId, relateLi := range productFamilyRelateMap { + originRelateLi, err := daoProductFamilyRelate.Select([]grmi.Predicate{meta.ProductFamilyRelate_ProductFamilyId.NewPredicate(grmi.Equal, productFamilyId)}, nil) + if err != nil { + _ = session.Rollback() + return grmi.NewBusinessError("查询已存在关联关系失败, error:" + err.Error()) + } + if len(originRelateLi) != 0 { + _ = session.Rollback() + return grmi.NewBusinessError("派生已存在关联关系, 派生ID:" + productFamilyId) + } + for index, relate := range relateLi { + if index != 0 && index % 20 == 0 { + err = daoProductFamilyRelate.Insert(&tempProductFamilyRelateLi) + if err != nil { + _ = session.Rollback() + return grmi.NewBusinessError("写入关联关系失败, error:" + err.Error()) + } + tempProductFamilyRelateLi = make([]model.ProductFamilyRelate, 0, 20) + } + relate.Pos = index + 1 + tempProductFamilyRelateLi = append(tempProductFamilyRelateLi, relate) + } + if len(tempProductFamilyRelateLi) != 0 { + err = daoProductFamilyRelate.Insert(&tempProductFamilyRelateLi) + if err != nil { + _ = session.Rollback() + return grmi.NewBusinessError("写入关联关系失败, error:" + err.Error()) + } + } + } + _ = session.Commit() + return nil +} diff --git a/web/controllers/me/BomHead.rest.go b/web/controllers/me/BomHead.rest.go index dad5e94..e6c1786 100644 --- a/web/controllers/me/BomHead.rest.go +++ b/web/controllers/me/BomHead.rest.go @@ -5,10 +5,12 @@ package me import ( "LAPP_ACURA_MOM_BACKEND/global" model "LAPP_ACURA_MOM_BACKEND/models/me" + "LAPP_ACURA_MOM_BACKEND/utils" "LAPP_ACURA_MOM_BACKEND/web/middleware/jwts" "LAPP_ACURA_MOM_BACKEND/web/supports" "github.com/kataras/iris/v12" "github.com/kataras/iris/v12/core/router" + "strings" ) /****************************************************************************** @@ -402,4 +404,57 @@ func RegisterCopyBom(party router.Party, path string, method func(*global.User, supports.Ok(ctx, supports.OptionSuccess, nil) }) -} \ No newline at end of file +} + +/****************************************************************************** + * + * @Function Name : RegisterBomHeadUploadExcel + *----------------------------------------------------------------------------- + * + * @Description : excel导入数据 + * + * @Function Parameters : 路由分组 + * + * @Function Parameters : HTTP方法 + * + * @Function Parameters : 路径 + * + * @Function Parameters : 实际处理请求的方法 + * + * @Author : zhangxin + * + * @Date : 2021-12-22 + * + ******************************************************************************/ +func RegisterBomHeadUploadExcel(party router.Party, path string, method func(*global.User, string) error) { + + party.Post(path, func(ctx iris.Context) { + user, ok := jwts.ParseToken(ctx) + if !ok { + return + } + var err error = nil + _, info, err := ctx.FormFile("uploadfile") + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, "获取上传文件出错,err: "+err.Error(), nil) + return + } + + guid := utils.MakeOrderSn("ME") + filenameLi := strings.Split(info.Filename, ".") + filename := filenameLi[0] + savePath := "web/public/uploadxlsx/" + filename + guid + ".xlsx" + err = utils.SaveUploadedFile(info, savePath) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, "保存上传文件出错,err: "+err.Error(), nil) + return + } + + err = method(user, savePath) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) + return + } + supports.Ok(ctx, supports.OptionSuccess, nil) + }) +} diff --git a/web/controllers/me/ProductFamily.rest.go b/web/controllers/me/ProductFamily.rest.go index 421f5a1..a8cb7a1 100644 --- a/web/controllers/me/ProductFamily.rest.go +++ b/web/controllers/me/ProductFamily.rest.go @@ -6,10 +6,12 @@ import ( "LAPP_ACURA_MOM_BACKEND/global" "LAPP_ACURA_MOM_BACKEND/grmi" model "LAPP_ACURA_MOM_BACKEND/models/me" + "LAPP_ACURA_MOM_BACKEND/utils" "LAPP_ACURA_MOM_BACKEND/web/middleware/jwts" "LAPP_ACURA_MOM_BACKEND/web/supports" "github.com/kataras/iris/v12" "github.com/kataras/iris/v12/core/router" + "strings" ) /****************************************************************************** @@ -486,3 +488,56 @@ func RegisterGeneratePackTemplateByProductFamily(party router.Party, path string supports.Ok(ctx, supports.OptionSuccess, nil) }) } + +/****************************************************************************** + * + * @Function Name : RegisterProductFamilyUploadExcel + *----------------------------------------------------------------------------- + * + * @Description : excel导入数据 + * + * @Function Parameters : 路由分组 + * + * @Function Parameters : HTTP方法 + * + * @Function Parameters : 路径 + * + * @Function Parameters : 实际处理请求的方法 + * + * @Author : zhangxin + * + * @Date : 2021-12-22 + * + ******************************************************************************/ +func RegisterProductFamilyUploadExcel(party router.Party, path string, method func(*global.User, string) error) { + + party.Post(path, func(ctx iris.Context) { + user, ok := jwts.ParseToken(ctx) + if !ok { + return + } + var err error = nil + _, info, err := ctx.FormFile("uploadfile") + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, "获取上传文件出错,err: "+err.Error(), nil) + return + } + + guid := utils.MakeOrderSn("ME") + filenameLi := strings.Split(info.Filename, ".") + filename := filenameLi[0] + savePath := "web/public/uploadxlsx/" + filename + guid + ".xlsx" + err = utils.SaveUploadedFile(info, savePath) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, "保存上传文件出错,err: "+err.Error(), nil) + return + } + + err = method(user, savePath) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) + return + } + supports.Ok(ctx, supports.OptionSuccess, nil) + }) +} diff --git a/web/controllers/me/ProductFamilyRelate.rest.go b/web/controllers/me/ProductFamilyRelate.rest.go index 6363027..4e97ede 100644 --- a/web/controllers/me/ProductFamilyRelate.rest.go +++ b/web/controllers/me/ProductFamilyRelate.rest.go @@ -6,10 +6,12 @@ import ( "LAPP_ACURA_MOM_BACKEND/global" "LAPP_ACURA_MOM_BACKEND/grmi" model "LAPP_ACURA_MOM_BACKEND/models/me" + "LAPP_ACURA_MOM_BACKEND/utils" "LAPP_ACURA_MOM_BACKEND/web/middleware/jwts" "LAPP_ACURA_MOM_BACKEND/web/supports" "github.com/kataras/iris/v12" "github.com/kataras/iris/v12/core/router" + "strings" ) /****************************************************************************** @@ -403,3 +405,56 @@ func RegisterUpdateProductFamilyRelate(party router.Party, path string, method f RegisterMultiProductFamilyRelate(party, "PUT", path, method) } + +/****************************************************************************** + * + * @Function Name : RegisterProductFamilyUploadExcel + *----------------------------------------------------------------------------- + * + * @Description : excel导入数据 + * + * @Function Parameters : 路由分组 + * + * @Function Parameters : HTTP方法 + * + * @Function Parameters : 路径 + * + * @Function Parameters : 实际处理请求的方法 + * + * @Author : zhangxin + * + * @Date : 2021-12-22 + * + ******************************************************************************/ +func RegisterProductFamilyRelateUploadExcel(party router.Party, path string, method func(*global.User, string) error) { + + party.Post(path, func(ctx iris.Context) { + user, ok := jwts.ParseToken(ctx) + if !ok { + return + } + var err error = nil + _, info, err := ctx.FormFile("uploadfile") + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, "获取上传文件出错,err: "+err.Error(), nil) + return + } + + guid := utils.MakeOrderSn("ME") + filenameLi := strings.Split(info.Filename, ".") + filename := filenameLi[0] + savePath := "web/public/uploadxlsx/" + filename + guid + ".xlsx" + err = utils.SaveUploadedFile(info, savePath) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, "保存上传文件出错,err: "+err.Error(), nil) + return + } + + err = method(user, savePath) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) + return + } + supports.Ok(ctx, supports.OptionSuccess, nil) + }) +} diff --git a/web/controllers/me/me.go b/web/controllers/me/me.go index 9afc4ac..083f868 100644 --- a/web/controllers/me/me.go +++ b/web/controllers/me/me.go @@ -71,6 +71,8 @@ func RegisterRoutes() { // RegisterUpdateProductFamily(productfamily, "/update", serviceOfProductFamily.Update) // ProductFamily 生成包装模板 RegisterGeneratePackTemplateByProductFamily(productfamily, "/generatetemplate", serviceOfProductFamily.GeneratePackTemplate) + // ProductFamily上传excel导入数据 + RegisterProductFamilyUploadExcel(productfamily, "/uploadexcel", serviceOfProductFamily.ImportFromExcel) // Product的路由组 product := party.Party("/product") @@ -141,6 +143,8 @@ func RegisterRoutes() { // RegisterUpdateBomHead(bomhead, "/update", serviceOfBomHead.Update) // BomHead 复制bom RegisterCopyBom(bomhead, "/copy", serviceOfBomHead.Copy) + // BomHead 通过文件导入数据 + RegisterBomHeadUploadExcel(bomhead, "/uploadexcel", serviceOfBomHead.ImportFromExcel) // BomLst的路由组 bomlst := party.Party("/bomlst") @@ -185,6 +189,8 @@ func RegisterRoutes() { // RegisterUpdateOneProductFamilyRelate(productfamilyrelate, "/updateone", serviceOfProductFamilyRelate.UpdateOne) // ProductFamilyRelate修改多条 // RegisterUpdateProductFamilyRelate(productfamilyrelate, "/update", serviceOfProductFamilyRelate.Update) + // ProductFamilyRelate 上传excel导入数据 + RegisterProductFamilyRelateUploadExcel(productfamilyrelate, "/uploadexcel", serviceOfProductFamilyRelate.ImportFromExcel) // ProductWorkLineLst的路由组 productworklinelst := party.Party("/productworklinelst")