plan_dispatch_record_dao.go
4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package dao
import (
"fmt"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
"time"
)
type ProductPlanDispatchRecordDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewProductPlanDispatchRecord(transactionContext *pgTransaction.TransactionContext) (*ProductPlanDispatchRecordDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ProductPlanDispatchRecordDao{
transactionContext: transactionContext,
}, nil
}
}
// 生产计划对应的批次
// 工段
// 日期
// 产品编号
// 调度状态 status
func (dao *ProductPlanDispatchRecordDao) ProductPlanDispatchRecord(companyId, orgId int, workStationId string, date time.Time, productCode string, status int) (*domain.ProductPlanDispatchRecord, error) {
tx := dao.transactionContext.PgTx
productPlanDispatchRecordModel := new(models.ProductPlanDispatchRecord)
query := sqlbuilder.BuildQuery(tx.Model(productPlanDispatchRecordModel), map[string]interface{}{})
query.Where("company_id = ?", companyId)
query.Where("org_id = ?", orgId)
query.Where("work_station->>'workStationId'=?", workStationId)
query.Where("product_date = ?", date)
if status > 0 {
query.Where("plan_dispatch_status = ?", status)
}
query.Where("plan_dispatch_record_ext->>'productCode'=?", productCode)
query.Order("updated_at desc")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
} else {
return nil, err
}
}
if productPlanDispatchRecordModel.ProductPlanDispatchRecordId == 0 {
return nil, nil
} else {
return transform.TransformToProductPlanDispatchRecordDomainModelFromPgModels(productPlanDispatchRecordModel)
}
}
func (dao *ProductPlanDispatchRecordDao) ProductPlan(companyId, orgId int, workshopId int, date time.Time, productCode string) (*domain.ProductPlan, error) {
tx := dao.transactionContext.PgTx
productPlan := new(models.ProductPlan)
query := sqlbuilder.BuildQuery(tx.Model(productPlan), map[string]interface{}{})
query.Where("company_id = ?", companyId)
query.Where("org_id = ?", orgId)
query.Where("workshop->>'workshopId'='?'", workshopId)
query.Where("product_date = ?", date)
if len(productCode) > 0 {
query.Where("ext #>>'{productPlanExt,productCode}'=?", productCode)
}
query.Order("updated_at desc")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
} else {
return nil, err
}
}
if productPlan.ProductPlanId == 0 {
return nil, nil
} else {
return transform.TransformToProductPlanDomainModelFromPgModels(productPlan)
}
}
func (dao *ProductPlanDispatchRecordDao) ProductPlans(companyId, orgId int, workshopId int, date time.Time, productCode string) ([]*domain.ProductPlan, error) {
tx := dao.transactionContext.PgTx
productPlan := new(models.ProductPlan)
query := sqlbuilder.BuildQuery(tx.Model(productPlan), map[string]interface{}{})
query.Where("company_id = ?", companyId)
query.Where("org_id = ?", orgId)
query.Where("workshop->>'workshopId'='?'", workshopId)
query.Where("product_date = ?", date)
if len(productCode) > 0 {
query.Where("ext #>>'{productPlanExt,productCode}'=?", productCode)
}
query.Order("updated_at desc")
var productPlanModels = make([]*models.ProductPlan, 0)
var productPlans = make([]*domain.ProductPlan, 0)
if err := query.Select(&productPlanModels); err != nil {
return productPlans, err
} else {
for _, productPlanModel := range productPlanModels {
if productPlan, err := transform.TransformToProductPlanDomainModelFromPgModels(productPlanModel); err != nil {
return productPlans, err
} else {
productPlans = append(productPlans, productPlan)
}
}
return productPlans, nil
}
}