...
|
...
|
@@ -30,7 +30,7 @@ func (productRecordService *ProductRecordService) SaveProductCapacities(operateI |
|
|
}()
|
|
|
|
|
|
//日期
|
|
|
recordDate, err := time.ParseInLocation("2006-01-02", param.RecordDate, time.Local)
|
|
|
recordDate, err := time.Parse("2006-01-02", param.RecordDate)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
|
|
|
}
|
...
|
...
|
@@ -156,12 +156,12 @@ func (productRecordService *ProductRecordService) ListProductCapacities(operateI |
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
productBeginTime, _ := time.ParseInLocation("2006-01-02", param.ProductBeginTime, time.Local)
|
|
|
productEndTime, _ := time.ParseInLocation("2006-01-02", param.ProductEndTime, time.Local)
|
|
|
productBeginTime, _ := time.Parse("2006-01-02", param.ProductBeginTime)
|
|
|
productEndTime, _ := time.Parse("2006-01-02", param.ProductEndTime)
|
|
|
condition := map[string]interface{}{
|
|
|
"companyId": param.CompanyId,
|
|
|
"orgId": param.OrgId,
|
|
|
"workerName": param.WorkerName,
|
|
|
"userName": param.WorkerName,
|
|
|
"workshopName": param.WorkshopName,
|
|
|
"lineName": param.LineName,
|
|
|
"sectionName": param.SectionName,
|
...
|
...
|
@@ -540,3 +540,117 @@ func (srv *ProductRecordService) BatchAddProductCapacities(operate *domain.Opera |
|
|
}
|
|
|
return failRows, nil
|
|
|
}
|
|
|
|
|
|
// 产能管理 页面上手动创建员工生产记录
|
|
|
func (productRecordService *ProductRecordService) CreateProductCapacities(operateInfo *domain.OperateInfo, param *command.CreateProductCapacitiesCmd) (map[string]interface{}, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
//日期
|
|
|
recordDate, err := time.Parse("2006-01-02", param.RecordDate)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
|
|
|
}
|
|
|
userService := domainService.NewUserService()
|
|
|
//操作人数据
|
|
|
var user *domain.User
|
|
|
user, err = userService.User(operateInfo.UserId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取操作人错误,"+err.Error())
|
|
|
}
|
|
|
//组织数据
|
|
|
var org *domain.Org
|
|
|
org, err = userService.Organization(operateInfo.OrgId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
//车间数据
|
|
|
workshopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
workshop, err := workshopRepo.FindOne(map[string]interface{}{"workshopId": param.WorkshopId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取车间数据失败"+err.Error())
|
|
|
}
|
|
|
workstation, err := workshop.FindWorkStation(param.WorkshopId, param.LineId, param.SectionId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error())
|
|
|
}
|
|
|
|
|
|
//获取生产记录
|
|
|
productPlanRepo, _ := factory.CreateProductPlanRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
planData, err := productPlanRepo.FindOne(map[string]interface{}{
|
|
|
"productPlanId": param.ProductPlanId,
|
|
|
})
|
|
|
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取计划任务数据失败"+err.Error())
|
|
|
}
|
|
|
|
|
|
//员工生产记录
|
|
|
productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
nowTime := time.Now()
|
|
|
productRecordIds := []int{}
|
|
|
for _, workerId := range param.WorkerId {
|
|
|
//员工数据
|
|
|
worker, err := userService.User(workerId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取员工错误,"+err.Error())
|
|
|
}
|
|
|
epRecord := &domain.ProductRecord{
|
|
|
UpdatedAt: nowTime,
|
|
|
OrgId: operateInfo.OrgId,
|
|
|
CompanyId: operateInfo.CompanyId,
|
|
|
WorkStation: workstation,
|
|
|
ProductWorker: worker,
|
|
|
CreatedAt: recordDate,
|
|
|
Ext: &domain.Ext{
|
|
|
Operator: user,
|
|
|
OrgName: org.OrgName,
|
|
|
},
|
|
|
ProductRecordType: domain.RecordTypeReceiveMaterial,
|
|
|
ProductRecordInfo: &domain.ProductRecordInfo{
|
|
|
WorkOn: param.WorkOn,
|
|
|
ProductDate: param.RecordDate,
|
|
|
Weigh: param.Weigh,
|
|
|
WeighBefore: param.Weigh,
|
|
|
ApproveStatus: domain.ProductRecordNotApprove,
|
|
|
ApproveAt: 0,
|
|
|
ApproveUser: nil,
|
|
|
ProductPlanId: planData.ProductPlanId,
|
|
|
PlanProductName: planData.PlanProductName,
|
|
|
BatchNumber: planData.BatchNumber,
|
|
|
},
|
|
|
}
|
|
|
if param.SaveAndApprove {
|
|
|
epRecord.ProductRecordInfo.ApproveAt = nowTime.Unix()
|
|
|
epRecord.ProductRecordInfo.ApproveStatus = domain.ProductRecordApproved
|
|
|
epRecord.ProductRecordInfo.ApproveUser = user
|
|
|
}
|
|
|
_, err = productRecordRepo.Save(epRecord)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "保存员工生产记录失败"+err.Error())
|
|
|
}
|
|
|
productRecordIds = append(productRecordIds, epRecord.ProductRecordId)
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"productRecordIds": productRecordIds,
|
|
|
}, nil
|
|
|
} |
...
|
...
|
|