Browse Source

product删除worklineid 添加通过excel导入数据的功能

pull/94/head
zhangxin 3 years ago
parent
commit
80a9433667
13 changed files with 480 additions and 9 deletions
  1. +1
    -3
      meta/me/Product.meta.go
  2. +0
    -1
      models/me/Product.model.go
  3. +19
    -0
      services/me/BomHead.service.go
  4. +19
    -0
      services/me/ProductFamily.service.go
  5. +19
    -0
      services/me/ProductFamilyRelate.service.go
  6. +7
    -3
      services/me/implments/BomHead.service.impl.go
  7. +0
    -1
      services/me/implments/Product.service.impl.go
  8. +112
    -0
      services/me/implments/ProductFamily.service.impl.go
  9. +131
    -0
      services/me/implments/ProductFamilyRelate.service.impl.go
  10. +56
    -1
      web/controllers/me/BomHead.rest.go
  11. +55
    -0
      web/controllers/me/ProductFamily.rest.go
  12. +55
    -0
      web/controllers/me/ProductFamilyRelate.rest.go
  13. +6
    -0
      web/controllers/me/me.go

+ 1
- 3
meta/me/Product.meta.go View File

@ -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"})

+ 0
- 1
models/me/Product.model.go View File

@ -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"`


+ 19
- 0
services/me/BomHead.service.go View File

@ -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
}
/******************************************************************************


+ 19
- 0
services/me/ProductFamily.service.go View File

@ -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
}
/******************************************************************************


+ 19
- 0
services/me/ProductFamilyRelate.service.go View File

@ -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
}
/******************************************************************************


+ 7
- 3
services/me/implments/BomHead.service.impl.go View File

@ -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 {


+ 0
- 1
services/me/implments/Product.service.impl.go View File

@ -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),


+ 112
- 0
services/me/implments/ProductFamily.service.impl.go View File

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

+ 131
- 0
services/me/implments/ProductFamilyRelate.service.impl.go View File

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

+ 56
- 1
web/controllers/me/BomHead.rest.go View File

@ -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)
})
}
}
/******************************************************************************
*
* @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)
})
}

+ 55
- 0
web/controllers/me/ProductFamily.rest.go View File

@ -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)
})
}

+ 55
- 0
web/controllers/me/ProductFamilyRelate.rest.go View File

@ -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)
})
}

+ 6
- 0
web/controllers/me/me.go View File

@ -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")


Loading…
Cancel
Save