正在显示
10 个修改的文件
包含
336 行增加
和
47 行删除
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type BatchRemoveProductMaterialCommand struct { | ||
12 | + // 物料ID们 | ||
13 | + ProductMaterialIds []int `cname:"物料ID" json:"productMaterialIds" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (batchRemoveProductMaterialCommand *BatchRemoveProductMaterialCommand) Valid(validation *validation.Validation) { | ||
17 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (batchRemoveProductMaterialCommand *BatchRemoveProductMaterialCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(batchRemoveProductMaterialCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(batchRemoveProductMaterialCommand).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
@@ -9,8 +9,30 @@ import ( | @@ -9,8 +9,30 @@ import ( | ||
9 | ) | 9 | ) |
10 | 10 | ||
11 | type UpdateProductMaterialCommand struct { | 11 | type UpdateProductMaterialCommand struct { |
12 | + // 企业id | ||
13 | + CompanyId int `cname:"企业id" json:"companyId"` | ||
14 | + // 组织ID | ||
15 | + OrgId int `cname:"组织ID" json:"orgId"` | ||
12 | // 物料ID | 16 | // 物料ID |
13 | ProductMaterialId int `cname:"物料ID" json:"productMaterialId" valid:"Required"` | 17 | ProductMaterialId int `cname:"物料ID" json:"productMaterialId" valid:"Required"` |
18 | + // 物料分组ID | ||
19 | + ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId" valid:"Required"` | ||
20 | + //// 物料编码 | ||
21 | + //MaterialNumber string `cname:"物料编码" json:"materialNumber" valid:"Required"` | ||
22 | + // 物料名称 | ||
23 | + MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"` | ||
24 | + // 物料属性 | ||
25 | + MaterialAttribute string `cname:"物料属性" json:"materialAttribute" valid:"Required"` | ||
26 | + // 物料类别 | ||
27 | + MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"` | ||
28 | + // 规格 | ||
29 | + Specification string `cname:"规格" json:"specification" valid:"Required"` | ||
30 | + // 单位 | ||
31 | + Unit string `cname:"单位" json:"unit" valid:"Required"` | ||
32 | + // 保质期 单位:天 | ||
33 | + ExpiredDay int `cname:"保质期 单位:天" json:"expiredDay"` | ||
34 | + // 备注 | ||
35 | + Remark string `cname:"备注" json:"remark"` | ||
14 | } | 36 | } |
15 | 37 | ||
16 | func (updateProductMaterialCommand *UpdateProductMaterialCommand) Valid(validation *validation.Validation) { | 38 | func (updateProductMaterialCommand *UpdateProductMaterialCommand) Valid(validation *validation.Validation) { |
1 | +package dto | ||
2 | + | ||
3 | +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
4 | + | ||
5 | +type DtoMaterial struct { | ||
6 | + ProductMaterialId int `json:"productMaterialId"` // 物料ID | ||
7 | + MaterialNumber string `json:"materialNumber"` //物料编码 | ||
8 | + MaterialName string `json:"materialName"` //物料名称 | ||
9 | + Specification string `json:"specification"` //规格型号 | ||
10 | + MaterialCategory string `json:"materialCategory"` //物料类别 | ||
11 | + Unit string `json:"unit"` //单位 | ||
12 | + MaterialAttribute string `json:"materialAttribute"` //物料属性 | ||
13 | + ProductMaterialGroupId int `json:"productMaterialGroupId"` //物料分组 string/string/string | ||
14 | + ExpiredDay int `json:"expiredDay"` //保质期 | ||
15 | + Remark string `json:"remark"` //备注 | ||
16 | + ProductMaterialGroupIdName []*domain.ProductMaterialGroup | ||
17 | +} |
1 | +package dto | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
5 | +) | ||
6 | + | ||
7 | +func DtoProductMaterial(productMaterialModel *domain.ProductMaterial) *DtoMaterial { | ||
8 | + return &DtoMaterial{ | ||
9 | + ProductMaterialId: productMaterialModel.ProductMaterialId, | ||
10 | + ProductMaterialGroupId: productMaterialModel.ProductMaterialGroupId, | ||
11 | + MaterialNumber: productMaterialModel.MaterialNumber, | ||
12 | + MaterialName: productMaterialModel.MaterialName, | ||
13 | + MaterialAttribute: productMaterialModel.MaterialAttribute.Attribute, | ||
14 | + MaterialCategory: productMaterialModel.MaterialCategory.Category, | ||
15 | + Specification: productMaterialModel.ProductMaterialExt.Specification, | ||
16 | + Remark: productMaterialModel.ProductMaterialExt.Remark, | ||
17 | + Unit: productMaterialModel.ProductMaterialExt.Unit, | ||
18 | + ExpiredDay: productMaterialModel.ProductMaterialExt.ExpiredDay, | ||
19 | + } | ||
20 | +} |
@@ -9,16 +9,17 @@ import ( | @@ -9,16 +9,17 @@ import ( | ||
9 | ) | 9 | ) |
10 | 10 | ||
11 | type ListProductMaterialQuery struct { | 11 | type ListProductMaterialQuery struct { |
12 | - // 查询偏离量 | ||
13 | - Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` | ||
14 | - // 查询限制 | ||
15 | - Limit int `cname:"查询限制" json:"limit" valid:"Required"` | 12 | + PageNumber int64 `json:"pageNumber"` |
13 | + PageSize int64 `json:"pageSize"` | ||
16 | // 物料分组ID | 14 | // 物料分组ID |
17 | - ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId" valid:"Required"` | 15 | + ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId"` |
16 | + // 物料分组ID数组 | ||
17 | + ProductMaterialGroupIds []int | ||
18 | // 物料名称 | 18 | // 物料名称 |
19 | - MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"` | 19 | + MaterialName string `cname:"物料名称" json:"materialName"` |
20 | // 物料类别 | 20 | // 物料类别 |
21 | - MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"` | 21 | + MaterialCategory string `cname:"物料类别" json:"materialCategory"` |
22 | + CompanyId int | ||
22 | } | 23 | } |
23 | 24 | ||
24 | func (listProductMaterialQuery *ListProductMaterialQuery) Valid(validation *validation.Validation) { | 25 | func (listProductMaterialQuery *ListProductMaterialQuery) Valid(validation *validation.Validation) { |
@@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
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/application/factory" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" |
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/command" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/command" |
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/dto" | ||
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/query" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/query" |
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" | 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" |
@@ -49,7 +50,7 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper | @@ -49,7 +50,7 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper | ||
49 | } | 50 | } |
50 | //var productMaterial *domain.ProductMaterial | 51 | //var productMaterial *domain.ProductMaterial |
51 | materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | 52 | materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) |
52 | - if _, err = materialService.AddMaterial(operateInfo, newProductMaterial); err != nil { | 53 | + if _, err := materialService.AddMaterial(operateInfo, newProductMaterial); err != nil { |
53 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 54 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
54 | } | 55 | } |
55 | if err := transactionContext.CommitTransaction(); err != nil { | 56 | if err := transactionContext.CommitTransaction(); err != nil { |
@@ -58,8 +59,8 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper | @@ -58,8 +59,8 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper | ||
58 | return struct{}{}, nil | 59 | return struct{}{}, nil |
59 | } | 60 | } |
60 | 61 | ||
61 | -// 返回生产物料服务 | ||
62 | -func (productMaterialService *ProductMaterialService) GetProductMaterial(getProductMaterialQuery *query.GetProductMaterialQuery) (interface{}, error) { | 62 | +// 返回生产物料服务单个 |
63 | +func (productMaterialService *ProductMaterialService) GetProductMaterial(operateInfo *domain.OperateInfo, getProductMaterialQuery *query.GetProductMaterialQuery) (interface{}, error) { | ||
63 | if err := getProductMaterialQuery.ValidateQuery(); err != nil { | 64 | if err := getProductMaterialQuery.ValidateQuery(); err != nil { |
64 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 65 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
65 | } | 66 | } |
@@ -88,15 +89,25 @@ func (productMaterialService *ProductMaterialService) GetProductMaterial(getProd | @@ -88,15 +89,25 @@ func (productMaterialService *ProductMaterialService) GetProductMaterial(getProd | ||
88 | if productMaterial == nil { | 89 | if productMaterial == nil { |
89 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductMaterialQuery.ProductMaterialId))) | 90 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductMaterialQuery.ProductMaterialId))) |
90 | } else { | 91 | } else { |
92 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
93 | + ProductMaterialGroupIdName, _, err := materialService.AllMaterialGroupParent(operateInfo, productMaterial.ProductMaterialGroupId) | ||
94 | + if err != nil { | ||
95 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
96 | + } | ||
97 | + if len(ProductMaterialGroupIdName) == 0 { | ||
98 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
99 | + } | ||
100 | + one := dto.DtoProductMaterial(productMaterial) | ||
101 | + one.ProductMaterialGroupIdName = ProductMaterialGroupIdName | ||
91 | if err := transactionContext.CommitTransaction(); err != nil { | 102 | if err := transactionContext.CommitTransaction(); err != nil { |
92 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 103 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
93 | } | 104 | } |
94 | - return productMaterial, nil | 105 | + return one, nil |
95 | } | 106 | } |
96 | } | 107 | } |
97 | 108 | ||
98 | -// 返回生产物料服务列表 | ||
99 | -func (productMaterialService *ProductMaterialService) ListProductMaterial(listProductMaterialQuery *query.ListProductMaterialQuery) (interface{}, error) { | 109 | +// 返回生产物料服务列表,未用 |
110 | +func (productMaterialService *ProductMaterialService) ListProductMaterial(operateInfo *domain.OperateInfo, listProductMaterialQuery *query.ListProductMaterialQuery) (interface{}, error) { | ||
100 | if err := listProductMaterialQuery.ValidateQuery(); err != nil { | 111 | if err := listProductMaterialQuery.ValidateQuery(); err != nil { |
101 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 112 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
102 | } | 113 | } |
@@ -118,21 +129,80 @@ func (productMaterialService *ProductMaterialService) ListProductMaterial(listPr | @@ -118,21 +129,80 @@ func (productMaterialService *ProductMaterialService) ListProductMaterial(listPr | ||
118 | } else { | 129 | } else { |
119 | productMaterialRepository = value | 130 | productMaterialRepository = value |
120 | } | 131 | } |
132 | + var results []*dto.DtoMaterial | ||
133 | + if listProductMaterialQuery.ProductMaterialGroupId != 0 { | ||
134 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
135 | + _, ProductMaterialGroupIds, err := materialService.AllMaterialGroupChild(operateInfo, listProductMaterialQuery.ProductMaterialGroupId) | ||
136 | + if err != nil { | ||
137 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
138 | + } | ||
139 | + listProductMaterialQuery.ProductMaterialGroupIds = ProductMaterialGroupIds | ||
140 | + } | ||
141 | + listProductMaterialQuery.CompanyId = operateInfo.CompanyId | ||
121 | if count, productMaterials, err := productMaterialRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialQuery)); err != nil { | 142 | if count, productMaterials, err := productMaterialRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialQuery)); err != nil { |
122 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 143 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
123 | } else { | 144 | } else { |
145 | + for _, productMaterial := range productMaterials { | ||
146 | + results = append(results, dto.DtoProductMaterial(productMaterial)) | ||
147 | + } | ||
124 | if err := transactionContext.CommitTransaction(); err != nil { | 148 | if err := transactionContext.CommitTransaction(); err != nil { |
125 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 149 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
126 | } | 150 | } |
127 | return map[string]interface{}{ | 151 | return map[string]interface{}{ |
128 | "count": count, | 152 | "count": count, |
129 | - "productMaterials": productMaterials, | 153 | + "productMaterials": results, |
130 | }, nil | 154 | }, nil |
131 | } | 155 | } |
132 | } | 156 | } |
133 | 157 | ||
158 | +// 返回生产物料服务列表 | ||
159 | +func (productMaterialService *ProductMaterialService) SearchProductMaterial(operateInfo *domain.OperateInfo, listProductMaterialQuery *query.ListProductMaterialQuery) (int64, []*dto.DtoMaterial, error) { | ||
160 | + if err := listProductMaterialQuery.ValidateQuery(); err != nil { | ||
161 | + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
162 | + } | ||
163 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
164 | + if err != nil { | ||
165 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
166 | + } | ||
167 | + if err := transactionContext.StartTransaction(); err != nil { | ||
168 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
169 | + } | ||
170 | + defer func() { | ||
171 | + transactionContext.RollbackTransaction() | ||
172 | + }() | ||
173 | + var productMaterialRepository domain.ProductMaterialRepository | ||
174 | + if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{ | ||
175 | + "transactionContext": transactionContext, | ||
176 | + }); err != nil { | ||
177 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
178 | + } else { | ||
179 | + productMaterialRepository = value | ||
180 | + } | ||
181 | + var results []*dto.DtoMaterial | ||
182 | + if listProductMaterialQuery.ProductMaterialGroupId != 0 { | ||
183 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
184 | + _, ProductMaterialGroupIds, err := materialService.AllMaterialGroupChild(operateInfo, listProductMaterialQuery.ProductMaterialGroupId) | ||
185 | + if err != nil { | ||
186 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
187 | + } | ||
188 | + listProductMaterialQuery.ProductMaterialGroupIds = ProductMaterialGroupIds | ||
189 | + } | ||
190 | + listProductMaterialQuery.CompanyId = operateInfo.CompanyId | ||
191 | + count, productMaterials, err := productMaterialRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialQuery)) | ||
192 | + if err != nil { | ||
193 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
194 | + } | ||
195 | + for _, productMaterial := range productMaterials { | ||
196 | + results = append(results, dto.DtoProductMaterial(productMaterial)) | ||
197 | + } | ||
198 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
199 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
200 | + } | ||
201 | + return count, results, err | ||
202 | +} | ||
203 | + | ||
134 | // 移除生产物料服务 | 204 | // 移除生产物料服务 |
135 | -func (productMaterialService *ProductMaterialService) RemoveProductMaterial(removeProductMaterialCommand *command.RemoveProductMaterialCommand) (interface{}, error) { | 205 | +func (productMaterialService *ProductMaterialService) RemoveProductMaterial(operateInfo *domain.OperateInfo, removeProductMaterialCommand *command.RemoveProductMaterialCommand) (interface{}, error) { |
136 | if err := removeProductMaterialCommand.ValidateCommand(); err != nil { | 206 | if err := removeProductMaterialCommand.ValidateCommand(); err != nil { |
137 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 207 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
138 | } | 208 | } |
@@ -154,7 +224,7 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo | @@ -154,7 +224,7 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo | ||
154 | } else { | 224 | } else { |
155 | productMaterialRepository = value | 225 | productMaterialRepository = value |
156 | } | 226 | } |
157 | - productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": removeProductMaterialCommand.ProductMaterialId}) | 227 | + productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"companyId": operateInfo.CompanyId, "productMaterialId": removeProductMaterialCommand.ProductMaterialId}) |
158 | if err != nil { | 228 | if err != nil { |
159 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 229 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
160 | } | 230 | } |
@@ -172,8 +242,8 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo | @@ -172,8 +242,8 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo | ||
172 | } | 242 | } |
173 | 243 | ||
174 | // 更新生产物料服务 | 244 | // 更新生产物料服务 |
175 | -func (productMaterialService *ProductMaterialService) UpdateProductMaterial(updateProductMaterialCommand *command.UpdateProductMaterialCommand) (interface{}, error) { | ||
176 | - if err := updateProductMaterialCommand.ValidateCommand(); err != nil { | 245 | +func (productMaterialService *ProductMaterialService) UpdateProductMaterial(operateInfo *domain.OperateInfo, cmd *command.UpdateProductMaterialCommand) (interface{}, error) { |
246 | + if err := cmd.ValidateCommand(); err != nil { | ||
177 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 247 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
178 | } | 248 | } |
179 | transactionContext, err := factory.CreateTransactionContext(nil) | 249 | transactionContext, err := factory.CreateTransactionContext(nil) |
@@ -194,24 +264,80 @@ func (productMaterialService *ProductMaterialService) UpdateProductMaterial(upda | @@ -194,24 +264,80 @@ func (productMaterialService *ProductMaterialService) UpdateProductMaterial(upda | ||
194 | } else { | 264 | } else { |
195 | productMaterialRepository = value | 265 | productMaterialRepository = value |
196 | } | 266 | } |
197 | - productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": updateProductMaterialCommand.ProductMaterialId}) | 267 | + productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": cmd.ProductMaterialId}) |
198 | if err != nil { | 268 | if err != nil { |
199 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 269 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
200 | } | 270 | } |
201 | if productMaterial == nil { | 271 | if productMaterial == nil { |
202 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductMaterialCommand.ProductMaterialId))) | 272 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(cmd.ProductMaterialId))) |
273 | + } | ||
274 | + newProductMaterial := &domain.ProductMaterial{ //赋值 | ||
275 | + ProductMaterialId: cmd.ProductMaterialId, | ||
276 | + ProductMaterialGroupId: cmd.ProductMaterialGroupId, | ||
277 | + MaterialName: cmd.MaterialName, | ||
278 | + MaterialNumber: productMaterial.MaterialNumber, | ||
279 | + MaterialAttribute: &domain.MaterialAttribute{Attribute: cmd.MaterialAttribute}, | ||
280 | + MaterialCategory: &domain.MaterialCategory{Category: cmd.MaterialCategory}, | ||
281 | + ProductMaterialExt: &domain.MaterialExt{ | ||
282 | + Specification: cmd.Specification, | ||
283 | + Unit: cmd.Unit, | ||
284 | + ExpiredDay: cmd.ExpiredDay, | ||
285 | + Remark: cmd.Remark, | ||
286 | + }, | ||
287 | + CreatedAt: productMaterial.CreatedAt, | ||
203 | } | 288 | } |
204 | - if err := productMaterial.Update(tool_funs.SimpleStructToMap(updateProductMaterialCommand)); err != nil { | ||
205 | - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 289 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) |
290 | + data, err := materialService.UpdateMaterial(operateInfo, newProductMaterial) | ||
291 | + if err != nil { | ||
292 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
293 | + } | ||
294 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
295 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
206 | } | 296 | } |
207 | - if productMaterial, err := productMaterialRepository.Save(productMaterial); err != nil { | 297 | + return data, nil |
298 | +} | ||
299 | + | ||
300 | +// 批量移除生产物料服务 | ||
301 | +func (productMaterialService *ProductMaterialService) BatchRemoveProductMaterial(operateInfo *domain.OperateInfo, batchRemoveProductMaterialCommand *command.BatchRemoveProductMaterialCommand) (interface{}, error) { | ||
302 | + if err := batchRemoveProductMaterialCommand.ValidateCommand(); err != nil { | ||
303 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
304 | + } | ||
305 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
306 | + if err != nil { | ||
307 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
308 | + } | ||
309 | + if err := transactionContext.StartTransaction(); err != nil { | ||
310 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
311 | + } | ||
312 | + defer func() { | ||
313 | + transactionContext.RollbackTransaction() | ||
314 | + }() | ||
315 | + var productMaterialRepository domain.ProductMaterialRepository | ||
316 | + if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{ | ||
317 | + "transactionContext": transactionContext, | ||
318 | + }); err != nil { | ||
208 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 319 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
209 | } else { | 320 | } else { |
210 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
211 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 321 | + productMaterialRepository = value |
322 | + } | ||
323 | + for i := range batchRemoveProductMaterialCommand.ProductMaterialIds { | ||
324 | + ProductMaterialId := batchRemoveProductMaterialCommand.ProductMaterialIds[i] | ||
325 | + productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"companyId": operateInfo.CompanyId, "productMaterialId": ProductMaterialId}) | ||
326 | + if err != nil { | ||
327 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
328 | + } | ||
329 | + if productMaterial == nil { | ||
330 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(ProductMaterialId))) | ||
331 | + } | ||
332 | + if _, err := productMaterialRepository.Remove(productMaterial); err != nil { | ||
333 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
212 | } | 334 | } |
213 | - return productMaterial, nil | ||
214 | } | 335 | } |
336 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
337 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
338 | + } | ||
339 | + return struct{}{}, nil | ||
340 | + | ||
215 | } | 341 | } |
216 | 342 | ||
217 | func NewProductMaterialService(options map[string]interface{}) *ProductMaterialService { | 343 | func NewProductMaterialService(options map[string]interface{}) *ProductMaterialService { |
@@ -18,12 +18,12 @@ type PGMaterialService struct { | @@ -18,12 +18,12 @@ type PGMaterialService struct { | ||
18 | 18 | ||
19 | func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain.ProductMaterial) (*domain.ProductMaterial, error) { | 19 | func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain.ProductMaterial) (*domain.ProductMaterial, error) { |
20 | var ( | 20 | var ( |
21 | - user *domain.User | ||
22 | - org *domain.Org | ||
23 | - err error | ||
24 | - newProductMaterial *domain.ProductMaterial | ||
25 | - productMaterialRepository, _ = repository.NewProductMaterialRepository(ptr.transactionContext) | ||
26 | - productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext) | 21 | + user *domain.User |
22 | + org *domain.Org | ||
23 | + err error | ||
24 | + newProductMaterial *domain.ProductMaterial | ||
25 | + productMaterialRepository, _ = repository.NewProductMaterialRepository(ptr.transactionContext) | ||
26 | + productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) | ||
27 | ) | 27 | ) |
28 | if user, err = NewUserService().User(opt.UserId); err != nil { | 28 | if user, err = NewUserService().User(opt.UserId); err != nil { |
29 | return nil, err | 29 | return nil, err |
@@ -31,7 +31,7 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain. | @@ -31,7 +31,7 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain. | ||
31 | if org, err = NewUserService().Organization(opt.OrgId); err != nil { | 31 | if org, err = NewUserService().Organization(opt.OrgId); err != nil { |
32 | return nil, err | 32 | return nil, err |
33 | } | 33 | } |
34 | - _, err = productGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productGroupId": item.ProductMaterialGroupId}) | 34 | + _, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.ProductMaterialGroupId}) |
35 | if err != nil { | 35 | if err != nil { |
36 | return nil, err | 36 | return nil, err |
37 | } | 37 | } |
@@ -52,8 +52,41 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain. | @@ -52,8 +52,41 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain. | ||
52 | UpdatedAt: time.Now(), | 52 | UpdatedAt: time.Now(), |
53 | Ext: domain.NewExt(org.OrgName).WithOperator(user), | 53 | Ext: domain.NewExt(org.OrgName).WithOperator(user), |
54 | } | 54 | } |
55 | - newProductMaterial, err = productMaterialRepository.Save(newProductMaterial) | ||
56 | - return newProductMaterial, err | 55 | + aaa, err := productMaterialRepository.Save(newProductMaterial) |
56 | + return aaa, err | ||
57 | +} | ||
58 | + | ||
59 | +func (ptr *PGMaterialService) UpdateMaterial(opt *domain.OperateInfo, item *domain.ProductMaterial) (*domain.ProductMaterial, error) { | ||
60 | + var ( | ||
61 | + user *domain.User | ||
62 | + org *domain.Org | ||
63 | + err error | ||
64 | + newProductMaterial *domain.ProductMaterial | ||
65 | + productMaterialRepository, _ = repository.NewProductMaterialRepository(ptr.transactionContext) | ||
66 | + //productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) | ||
67 | + ) | ||
68 | + if user, err = NewUserService().User(opt.UserId); err != nil { | ||
69 | + return nil, err | ||
70 | + } | ||
71 | + if org, err = NewUserService().Organization(opt.OrgId); err != nil { | ||
72 | + return nil, err | ||
73 | + } | ||
74 | + newProductMaterial = &domain.ProductMaterial{ | ||
75 | + CompanyId: opt.CompanyId, | ||
76 | + OrgId: opt.OrgId, | ||
77 | + ProductMaterialId: item.ProductMaterialId, | ||
78 | + ProductMaterialGroupId: item.ProductMaterialGroupId, | ||
79 | + MaterialName: item.MaterialName, | ||
80 | + MaterialNumber: item.MaterialNumber, | ||
81 | + MaterialAttribute: item.MaterialAttribute, | ||
82 | + MaterialCategory: item.MaterialCategory, | ||
83 | + ProductMaterialExt: item.ProductMaterialExt, | ||
84 | + CreatedAt: item.CreatedAt, | ||
85 | + UpdatedAt: time.Now(), | ||
86 | + Ext: domain.NewExt(org.OrgName).WithOperator(user), | ||
87 | + } | ||
88 | + aaa, err := productMaterialRepository.Save(newProductMaterial) | ||
89 | + return aaa, err | ||
57 | } | 90 | } |
58 | 91 | ||
59 | // 物料分组 | 92 | // 物料分组 |
@@ -157,6 +157,15 @@ func (repository *ProductMaterialRepository) Find(queryOptions map[string]interf | @@ -157,6 +157,15 @@ 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["productMaterialGroupIds"]; ok && len(v.([]int)) > 0 { | ||
161 | + query.Where("product_material_group_id in (?)", pg.In(v)) | ||
162 | + } | ||
163 | + if v, ok := queryOptions["materialName"]; ok && v != "" { | ||
164 | + query.Where("material_name like ?", fmt.Sprintf("%%%v%%", v)) | ||
165 | + } | ||
166 | + if v, ok := queryOptions["materialCategory"]; ok && v != "" { | ||
167 | + query.Where("material_category like ?", fmt.Sprintf("%%%v%%", v)) | ||
168 | + } | ||
160 | query.SetOffsetAndLimit(domain.MaxQueryRow) | 169 | query.SetOffsetAndLimit(domain.MaxQueryRow) |
161 | query.SetOrderDirect("product_material_id", "DESC") | 170 | query.SetOrderDirect("product_material_id", "DESC") |
162 | if count, err := query.SelectAndCount(); err != nil { | 171 | if count, err := query.SelectAndCount(); err != nil { |
@@ -28,7 +28,10 @@ func (controller *ProductMaterialController) UpdateProductMaterial() { | @@ -28,7 +28,10 @@ func (controller *ProductMaterialController) UpdateProductMaterial() { | ||
28 | controller.Unmarshal(updateProductMaterialCommand) | 28 | controller.Unmarshal(updateProductMaterialCommand) |
29 | productMaterialId, _ := controller.GetInt(":productMaterialId") | 29 | productMaterialId, _ := controller.GetInt(":productMaterialId") |
30 | updateProductMaterialCommand.ProductMaterialId = productMaterialId | 30 | updateProductMaterialCommand.ProductMaterialId = productMaterialId |
31 | - data, err := productMaterialService.UpdateProductMaterial(updateProductMaterialCommand) | 31 | + operateInfo := ParseOperateInfo(controller.BaseController) |
32 | + updateProductMaterialCommand.CompanyId = operateInfo.CompanyId | ||
33 | + updateProductMaterialCommand.OrgId = operateInfo.OrgId | ||
34 | + data, err := productMaterialService.UpdateProductMaterial(operateInfo, updateProductMaterialCommand) | ||
32 | controller.Response(data, err) | 35 | controller.Response(data, err) |
33 | } | 36 | } |
34 | 37 | ||
@@ -37,7 +40,8 @@ func (controller *ProductMaterialController) GetProductMaterial() { | @@ -37,7 +40,8 @@ func (controller *ProductMaterialController) GetProductMaterial() { | ||
37 | getProductMaterialQuery := &query.GetProductMaterialQuery{} | 40 | getProductMaterialQuery := &query.GetProductMaterialQuery{} |
38 | productMaterialId, _ := controller.GetInt(":productMaterialId") | 41 | productMaterialId, _ := controller.GetInt(":productMaterialId") |
39 | getProductMaterialQuery.ProductMaterialId = productMaterialId | 42 | getProductMaterialQuery.ProductMaterialId = productMaterialId |
40 | - data, err := productMaterialService.GetProductMaterial(getProductMaterialQuery) | 43 | + operateInfo := ParseOperateInfo(controller.BaseController) |
44 | + data, err := productMaterialService.GetProductMaterial(operateInfo, getProductMaterialQuery) | ||
41 | controller.Response(data, err) | 45 | controller.Response(data, err) |
42 | } | 46 | } |
43 | 47 | ||
@@ -47,17 +51,34 @@ func (controller *ProductMaterialController) RemoveProductMaterial() { | @@ -47,17 +51,34 @@ func (controller *ProductMaterialController) RemoveProductMaterial() { | ||
47 | controller.Unmarshal(removeProductMaterialCommand) | 51 | controller.Unmarshal(removeProductMaterialCommand) |
48 | productMaterialId, _ := controller.GetInt(":productMaterialId") | 52 | productMaterialId, _ := controller.GetInt(":productMaterialId") |
49 | removeProductMaterialCommand.ProductMaterialId = productMaterialId | 53 | removeProductMaterialCommand.ProductMaterialId = productMaterialId |
50 | - data, err := productMaterialService.RemoveProductMaterial(removeProductMaterialCommand) | 54 | + operateInfo := ParseOperateInfo(controller.BaseController) |
55 | + data, err := productMaterialService.RemoveProductMaterial(operateInfo, removeProductMaterialCommand) | ||
51 | controller.Response(data, err) | 56 | controller.Response(data, err) |
52 | } | 57 | } |
53 | 58 | ||
59 | +//没用到 | ||
54 | func (controller *ProductMaterialController) ListProductMaterial() { | 60 | func (controller *ProductMaterialController) ListProductMaterial() { |
55 | productMaterialService := service.NewProductMaterialService(nil) | 61 | productMaterialService := service.NewProductMaterialService(nil) |
56 | listProductMaterialQuery := &query.ListProductMaterialQuery{} | 62 | listProductMaterialQuery := &query.ListProductMaterialQuery{} |
57 | - offset, _ := controller.GetInt("offset") | ||
58 | - listProductMaterialQuery.Offset = offset | ||
59 | - limit, _ := controller.GetInt("limit") | ||
60 | - listProductMaterialQuery.Limit = limit | ||
61 | - data, err := productMaterialService.ListProductMaterial(listProductMaterialQuery) | 63 | + operateInfo := ParseOperateInfo(controller.BaseController) |
64 | + data, err := productMaterialService.ListProductMaterial(operateInfo, listProductMaterialQuery) | ||
65 | + controller.Response(data, err) | ||
66 | +} | ||
67 | + | ||
68 | +func (controller *ProductMaterialController) SearchProductMaterial() { | ||
69 | + productMaterialService := service.NewProductMaterialService(nil) | ||
70 | + listProductMaterialQuery := &query.ListProductMaterialQuery{} | ||
71 | + controller.Unmarshal(listProductMaterialQuery) | ||
72 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
73 | + total, data, err := productMaterialService.SearchProductMaterial(operateInfo, listProductMaterialQuery) | ||
74 | + ResponseGrid(controller.BaseController, total, data, err) | ||
75 | +} | ||
76 | + | ||
77 | +func (controller *ProductMaterialController) BatchRemoveProductMaterial() { | ||
78 | + productMaterialService := service.NewProductMaterialService(nil) | ||
79 | + batchremoveProductMaterialCommand := &command.BatchRemoveProductMaterialCommand{} | ||
80 | + controller.Unmarshal(batchremoveProductMaterialCommand) | ||
81 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
82 | + data, err := productMaterialService.BatchRemoveProductMaterial(operateInfo, batchremoveProductMaterialCommand) | ||
62 | controller.Response(data, err) | 83 | controller.Response(data, err) |
63 | } | 84 | } |
@@ -6,9 +6,11 @@ import ( | @@ -6,9 +6,11 @@ import ( | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | func init() { | 8 | func init() { |
9 | - web.Router("/product-materials/", &controllers.ProductMaterialController{}, "Post:CreateProductMaterial") | ||
10 | - web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Put:UpdateProductMaterial") | ||
11 | - web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Get:GetProductMaterial") | ||
12 | - web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Delete:RemoveProductMaterial") | 9 | + web.Router("/product-materials/", &controllers.ProductMaterialController{}, "Post:CreateProductMaterial") //新增单个物料 |
10 | + web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Put:UpdateProductMaterial") //更新单个物料 | ||
11 | + web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Get:GetProductMaterial") //获取单个物料 | ||
12 | + web.Router("/product-materials/:productMaterialId", &controllers.ProductMaterialController{}, "Delete:RemoveProductMaterial") //删除单个物料 | ||
13 | web.Router("/product-materials/", &controllers.ProductMaterialController{}, "Get:ListProductMaterial") | 13 | web.Router("/product-materials/", &controllers.ProductMaterialController{}, "Get:ListProductMaterial") |
14 | + web.Router("/product-materials/search", &controllers.ProductMaterialController{}, "Post:SearchProductMaterial") //搜索返回列表 | ||
15 | + web.Router("/product-materials/batch-remove", &controllers.ProductMaterialController{}, "Post:BatchRemoveProductMaterial") //批量删除物料 | ||
14 | } | 16 | } |
-
请 注册 或 登录 后发表评论