From fef2512d60ba1c56521b598d04fe2c2d004c0a0c Mon Sep 17 00:00:00 2001 From: yehongyang Date: Tue, 16 Nov 2021 09:22:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=9B=B6=E4=BB=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=9B=B6=E4=BB=B6=E6=95=B0=E9=87=8F=20=E9=9B=B6?= =?UTF-8?q?=E4=BB=B6=E9=85=8D=E7=BD=AE=20=E5=A2=9E=E5=8A=A0=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=8F=AF=E4=BB=A5=E8=AE=BE=E7=BD=AE=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=20-p=20=E4=BC=98=E5=8C=96=E6=89=80=E6=9C=89?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=9C=A8goland=20debug=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E8=AE=BF=E9=97=AE=E5=90=8C=E4=B8=80=E4=B8=AA=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/me/implments/Product.dao.impl.go | 4 +++- dao/me/implments/ProductFamily.dao.impl.go | 5 ++++- main.go | 1 + meta/me/ProductFamilyRelate.meta.go | 2 ++ models/me/Product.model.go | 3 ++- models/me/ProductFamily.model.go | 1 + models/me/ProductFamilyRelate.model.go | 1 + services/me/implments/Product.service.impl.go | 16 ++++++++++++++++ .../me/implments/ProductFamily.service.impl.go | 4 +++- .../ProductFamilyRelate.service.impl.go | 1 + utils/file.go | 3 +++ utils/sysconf.go | 1 + 12 files changed, 38 insertions(+), 4 deletions(-) diff --git a/dao/me/implments/Product.dao.impl.go b/dao/me/implments/Product.dao.impl.go index 01ada94..685282c 100644 --- a/dao/me/implments/Product.dao.impl.go +++ b/dao/me/implments/Product.dao.impl.go @@ -100,9 +100,11 @@ func (impl *ProductDAOImplement) SelectOne(productId string) (*model.Product, er impl.session.Table(meta.ProductFamilyRelate.TableName).Where("ProductId=?", data.ProductId).Find(&relate) var projectId []string var familyId []string + familyCount := make(map[string]int) for _, v := range relate { projectId = append(projectId, v.ProjectId) familyId = append(familyId, v.ProductFamilyId) + familyCount[v.ProductFamilyId] = v.Count } //查询车型 var project []model.Project @@ -113,6 +115,7 @@ func (impl *ProductDAOImplement) SelectOne(productId string) (*model.Product, er //配置map familyMap := make(map[string][]model.ProductFamily) for _, v := range family { + v.Count = familyCount[v.ProductFamilyId] familyMap[v.ProjectId] = append(familyMap[v.ProjectId], v) } //将配置导入车型 @@ -333,4 +336,3 @@ func (impl *ProductDAOImplement) UpdateWhere(predicates []grmi.Predicate, entity } return nil } - diff --git a/dao/me/implments/ProductFamily.dao.impl.go b/dao/me/implments/ProductFamily.dao.impl.go index 86bfb3b..13a688e 100644 --- a/dao/me/implments/ProductFamily.dao.impl.go +++ b/dao/me/implments/ProductFamily.dao.impl.go @@ -99,16 +99,19 @@ func (impl *ProductFamilyDAOImplement) SelectOne(productFamilyId string) (*model var relate []model.ProductFamilyRelate err = impl.session.Table(meta.ProductFamilyRelate.TableName).Where("ProductFamilyId = ? and ProjectId=?", data.ProductFamilyId, data.ProjectId).Find(&relate) var productId []string + productCount := make(map[string]int) for _, v := range relate { productId = append(productId, v.ProductId) + productCount[v.ProductId] = v.Count } //查询车型配置零件 var product []model.Product err = impl.session.Table(meta.Product.TableName).In("ProductId", productId).Find(&product) if err == nil { - for k, _ := range product { + for k, v := range product { product[k].ProductFamilyId = data.ProductFamilyId product[k].ProjectId = data.ProjectId + product[k].Count = productCount[v.ProductId] } data.Product = product } diff --git a/main.go b/main.go index 4870219..7a8c910 100644 --- a/main.go +++ b/main.go @@ -81,6 +81,7 @@ func imain() { //初始化日志开始 baseDir := "" flag.StringVar(&baseDir, "dir", "log", "running in a directory") + flag.StringVar(&utils.SysPath, "p", "", "root Path") flag.Parse() defer glog.Flush() diff --git a/meta/me/ProductFamilyRelate.meta.go b/meta/me/ProductFamilyRelate.meta.go index 1e43450..d932050 100644 --- a/meta/me/ProductFamilyRelate.meta.go +++ b/meta/me/ProductFamilyRelate.meta.go @@ -22,6 +22,7 @@ var ProductFamilyRelate_ProjectId = grmi.NewField("ProjectId", "[ME_ProductFamil var ProductFamilyRelate_ProductId = grmi.NewField("ProductId", "[ME_ProductFamilyRelate].ProductId", "productid", grmi.TypeString) var ProductFamilyRelate_ProductDescr = grmi.NewField("ProductDescr", "[ME_ProductFamilyRelate].ProductDescr", "productdescr", grmi.TypeString) var ProductFamilyRelate_Pos = grmi.NewField("Pos", "[ME_ProductFamilyRelate].Pos", "pos", grmi.TypeInt) +var ProductFamilyRelate_Count = grmi.NewField("Count", "[ME_ProductFamilyRelate].Count", "count", grmi.TypeInt) var ProductFamilyRelate_LastModify = grmi.NewField("LastModify", "[ME_ProductFamilyRelate].LastModify", "lastmodify", grmi.TypeDateTime) var ProductFamilyRelate_LastUser = grmi.NewField("LastUser", "[ME_ProductFamilyRelate].LastUser", "lastuser", grmi.TypeString) var ProductFamilyRelate_CreateTime = grmi.NewField("CreateTime", "[ME_ProductFamilyRelate].CreateTime", "createtime", grmi.TypeDateTime) @@ -45,6 +46,7 @@ var ProductFamilyRelate = grmi.NewEntity( ProductFamilyRelate_ProductId.Name: ProductFamilyRelate_ProductId, ProductFamilyRelate_ProductDescr.Name: ProductFamilyRelate_ProductDescr, ProductFamilyRelate_Pos.Name: ProductFamilyRelate_Pos, + ProductFamilyRelate_Count.Name: ProductFamilyRelate_Count, ProductFamilyRelate_LastModify.Name: ProductFamilyRelate_LastModify, ProductFamilyRelate_LastUser.Name: ProductFamilyRelate_LastUser, ProductFamilyRelate_CreateTime.Name: ProductFamilyRelate_CreateTime, diff --git a/models/me/Product.model.go b/models/me/Product.model.go index 534312f..d49b4b9 100644 --- a/models/me/Product.model.go +++ b/models/me/Product.model.go @@ -24,7 +24,7 @@ type Product struct { ProductId string `xorm:"pk nvarchar(40) 'ProductId'" json:"ME_Product-ProductId"` Descr string `xorm:"nvarchar(40) 'Descr' not null" json:"ME_Product-Descr"` ProductFamilyId string `xorm:"-" json:"ME_Product-ProductFamilyId"` - ProjectId string `xorm:"-" json:"ME_Product-ProjectId"` + ProjectId string `xorm:"nvarchar(40) 'ProjectId'" json:"ME_Product-ProjectId"` DefaultWorkLineId string `xorm:"nvarchar(40) 'DefaultWorkLineId'" json:"ME_Product-DefaultWorkLineId"` MultiWorkLineToggle bool `xorm:"bit 'MultiWorkLineToggle' not null" json:"ME_Product-MultiWorkLineToggle"` Descr1 string `xorm:"nvarchar(40) 'Descr1' not null" json:"ME_Product-Descr1"` @@ -62,6 +62,7 @@ type Product struct { CreateTime grmi.DateTime `xorm:"datetime 'CreateTime' not null created" json:"ME_Product-CreateTime"` Project []Project `xorm:"-" json:"-"` ProductFamily []ProductFamily `xorm:"-" json:"ME_Product-ProductFamily"` + Count int `xorm:"-" json:"ME_Product-Count"` } /****************************************************************************** diff --git a/models/me/ProductFamily.model.go b/models/me/ProductFamily.model.go index ba570c0..669c4fb 100644 --- a/models/me/ProductFamily.model.go +++ b/models/me/ProductFamily.model.go @@ -44,6 +44,7 @@ type ProductFamily struct { Product []Product `xorm:"-" json:"ME_ProductFamily-Product"` Relate []ProductFamilyRelate `xorm:"-" json:"-"` Project Project `xorm:"-" json:"-"` + Count int `xorm:"-" json:"ME_ProductFamily-Count"` } /****************************************************************************** diff --git a/models/me/ProductFamilyRelate.model.go b/models/me/ProductFamilyRelate.model.go index 777c8f5..fbbe35f 100644 --- a/models/me/ProductFamilyRelate.model.go +++ b/models/me/ProductFamilyRelate.model.go @@ -26,6 +26,7 @@ type ProductFamilyRelate struct { ProductId string `xorm:"pk nvarchar(40) 'ProductId'" json:"ME_ProductFamilyRelate-ProductId"` ProductDescr string `xorm:"nvarchar(40) 'ProductDescr' not null" json:"ME_ProductFamilyRelate-ProductDescr"` Pos int `xorm:"int 'Pos' not null" json:"ME_ProductFamilyRelate-Pos"` + Count int `xorm:"int 'Count' not null" json:"ME_ProductFamilyRelate-Count"` LastModify grmi.DateTime `xorm:"datetime 'LastModify' not null updated" json:"ME_ProductFamilyRelate-LastModify"` LastUser string `xorm:"nvarchar(20) 'LastUser' not null" json:"ME_ProductFamilyRelate-LastUser"` CreateTime grmi.DateTime `xorm:"datetime 'CreateTime' not null created" json:"ME_ProductFamilyRelate-CreateTime"` diff --git a/services/me/implments/Product.service.impl.go b/services/me/implments/Product.service.impl.go index 71147e6..a357dd4 100644 --- a/services/me/implments/Product.service.impl.go +++ b/services/me/implments/Product.service.impl.go @@ -133,6 +133,9 @@ func (impl *ProductServiceImplement) InsertOne(user *global.User, entity *model. if record != nil { return grmi.NewBusinessError("已经存在相同主键的记录!") } + if !(entity.Count > 0) { + return grmi.NewBusinessError("请填写数量!") + } //查询配置 relateL, err := relateDao.SelectOne(entity.ProductFamilyId, entity.ProjectId, entity.ProductId) if err != nil { @@ -148,6 +151,7 @@ func (impl *ProductServiceImplement) InsertOne(user *global.User, entity *model. ProductDescr: entity.Descr, ProjectId: entity.ProjectId, ProductId: entity.ProductId, + Count: entity.Count, } err = relateDao.InsertOne(&relateData) if err != nil { @@ -293,6 +297,18 @@ func (impl *ProductServiceImplement) UpdateOne(user *global.User, entity *model. return grmi.NewBusinessError("不存在指定记录!") } err = dao.UpdateOne(entity) + //如过count大于0修改对应配置数量 + if entity.Count > 0 { + rateDao := dal.NewProductFamilyRelateDAO(session, user.PlantNr, user.UserId) + //修改数量 + rate := model.ProductFamilyRelate{ + Count: entity.Count, + ProjectId: entity.ProjectId, + ProductFamilyId: entity.ProductFamilyId, + ProductId: entity.ProductId, + } + rateDao.UpdateOne(&rate) + } if err != nil { return err } diff --git a/services/me/implments/ProductFamily.service.impl.go b/services/me/implments/ProductFamily.service.impl.go index 5b71e88..508311c 100644 --- a/services/me/implments/ProductFamily.service.impl.go +++ b/services/me/implments/ProductFamily.service.impl.go @@ -153,12 +153,14 @@ func (impl *ProductFamilyServiceImplement) Association(user *global.User, entity } //添加配置 var relateData []model.ProductFamilyRelate - for _, v := range entity.Product { + for k, v := range entity.Product { relateData = append(relateData, model.ProductFamilyRelate{ ProductId: v.ProductId, ProductFamilyId: record.ProductFamilyId, ProjectId: record.ProjectId, ProductDescr: v.Descr, + Count: v.Count, + Pos: k, }) } if len(relateData) == 0 { diff --git a/services/me/implments/ProductFamilyRelate.service.impl.go b/services/me/implments/ProductFamilyRelate.service.impl.go index 1acab3b..d357b50 100644 --- a/services/me/implments/ProductFamilyRelate.service.impl.go +++ b/services/me/implments/ProductFamilyRelate.service.impl.go @@ -30,6 +30,7 @@ var DefaultConditionOfProductFamilyRelate = grmi.NewCondition( meta.ProductFamilyRelate_LastModify.UrlParameterName: grmi.NewConditionItem(meta.ProductFamilyRelate_LastModify, grmi.Approximate, false), meta.ProductFamilyRelate_LastUser.UrlParameterName: grmi.NewConditionItem(meta.ProductFamilyRelate_LastUser, grmi.Equal, false), meta.ProductFamilyRelate_CreateTime.UrlParameterName: grmi.NewConditionItem(meta.ProductFamilyRelate_CreateTime, grmi.Approximate, false), + meta.ProductFamilyRelate_Count.UrlParameterName: grmi.NewConditionItem(meta.ProductFamilyRelate_Count, grmi.Equal, false), }, nil, ) diff --git a/utils/file.go b/utils/file.go index a4f95ef..141de76 100644 --- a/utils/file.go +++ b/utils/file.go @@ -117,6 +117,9 @@ func IsExists(path string) bool { * ******************************************************************************/ func GetCurrentPath(dir string) (string, error) { + if SysPath != "" { + return SysPath + dir, nil + } file, err := exec.LookPath(os.Args[0]) if err != nil { return "", err diff --git a/utils/sysconf.go b/utils/sysconf.go index 4063288..cc6ce23 100644 --- a/utils/sysconf.go +++ b/utils/sysconf.go @@ -28,3 +28,4 @@ const ( // 中国时区 var SysTimeLocation, _ = time.LoadLocation("Asia/Chongqing") +var SysPath string