...
|
...
|
@@ -4,13 +4,11 @@ import ( |
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/dto"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -66,61 +64,56 @@ func (productRecordService *ProductRecordService) CreateProductCapacities(operat |
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error())
|
|
|
}
|
|
|
|
|
|
//产品数据
|
|
|
productRepo, _ := factory.CreateProductRepository(map[string]interface{}{
|
|
|
//获取生产记录
|
|
|
productPlanRepo, _ := factory.CreateProductPlanRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
//获取产品
|
|
|
productData, err := productRepo.FindOne(map[string]interface{}{
|
|
|
"companyId": operateInfo.CompanyId,
|
|
|
"orgId": operateInfo.OrgId,
|
|
|
"productCode": param.ProductCode,
|
|
|
planData, err := productPlanRepo.FindOne(map[string]interface{}{
|
|
|
"productPlanId": param.ProductPlanId,
|
|
|
})
|
|
|
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取产品数据失败"+err.Error())
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取计划任务数据失败"+err.Error())
|
|
|
}
|
|
|
nowTime := time.Now()
|
|
|
|
|
|
//员工生产记录
|
|
|
eProductRecordRepo, _ := factory.CreateEmployeeProductRecordRepository(map[string]interface{}{
|
|
|
productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
var epRecord *domain.EmployeeProductRecord
|
|
|
if param.EmployeeProductRecordId != 0 {
|
|
|
epRecord, err = eProductRecordRepo.FindOne(map[string]interface{}{
|
|
|
"employeeProductRecordId": param.EmployeeProductRecordId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取员工生产记录数据失败"+err.Error())
|
|
|
}
|
|
|
} else {
|
|
|
epRecord = &domain.EmployeeProductRecord{
|
|
|
CreatedAt: nowTime,
|
|
|
OrgId: operateInfo.OrgId,
|
|
|
CompanyId: operateInfo.CompanyId,
|
|
|
}
|
|
|
}
|
|
|
epRecord.UpdatedAt = time.Now()
|
|
|
epRecord.ParticipateType = param.ParticipateType //参与类型
|
|
|
epRecord.WorkStation = workstation //车间工段
|
|
|
epRecord.ProductWorker = worker //员工
|
|
|
epRecord.WorkOn = param.WorkOn //上班班次
|
|
|
epRecord.CreatedAt = recordDate //日期
|
|
|
epRecord.Ext = &domain.Ext{
|
|
|
Operator: user,
|
|
|
OrgName: org.OrgName,
|
|
|
}
|
|
|
epRecord.ProductWeigh = param.Weigh //重量
|
|
|
if epRecord.ProductRecordInfo == nil {
|
|
|
epRecord.ProductRecordInfo = &domain.ProductRecordStaticInfo{}
|
|
|
}
|
|
|
epRecord.ProductRecordInfo.OutputWeight = param.Weigh //重量
|
|
|
epRecord.ProductRecordInfo.PlanProductName = productData.ProductName //产品名称
|
|
|
epRecord.ProductRecordInfo.PlanProductCode = productData.ProductCode //产品编码
|
|
|
epRecord.ProductRecordInfo.OutputWeight = param.Weigh //重量
|
|
|
_, err = eProductRecordRepo.Save(epRecord)
|
|
|
nowTime := time.Now()
|
|
|
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
|
|
|
}
|
|
|
// epRecord.ParticipateType = param.ParticipateType //参与类型
|
|
|
_, err = productRecordRepo.Save(epRecord)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "保存员工生产记录失败"+err.Error())
|
|
|
}
|
...
|
...
|
@@ -128,7 +121,7 @@ func (productRecordService *ProductRecordService) CreateProductCapacities(operat |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"employeeProductRecordId": epRecord.EmployeeProductRecordId,
|
|
|
"productRecordId": epRecord.ProductRecordId,
|
|
|
}, nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -144,7 +137,11 @@ func (productRecordService *ProductRecordService) ListProductCapacities(operateI |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
productRecordRepository, _ := dao.NewEmployeeProductRecordDao(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
|
|
|
productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
productBeginTime, _ := time.ParseInLocation("2006-01-02", param.ProductBeginTime, time.Local)
|
|
|
productEndTime, _ := time.ParseInLocation("2006-01-02", param.ProductEndTime, time.Local)
|
|
|
condition := map[string]interface{}{
|
...
|
...
|
@@ -166,7 +163,7 @@ func (productRecordService *ProductRecordService) ListProductCapacities(operateI |
|
|
if offset >= 0 {
|
|
|
condition["offset"] = limit
|
|
|
}
|
|
|
count, productRecords, err := productRecordRepository.SearchEmployeeProductRecord(condition)
|
|
|
count, productRecords, err := productRecordRepo.Find(condition)
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -177,17 +174,17 @@ func (productRecordService *ProductRecordService) ListProductCapacities(operateI |
|
|
var result = make([]dto.ProductCapacitiesList, 0)
|
|
|
for _, v := range productRecords {
|
|
|
item := dto.ProductCapacitiesList{
|
|
|
EmployeeProductRecordId: v.EmployeeProductRecordId,
|
|
|
WorkshopName: v.WorkStation.WorkshopName,
|
|
|
LineName: v.WorkStation.LineName,
|
|
|
SectionName: v.WorkStation.SectionName,
|
|
|
WorkerName: v.ProductWorker.UserName,
|
|
|
EmployeeType: v.ProductWorker.EmployeeType,
|
|
|
ProductName: v.ProductRecordInfo.PlanProductName,
|
|
|
ParticipateType: v.ParticipateType,
|
|
|
ProductWeigh: v.ProductRecordInfo.OutputWeight,
|
|
|
CreatedAt: v.CreatedAt.Format("2006-01-02"),
|
|
|
ApproveStatus: v.ApproveStatus,
|
|
|
ProductRecordId: v.ProductRecordId,
|
|
|
WorkshopName: v.WorkStation.WorkshopName,
|
|
|
LineName: v.WorkStation.LineName,
|
|
|
SectionName: v.WorkStation.SectionName,
|
|
|
WorkerName: v.ProductWorker.UserName,
|
|
|
EmployeeType: v.ProductWorker.EmployeeType,
|
|
|
ProductName: v.ProductRecordInfo.PlanProductName,
|
|
|
// ParticipateType: v.ParticipateType,
|
|
|
ProductWeigh: v.ProductRecordInfo.Weigh,
|
|
|
CreatedAt: v.CreatedAt.Format("2006-01-02"),
|
|
|
ApproveStatus: v.ProductRecordInfo.ApproveStatus,
|
|
|
}
|
|
|
result = append(result, item)
|
|
|
}
|
...
|
...
|
@@ -207,12 +204,12 @@ func (productRecordService *ProductRecordService) GetProductCapacities(operateIn |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
eProductRecordRepo, _ := factory.CreateEmployeeProductRecordRepository(map[string]interface{}{
|
|
|
productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
recordData, err := eProductRecordRepo.FindOne(map[string]interface{}{
|
|
|
"employeeProductRecordId": id,
|
|
|
recordData, err := productRecordRepo.FindOne(map[string]interface{}{
|
|
|
"productRecordId": id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -223,21 +220,21 @@ func (productRecordService *ProductRecordService) GetProductCapacities(operateIn |
|
|
}
|
|
|
|
|
|
var result = dto.ProductCapacitiesInfo{
|
|
|
EmployeeProductRecordId: recordData.EmployeeProductRecordId,
|
|
|
WorkshopId: recordData.WorkStation.WorkshopId,
|
|
|
WorkshopName: recordData.WorkStation.WorkshopName,
|
|
|
LineId: recordData.WorkStation.LineId,
|
|
|
LineName: recordData.WorkStation.LineName,
|
|
|
SectionId: recordData.WorkStation.SectionId,
|
|
|
SectionName: recordData.WorkStation.SectionName,
|
|
|
WorkerId: recordData.ProductWorker.UserId,
|
|
|
WorkerName: recordData.ProductWorker.UserName,
|
|
|
Weigh: recordData.ProductRecordInfo.OutputWeight,
|
|
|
ProductCode: recordData.ProductRecordInfo.PlanProductCode,
|
|
|
ProductName: recordData.ProductRecordInfo.PlanProductName,
|
|
|
ParticipateType: recordData.ParticipateType,
|
|
|
RecordDate: recordData.CreatedAt.Format("2006-01-02"),
|
|
|
WorkOn: recordData.WorkOn,
|
|
|
ProductRecordId: recordData.ProductRecordId,
|
|
|
WorkshopId: recordData.WorkStation.WorkshopId,
|
|
|
WorkshopName: recordData.WorkStation.WorkshopName,
|
|
|
LineId: recordData.WorkStation.LineId,
|
|
|
LineName: recordData.WorkStation.LineName,
|
|
|
SectionId: recordData.WorkStation.SectionId,
|
|
|
SectionName: recordData.WorkStation.SectionName,
|
|
|
WorkerId: recordData.ProductWorker.UserId,
|
|
|
WorkerName: recordData.ProductWorker.UserName,
|
|
|
Weigh: recordData.ProductRecordInfo.Weigh,
|
|
|
ProductCode: recordData.ProductRecordInfo.BatchNumber,
|
|
|
ProductName: recordData.ProductRecordInfo.PlanProductName,
|
|
|
// ParticipateType: recordData.ParticipateType,
|
|
|
RecordDate: recordData.CreatedAt.Format("2006-01-02"),
|
|
|
WorkOn: recordData.ProductRecordInfo.WorkOn,
|
|
|
}
|
|
|
|
|
|
return &result, nil
|
...
|
...
|
@@ -256,12 +253,12 @@ func (productRecordService *ProductRecordService) DeleteProductCapacities(operat |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
eProductRecordRepo, _ := factory.CreateEmployeeProductRecordRepository(map[string]interface{}{
|
|
|
eProductRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
recordData, err := eProductRecordRepo.FindOne(map[string]interface{}{
|
|
|
"employeeProductRecordId": id,
|
|
|
"productRecordId": id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -275,7 +272,7 @@ func (productRecordService *ProductRecordService) DeleteProductCapacities(operat |
|
|
}
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"employeeProductRecordId": recordData.EmployeeProductRecordId,
|
|
|
"productRecordId": recordData.ProductRecordId,
|
|
|
}, nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -292,12 +289,12 @@ func (productRecordService *ProductRecordService) ApproveProductCapacities(opera |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
eProductRecordRepo, _ := factory.CreateEmployeeProductRecordRepository(map[string]interface{}{
|
|
|
productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
recordData, err := eProductRecordRepo.FindOne(map[string]interface{}{
|
|
|
"employeeProductRecordId": id,
|
|
|
recordData, err := productRecordRepo.FindOne(map[string]interface{}{
|
|
|
"productRecordId": id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -310,12 +307,11 @@ func (productRecordService *ProductRecordService) ApproveProductCapacities(opera |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取操作人错误,"+err.Error())
|
|
|
}
|
|
|
|
|
|
nowTime := time.Now()
|
|
|
recordData.ApproveAt = &nowTime
|
|
|
recordData.ApproveStatus = 1
|
|
|
recordData.ApproveUser = user
|
|
|
_, err = eProductRecordRepo.Save(recordData)
|
|
|
err = recordData.Approve(user, recordData.ProductRecordInfo.Weigh, time.Now(), domain.ProductRecordApproved)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
_, err = productRecordRepo.Save(recordData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "保存数据错误,"+err.Error())
|
|
|
}
|
...
|
...
|
@@ -323,6 +319,6 @@ func (productRecordService *ProductRecordService) ApproveProductCapacities(opera |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"employeeProductRecordId": recordData.EmployeeProductRecordId,
|
|
|
"productRecordId": recordData.ProductRecordId,
|
|
|
}, nil
|
|
|
} |
...
|
...
|
|