...
|
...
|
@@ -7,6 +7,7 @@ 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/productTrouble/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/dto"
|
...
|
...
|
@@ -226,8 +227,10 @@ func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.Opera |
|
|
if err != nil {
|
|
|
return application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
//汇总奖惩明细
|
|
|
err = srv.CreateRewardSummaryByProductTrouble(troubleData)
|
|
|
summaryServe, _ := domainService.NewPGRewardSummaryStaticService(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
err = summaryServe.CreateRewardSummaryByProductTrouble(troubleData)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.ARG_ERROR, "计算功过奖惩明细失败,"+err.Error())
|
|
|
}
|
...
|
...
|
@@ -442,7 +445,7 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper |
|
|
productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
summaryServe, _ := domainService.NewPGRewardSummaryStaticService(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
for i := range troubleDataList {
|
|
|
//添加事故数据
|
|
|
_, err = productTroubleRepo.Save(troubleDataList[i])
|
...
|
...
|
@@ -450,7 +453,7 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper |
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
//汇总奖惩明细
|
|
|
err = srv.CreateRewardSummaryByProductTrouble(troubleDataList[i])
|
|
|
err = summaryServe.CreateRewardSummaryByProductTrouble(troubleDataList[i])
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "计算功过奖惩明细失败,"+err.Error())
|
|
|
}
|
...
|
...
|
@@ -463,7 +466,7 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper |
|
|
}
|
|
|
|
|
|
// 奖惩汇总数据列表
|
|
|
func (srv ProductTroubleService) ListRewardSummary(param query.ListRewardSummaryQuery) (int64, []dto.RewardSummaryList, error) {
|
|
|
func (srv ProductTroubleService) ListRewardSummary(param *query.ListRewardSummaryQuery) (int64, []dto.RewardSummaryList, error) {
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
...
|
...
|
@@ -549,73 +552,73 @@ func (srv ProductTroubleService) ListRewardSummary(param query.ListRewardSummary |
|
|
}
|
|
|
|
|
|
// 根据事故数据创建奖惩汇总数据
|
|
|
func (srv ProductTroubleService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
rewardSummaryRepo, _ := factory.CreateRewardSummaryRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
//查询是否已经有汇总数据
|
|
|
condtion := map[string]interface{}{
|
|
|
"orgId": param.OrgId,
|
|
|
"companyId": param.CompanyId,
|
|
|
"lineId": param.WorkStation.LineId,
|
|
|
"sectionId": param.WorkStation.SectionId,
|
|
|
"workshopId": param.WorkStation.WorkshopId,
|
|
|
"workerId": param.ProductWorker.UserId,
|
|
|
"recordDateStr": param.RecordDate.Format("200-01-02"),
|
|
|
}
|
|
|
|
|
|
_, summaryList, err := rewardSummaryRepo.Find(condtion)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var summaryData *domain.RewardSummary
|
|
|
nowTime := time.Now()
|
|
|
if len(summaryList) > 0 {
|
|
|
summaryData = summaryList[0]
|
|
|
} else {
|
|
|
summaryData = &domain.RewardSummary{
|
|
|
Id: 0,
|
|
|
CompanyId: param.CompanyId,
|
|
|
OrgId: param.OrgId,
|
|
|
WorkStation: param.WorkStation,
|
|
|
Worker: param.ProductWorker,
|
|
|
RecordDate: param.RecordDate,
|
|
|
RecordDateStr: param.RecordDate.Format("2006-01-02"),
|
|
|
UpToStandard: 0.0,
|
|
|
Yield: 0.0,
|
|
|
AccidentNum1: 0,
|
|
|
AccidentAmount1: 0.0,
|
|
|
AccidentNum2: 0,
|
|
|
AccidentAmount2: 0.0,
|
|
|
AccidentNum3: 0,
|
|
|
AccidentNum4: 0,
|
|
|
SummaryResult: 0.0,
|
|
|
CreatedAt: nowTime,
|
|
|
UpdatedAt: nowTime,
|
|
|
}
|
|
|
}
|
|
|
// 将审核过的事故放入汇总数据计算
|
|
|
summaryData.SummaryAccident(param)
|
|
|
summaryData.UpdatedAt = nowTime
|
|
|
_, err = rewardSummaryRepo.Save(summaryData)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
} |
|
|
// func (srv ProductTroubleService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error {
|
|
|
// transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
// if err != nil {
|
|
|
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
// }
|
|
|
// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
// }
|
|
|
// defer func() {
|
|
|
// transactionContext.RollbackTransaction()
|
|
|
// }()
|
|
|
|
|
|
// rewardSummaryRepo, _ := factory.CreateRewardSummaryRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
// })
|
|
|
|
|
|
// //查询是否已经有汇总数据
|
|
|
// condtion := map[string]interface{}{
|
|
|
// "orgId": param.OrgId,
|
|
|
// "companyId": param.CompanyId,
|
|
|
// "lineId": param.WorkStation.LineId,
|
|
|
// "sectionId": param.WorkStation.SectionId,
|
|
|
// "workshopId": param.WorkStation.WorkshopId,
|
|
|
// "workerId": param.ProductWorker.UserId,
|
|
|
// "recordDateStr": param.RecordDate.Format("200-01-02"),
|
|
|
// }
|
|
|
|
|
|
// _, summaryList, err := rewardSummaryRepo.Find(condtion)
|
|
|
// if err != nil {
|
|
|
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// }
|
|
|
|
|
|
// var summaryData *domain.RewardSummary
|
|
|
// nowTime := time.Now()
|
|
|
// if len(summaryList) > 0 {
|
|
|
// summaryData = summaryList[0]
|
|
|
// } else {
|
|
|
// summaryData = &domain.RewardSummary{
|
|
|
// Id: 0,
|
|
|
// CompanyId: param.CompanyId,
|
|
|
// OrgId: param.OrgId,
|
|
|
// WorkStation: param.WorkStation,
|
|
|
// Worker: param.ProductWorker,
|
|
|
// RecordDate: param.RecordDate,
|
|
|
// RecordDateStr: param.RecordDate.Format("2006-01-02"),
|
|
|
// UpToStandard: 0.0,
|
|
|
// Yield: 0.0,
|
|
|
// AccidentNum1: 0,
|
|
|
// AccidentAmount1: 0.0,
|
|
|
// AccidentNum2: 0,
|
|
|
// AccidentAmount2: 0.0,
|
|
|
// AccidentNum3: 0,
|
|
|
// AccidentNum4: 0,
|
|
|
// SummaryResult: 0.0,
|
|
|
// CreatedAt: nowTime,
|
|
|
// UpdatedAt: nowTime,
|
|
|
// }
|
|
|
// }
|
|
|
// // 将审核过的事故放入汇总数据计算
|
|
|
// summaryData.SummaryAccident(param)
|
|
|
// summaryData.UpdatedAt = nowTime
|
|
|
// _, err = rewardSummaryRepo.Save(summaryData)
|
|
|
// if err != nil {
|
|
|
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// }
|
|
|
// if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
// }
|
|
|
// return nil
|
|
|
// } |
...
|
...
|
|