作者 Your Name

更新

@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 ) 9 )
10 10
11 type CreateProductRecordCommand struct { 11 type CreateProductRecordCommand struct {
12 - ProductRecordId int `json:"productRecordId"` 12 +
13 // 车间ID 13 // 车间ID
14 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` 14 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
15 // 生产线ID 15 // 生产线ID
@@ -17,7 +17,7 @@ type CreateProductRecordCommand struct { @@ -17,7 +17,7 @@ type CreateProductRecordCommand struct {
17 // 工段ID 17 // 工段ID
18 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` 18 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
19 19
20 - WorkerId int `cname:"工人ID" json:"workerId" valid:"Required"` 20 + WorkerId []int `cname:"工人ID" json:"workerId" valid:"Required"`
21 21
22 //生气计划id 22 //生气计划id
23 ProductPlanId int `cname:"生气计划id" json:"productPlanId" valid:"Required"` 23 ProductPlanId int `cname:"生气计划id" json:"productPlanId" valid:"Required"`
@@ -56,7 +56,7 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm @@ -56,7 +56,7 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm
56 return struct{}{}, nil 56 return struct{}{}, nil
57 } 57 }
58 58
59 -// 创建生产记录服务 59 +// 创建生产记录服务,二级品
60 func (productRecordService *ProductRecordService) CreateProductRecord(operateInfo *domain.OperateInfo, param *command.CreateProductRecordCommand) (interface{}, error) { 60 func (productRecordService *ProductRecordService) CreateProductRecord(operateInfo *domain.OperateInfo, param *command.CreateProductRecordCommand) (interface{}, error) {
61 if err := param.ValidateCommand(); err != nil { 61 if err := param.ValidateCommand(); err != nil {
62 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 62 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -117,13 +117,17 @@ func (productRecordService *ProductRecordService) CreateProductRecord(operateInf @@ -117,13 +117,17 @@ func (productRecordService *ProductRecordService) CreateProductRecord(operateInf
117 if err != nil { 117 if err != nil {
118 return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error()) 118 return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error())
119 } 119 }
120 - 120 + productRecordIds := []int{}
  121 + for _, workerId := range param.WorkerId {
  122 + workerData, err := userService.User(workerId)
  123 + if err != nil {
  124 + return nil, application.ThrowError(application.ARG_ERROR, "获取员工数据错误,"+err.Error())
  125 + }
121 productRecordData := &domain.ProductRecord{ 126 productRecordData := &domain.ProductRecord{
122 - ProductRecordId: param.ProductRecordId,  
123 CompanyId: operateInfo.CompanyId, 127 CompanyId: operateInfo.CompanyId,
124 OrgId: operateInfo.OrgId, 128 OrgId: operateInfo.OrgId,
125 ProductRecordType: domain.RecordTypeSecondLevelWeigh, 129 ProductRecordType: domain.RecordTypeSecondLevelWeigh,
126 - ProductWorker: user, 130 + ProductWorker: workerData,
127 WorkStation: workstation, 131 WorkStation: workstation,
128 CreatedAt: dataTime, 132 CreatedAt: dataTime,
129 UpdatedAt: time.Now(), 133 UpdatedAt: time.Now(),
@@ -150,11 +154,13 @@ func (productRecordService *ProductRecordService) CreateProductRecord(operateInf @@ -150,11 +154,13 @@ func (productRecordService *ProductRecordService) CreateProductRecord(operateInf
150 if err != nil { 154 if err != nil {
151 return nil, application.ThrowError(application.ARG_ERROR, "保存生产记录"+err.Error()) 155 return nil, application.ThrowError(application.ARG_ERROR, "保存生产记录"+err.Error())
152 } 156 }
  157 + productRecordIds = append(productRecordIds, productRecordData.ProductRecordId)
  158 + }
153 if err := transactionContext.CommitTransaction(); err != nil { 159 if err := transactionContext.CommitTransaction(); err != nil {
154 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 160 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
155 } 161 }
156 return map[string]interface{}{ 162 return map[string]interface{}{
157 - "productRecordId": productRecordData.ProductRecordId, 163 + "productRecordId": productRecordIds,
158 }, nil 164 }, nil
159 } 165 }
160 166
@@ -2,12 +2,13 @@ package repository @@ -2,12 +2,13 @@ package repository
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
  6 +
5 "github.com/go-pg/pg/v10" 7 "github.com/go-pg/pg/v10"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
10 - "time"  
11 12
12 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 13 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
13 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 14 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -176,7 +177,7 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac @@ -176,7 +177,7 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac
176 query.Where("created_at>=?", v.(time.Time)) 177 query.Where("created_at>=?", v.(time.Time))
177 } 178 }
178 if v, ok := queryOptions["productEndTime"]; ok && !((v.(time.Time)).IsZero()) { 179 if v, ok := queryOptions["productEndTime"]; ok && !((v.(time.Time)).IsZero()) {
179 - query.Where("created_at<?", v.(time.Time)) 180 + query.Where("created_at<=?", v.(time.Time))
180 } 181 }
181 if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 { 182 if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 {
182 query.Where(fmt.Sprintf(`product_record_info->>'batchNumber' like '%%%v%%'`, v)) 183 query.Where(fmt.Sprintf(`product_record_info->>'batchNumber' like '%%%v%%'`, v))