Merge branch 'feature_material' of http://gitlab.fjmaimaimai.com/allied-creation…
…/allied-creation-manufacture into feature_material
正在显示
12 个修改的文件
包含
339 行增加
和
49 行删除
| 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 | +} |
| @@ -2,17 +2,16 @@ package command | @@ -2,17 +2,16 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "github.com/beego/beego/v2/core/validation" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | - | ||
| 8 | - "github.com/beego/beego/v2/core/validation" | ||
| 9 | ) | 8 | ) |
| 10 | 9 | ||
| 11 | type CreateProductMaterialCommand struct { | 10 | type CreateProductMaterialCommand struct { |
| 12 | // 企业id | 11 | // 企业id |
| 13 | - CompanyId int `cname:"企业id" json:"companyId" valid:"Required"` | 12 | + CompanyId int `cname:"企业id" json:"companyId"` |
| 14 | // 组织ID | 13 | // 组织ID |
| 15 | - OrgId int `cname:"组织ID" json:"orgId" valid:"Required"` | 14 | + OrgId int `cname:"组织ID" json:"orgId"` |
| 16 | // 物料分组ID | 15 | // 物料分组ID |
| 17 | ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId" valid:"Required"` | 16 | ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId" valid:"Required"` |
| 18 | // 物料编码 | 17 | // 物料编码 |
| @@ -24,9 +23,9 @@ type CreateProductMaterialCommand struct { | @@ -24,9 +23,9 @@ type CreateProductMaterialCommand struct { | ||
| 24 | // 物料类别 | 23 | // 物料类别 |
| 25 | MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"` | 24 | MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"` |
| 26 | // 规格 | 25 | // 规格 |
| 27 | - Specification string `cname:"规格" json:"specification"` | 26 | + Specification string `cname:"规格" json:"specification" valid:"Required"` |
| 28 | // 单位 | 27 | // 单位 |
| 29 | - Unit string `cname:"单位" json:"unit"` | 28 | + Unit string `cname:"单位" json:"unit" valid:"Required"` |
| 30 | // 保质期 单位:天 | 29 | // 保质期 单位:天 |
| 31 | ExpiredDay int `cname:"保质期 单位:天" json:"expiredDay"` | 30 | ExpiredDay int `cname:"保质期 单位:天" json:"expiredDay"` |
| 32 | // 备注 | 31 | // 备注 |
| @@ -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 | +type DtoMaterial struct { | ||
| 4 | + ProductMaterialId int `json:"productMaterialId"` // 物料ID | ||
| 5 | + MaterialNumber string `json:"materialNumber"` //物料编码 | ||
| 6 | + MaterialName string `json:"materialName"` //物料名称 | ||
| 7 | + Specification string `json:"specification"` //规格型号 | ||
| 8 | + MaterialCategory string `json:"materialCategory"` //物料类别 | ||
| 9 | + Unit string `json:"unit"` //单位 | ||
| 10 | + MaterialAttribute string `json:"materialAttribute"` //物料属性 | ||
| 11 | + ProductMaterialGroupId int `json:"productMaterialGroupId"` //物料分组 string/string/string | ||
| 12 | + ExpiredDay int `json:"expiredDay"` //保质期 | ||
| 13 | + Remark string `json:"remark"` //备注 | ||
| 14 | + ProductMaterialGroups []int `json:"productMaterialGroups"` | ||
| 15 | +} |
| 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) { |
| 1 | +package query | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type SearchProductMaterialQuery struct { | ||
| 12 | + PageNumber int64 `json:"pageNumber"` | ||
| 13 | + PageSize int64 `json:"pageSize"` | ||
| 14 | + // 物料分组ID | ||
| 15 | + ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId"` | ||
| 16 | + // 物料分组ID数组 | ||
| 17 | + ProductMaterialGroupIds []int | ||
| 18 | + // 物料名称 | ||
| 19 | + MaterialName string `cname:"物料名称" json:"materialName"` | ||
| 20 | + // 物料类别 | ||
| 21 | + MaterialCategory string `cname:"物料类别" json:"materialCategory"` | ||
| 22 | + CompanyId int | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +func (listProductMaterialQuery *SearchProductMaterialQuery) Valid(validation *validation.Validation) { | ||
| 26 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +func (listProductMaterialQuery *SearchProductMaterialQuery) ValidateQuery() error { | ||
| 30 | + valid := validation.Validation{} | ||
| 31 | + b, err := valid.Valid(listProductMaterialQuery) | ||
| 32 | + if err != nil { | ||
| 33 | + return err | ||
| 34 | + } | ||
| 35 | + if !b { | ||
| 36 | + elem := reflect.TypeOf(listProductMaterialQuery).Elem() | ||
| 37 | + for _, validErr := range valid.Errors { | ||
| 38 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 39 | + if isExist { | ||
| 40 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 41 | + } else { | ||
| 42 | + return fmt.Errorf(validErr.Message) | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + return nil | ||
| 47 | +} |
| @@ -7,9 +7,11 @@ import ( | @@ -7,9 +7,11 @@ 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" |
| 14 | + "time" | ||
| 13 | ) | 15 | ) |
| 14 | 16 | ||
| 15 | // 生产物料服务 | 17 | // 生产物料服务 |
| @@ -49,7 +51,7 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper | @@ -49,7 +51,7 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper | ||
| 49 | } | 51 | } |
| 50 | //var productMaterial *domain.ProductMaterial | 52 | //var productMaterial *domain.ProductMaterial |
| 51 | materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | 53 | materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) |
| 52 | - if _, err = materialService.AddMaterial(operateInfo, newProductMaterial); err != nil { | 54 | + if _, err := materialService.AddMaterial(operateInfo, newProductMaterial); err != nil { |
| 53 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 55 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 54 | } | 56 | } |
| 55 | if err := transactionContext.CommitTransaction(); err != nil { | 57 | if err := transactionContext.CommitTransaction(); err != nil { |
| @@ -58,8 +60,8 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper | @@ -58,8 +60,8 @@ func (productMaterialService *ProductMaterialService) CreateProductMaterial(oper | ||
| 58 | return struct{}{}, nil | 60 | return struct{}{}, nil |
| 59 | } | 61 | } |
| 60 | 62 | ||
| 61 | -// 返回生产物料服务 | ||
| 62 | -func (productMaterialService *ProductMaterialService) GetProductMaterial(getProductMaterialQuery *query.GetProductMaterialQuery) (interface{}, error) { | 63 | +// 返回生产物料服务单个 |
| 64 | +func (productMaterialService *ProductMaterialService) GetProductMaterial(operateInfo *domain.OperateInfo, getProductMaterialQuery *query.GetProductMaterialQuery) (interface{}, error) { | ||
| 63 | if err := getProductMaterialQuery.ValidateQuery(); err != nil { | 65 | if err := getProductMaterialQuery.ValidateQuery(); err != nil { |
| 64 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 66 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| 65 | } | 67 | } |
| @@ -88,15 +90,29 @@ func (productMaterialService *ProductMaterialService) GetProductMaterial(getProd | @@ -88,15 +90,29 @@ func (productMaterialService *ProductMaterialService) GetProductMaterial(getProd | ||
| 88 | if productMaterial == nil { | 90 | if productMaterial == nil { |
| 89 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductMaterialQuery.ProductMaterialId))) | 91 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductMaterialQuery.ProductMaterialId))) |
| 90 | } else { | 92 | } else { |
| 93 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
| 94 | + productMaterialGroupIdNames, _, err := materialService.AllMaterialGroupParent(operateInfo, productMaterial.ProductMaterialGroupId) | ||
| 95 | + if err != nil { | ||
| 96 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 97 | + } | ||
| 98 | + if len(productMaterialGroupIdNames) == 0 { | ||
| 99 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 100 | + } | ||
| 101 | + var productMaterialGroups []int | ||
| 102 | + for _, productMaterialGroupIdName := range productMaterialGroupIdNames { | ||
| 103 | + productMaterialGroups = append(productMaterialGroups, productMaterialGroupIdName.ProductMaterialGroupId) | ||
| 104 | + } | ||
| 105 | + one := dto.DtoProductMaterial(productMaterial) | ||
| 106 | + one.ProductMaterialGroups = productMaterialGroups | ||
| 91 | if err := transactionContext.CommitTransaction(); err != nil { | 107 | if err := transactionContext.CommitTransaction(); err != nil { |
| 92 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 108 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 93 | } | 109 | } |
| 94 | - return productMaterial, nil | 110 | + return one, nil |
| 95 | } | 111 | } |
| 96 | } | 112 | } |
| 97 | 113 | ||
| 98 | -// 返回生产物料服务列表 | ||
| 99 | -func (productMaterialService *ProductMaterialService) ListProductMaterial(listProductMaterialQuery *query.ListProductMaterialQuery) (interface{}, error) { | 114 | +// 返回生产物料服务列表,未用 |
| 115 | +func (productMaterialService *ProductMaterialService) ListProductMaterial(operateInfo *domain.OperateInfo, listProductMaterialQuery *query.ListProductMaterialQuery) (interface{}, error) { | ||
| 100 | if err := listProductMaterialQuery.ValidateQuery(); err != nil { | 116 | if err := listProductMaterialQuery.ValidateQuery(); err != nil { |
| 101 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 117 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| 102 | } | 118 | } |
| @@ -118,21 +134,80 @@ func (productMaterialService *ProductMaterialService) ListProductMaterial(listPr | @@ -118,21 +134,80 @@ func (productMaterialService *ProductMaterialService) ListProductMaterial(listPr | ||
| 118 | } else { | 134 | } else { |
| 119 | productMaterialRepository = value | 135 | productMaterialRepository = value |
| 120 | } | 136 | } |
| 137 | + var results []*dto.DtoMaterial | ||
| 138 | + if listProductMaterialQuery.ProductMaterialGroupId != 0 { | ||
| 139 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
| 140 | + _, ProductMaterialGroupIds, err := materialService.AllMaterialGroupChild(operateInfo, listProductMaterialQuery.ProductMaterialGroupId) | ||
| 141 | + if err != nil { | ||
| 142 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 143 | + } | ||
| 144 | + listProductMaterialQuery.ProductMaterialGroupIds = ProductMaterialGroupIds | ||
| 145 | + } | ||
| 146 | + listProductMaterialQuery.CompanyId = operateInfo.CompanyId | ||
| 121 | if count, productMaterials, err := productMaterialRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialQuery)); err != nil { | 147 | if count, productMaterials, err := productMaterialRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialQuery)); err != nil { |
| 122 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 148 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 123 | } else { | 149 | } else { |
| 150 | + for _, productMaterial := range productMaterials { | ||
| 151 | + results = append(results, dto.DtoProductMaterial(productMaterial)) | ||
| 152 | + } | ||
| 124 | if err := transactionContext.CommitTransaction(); err != nil { | 153 | if err := transactionContext.CommitTransaction(); err != nil { |
| 125 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 154 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 126 | } | 155 | } |
| 127 | return map[string]interface{}{ | 156 | return map[string]interface{}{ |
| 128 | "count": count, | 157 | "count": count, |
| 129 | - "productMaterials": productMaterials, | 158 | + "productMaterials": results, |
| 130 | }, nil | 159 | }, nil |
| 131 | } | 160 | } |
| 132 | } | 161 | } |
| 133 | 162 | ||
| 163 | +// 返回生产物料服务列表 | ||
| 164 | +func (productMaterialService *ProductMaterialService) SearchProductMaterial(operateInfo *domain.OperateInfo, listProductMaterialQuery *query.SearchProductMaterialQuery) (int64, []*dto.DtoMaterial, error) { | ||
| 165 | + if err := listProductMaterialQuery.ValidateQuery(); err != nil { | ||
| 166 | + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 167 | + } | ||
| 168 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 169 | + if err != nil { | ||
| 170 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 171 | + } | ||
| 172 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 173 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 174 | + } | ||
| 175 | + defer func() { | ||
| 176 | + transactionContext.RollbackTransaction() | ||
| 177 | + }() | ||
| 178 | + var productMaterialRepository domain.ProductMaterialRepository | ||
| 179 | + if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{ | ||
| 180 | + "transactionContext": transactionContext, | ||
| 181 | + }); err != nil { | ||
| 182 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 183 | + } else { | ||
| 184 | + productMaterialRepository = value | ||
| 185 | + } | ||
| 186 | + results := make([]*dto.DtoMaterial, 0) | ||
| 187 | + if listProductMaterialQuery.ProductMaterialGroupId != 0 { | ||
| 188 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
| 189 | + _, ProductMaterialGroupIds, err := materialService.AllMaterialGroupChild(operateInfo, listProductMaterialQuery.ProductMaterialGroupId) | ||
| 190 | + if err != nil { | ||
| 191 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 192 | + } | ||
| 193 | + listProductMaterialQuery.ProductMaterialGroupIds = ProductMaterialGroupIds | ||
| 194 | + } | ||
| 195 | + listProductMaterialQuery.CompanyId = operateInfo.CompanyId | ||
| 196 | + count, productMaterials, err := productMaterialRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialQuery)) | ||
| 197 | + if err != nil { | ||
| 198 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 199 | + } | ||
| 200 | + for _, productMaterial := range productMaterials { | ||
| 201 | + results = append(results, dto.DtoProductMaterial(productMaterial)) | ||
| 202 | + } | ||
| 203 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 204 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 205 | + } | ||
| 206 | + return count, results, err | ||
| 207 | +} | ||
| 208 | + | ||
| 134 | // 移除生产物料服务 | 209 | // 移除生产物料服务 |
| 135 | -func (productMaterialService *ProductMaterialService) RemoveProductMaterial(removeProductMaterialCommand *command.RemoveProductMaterialCommand) (interface{}, error) { | 210 | +func (productMaterialService *ProductMaterialService) RemoveProductMaterial(operateInfo *domain.OperateInfo, removeProductMaterialCommand *command.RemoveProductMaterialCommand) (interface{}, error) { |
| 136 | if err := removeProductMaterialCommand.ValidateCommand(); err != nil { | 211 | if err := removeProductMaterialCommand.ValidateCommand(); err != nil { |
| 137 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 212 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| 138 | } | 213 | } |
| @@ -154,7 +229,7 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo | @@ -154,7 +229,7 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo | ||
| 154 | } else { | 229 | } else { |
| 155 | productMaterialRepository = value | 230 | productMaterialRepository = value |
| 156 | } | 231 | } |
| 157 | - productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": removeProductMaterialCommand.ProductMaterialId}) | 232 | + productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"companyId": operateInfo.CompanyId, "productMaterialId": removeProductMaterialCommand.ProductMaterialId}) |
| 158 | if err != nil { | 233 | if err != nil { |
| 159 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 234 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 160 | } | 235 | } |
| @@ -172,8 +247,49 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo | @@ -172,8 +247,49 @@ func (productMaterialService *ProductMaterialService) RemoveProductMaterial(remo | ||
| 172 | } | 247 | } |
| 173 | 248 | ||
| 174 | // 更新生产物料服务 | 249 | // 更新生产物料服务 |
| 175 | -func (productMaterialService *ProductMaterialService) UpdateProductMaterial(updateProductMaterialCommand *command.UpdateProductMaterialCommand) (interface{}, error) { | ||
| 176 | - if err := updateProductMaterialCommand.ValidateCommand(); err != nil { | 250 | +func (productMaterialService *ProductMaterialService) UpdateProductMaterial(operateInfo *domain.OperateInfo, cmd *command.UpdateProductMaterialCommand) (interface{}, error) { |
| 251 | + if err := cmd.ValidateCommand(); err != nil { | ||
| 252 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 253 | + } | ||
| 254 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 255 | + if err != nil { | ||
| 256 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 257 | + } | ||
| 258 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 259 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 260 | + } | ||
| 261 | + defer func() { | ||
| 262 | + transactionContext.RollbackTransaction() | ||
| 263 | + }() | ||
| 264 | + productMaterialRepository, productMaterial, err := factory.FastProductMaterial(transactionContext, cmd.ProductMaterialId) | ||
| 265 | + if err != nil { | ||
| 266 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + productMaterial.ProductMaterialGroupId = cmd.ProductMaterialGroupId | ||
| 270 | + productMaterial.MaterialName = cmd.MaterialName | ||
| 271 | + productMaterial.MaterialAttribute.Attribute = cmd.MaterialAttribute | ||
| 272 | + productMaterial.MaterialCategory.Category = cmd.MaterialCategory | ||
| 273 | + productMaterial.ProductMaterialExt = &domain.MaterialExt{ | ||
| 274 | + Specification: cmd.Specification, | ||
| 275 | + Unit: cmd.Unit, | ||
| 276 | + ExpiredDay: cmd.ExpiredDay, | ||
| 277 | + Remark: cmd.Remark, | ||
| 278 | + } | ||
| 279 | + productMaterial.UpdatedAt = time.Now() | ||
| 280 | + | ||
| 281 | + if _, err := productMaterialRepository.Save(productMaterial); err != nil { | ||
| 282 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 283 | + } | ||
| 284 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 285 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 286 | + } | ||
| 287 | + return struct{}{}, nil | ||
| 288 | +} | ||
| 289 | + | ||
| 290 | +// 批量移除生产物料服务 | ||
| 291 | +func (productMaterialService *ProductMaterialService) BatchRemoveProductMaterial(operateInfo *domain.OperateInfo, batchRemoveProductMaterialCommand *command.BatchRemoveProductMaterialCommand) (interface{}, error) { | ||
| 292 | + if err := batchRemoveProductMaterialCommand.ValidateCommand(); err != nil { | ||
| 177 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 293 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| 178 | } | 294 | } |
| 179 | transactionContext, err := factory.CreateTransactionContext(nil) | 295 | transactionContext, err := factory.CreateTransactionContext(nil) |
| @@ -194,24 +310,24 @@ func (productMaterialService *ProductMaterialService) UpdateProductMaterial(upda | @@ -194,24 +310,24 @@ func (productMaterialService *ProductMaterialService) UpdateProductMaterial(upda | ||
| 194 | } else { | 310 | } else { |
| 195 | productMaterialRepository = value | 311 | productMaterialRepository = value |
| 196 | } | 312 | } |
| 197 | - productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": updateProductMaterialCommand.ProductMaterialId}) | 313 | + for i := range batchRemoveProductMaterialCommand.ProductMaterialIds { |
| 314 | + ProductMaterialId := batchRemoveProductMaterialCommand.ProductMaterialIds[i] | ||
| 315 | + productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"companyId": operateInfo.CompanyId, "productMaterialId": ProductMaterialId}) | ||
| 198 | if err != nil { | 316 | if err != nil { |
| 199 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 317 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 200 | } | 318 | } |
| 201 | if productMaterial == nil { | 319 | if productMaterial == nil { |
| 202 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductMaterialCommand.ProductMaterialId))) | ||
| 203 | - } | ||
| 204 | - if err := productMaterial.Update(tool_funs.SimpleStructToMap(updateProductMaterialCommand)); err != nil { | ||
| 205 | - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 320 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(ProductMaterialId))) |
| 206 | } | 321 | } |
| 207 | - if productMaterial, err := productMaterialRepository.Save(productMaterial); err != nil { | 322 | + if _, err := productMaterialRepository.Remove(productMaterial); err != nil { |
| 208 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 323 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 209 | - } else { | 324 | + } |
| 325 | + } | ||
| 210 | if err := transactionContext.CommitTransaction(); err != nil { | 326 | if err := transactionContext.CommitTransaction(); err != nil { |
| 211 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 327 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 212 | } | 328 | } |
| 213 | - return productMaterial, nil | ||
| 214 | - } | 329 | + return struct{}{}, nil |
| 330 | + | ||
| 215 | } | 331 | } |
| 216 | 332 | ||
| 217 | func NewProductMaterialService(options map[string]interface{}) *ProductMaterialService { | 333 | func NewProductMaterialService(options map[string]interface{}) *ProductMaterialService { |
| @@ -24,7 +24,7 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain. | @@ -24,7 +24,7 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain. | ||
| 24 | err error | 24 | err error |
| 25 | newProductMaterial *domain.ProductMaterial | 25 | newProductMaterial *domain.ProductMaterial |
| 26 | productMaterialRepository, _ = repository.NewProductMaterialRepository(ptr.transactionContext) | 26 | productMaterialRepository, _ = repository.NewProductMaterialRepository(ptr.transactionContext) |
| 27 | - productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext) | 27 | + productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) |
| 28 | ) | 28 | ) |
| 29 | if user, err = NewUserService().User(opt.UserId); err != nil { | 29 | if user, err = NewUserService().User(opt.UserId); err != nil { |
| 30 | return nil, err | 30 | return nil, err |
| @@ -32,7 +32,7 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain. | @@ -32,7 +32,7 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain. | ||
| 32 | if org, err = NewUserService().Organization(opt.OrgId); err != nil { | 32 | if org, err = NewUserService().Organization(opt.OrgId); err != nil { |
| 33 | return nil, err | 33 | return nil, err |
| 34 | } | 34 | } |
| 35 | - _, err = productGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productGroupId": item.ProductMaterialGroupId}) | 35 | + _, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.ProductMaterialGroupId}) |
| 36 | if err != nil { | 36 | if err != nil { |
| 37 | return nil, err | 37 | return nil, err |
| 38 | } | 38 | } |
| @@ -53,8 +53,8 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain. | @@ -53,8 +53,8 @@ func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain. | ||
| 53 | UpdatedAt: time.Now(), | 53 | UpdatedAt: time.Now(), |
| 54 | Ext: domain.NewExt(org.OrgName).WithOperator(user), | 54 | Ext: domain.NewExt(org.OrgName).WithOperator(user), |
| 55 | } | 55 | } |
| 56 | - newProductMaterial, err = productMaterialRepository.Save(newProductMaterial) | ||
| 57 | - return newProductMaterial, err | 56 | + aaa, err := productMaterialRepository.Save(newProductMaterial) |
| 57 | + return aaa, err | ||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | // 物料分组 | 60 | // 物料分组 |
| @@ -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(fmt.Sprintf(`material_category->>'category' like '%%%v%%'`, v)) | ||
| 168 | + } | ||
| 160 | if v, ok := queryOptions["materialNumbers"]; ok && len(v.([]string)) > 0 { | 169 | if v, ok := queryOptions["materialNumbers"]; ok && len(v.([]string)) > 0 { |
| 161 | query.Where("material_number in (?)", pg.In(v)) | 170 | query.Where("material_number in (?)", pg.In(v)) |
| 162 | } | 171 | } |
| @@ -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.SearchProductMaterialQuery{} | ||
| 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 | } |
-
请 注册 或 登录 后发表评论