正在显示
9 个修改的文件
包含
109 行增加
和
94 行删除
| 1 | 1 | ||
| 2 | -- 表product_material_group 增加唯一索引 idx_unq_product_material_group_company_id_org_id_material_group_number | 2 | -- 表product_material_group 增加唯一索引 idx_unq_product_material_group_company_id_org_id_material_group_number |
| 3 | 3 | ||
| 4 | -create UNIQUE INDEX idx_unq_product_material_group_company_id_org_id_material_group_number on manufacture.product_material_group using btree(company_id,org_id,material_group_number); | ||
| 4 | +create UNIQUE INDEX idx_unq_product_material_group_company_id_org_id_material_group_number on manufacture.product_material_group using btree(company_id,org_id,material_group_number); | ||
| 5 | + | ||
| 6 | +-- 表product_material 增加唯一索引 idx_unq_product_material_company_id_material_number | ||
| 7 | +create UNIQUE INDEX idx_unq_product_material_company_id_material_number on manufacture.product_material using btree(company_id,material_number); |
| @@ -14,19 +14,15 @@ type CreateProductCommand struct { | @@ -14,19 +14,15 @@ type CreateProductCommand struct { | ||
| 14 | // 组织ID | 14 | // 组织ID |
| 15 | OrgId int `cname:"组织ID" json:"orgId" valid:"Required"` | 15 | OrgId int `cname:"组织ID" json:"orgId" valid:"Required"` |
| 16 | // 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001 | 16 | // 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001 |
| 17 | - ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode"` | 17 | + ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode" valid:"Required"` |
| 18 | // 产品名称 | 18 | // 产品名称 |
| 19 | - ProductName string `cname:"产品名称" json:"productName" valid:"Required"` | 19 | + // ProductName string `cname:"产品名称" json:"productName" valid:"Required"` |
| 20 | // 产品类别 | 20 | // 产品类别 |
| 21 | - ProductCategory string `cname:"产品类别" json:"productCategory" valid:"Required"` | ||
| 22 | - // 数量(保留两位小数) | ||
| 23 | - //Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"` | 21 | + // ProductCategory string `cname:"产品类别" json:"productCategory" valid:"Required"` |
| 24 | // 单位 | 22 | // 单位 |
| 25 | - Unit string `cname:"单位" json:"unit" valid:"Required"` | 23 | + // Unit string `cname:"单位" json:"unit" valid:"Required"` |
| 26 | // 单份重量(原材料) | 24 | // 单份重量(原材料) |
| 27 | UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"` | 25 | UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"` |
| 28 | - // 重量 | ||
| 29 | - //Weight float64 `cname:"重量" json:"weight" valid:"Required"` | ||
| 30 | } | 26 | } |
| 31 | 27 | ||
| 32 | func (createProductCommand *CreateProductCommand) Valid(validation *validation.Validation) { | 28 | func (createProductCommand *CreateProductCommand) Valid(validation *validation.Validation) { |
| @@ -12,19 +12,15 @@ type UpdateProductCommand struct { | @@ -12,19 +12,15 @@ type UpdateProductCommand struct { | ||
| 12 | // 产品ID | 12 | // 产品ID |
| 13 | ProductId int `cname:"产品ID" json:"productId" valid:"Required"` | 13 | ProductId int `cname:"产品ID" json:"productId" valid:"Required"` |
| 14 | // 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001 | 14 | // 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001 |
| 15 | - ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode"` | 15 | + //ProductCode string `cname:"产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001" json:"productCode"` |
| 16 | // 产品名称 | 16 | // 产品名称 |
| 17 | - ProductName string `cname:"产品名称" json:"productName" valid:"Required"` | 17 | + ProductName string `cname:"产品名称" json:"productName" ` |
| 18 | // 产品类别 | 18 | // 产品类别 |
| 19 | - ProductCategory string `cname:"产品类别" json:"productCategory" valid:"Required"` | ||
| 20 | - // 数量(保留两位小数) | ||
| 21 | - //Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"` | 19 | + ProductCategory string `cname:"产品类别" json:"productCategory"` |
| 22 | // 单位 | 20 | // 单位 |
| 23 | - Unit string `cname:"单位" json:"unit" valid:"Required"` | 21 | + Unit string `cname:"单位" json:"unit"` |
| 24 | // 单份重量(原材料) | 22 | // 单份重量(原材料) |
| 25 | UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"` | 23 | UnitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"` |
| 26 | - // 重量 | ||
| 27 | - //Weight float64 `cname:"重量" json:"weight" valid:"Required"` | ||
| 28 | } | 24 | } |
| 29 | 25 | ||
| 30 | func (updateProductCommand *UpdateProductCommand) Valid(validation *validation.Validation) { | 26 | func (updateProductCommand *UpdateProductCommand) Valid(validation *validation.Validation) { |
| @@ -14,7 +14,6 @@ import ( | @@ -14,7 +14,6 @@ import ( | ||
| 14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" | 14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" |
| 15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | 15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
| 16 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | 16 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" |
| 17 | - "time" | ||
| 18 | ) | 17 | ) |
| 19 | 18 | ||
| 20 | // 产品服务 | 19 | // 产品服务 |
| @@ -22,7 +21,7 @@ type ProductService struct { | @@ -22,7 +21,7 @@ type ProductService struct { | ||
| 22 | } | 21 | } |
| 23 | 22 | ||
| 24 | // 创建产品服务 | 23 | // 创建产品服务 |
| 25 | -func (productService *ProductService) CreateProduct(createProductCommand *command.CreateProductCommand) (interface{}, error) { | 24 | +func (productService *ProductService) CreateProduct(opt *domain.OperateInfo, createProductCommand *command.CreateProductCommand) (interface{}, error) { |
| 26 | if err := createProductCommand.ValidateCommand(); err != nil { | 25 | if err := createProductCommand.ValidateCommand(); err != nil { |
| 27 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 26 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| 28 | } | 27 | } |
| @@ -37,50 +36,23 @@ func (productService *ProductService) CreateProduct(createProductCommand *comman | @@ -37,50 +36,23 @@ func (productService *ProductService) CreateProduct(createProductCommand *comman | ||
| 37 | transactionContext.RollbackTransaction() | 36 | transactionContext.RollbackTransaction() |
| 38 | }() | 37 | }() |
| 39 | 38 | ||
| 40 | - if len(createProductCommand.ProductCode) == 0 { | ||
| 41 | - generator := redis.NewProductCodeCache(createProductCommand.CompanyId) | ||
| 42 | - code, err := redis.GenCode(generator) | ||
| 43 | - if err != nil { | ||
| 44 | - log.Logger.Error(err.Error()) | ||
| 45 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "服务器异常") | ||
| 46 | - } | ||
| 47 | - createProductCommand.ProductCode = code | 39 | + batchAddProductService, _ := domainService.NewPGBatchAddProductService(transactionContext.(*pgTransaction.TransactionContext)) |
| 40 | + item := &domain.ImportProductItem{ | ||
| 41 | + ProductCode: createProductCommand.ProductCode, | ||
| 42 | + UnitWeight: utils.AssertString(createProductCommand.UnitWeight), | ||
| 48 | } | 43 | } |
| 49 | - var userService = domainService.NewUserService() | ||
| 50 | - var org *domain.Org | ||
| 51 | - org, err = userService.Organization(createProductCommand.OrgId) | ||
| 52 | - if err != nil { | ||
| 53 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 44 | + if _, err = batchAddProductService.BatchAddProduct(opt, []*domain.ImportProductItem{ |
| 45 | + item, | ||
| 46 | + }, false); err != nil { | ||
| 47 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 54 | } | 48 | } |
| 55 | - | ||
| 56 | - newProduct := &domain.Product{ | ||
| 57 | - CompanyId: createProductCommand.CompanyId, | ||
| 58 | - OrgId: createProductCommand.OrgId, | ||
| 59 | - ProductCode: createProductCommand.ProductCode, | ||
| 60 | - ProductName: createProductCommand.ProductName, | ||
| 61 | - ProductCategory: createProductCommand.ProductCategory, | ||
| 62 | - ProductSpec: &domain.UnitQuantity{ | ||
| 63 | - Unit: createProductCommand.Unit, | ||
| 64 | - UnitWeight: createProductCommand.UnitWeight, | ||
| 65 | - }, | ||
| 66 | - CreatedAt: time.Now(), | ||
| 67 | - UpdatedAt: time.Now(), | ||
| 68 | - Ext: domain.NewExt(org.OrgName), | ||
| 69 | - } | ||
| 70 | - productRepository, _, _ := factory.FastPgProduct(transactionContext, 0) | ||
| 71 | - | ||
| 72 | - if item, err := productRepository.FindOne(map[string]interface{}{"companyId": createProductCommand.CompanyId, "productCode": createProductCommand.ProductCode}); err == nil && item != nil { | ||
| 73 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "产品编号重复,请重新提交") | 49 | + if len(item.FailReason) > 0 { |
| 50 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, item.FailReason) | ||
| 74 | } | 51 | } |
| 75 | - | ||
| 76 | - if product, err := productRepository.Save(newProduct); err != nil { | ||
| 77 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 78 | - } else { | ||
| 79 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
| 80 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 81 | - } | ||
| 82 | - return product, nil | 52 | + if err := transactionContext.CommitTransaction(); err != nil { |
| 53 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 83 | } | 54 | } |
| 55 | + return struct{}{}, nil | ||
| 84 | } | 56 | } |
| 85 | 57 | ||
| 86 | // 返回产品服务 | 58 | // 返回产品服务 |
| @@ -242,7 +214,7 @@ func (productService *ProductService) BatchRemoveProduct(cmd *command.BatchRemov | @@ -242,7 +214,7 @@ func (productService *ProductService) BatchRemoveProduct(cmd *command.BatchRemov | ||
| 242 | } | 214 | } |
| 243 | 215 | ||
| 244 | // 更新产品服务 | 216 | // 更新产品服务 |
| 245 | -func (productService *ProductService) UpdateProduct(updateProductCommand *command.UpdateProductCommand) (interface{}, error) { | 217 | +func (productService *ProductService) UpdateProduct(opt *domain.OperateInfo, updateProductCommand *command.UpdateProductCommand) (interface{}, error) { |
| 246 | if err := updateProductCommand.ValidateCommand(); err != nil { | 218 | if err := updateProductCommand.ValidateCommand(); err != nil { |
| 247 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 219 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| 248 | } | 220 | } |
| @@ -260,19 +232,11 @@ func (productService *ProductService) UpdateProduct(updateProductCommand *comman | @@ -260,19 +232,11 @@ func (productService *ProductService) UpdateProduct(updateProductCommand *comman | ||
| 260 | if err != nil { | 232 | if err != nil { |
| 261 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 233 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 262 | } | 234 | } |
| 263 | - if len(updateProductCommand.ProductCode) == 0 { | ||
| 264 | - generator := redis.NewProductCodeCache(product.CompanyId) | ||
| 265 | - code, err := redis.GenCode(generator) | ||
| 266 | - if err != nil { | ||
| 267 | - log.Logger.Error(err.Error()) | ||
| 268 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "服务器异常") | ||
| 269 | - } | ||
| 270 | - updateProductCommand.ProductCode = code | ||
| 271 | - } | ||
| 272 | - if updateProductCommand.ProductCode != product.ProductCode { | ||
| 273 | - if item, err := productRepository.FindOne(map[string]interface{}{"companyId": product.CompanyId, "productCode": updateProductCommand.ProductCode}); err == nil && item != nil { | ||
| 274 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "产品编号重复,请重新提交") | ||
| 275 | - } | 235 | + |
| 236 | + var material *domain.ProductMaterial | ||
| 237 | + productMaterialRepository, _, _ := factory.FastProductMaterial(transactionContext, 0) | ||
| 238 | + if material, err = productMaterialRepository.FindOne(map[string]interface{}{"companyId": product.CompanyId, "materialNumber": product.ProductCode}); err != nil || material == nil { | ||
| 239 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "物料不存在") | ||
| 276 | } | 240 | } |
| 277 | 241 | ||
| 278 | var userService = domainService.NewUserService() | 242 | var userService = domainService.NewUserService() |
| @@ -281,8 +245,13 @@ func (productService *ProductService) UpdateProduct(updateProductCommand *comman | @@ -281,8 +245,13 @@ func (productService *ProductService) UpdateProduct(updateProductCommand *comman | ||
| 281 | if err != nil { | 245 | if err != nil { |
| 282 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 246 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 283 | } | 247 | } |
| 248 | + | ||
| 249 | + updateProductCommand.ProductName = material.MaterialName | ||
| 250 | + updateProductCommand.Unit = material.ProductMaterialExt.Unit | ||
| 251 | + updateProductCommand.ProductCategory = material.MaterialCategory.Category | ||
| 284 | data := tool_funs.SimpleStructToMap(updateProductCommand) | 252 | data := tool_funs.SimpleStructToMap(updateProductCommand) |
| 285 | data["orgName"] = org.OrgName | 253 | data["orgName"] = org.OrgName |
| 254 | + | ||
| 286 | if err := product.Update(data); err != nil { | 255 | if err := product.Update(data); err != nil { |
| 287 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 256 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
| 288 | } | 257 | } |
| @@ -2,6 +2,7 @@ package domain | @@ -2,6 +2,7 @@ package domain | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
| 5 | "strconv" | 6 | "strconv" |
| 6 | "time" | 7 | "time" |
| 7 | ) | 8 | ) |
| @@ -99,15 +100,18 @@ type ImportProductItem struct { | @@ -99,15 +100,18 @@ type ImportProductItem struct { | ||
| 99 | } | 100 | } |
| 100 | 101 | ||
| 101 | func (item *ImportProductItem) Valid() error { | 102 | func (item *ImportProductItem) Valid() error { |
| 102 | - if len(item.ProductName) == 0 { | ||
| 103 | - return fmt.Errorf("品名不能为空") | ||
| 104 | - } | ||
| 105 | - if len(item.Unit) == 0 { | ||
| 106 | - return fmt.Errorf("规格不能为空") | ||
| 107 | - } | ||
| 108 | - if len(item.ProductCategory) == 0 { | ||
| 109 | - return fmt.Errorf("类别不能为空") | 103 | + if len(item.ProductCode) == 0 { |
| 104 | + return fmt.Errorf("产品编号不能为空") | ||
| 110 | } | 105 | } |
| 106 | + //if len(item.ProductName) == 0 { | ||
| 107 | + // return fmt.Errorf("品名不能为空") | ||
| 108 | + //} | ||
| 109 | + //if len(item.Unit) == 0 { | ||
| 110 | + // return fmt.Errorf("规格不能为空") | ||
| 111 | + //} | ||
| 112 | + //if len(item.ProductCategory) == 0 { | ||
| 113 | + // return fmt.Errorf("类别不能为空") | ||
| 114 | + //} | ||
| 111 | if len(item.UnitWeight) == 0 { | 115 | if len(item.UnitWeight) == 0 { |
| 112 | item.UnitWeight = "0" | 116 | item.UnitWeight = "0" |
| 113 | } | 117 | } |
| @@ -116,3 +120,13 @@ func (item *ImportProductItem) Valid() error { | @@ -116,3 +120,13 @@ func (item *ImportProductItem) Valid() error { | ||
| 116 | } | 120 | } |
| 117 | return nil | 121 | return nil |
| 118 | } | 122 | } |
| 123 | + | ||
| 124 | +type Products []*Product | ||
| 125 | + | ||
| 126 | +func (products Products) ProductCodes() []string { | ||
| 127 | + var result = utils.NewSet() | ||
| 128 | + for _, v := range products { | ||
| 129 | + result.Add(v.ProductCode) | ||
| 130 | + } | ||
| 131 | + return result.KeysStr() | ||
| 132 | +} |
| @@ -59,3 +59,11 @@ func (productMaterials ProductMaterials) ToMapById() map[int]*ProductMaterial { | @@ -59,3 +59,11 @@ func (productMaterials ProductMaterials) ToMapById() map[int]*ProductMaterial { | ||
| 59 | } | 59 | } |
| 60 | return mapProductMaterial | 60 | return mapProductMaterial |
| 61 | } | 61 | } |
| 62 | + | ||
| 63 | +func (productMaterials ProductMaterials) ToMapByNumber() map[string]*ProductMaterial { | ||
| 64 | + var mapProductMaterial = make(map[string]*ProductMaterial, 0) | ||
| 65 | + for _, v := range productMaterials { | ||
| 66 | + mapProductMaterial[v.MaterialNumber] = v | ||
| 67 | + } | ||
| 68 | + return mapProductMaterial | ||
| 69 | +} |
| @@ -6,8 +6,8 @@ import ( | @@ -6,8 +6,8 @@ import ( | ||
| 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
| 7 | "github.com/linmadan/egglib-go/utils/tool_funs" | 7 | "github.com/linmadan/egglib-go/utils/tool_funs" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
| 9 | - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" | ||
| 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" |
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
| 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" |
| 12 | "strconv" | 12 | "strconv" |
| 13 | "time" | 13 | "time" |
| @@ -36,10 +36,22 @@ func (ptr *PGBatchAddProductService) BatchAddProduct(opt *domain.OperateInfo, li | @@ -36,10 +36,22 @@ func (ptr *PGBatchAddProductService) BatchAddProduct(opt *domain.OperateInfo, li | ||
| 36 | if err != nil { | 36 | if err != nil { |
| 37 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 37 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 38 | } | 38 | } |
| 39 | - | ||
| 40 | - var generator = redis.NewProductCodeCache(opt.CompanyId) | 39 | + var materials domain.ProductMaterials |
| 40 | + if materials, err = ptr.GetProductMaterialByImportItems(opt.CompanyId, list); err != nil { | ||
| 41 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 42 | + } | ||
| 43 | + mapMaterials := materials.ToMapByNumber() | ||
| 41 | for i := range list { | 44 | for i := range list { |
| 42 | item := list[i] | 45 | item := list[i] |
| 46 | + if v, ok := mapMaterials[item.ProductCode]; !ok { | ||
| 47 | + item.FailReason = "导入的产品编号不存在" | ||
| 48 | + failRows = append(failRows, item) | ||
| 49 | + continue | ||
| 50 | + } else { | ||
| 51 | + item.Unit = v.ProductMaterialExt.Unit | ||
| 52 | + item.ProductName = v.MaterialName | ||
| 53 | + item.ProductCategory = v.MaterialCategory.Category | ||
| 54 | + } | ||
| 43 | if err := item.Valid(); err != nil { | 55 | if err := item.Valid(); err != nil { |
| 44 | item.FailReason = err.Error() | 56 | item.FailReason = err.Error() |
| 45 | failRows = append(failRows, item) | 57 | failRows = append(failRows, item) |
| @@ -69,14 +81,6 @@ func (ptr *PGBatchAddProductService) BatchAddProduct(opt *domain.OperateInfo, li | @@ -69,14 +81,6 @@ func (ptr *PGBatchAddProductService) BatchAddProduct(opt *domain.OperateInfo, li | ||
| 69 | continue | 81 | continue |
| 70 | } | 82 | } |
| 71 | } | 83 | } |
| 72 | - if len(newItem.ProductCode) == 0 { | ||
| 73 | - code, err := redis.GenCode(generator) | ||
| 74 | - if err != nil { | ||
| 75 | - log.Logger.Error(err.Error()) | ||
| 76 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "服务器异常") | ||
| 77 | - } | ||
| 78 | - newItem.ProductCode = code | ||
| 79 | - } | ||
| 80 | 84 | ||
| 81 | if _, ok := mapProduct[newItem.ProductCode]; !ok { | 85 | if _, ok := mapProduct[newItem.ProductCode]; !ok { |
| 82 | mapProduct[newItem.ProductCode] = newItem | 86 | mapProduct[newItem.ProductCode] = newItem |
| @@ -105,6 +109,28 @@ func (ptr *PGBatchAddProductService) updateProduct(opt *domain.OperateInfo, item | @@ -105,6 +109,28 @@ func (ptr *PGBatchAddProductService) updateProduct(opt *domain.OperateInfo, item | ||
| 105 | return nil | 109 | return nil |
| 106 | } | 110 | } |
| 107 | 111 | ||
| 112 | +func (ptr *PGBatchAddProductService) GetProductMaterialByProductCodes(companyId int, productCodes []string) ([]*domain.ProductMaterial, error) { | ||
| 113 | + productMaterialRepository, _ := repository.NewProductMaterialRepository(ptr.transactionContext) | ||
| 114 | + _, productMaterials, err := productMaterialRepository.Find(map[string]interface{}{"companyId": companyId, "materialNumbers": productCodes}) | ||
| 115 | + return productMaterials, err | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | +func (ptr *PGBatchAddProductService) GetProductMaterialByImportItems(companyId int, list []*domain.ImportProductItem) ([]*domain.ProductMaterial, error) { | ||
| 119 | + productCodes := ptr.GetProductCodesByImportItems(list) | ||
| 120 | + if len(productCodes) == 0 { | ||
| 121 | + return []*domain.ProductMaterial{}, nil | ||
| 122 | + } | ||
| 123 | + return ptr.GetProductMaterialByProductCodes(companyId, productCodes) | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +func (ptr *PGBatchAddProductService) GetProductCodesByImportItems(list []*domain.ImportProductItem) []string { | ||
| 127 | + var result = utils.NewSet() | ||
| 128 | + for _, v := range list { | ||
| 129 | + result.Add(v.ProductCode) | ||
| 130 | + } | ||
| 131 | + return result.KeysStr() | ||
| 132 | +} | ||
| 133 | + | ||
| 108 | func NewPGBatchAddProductService(transactionContext *pgTransaction.TransactionContext) (*PGBatchAddProductService, error) { | 134 | func NewPGBatchAddProductService(transactionContext *pgTransaction.TransactionContext) (*PGBatchAddProductService, error) { |
| 109 | if transactionContext == nil { | 135 | if transactionContext == nil { |
| 110 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 136 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
| @@ -157,6 +157,9 @@ func (repository *ProductMaterialRepository) Find(queryOptions map[string]interf | @@ -157,6 +157,9 @@ func (repository *ProductMaterialRepository) Find(queryOptions map[string]interf | ||
| 157 | if v, ok := queryOptions["productMaterialIds"]; ok && len(v.([]int)) > 0 { | 157 | if v, ok := queryOptions["productMaterialIds"]; ok && len(v.([]int)) > 0 { |
| 158 | query.Where("product_material_id in (?)", pg.In(v)) | 158 | query.Where("product_material_id in (?)", pg.In(v)) |
| 159 | } | 159 | } |
| 160 | + if v, ok := queryOptions["materialNumbers"]; ok && len(v.([]string)) > 0 { | ||
| 161 | + query.Where("material_number in (?)", pg.In(v)) | ||
| 162 | + } | ||
| 160 | query.SetOffsetAndLimit(domain.MaxQueryRow) | 163 | query.SetOffsetAndLimit(domain.MaxQueryRow) |
| 161 | query.SetOrderDirect("product_material_id", "DESC") | 164 | query.SetOrderDirect("product_material_id", "DESC") |
| 162 | if count, err := query.SelectAndCount(); err != nil { | 165 | if count, err := query.SelectAndCount(); err != nil { |
| @@ -19,7 +19,7 @@ func (controller *ProductController) CreateProduct() { | @@ -19,7 +19,7 @@ func (controller *ProductController) CreateProduct() { | ||
| 19 | op := ParseOperateInfo(controller.BaseController) | 19 | op := ParseOperateInfo(controller.BaseController) |
| 20 | createProductCommand.CompanyId = op.CompanyId | 20 | createProductCommand.CompanyId = op.CompanyId |
| 21 | createProductCommand.OrgId = op.OrgId | 21 | createProductCommand.OrgId = op.OrgId |
| 22 | - data, err := productService.CreateProduct(createProductCommand) | 22 | + data, err := productService.CreateProduct(ParseOperateInfo(controller.BaseController), createProductCommand) |
| 23 | controller.Response(data, err) | 23 | controller.Response(data, err) |
| 24 | } | 24 | } |
| 25 | 25 | ||
| @@ -29,7 +29,7 @@ func (controller *ProductController) UpdateProduct() { | @@ -29,7 +29,7 @@ func (controller *ProductController) UpdateProduct() { | ||
| 29 | Must(controller.Unmarshal(updateProductCommand)) | 29 | Must(controller.Unmarshal(updateProductCommand)) |
| 30 | productId, _ := controller.GetInt(":productId") | 30 | productId, _ := controller.GetInt(":productId") |
| 31 | updateProductCommand.ProductId = productId | 31 | updateProductCommand.ProductId = productId |
| 32 | - data, err := productService.UpdateProduct(updateProductCommand) | 32 | + data, err := productService.UpdateProduct(ParseOperateInfo(controller.BaseController), updateProductCommand) |
| 33 | controller.Response(data, err) | 33 | controller.Response(data, err) |
| 34 | } | 34 | } |
| 35 | 35 |
-
请 注册 或 登录 后发表评论