Merge branch 'feature_material' into test
正在显示
84 个修改的文件
包含
4170 行增加
和
140 行删除
deploy/db/db_device_data_bak_script.sql
0 → 100644
| 1 | +select count(*) from manufacture.device_running_record where device_running_record_id <=2000000 | ||
| 2 | +select count(*) from manufacture.device_collections where created_at <'2022-6-01 16:00:00' | ||
| 3 | + | ||
| 4 | +--1.备份设备运行数据-按数量 | ||
| 5 | +-- 备份数据 2000000 | ||
| 6 | +select * into table manufacture.device_running_record_0_2000 | ||
| 7 | +from manufacture.device_running_record | ||
| 8 | +where device_running_record_id <=2000000 | ||
| 9 | +-- 删除数据 | ||
| 10 | +delete from manufacture.device_running_record where device_running_record_id <=2000000; | ||
| 11 | +-- 重建索引 | ||
| 12 | +reindex table manufacture.device_running_record; | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +--2.备份设备采集数据-按时间 | ||
| 17 | +-- 备份数据 2000000 | ||
| 18 | +select * into table manufacture.device_collections_history | ||
| 19 | +from manufacture.device_collections | ||
| 20 | +where created_at <'2022-6-01 16:00:00' | ||
| 21 | +-- 删除数据 | ||
| 22 | +delete from manufacture.device_collections where created_at <'2022-6-01 16:00:00'; | ||
| 23 | +-- 重建索引 | ||
| 24 | +reindex table manufacture.device_collections; | ||
| 25 | + | ||
| 26 | + | ||
| 27 | +--3.查看备份情况 | ||
| 28 | +select count(*) from manufacture.device_running_record_0_2000 | ||
| 29 | +select count(*) from manufacture.device_collections_history | ||
| 30 | +select count(*) from manufacture.device_collections where created_at <'2022-6-01 16:00:00' |
deploy/db/v1.0.2 db_basic_script.sql
0 → 100644
| 1 | +delete FROM "dictionarys" where dictionary_id in (3812266576427090944); | ||
| 2 | + | ||
| 3 | +INSERT INTO "public"."dictionarys"("dictionary_id", "dict_code", "dict_name", "describe", "dict_items") VALUES (3972873532463383552, 'ACM-001', '天联共创-生产制造-物料属性', '', '[{"sort": 1, "isShow": 1, "itemCode": "1", "itemLabel": "", "itemValue": "外购"}, {"sort": 2, "isShow": 1, "itemCode": "2", "itemLabel": "", "itemValue": "自制"}, {"sort": 3, "isShow": 1, "itemCode": "3", "itemLabel": "", "itemValue": "委外"}]'); | ||
| 4 | +INSERT INTO "public"."dictionarys"("dictionary_id", "dict_code", "dict_name", "describe", "dict_items") VALUES (3972875981165167616, 'ACM-002', '天联共创-生产制造-物料管理-物料类别', '', '[{"sort": 1, "isShow": 1, "itemCode": "1", "itemLabel": "", "itemValue": "原材料"}, {"sort": 2, "isShow": 1, "itemCode": "2", "itemLabel": "", "itemValue": "半成品"}, {"sort": 3, "isShow": 1, "itemCode": "3", "itemLabel": "", "itemValue": "成品"}]'); | ||
| 5 | +INSERT INTO "public"."dictionarys"("dictionary_id", "dict_code", "dict_name", "describe", "dict_items") VALUES (3972882719129994240, 'ACM-003', '天联共创-生产制造-单位', '', '[{"sort": 1, "isShow": 1, "itemCode": "1", "itemLabel": "", "itemValue": "千克"}, {"sort": 2, "isShow": 1, "itemCode": "2", "itemLabel": "", "itemValue": "个"}, {"sort": 3, "isShow": 1, "itemCode": "3", "itemLabel": "", "itemValue": "包"}, {"sort": 4, "isShow": 1, "itemCode": "4", "itemLabel": "", "itemValue": "箱"}, {"sort": 5, "isShow": 1, "itemCode": "5", "itemLabel": "", "itemValue": "片"}, {"sort": 6, "isShow": 1, "itemCode": "6", "itemLabel": "", "itemValue": "套"}, {"sort": 7, "isShow": 1, "itemCode": "7", "itemLabel": "", "itemValue": "份"}, {"sort": 8, "isShow": 1, "itemCode": "8", "itemLabel": "", "itemValue": "台"}, {"sort": 9, "isShow": 1, "itemCode": "9", "itemLabel": "", "itemValue": "米"}, {"sort": 10, "isShow": 1, "itemCode": "10", "itemLabel": "", "itemValue": "升"}, {"sort": 11, "isShow": 1, "itemCode": "11", "itemLabel": "", "itemValue": "辆"}, {"sort": 12, "isShow": 1, "itemCode": "12", "itemLabel": "", "itemValue": "秒"}, {"sort": 13, "isShow": 1, "itemCode": "13", "itemLabel": "", "itemValue": "栋"}, {"sort": 14, "isShow": 1, "itemCode": "14", "itemLabel": "", "itemValue": "袋"}, {"sort": 15, "isShow": 1, "itemCode": "15", "itemLabel": "", "itemValue": "kg"}, {"sort": 16, "isShow": 1, "itemCode": "16", "itemLabel": "", "itemValue": "串"}, {"sort": 17, "isShow": 1, "itemCode": "17", "itemLabel": "", "itemValue": "件"}]'); | ||
| 6 | +INSERT INTO "public"."dictionarys"("dictionary_id", "dict_code", "dict_name", "describe", "dict_items") VALUES (3978995238135399424, 'ACM-004', '天联共创-生产制造-单位换算-物料类别', '', '[{"sort": 1, "isShow": 1, "itemCode": "1", "itemLabel": "", "itemValue": "南瓜饼串"}, {"sort": 2, "isShow": 1, "itemCode": "2", "itemLabel": "", "itemValue": "包装袋(空)"}, {"sort": 3, "isShow": 1, "itemCode": "3", "itemLabel": "", "itemValue": "包装袋(件数)"}, {"sort": 4, "isShow": 1, "itemCode": "4", "itemLabel": "", "itemValue": "装箱(件数)"}]'); | ||
| 7 | +INSERT INTO "public"."dictionarys"("dictionary_id", "dict_code", "dict_name", "describe", "dict_items") VALUES (3812266576427090944, 'XTZD-003', '生产制造-单位', '', '[{"sort": 1, "isShow": 1, "itemCode": "1", "itemLabel": "", "itemValue": "个"}, {"sort": 2, "isShow": 1, "itemCode": "2", "itemLabel": "", "itemValue": "袋"}, {"sort": 3, "isShow": 1, "itemCode": "3", "itemLabel": "", "itemValue": "kg"}, {"sort": 4, "isShow": 1, "itemCode": "4", "itemLabel": "", "itemValue": "串"}, {"sort": 5, "isShow": 1, "itemCode": "5", "itemLabel": "", "itemValue": "箱"}, {"sort": 6, "isShow": 1, "itemCode": "6", "itemLabel": "", "itemValue": "件"}]'); |
deploy/db/v1.0.2 db_script.sql
0 → 100644
| 1 | + | ||
| 2 | +-- 表product_material_group 增加唯一索引 idx_unq_product_material_group_company_id_org_id_material_group_number | ||
| 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,deleted_at); | ||
| 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,deleted_at); |
| @@ -3,6 +3,7 @@ package main | @@ -3,6 +3,7 @@ package main | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | "github.com/beego/beego/v2/server/web" | 5 | "github.com/beego/beego/v2/server/web" |
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab" | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" |
| @@ -10,7 +11,6 @@ import ( | @@ -10,7 +11,6 @@ import ( | ||
| 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/task" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/task" |
| 11 | "time" | 12 | "time" |
| 12 | 13 | ||
| 13 | - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab" | ||
| 14 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 14 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
| 15 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | 15 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" |
| 16 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" | 16 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" |
| @@ -60,6 +60,12 @@ func (crontabService *CrontabService) initTask() { | @@ -60,6 +60,12 @@ func (crontabService *CrontabService) initTask() { | ||
| 60 | 60 | ||
| 61 | syncProductPlan := task.NewTask("定时同步车间计划", "0 5 * * * *", SyncProductPlan) | 61 | syncProductPlan := task.NewTask("定时同步车间计划", "0 5 * * * *", SyncProductPlan) |
| 62 | task.AddTask("SyncProductPlan", syncProductPlan) | 62 | task.AddTask("SyncProductPlan", syncProductPlan) |
| 63 | + | ||
| 64 | + syncMaterialGroup := task.NewTask("定时同步物料分组", "0 0 0/2 * * *", SyncMaterialGroup) | ||
| 65 | + task.AddTask("syncMaterialGroup", syncMaterialGroup) | ||
| 66 | + | ||
| 67 | + syncMaterial := task.NewTask("定时同步物料", "0 0 0/2 * * *", SyncMaterial) | ||
| 68 | + task.AddTask("syncMaterial", syncMaterial) | ||
| 63 | } | 69 | } |
| 64 | 70 | ||
| 65 | func (crontabService *CrontabService) StartCrontabTask() { | 71 | func (crontabService *CrontabService) StartCrontabTask() { |
| 1 | +package crontab | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "fmt" | ||
| 6 | + "github.com/linmadan/egglib-go/transaction/pg" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/syncdata" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | ||
| 10 | + "runtime/debug" | ||
| 11 | + "time" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +// SyncMaterial 定时同步物料 | ||
| 15 | +func SyncMaterial(ctx context.Context) error { | ||
| 16 | + defer func() { | ||
| 17 | + if r := recover(); r != nil { | ||
| 18 | + log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "定时同步物料", "stack": string(debug.Stack())}) | ||
| 19 | + } | ||
| 20 | + }() | ||
| 21 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 22 | + if err != nil { | ||
| 23 | + return err | ||
| 24 | + } | ||
| 25 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 26 | + return err | ||
| 27 | + } | ||
| 28 | + defer func() { | ||
| 29 | + if err != nil { | ||
| 30 | + log.Logger.Error("【定时同步物料】 失败:" + err.Error()) | ||
| 31 | + } | ||
| 32 | + transactionContext.RollbackTransaction() | ||
| 33 | + }() | ||
| 34 | + var pullType string = "" | ||
| 35 | + if val := ctx.Value("pullType"); val != nil { | ||
| 36 | + pullType = val.(string) | ||
| 37 | + } | ||
| 38 | + log.Logger.Debug("【定时同步物料】 启动") | ||
| 39 | + pullK3CloudService := syncdata.PullDataK3CloudService{} | ||
| 40 | + if err := pullK3CloudService.SyncDataMaterial(transactionContext.(*pg.TransactionContext), pullType, time.Time{}); err != nil { | ||
| 41 | + log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时同步物料"}) | ||
| 42 | + return nil | ||
| 43 | + } | ||
| 44 | + if err = transactionContext.CommitTransaction(); err != nil { | ||
| 45 | + return err | ||
| 46 | + } | ||
| 47 | + return nil | ||
| 48 | +} |
| 1 | +package crontab | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "fmt" | ||
| 6 | + "github.com/linmadan/egglib-go/transaction/pg" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/syncdata" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | ||
| 10 | + "runtime/debug" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +// SyncMaterialGroup 定时同步物料分组 | ||
| 14 | +func SyncMaterialGroup(ctx context.Context) error { | ||
| 15 | + defer func() { | ||
| 16 | + if r := recover(); r != nil { | ||
| 17 | + log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "定时同步物料分组", "stack": string(debug.Stack())}) | ||
| 18 | + } | ||
| 19 | + }() | ||
| 20 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 21 | + if err != nil { | ||
| 22 | + return err | ||
| 23 | + } | ||
| 24 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 25 | + return err | ||
| 26 | + } | ||
| 27 | + defer func() { | ||
| 28 | + if err != nil { | ||
| 29 | + log.Logger.Error("【定时同步物料分组】 失败:" + err.Error()) | ||
| 30 | + } | ||
| 31 | + transactionContext.RollbackTransaction() | ||
| 32 | + }() | ||
| 33 | + | ||
| 34 | + log.Logger.Debug("【定时同步物料分组】 启动") | ||
| 35 | + pullK3CloudService := syncdata.PullDataK3CloudService{} | ||
| 36 | + if err := pullK3CloudService.SyncDataMaterialGroup(transactionContext.(*pg.TransactionContext)); err != nil { | ||
| 37 | + log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时同步物料分组"}) | ||
| 38 | + return nil | ||
| 39 | + } | ||
| 40 | + if err = transactionContext.CommitTransaction(); err != nil { | ||
| 41 | + return err | ||
| 42 | + } | ||
| 43 | + return nil | ||
| 44 | +} |
| @@ -413,6 +413,58 @@ func FastPgDeviceDailyRunningRecord(transactionContext application.TransactionCo | @@ -413,6 +413,58 @@ func FastPgDeviceDailyRunningRecord(transactionContext application.TransactionCo | ||
| 413 | return rep, mod, err | 413 | return rep, mod, err |
| 414 | } | 414 | } |
| 415 | 415 | ||
| 416 | +// FastProductMaterialGroup 快速返回物料 | ||
| 417 | +// | ||
| 418 | +// transactionContext 事务 | ||
| 419 | +// id 对象唯一标识 | ||
| 420 | +func FastProductMaterialGroup(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductMaterialGroupRepository, *domain.ProductMaterialGroup, error) { | ||
| 421 | + var rep domain.ProductMaterialGroupRepository | ||
| 422 | + var mod *domain.ProductMaterialGroup | ||
| 423 | + var err error | ||
| 424 | + if value, err := CreateProductMaterialGroupRepository(map[string]interface{}{ | ||
| 425 | + "transactionContext": transactionContext, | ||
| 426 | + }); err != nil { | ||
| 427 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 428 | + } else { | ||
| 429 | + rep = value | ||
| 430 | + } | ||
| 431 | + if id > 0 { | ||
| 432 | + if mod, err = rep.FindOne(map[string]interface{}{"productMaterialGroupId": id}); err != nil { | ||
| 433 | + if err == domain.ErrorNotFound { | ||
| 434 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该物料分组不存在") | ||
| 435 | + } | ||
| 436 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 437 | + } | ||
| 438 | + } | ||
| 439 | + return rep, mod, err | ||
| 440 | +} | ||
| 441 | + | ||
| 442 | +// FastProductMaterialGroup 快速返回物料 | ||
| 443 | +// | ||
| 444 | +// transactionContext 事务 | ||
| 445 | +// id 对象唯一标识 | ||
| 446 | +func FastProductMaterial(transactionContext application.TransactionContext, id int, options ...option) (domain.ProductMaterialRepository, *domain.ProductMaterial, error) { | ||
| 447 | + var rep domain.ProductMaterialRepository | ||
| 448 | + var mod *domain.ProductMaterial | ||
| 449 | + var err error | ||
| 450 | + if value, err := CreateProductMaterialRepository(map[string]interface{}{ | ||
| 451 | + "transactionContext": transactionContext, | ||
| 452 | + }); err != nil { | ||
| 453 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 454 | + } else { | ||
| 455 | + rep = value | ||
| 456 | + } | ||
| 457 | + if id > 0 { | ||
| 458 | + if mod, err = rep.FindOne(map[string]interface{}{"productMaterialId": id}); err != nil { | ||
| 459 | + if err == domain.ErrorNotFound { | ||
| 460 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该物料分组不存在") | ||
| 461 | + } | ||
| 462 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 463 | + } | ||
| 464 | + } | ||
| 465 | + return rep, mod, err | ||
| 466 | +} | ||
| 467 | + | ||
| 416 | /***** 2.配置 *****/ | 468 | /***** 2.配置 *****/ |
| 417 | 469 | ||
| 418 | type FastOptions struct { | 470 | type FastOptions struct { |
| @@ -141,3 +141,19 @@ func CreateDeviceDailyRunningRecordRepository(options map[string]interface{}) (d | @@ -141,3 +141,19 @@ func CreateDeviceDailyRunningRecordRepository(options map[string]interface{}) (d | ||
| 141 | } | 141 | } |
| 142 | return repository.NewDeviceDailyRunningRecordRepository(transactionContext) | 142 | return repository.NewDeviceDailyRunningRecordRepository(transactionContext) |
| 143 | } | 143 | } |
| 144 | + | ||
| 145 | +func CreateProductMaterialGroupRepository(options map[string]interface{}) (domain.ProductMaterialGroupRepository, error) { | ||
| 146 | + var transactionContext *pg.TransactionContext | ||
| 147 | + if value, ok := options["transactionContext"]; ok { | ||
| 148 | + transactionContext = value.(*pg.TransactionContext) | ||
| 149 | + } | ||
| 150 | + return repository.NewProductMaterialGroupRepository(transactionContext) | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +func CreateProductMaterialRepository(options map[string]interface{}) (domain.ProductMaterialRepository, error) { | ||
| 154 | + var transactionContext *pg.TransactionContext | ||
| 155 | + if value, ok := options["transactionContext"]; ok { | ||
| 156 | + transactionContext = value.(*pg.TransactionContext) | ||
| 157 | + } | ||
| 158 | + return repository.NewProductMaterialRepository(transactionContext) | ||
| 159 | +} |
| @@ -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 | } |
| 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 | +} |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/beego/beego/v2/core/validation" | ||
| 6 | + "reflect" | ||
| 7 | + "regexp" | ||
| 8 | + "strings" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type CreateProductMaterialCommand struct { | ||
| 12 | + // 企业id | ||
| 13 | + CompanyId int `cname:"企业id" json:"companyId"` | ||
| 14 | + // 组织ID | ||
| 15 | + OrgId int `cname:"组织ID" json:"orgId"` | ||
| 16 | + // 物料分组ID | ||
| 17 | + ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId" valid:"Required"` | ||
| 18 | + // 物料编码 | ||
| 19 | + MaterialNumber string `cname:"物料编码" json:"materialNumber" valid:"Required"` | ||
| 20 | + // 物料名称 | ||
| 21 | + MaterialName string `cname:"物料名称" json:"materialName" valid:"Required"` | ||
| 22 | + // 物料属性 | ||
| 23 | + MaterialAttribute string `cname:"物料属性" json:"materialAttribute" valid:"Required"` | ||
| 24 | + // 物料类别 | ||
| 25 | + MaterialCategory string `cname:"物料类别" json:"materialCategory" valid:"Required"` | ||
| 26 | + // 规格 | ||
| 27 | + Specification string `cname:"规格" json:"specification" valid:"Required"` | ||
| 28 | + // 单位 | ||
| 29 | + Unit string `cname:"单位" json:"unit" valid:"Required"` | ||
| 30 | + // 保质期 单位:天 | ||
| 31 | + ExpiredDay int `cname:"保质期 单位:天" json:"expiredDay"` | ||
| 32 | + // 备注 | ||
| 33 | + Remark string `cname:"备注" json:"remark"` | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +func (createProductMaterialCommand *CreateProductMaterialCommand) Valid(validation *validation.Validation) { | ||
| 37 | + createProductMaterialCommand.MaterialNumber = strings.ToUpper(createProductMaterialCommand.MaterialNumber) | ||
| 38 | + match, err := regexp.MatchString("^[A-Z0-9]+$", createProductMaterialCommand.MaterialNumber) | ||
| 39 | + if !match { | ||
| 40 | + validation.Error("物料编码只允许数字加大写字母组合") | ||
| 41 | + return | ||
| 42 | + } | ||
| 43 | + if err != nil { | ||
| 44 | + validation.Error(err.Error()) | ||
| 45 | + return | ||
| 46 | + } | ||
| 47 | + if len([]rune(createProductMaterialCommand.Specification)) > 50 { | ||
| 48 | + validation.Error("规格最多允许50个字符") | ||
| 49 | + return | ||
| 50 | + } | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +func (createProductMaterialCommand *CreateProductMaterialCommand) ValidateCommand() error { | ||
| 54 | + valid := validation.Validation{} | ||
| 55 | + b, err := valid.Valid(createProductMaterialCommand) | ||
| 56 | + if err != nil { | ||
| 57 | + return err | ||
| 58 | + } | ||
| 59 | + if !b { | ||
| 60 | + elem := reflect.TypeOf(createProductMaterialCommand).Elem() | ||
| 61 | + for _, validErr := range valid.Errors { | ||
| 62 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 63 | + if isExist { | ||
| 64 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 65 | + } else { | ||
| 66 | + return fmt.Errorf(validErr.Message) | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + return nil | ||
| 71 | +} |
| 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 RemoveProductMaterialCommand struct { | ||
| 12 | + // 物料ID | ||
| 13 | + ProductMaterialId int `cname:"物料ID" json:"productMaterialId" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (removeProductMaterialCommand *RemoveProductMaterialCommand) Valid(validation *validation.Validation) { | ||
| 17 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (removeProductMaterialCommand *RemoveProductMaterialCommand) ValidateCommand() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(removeProductMaterialCommand) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(removeProductMaterialCommand).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 | +} |
| 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 UpdateProductMaterialCommand struct { | ||
| 12 | + // 企业id | ||
| 13 | + //CompanyId int `cname:"企业id" json:"companyId"` | ||
| 14 | + // 组织ID | ||
| 15 | + //OrgId int `cname:"组织ID" json:"orgId"` | ||
| 16 | + // 物料ID | ||
| 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"` | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +func (updateProductMaterialCommand *UpdateProductMaterialCommand) Valid(validation *validation.Validation) { | ||
| 39 | + if len([]rune(updateProductMaterialCommand.Specification)) > 50 { | ||
| 40 | + validation.Error("规格最多允许50个字符") | ||
| 41 | + return | ||
| 42 | + } | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +func (updateProductMaterialCommand *UpdateProductMaterialCommand) ValidateCommand() error { | ||
| 46 | + valid := validation.Validation{} | ||
| 47 | + b, err := valid.Valid(updateProductMaterialCommand) | ||
| 48 | + if err != nil { | ||
| 49 | + return err | ||
| 50 | + } | ||
| 51 | + if !b { | ||
| 52 | + elem := reflect.TypeOf(updateProductMaterialCommand).Elem() | ||
| 53 | + for _, validErr := range valid.Errors { | ||
| 54 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 55 | + if isExist { | ||
| 56 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 57 | + } else { | ||
| 58 | + return fmt.Errorf(validErr.Message) | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + return nil | ||
| 63 | +} |
| 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 | +} |
| 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 GetProductMaterialQuery struct { | ||
| 12 | + // 物料ID | ||
| 13 | + ProductMaterialId int `cname:"物料ID" json:"productMaterialId" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (getProductMaterialQuery *GetProductMaterialQuery) Valid(validation *validation.Validation) { | ||
| 17 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (getProductMaterialQuery *GetProductMaterialQuery) ValidateQuery() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(getProductMaterialQuery) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(getProductMaterialQuery).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 | +} |
| 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 ListProductMaterialQuery 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 *ListProductMaterialQuery) Valid(validation *validation.Validation) { | ||
| 26 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +func (listProductMaterialQuery *ListProductMaterialQuery) 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 | +} |
| 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 | +} |
| 1 | +package service | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/linmadan/egglib-go/core/application" | ||
| 6 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 7 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
| 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" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/dto" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/query" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 13 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" | ||
| 14 | + "time" | ||
| 15 | +) | ||
| 16 | + | ||
| 17 | +// 生产物料服务 | ||
| 18 | +type ProductMaterialService struct { | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +// 创建生产物料服务 | ||
| 22 | +func (productMaterialService *ProductMaterialService) CreateProductMaterial(operateInfo *domain.OperateInfo, cmd *command.CreateProductMaterialCommand) (interface{}, error) { | ||
| 23 | + if err := cmd.ValidateCommand(); err != nil { | ||
| 24 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 25 | + } | ||
| 26 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 27 | + if err != nil { | ||
| 28 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 29 | + } | ||
| 30 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 31 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 32 | + } | ||
| 33 | + defer func() { | ||
| 34 | + transactionContext.RollbackTransaction() | ||
| 35 | + }() | ||
| 36 | + | ||
| 37 | + newProductMaterial := &domain.ProductMaterial{ | ||
| 38 | + CompanyId: cmd.CompanyId, | ||
| 39 | + OrgId: cmd.OrgId, | ||
| 40 | + ProductMaterialGroupId: cmd.ProductMaterialGroupId, | ||
| 41 | + MaterialNumber: cmd.MaterialNumber, | ||
| 42 | + MaterialName: cmd.MaterialName, | ||
| 43 | + MaterialAttribute: &domain.MaterialAttribute{Attribute: cmd.MaterialAttribute}, | ||
| 44 | + MaterialCategory: &domain.MaterialCategory{Category: cmd.MaterialCategory}, | ||
| 45 | + ProductMaterialExt: &domain.MaterialExt{ | ||
| 46 | + Specification: cmd.Specification, | ||
| 47 | + Unit: cmd.Unit, | ||
| 48 | + ExpiredDay: cmd.ExpiredDay, | ||
| 49 | + Remark: cmd.Remark, | ||
| 50 | + }, | ||
| 51 | + } | ||
| 52 | + //var productMaterial *domain.ProductMaterial | ||
| 53 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
| 54 | + if _, err := materialService.AddMaterial(operateInfo, newProductMaterial); err != nil { | ||
| 55 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 56 | + } | ||
| 57 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 58 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 59 | + } | ||
| 60 | + return struct{}{}, nil | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +// 返回生产物料服务单个 | ||
| 64 | +func (productMaterialService *ProductMaterialService) GetProductMaterial(operateInfo *domain.OperateInfo, getProductMaterialQuery *query.GetProductMaterialQuery) (interface{}, error) { | ||
| 65 | + if err := getProductMaterialQuery.ValidateQuery(); err != nil { | ||
| 66 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 67 | + } | ||
| 68 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 69 | + if err != nil { | ||
| 70 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 71 | + } | ||
| 72 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 73 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 74 | + } | ||
| 75 | + defer func() { | ||
| 76 | + transactionContext.RollbackTransaction() | ||
| 77 | + }() | ||
| 78 | + var productMaterialRepository domain.ProductMaterialRepository | ||
| 79 | + if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{ | ||
| 80 | + "transactionContext": transactionContext, | ||
| 81 | + }); err != nil { | ||
| 82 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 83 | + } else { | ||
| 84 | + productMaterialRepository = value | ||
| 85 | + } | ||
| 86 | + productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"productMaterialId": getProductMaterialQuery.ProductMaterialId}) | ||
| 87 | + if err != nil { | ||
| 88 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 89 | + } | ||
| 90 | + if productMaterial == nil { | ||
| 91 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductMaterialQuery.ProductMaterialId))) | ||
| 92 | + } else { | ||
| 93 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
| 94 | + productMaterialGroupIdNames, _, err := materialService.AllMaterialGroupParentByBacktracking(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 | ||
| 107 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 108 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 109 | + } | ||
| 110 | + return one, nil | ||
| 111 | + } | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +// 返回生产物料服务列表,未用 | ||
| 115 | +func (productMaterialService *ProductMaterialService) ListProductMaterial(operateInfo *domain.OperateInfo, listProductMaterialQuery *query.ListProductMaterialQuery) (interface{}, error) { | ||
| 116 | + if err := listProductMaterialQuery.ValidateQuery(); err != nil { | ||
| 117 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 118 | + } | ||
| 119 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 120 | + if err != nil { | ||
| 121 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 122 | + } | ||
| 123 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 124 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 125 | + } | ||
| 126 | + defer func() { | ||
| 127 | + transactionContext.RollbackTransaction() | ||
| 128 | + }() | ||
| 129 | + var productMaterialRepository domain.ProductMaterialRepository | ||
| 130 | + if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{ | ||
| 131 | + "transactionContext": transactionContext, | ||
| 132 | + }); err != nil { | ||
| 133 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 134 | + } else { | ||
| 135 | + productMaterialRepository = value | ||
| 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 | ||
| 147 | + if count, productMaterials, err := productMaterialRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialQuery)); err != nil { | ||
| 148 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 149 | + } else { | ||
| 150 | + for _, productMaterial := range productMaterials { | ||
| 151 | + results = append(results, dto.DtoProductMaterial(productMaterial)) | ||
| 152 | + } | ||
| 153 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 154 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 155 | + } | ||
| 156 | + return map[string]interface{}{ | ||
| 157 | + "count": count, | ||
| 158 | + "productMaterials": results, | ||
| 159 | + }, nil | ||
| 160 | + } | ||
| 161 | +} | ||
| 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 | + | ||
| 209 | +// 移除生产物料服务 | ||
| 210 | +func (productMaterialService *ProductMaterialService) RemoveProductMaterial(operateInfo *domain.OperateInfo, removeProductMaterialCommand *command.RemoveProductMaterialCommand) (interface{}, error) { | ||
| 211 | + if err := removeProductMaterialCommand.ValidateCommand(); err != nil { | ||
| 212 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 213 | + } | ||
| 214 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 215 | + if err != nil { | ||
| 216 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 217 | + } | ||
| 218 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 219 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 220 | + } | ||
| 221 | + defer func() { | ||
| 222 | + transactionContext.RollbackTransaction() | ||
| 223 | + }() | ||
| 224 | + var productMaterialRepository domain.ProductMaterialRepository | ||
| 225 | + if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{ | ||
| 226 | + "transactionContext": transactionContext, | ||
| 227 | + }); err != nil { | ||
| 228 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 229 | + } else { | ||
| 230 | + productMaterialRepository = value | ||
| 231 | + } | ||
| 232 | + productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"companyId": operateInfo.CompanyId, "productMaterialId": removeProductMaterialCommand.ProductMaterialId}) | ||
| 233 | + if err != nil { | ||
| 234 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 235 | + } | ||
| 236 | + if productMaterial == nil { | ||
| 237 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProductMaterialCommand.ProductMaterialId))) | ||
| 238 | + } | ||
| 239 | + if productMaterial, err := productMaterialRepository.Remove(productMaterial); err != nil { | ||
| 240 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 241 | + } else { | ||
| 242 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 243 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 244 | + } | ||
| 245 | + return productMaterial, nil | ||
| 246 | + } | ||
| 247 | +} | ||
| 248 | + | ||
| 249 | +// 更新生产物料服务 | ||
| 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 | + | ||
| 265 | + var productMaterialRepository domain.ProductMaterialRepository | ||
| 266 | + if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{ | ||
| 267 | + "transactionContext": transactionContext, | ||
| 268 | + }); err != nil { | ||
| 269 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 270 | + } else { | ||
| 271 | + productMaterialRepository = value | ||
| 272 | + } | ||
| 273 | + productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"companyId": operateInfo.CompanyId, "productMaterialId": cmd.ProductMaterialId}) | ||
| 274 | + if err != nil { | ||
| 275 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 276 | + } | ||
| 277 | + productMaterial.ProductMaterialGroupId = cmd.ProductMaterialGroupId | ||
| 278 | + productMaterial.MaterialName = cmd.MaterialName | ||
| 279 | + productMaterial.MaterialAttribute.Attribute = cmd.MaterialAttribute | ||
| 280 | + productMaterial.MaterialCategory.Category = cmd.MaterialCategory | ||
| 281 | + productMaterial.ProductMaterialExt = &domain.MaterialExt{ | ||
| 282 | + Specification: cmd.Specification, | ||
| 283 | + Unit: cmd.Unit, | ||
| 284 | + ExpiredDay: cmd.ExpiredDay, | ||
| 285 | + Remark: cmd.Remark, | ||
| 286 | + } | ||
| 287 | + productMaterial.UpdatedAt = time.Now() | ||
| 288 | + | ||
| 289 | + if _, err := productMaterialRepository.Save(productMaterial); err != nil { | ||
| 290 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 291 | + } | ||
| 292 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 293 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 294 | + } | ||
| 295 | + return struct{}{}, nil | ||
| 296 | +} | ||
| 297 | + | ||
| 298 | +// 批量移除生产物料服务 | ||
| 299 | +func (productMaterialService *ProductMaterialService) BatchRemoveProductMaterial(operateInfo *domain.OperateInfo, batchRemoveProductMaterialCommand *command.BatchRemoveProductMaterialCommand) (interface{}, error) { | ||
| 300 | + if err := batchRemoveProductMaterialCommand.ValidateCommand(); err != nil { | ||
| 301 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 302 | + } | ||
| 303 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 304 | + if err != nil { | ||
| 305 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 306 | + } | ||
| 307 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 308 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 309 | + } | ||
| 310 | + defer func() { | ||
| 311 | + transactionContext.RollbackTransaction() | ||
| 312 | + }() | ||
| 313 | + var productMaterialRepository domain.ProductMaterialRepository | ||
| 314 | + if value, err := factory.CreateProductMaterialRepository(map[string]interface{}{ | ||
| 315 | + "transactionContext": transactionContext, | ||
| 316 | + }); err != nil { | ||
| 317 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 318 | + } else { | ||
| 319 | + productMaterialRepository = value | ||
| 320 | + } | ||
| 321 | + for i := range batchRemoveProductMaterialCommand.ProductMaterialIds { | ||
| 322 | + ProductMaterialId := batchRemoveProductMaterialCommand.ProductMaterialIds[i] | ||
| 323 | + productMaterial, err := productMaterialRepository.FindOne(map[string]interface{}{"companyId": operateInfo.CompanyId, "productMaterialId": ProductMaterialId}) | ||
| 324 | + if err != nil { | ||
| 325 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 326 | + } | ||
| 327 | + if productMaterial == nil { | ||
| 328 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(ProductMaterialId))) | ||
| 329 | + } | ||
| 330 | + if _, err := productMaterialRepository.Remove(productMaterial); err != nil { | ||
| 331 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 332 | + } | ||
| 333 | + } | ||
| 334 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 335 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 336 | + } | ||
| 337 | + return struct{}{}, nil | ||
| 338 | + | ||
| 339 | +} | ||
| 340 | + | ||
| 341 | +func NewProductMaterialService(options map[string]interface{}) *ProductMaterialService { | ||
| 342 | + newProductMaterialService := &ProductMaterialService{} | ||
| 343 | + return newProductMaterialService | ||
| 344 | +} |
| 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 CreateProductMaterialGroupCommand struct { | ||
| 12 | + // 企业id | ||
| 13 | + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"` | ||
| 14 | + // 组织ID | ||
| 15 | + OrgId int `cname:"组织ID" json:"orgId" valid:"Required"` | ||
| 16 | + // 父级ID | ||
| 17 | + Pid int `cname:"父级ID" json:"pid"` | ||
| 18 | + // 物料分组名称 | ||
| 19 | + MaterialGroupName string `cname:"物料分组名称" json:"materialGroupName" valid:"Required"` | ||
| 20 | + // 物料分组编码 | ||
| 21 | + MaterialGroupNumber string `cname:"物料分组编码" json:"materialGroupNumber,omitempty"` | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +func (createProductMaterialGroupCommand *CreateProductMaterialGroupCommand) Valid(validation *validation.Validation) { | ||
| 25 | + | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +func (createProductMaterialGroupCommand *CreateProductMaterialGroupCommand) ValidateCommand() error { | ||
| 29 | + valid := validation.Validation{} | ||
| 30 | + b, err := valid.Valid(createProductMaterialGroupCommand) | ||
| 31 | + if err != nil { | ||
| 32 | + return err | ||
| 33 | + } | ||
| 34 | + if !b { | ||
| 35 | + elem := reflect.TypeOf(createProductMaterialGroupCommand).Elem() | ||
| 36 | + for _, validErr := range valid.Errors { | ||
| 37 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 38 | + if isExist { | ||
| 39 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 40 | + } else { | ||
| 41 | + return fmt.Errorf(validErr.Message) | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + return nil | ||
| 46 | +} |
| 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 RemoveProductMaterialGroupCommand struct { | ||
| 12 | + // 物料分组ID | ||
| 13 | + ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (removeProductMaterialGroupCommand *RemoveProductMaterialGroupCommand) Valid(validation *validation.Validation) { | ||
| 17 | + | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (removeProductMaterialGroupCommand *RemoveProductMaterialGroupCommand) ValidateCommand() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(removeProductMaterialGroupCommand) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(removeProductMaterialGroupCommand).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 | +} |
| 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 UpdateProductMaterialGroupCommand struct { | ||
| 12 | + // 物料分组ID | ||
| 13 | + ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId" valid:"Required"` | ||
| 14 | + // 物料分组名称 | ||
| 15 | + MaterialGroupName string `cname:"物料分组名称" json:"materialGroupName" valid:"Required"` | ||
| 16 | + // 物料分组编码 | ||
| 17 | + MaterialGroupNumber string `cname:"物料分组编码" json:"materialGroupNumber"` | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (updateProductMaterialGroupCommand *UpdateProductMaterialGroupCommand) Valid(validation *validation.Validation) { | ||
| 21 | + | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +func (updateProductMaterialGroupCommand *UpdateProductMaterialGroupCommand) ValidateCommand() error { | ||
| 25 | + valid := validation.Validation{} | ||
| 26 | + b, err := valid.Valid(updateProductMaterialGroupCommand) | ||
| 27 | + if err != nil { | ||
| 28 | + return err | ||
| 29 | + } | ||
| 30 | + if !b { | ||
| 31 | + elem := reflect.TypeOf(updateProductMaterialGroupCommand).Elem() | ||
| 32 | + for _, validErr := range valid.Errors { | ||
| 33 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 34 | + if isExist { | ||
| 35 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 36 | + } else { | ||
| 37 | + return fmt.Errorf(validErr.Message) | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + return nil | ||
| 42 | +} |
| 1 | +package dto | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type MaterialGroupDto struct { | ||
| 9 | + // 物料分组ID | ||
| 10 | + ProductMaterialGroupId int `json:"id"` | ||
| 11 | + // 企业id | ||
| 12 | + //CompanyId int `json:"companyId"` | ||
| 13 | + // 组织ID | ||
| 14 | + //OrgId int `json:"orgId"` | ||
| 15 | + // 父级ID | ||
| 16 | + Pid int `json:"pid"` | ||
| 17 | + // 路径 (不使用,如果父级改变的话,子级的Path要做更新) | ||
| 18 | + //Path string `json:"path"` | ||
| 19 | + // 物料分组名称 | ||
| 20 | + MaterialGroupName string `json:"materialGroupName"` | ||
| 21 | + // 物料分组编码 | ||
| 22 | + MaterialGroupNumber string `json:"materialGroupNumber"` | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +func (d *MaterialGroupDto) LoadDto(m *domain.ProductMaterialGroup, orgId int) *MaterialGroupDto { | ||
| 26 | + d.ProductMaterialGroupId = m.ProductMaterialGroupId | ||
| 27 | + d.Pid = m.Pid | ||
| 28 | + d.MaterialGroupName = m.MaterialGroupName | ||
| 29 | + d.MaterialGroupNumber = m.MaterialGroupNumber | ||
| 30 | + return d | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +func (productMaterialGroup *MaterialGroupDto) PID() string { | ||
| 34 | + return fmt.Sprintf("%d", productMaterialGroup.Pid) | ||
| 35 | +} | ||
| 36 | +func (productMaterialGroup *MaterialGroupDto) ID() string { | ||
| 37 | + return fmt.Sprintf("%d", productMaterialGroup.ProductMaterialGroupId) | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +type MaterialGroupDtos []*MaterialGroupDto | ||
| 41 | + | ||
| 42 | +func (tree MaterialGroupDtos) Len() int { | ||
| 43 | + return len(tree) | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +func (tree MaterialGroupDtos) Less(i, j int) bool { | ||
| 47 | + if tree[i].Pid < tree[j].Pid { | ||
| 48 | + return true | ||
| 49 | + } | ||
| 50 | + if tree[i].Pid == tree[j].Pid { | ||
| 51 | + return tree[i].ProductMaterialGroupId < tree[j].ProductMaterialGroupId | ||
| 52 | + } | ||
| 53 | + return false | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +func (tree MaterialGroupDtos) Swap(i, j int) { | ||
| 57 | + tree[i], tree[j] = tree[j], tree[i] | ||
| 58 | +} |
| 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 GetProductMaterialGroupQuery struct { | ||
| 12 | + // 物料分组ID | ||
| 13 | + ProductMaterialGroupId int `cname:"物料分组ID" json:"productMaterialGroupId" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (getProductMaterialGroupQuery *GetProductMaterialGroupQuery) Valid(validation *validation.Validation) { | ||
| 17 | + | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (getProductMaterialGroupQuery *GetProductMaterialGroupQuery) ValidateQuery() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(getProductMaterialGroupQuery) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(getProductMaterialGroupQuery).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 | +} |
| 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 ListProductMaterialGroupQuery struct { | ||
| 12 | + // 查询偏离量 | ||
| 13 | + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` | ||
| 14 | + // 查询限制 | ||
| 15 | + Limit int `cname:"查询限制" json:"limit" valid:"Required"` | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (listProductMaterialGroupQuery *ListProductMaterialGroupQuery) Valid(validation *validation.Validation) { | ||
| 19 | + | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func (listProductMaterialGroupQuery *ListProductMaterialGroupQuery) ValidateQuery() error { | ||
| 23 | + valid := validation.Validation{} | ||
| 24 | + b, err := valid.Valid(listProductMaterialGroupQuery) | ||
| 25 | + if err != nil { | ||
| 26 | + return err | ||
| 27 | + } | ||
| 28 | + if !b { | ||
| 29 | + elem := reflect.TypeOf(listProductMaterialGroupQuery).Elem() | ||
| 30 | + for _, validErr := range valid.Errors { | ||
| 31 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 32 | + if isExist { | ||
| 33 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 34 | + } else { | ||
| 35 | + return fmt.Errorf(validErr.Message) | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + return nil | ||
| 40 | +} |
| 1 | +package query | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 6 | + "reflect" | ||
| 7 | + "strings" | ||
| 8 | + | ||
| 9 | + "github.com/beego/beego/v2/core/validation" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type SearchProductMaterialGroupQuery struct { | ||
| 13 | + // 查询偏离量 | ||
| 14 | + Offset int `cname:"查询偏离量" json:"offset"` | ||
| 15 | + // 查询限制 | ||
| 16 | + Limit int `cname:"查询限制" json:"limit"` | ||
| 17 | + | ||
| 18 | + // 当前公司 | ||
| 19 | + CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"` | ||
| 20 | + // 当前登录的组织 | ||
| 21 | + //OrgId int `cname:"当前登录的组织" json:"orgId,omitempty"` | ||
| 22 | + // 匹配多个组织 | ||
| 23 | + //InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty" valid:"Required"` | ||
| 24 | + // 页码 | ||
| 25 | + PageNumber int `cname:"页码" json:"pageNumber,omitempty"` | ||
| 26 | + // 页数 | ||
| 27 | + PageSize int `cname:"页数" json:"pageSize,omitempty"` | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func (cmd *SearchProductMaterialGroupQuery) Valid(validation *validation.Validation) { | ||
| 31 | + cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize) | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +func (cmd *SearchProductMaterialGroupQuery) ValidateQuery() error { | ||
| 35 | + valid := validation.Validation{} | ||
| 36 | + b, err := valid.Valid(cmd) | ||
| 37 | + if err != nil { | ||
| 38 | + return err | ||
| 39 | + } | ||
| 40 | + if !b { | ||
| 41 | + elem := reflect.TypeOf(cmd).Elem() | ||
| 42 | + for _, validErr := range valid.Errors { | ||
| 43 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 44 | + if isExist { | ||
| 45 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 46 | + } else { | ||
| 47 | + return fmt.Errorf(validErr.Message) | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + return nil | ||
| 52 | +} |
| 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 SelectorProductMaterialGroupQuery struct { | ||
| 12 | + // 查询偏离量 | ||
| 13 | + //Offset int `cname:"查询偏离量" json:"offset"` | ||
| 14 | + // 查询限制 | ||
| 15 | + //Limit int `cname:"查询限制" json:"limit"` | ||
| 16 | + // options 'tree' 'list' default tree | ||
| 17 | + Style string `json:"style"` | ||
| 18 | + // 当前公司 | ||
| 19 | + CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"` | ||
| 20 | + // 页码 | ||
| 21 | + //PageNumber int `cname:"页码" json:"pageNumber,omitempty"` | ||
| 22 | + // 页数 | ||
| 23 | + //PageSize int `cname:"页数" json:"pageSize,omitempty"` | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (cmd *SelectorProductMaterialGroupQuery) Valid(validation *validation.Validation) { | ||
| 27 | + //cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize) | ||
| 28 | + cmd.Style = "tree" | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +func (cmd *SelectorProductMaterialGroupQuery) ValidateQuery() error { | ||
| 32 | + valid := validation.Validation{} | ||
| 33 | + b, err := valid.Valid(cmd) | ||
| 34 | + if err != nil { | ||
| 35 | + return err | ||
| 36 | + } | ||
| 37 | + if !b { | ||
| 38 | + elem := reflect.TypeOf(cmd).Elem() | ||
| 39 | + for _, validErr := range valid.Errors { | ||
| 40 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 41 | + if isExist { | ||
| 42 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 43 | + } else { | ||
| 44 | + return fmt.Errorf(validErr.Message) | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + return nil | ||
| 49 | +} |
| 1 | +package service | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/linmadan/egglib-go/core/application" | ||
| 6 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 7 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterialGroup/command" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterialGroup/dto" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterialGroup/query" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 13 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" | ||
| 14 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
| 15 | + "sort" | ||
| 16 | +) | ||
| 17 | + | ||
| 18 | +// 物料分组服务 | ||
| 19 | +type ProductMaterialGroupService struct { | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +// 创建物料分组服务 | ||
| 23 | +func (productMaterialGroupService *ProductMaterialGroupService) CreateProductMaterialGroup(operateInfo *domain.OperateInfo, createProductMaterialGroupCommand *command.CreateProductMaterialGroupCommand) (interface{}, error) { | ||
| 24 | + if err := createProductMaterialGroupCommand.ValidateCommand(); err != nil { | ||
| 25 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 26 | + } | ||
| 27 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 28 | + if err != nil { | ||
| 29 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 30 | + } | ||
| 31 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 32 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 33 | + } | ||
| 34 | + defer func() { | ||
| 35 | + transactionContext.RollbackTransaction() | ||
| 36 | + }() | ||
| 37 | + newProductMaterialGroup := &domain.ProductMaterialGroup{ | ||
| 38 | + Pid: createProductMaterialGroupCommand.Pid, | ||
| 39 | + MaterialGroupName: createProductMaterialGroupCommand.MaterialGroupName, | ||
| 40 | + MaterialGroupNumber: createProductMaterialGroupCommand.MaterialGroupNumber, | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + var productMaterialGroup *domain.ProductMaterialGroup | ||
| 44 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
| 45 | + if productMaterialGroup, err = materialService.AddMaterialGroup(operateInfo, newProductMaterialGroup); err != nil { | ||
| 46 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 47 | + } | ||
| 48 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 49 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 50 | + } | ||
| 51 | + return productMaterialGroup, nil | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +// 返回物料分组服务 | ||
| 55 | +func (productMaterialGroupService *ProductMaterialGroupService) GetProductMaterialGroup(getProductMaterialGroupQuery *query.GetProductMaterialGroupQuery) (interface{}, error) { | ||
| 56 | + if err := getProductMaterialGroupQuery.ValidateQuery(); err != nil { | ||
| 57 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 58 | + } | ||
| 59 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 60 | + if err != nil { | ||
| 61 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 62 | + } | ||
| 63 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 64 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 65 | + } | ||
| 66 | + defer func() { | ||
| 67 | + transactionContext.RollbackTransaction() | ||
| 68 | + }() | ||
| 69 | + var productMaterialGroupRepository domain.ProductMaterialGroupRepository | ||
| 70 | + if value, err := factory.CreateProductMaterialGroupRepository(map[string]interface{}{ | ||
| 71 | + "transactionContext": transactionContext, | ||
| 72 | + }); err != nil { | ||
| 73 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 74 | + } else { | ||
| 75 | + productMaterialGroupRepository = value | ||
| 76 | + } | ||
| 77 | + productMaterialGroup, err := productMaterialGroupRepository.FindOne(map[string]interface{}{"productMaterialGroupId": getProductMaterialGroupQuery.ProductMaterialGroupId}) | ||
| 78 | + if err != nil { | ||
| 79 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 80 | + } | ||
| 81 | + if productMaterialGroup == nil { | ||
| 82 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductMaterialGroupQuery.ProductMaterialGroupId))) | ||
| 83 | + } | ||
| 84 | + //测试 | ||
| 85 | + //materialService,_:= domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
| 86 | + //nodes,child,_:=materialService.AllMaterialGroupChild(&domain.OperateInfo{CompanyId: productMaterialGroup.CompanyId},productMaterialGroup.ProductMaterialGroupId) | ||
| 87 | + //log.Logger.Debug("节点的Child", map[string]interface{}{"data":child,"nodes":nodes}) | ||
| 88 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 89 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 90 | + } | ||
| 91 | + materialGroupDto := dto.MaterialGroupDto{} | ||
| 92 | + return materialGroupDto.LoadDto(productMaterialGroup, 0), nil | ||
| 93 | + | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +// 返回物料分组服务列表 | ||
| 97 | +func (productMaterialGroupService *ProductMaterialGroupService) ListProductMaterialGroup(listProductMaterialGroupQuery *query.ListProductMaterialGroupQuery) (interface{}, error) { | ||
| 98 | + if err := listProductMaterialGroupQuery.ValidateQuery(); err != nil { | ||
| 99 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 100 | + } | ||
| 101 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 102 | + if err != nil { | ||
| 103 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 104 | + } | ||
| 105 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 106 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 107 | + } | ||
| 108 | + defer func() { | ||
| 109 | + transactionContext.RollbackTransaction() | ||
| 110 | + }() | ||
| 111 | + var productMaterialGroupRepository domain.ProductMaterialGroupRepository | ||
| 112 | + if value, err := factory.CreateProductMaterialGroupRepository(map[string]interface{}{ | ||
| 113 | + "transactionContext": transactionContext, | ||
| 114 | + }); err != nil { | ||
| 115 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 116 | + } else { | ||
| 117 | + productMaterialGroupRepository = value | ||
| 118 | + } | ||
| 119 | + if count, productMaterialGroups, err := productMaterialGroupRepository.Find(tool_funs.SimpleStructToMap(listProductMaterialGroupQuery)); err != nil { | ||
| 120 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 121 | + } else { | ||
| 122 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 123 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 124 | + } | ||
| 125 | + return map[string]interface{}{ | ||
| 126 | + "count": count, | ||
| 127 | + "productMaterialGroups": productMaterialGroups, | ||
| 128 | + }, nil | ||
| 129 | + } | ||
| 130 | +} | ||
| 131 | + | ||
| 132 | +// 移除物料分组服务 | ||
| 133 | +func (productMaterialGroupService *ProductMaterialGroupService) RemoveProductMaterialGroup(removeProductMaterialGroupCommand *command.RemoveProductMaterialGroupCommand) (interface{}, error) { | ||
| 134 | + if err := removeProductMaterialGroupCommand.ValidateCommand(); err != nil { | ||
| 135 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 136 | + } | ||
| 137 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 138 | + if err != nil { | ||
| 139 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 140 | + } | ||
| 141 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 142 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 143 | + } | ||
| 144 | + defer func() { | ||
| 145 | + transactionContext.RollbackTransaction() | ||
| 146 | + }() | ||
| 147 | + var productMaterialGroupRepository domain.ProductMaterialGroupRepository | ||
| 148 | + if value, err := factory.CreateProductMaterialGroupRepository(map[string]interface{}{ | ||
| 149 | + "transactionContext": transactionContext, | ||
| 150 | + }); err != nil { | ||
| 151 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 152 | + } else { | ||
| 153 | + productMaterialGroupRepository = value | ||
| 154 | + } | ||
| 155 | + productMaterialGroup, err := productMaterialGroupRepository.FindOne(map[string]interface{}{"productMaterialGroupId": removeProductMaterialGroupCommand.ProductMaterialGroupId}) | ||
| 156 | + if err != nil { | ||
| 157 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 158 | + } | ||
| 159 | + if productMaterialGroup == nil { | ||
| 160 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("已删除 %s", string(removeProductMaterialGroupCommand.ProductMaterialGroupId))) | ||
| 161 | + } | ||
| 162 | + if productMaterialGroup, err := productMaterialGroupRepository.Remove(productMaterialGroup); err != nil { | ||
| 163 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 164 | + } else { | ||
| 165 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 166 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 167 | + } | ||
| 168 | + return productMaterialGroup, nil | ||
| 169 | + } | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | +// 更新物料分组服务 | ||
| 173 | +func (productMaterialGroupService *ProductMaterialGroupService) UpdateProductMaterialGroup(operateInfo *domain.OperateInfo, cmd *command.UpdateProductMaterialGroupCommand) (interface{}, error) { | ||
| 174 | + if err := cmd.ValidateCommand(); err != nil { | ||
| 175 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 176 | + } | ||
| 177 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 178 | + if err != nil { | ||
| 179 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 180 | + } | ||
| 181 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 182 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 183 | + } | ||
| 184 | + defer func() { | ||
| 185 | + transactionContext.RollbackTransaction() | ||
| 186 | + }() | ||
| 187 | + productMaterialGroup := &domain.ProductMaterialGroup{ | ||
| 188 | + ProductMaterialGroupId: cmd.ProductMaterialGroupId, | ||
| 189 | + MaterialGroupName: cmd.MaterialGroupName, | ||
| 190 | + //MaterialGroupNumber: cmd.MaterialGroupNumber, | ||
| 191 | + } | ||
| 192 | + materialService, _ := domainService.NewPGMaterialService(transactionContext.(*pgTransaction.TransactionContext)) | ||
| 193 | + if productMaterialGroup, err := materialService.UpdateMaterialGroup(operateInfo, productMaterialGroup); err != nil { | ||
| 194 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 195 | + } else { | ||
| 196 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 197 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 198 | + } | ||
| 199 | + materialGroupDto := dto.MaterialGroupDto{} | ||
| 200 | + return materialGroupDto.LoadDto(productMaterialGroup, 0), nil | ||
| 201 | + } | ||
| 202 | +} | ||
| 203 | + | ||
| 204 | +// 搜索物料分组服务列表 | ||
| 205 | +func (productMaterialGroupService *ProductMaterialGroupService) SearchProductMaterialGroup(operateInfo *domain.OperateInfo, cmd *query.SearchProductMaterialGroupQuery) (int64, interface{}, error) { | ||
| 206 | + if err := cmd.ValidateQuery(); err != nil { | ||
| 207 | + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 208 | + } | ||
| 209 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 210 | + if err != nil { | ||
| 211 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 212 | + } | ||
| 213 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 214 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 215 | + } | ||
| 216 | + defer func() { | ||
| 217 | + transactionContext.RollbackTransaction() | ||
| 218 | + }() | ||
| 219 | + var productMaterialGroupRepository domain.ProductMaterialGroupRepository | ||
| 220 | + productMaterialGroupRepository, _, _ = factory.FastProductMaterialGroup(transactionContext, 0) | ||
| 221 | + queryOptions := utils.ObjectToMap(cmd) | ||
| 222 | + count, productGroups, err := productMaterialGroupRepository.Find(queryOptions) | ||
| 223 | + if err != nil { | ||
| 224 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 225 | + } | ||
| 226 | + var results = make([]*dto.MaterialGroupDto, 0) | ||
| 227 | + for i := range productGroups { | ||
| 228 | + newItem := &dto.MaterialGroupDto{} | ||
| 229 | + newItem.LoadDto(productGroups[i], operateInfo.OrgId) | ||
| 230 | + results = append(results, newItem) | ||
| 231 | + } | ||
| 232 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 233 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 234 | + } | ||
| 235 | + return count, results, nil | ||
| 236 | +} | ||
| 237 | + | ||
| 238 | +func (productMaterialGroupService *ProductMaterialGroupService) SelectorProductMaterialGroup(operateInfo *domain.OperateInfo, cmd *query.SelectorProductMaterialGroupQuery) (int64, interface{}, error) { | ||
| 239 | + if err := cmd.ValidateQuery(); err != nil { | ||
| 240 | + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 241 | + } | ||
| 242 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 243 | + if err != nil { | ||
| 244 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 245 | + } | ||
| 246 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 247 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 248 | + } | ||
| 249 | + defer func() { | ||
| 250 | + transactionContext.RollbackTransaction() | ||
| 251 | + }() | ||
| 252 | + var productMaterialGroupRepository domain.ProductMaterialGroupRepository | ||
| 253 | + productMaterialGroupRepository, _, _ = factory.FastProductMaterialGroup(transactionContext, 0) | ||
| 254 | + queryOptions := utils.ObjectToMap(cmd) | ||
| 255 | + count, productGroups, err := productMaterialGroupRepository.Find(queryOptions) | ||
| 256 | + if err != nil { | ||
| 257 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 258 | + } | ||
| 259 | + var results = make([]*dto.MaterialGroupDto, 0) | ||
| 260 | + for i := range productGroups { | ||
| 261 | + newItem := &dto.MaterialGroupDto{} | ||
| 262 | + newItem.LoadDto(productGroups[i], operateInfo.OrgId) | ||
| 263 | + results = append(results, newItem) | ||
| 264 | + } | ||
| 265 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 266 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 267 | + } | ||
| 268 | + if cmd.Style == "tree" { | ||
| 269 | + sort.Stable(dto.MaterialGroupDtos(results)) | ||
| 270 | + nodes := make([]utils.TreeNode, 0) | ||
| 271 | + for i := range results { | ||
| 272 | + nodes = append(nodes, results[i]) | ||
| 273 | + } | ||
| 274 | + tree := utils.NewTree(nodes) | ||
| 275 | + return count, tree.Nodes, nil | ||
| 276 | + } | ||
| 277 | + return count, results, nil | ||
| 278 | +} | ||
| 279 | + | ||
| 280 | +func NewProductMaterialGroupService(options map[string]interface{}) *ProductMaterialGroupService { | ||
| 281 | + newProductMaterialGroupService := &ProductMaterialGroupService{} | ||
| 282 | + return newProductMaterialGroupService | ||
| 283 | +} |
| 1 | package syncdata | 1 | package syncdata |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "fmt" | ||
| 4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
| 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
| 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" |
| @@ -209,6 +210,101 @@ func (srv *PullDataK3CloudService) PullMaterial(timeFilter time.Time) error { | @@ -209,6 +210,101 @@ func (srv *PullDataK3CloudService) PullMaterial(timeFilter time.Time) error { | ||
| 209 | return nil | 210 | return nil |
| 210 | } | 211 | } |
| 211 | 212 | ||
| 213 | +func (srv *PullDataK3CloudService) pullMaterial(timeFilter time.Time) ([]models.MaterialK3cloud, error) { | ||
| 214 | + //拉取数据 | ||
| 215 | + var filterString []string | ||
| 216 | + if !timeFilter.IsZero() { | ||
| 217 | + str := timeFilter.Format("2006-01-02T15:04:05") | ||
| 218 | + filterString = append(filterString, "FModifyDate>='"+str+"'") | ||
| 219 | + } | ||
| 220 | + client, err := newK3cloudClient() | ||
| 221 | + if err != nil { | ||
| 222 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 223 | + } | ||
| 224 | + fieldKeys := []string{ | ||
| 225 | + "FMATERIALID", "FSpecification", "FName", "FNumber", | ||
| 226 | + "FDocumentStatus", "FForbidStatus", "FErpClsID", | ||
| 227 | + "FBaseUnitId", "FBaseUnitId.FName", "FCreateDate", "FModifyDate", | ||
| 228 | + "FForbidDate", "FApproveDate", "FMaterialGroup", "FMaterialGroup.FName", | ||
| 229 | + "FRefStatus", "FMaterialGroup.FNumber", "FUseOrgId", "FUseOrgId.FName", "FCategoryID", | ||
| 230 | + } | ||
| 231 | + var ( | ||
| 232 | + startRow int | ||
| 233 | + allResult []map[string]string | ||
| 234 | + queryErr error | ||
| 235 | + ) | ||
| 236 | + for { | ||
| 237 | + result, err := client.ExecuteBillQuery(k3cloud.RequestExecuteBillQuery{ | ||
| 238 | + FormId: "BD_MATERIAL", | ||
| 239 | + Data: k3cloud.ExecuteBillQueryData{ | ||
| 240 | + FormId: "BD_MATERIAL", | ||
| 241 | + FieldKeys: strings.Join(fieldKeys, ","), //查询的字段 | ||
| 242 | + StartRow: startRow, | ||
| 243 | + Limit: 1000, | ||
| 244 | + FilterString: strings.Join(filterString, " and "), | ||
| 245 | + }, | ||
| 246 | + }) | ||
| 247 | + if err != nil { | ||
| 248 | + queryErr = err | ||
| 249 | + break | ||
| 250 | + } | ||
| 251 | + mp := result.ToMapString() | ||
| 252 | + if len(mp) == 0 { | ||
| 253 | + break | ||
| 254 | + } | ||
| 255 | + allResult = append(allResult, mp...) | ||
| 256 | + startRow += 1000 | ||
| 257 | + } | ||
| 258 | + if queryErr != nil { | ||
| 259 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 260 | + } | ||
| 261 | + var ( | ||
| 262 | + materialModels []models.MaterialK3cloud | ||
| 263 | + materialTemp models.MaterialK3cloud | ||
| 264 | + ) | ||
| 265 | + nowTime := time.Now() | ||
| 266 | + for _, item := range allResult { | ||
| 267 | + materialId, err := strconv.Atoi(item["FMATERIALID"]) | ||
| 268 | + if err != nil { | ||
| 269 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 270 | + } | ||
| 271 | + fErpClsID, _ := strconv.Atoi(item["FErpClsID"]) | ||
| 272 | + fBaseUnitId, _ := strconv.Atoi(item["FBaseUnitId"]) | ||
| 273 | + materialGroup, _ := strconv.Atoi(item["MaterialGroup"]) | ||
| 274 | + fUseOrgId, _ := strconv.Atoi(item["FUseOrgId"]) | ||
| 275 | + refStatus, _ := strconv.Atoi(item["RefStatus"]) | ||
| 276 | + fCreateDate, _ := time.Parse("2006-01-02T15:04:05.999", item["FCreateDate"]) | ||
| 277 | + fModifyDate, _ := time.Parse("2006-01-02T15:04:05.999", item["FModifyDate"]) | ||
| 278 | + fForbidDate, _ := time.Parse("2006-01-02T15:04:05.999", item["FForbidDate"]) | ||
| 279 | + fApproveDate, _ := time.Parse("2006-01-02T15:04:05.999", item["FApproveDate"]) | ||
| 280 | + materialTemp = models.MaterialK3cloud{ | ||
| 281 | + MaterialId: materialId, | ||
| 282 | + Name: item["FName"], | ||
| 283 | + Number: item["FNumber"], | ||
| 284 | + Specification: item["FSpecification"], | ||
| 285 | + ForbidStatus: item["FForbidStatus"], | ||
| 286 | + ErpClsId: fErpClsID, | ||
| 287 | + BaseUnitId: fBaseUnitId, | ||
| 288 | + BaseUnitName: item["FBaseUnitId.FName"], | ||
| 289 | + CreateDate: fCreateDate, | ||
| 290 | + ModifyDate: fModifyDate, | ||
| 291 | + ForbidDate: fForbidDate, | ||
| 292 | + ApproveDate: fApproveDate, | ||
| 293 | + MaterialGroup: materialGroup, | ||
| 294 | + MaterialGroupNumber: item["FMaterialGroup.FNumber"], | ||
| 295 | + MaterialGroupName: item["FMaterialGroup.FName"], | ||
| 296 | + RefStatus: refStatus, | ||
| 297 | + UseOrgId: fUseOrgId, | ||
| 298 | + UseOrgName: item["FUseOrgId.FName"], | ||
| 299 | + JoinProductId: 0, | ||
| 300 | + DataVersion: nowTime.Unix(), | ||
| 301 | + FCategoryID: item["FCategoryID"], | ||
| 302 | + } | ||
| 303 | + materialModels = append(materialModels, materialTemp) | ||
| 304 | + } | ||
| 305 | + return materialModels, nil | ||
| 306 | +} | ||
| 307 | + | ||
| 212 | //PullMaterialGroup 拉取物料分组 | 308 | //PullMaterialGroup 拉取物料分组 |
| 213 | func (srv *PullDataK3CloudService) PullMaterialGroup() error { | 309 | func (srv *PullDataK3CloudService) PullMaterialGroup() error { |
| 214 | client, err := newK3cloudClient() | 310 | client, err := newK3cloudClient() |
| @@ -462,6 +558,33 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { | @@ -462,6 +558,33 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { | ||
| 462 | return nil | 558 | return nil |
| 463 | } | 559 | } |
| 464 | 560 | ||
| 561 | +// PullMaterialCategory 拉取物料分类 | ||
| 562 | +func (srv *PullDataK3CloudService) PullMaterialCategory() (map[string]string, error) { | ||
| 563 | + client, err := newK3cloudClient() | ||
| 564 | + if err != nil { | ||
| 565 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 566 | + } | ||
| 567 | + fieldKeys := []string{ | ||
| 568 | + "FName", "FNUMBER", "FMasterId", | ||
| 569 | + } | ||
| 570 | + result, err := client.ExecuteBillQuery(k3cloud.RequestExecuteBillQuery{ | ||
| 571 | + FormId: "BD_MATERIALCATEGORY", | ||
| 572 | + Data: k3cloud.ExecuteBillQueryData{ | ||
| 573 | + FormId: "BD_MATERIALCATEGORY", | ||
| 574 | + FieldKeys: strings.Join(fieldKeys, ","), //查询的字段 | ||
| 575 | + //TopRowCount: 4, | ||
| 576 | + | ||
| 577 | + FilterString: "", | ||
| 578 | + }, | ||
| 579 | + }) | ||
| 580 | + categorys := result.ToMapString() | ||
| 581 | + var categorysById = make(map[string]string) | ||
| 582 | + for _, v := range categorys { | ||
| 583 | + categorysById[v["FMasterId"]] = v["FName"] | ||
| 584 | + } | ||
| 585 | + return categorysById, nil | ||
| 586 | +} | ||
| 587 | + | ||
| 465 | // 同步产品 | 588 | // 同步产品 |
| 466 | func (srv *PullDataK3CloudService) SyncDataProduct(ptr *pgTransaction.TransactionContext, fromTime time.Time) error { | 589 | func (srv *PullDataK3CloudService) SyncDataProduct(ptr *pgTransaction.TransactionContext, fromTime time.Time) error { |
| 467 | prdMoDao, err := dao.NewMaterialK3cloudDao(ptr) | 590 | prdMoDao, err := dao.NewMaterialK3cloudDao(ptr) |
| @@ -612,3 +735,165 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa | @@ -612,3 +735,165 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa | ||
| 612 | } | 735 | } |
| 613 | return nil | 736 | return nil |
| 614 | } | 737 | } |
| 738 | + | ||
| 739 | +// 同步产品 | ||
| 740 | +func (srv *PullDataK3CloudService) SyncDataMaterialGroup(ptr *pgTransaction.TransactionContext) error { | ||
| 741 | + prdMoDao, err := dao.NewMaterialK3cloudDao(ptr) | ||
| 742 | + if err != nil { | ||
| 743 | + return err | ||
| 744 | + } | ||
| 745 | + var userService = domainService.NewUserService() | ||
| 746 | + org, err := userService.Organization(constant.MANUFACTURE_DEFAULT_ORGID) | ||
| 747 | + if err != nil { | ||
| 748 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 749 | + } | ||
| 750 | + fromMaterialGroups, err := prdMoDao.SearchMaterialGroup() // 默认企业名称素天下、或者使用组织ID | ||
| 751 | + if err != nil { | ||
| 752 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 753 | + } | ||
| 754 | + var ( | ||
| 755 | + cid = constant.MANUFACTURE_DEFAULT_COMPANYID | ||
| 756 | + oid = constant.MANUFACTURE_DEFAULT_ORGID | ||
| 757 | + ) | ||
| 758 | + productMaterialGroupRepository, _, _ := factory.FastProductMaterialGroup(ptr, 0) | ||
| 759 | + _, materialGroups, err := productMaterialGroupRepository.Find(map[string]interface{}{"companyId": cid}) | ||
| 760 | + if err != nil { | ||
| 761 | + return err | ||
| 762 | + } | ||
| 763 | + mapMaterialGroups := domain.ProductMaterialGroups(materialGroups).ToMapByGroupNumber() | ||
| 764 | + mapFromMaterialGroups := models.MaterialGroupK3clouds(fromMaterialGroups).ToMapId() | ||
| 765 | + for _, from := range fromMaterialGroups { | ||
| 766 | + to, ok := mapMaterialGroups[from.Number] | ||
| 767 | + if ok { | ||
| 768 | + // 更新 | ||
| 769 | + if to.MaterialGroupName != from.Name { | ||
| 770 | + log.Logger.Info(fmt.Sprintf("更新物料分组 old:%v new:%v", to.MaterialGroupName, from.Name), map[string]interface{}{"material": to}) | ||
| 771 | + to.MaterialGroupName = from.Name | ||
| 772 | + } | ||
| 773 | + continue | ||
| 774 | + } | ||
| 775 | + var parentId int | ||
| 776 | + if from.ParentId > 0 { | ||
| 777 | + parent, ok := mapFromMaterialGroups[from.ParentId] | ||
| 778 | + if !ok { | ||
| 779 | + log.Logger.Warn("parent node not exits", map[string]interface{}{"material": to}) | ||
| 780 | + continue | ||
| 781 | + } | ||
| 782 | + toParent, ok := mapMaterialGroups[parent.Number] | ||
| 783 | + if !ok { | ||
| 784 | + log.Logger.Warn("to parent node not exits", map[string]interface{}{"material": to}) | ||
| 785 | + continue | ||
| 786 | + } | ||
| 787 | + parentId = toParent.ProductMaterialGroupId | ||
| 788 | + } | ||
| 789 | + productMaterialGroup := &domain.ProductMaterialGroup{ | ||
| 790 | + CompanyId: cid, | ||
| 791 | + OrgId: oid, | ||
| 792 | + Pid: parentId, | ||
| 793 | + MaterialGroupName: from.Name, | ||
| 794 | + MaterialGroupNumber: from.Number, | ||
| 795 | + CreatedAt: time.Now(), | ||
| 796 | + UpdatedAt: time.Now(), | ||
| 797 | + Ext: domain.NewExt(org.OrgName), | ||
| 798 | + } | ||
| 799 | + if productMaterialGroup, err = productMaterialGroupRepository.Save(productMaterialGroup); err != nil { | ||
| 800 | + return err | ||
| 801 | + } | ||
| 802 | + mapMaterialGroups[productMaterialGroup.MaterialGroupNumber] = productMaterialGroup | ||
| 803 | + } | ||
| 804 | + return nil | ||
| 805 | +} | ||
| 806 | + | ||
| 807 | +// SyncDataMaterial 同步物料数据 | ||
| 808 | +// pullType 拉取数据方式 full:全量 其他:增量 | ||
| 809 | +func (srv *PullDataK3CloudService) SyncDataMaterial(ptr *pgTransaction.TransactionContext, pullType string, fromTime time.Time) error { | ||
| 810 | + var ( | ||
| 811 | + lastTime = utils.GetZeroTime(time.Now()).Add(-time.Hour * 24) //前一天有修改的记录 | ||
| 812 | + org *domain.Org | ||
| 813 | + err error | ||
| 814 | + ) | ||
| 815 | + if pullType == "full" { | ||
| 816 | + lastTime = time.Time{} | ||
| 817 | + } | ||
| 818 | + | ||
| 819 | + var userService = domainService.NewUserService() | ||
| 820 | + org, err = userService.Organization(constant.MANUFACTURE_DEFAULT_ORGID) | ||
| 821 | + if err != nil { | ||
| 822 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 823 | + } | ||
| 824 | + | ||
| 825 | + var ( | ||
| 826 | + cid = constant.MANUFACTURE_DEFAULT_COMPANYID | ||
| 827 | + oid = constant.MANUFACTURE_DEFAULT_ORGID | ||
| 828 | + productMaterialRepository, _, _ = factory.FastProductMaterial(ptr, 0) | ||
| 829 | + productMaterialGroupRepository, _, _ = factory.FastProductMaterialGroup(ptr, 0) | ||
| 830 | + materialGroups domain.ProductMaterialGroups | ||
| 831 | + ) | ||
| 832 | + | ||
| 833 | + _, materialGroups, err = productMaterialGroupRepository.Find(map[string]interface{}{"companyId": cid}) | ||
| 834 | + if err != nil { | ||
| 835 | + return err | ||
| 836 | + } | ||
| 837 | + mapMaterialGroup := materialGroups.ToMapByGroupNumber() | ||
| 838 | + | ||
| 839 | + records, err := srv.pullMaterial(lastTime) | ||
| 840 | + if err != nil { | ||
| 841 | + return err | ||
| 842 | + } | ||
| 843 | + | ||
| 844 | + mapMaterialCategory, err := srv.PullMaterialCategory() | ||
| 845 | + if err != nil { | ||
| 846 | + return err | ||
| 847 | + } | ||
| 848 | + log.Logger.Debug(fmt.Sprintf("【同步物料数据】查询数据条数:%v", len(records))) | ||
| 849 | + _, materialsFromDb, _ := productMaterialRepository.Find(map[string]interface{}{"companyId": cid, "limit": 20000}) | ||
| 850 | + mapMaterialsFromDb := domain.ProductMaterials(materialsFromDb).ToMapByNumber() | ||
| 851 | + for index, item := range records { | ||
| 852 | + var ( | ||
| 853 | + material *domain.ProductMaterial | ||
| 854 | + materialGroup *domain.ProductMaterialGroup | ||
| 855 | + ok bool | ||
| 856 | + attribute string //物料属性 | ||
| 857 | + category string //物料类别 | ||
| 858 | + ) | ||
| 859 | + if item.UseOrgName != "素天下" { | ||
| 860 | + continue | ||
| 861 | + } | ||
| 862 | + if materialGroup, ok = mapMaterialGroup[item.MaterialGroupNumber]; !ok { | ||
| 863 | + continue | ||
| 864 | + } | ||
| 865 | + if _, ok := mapMaterialsFromDb[item.Number]; ok { | ||
| 866 | + continue | ||
| 867 | + } | ||
| 868 | + if v, ok := mapMaterialCategory[item.FCategoryID]; ok { | ||
| 869 | + category = v | ||
| 870 | + } | ||
| 871 | + attribute = domain.MaterialAttributeDescription(item.ErpClsId) | ||
| 872 | + | ||
| 873 | + material = &domain.ProductMaterial{ | ||
| 874 | + CompanyId: cid, | ||
| 875 | + OrgId: oid, | ||
| 876 | + ProductMaterialGroupId: materialGroup.ProductMaterialGroupId, | ||
| 877 | + MaterialName: item.Name, | ||
| 878 | + MaterialNumber: item.Number, | ||
| 879 | + MaterialAttribute: &domain.MaterialAttribute{Attribute: attribute}, | ||
| 880 | + MaterialCategory: &domain.MaterialCategory{Category: category}, | ||
| 881 | + ProductMaterialExt: &domain.MaterialExt{ | ||
| 882 | + Specification: item.Specification, | ||
| 883 | + Unit: item.BaseUnitName, | ||
| 884 | + ExpiredDay: 0, | ||
| 885 | + Remark: "", | ||
| 886 | + Source: "k3cloud", | ||
| 887 | + }, | ||
| 888 | + CreatedAt: time.Now(), | ||
| 889 | + UpdatedAt: time.Now(), | ||
| 890 | + Ext: domain.NewExt(org.OrgName), | ||
| 891 | + } | ||
| 892 | + if material, err = productMaterialRepository.Save(material); err != nil { | ||
| 893 | + log.Logger.Debug(fmt.Sprintf("同步失败 序号:%v 物料数据 id:%v number:%v name:%v 错误:%v", index, material.ProductMaterialId, material.MaterialNumber, material.MaterialName, err.Error())) | ||
| 894 | + continue | ||
| 895 | + } | ||
| 896 | + log.Logger.Debug(fmt.Sprintf("同步 序号:%v 物料数据 id:%v number:%v name:%v", index, material.ProductMaterialId, material.MaterialNumber, material.MaterialName)) | ||
| 897 | + } | ||
| 898 | + return nil | ||
| 899 | +} |
| @@ -13,10 +13,13 @@ type MaterialUnitConversionDto struct { | @@ -13,10 +13,13 @@ type MaterialUnitConversionDto struct { | ||
| 13 | ToUnitQuantity *domain.UnitQuantity `json:"toUnitQuantity,omitempty"` | 13 | ToUnitQuantity *domain.UnitQuantity `json:"toUnitQuantity,omitempty"` |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | -func (d *MaterialUnitConversionDto) LoadDto(m *domain.UnitConversion) *MaterialUnitConversionDto { | 16 | +func (d *MaterialUnitConversionDto) LoadDto(m *domain.UnitConversion, material *domain.ProductMaterial) *MaterialUnitConversionDto { |
| 17 | d.UnitConversionId = m.UnitConversionId | 17 | d.UnitConversionId = m.UnitConversionId |
| 18 | d.MaterialName = m.Material.MaterialName | 18 | d.MaterialName = m.Material.MaterialName |
| 19 | d.FromUnitQuantity = m.FromUnitQuantity | 19 | d.FromUnitQuantity = m.FromUnitQuantity |
| 20 | d.ToUnitQuantity = m.ToUnitQuantity | 20 | d.ToUnitQuantity = m.ToUnitQuantity |
| 21 | + if material != nil { | ||
| 22 | + d.MaterialName = material.MaterialName | ||
| 23 | + } | ||
| 21 | return d | 24 | return d |
| 22 | } | 25 | } |
| @@ -25,7 +25,7 @@ type UnitConversionDto struct { | @@ -25,7 +25,7 @@ type UnitConversionDto struct { | ||
| 25 | AuthFlag bool `json:"authFlag"` | 25 | AuthFlag bool `json:"authFlag"` |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | -func (d *UnitConversionDto) LoadDto(m *domain.UnitConversion, orgId int) *UnitConversionDto { | 28 | +func (d *UnitConversionDto) LoadDto(m *domain.UnitConversion, orgId int, productMaterial *domain.ProductMaterial) *UnitConversionDto { |
| 29 | d.UnitConversionId = m.UnitConversionId | 29 | d.UnitConversionId = m.UnitConversionId |
| 30 | d.WorkStation = m.WorkStation | 30 | d.WorkStation = m.WorkStation |
| 31 | d.Material = m.Material | 31 | d.Material = m.Material |
| @@ -36,5 +36,8 @@ func (d *UnitConversionDto) LoadDto(m *domain.UnitConversion, orgId int) *UnitCo | @@ -36,5 +36,8 @@ func (d *UnitConversionDto) LoadDto(m *domain.UnitConversion, orgId int) *UnitCo | ||
| 36 | if m.Ext != nil { | 36 | if m.Ext != nil { |
| 37 | d.OrgName = m.Ext.OrgName | 37 | d.OrgName = m.Ext.OrgName |
| 38 | } | 38 | } |
| 39 | + if productMaterial != nil { | ||
| 40 | + d.Material.MaterialName = productMaterial.MaterialName | ||
| 41 | + } | ||
| 39 | return d | 42 | return d |
| 40 | } | 43 | } |
| @@ -91,12 +91,21 @@ func (unitConversionService *UnitConversionService) GetUnitConversion(getUnitCon | @@ -91,12 +91,21 @@ func (unitConversionService *UnitConversionService) GetUnitConversion(getUnitCon | ||
| 91 | //var unitConversionRepository domain.UnitConversionRepository | 91 | //var unitConversionRepository domain.UnitConversionRepository |
| 92 | var unitConversion *domain.UnitConversion | 92 | var unitConversion *domain.UnitConversion |
| 93 | _, unitConversion, err = factory.FastPgUnitConversion(transactionContext, getUnitConversionQuery.UnitConversionId) | 93 | _, unitConversion, err = factory.FastPgUnitConversion(transactionContext, getUnitConversionQuery.UnitConversionId) |
| 94 | - | 94 | + if err != nil { |
| 95 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 96 | + } | ||
| 97 | + var productMaterial *domain.ProductMaterial | ||
| 98 | + if unitConversion.Material.ProductMaterialId > 0 { | ||
| 99 | + _, productMaterial, err = factory.FastProductMaterial(transactionContext, unitConversion.Material.ProductMaterialId) | ||
| 100 | + if err != nil { | ||
| 101 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 102 | + } | ||
| 103 | + } | ||
| 95 | if err := transactionContext.CommitTransaction(); err != nil { | 104 | if err := transactionContext.CommitTransaction(); err != nil { |
| 96 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 105 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 97 | } | 106 | } |
| 98 | result := &dto.UnitConversionDto{} | 107 | result := &dto.UnitConversionDto{} |
| 99 | - result.LoadDto(unitConversion, 0) | 108 | + result.LoadDto(unitConversion, 0, productMaterial) |
| 100 | return result, nil | 109 | return result, nil |
| 101 | 110 | ||
| 102 | } | 111 | } |
| @@ -293,17 +302,29 @@ func (unitConversionService *UnitConversionService) SearchUnitConversion(operate | @@ -293,17 +302,29 @@ func (unitConversionService *UnitConversionService) SearchUnitConversion(operate | ||
| 293 | if err != nil { | 302 | if err != nil { |
| 294 | return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 303 | return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 295 | } | 304 | } |
| 296 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
| 297 | - return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 305 | + |
| 306 | + var mapProductMaterial = make(map[int]*domain.ProductMaterial, 0) | ||
| 307 | + productMaterialIds := domain.UnitConversions(unitConversions).ProductMaterialIds() | ||
| 308 | + if len(productMaterialIds) > 0 { | ||
| 309 | + productMaterialRepository, _, _ := factory.FastProductMaterial(transactionContext, 0) | ||
| 310 | + _, productMaterials, err := productMaterialRepository.Find(map[string]interface{}{"productMaterialIds": productMaterialIds}) | ||
| 311 | + if err != nil { | ||
| 312 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 313 | + } | ||
| 314 | + mapProductMaterial = domain.ProductMaterials(productMaterials).ToMapById() | ||
| 298 | } | 315 | } |
| 299 | 316 | ||
| 300 | var result = make([]*dto.UnitConversionDto, 0) | 317 | var result = make([]*dto.UnitConversionDto, 0) |
| 301 | for i := range unitConversions { | 318 | for i := range unitConversions { |
| 302 | item := unitConversions[i] | 319 | item := unitConversions[i] |
| 303 | newItem := &dto.UnitConversionDto{} | 320 | newItem := &dto.UnitConversionDto{} |
| 304 | - newItem.LoadDto(item, operateInfo.OrgId) | 321 | + newItem.LoadDto(item, operateInfo.OrgId, mapProductMaterial[item.Material.ProductMaterialId]) |
| 305 | result = append(result, newItem) | 322 | result = append(result, newItem) |
| 306 | } | 323 | } |
| 324 | + | ||
| 325 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 326 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 327 | + } | ||
| 307 | return count, result, nil | 328 | return count, result, nil |
| 308 | } | 329 | } |
| 309 | 330 | ||
| @@ -331,11 +352,22 @@ func (unitConversionService *UnitConversionService) SearchMaterial(operateInfo * | @@ -331,11 +352,22 @@ func (unitConversionService *UnitConversionService) SearchMaterial(operateInfo * | ||
| 331 | return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 352 | return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 332 | } | 353 | } |
| 333 | 354 | ||
| 355 | + var mapProductMaterial = make(map[int]*domain.ProductMaterial, 0) | ||
| 356 | + productMaterialIds := domain.UnitConversions(unitConversions).ProductMaterialIds() | ||
| 357 | + if len(productMaterialIds) > 0 { | ||
| 358 | + productMaterialRepository, _, _ := factory.FastProductMaterial(transactionContext, 0) | ||
| 359 | + _, productMaterials, err := productMaterialRepository.Find(map[string]interface{}{"productMaterialIds": productMaterialIds}) | ||
| 360 | + if err != nil { | ||
| 361 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 362 | + } | ||
| 363 | + mapProductMaterial = domain.ProductMaterials(productMaterials).ToMapById() | ||
| 364 | + } | ||
| 365 | + | ||
| 334 | var result = make([]*dto.MaterialUnitConversionDto, 0) | 366 | var result = make([]*dto.MaterialUnitConversionDto, 0) |
| 335 | for i := range unitConversions { | 367 | for i := range unitConversions { |
| 336 | item := unitConversions[i] | 368 | item := unitConversions[i] |
| 337 | newItem := &dto.MaterialUnitConversionDto{} | 369 | newItem := &dto.MaterialUnitConversionDto{} |
| 338 | - newItem.LoadDto(item) | 370 | + newItem.LoadDto(item, mapProductMaterial[item.Material.ProductMaterialId]) |
| 339 | result = append(result, newItem) | 371 | result = append(result, newItem) |
| 340 | } | 372 | } |
| 341 | return count, map[string]interface{}{ | 373 | return count, map[string]interface{}{ |
| @@ -2,6 +2,9 @@ package domain | @@ -2,6 +2,9 @@ package domain | ||
| 2 | 2 | ||
| 3 | // 冗余附加数据 | 3 | // 冗余附加数据 |
| 4 | type Ext struct { | 4 | type Ext struct { |
| 5 | + // 操作人 | ||
| 6 | + Operator *User `json:"operator,omitempty"` | ||
| 7 | + | ||
| 5 | // 组织名称 | 8 | // 组织名称 |
| 6 | OrgName string `json:"orgName,omitempty"` | 9 | OrgName string `json:"orgName,omitempty"` |
| 7 | 10 | ||
| @@ -35,3 +38,8 @@ func (e *Ext) WithProductPlanExt(ext *ProductPlanExt) *Ext { | @@ -35,3 +38,8 @@ func (e *Ext) WithProductPlanExt(ext *ProductPlanExt) *Ext { | ||
| 35 | e.ProductPlanExt = ext | 38 | e.ProductPlanExt = ext |
| 36 | return e | 39 | return e |
| 37 | } | 40 | } |
| 41 | + | ||
| 42 | +func (e *Ext) WithOperator(ext *User) *Ext { | ||
| 43 | + e.Operator = ext | ||
| 44 | + return e | ||
| 45 | +} |
| @@ -2,8 +2,36 @@ package domain | @@ -2,8 +2,36 @@ package domain | ||
| 2 | 2 | ||
| 3 | // 物料 | 3 | // 物料 |
| 4 | type Material struct { | 4 | type Material struct { |
| 5 | - // 物料名称 | 5 | + // 物料ID |
| 6 | + ProductMaterialId int `json:"productMaterialId"` | ||
| 7 | + // 物料名称 (最新数据需要查询物料表) | ||
| 6 | MaterialName string `json:"materialName,omitempty"` | 8 | MaterialName string `json:"materialName,omitempty"` |
| 7 | - // 物料类别 | 9 | + // 物料类别 ‘南瓜饼串’、‘ 包装袋(空)’、‘包装袋(件数)’、装箱(件数) |
| 8 | MaterialCategory string `json:"materialCategory,omitempty"` | 10 | MaterialCategory string `json:"materialCategory,omitempty"` |
| 9 | } | 11 | } |
| 12 | + | ||
| 13 | +// 物料类别 | ||
| 14 | +type MaterialCategory struct { | ||
| 15 | + //Id int `json:"id"` | ||
| 16 | + Category string `json:"category"` | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +// 物料属性 | ||
| 20 | +type MaterialAttribute struct { | ||
| 21 | + //Id int `json:"id"` | ||
| 22 | + Attribute string `json:"attribute"` | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +// 物料扩展数据 | ||
| 26 | +type MaterialExt struct { | ||
| 27 | + // 规格 | ||
| 28 | + Specification string `json:"specification"` | ||
| 29 | + // 单位 | ||
| 30 | + Unit string `json:"unit"` | ||
| 31 | + // 保质期 单位:天 | ||
| 32 | + ExpiredDay int `json:"expiredDay"` | ||
| 33 | + // 备注 | ||
| 34 | + Remark string `json:"remark"` | ||
| 35 | + // 来源 k3cloud | ||
| 36 | + Source string `json:"source"` | ||
| 37 | +} |
| @@ -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 | +} |
pkg/domain/product_material.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 生产物料 | ||
| 6 | +type ProductMaterial struct { | ||
| 7 | + // 物料ID | ||
| 8 | + ProductMaterialId int `json:"productMaterialId"` | ||
| 9 | + // 企业id | ||
| 10 | + CompanyId int `json:"companyId"` | ||
| 11 | + // 组织ID | ||
| 12 | + OrgId int `json:"orgId"` | ||
| 13 | + // 物料分组ID | ||
| 14 | + ProductMaterialGroupId int `json:"productMaterialGroupId"` | ||
| 15 | + // 物料编码 | ||
| 16 | + MaterialNumber string `json:"materialNumber"` | ||
| 17 | + // 物料名称 | ||
| 18 | + MaterialName string `json:"materialName"` | ||
| 19 | + // 物料属性 | ||
| 20 | + MaterialAttribute *MaterialAttribute `json:"materialAttribute"` | ||
| 21 | + // 物料类别 | ||
| 22 | + MaterialCategory *MaterialCategory `json:"materialCategory"` | ||
| 23 | + // 物料扩展 | ||
| 24 | + ProductMaterialExt *MaterialExt `json:"productMaterialExt"` | ||
| 25 | + // 创建时间 | ||
| 26 | + CreatedAt time.Time `json:"createdAt"` | ||
| 27 | + // 更新时间 | ||
| 28 | + UpdatedAt time.Time `json:"updatedAt"` | ||
| 29 | + // 删除时间 | ||
| 30 | + DeletedAt time.Time `json:"deletedAt"` | ||
| 31 | + // 扩展 | ||
| 32 | + Ext *Ext `json:"ext"` | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +type ProductMaterialRepository interface { | ||
| 36 | + Save(productMaterial *ProductMaterial) (*ProductMaterial, error) | ||
| 37 | + Remove(productMaterial *ProductMaterial) (*ProductMaterial, error) | ||
| 38 | + FindOne(queryOptions map[string]interface{}) (*ProductMaterial, error) | ||
| 39 | + Find(queryOptions map[string]interface{}) (int64, []*ProductMaterial, error) | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +func (productMaterial *ProductMaterial) Identify() interface{} { | ||
| 43 | + if productMaterial.ProductMaterialId == 0 { | ||
| 44 | + return nil | ||
| 45 | + } | ||
| 46 | + return productMaterial.ProductMaterialId | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +func (productMaterial *ProductMaterial) Update(data map[string]interface{}) error { | ||
| 50 | + return nil | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +type ProductMaterials []*ProductMaterial | ||
| 54 | + | ||
| 55 | +func (productMaterials ProductMaterials) ToMapById() map[int]*ProductMaterial { | ||
| 56 | + var mapProductMaterial = make(map[int]*ProductMaterial, 0) | ||
| 57 | + for _, v := range productMaterials { | ||
| 58 | + mapProductMaterial[v.ProductMaterialId] = v | ||
| 59 | + } | ||
| 60 | + return mapProductMaterial | ||
| 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 | +} | ||
| 70 | + | ||
| 71 | +// 10:资产,9:配置,2:自制,11:费用,12:模型,5:虚拟,7:一次性,13:产品系列 12:模型,3:委外,4:特征,6:服务,1:外购 | ||
| 72 | +var mapMaterialCategory = map[int]string{ | ||
| 73 | + 1: "外购", | ||
| 74 | + 2: "自制", | ||
| 75 | + 3: "委外", | ||
| 76 | + 4: "特征", | ||
| 77 | + 5: "虚拟", | ||
| 78 | + 6: "服务", | ||
| 79 | + 7: "一次性", | ||
| 80 | + 8: "", | ||
| 81 | + 9: "配置", | ||
| 82 | + 10: "资产", | ||
| 83 | + 11: "费用", | ||
| 84 | + 12: "模型", | ||
| 85 | + 13: "产品系列", | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +func MaterialAttributeDescription(code int) string { | ||
| 89 | + if v, ok := mapMaterialCategory[code]; ok { | ||
| 90 | + return v | ||
| 91 | + } | ||
| 92 | + return "" | ||
| 93 | +} |
pkg/domain/product_material_group.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "strconv" | ||
| 6 | + "time" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +// 物料分组 | ||
| 10 | +type ProductMaterialGroup struct { | ||
| 11 | + // 物料分组ID | ||
| 12 | + ProductMaterialGroupId int `json:"productMaterialGroupId"` | ||
| 13 | + // 企业id | ||
| 14 | + CompanyId int `json:"companyId"` | ||
| 15 | + // 组织ID | ||
| 16 | + OrgId int `json:"orgId"` | ||
| 17 | + // 父级ID | ||
| 18 | + Pid int `json:"pid"` | ||
| 19 | + // 路径 (不使用,如果父级改变的话,子级的Path要做更新) | ||
| 20 | + //Path string `json:"path"` | ||
| 21 | + // 物料分组名称 | ||
| 22 | + MaterialGroupName string `json:"materialGroupName"` | ||
| 23 | + // 物料分组编码 | ||
| 24 | + MaterialGroupNumber string `json:"materialGroupNumber"` | ||
| 25 | + // 创建时间 | ||
| 26 | + CreatedAt time.Time `json:"createdAt"` | ||
| 27 | + // 更新时间 | ||
| 28 | + UpdatedAt time.Time `json:"updatedAt"` | ||
| 29 | + // 删除时间 | ||
| 30 | + DeletedAt time.Time `json:"deletedAt"` | ||
| 31 | + // 扩展数据 | ||
| 32 | + Ext *Ext `json:"ext,omitempty"` | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +type ProductMaterialGroupRepository interface { | ||
| 36 | + Save(productMaterialGroup *ProductMaterialGroup) (*ProductMaterialGroup, error) | ||
| 37 | + Remove(productMaterialGroup *ProductMaterialGroup) (*ProductMaterialGroup, error) | ||
| 38 | + FindOne(queryOptions map[string]interface{}) (*ProductMaterialGroup, error) | ||
| 39 | + Find(queryOptions map[string]interface{}) (int64, []*ProductMaterialGroup, error) | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +func (productMaterialGroup *ProductMaterialGroup) Identify() interface{} { | ||
| 43 | + if productMaterialGroup.ProductMaterialGroupId == 0 { | ||
| 44 | + return nil | ||
| 45 | + } | ||
| 46 | + return productMaterialGroup.ProductMaterialGroupId | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +func (productMaterialGroup *ProductMaterialGroup) Update(data map[string]interface{}) error { | ||
| 50 | + return nil | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +func (productMaterialGroup *ProductMaterialGroup) GroupNumberComposeUp(parent *ProductMaterialGroup, latestNumber string, total int) string { | ||
| 54 | + iNumber, err := strconv.ParseInt(latestNumber, 10, 64) | ||
| 55 | + | ||
| 56 | + if err == nil { | ||
| 57 | + iNumber += 1 | ||
| 58 | + return formatFunc(iNumber) | ||
| 59 | + } | ||
| 60 | + if parent != nil { | ||
| 61 | + return parent.MaterialGroupNumber + formatFunc(int64(total+1)) | ||
| 62 | + } | ||
| 63 | + return formatFunc(int64(total + 1)) | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +func formatFunc(iNumber int64) string { | ||
| 67 | + sNumber := fmt.Sprintf("%d", iNumber) | ||
| 68 | + if len(sNumber)%2 == 1 { | ||
| 69 | + return "0" + sNumber | ||
| 70 | + } | ||
| 71 | + return sNumber | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +/***** 1.实现树 *****/ | ||
| 75 | + | ||
| 76 | +func (productMaterialGroup *ProductMaterialGroup) PID() string { | ||
| 77 | + return fmt.Sprintf("%d", productMaterialGroup.Pid) | ||
| 78 | +} | ||
| 79 | +func (productMaterialGroup *ProductMaterialGroup) ID() string { | ||
| 80 | + return fmt.Sprintf("%d", productMaterialGroup.ProductMaterialGroupId) | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +type ProductMaterialGroups []*ProductMaterialGroup | ||
| 84 | + | ||
| 85 | +func (tree ProductMaterialGroups) Len() int { | ||
| 86 | + return len(tree) | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +func (tree ProductMaterialGroups) Less(i, j int) bool { | ||
| 90 | + if tree[i].Pid < tree[j].Pid { | ||
| 91 | + return true | ||
| 92 | + } | ||
| 93 | + if tree[i].Pid == tree[j].Pid { | ||
| 94 | + return tree[i].ProductMaterialGroupId < tree[j].ProductMaterialGroupId | ||
| 95 | + } | ||
| 96 | + return false | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +func (tree ProductMaterialGroups) Swap(i, j int) { | ||
| 100 | + tree[i], tree[j] = tree[j], tree[i] | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +func (tree ProductMaterialGroups) ToMapByGroupNumber() map[string]*ProductMaterialGroup { | ||
| 104 | + var result = make(map[string]*ProductMaterialGroup) | ||
| 105 | + for i := range tree { | ||
| 106 | + result[tree[i].MaterialGroupNumber] = tree[i] | ||
| 107 | + } | ||
| 108 | + return result | ||
| 109 | +} |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | -import "time" | 3 | +import ( |
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 4 | 7 | ||
| 5 | // 单位换算 | 8 | // 单位换算 |
| 6 | type UnitConversion struct { | 9 | type UnitConversion struct { |
| @@ -57,3 +60,16 @@ func (unitConversion *UnitConversion) Update(data map[string]interface{}) error | @@ -57,3 +60,16 @@ func (unitConversion *UnitConversion) Update(data map[string]interface{}) error | ||
| 57 | unitConversion.UpdatedAt = time.Now() | 60 | unitConversion.UpdatedAt = time.Now() |
| 58 | return nil | 61 | return nil |
| 59 | } | 62 | } |
| 63 | + | ||
| 64 | +type UnitConversions []*UnitConversion | ||
| 65 | + | ||
| 66 | +func (unitConversions UnitConversions) ProductMaterialIds() []int { | ||
| 67 | + set := utils.NewSet() | ||
| 68 | + for i := range unitConversions { | ||
| 69 | + if unitConversions[i].Material.ProductMaterialId == 0 { | ||
| 70 | + continue | ||
| 71 | + } | ||
| 72 | + set.Add(unitConversions[i].Material.ProductMaterialId) | ||
| 73 | + } | ||
| 74 | + return set.KeysInt() | ||
| 75 | +} |
| @@ -25,7 +25,6 @@ func (dao *DeviceDailyRunningRecordDao) TimeSectionRunningRecord(companyId, orgI | @@ -25,7 +25,6 @@ func (dao *DeviceDailyRunningRecordDao) TimeSectionRunningRecord(companyId, orgI | ||
| 25 | 25 | ||
| 26 | tx := dao.transactionContext.PgTx | 26 | tx := dao.transactionContext.PgTx |
| 27 | sql := fmt.Sprintf(` | 27 | sql := fmt.Sprintf(` |
| 28 | - | ||
| 29 | WITH ts_product as( | 28 | WITH ts_product as( |
| 30 | select sum(a.weight) total,a.ts from ( | 29 | select sum(a.weight) total,a.ts from ( |
| 31 | select | 30 | select |
| @@ -38,7 +37,7 @@ WITH ts_product as( | @@ -38,7 +37,7 @@ WITH ts_product as( | ||
| 38 | and work_station->>'workshopId'='?' | 37 | and work_station->>'workshopId'='?' |
| 39 | and work_station->>'lineId'='?' | 38 | and work_station->>'lineId'='?' |
| 40 | and work_station->>'sectionName'=? | 39 | and work_station->>'sectionName'=? |
| 41 | - and created_at >? | 40 | + and created_at >=? |
| 42 | and created_at <? | 41 | and created_at <? |
| 43 | ) a | 42 | ) a |
| 44 | group by a.ts | 43 | group by a.ts |
| @@ -47,14 +46,14 @@ WITH ts_product as( | @@ -47,14 +46,14 @@ WITH ts_product as( | ||
| 47 | -- select * from ts_product | 46 | -- select * from ts_product |
| 48 | , ts_product_list as ( | 47 | , ts_product_list as ( |
| 49 | select d.ts,ts_product.total from ( | 48 | select d.ts,ts_product.total from ( |
| 50 | - select to_char(c.ts::timestamp,'mm-dd') ts from ( | ||
| 51 | - select generate_series(to_timestamp(?),to_timestamp(?),'1 day') ts | 49 | + select to_char(c.ts,'mm-dd') ts from ( |
| 50 | + select generate_series(to_timestamp(?,'YYYY-MM-DD HH24:MI:SS') at time ZONE 'Asia/shanghai',to_timestamp(?,'YYYY-MM-DD HH24:MI:SS') at time ZONE 'Asia/shanghai','1 day') ts | ||
| 52 | ) c ) d left join ts_product on d.ts = ts_product.ts | 51 | ) c ) d left join ts_product on d.ts = ts_product.ts |
| 53 | ) | 52 | ) |
| 54 | SELECT ts, coalesce(total,0) total | 53 | SELECT ts, coalesce(total,0) total |
| 55 | from ts_product_list | 54 | from ts_product_list |
| 56 | `) | 55 | `) |
| 57 | - if _, err := tx.Query(result, sql, companyId, orgId, workshopId, lineId, sectionName, beginTime, endTime, beginTime.Unix(), endTime.Unix()); err != nil { | 56 | + if _, err := tx.Query(result, sql, companyId, orgId, workshopId, lineId, sectionName, beginTime, endTime, beginTime, endTime); err != nil { |
| 58 | return err | 57 | return err |
| 59 | } | 58 | } |
| 60 | return nil | 59 | return nil |
| @@ -120,7 +119,7 @@ select * from device_running_oee | @@ -120,7 +119,7 @@ select * from device_running_oee | ||
| 120 | } | 119 | } |
| 121 | 120 | ||
| 122 | // 时段产能 | 121 | // 时段产能 |
| 123 | -func (dao *DeviceDailyRunningRecordDao) TimeSectionProductRecord(companyId, orgId, workshopId int, lineId int, sectionName string, beginTime time.Time, result interface{}) error { | 122 | +func (dao *DeviceDailyRunningRecordDao) TimeSectionProductRecord(companyId, orgId, workshopId int, lineId int, sectionName string, beginTime time.Time, endTime time.Time, result interface{}) error { |
| 124 | 123 | ||
| 125 | tx := dao.transactionContext.PgTx | 124 | tx := dao.transactionContext.PgTx |
| 126 | sql := fmt.Sprintf(` | 125 | sql := fmt.Sprintf(` |
| @@ -137,7 +136,8 @@ WITH ts_product as( | @@ -137,7 +136,8 @@ WITH ts_product as( | ||
| 137 | and work_station->>'lineId'='?' | 136 | and work_station->>'lineId'='?' |
| 138 | and work_station->>'sectionName'=? | 137 | and work_station->>'sectionName'=? |
| 139 | and device_running_record_info->>'deviceType'='CCJ' | 138 | and device_running_record_info->>'deviceType'='CCJ' |
| 140 | - and created_at >? | 139 | + and created_at >=? |
| 140 | + and created_at < ? | ||
| 141 | ) a | 141 | ) a |
| 142 | group by a.ts | 142 | group by a.ts |
| 143 | order by ts | 143 | order by ts |
| @@ -145,19 +145,15 @@ WITH ts_product as( | @@ -145,19 +145,15 @@ WITH ts_product as( | ||
| 145 | -- select * from ts_product | 145 | -- select * from ts_product |
| 146 | , ts_product_list as ( | 146 | , ts_product_list as ( |
| 147 | select d.ts,ts_product.total from ( | 147 | select d.ts,ts_product.total from ( |
| 148 | - select to_char(c.ts::timestamp,'HH24:MI') ts from ( | ||
| 149 | - select generate_series(a.end - interval '5 hour', | ||
| 150 | - "replace"(to_char(a.end, 'yyyy-mm-dd HH24:') || cast(date_part('minute',a.end) as integer)/30*30+30, ':0', ':00')::timestamp, | ||
| 151 | - '30 minute') ts from ( | ||
| 152 | - select to_timestamp(to_char(now() at time ZONE 'Asia/shanghai','yyyy-mm-dd HH24'),'yyyy-mm-dd HH24') as end | ||
| 153 | - ) a | ||
| 154 | - ) c | 148 | + select "replace"(to_char(created_at at time ZONE 'Asia/shanghai', 'HH24:') || cast(date_part('minute',created_at) as integer)/30*30, ':0', ':00') ts from ( |
| 149 | + select generate_series(to_timestamp(?,'YYYY-MM-DD HH24:MI:SS'),to_timestamp(?,'YYYY-MM-DD HH24:MI:SS'),'30 minute') created_at | ||
| 150 | + ) a | ||
| 155 | ) d left join ts_product on d.ts = ts_product.ts | 151 | ) d left join ts_product on d.ts = ts_product.ts |
| 156 | ) | 152 | ) |
| 157 | SELECT ts, coalesce(total,0) total | 153 | SELECT ts, coalesce(total,0) total |
| 158 | from ts_product_list | 154 | from ts_product_list |
| 159 | `) | 155 | `) |
| 160 | - if _, err := tx.Query(result, sql, companyId, orgId, workshopId, lineId, sectionName, beginTime); err != nil { | 156 | + if _, err := tx.Query(result, sql, companyId, orgId, workshopId, lineId, sectionName, beginTime, endTime, beginTime, endTime.Add(-time.Minute*1)); err != nil { |
| 161 | return err | 157 | return err |
| 162 | } | 158 | } |
| 163 | return nil | 159 | return nil |
| @@ -178,3 +178,13 @@ func (d *MaterialK3cloudDao) GetLastVersion() (int64, error) { | @@ -178,3 +178,13 @@ func (d *MaterialK3cloudDao) GetLastVersion() (int64, error) { | ||
| 178 | } | 178 | } |
| 179 | return materialData[0].DataVersion, nil | 179 | return materialData[0].DataVersion, nil |
| 180 | } | 180 | } |
| 181 | + | ||
| 182 | +func (d *MaterialK3cloudDao) SearchMaterialGroup() ([]*models.MaterialGroupK3cloud, error) { | ||
| 183 | + var materialData []*models.MaterialGroupK3cloud | ||
| 184 | + query := d.transactionContext.PgTx.Model(&materialData) | ||
| 185 | + query.OrderExpr("number asc") | ||
| 186 | + if err := query.Select(); err != nil { | ||
| 187 | + return nil, err | ||
| 188 | + } | ||
| 189 | + return materialData, nil | ||
| 190 | +} |
| @@ -170,3 +170,18 @@ func (d *PrdMoK3cloudDao) GetLatestData(fromTime time.Time) ([]*models.PrdMoK3cl | @@ -170,3 +170,18 @@ func (d *PrdMoK3cloudDao) GetLatestData(fromTime time.Time) ([]*models.PrdMoK3cl | ||
| 170 | } | 170 | } |
| 171 | return result, nil | 171 | return result, nil |
| 172 | } | 172 | } |
| 173 | + | ||
| 174 | +// GetLatestMaterialData 增量获取物料数据 | ||
| 175 | +func (d *PrdMoK3cloudDao) GetLatestMaterialData(fromTime time.Time, offset, limit int) ([]*models.MaterialK3cloud, int, error) { | ||
| 176 | + m := new(models.MaterialK3cloud) | ||
| 177 | + result := make([]*models.MaterialK3cloud, 0) | ||
| 178 | + query := d.transactionContext.PgTx.Model(m) | ||
| 179 | + if !fromTime.IsZero() { | ||
| 180 | + query.Where("modify_date>=?", fromTime) | ||
| 181 | + } | ||
| 182 | + err := query.Select(&result) | ||
| 183 | + if err != nil { | ||
| 184 | + return nil, 0, err | ||
| 185 | + } | ||
| 186 | + return result, len(result), nil | ||
| 187 | +} |
| 1 | +package dao | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +type ProductMaterialGroupDao struct { | ||
| 10 | + transactionContext *pgTransaction.TransactionContext | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +func (dao *ProductMaterialGroupDao) CurrentGroupLatestNumber(companyId int, productMaterialGroupId int) (string, int, error) { | ||
| 14 | + m := new(models.ProductMaterialGroup) | ||
| 15 | + var result string | ||
| 16 | + var total int | ||
| 17 | + query := dao.transactionContext.PgTx.Model(m).Where("company_id = ?", companyId) | ||
| 18 | + query.Where("pid = ?", productMaterialGroupId) | ||
| 19 | + query.ColumnExpr("max(material_group_number) number") | ||
| 20 | + query.ColumnExpr("count(material_group_number) total") | ||
| 21 | + query.AllWithDeleted() | ||
| 22 | + err := query.Select(&result, &total) | ||
| 23 | + return result, total, err | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func NewProductMaterialGroupDao(transactionContext *pgTransaction.TransactionContext) (*ProductMaterialGroupDao, error) { | ||
| 27 | + if transactionContext == nil { | ||
| 28 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 29 | + } else { | ||
| 30 | + return &ProductMaterialGroupDao{ | ||
| 31 | + transactionContext: transactionContext, | ||
| 32 | + }, nil | ||
| 33 | + } | ||
| 34 | +} |
| @@ -3,6 +3,6 @@ package domainService | @@ -3,6 +3,6 @@ package domainService | ||
| 3 | import "testing" | 3 | import "testing" |
| 4 | 4 | ||
| 5 | func TestSectionProductive(t *testing.T) { | 5 | func TestSectionProductive(t *testing.T) { |
| 6 | - svr := NewByteBankService() | ||
| 7 | - svr.SectionProductive() | 6 | + //svr := NewByteBankService() |
| 7 | + //svr.SectionProductive() | ||
| 8 | } | 8 | } |
| @@ -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") |
| @@ -94,11 +94,19 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[ | @@ -94,11 +94,19 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[ | ||
| 94 | } | 94 | } |
| 95 | productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext) | 95 | productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext) |
| 96 | 96 | ||
| 97 | - var response = make([]interface{}, 0) | ||
| 98 | - var tmpXData = make([]string, 0) | 97 | + var ( |
| 98 | + response = make([]interface{}, 0) | ||
| 99 | + tmpXData = make([]string, 0) | ||
| 100 | + beginTime = xtime.BeginningOfDay() //time.Now().Add(-time.Hour*5) | ||
| 101 | + endTime = time.Now() | ||
| 102 | + ) | ||
| 103 | + if !xtime.IsZero(request.Date.Time()) && !request.Date.Time().Equal(beginTime) { | ||
| 104 | + beginTime = request.Date.Time().AddDate(0, 0, -1) | ||
| 105 | + endTime = request.Date.Time() | ||
| 106 | + } | ||
| 99 | for _, v := range workshop.GetProductLines(domain.NotDeleted) { | 107 | for _, v := range workshop.GetProductLines(domain.NotDeleted) { |
| 100 | var result = make([]*record, 0) | 108 | var result = make([]*record, 0) |
| 101 | - if err := productRecordDao.TimeSectionProductRecord(request.CompanyId, request.OrgId, request.WorkshopId, v.LineId, SectionNameCCJ, time.Now().Add(-time.Hour*5), &result); err != nil { | 109 | + if err := productRecordDao.TimeSectionProductRecord(request.CompanyId, request.OrgId, request.WorkshopId, v.LineId, SectionNameCCJ, beginTime, endTime, &result); err != nil { |
| 102 | log.Logger.Error(err.Error()) | 110 | log.Logger.Error(err.Error()) |
| 103 | continue | 111 | continue |
| 104 | } | 112 | } |
| @@ -123,10 +131,10 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[ | @@ -123,10 +131,10 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[ | ||
| 123 | } | 131 | } |
| 124 | 132 | ||
| 125 | type HourProductiveStatisticsRequest struct { | 133 | type HourProductiveStatisticsRequest struct { |
| 126 | - CompanyId int `json:"companyId" valid:"Required"` | ||
| 127 | - OrgId int `json:"orgId" valid:"Required"` | ||
| 128 | - WorkshopId int `json:"workshopId" valid:"Required"` | ||
| 129 | - Date time.Time `json:"date"` | 134 | + CompanyId int `json:"companyId" valid:"Required"` |
| 135 | + OrgId int `json:"orgId" valid:"Required"` | ||
| 136 | + WorkshopId int `json:"workshopId" valid:"Required"` | ||
| 137 | + Date utils.TimeString `json:"date"` | ||
| 130 | } | 138 | } |
| 131 | 139 | ||
| 132 | func NewXYData(xData []string, values interface{}) interface{} { | 140 | func NewXYData(xData []string, values interface{}) interface{} { |
| @@ -141,7 +149,7 @@ func NewXYData(xData []string, values interface{}) interface{} { | @@ -141,7 +149,7 @@ func NewXYData(xData []string, values interface{}) interface{} { | ||
| 141 | return values | 149 | return values |
| 142 | } | 150 | } |
| 143 | 151 | ||
| 144 | -// 时段产能-统计 (传串设备) | 152 | +// DailyProductiveStatistics 每日产能-统计 (传串设备) |
| 145 | func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map[string]interface{}) (interface{}, error) { | 153 | func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map[string]interface{}) (interface{}, error) { |
| 146 | var request = &HourProductiveStatisticsRequest{} | 154 | var request = &HourProductiveStatisticsRequest{} |
| 147 | if err := utils.LoadQueryObject(queryOptions, request); err != nil { | 155 | if err := utils.LoadQueryObject(queryOptions, request); err != nil { |
| @@ -153,9 +161,13 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map | @@ -153,9 +161,13 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map | ||
| 153 | Ts string `json:"ts"` | 161 | Ts string `json:"ts"` |
| 154 | Total float64 `json:"total"` | 162 | Total float64 `json:"total"` |
| 155 | } | 163 | } |
| 156 | - var date = time.Now() | ||
| 157 | - if !xtime.IsZero(request.Date) { | ||
| 158 | - date = request.Date | 164 | + var ( |
| 165 | + beingTime = xtime.BeginningOfDay().AddDate(0, 0, -6) | ||
| 166 | + endTime = xtime.BeginningOfDay().AddDate(0, 0, 1).Add(-time.Second) | ||
| 167 | + ) | ||
| 168 | + if !xtime.IsZero(time.Time(request.Date)) { | ||
| 169 | + beingTime = request.Date.Time().AddDate(0, 0, -6) | ||
| 170 | + endTime = request.Date.Time().AddDate(0, 0, 1).Add(-time.Second) | ||
| 159 | } | 171 | } |
| 160 | workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}) | 172 | workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}) |
| 161 | if err != nil || workshop == nil { | 173 | if err != nil || workshop == nil { |
| @@ -168,7 +180,7 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map | @@ -168,7 +180,7 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map | ||
| 168 | 180 | ||
| 169 | for _, v := range workshop.GetProductLines(domain.NotDeleted) { | 181 | for _, v := range workshop.GetProductLines(domain.NotDeleted) { |
| 170 | var result = make([]*record, 0) | 182 | var result = make([]*record, 0) |
| 171 | - if err := productRecordDao.TimeSectionRunningRecord(request.CompanyId, request.OrgId, request.WorkshopId, v.LineId, SectionNameCCJ, date.Add(-time.Hour*24*7), date, &result); err != nil { | 183 | + if err := productRecordDao.TimeSectionRunningRecord(request.CompanyId, request.OrgId, request.WorkshopId, v.LineId, SectionNameCCJ, beingTime, endTime, &result); err != nil { |
| 172 | log.Logger.Error(err.Error()) | 184 | log.Logger.Error(err.Error()) |
| 173 | continue | 185 | continue |
| 174 | } | 186 | } |
| @@ -213,8 +225,8 @@ func (ptr *PGCommonStatisticsService) ProportionOfSecondLevelStatistics(queryOpt | @@ -213,8 +225,8 @@ func (ptr *PGCommonStatisticsService) ProportionOfSecondLevelStatistics(queryOpt | ||
| 213 | } | 225 | } |
| 214 | productRecordDao, _ := dao.NewProductRecordDao(ptr.transactionContext) | 226 | productRecordDao, _ := dao.NewProductRecordDao(ptr.transactionContext) |
| 215 | var date = time.Now() | 227 | var date = time.Now() |
| 216 | - if !xtime.IsZero(request.Date) { | ||
| 217 | - date = request.Date | 228 | + if !xtime.IsZero(time.Time(request.Date)) { |
| 229 | + date = request.Date.Time() | ||
| 218 | } | 230 | } |
| 219 | var input = []struct { | 231 | var input = []struct { |
| 220 | name string | 232 | name string |
| @@ -262,8 +274,8 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que | @@ -262,8 +274,8 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que | ||
| 262 | } | 274 | } |
| 263 | productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext) | 275 | productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext) |
| 264 | var date = time.Now() | 276 | var date = time.Now() |
| 265 | - if !xtime.IsZero(request.Date) { | ||
| 266 | - date = request.Date | 277 | + if !xtime.IsZero(time.Time(request.Date)) { |
| 278 | + date = time.Time(request.Date) | ||
| 267 | } | 279 | } |
| 268 | var input = []struct { | 280 | var input = []struct { |
| 269 | name string | 281 | name string |
| 1 | +package domainService | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
| 10 | + "sort" | ||
| 11 | + "time" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type PGMaterialService struct { | ||
| 15 | + transactionContext *pgTransaction.TransactionContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +// 物料 | ||
| 19 | + | ||
| 20 | +func (ptr *PGMaterialService) AddMaterial(opt *domain.OperateInfo, item *domain.ProductMaterial) (*domain.ProductMaterial, error) { | ||
| 21 | + var ( | ||
| 22 | + user *domain.User | ||
| 23 | + org *domain.Org | ||
| 24 | + err error | ||
| 25 | + newProductMaterial *domain.ProductMaterial | ||
| 26 | + productMaterialRepository, _ = repository.NewProductMaterialRepository(ptr.transactionContext) | ||
| 27 | + productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) | ||
| 28 | + ) | ||
| 29 | + if user, err = NewUserService().User(opt.UserId); err != nil { | ||
| 30 | + return nil, err | ||
| 31 | + } | ||
| 32 | + if org, err = NewUserService().Organization(opt.OrgId); err != nil { | ||
| 33 | + return nil, err | ||
| 34 | + } | ||
| 35 | + _, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.ProductMaterialGroupId}) | ||
| 36 | + if err != nil { | ||
| 37 | + return nil, err | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + if newProductMaterial, err = productMaterialRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialNumber": item.MaterialNumber}); err == nil || newProductMaterial != nil { | ||
| 41 | + return nil, fmt.Errorf("物料编码已存在") | ||
| 42 | + } | ||
| 43 | + newProductMaterial = &domain.ProductMaterial{ | ||
| 44 | + CompanyId: item.CompanyId, | ||
| 45 | + OrgId: item.OrgId, | ||
| 46 | + ProductMaterialGroupId: item.ProductMaterialGroupId, | ||
| 47 | + MaterialName: item.MaterialName, | ||
| 48 | + MaterialNumber: item.MaterialNumber, | ||
| 49 | + MaterialAttribute: item.MaterialAttribute, | ||
| 50 | + MaterialCategory: item.MaterialCategory, | ||
| 51 | + ProductMaterialExt: item.ProductMaterialExt, | ||
| 52 | + CreatedAt: time.Now(), | ||
| 53 | + UpdatedAt: time.Now(), | ||
| 54 | + Ext: domain.NewExt(org.OrgName).WithOperator(user), | ||
| 55 | + } | ||
| 56 | + return productMaterialRepository.Save(newProductMaterial) | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +// 物料分组 | ||
| 60 | + | ||
| 61 | +func (ptr *PGMaterialService) AddMaterialGroup(opt *domain.OperateInfo, item *domain.ProductMaterialGroup) (*domain.ProductMaterialGroup, error) { | ||
| 62 | + var ( | ||
| 63 | + user *domain.User | ||
| 64 | + org *domain.Org | ||
| 65 | + err error | ||
| 66 | + parent *domain.ProductMaterialGroup | ||
| 67 | + newProductMaterialGroup *domain.ProductMaterialGroup | ||
| 68 | + productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) | ||
| 69 | + | ||
| 70 | + productMaterialGroupDao *dao.ProductMaterialGroupDao | ||
| 71 | + latestNumber string | ||
| 72 | + total int | ||
| 73 | + ) | ||
| 74 | + if user, err = NewUserService().User(opt.UserId); err != nil { | ||
| 75 | + return nil, err | ||
| 76 | + } | ||
| 77 | + if org, err = NewUserService().Organization(opt.OrgId); err != nil { | ||
| 78 | + return nil, err | ||
| 79 | + } | ||
| 80 | + if item.Pid != 0 { | ||
| 81 | + if parent, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.Pid}); err != nil || parent == nil { | ||
| 82 | + return nil, fmt.Errorf("上级物料分组不存在") | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + if newProductMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || newProductMaterialGroup != nil { | ||
| 86 | + return nil, fmt.Errorf("物料分组编码已存在") | ||
| 87 | + } | ||
| 88 | + productMaterialGroupDao, _ = dao.NewProductMaterialGroupDao(ptr.transactionContext) | ||
| 89 | + latestNumber, total, err = productMaterialGroupDao.CurrentGroupLatestNumber(opt.CompanyId, item.Pid) | ||
| 90 | + if err != nil { | ||
| 91 | + return nil, err | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + newProductMaterialGroup = &domain.ProductMaterialGroup{ | ||
| 95 | + CompanyId: opt.CompanyId, | ||
| 96 | + OrgId: opt.OrgId, | ||
| 97 | + Pid: item.Pid, | ||
| 98 | + //Path: item.GetPath(parent), | ||
| 99 | + MaterialGroupName: item.MaterialGroupName, | ||
| 100 | + MaterialGroupNumber: item.MaterialGroupNumber, | ||
| 101 | + CreatedAt: time.Now(), | ||
| 102 | + UpdatedAt: time.Now(), | ||
| 103 | + Ext: domain.NewExt(org.OrgName).WithOperator(user), | ||
| 104 | + } | ||
| 105 | + newProductMaterialGroup.MaterialGroupNumber = newProductMaterialGroup.GroupNumberComposeUp(parent, latestNumber, total) | ||
| 106 | + newProductMaterialGroup, err = productMaterialGroupRepository.Save(newProductMaterialGroup) | ||
| 107 | + return newProductMaterialGroup, err | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +func (ptr *PGMaterialService) UpdateMaterialGroup(opt *domain.OperateInfo, item *domain.ProductMaterialGroup) (*domain.ProductMaterialGroup, error) { | ||
| 111 | + var ( | ||
| 112 | + user *domain.User | ||
| 113 | + org *domain.Org | ||
| 114 | + err error | ||
| 115 | + //parent *domain.ProductMaterialGroup | ||
| 116 | + productMaterialGroup *domain.ProductMaterialGroup | ||
| 117 | + productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) | ||
| 118 | + ) | ||
| 119 | + if user, err = NewUserService().User(opt.UserId); err != nil { | ||
| 120 | + return nil, err | ||
| 121 | + } | ||
| 122 | + if org, err = NewUserService().Organization(opt.OrgId); err != nil { | ||
| 123 | + return nil, err | ||
| 124 | + } | ||
| 125 | + //if item.ProductMaterialGroupId == item.Pid { | ||
| 126 | + // return nil, fmt.Errorf("当前物料分组不能做为自己上级") | ||
| 127 | + //} | ||
| 128 | + if productMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.ProductMaterialGroupId}); err != nil || productMaterialGroup == nil { | ||
| 129 | + return nil, fmt.Errorf("物料分组不存在") | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + //if item.Pid != productMaterialGroup.ProductMaterialGroupId && item.Pid != 0 { | ||
| 133 | + // if parent, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": item.Pid}); err != nil || parent == nil { | ||
| 134 | + // return nil, fmt.Errorf("上级物料分组不存在") | ||
| 135 | + // } | ||
| 136 | + //} | ||
| 137 | + //if productMaterialGroup.MaterialGroupNumber != item.MaterialGroupNumber { | ||
| 138 | + // if group, err := productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "materialGroupNumber": item.MaterialGroupNumber}); err == nil || group != nil { | ||
| 139 | + // return nil, fmt.Errorf("物料分组编码已存在") | ||
| 140 | + // } | ||
| 141 | + //} | ||
| 142 | + //productMaterialGroup.MaterialGroupNumber = item.MaterialGroupNumber | ||
| 143 | + | ||
| 144 | + productMaterialGroup.MaterialGroupName = item.MaterialGroupName | ||
| 145 | + productMaterialGroup.UpdatedAt = item.UpdatedAt | ||
| 146 | + productMaterialGroup.Ext = domain.NewExt(org.OrgName).WithOperator(user) | ||
| 147 | + | ||
| 148 | + productMaterialGroup, err = productMaterialGroupRepository.Save(productMaterialGroup) | ||
| 149 | + return productMaterialGroup, err | ||
| 150 | +} | ||
| 151 | + | ||
| 152 | +func (ptr *PGMaterialService) AllMaterialGroupChild(opt *domain.OperateInfo, productMaterialGroupId int) ([]*domain.ProductMaterialGroup, []int, error) { | ||
| 153 | + var ( | ||
| 154 | + err error | ||
| 155 | + listId []int | ||
| 156 | + productMaterialGroup *domain.ProductMaterialGroup | ||
| 157 | + productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) | ||
| 158 | + groups domain.ProductMaterialGroups | ||
| 159 | + ) | ||
| 160 | + if productMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": productMaterialGroupId}); err != nil || productMaterialGroup == nil { | ||
| 161 | + return nil, listId, fmt.Errorf("物料分组不存在") | ||
| 162 | + } | ||
| 163 | + _, groups, err = productMaterialGroupRepository.Find(map[string]interface{}{"companyId": opt.CompanyId}) //,"orderByProductMaterialGroupId":"asc" | ||
| 164 | + if len(groups) == 0 || err != nil { | ||
| 165 | + return nil, listId, err | ||
| 166 | + } | ||
| 167 | + // 先排序 sort pid,id asc | ||
| 168 | + sort.Stable(groups) | ||
| 169 | + var treeNodes = make([]utils.TreeNode, len(groups)) | ||
| 170 | + for i := 0; i < len(groups); i++ { | ||
| 171 | + treeNodes[i] = groups[i] | ||
| 172 | + } | ||
| 173 | + tree := utils.NewTree(treeNodes) | ||
| 174 | + child := tree.AllChildNode(productMaterialGroup) | ||
| 175 | + var result = make([]*domain.ProductMaterialGroup, 0) | ||
| 176 | + for i := range child { | ||
| 177 | + if v, ok := child[i].(*domain.ProductMaterialGroup); ok { | ||
| 178 | + result = append(result, v) | ||
| 179 | + listId = append(listId, v.ProductMaterialGroupId) | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + return result, listId, err | ||
| 183 | +} | ||
| 184 | + | ||
| 185 | +func (ptr *PGMaterialService) AllMaterialGroupParent(opt *domain.OperateInfo, productMaterialGroupId int) ([]*domain.ProductMaterialGroup, []int, error) { | ||
| 186 | + var ( | ||
| 187 | + err error | ||
| 188 | + listId []int | ||
| 189 | + productMaterialGroup *domain.ProductMaterialGroup | ||
| 190 | + productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) | ||
| 191 | + groups domain.ProductMaterialGroups | ||
| 192 | + ) | ||
| 193 | + if productMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": productMaterialGroupId}); err != nil || productMaterialGroup == nil { | ||
| 194 | + return nil, listId, fmt.Errorf("物料分组不存在") | ||
| 195 | + } | ||
| 196 | + _, groups, err = productMaterialGroupRepository.Find(map[string]interface{}{"companyId": opt.CompanyId}) //,"orderByProductMaterialGroupId":"asc" | ||
| 197 | + if len(groups) == 0 || err != nil { | ||
| 198 | + return nil, listId, err | ||
| 199 | + } | ||
| 200 | + // 先排序 sort pid,id asc | ||
| 201 | + sort.Stable(groups) | ||
| 202 | + var treeNodes = make([]utils.TreeNode, len(groups)) | ||
| 203 | + for i := 0; i < len(groups); i++ { | ||
| 204 | + treeNodes[i] = groups[i] | ||
| 205 | + } | ||
| 206 | + tree := utils.NewTree(treeNodes) | ||
| 207 | + child := tree.TreeNodePaths(productMaterialGroup) | ||
| 208 | + var result = make([]*domain.ProductMaterialGroup, 0) | ||
| 209 | + for i := range child { | ||
| 210 | + if v, ok := child[i].(*domain.ProductMaterialGroup); ok { | ||
| 211 | + result = append(result, v) | ||
| 212 | + listId = append(listId, v.ProductMaterialGroupId) | ||
| 213 | + } | ||
| 214 | + } | ||
| 215 | + return result, listId, err | ||
| 216 | +} | ||
| 217 | + | ||
| 218 | +func (ptr *PGMaterialService) AllMaterialGroupParentByBacktracking(opt *domain.OperateInfo, productMaterialGroupId int) ([]*domain.ProductMaterialGroup, []int, error) { | ||
| 219 | + var ( | ||
| 220 | + err error | ||
| 221 | + listId []int | ||
| 222 | + productMaterialGroup *domain.ProductMaterialGroup | ||
| 223 | + productMaterialGroupRepository, _ = repository.NewProductMaterialGroupRepository(ptr.transactionContext) | ||
| 224 | + pid = productMaterialGroupId | ||
| 225 | + mapExists = make(map[int]int) | ||
| 226 | + ) | ||
| 227 | + var result = make([]*domain.ProductMaterialGroup, 0) | ||
| 228 | + for { | ||
| 229 | + if pid == 0 { | ||
| 230 | + break | ||
| 231 | + } | ||
| 232 | + if _, exists := mapExists[pid]; exists { | ||
| 233 | + break | ||
| 234 | + } | ||
| 235 | + mapExists[pid] = pid | ||
| 236 | + productMaterialGroup, err = productMaterialGroupRepository.FindOne(map[string]interface{}{"companyId": opt.CompanyId, "productMaterialGroupId": pid, "allWithDeleted": "1"}) | ||
| 237 | + if err != nil || productMaterialGroup == nil { | ||
| 238 | + return nil, listId, fmt.Errorf("物料分组不存在") | ||
| 239 | + } | ||
| 240 | + pid = productMaterialGroup.Pid | ||
| 241 | + result = append([]*domain.ProductMaterialGroup{productMaterialGroup}, result...) | ||
| 242 | + } | ||
| 243 | + return result, listId, err | ||
| 244 | +} | ||
| 245 | + | ||
| 246 | +func NewPGMaterialService(transactionContext *pgTransaction.TransactionContext) (*PGMaterialService, error) { | ||
| 247 | + if transactionContext == nil { | ||
| 248 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 249 | + } else { | ||
| 250 | + return &PGMaterialService{ | ||
| 251 | + transactionContext: transactionContext, | ||
| 252 | + }, nil | ||
| 253 | + } | ||
| 254 | +} |
| @@ -67,7 +67,7 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | @@ -67,7 +67,7 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | ||
| 67 | productCalendar, _ = productCalendarRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "workStationId": workStation.WorkStationId}) | 67 | productCalendar, _ = productCalendarRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "workStationId": workStation.WorkStationId}) |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | - beginTime := report.ActionTime.Add(-time.Hour * 13) | 70 | + beginTime := report.ActionTime.Add(-time.Hour * 16) |
| 71 | endTime := report.ActionTime | 71 | endTime := report.ActionTime |
| 72 | _, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, "", beginTime, endTime) | 72 | _, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, "", beginTime, endTime) |
| 73 | for i := 0; i < len(records); i++ { | 73 | for i := 0; i < len(records); i++ { |
| @@ -48,6 +48,8 @@ func init() { | @@ -48,6 +48,8 @@ func init() { | ||
| 48 | (*models.DeviceDailyRunningRecord)(nil), | 48 | (*models.DeviceDailyRunningRecord)(nil), |
| 49 | (*models.DeviceRunningRecord)(nil), | 49 | (*models.DeviceRunningRecord)(nil), |
| 50 | (*models.WorkshopPlanCompletionRecord)(nil), | 50 | (*models.WorkshopPlanCompletionRecord)(nil), |
| 51 | + (*models.ProductMaterialGroup)(nil), | ||
| 52 | + (*models.ProductMaterial)(nil), | ||
| 51 | } { | 53 | } { |
| 52 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ | 54 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ |
| 53 | Temp: false, | 55 | Temp: false, |
| @@ -9,3 +9,13 @@ type MaterialGroupK3cloud struct { | @@ -9,3 +9,13 @@ type MaterialGroupK3cloud struct { | ||
| 9 | ParentId int `comment:"父级id" pg:"parent_id"` | 9 | ParentId int `comment:"父级id" pg:"parent_id"` |
| 10 | DataVersion int64 `comment:"数据版本" pg:"data_version"` | 10 | DataVersion int64 `comment:"数据版本" pg:"data_version"` |
| 11 | } | 11 | } |
| 12 | + | ||
| 13 | +type MaterialGroupK3clouds []*MaterialGroupK3cloud | ||
| 14 | + | ||
| 15 | +func (materialGroupK3clouds MaterialGroupK3clouds) ToMapId() map[int]*MaterialGroupK3cloud { | ||
| 16 | + var result = make(map[int]*MaterialGroupK3cloud) | ||
| 17 | + for i := range materialGroupK3clouds { | ||
| 18 | + result[materialGroupK3clouds[i].Id] = materialGroupK3clouds[i] | ||
| 19 | + } | ||
| 20 | + return result | ||
| 21 | +} |
| @@ -25,6 +25,7 @@ type MaterialK3cloud struct { | @@ -25,6 +25,7 @@ type MaterialK3cloud struct { | ||
| 25 | UseOrgName string `comment:"使用组织" pg:"use_org_name"` | 25 | UseOrgName string `comment:"使用组织" pg:"use_org_name"` |
| 26 | JoinProductId int64 `comment:"关联的product表id" pg:"join_product_id"` | 26 | JoinProductId int64 `comment:"关联的product表id" pg:"join_product_id"` |
| 27 | DataVersion int64 `comment:"数据版本" pg:"data_version"` | 27 | DataVersion int64 `comment:"数据版本" pg:"data_version"` |
| 28 | + FCategoryID string `pg:"-"` | ||
| 28 | } | 29 | } |
| 29 | 30 | ||
| 30 | //批量处理sql脚本样例 | 31 | //批量处理sql脚本样例 |
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type ProductMaterial struct { | ||
| 9 | + tableName string `comment:"生产物料" pg:"manufacture.product_material"` | ||
| 10 | + // 物料ID | ||
| 11 | + ProductMaterialId int `comment:"物料ID" pg:"pk:product_material_id"` | ||
| 12 | + // 企业id | ||
| 13 | + CompanyId int `comment:"企业id"` | ||
| 14 | + // 组织ID | ||
| 15 | + OrgId int `comment:"组织ID"` | ||
| 16 | + // 物料分组ID | ||
| 17 | + ProductMaterialGroupId int `comment:"物料分组ID"` | ||
| 18 | + // 物料编码 | ||
| 19 | + MaterialNumber string `comment:"物料编码"` | ||
| 20 | + // 物料名称 | ||
| 21 | + MaterialName string `comment:"物料名称"` | ||
| 22 | + // 物料属性 | ||
| 23 | + MaterialAttribute *domain.MaterialAttribute `comment:"物料属性"` | ||
| 24 | + // 物料类别 | ||
| 25 | + MaterialCategory *domain.MaterialCategory `comment:"物料类别"` | ||
| 26 | + // 物料扩展 | ||
| 27 | + ProductMaterialExt *domain.MaterialExt `comment:"物料扩展"` | ||
| 28 | + // 创建时间 | ||
| 29 | + CreatedAt time.Time `comment:"创建时间"` | ||
| 30 | + // 更新时间 | ||
| 31 | + UpdatedAt time.Time `comment:"更新时间"` | ||
| 32 | + // 删除时间 | ||
| 33 | + DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` | ||
| 34 | + // 扩展 | ||
| 35 | + Ext *domain.Ext `comment:"扩展"` | ||
| 36 | +} |
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type ProductMaterialGroup struct { | ||
| 9 | + tableName string `comment:"物料分组" pg:"manufacture.product_material_group"` | ||
| 10 | + // 物料分组ID | ||
| 11 | + ProductMaterialGroupId int `comment:"物料分组ID" pg:"pk:product_material_group_id"` | ||
| 12 | + // 企业id | ||
| 13 | + CompanyId int `comment:"企业id"` | ||
| 14 | + // 组织ID | ||
| 15 | + OrgId int `comment:"组织ID"` | ||
| 16 | + // 父级ID | ||
| 17 | + Pid int `comment:"父级ID"` | ||
| 18 | + // 路径 | ||
| 19 | + // Path string `comment:"路径"` | ||
| 20 | + // 物料分组名称 | ||
| 21 | + MaterialGroupName string `comment:"物料分组名称"` | ||
| 22 | + // 物料分组编码 | ||
| 23 | + MaterialGroupNumber string `comment:"物料分组编码"` | ||
| 24 | + // 创建时间 | ||
| 25 | + CreatedAt time.Time `comment:"创建时间"` | ||
| 26 | + // 更新时间 | ||
| 27 | + UpdatedAt time.Time `comment:"更新时间"` | ||
| 28 | + // 删除时间 | ||
| 29 | + DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` | ||
| 30 | + // 扩展 | ||
| 31 | + Ext *domain.Ext `comment:"扩展"` | ||
| 32 | +} |
| 1 | +package transform | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func TransformToProductMaterialDomainModelFromPgModels(productMaterialModel *models.ProductMaterial) (*domain.ProductMaterial, error) { | ||
| 9 | + return &domain.ProductMaterial{ | ||
| 10 | + ProductMaterialId: productMaterialModel.ProductMaterialId, | ||
| 11 | + CompanyId: productMaterialModel.CompanyId, | ||
| 12 | + OrgId: productMaterialModel.OrgId, | ||
| 13 | + ProductMaterialGroupId: productMaterialModel.ProductMaterialGroupId, | ||
| 14 | + MaterialNumber: productMaterialModel.MaterialNumber, | ||
| 15 | + MaterialName: productMaterialModel.MaterialName, | ||
| 16 | + MaterialAttribute: productMaterialModel.MaterialAttribute, | ||
| 17 | + MaterialCategory: productMaterialModel.MaterialCategory, | ||
| 18 | + ProductMaterialExt: productMaterialModel.ProductMaterialExt, | ||
| 19 | + CreatedAt: productMaterialModel.CreatedAt, | ||
| 20 | + UpdatedAt: productMaterialModel.UpdatedAt, | ||
| 21 | + DeletedAt: productMaterialModel.DeletedAt, | ||
| 22 | + Ext: productMaterialModel.Ext, | ||
| 23 | + }, nil | ||
| 24 | +} |
| 1 | +package transform | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func TransformToProductMaterialGroupDomainModelFromPgModels(productMaterialGroupModel *models.ProductMaterialGroup) (*domain.ProductMaterialGroup, error) { | ||
| 9 | + return &domain.ProductMaterialGroup{ | ||
| 10 | + ProductMaterialGroupId: productMaterialGroupModel.ProductMaterialGroupId, | ||
| 11 | + CompanyId: productMaterialGroupModel.CompanyId, | ||
| 12 | + OrgId: productMaterialGroupModel.OrgId, | ||
| 13 | + Pid: productMaterialGroupModel.Pid, | ||
| 14 | + //Path: productMaterialGroupModel.Path, | ||
| 15 | + MaterialGroupName: productMaterialGroupModel.MaterialGroupName, | ||
| 16 | + MaterialGroupNumber: productMaterialGroupModel.MaterialGroupNumber, | ||
| 17 | + CreatedAt: productMaterialGroupModel.CreatedAt, | ||
| 18 | + UpdatedAt: productMaterialGroupModel.UpdatedAt, | ||
| 19 | + DeletedAt: productMaterialGroupModel.DeletedAt, | ||
| 20 | + Ext: productMaterialGroupModel.Ext, | ||
| 21 | + }, nil | ||
| 22 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/go-pg/pg/v10" | ||
| 6 | + | ||
| 7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
| 8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type ProductMaterialGroupRepository struct { | ||
| 16 | + transactionContext *pgTransaction.TransactionContext | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (repository *ProductMaterialGroupRepository) nextIdentify() (int64, error) { | ||
| 20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
| 21 | + if err != nil { | ||
| 22 | + return 0, err | ||
| 23 | + } | ||
| 24 | + id, err := IdWorker.NextId() | ||
| 25 | + return id, err | ||
| 26 | +} | ||
| 27 | +func (repository *ProductMaterialGroupRepository) Save(productMaterialGroup *domain.ProductMaterialGroup) (*domain.ProductMaterialGroup, error) { | ||
| 28 | + sqlBuildFields := []string{ | ||
| 29 | + "product_material_group_id", | ||
| 30 | + "company_id", | ||
| 31 | + "org_id", | ||
| 32 | + "pid", | ||
| 33 | + //"path", | ||
| 34 | + "material_group_name", | ||
| 35 | + "material_group_number", | ||
| 36 | + "created_at", | ||
| 37 | + "updated_at", | ||
| 38 | + "deleted_at", | ||
| 39 | + "ext", | ||
| 40 | + } | ||
| 41 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_material_group_id", "deleted_at")) | ||
| 42 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_material_group_id", "deleted_at")) | ||
| 43 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 44 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_material_group_id", "deleted_at") | ||
| 45 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
| 46 | + tx := repository.transactionContext.PgTx | ||
| 47 | + if productMaterialGroup.Identify() == nil { | ||
| 48 | + if _, err := tx.QueryOne( | ||
| 49 | + pg.Scan( | ||
| 50 | + &productMaterialGroup.ProductMaterialGroupId, | ||
| 51 | + &productMaterialGroup.CompanyId, | ||
| 52 | + &productMaterialGroup.OrgId, | ||
| 53 | + &productMaterialGroup.Pid, | ||
| 54 | + //&productMaterialGroup.Path, | ||
| 55 | + &productMaterialGroup.MaterialGroupName, | ||
| 56 | + &productMaterialGroup.MaterialGroupNumber, | ||
| 57 | + &productMaterialGroup.CreatedAt, | ||
| 58 | + &productMaterialGroup.UpdatedAt, | ||
| 59 | + &productMaterialGroup.DeletedAt, | ||
| 60 | + &productMaterialGroup.Ext, | ||
| 61 | + ), | ||
| 62 | + fmt.Sprintf("INSERT INTO manufacture.product_material_group (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
| 63 | + productMaterialGroup.CompanyId, | ||
| 64 | + productMaterialGroup.OrgId, | ||
| 65 | + productMaterialGroup.Pid, | ||
| 66 | + //productMaterialGroup.Path, | ||
| 67 | + productMaterialGroup.MaterialGroupName, | ||
| 68 | + productMaterialGroup.MaterialGroupNumber, | ||
| 69 | + productMaterialGroup.CreatedAt, | ||
| 70 | + productMaterialGroup.UpdatedAt, | ||
| 71 | + productMaterialGroup.Ext, | ||
| 72 | + ); err != nil { | ||
| 73 | + return productMaterialGroup, err | ||
| 74 | + } | ||
| 75 | + } else { | ||
| 76 | + if _, err := tx.QueryOne( | ||
| 77 | + pg.Scan( | ||
| 78 | + &productMaterialGroup.ProductMaterialGroupId, | ||
| 79 | + &productMaterialGroup.CompanyId, | ||
| 80 | + &productMaterialGroup.OrgId, | ||
| 81 | + &productMaterialGroup.Pid, | ||
| 82 | + //&productMaterialGroup.Path, | ||
| 83 | + &productMaterialGroup.MaterialGroupName, | ||
| 84 | + &productMaterialGroup.MaterialGroupNumber, | ||
| 85 | + &productMaterialGroup.CreatedAt, | ||
| 86 | + &productMaterialGroup.UpdatedAt, | ||
| 87 | + &productMaterialGroup.DeletedAt, | ||
| 88 | + &productMaterialGroup.Ext, | ||
| 89 | + ), | ||
| 90 | + fmt.Sprintf("UPDATE manufacture.product_material_group SET %s WHERE product_material_group_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
| 91 | + productMaterialGroup.CompanyId, | ||
| 92 | + productMaterialGroup.OrgId, | ||
| 93 | + productMaterialGroup.Pid, | ||
| 94 | + //productMaterialGroup.Path, | ||
| 95 | + productMaterialGroup.MaterialGroupName, | ||
| 96 | + productMaterialGroup.MaterialGroupNumber, | ||
| 97 | + productMaterialGroup.CreatedAt, | ||
| 98 | + productMaterialGroup.UpdatedAt, | ||
| 99 | + productMaterialGroup.Ext, | ||
| 100 | + productMaterialGroup.Identify(), | ||
| 101 | + ); err != nil { | ||
| 102 | + return productMaterialGroup, err | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + return productMaterialGroup, nil | ||
| 106 | +} | ||
| 107 | +func (repository *ProductMaterialGroupRepository) Remove(productMaterialGroup *domain.ProductMaterialGroup) (*domain.ProductMaterialGroup, error) { | ||
| 108 | + tx := repository.transactionContext.PgTx | ||
| 109 | + productMaterialGroupModel := new(models.ProductMaterialGroup) | ||
| 110 | + productMaterialGroupModel.ProductMaterialGroupId = productMaterialGroup.Identify().(int) | ||
| 111 | + if _, err := tx.Model(productMaterialGroupModel).WherePK().Delete(); err != nil { | ||
| 112 | + return productMaterialGroup, err | ||
| 113 | + } | ||
| 114 | + return productMaterialGroup, nil | ||
| 115 | +} | ||
| 116 | +func (repository *ProductMaterialGroupRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProductMaterialGroup, error) { | ||
| 117 | + tx := repository.transactionContext.PgTx | ||
| 118 | + productMaterialGroupModel := new(models.ProductMaterialGroup) | ||
| 119 | + query := sqlbuilder.BuildQuery(tx.Model(productMaterialGroupModel), queryOptions) | ||
| 120 | + query.SetWhereByQueryOption("product_material_group_id = ?", "productMaterialGroupId") | ||
| 121 | + query.SetWhereByQueryOption("company_id = ?", "companyId") | ||
| 122 | + query.SetWhereByQueryOption("material_group_number = ?", "materialGroupNumber") | ||
| 123 | + if _, ok := queryOptions["allWithDeleted"]; ok { | ||
| 124 | + query.AllWithDeleted() | ||
| 125 | + } | ||
| 126 | + if err := query.First(); err != nil { | ||
| 127 | + if err.Error() == "pg: no rows in result set" { | ||
| 128 | + return nil, domain.ErrorNotFound | ||
| 129 | + } else { | ||
| 130 | + return nil, err | ||
| 131 | + } | ||
| 132 | + } | ||
| 133 | + if productMaterialGroupModel.ProductMaterialGroupId == 0 { | ||
| 134 | + return nil, nil | ||
| 135 | + } else { | ||
| 136 | + return transform.TransformToProductMaterialGroupDomainModelFromPgModels(productMaterialGroupModel) | ||
| 137 | + } | ||
| 138 | +} | ||
| 139 | +func (repository *ProductMaterialGroupRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProductMaterialGroup, error) { | ||
| 140 | + tx := repository.transactionContext.PgTx | ||
| 141 | + var productMaterialGroupModels []*models.ProductMaterialGroup | ||
| 142 | + productMaterialGroups := make([]*domain.ProductMaterialGroup, 0) | ||
| 143 | + query := sqlbuilder.BuildQuery(tx.Model(&productMaterialGroupModels), queryOptions) | ||
| 144 | + query.SetOffsetAndLimit(domain.MaxQueryRow) | ||
| 145 | + query.SetWhereByQueryOption("company_id = ?", "companyId") | ||
| 146 | + if v, ok := queryOptions["orderByProductMaterialGroupId"]; ok { | ||
| 147 | + query.SetOrderDirect("product_material_group_id", v.(string)) | ||
| 148 | + } else { | ||
| 149 | + query.SetOrderDirect("product_material_group_id", "DESC") | ||
| 150 | + } | ||
| 151 | + if count, err := query.SelectAndCount(); err != nil { | ||
| 152 | + return 0, productMaterialGroups, err | ||
| 153 | + } else { | ||
| 154 | + for _, productMaterialGroupModel := range productMaterialGroupModels { | ||
| 155 | + if productMaterialGroup, err := transform.TransformToProductMaterialGroupDomainModelFromPgModels(productMaterialGroupModel); err != nil { | ||
| 156 | + return 0, productMaterialGroups, err | ||
| 157 | + } else { | ||
| 158 | + productMaterialGroups = append(productMaterialGroups, productMaterialGroup) | ||
| 159 | + } | ||
| 160 | + } | ||
| 161 | + return int64(count), productMaterialGroups, nil | ||
| 162 | + } | ||
| 163 | +} | ||
| 164 | +func NewProductMaterialGroupRepository(transactionContext *pgTransaction.TransactionContext) (*ProductMaterialGroupRepository, error) { | ||
| 165 | + if transactionContext == nil { | ||
| 166 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 167 | + } else { | ||
| 168 | + return &ProductMaterialGroupRepository{ | ||
| 169 | + transactionContext: transactionContext, | ||
| 170 | + }, nil | ||
| 171 | + } | ||
| 172 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/go-pg/pg/v10" | ||
| 6 | + | ||
| 7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
| 8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type ProductMaterialRepository struct { | ||
| 16 | + transactionContext *pgTransaction.TransactionContext | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (repository *ProductMaterialRepository) nextIdentify() (int64, error) { | ||
| 20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
| 21 | + if err != nil { | ||
| 22 | + return 0, err | ||
| 23 | + } | ||
| 24 | + id, err := IdWorker.NextId() | ||
| 25 | + return id, err | ||
| 26 | +} | ||
| 27 | +func (repository *ProductMaterialRepository) Save(productMaterial *domain.ProductMaterial) (*domain.ProductMaterial, error) { | ||
| 28 | + sqlBuildFields := []string{ | ||
| 29 | + "product_material_id", | ||
| 30 | + "company_id", | ||
| 31 | + "org_id", | ||
| 32 | + "product_material_group_id", | ||
| 33 | + "material_number", | ||
| 34 | + "material_name", | ||
| 35 | + "material_attribute", | ||
| 36 | + "material_category", | ||
| 37 | + "product_material_ext", | ||
| 38 | + "created_at", | ||
| 39 | + "updated_at", | ||
| 40 | + "deleted_at", | ||
| 41 | + "ext", | ||
| 42 | + } | ||
| 43 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_material_id", "deleted_at")) | ||
| 44 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_material_id", "deleted_at")) | ||
| 45 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 46 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_material_id", "deleted_at") | ||
| 47 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
| 48 | + tx := repository.transactionContext.PgTx | ||
| 49 | + if productMaterial.Identify() == nil { | ||
| 50 | + if _, err := tx.QueryOne( | ||
| 51 | + pg.Scan( | ||
| 52 | + &productMaterial.ProductMaterialId, | ||
| 53 | + &productMaterial.CompanyId, | ||
| 54 | + &productMaterial.OrgId, | ||
| 55 | + &productMaterial.ProductMaterialGroupId, | ||
| 56 | + &productMaterial.MaterialNumber, | ||
| 57 | + &productMaterial.MaterialName, | ||
| 58 | + &productMaterial.MaterialAttribute, | ||
| 59 | + &productMaterial.MaterialCategory, | ||
| 60 | + &productMaterial.ProductMaterialExt, | ||
| 61 | + &productMaterial.CreatedAt, | ||
| 62 | + &productMaterial.UpdatedAt, | ||
| 63 | + &productMaterial.DeletedAt, | ||
| 64 | + &productMaterial.Ext, | ||
| 65 | + ), | ||
| 66 | + fmt.Sprintf("INSERT INTO manufacture.product_material (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
| 67 | + productMaterial.CompanyId, | ||
| 68 | + productMaterial.OrgId, | ||
| 69 | + productMaterial.ProductMaterialGroupId, | ||
| 70 | + productMaterial.MaterialNumber, | ||
| 71 | + productMaterial.MaterialName, | ||
| 72 | + productMaterial.MaterialAttribute, | ||
| 73 | + productMaterial.MaterialCategory, | ||
| 74 | + productMaterial.ProductMaterialExt, | ||
| 75 | + productMaterial.CreatedAt, | ||
| 76 | + productMaterial.UpdatedAt, | ||
| 77 | + productMaterial.Ext, | ||
| 78 | + ); err != nil { | ||
| 79 | + return productMaterial, err | ||
| 80 | + } | ||
| 81 | + } else { | ||
| 82 | + if _, err := tx.QueryOne( | ||
| 83 | + pg.Scan( | ||
| 84 | + &productMaterial.ProductMaterialId, | ||
| 85 | + &productMaterial.CompanyId, | ||
| 86 | + &productMaterial.OrgId, | ||
| 87 | + &productMaterial.ProductMaterialGroupId, | ||
| 88 | + &productMaterial.MaterialNumber, | ||
| 89 | + &productMaterial.MaterialName, | ||
| 90 | + &productMaterial.MaterialAttribute, | ||
| 91 | + &productMaterial.MaterialCategory, | ||
| 92 | + &productMaterial.ProductMaterialExt, | ||
| 93 | + &productMaterial.CreatedAt, | ||
| 94 | + &productMaterial.UpdatedAt, | ||
| 95 | + &productMaterial.DeletedAt, | ||
| 96 | + &productMaterial.Ext, | ||
| 97 | + ), | ||
| 98 | + fmt.Sprintf("UPDATE manufacture.product_material SET %s WHERE product_material_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
| 99 | + productMaterial.CompanyId, | ||
| 100 | + productMaterial.OrgId, | ||
| 101 | + productMaterial.ProductMaterialGroupId, | ||
| 102 | + productMaterial.MaterialNumber, | ||
| 103 | + productMaterial.MaterialName, | ||
| 104 | + productMaterial.MaterialAttribute, | ||
| 105 | + productMaterial.MaterialCategory, | ||
| 106 | + productMaterial.ProductMaterialExt, | ||
| 107 | + productMaterial.CreatedAt, | ||
| 108 | + productMaterial.UpdatedAt, | ||
| 109 | + productMaterial.Ext, | ||
| 110 | + productMaterial.Identify(), | ||
| 111 | + ); err != nil { | ||
| 112 | + return productMaterial, err | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + return productMaterial, nil | ||
| 116 | +} | ||
| 117 | +func (repository *ProductMaterialRepository) Remove(productMaterial *domain.ProductMaterial) (*domain.ProductMaterial, error) { | ||
| 118 | + tx := repository.transactionContext.PgTx | ||
| 119 | + productMaterialModel := new(models.ProductMaterial) | ||
| 120 | + productMaterialModel.ProductMaterialId = productMaterial.Identify().(int) | ||
| 121 | + if _, err := tx.Model(productMaterialModel).WherePK().Delete(); err != nil { | ||
| 122 | + return productMaterial, err | ||
| 123 | + } | ||
| 124 | + return productMaterial, nil | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +// query compose | ||
| 128 | +// 1. company_id,material_number | ||
| 129 | + | ||
| 130 | +func (repository *ProductMaterialRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProductMaterial, error) { | ||
| 131 | + tx := repository.transactionContext.PgTx | ||
| 132 | + productMaterialModel := new(models.ProductMaterial) | ||
| 133 | + query := sqlbuilder.BuildQuery(tx.Model(productMaterialModel), queryOptions) | ||
| 134 | + query.SetWhereByQueryOption("product_material.product_material_id = ?", "productMaterialId") | ||
| 135 | + | ||
| 136 | + query.SetWhereByQueryOption("product_material.company_id = ?", "companyId") | ||
| 137 | + query.SetWhereByQueryOption("product_material.material_number = ?", "materialNumber") | ||
| 138 | + if err := query.First(); err != nil { | ||
| 139 | + if err.Error() == "pg: no rows in result set" { | ||
| 140 | + return nil, domain.ErrorNotFound | ||
| 141 | + } else { | ||
| 142 | + return nil, err | ||
| 143 | + } | ||
| 144 | + } | ||
| 145 | + if productMaterialModel.ProductMaterialId == 0 { | ||
| 146 | + return nil, nil | ||
| 147 | + } else { | ||
| 148 | + return transform.TransformToProductMaterialDomainModelFromPgModels(productMaterialModel) | ||
| 149 | + } | ||
| 150 | +} | ||
| 151 | +func (repository *ProductMaterialRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProductMaterial, error) { | ||
| 152 | + tx := repository.transactionContext.PgTx | ||
| 153 | + var productMaterialModels []*models.ProductMaterial | ||
| 154 | + productMaterials := make([]*domain.ProductMaterial, 0) | ||
| 155 | + query := sqlbuilder.BuildQuery(tx.Model(&productMaterialModels), queryOptions) | ||
| 156 | + query.SetWhereByQueryOption("company_id = ?", "companyId") | ||
| 157 | + if v, ok := queryOptions["productMaterialIds"]; ok && len(v.([]int)) > 0 { | ||
| 158 | + query.Where("product_material_id in (?)", pg.In(v)) | ||
| 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 | + } | ||
| 169 | + if v, ok := queryOptions["materialNumbers"]; ok && len(v.([]string)) > 0 { | ||
| 170 | + query.Where("material_number in (?)", pg.In(v)) | ||
| 171 | + } | ||
| 172 | + query.SetOffsetAndLimit(domain.MaxQueryRow) | ||
| 173 | + query.SetOrderDirect("product_material_id", "DESC") | ||
| 174 | + if count, err := query.SelectAndCount(); err != nil { | ||
| 175 | + return 0, productMaterials, err | ||
| 176 | + } else { | ||
| 177 | + for _, productMaterialModel := range productMaterialModels { | ||
| 178 | + if productMaterial, err := transform.TransformToProductMaterialDomainModelFromPgModels(productMaterialModel); err != nil { | ||
| 179 | + return 0, productMaterials, err | ||
| 180 | + } else { | ||
| 181 | + productMaterials = append(productMaterials, productMaterial) | ||
| 182 | + } | ||
| 183 | + } | ||
| 184 | + return int64(count), productMaterials, nil | ||
| 185 | + } | ||
| 186 | +} | ||
| 187 | +func NewProductMaterialRepository(transactionContext *pgTransaction.TransactionContext) (*ProductMaterialRepository, error) { | ||
| 188 | + if transactionContext == nil { | ||
| 189 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 190 | + } else { | ||
| 191 | + return &ProductMaterialRepository{ | ||
| 192 | + transactionContext: transactionContext, | ||
| 193 | + }, nil | ||
| 194 | + } | ||
| 195 | +} |
| @@ -2,6 +2,7 @@ package k3cloud | @@ -2,6 +2,7 @@ package k3cloud | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "errors" | 4 | "errors" |
| 5 | + "fmt" | ||
| 5 | "io" | 6 | "io" |
| 6 | "time" | 7 | "time" |
| 7 | 8 | ||
| @@ -87,3 +88,20 @@ func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*BillQueryResu | @@ -87,3 +88,20 @@ func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*BillQueryResu | ||
| 87 | queryResult := newBillQueryResult(dataByte, param.Data.FieldKeys) | 88 | queryResult := newBillQueryResult(dataByte, param.Data.FieldKeys) |
| 88 | return queryResult, queryResult.Error() | 89 | return queryResult, queryResult.Error() |
| 89 | } | 90 | } |
| 91 | + | ||
| 92 | +// ExecuteMetaDataQuery 元数据查询 | ||
| 93 | +func (c *Client) ExecuteMetaDataQuery(param RequestMetaDataQuery) ([]byte, error) { | ||
| 94 | + api := "/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.QueryBusinessInfo.common.kdsvc" | ||
| 95 | + resp, err := c.PostRequest(api, param) | ||
| 96 | + if err != nil { | ||
| 97 | + return nil, err | ||
| 98 | + } | ||
| 99 | + defer resp.Body.Close() | ||
| 100 | + var dataByte []byte | ||
| 101 | + dataByte, err = io.ReadAll(resp.Body) | ||
| 102 | + if err != nil { | ||
| 103 | + return nil, err | ||
| 104 | + } | ||
| 105 | + fmt.Println("data ", string(dataByte)) | ||
| 106 | + return dataByte, nil | ||
| 107 | +} |
| 1 | package k3cloud | 1 | package k3cloud |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "fmt" | ||
| 4 | "strings" | 5 | "strings" |
| 5 | "testing" | 6 | "testing" |
| 7 | + "time" | ||
| 6 | ) | 8 | ) |
| 7 | 9 | ||
| 8 | var ( | 10 | var ( |
| @@ -40,7 +42,7 @@ func TestExecuteBillQuery(t *testing.T) { | @@ -40,7 +42,7 @@ func TestExecuteBillQuery(t *testing.T) { | ||
| 40 | "FDocumentStatus", "FForbidStatus", "FErpClsID", | 42 | "FDocumentStatus", "FForbidStatus", "FErpClsID", |
| 41 | "FBaseUnitId", "FBaseUnitId.FName", "FCreateDate", "FModifyDate", | 43 | "FBaseUnitId", "FBaseUnitId.FName", "FCreateDate", "FModifyDate", |
| 42 | "FForbidDate", "FApproveDate", "FMaterialGroup", "FMaterialGroup.FName", | 44 | "FForbidDate", "FApproveDate", "FMaterialGroup", "FMaterialGroup.FName", |
| 43 | - "FRefStatus", "FMaterialGroup.FNumber", "FUseOrgId", "FUseOrgId.FName", | 45 | + "FRefStatus", "FMaterialGroup.FNumber", "FUseOrgId", "FUseOrgId.FName", "FCategoryID", |
| 44 | } | 46 | } |
| 45 | result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{ | 47 | result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{ |
| 46 | FormId: "BD_MATERIAL", | 48 | FormId: "BD_MATERIAL", |
| @@ -85,3 +87,52 @@ func TestExecuteBillQuery2(t *testing.T) { | @@ -85,3 +87,52 @@ func TestExecuteBillQuery2(t *testing.T) { | ||
| 85 | return | 87 | return |
| 86 | } | 88 | } |
| 87 | } | 89 | } |
| 90 | + | ||
| 91 | +func TestMetaDataQuery(t *testing.T) { | ||
| 92 | + client, err := NewClient(hostUrl, acctID, username, password) | ||
| 93 | + if err != nil { | ||
| 94 | + t.Error(err) | ||
| 95 | + return | ||
| 96 | + } | ||
| 97 | + inputs := []struct { | ||
| 98 | + formId string | ||
| 99 | + desc string | ||
| 100 | + }{ | ||
| 101 | + {"BD_MATERIALCATEGORY", "货类别没"}, | ||
| 102 | + {"BD_MATERIALCATEGORY", "货类别没"}, | ||
| 103 | + } | ||
| 104 | + for _, v := range inputs { | ||
| 105 | + result, err := client.ExecuteMetaDataQuery(RequestMetaDataQuery{Data{FormId: v.formId}, v.formId}) | ||
| 106 | + if err != nil { | ||
| 107 | + fmt.Println(err.Error()) | ||
| 108 | + } | ||
| 109 | + t.Log(v.formId, v.desc, string(result)) | ||
| 110 | + } | ||
| 111 | + time.Sleep(time.Second) | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +func TestExecuteMATERIALCATEGORYQuery(t *testing.T) { | ||
| 115 | + client, err := NewClient(hostUrl, acctID, username, password) | ||
| 116 | + if err != nil { | ||
| 117 | + t.Error(err) | ||
| 118 | + return | ||
| 119 | + } | ||
| 120 | + fieldKeys := []string{ | ||
| 121 | + "FName", "FNUMBER", "FMasterId", | ||
| 122 | + } | ||
| 123 | + result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{ | ||
| 124 | + FormId: "PRD_MO", | ||
| 125 | + Data: ExecuteBillQueryData{ | ||
| 126 | + FormId: "BD_MATERIALCATEGORY", | ||
| 127 | + FieldKeys: strings.Join(fieldKeys, ","), //查询的字段 | ||
| 128 | + //TopRowCount: 4, | ||
| 129 | + | ||
| 130 | + FilterString: "", | ||
| 131 | + }, | ||
| 132 | + }) | ||
| 133 | + t.Logf("result buf===> %s \n", string(result.Buf)) | ||
| 134 | + if err != nil { | ||
| 135 | + t.Error(err) | ||
| 136 | + return | ||
| 137 | + } | ||
| 138 | +} |
| @@ -51,3 +51,13 @@ type ( | @@ -51,3 +51,13 @@ type ( | ||
| 51 | Data ExecuteBillQueryData `json:"data"` | 51 | Data ExecuteBillQueryData `json:"data"` |
| 52 | } | 52 | } |
| 53 | ) | 53 | ) |
| 54 | + | ||
| 55 | +type ( | ||
| 56 | + RequestMetaDataQuery struct { | ||
| 57 | + Data Data `json:"data"` | ||
| 58 | + FormId string `json:"FormId"` //必录,查询表单元数据唯一标识 | ||
| 59 | + } | ||
| 60 | + Data struct { | ||
| 61 | + FormId string `json:"FormId"` //必录,查询表单元数据唯一标识 | ||
| 62 | + } | ||
| 63 | +) |
pkg/infrastructure/utils/set.go
0 → 100644
| 1 | +package utils | ||
| 2 | + | ||
| 3 | +const ( | ||
| 4 | + unmanaged = iota | ||
| 5 | + untyped | ||
| 6 | + intType | ||
| 7 | + int64Type | ||
| 8 | + uintType | ||
| 9 | + uint64Type | ||
| 10 | + stringType | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +type PlaceholderType = struct{} | ||
| 14 | + | ||
| 15 | +// Set is not thread-safe, for concurrent use, make sure to use it with synchronization. | ||
| 16 | +type Set struct { | ||
| 17 | + data map[interface{}]PlaceholderType | ||
| 18 | + tp int | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +// NewSet returns a managed Set, can only put the values with the same type. | ||
| 22 | +func NewSet() *Set { | ||
| 23 | + return &Set{ | ||
| 24 | + data: make(map[interface{}]PlaceholderType), | ||
| 25 | + tp: untyped, | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// NewUnmanagedSet returns a unmanaged Set, which can put values with different types. | ||
| 30 | +func NewUnmanagedSet() *Set { | ||
| 31 | + return &Set{ | ||
| 32 | + data: make(map[interface{}]PlaceholderType), | ||
| 33 | + tp: unmanaged, | ||
| 34 | + } | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +// Add adds i into s. | ||
| 38 | +func (s *Set) Add(i ...interface{}) { | ||
| 39 | + for _, each := range i { | ||
| 40 | + s.add(each) | ||
| 41 | + } | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +// AddInt adds int values ii into s. | ||
| 45 | +func (s *Set) AddInt(ii ...int) { | ||
| 46 | + for _, each := range ii { | ||
| 47 | + s.add(each) | ||
| 48 | + } | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +// AddInt64 adds int64 values ii into s. | ||
| 52 | +func (s *Set) AddInt64(ii ...int64) { | ||
| 53 | + for _, each := range ii { | ||
| 54 | + s.add(each) | ||
| 55 | + } | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +// AddUint adds uint values ii into s. | ||
| 59 | +func (s *Set) AddUint(ii ...uint) { | ||
| 60 | + for _, each := range ii { | ||
| 61 | + s.add(each) | ||
| 62 | + } | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +// AddUint64 adds uint64 values ii into s. | ||
| 66 | +func (s *Set) AddUint64(ii ...uint64) { | ||
| 67 | + for _, each := range ii { | ||
| 68 | + s.add(each) | ||
| 69 | + } | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +// AddStr adds string values ss into s. | ||
| 73 | +func (s *Set) AddStr(ss ...string) { | ||
| 74 | + for _, each := range ss { | ||
| 75 | + s.add(each) | ||
| 76 | + } | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +// Contains checks if i is in s. | ||
| 80 | +func (s *Set) Contains(i interface{}) bool { | ||
| 81 | + if len(s.data) == 0 { | ||
| 82 | + return false | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + s.validate(i) | ||
| 86 | + _, ok := s.data[i] | ||
| 87 | + return ok | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +// Keys returns the keys in s. | ||
| 91 | +func (s *Set) Keys() []interface{} { | ||
| 92 | + var keys []interface{} | ||
| 93 | + | ||
| 94 | + for key := range s.data { | ||
| 95 | + keys = append(keys, key) | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + return keys | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +// KeysInt returns the int keys in s. | ||
| 102 | +func (s *Set) KeysInt() []int { | ||
| 103 | + var keys []int | ||
| 104 | + | ||
| 105 | + for key := range s.data { | ||
| 106 | + if intKey, ok := key.(int); ok { | ||
| 107 | + keys = append(keys, intKey) | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + return keys | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +// KeysInt64 returns int64 keys in s. | ||
| 115 | +func (s *Set) KeysInt64() []int64 { | ||
| 116 | + var keys []int64 | ||
| 117 | + | ||
| 118 | + for key := range s.data { | ||
| 119 | + if intKey, ok := key.(int64); ok { | ||
| 120 | + keys = append(keys, intKey) | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + return keys | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +// KeysUint returns uint keys in s. | ||
| 128 | +func (s *Set) KeysUint() []uint { | ||
| 129 | + var keys []uint | ||
| 130 | + | ||
| 131 | + for key := range s.data { | ||
| 132 | + if intKey, ok := key.(uint); ok { | ||
| 133 | + keys = append(keys, intKey) | ||
| 134 | + } | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + return keys | ||
| 138 | +} | ||
| 139 | + | ||
| 140 | +// KeysUint64 returns uint64 keys in s. | ||
| 141 | +func (s *Set) KeysUint64() []uint64 { | ||
| 142 | + var keys []uint64 | ||
| 143 | + | ||
| 144 | + for key := range s.data { | ||
| 145 | + if intKey, ok := key.(uint64); ok { | ||
| 146 | + keys = append(keys, intKey) | ||
| 147 | + } | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + return keys | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +// KeysStr returns string keys in s. | ||
| 154 | +func (s *Set) KeysStr() []string { | ||
| 155 | + var keys []string | ||
| 156 | + | ||
| 157 | + for key := range s.data { | ||
| 158 | + if strKey, ok := key.(string); ok { | ||
| 159 | + keys = append(keys, strKey) | ||
| 160 | + } | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + return keys | ||
| 164 | +} | ||
| 165 | + | ||
| 166 | +// Remove removes i from s. | ||
| 167 | +func (s *Set) Remove(i interface{}) { | ||
| 168 | + s.validate(i) | ||
| 169 | + delete(s.data, i) | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | +// Count returns the number of items in s. | ||
| 173 | +func (s *Set) Count() int { | ||
| 174 | + return len(s.data) | ||
| 175 | +} | ||
| 176 | + | ||
| 177 | +func (s *Set) add(i interface{}) { | ||
| 178 | + switch s.tp { | ||
| 179 | + case unmanaged: | ||
| 180 | + // do nothing | ||
| 181 | + case untyped: | ||
| 182 | + s.setType(i) | ||
| 183 | + default: | ||
| 184 | + s.validate(i) | ||
| 185 | + } | ||
| 186 | + s.data[i] = PlaceholderType{} | ||
| 187 | +} | ||
| 188 | + | ||
| 189 | +func (s *Set) setType(i interface{}) { | ||
| 190 | + // s.tp can only be untyped here | ||
| 191 | + switch i.(type) { | ||
| 192 | + case int: | ||
| 193 | + s.tp = intType | ||
| 194 | + case int64: | ||
| 195 | + s.tp = int64Type | ||
| 196 | + case uint: | ||
| 197 | + s.tp = uintType | ||
| 198 | + case uint64: | ||
| 199 | + s.tp = uint64Type | ||
| 200 | + case string: | ||
| 201 | + s.tp = stringType | ||
| 202 | + } | ||
| 203 | +} | ||
| 204 | + | ||
| 205 | +func (s *Set) validate(i interface{}) { | ||
| 206 | + if s.tp == unmanaged { | ||
| 207 | + return | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + switch i.(type) { | ||
| 211 | + case int: | ||
| 212 | + if s.tp != intType { | ||
| 213 | + //logx.Errorf("Error: element is int, but set contains elements with type %d", s.tp) | ||
| 214 | + } | ||
| 215 | + case int64: | ||
| 216 | + if s.tp != int64Type { | ||
| 217 | + //logx.Errorf("Error: element is int64, but set contains elements with type %d", s.tp) | ||
| 218 | + } | ||
| 219 | + case uint: | ||
| 220 | + if s.tp != uintType { | ||
| 221 | + //logx.Errorf("Error: element is uint, but set contains elements with type %d", s.tp) | ||
| 222 | + } | ||
| 223 | + case uint64: | ||
| 224 | + if s.tp != uint64Type { | ||
| 225 | + //logx.Errorf("Error: element is uint64, but set contains elements with type %d", s.tp) | ||
| 226 | + } | ||
| 227 | + case string: | ||
| 228 | + if s.tp != stringType { | ||
| 229 | + //logx.Errorf("Error: element is string, but set contains elements with type %d", s.tp) | ||
| 230 | + } | ||
| 231 | + } | ||
| 232 | +} |
| 1 | package utils | 1 | package utils |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
| 4 | "strconv" | 5 | "strconv" |
| 5 | "time" | 6 | "time" |
| 6 | ) | 7 | ) |
| @@ -103,3 +104,32 @@ func TimeBeforeEqual(t1, t2 time.Time) bool { | @@ -103,3 +104,32 @@ func TimeBeforeEqual(t1, t2 time.Time) bool { | ||
| 103 | } | 104 | } |
| 104 | return false | 105 | return false |
| 105 | } | 106 | } |
| 107 | + | ||
| 108 | +type TimeString time.Time | ||
| 109 | + | ||
| 110 | +func (timeString *TimeString) UnmarshalJSON(data []byte) error { | ||
| 111 | + if len(data) == 2 { | ||
| 112 | + return nil | ||
| 113 | + } | ||
| 114 | + t, err := xtime.Parse(string(data[1 : len(data)-1])) | ||
| 115 | + if err != nil { | ||
| 116 | + return err | ||
| 117 | + } | ||
| 118 | + *timeString = TimeString(t) | ||
| 119 | + return nil | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +func (timeString TimeString) MarshalJSON() ([]byte, error) { | ||
| 123 | + if xtime.IsZero(time.Time(timeString)) { | ||
| 124 | + return []byte(`""`), nil | ||
| 125 | + } | ||
| 126 | + b := make([]byte, 0) | ||
| 127 | + b = append(b, '"') | ||
| 128 | + b = time.Time(timeString).AppendFormat(b, time.RFC3339) | ||
| 129 | + b = append(b, '"') | ||
| 130 | + return b, nil | ||
| 131 | +} | ||
| 132 | + | ||
| 133 | +func (timeString TimeString) Time() time.Time { | ||
| 134 | + return time.Time(timeString) | ||
| 135 | +} |
| @@ -24,6 +24,20 @@ func NewTree(nodes []TreeNode) *Tree { | @@ -24,6 +24,20 @@ func NewTree(nodes []TreeNode) *Tree { | ||
| 24 | return tree | 24 | return tree |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | +func NewTreeWithNodes(nodes ...TreeNode) *Tree { | ||
| 28 | + var tree = &Tree{ | ||
| 29 | + Node: nil, | ||
| 30 | + Nodes: make([]*Tree, 0), | ||
| 31 | + } | ||
| 32 | + for i := range nodes { | ||
| 33 | + match := traverseAdd(tree, nodes[i]) | ||
| 34 | + if !match { | ||
| 35 | + tree.Nodes = append(tree.Nodes, newTree(nodes[i])) | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + return tree | ||
| 39 | +} | ||
| 40 | + | ||
| 27 | func newTree(node TreeNode) *Tree { | 41 | func newTree(node TreeNode) *Tree { |
| 28 | return &Tree{ | 42 | return &Tree{ |
| 29 | Node: node, | 43 | Node: node, |
| @@ -144,6 +144,16 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context) | @@ -144,6 +144,16 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context) | ||
| 144 | }) | 144 | }) |
| 145 | } | 145 | } |
| 146 | } | 146 | } |
| 147 | + case "11": | ||
| 148 | + crontab.SyncMaterialGroup(nil) | ||
| 149 | + case "12": | ||
| 150 | + bc := c.Background() | ||
| 151 | + bc = c.WithValue(bc, "pullType", "full") | ||
| 152 | + err := crontab.SyncMaterial(bc) | ||
| 153 | + if err != nil { | ||
| 154 | + Response(ctx, nil, err) | ||
| 155 | + return | ||
| 156 | + } | ||
| 147 | } | 157 | } |
| 148 | Response(ctx, nil, nil) | 158 | Response(ctx, nil, nil) |
| 149 | } | 159 | } |
| @@ -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 |
| 1 | +package controllers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/web/beego" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/command" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/query" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/service" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +type ProductMaterialController struct { | ||
| 11 | + beego.BaseController | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +func (controller *ProductMaterialController) CreateProductMaterial() { | ||
| 15 | + productMaterialService := service.NewProductMaterialService(nil) | ||
| 16 | + cmd := &command.CreateProductMaterialCommand{} | ||
| 17 | + controller.Unmarshal(cmd) | ||
| 18 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
| 19 | + cmd.CompanyId = operateInfo.CompanyId | ||
| 20 | + cmd.OrgId = operateInfo.OrgId | ||
| 21 | + data, err := productMaterialService.CreateProductMaterial(operateInfo, cmd) | ||
| 22 | + controller.Response(data, err) | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +func (controller *ProductMaterialController) UpdateProductMaterial() { | ||
| 26 | + productMaterialService := service.NewProductMaterialService(nil) | ||
| 27 | + updateProductMaterialCommand := &command.UpdateProductMaterialCommand{} | ||
| 28 | + controller.Unmarshal(updateProductMaterialCommand) | ||
| 29 | + productMaterialId, _ := controller.GetInt(":productMaterialId") | ||
| 30 | + updateProductMaterialCommand.ProductMaterialId = productMaterialId | ||
| 31 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
| 32 | + //updateProductMaterialCommand.CompanyId = operateInfo.CompanyId | ||
| 33 | + //updateProductMaterialCommand.OrgId = operateInfo.OrgId | ||
| 34 | + data, err := productMaterialService.UpdateProductMaterial(operateInfo, updateProductMaterialCommand) | ||
| 35 | + controller.Response(data, err) | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +func (controller *ProductMaterialController) GetProductMaterial() { | ||
| 39 | + productMaterialService := service.NewProductMaterialService(nil) | ||
| 40 | + getProductMaterialQuery := &query.GetProductMaterialQuery{} | ||
| 41 | + productMaterialId, _ := controller.GetInt(":productMaterialId") | ||
| 42 | + getProductMaterialQuery.ProductMaterialId = productMaterialId | ||
| 43 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
| 44 | + data, err := productMaterialService.GetProductMaterial(operateInfo, getProductMaterialQuery) | ||
| 45 | + controller.Response(data, err) | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +func (controller *ProductMaterialController) RemoveProductMaterial() { | ||
| 49 | + productMaterialService := service.NewProductMaterialService(nil) | ||
| 50 | + removeProductMaterialCommand := &command.RemoveProductMaterialCommand{} | ||
| 51 | + controller.Unmarshal(removeProductMaterialCommand) | ||
| 52 | + productMaterialId, _ := controller.GetInt(":productMaterialId") | ||
| 53 | + removeProductMaterialCommand.ProductMaterialId = productMaterialId | ||
| 54 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
| 55 | + data, err := productMaterialService.RemoveProductMaterial(operateInfo, removeProductMaterialCommand) | ||
| 56 | + controller.Response(data, err) | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +//没用到 | ||
| 60 | +func (controller *ProductMaterialController) ListProductMaterial() { | ||
| 61 | + productMaterialService := service.NewProductMaterialService(nil) | ||
| 62 | + listProductMaterialQuery := &query.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) | ||
| 83 | + controller.Response(data, err) | ||
| 84 | +} |
| 1 | +package controllers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/web/beego" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterialGroup/command" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterialGroup/query" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterialGroup/service" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +type ProductMaterialGroupController struct { | ||
| 11 | + beego.BaseController | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +func (controller *ProductMaterialGroupController) CreateProductMaterialGroup() { | ||
| 15 | + productMaterialGroupService := service.NewProductMaterialGroupService(nil) | ||
| 16 | + cmd := &command.CreateProductMaterialGroupCommand{} | ||
| 17 | + controller.Unmarshal(cmd) | ||
| 18 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
| 19 | + cmd.CompanyId = operateInfo.CompanyId | ||
| 20 | + cmd.OrgId = operateInfo.OrgId | ||
| 21 | + data, err := productMaterialGroupService.CreateProductMaterialGroup(operateInfo, cmd) | ||
| 22 | + controller.Response(data, err) | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +func (controller *ProductMaterialGroupController) UpdateProductMaterialGroup() { | ||
| 26 | + productMaterialGroupService := service.NewProductMaterialGroupService(nil) | ||
| 27 | + updateProductMaterialGroupCommand := &command.UpdateProductMaterialGroupCommand{} | ||
| 28 | + controller.Unmarshal(updateProductMaterialGroupCommand) | ||
| 29 | + productMaterialGroupId, _ := controller.GetInt(":productMaterialGroupId") | ||
| 30 | + updateProductMaterialGroupCommand.ProductMaterialGroupId = productMaterialGroupId | ||
| 31 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
| 32 | + data, err := productMaterialGroupService.UpdateProductMaterialGroup(operateInfo, updateProductMaterialGroupCommand) | ||
| 33 | + controller.Response(data, err) | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +func (controller *ProductMaterialGroupController) GetProductMaterialGroup() { | ||
| 37 | + productMaterialGroupService := service.NewProductMaterialGroupService(nil) | ||
| 38 | + getProductMaterialGroupQuery := &query.GetProductMaterialGroupQuery{} | ||
| 39 | + productMaterialGroupId, _ := controller.GetInt(":productMaterialGroupId") | ||
| 40 | + getProductMaterialGroupQuery.ProductMaterialGroupId = productMaterialGroupId | ||
| 41 | + data, err := productMaterialGroupService.GetProductMaterialGroup(getProductMaterialGroupQuery) | ||
| 42 | + controller.Response(data, err) | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +func (controller *ProductMaterialGroupController) RemoveProductMaterialGroup() { | ||
| 46 | + productMaterialGroupService := service.NewProductMaterialGroupService(nil) | ||
| 47 | + removeProductMaterialGroupCommand := &command.RemoveProductMaterialGroupCommand{} | ||
| 48 | + controller.Unmarshal(removeProductMaterialGroupCommand) | ||
| 49 | + productMaterialGroupId, _ := controller.GetInt(":productMaterialGroupId") | ||
| 50 | + removeProductMaterialGroupCommand.ProductMaterialGroupId = productMaterialGroupId | ||
| 51 | + data, err := productMaterialGroupService.RemoveProductMaterialGroup(removeProductMaterialGroupCommand) | ||
| 52 | + controller.Response(data, err) | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +func (controller *ProductMaterialGroupController) ListProductMaterialGroup() { | ||
| 56 | + productMaterialGroupService := service.NewProductMaterialGroupService(nil) | ||
| 57 | + listProductMaterialGroupQuery := &query.ListProductMaterialGroupQuery{} | ||
| 58 | + offset, _ := controller.GetInt("offset") | ||
| 59 | + listProductMaterialGroupQuery.Offset = offset | ||
| 60 | + limit, _ := controller.GetInt("limit") | ||
| 61 | + listProductMaterialGroupQuery.Limit = limit | ||
| 62 | + data, err := productMaterialGroupService.ListProductMaterialGroup(listProductMaterialGroupQuery) | ||
| 63 | + controller.Response(data, err) | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +func (controller *ProductMaterialGroupController) SearchProductMaterialGroup() { | ||
| 67 | + productMaterialGroupService := service.NewProductMaterialGroupService(nil) | ||
| 68 | + cmd := &query.SearchProductMaterialGroupQuery{} | ||
| 69 | + offset, _ := controller.GetInt("offset") | ||
| 70 | + cmd.Offset = offset | ||
| 71 | + limit, _ := controller.GetInt("limit") | ||
| 72 | + cmd.Limit = limit | ||
| 73 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
| 74 | + cmd.CompanyId = operateInfo.CompanyId | ||
| 75 | + total, data, err := productMaterialGroupService.SearchProductMaterialGroup(ParseOperateInfo(controller.BaseController), cmd) | ||
| 76 | + ResponseGrid(controller.BaseController, total, data, err) | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +func (controller *ProductMaterialGroupController) SelectorProductMaterialGroup() { | ||
| 80 | + productMaterialGroupService := service.NewProductMaterialGroupService(nil) | ||
| 81 | + cmd := &query.SelectorProductMaterialGroupQuery{} | ||
| 82 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
| 83 | + cmd.CompanyId = operateInfo.CompanyId | ||
| 84 | + count, data, err := productMaterialGroupService.SelectorProductMaterialGroup(ParseOperateInfo(controller.BaseController), cmd) | ||
| 85 | + controller.Response(map[string]interface{}{ | ||
| 86 | + "groups": data, | ||
| 87 | + "count": count, | ||
| 88 | + }, err) | ||
| 89 | +} |
| 1 | +package routers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/beego/beego/v2/server/web" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func init() { | ||
| 9 | + web.Router("/product-material-groups/", &controllers.ProductMaterialGroupController{}, "Post:CreateProductMaterialGroup") | ||
| 10 | + web.Router("/product-material-groups/:productMaterialGroupId", &controllers.ProductMaterialGroupController{}, "Put:UpdateProductMaterialGroup") | ||
| 11 | + web.Router("/product-material-groups/:productMaterialGroupId", &controllers.ProductMaterialGroupController{}, "Get:GetProductMaterialGroup") | ||
| 12 | + web.Router("/product-material-groups/:productMaterialGroupId", &controllers.ProductMaterialGroupController{}, "Delete:RemoveProductMaterialGroup") | ||
| 13 | + web.Router("/product-material-groups/", &controllers.ProductMaterialGroupController{}, "Get:ListProductMaterialGroup") | ||
| 14 | + web.Router("/product-material-groups/search", &controllers.ProductMaterialGroupController{}, "Post:SearchProductMaterialGroup") | ||
| 15 | + web.Router("/product-material-groups/selector", &controllers.ProductMaterialGroupController{}, "Post:SelectorProductMaterialGroup") | ||
| 16 | +} |
| 1 | +package routers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/beego/beego/v2/server/web" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers" | ||
| 6 | +) | ||
| 7 | + | ||
| 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") //删除单个物料 | ||
| 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") //批量删除物料 | ||
| 16 | +} |
| 1 | +package product_material | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + | ||
| 6 | + "github.com/gavv/httpexpect" | ||
| 7 | + . "github.com/onsi/ginkgo" | ||
| 8 | + . "github.com/onsi/gomega" | ||
| 9 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +var _ = Describe("创建生产物料服务", func() { | ||
| 13 | + Describe("提交数据创建生产物料服务", func() { | ||
| 14 | + Context("提交正确的新生产物料数据", func() { | ||
| 15 | + It("返回生产物料数据", func() { | ||
| 16 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 17 | + body := map[string]interface{}{ | ||
| 18 | + "productMaterialGroupId": "int", | ||
| 19 | + "materialNumber": "string", | ||
| 20 | + "materialName": "string", | ||
| 21 | + "materialAttribute": "string", | ||
| 22 | + "materialCategory": "string", | ||
| 23 | + "productMaterialExt": "string", | ||
| 24 | + } | ||
| 25 | + httpExpect.POST("/product-materials/"). | ||
| 26 | + WithJSON(body). | ||
| 27 | + Expect(). | ||
| 28 | + Status(http.StatusOK). | ||
| 29 | + JSON(). | ||
| 30 | + Object(). | ||
| 31 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 33 | + ContainsKey("data").Value("data").Object(). | ||
| 34 | + ContainsKey("productMaterialId").ValueNotEqual("productMaterialId", BeZero()) | ||
| 35 | + }) | ||
| 36 | + }) | ||
| 37 | + }) | ||
| 38 | + AfterEach(func() { | ||
| 39 | + _, err := pG.DB.Exec("DELETE FROM product_materials WHERE true") | ||
| 40 | + Expect(err).NotTo(HaveOccurred()) | ||
| 41 | + }) | ||
| 42 | +}) |
| 1 | +package product_material | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("返回生产物料服务", func() { | ||
| 14 | + var productMaterialId int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&productMaterialId), | ||
| 18 | + "INSERT INTO product_materials (product_material_id, company_id, org_id, product_material_group_id, material_number, material_name, material_attribute, material_category, product_material_ext, created_at, updated_at, deleted_at, ext) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_material_id", | ||
| 19 | + "testProductMaterialId", "testCompanyId", "testOrgId", "testProductMaterialGroupId", "testMaterialNumber", "testMaterialName", "testMaterialAttribute", "testMaterialCategory", "testProductMaterialExt", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testExt") | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("根据productMaterialId参数返回生产物料", func() { | ||
| 23 | + Context("传入有效的productMaterialId", func() { | ||
| 24 | + It("返回生产物料数据", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + httpExpect.GET("/product-materials/{productMaterialId}"). | ||
| 27 | + Expect(). | ||
| 28 | + Status(http.StatusOK). | ||
| 29 | + JSON(). | ||
| 30 | + Object(). | ||
| 31 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 33 | + ContainsKey("data").Value("data").Object() | ||
| 34 | + }) | ||
| 35 | + }) | ||
| 36 | + }) | ||
| 37 | + AfterEach(func() { | ||
| 38 | + _, err := pG.DB.Exec("DELETE FROM product_materials WHERE true") | ||
| 39 | + Expect(err).NotTo(HaveOccurred()) | ||
| 40 | + }) | ||
| 41 | +}) |
| 1 | +package product_material | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("返回生产物料服务列表", func() { | ||
| 14 | + var productMaterialId int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&productMaterialId), | ||
| 18 | + "INSERT INTO product_materials (product_material_id, company_id, org_id, product_material_group_id, material_number, material_name, material_attribute, material_category, product_material_ext, created_at, updated_at, deleted_at, ext) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_material_id", | ||
| 19 | + "testProductMaterialId", "testCompanyId", "testOrgId", "testProductMaterialGroupId", "testMaterialNumber", "testMaterialName", "testMaterialAttribute", "testMaterialCategory", "testProductMaterialExt", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testExt") | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("根据参数返回生产物料列表", func() { | ||
| 23 | + Context("传入有效的参数", func() { | ||
| 24 | + It("返回生产物料数据列表", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + httpExpect.GET("/product-materials/"). | ||
| 27 | + WithQuery("offset", "int"). | ||
| 28 | + WithQuery("limit", "int"). | ||
| 29 | + Expect(). | ||
| 30 | + Status(http.StatusOK). | ||
| 31 | + JSON(). | ||
| 32 | + Object(). | ||
| 33 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 34 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 35 | + ContainsKey("data").Value("data").Object(). | ||
| 36 | + ContainsKey("count").ValueEqual("count", 1). | ||
| 37 | + ContainsKey("productMaterials").Value("productMaterials").Array() | ||
| 38 | + }) | ||
| 39 | + }) | ||
| 40 | + }) | ||
| 41 | + AfterEach(func() { | ||
| 42 | + _, err := pG.DB.Exec("DELETE FROM product_materials WHERE true") | ||
| 43 | + Expect(err).NotTo(HaveOccurred()) | ||
| 44 | + }) | ||
| 45 | +}) |
| 1 | +package product_material | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + "net/http/httptest" | ||
| 6 | + "testing" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/server/web" | ||
| 9 | + . "github.com/onsi/ginkgo" | ||
| 10 | + . "github.com/onsi/gomega" | ||
| 11 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application" | ||
| 12 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 13 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego" | ||
| 14 | +) | ||
| 15 | + | ||
| 16 | +func TestProductMaterial(t *testing.T) { | ||
| 17 | + RegisterFailHandler(Fail) | ||
| 18 | + RunSpecs(t, "Beego Port ProductMaterial Correlations Test Case Suite") | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +var handler http.Handler | ||
| 22 | +var server *httptest.Server | ||
| 23 | + | ||
| 24 | +var _ = BeforeSuite(func() { | ||
| 25 | + handler = web.BeeApp.Handlers | ||
| 26 | + server = httptest.NewServer(handler) | ||
| 27 | +}) | ||
| 28 | + | ||
| 29 | +var _ = AfterSuite(func() { | ||
| 30 | + server.Close() | ||
| 31 | +}) |
| 1 | +package product_material | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("移除生产物料服务", func() { | ||
| 14 | + var productMaterialId int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&productMaterialId), | ||
| 18 | + "INSERT INTO product_materials (product_material_id, company_id, org_id, product_material_group_id, material_number, material_name, material_attribute, material_category, product_material_ext, created_at, updated_at, deleted_at, ext) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_material_id", | ||
| 19 | + "testProductMaterialId", "testCompanyId", "testOrgId", "testProductMaterialGroupId", "testMaterialNumber", "testMaterialName", "testMaterialAttribute", "testMaterialCategory", "testProductMaterialExt", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testExt") | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("根据参数移除生产物料服务", func() { | ||
| 23 | + Context("传入有效的productMaterialId", func() { | ||
| 24 | + It("返回被移除生产物料的数据", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + httpExpect.DELETE("/product-materials/{productMaterialId}"). | ||
| 27 | + Expect(). | ||
| 28 | + Status(http.StatusOK). | ||
| 29 | + JSON(). | ||
| 30 | + Object(). | ||
| 31 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 33 | + ContainsKey("data").Value("data").Object() | ||
| 34 | + }) | ||
| 35 | + }) | ||
| 36 | + }) | ||
| 37 | + AfterEach(func() { | ||
| 38 | + _, err := pG.DB.Exec("DELETE FROM product_materials WHERE true") | ||
| 39 | + Expect(err).NotTo(HaveOccurred()) | ||
| 40 | + }) | ||
| 41 | +}) |
| 1 | +package product_material | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("更新生产物料服务", func() { | ||
| 14 | + var productMaterialId int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&productMaterialId), | ||
| 18 | + "INSERT INTO product_materials (product_material_id, company_id, org_id, product_material_group_id, material_number, material_name, material_attribute, material_category, product_material_ext, created_at, updated_at, deleted_at, ext) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_material_id", | ||
| 19 | + "testProductMaterialId", "testCompanyId", "testOrgId", "testProductMaterialGroupId", "testMaterialNumber", "testMaterialName", "testMaterialAttribute", "testMaterialCategory", "testProductMaterialExt", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testExt") | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("提交数据更新生产物料服务", func() { | ||
| 23 | + Context("提交正确的生产物料数据", func() { | ||
| 24 | + It("返回更新后的生产物料数据", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + body := map[string]interface{}{} | ||
| 27 | + httpExpect.PUT("/product-materials/{productMaterialId}"). | ||
| 28 | + WithJSON(body). | ||
| 29 | + Expect(). | ||
| 30 | + Status(http.StatusOK). | ||
| 31 | + JSON(). | ||
| 32 | + Object(). | ||
| 33 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 34 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 35 | + ContainsKey("data").Value("data").Object(). | ||
| 36 | + ContainsKey("productMaterialId").ValueEqual("productMaterialId", productMaterialId) | ||
| 37 | + }) | ||
| 38 | + }) | ||
| 39 | + }) | ||
| 40 | + AfterEach(func() { | ||
| 41 | + _, err := pG.DB.Exec("DELETE FROM product_materials WHERE true") | ||
| 42 | + Expect(err).NotTo(HaveOccurred()) | ||
| 43 | + }) | ||
| 44 | +}) |
| 1 | +package product_material_group | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + | ||
| 6 | + "github.com/gavv/httpexpect" | ||
| 7 | + . "github.com/onsi/ginkgo" | ||
| 8 | + . "github.com/onsi/gomega" | ||
| 9 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +var _ = Describe("创建物料分组服务", func() { | ||
| 13 | + Describe("提交数据创建物料分组服务", func() { | ||
| 14 | + Context("提交正确的新物料分组数据", func() { | ||
| 15 | + It("返回物料分组数据", func() { | ||
| 16 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 17 | + body := map[string]interface{}{ | ||
| 18 | + "pid": "int", | ||
| 19 | + "materialGroupName": "string", | ||
| 20 | + "materialGroupNumber": "string", | ||
| 21 | + } | ||
| 22 | + httpExpect.POST("/product-material-groups/"). | ||
| 23 | + WithJSON(body). | ||
| 24 | + Expect(). | ||
| 25 | + Status(http.StatusOK). | ||
| 26 | + JSON(). | ||
| 27 | + Object(). | ||
| 28 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 29 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 30 | + ContainsKey("data").Value("data").Object(). | ||
| 31 | + ContainsKey("productMaterialGroupId").ValueNotEqual("productMaterialGroupId", BeZero()) | ||
| 32 | + }) | ||
| 33 | + }) | ||
| 34 | + }) | ||
| 35 | + AfterEach(func() { | ||
| 36 | + _, err := pG.DB.Exec("DELETE FROM product_material_groups WHERE true") | ||
| 37 | + Expect(err).NotTo(HaveOccurred()) | ||
| 38 | + }) | ||
| 39 | +}) |
| 1 | +package product_material_group | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("返回物料分组服务", func() { | ||
| 14 | + var productMaterialGroupId int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&productMaterialGroupId), | ||
| 18 | + "INSERT INTO product_material_groups (product_material_group_id, company_id, org_id, pid, path, material_group_name, material_group_number, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_material_group_id", | ||
| 19 | + "testProductMaterialGroupId", "testCompanyId", "testOrgId", "testPid", "testPath", "testMaterialGroupName", "testMaterialGroupNumber", "testCreatedAt", "testUpdatedAt", "testDeletedAt") | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("根据productMaterialGroupId参数返回物料分组", func() { | ||
| 23 | + Context("传入有效的productMaterialGroupId", func() { | ||
| 24 | + It("返回物料分组数据", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + httpExpect.GET("/product-material-groups/{productMaterialGroupId}"). | ||
| 27 | + Expect(). | ||
| 28 | + Status(http.StatusOK). | ||
| 29 | + JSON(). | ||
| 30 | + Object(). | ||
| 31 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 33 | + ContainsKey("data").Value("data").Object() | ||
| 34 | + }) | ||
| 35 | + }) | ||
| 36 | + }) | ||
| 37 | + AfterEach(func() { | ||
| 38 | + _, err := pG.DB.Exec("DELETE FROM product_material_groups WHERE true") | ||
| 39 | + Expect(err).NotTo(HaveOccurred()) | ||
| 40 | + }) | ||
| 41 | +}) |
| 1 | +package product_material_group | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("返回物料分组服务列表", func() { | ||
| 14 | + var productMaterialGroupId int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&productMaterialGroupId), | ||
| 18 | + "INSERT INTO product_material_groups (product_material_group_id, company_id, org_id, pid, path, material_group_name, material_group_number, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_material_group_id", | ||
| 19 | + "testProductMaterialGroupId", "testCompanyId", "testOrgId", "testPid", "testPath", "testMaterialGroupName", "testMaterialGroupNumber", "testCreatedAt", "testUpdatedAt", "testDeletedAt") | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("根据参数返回物料分组列表", func() { | ||
| 23 | + Context("传入有效的参数", func() { | ||
| 24 | + It("返回物料分组数据列表", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + httpExpect.GET("/product-material-groups/"). | ||
| 27 | + WithQuery("offset", "int"). | ||
| 28 | + WithQuery("limit", "int"). | ||
| 29 | + Expect(). | ||
| 30 | + Status(http.StatusOK). | ||
| 31 | + JSON(). | ||
| 32 | + Object(). | ||
| 33 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 34 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 35 | + ContainsKey("data").Value("data").Object(). | ||
| 36 | + ContainsKey("count").ValueEqual("count", 1). | ||
| 37 | + ContainsKey("productMaterialGroups").Value("productMaterialGroups").Array() | ||
| 38 | + }) | ||
| 39 | + }) | ||
| 40 | + }) | ||
| 41 | + AfterEach(func() { | ||
| 42 | + _, err := pG.DB.Exec("DELETE FROM product_material_groups WHERE true") | ||
| 43 | + Expect(err).NotTo(HaveOccurred()) | ||
| 44 | + }) | ||
| 45 | +}) |
| 1 | +package product_material_group | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + "net/http/httptest" | ||
| 6 | + "testing" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/server/web" | ||
| 9 | + . "github.com/onsi/ginkgo" | ||
| 10 | + . "github.com/onsi/gomega" | ||
| 11 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application" | ||
| 12 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 13 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego" | ||
| 14 | +) | ||
| 15 | + | ||
| 16 | +func TestProductMaterialGroup(t *testing.T) { | ||
| 17 | + RegisterFailHandler(Fail) | ||
| 18 | + RunSpecs(t, "Beego Port ProductMaterialGroup Correlations Test Case Suite") | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +var handler http.Handler | ||
| 22 | +var server *httptest.Server | ||
| 23 | + | ||
| 24 | +var _ = BeforeSuite(func() { | ||
| 25 | + handler = web.BeeApp.Handlers | ||
| 26 | + server = httptest.NewServer(handler) | ||
| 27 | +}) | ||
| 28 | + | ||
| 29 | +var _ = AfterSuite(func() { | ||
| 30 | + server.Close() | ||
| 31 | +}) |
| 1 | +package product_material_group | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("移除物料分组服务", func() { | ||
| 14 | + var productMaterialGroupId int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&productMaterialGroupId), | ||
| 18 | + "INSERT INTO product_material_groups (product_material_group_id, company_id, org_id, pid, path, material_group_name, material_group_number, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_material_group_id", | ||
| 19 | + "testProductMaterialGroupId", "testCompanyId", "testOrgId", "testPid", "testPath", "testMaterialGroupName", "testMaterialGroupNumber", "testCreatedAt", "testUpdatedAt", "testDeletedAt") | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("根据参数移除物料分组服务", func() { | ||
| 23 | + Context("传入有效的productMaterialGroupId", func() { | ||
| 24 | + It("返回被移除物料分组的数据", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + httpExpect.DELETE("/product-material-groups/{productMaterialGroupId}"). | ||
| 27 | + Expect(). | ||
| 28 | + Status(http.StatusOK). | ||
| 29 | + JSON(). | ||
| 30 | + Object(). | ||
| 31 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 33 | + ContainsKey("data").Value("data").Object() | ||
| 34 | + }) | ||
| 35 | + }) | ||
| 36 | + }) | ||
| 37 | + AfterEach(func() { | ||
| 38 | + _, err := pG.DB.Exec("DELETE FROM product_material_groups WHERE true") | ||
| 39 | + Expect(err).NotTo(HaveOccurred()) | ||
| 40 | + }) | ||
| 41 | +}) |
| 1 | +package product_material_group | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("更新物料分组服务", func() { | ||
| 14 | + var productMaterialGroupId int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&productMaterialGroupId), | ||
| 18 | + "INSERT INTO product_material_groups (product_material_group_id, company_id, org_id, pid, path, material_group_name, material_group_number, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING product_material_group_id", | ||
| 19 | + "testProductMaterialGroupId", "testCompanyId", "testOrgId", "testPid", "testPath", "testMaterialGroupName", "testMaterialGroupNumber", "testCreatedAt", "testUpdatedAt", "testDeletedAt") | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("提交数据更新物料分组服务", func() { | ||
| 23 | + Context("提交正确的物料分组数据", func() { | ||
| 24 | + It("返回更新后的物料分组数据", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + body := map[string]interface{}{ | ||
| 27 | + "materialGroupName": "string", | ||
| 28 | + "materialGroupNumber": "string", | ||
| 29 | + } | ||
| 30 | + httpExpect.PUT("/product-material-groups/{productMaterialGroupId}"). | ||
| 31 | + WithJSON(body). | ||
| 32 | + Expect(). | ||
| 33 | + Status(http.StatusOK). | ||
| 34 | + JSON(). | ||
| 35 | + Object(). | ||
| 36 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 37 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 38 | + ContainsKey("data").Value("data").Object(). | ||
| 39 | + ContainsKey("productMaterialGroupId").ValueEqual("productMaterialGroupId", productMaterialGroupId) | ||
| 40 | + }) | ||
| 41 | + }) | ||
| 42 | + }) | ||
| 43 | + AfterEach(func() { | ||
| 44 | + _, err := pG.DB.Exec("DELETE FROM product_material_groups WHERE true") | ||
| 45 | + Expect(err).NotTo(HaveOccurred()) | ||
| 46 | + }) | ||
| 47 | +}) |
-
请 注册 或 登录 后发表评论