pg_reward_summary_statics_service.go
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package domainService
import (
"fmt"
"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/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
)
//功过奖惩明细汇总
type PGRewardSummaryStaticService struct {
transactionContext *pgTransaction.TransactionContext
}
func NewPGRewardSummaryStaticService(transactionContext *pgTransaction.TransactionContext) (*PGRewardSummaryStaticService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &PGRewardSummaryStaticService{
transactionContext: transactionContext,
}, nil
}
}
// 根据
func (c *PGRewardSummaryStaticService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error {
rewardSummaryRepo, _ := repository.NewRewardSummaryRepository(c.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)
//获取奖惩标准 按
rewardStandardRepo, _ := repository.NewRewardStandardRepository(c.transactionContext)
rewardStandardRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"orgId": param.OrgId,
})
summaryData.UpdatedAt = nowTime
_, err = rewardSummaryRepo.Save(summaryData)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}