|
@@ -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,44 +117,50 @@ func (productRecordService *ProductRecordService) CreateProductRecord(operateInf |
|
@@ -117,44 +117,50 @@ 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
|
-
|
|
|
121
|
- productRecordData := &domain.ProductRecord{
|
|
|
122
|
- ProductRecordId: param.ProductRecordId,
|
|
|
123
|
- CompanyId: operateInfo.CompanyId,
|
|
|
124
|
- OrgId: operateInfo.OrgId,
|
|
|
125
|
- ProductRecordType: domain.RecordTypeSecondLevelWeigh,
|
|
|
126
|
- ProductWorker: user,
|
|
|
127
|
- WorkStation: workstation,
|
|
|
128
|
- CreatedAt: dataTime,
|
|
|
129
|
- UpdatedAt: time.Now(),
|
|
|
130
|
- ProductRecordInfo: &domain.ProductRecordInfo{
|
|
|
131
|
- ProductDate: productPlanData.ProductDate.Local().Format("2006-01-02"),
|
|
|
132
|
- Original: param.Weigh,
|
|
|
133
|
- Weigh: utils.Round(param.Weigh, 1),
|
|
|
134
|
- WeighBefore: utils.Round(param.Weigh, 1),
|
|
|
135
|
- UnitConversionId: 0,
|
|
|
136
|
- ApproveStatus: domain.ProductRecordNotApprove,
|
|
|
137
|
- ProductPlanId: productPlanData.ProductPlanId,
|
|
|
138
|
- BatchNumber: productPlanData.BatchNumber,
|
|
|
139
|
- PlanProductName: productPlanData.PlanProductName,
|
|
|
140
|
- ProductGroupId: 0,
|
|
|
141
|
- WorkOn: productPlanData.WorkOn,
|
|
|
142
|
- },
|
|
|
143
|
- Ext: domain.NewExt(org.OrgName),
|
|
|
144
|
- }
|
|
|
145
|
- //保存并审核
|
|
|
146
|
- if param.SaveAndApprove {
|
|
|
147
|
- productRecordData.Approve(user, param.Weigh, time.Now(), domain.ProductRecordApproved)
|
|
|
148
|
- }
|
|
|
149
|
- _, err = productRecordRepo.Save(productRecordData)
|
|
|
150
|
- if err != nil {
|
|
|
151
|
- return nil, application.ThrowError(application.ARG_ERROR, "保存生产记录"+err.Error())
|
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
|
+ }
|
|
|
126
|
+ productRecordData := &domain.ProductRecord{
|
|
|
127
|
+ CompanyId: operateInfo.CompanyId,
|
|
|
128
|
+ OrgId: operateInfo.OrgId,
|
|
|
129
|
+ ProductRecordType: domain.RecordTypeSecondLevelWeigh,
|
|
|
130
|
+ ProductWorker: workerData,
|
|
|
131
|
+ WorkStation: workstation,
|
|
|
132
|
+ CreatedAt: dataTime,
|
|
|
133
|
+ UpdatedAt: time.Now(),
|
|
|
134
|
+ ProductRecordInfo: &domain.ProductRecordInfo{
|
|
|
135
|
+ ProductDate: productPlanData.ProductDate.Local().Format("2006-01-02"),
|
|
|
136
|
+ Original: param.Weigh,
|
|
|
137
|
+ Weigh: utils.Round(param.Weigh, 1),
|
|
|
138
|
+ WeighBefore: utils.Round(param.Weigh, 1),
|
|
|
139
|
+ UnitConversionId: 0,
|
|
|
140
|
+ ApproveStatus: domain.ProductRecordNotApprove,
|
|
|
141
|
+ ProductPlanId: productPlanData.ProductPlanId,
|
|
|
142
|
+ BatchNumber: productPlanData.BatchNumber,
|
|
|
143
|
+ PlanProductName: productPlanData.PlanProductName,
|
|
|
144
|
+ ProductGroupId: 0,
|
|
|
145
|
+ WorkOn: productPlanData.WorkOn,
|
|
|
146
|
+ },
|
|
|
147
|
+ Ext: domain.NewExt(org.OrgName),
|
|
|
148
|
+ }
|
|
|
149
|
+ //保存并审核
|
|
|
150
|
+ if param.SaveAndApprove {
|
|
|
151
|
+ productRecordData.Approve(user, param.Weigh, time.Now(), domain.ProductRecordApproved)
|
|
|
152
|
+ }
|
|
|
153
|
+ _, err = productRecordRepo.Save(productRecordData)
|
|
|
154
|
+ if err != nil {
|
|
|
155
|
+ return nil, application.ThrowError(application.ARG_ERROR, "保存生产记录"+err.Error())
|
|
|
156
|
+ }
|
|
|
157
|
+ productRecordIds = append(productRecordIds, productRecordData.ProductRecordId)
|
152
|
}
|
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
|
|