...
|
...
|
@@ -29,7 +29,7 @@ func NewProductPlanDispatchRecord(transactionContext *pgTransaction.TransactionC |
|
|
// 日期
|
|
|
// 产品编号
|
|
|
// 调度状态 status
|
|
|
func (dao *ProductPlanDispatchRecordDao) DeviceProductPlan(companyId, orgId int, workStationId string, date time.Time, productCode string, status int) (*domain.ProductPlanDispatchRecord, error) {
|
|
|
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{}{})
|
...
|
...
|
@@ -37,7 +37,9 @@ func (dao *ProductPlanDispatchRecordDao) DeviceProductPlan(companyId, orgId int, |
|
|
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 {
|
...
|
...
|
@@ -53,3 +55,57 @@ func (dao *ProductPlanDispatchRecordDao) DeviceProductPlan(companyId, orgId int, |
|
|
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
|
|
|
}
|
|
|
} |
...
|
...
|
|