pg_reward_summary_statics_service.go
4.1 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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,
}
}
var targetType int
switch param.Types {
case domain.TroubleType1:
targetType = domain.TargetType3
case domain.TroubleType2:
targetType = domain.TargetType4
case domain.TroubleType3:
targetType = domain.TargetType5
case domain.TroubleType4:
targetType = domain.TargetType5
}
//获取奖惩标准 按 车间 线别 工段 类型
rewardStandardRepo, _ := repository.NewRewardStandardRepository(c.transactionContext)
_, rewardStandardList, err := rewardStandardRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"orgId": param.OrgId,
"workshopId": param.WorkStation.WorkshopId,
"lineId": param.WorkStation.LineId,
"sectionId": param.WorkStation.SectionId,
"targetType": targetType,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(rewardStandardList) > 0 {
summaryData.SummaryAccident(param, rewardStandardList[0])
} else {
summaryData.SummaryAccident(param, nil)
}
//获取奖惩规则
rewardRuleRepo, _ := repository.NewRewardRuleRepository(c.transactionContext)
_, rewardRuleList, err := rewardRuleRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"orgId": param.OrgId,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取奖惩规则"+err.Error())
}
if len(rewardRuleList) == 0 {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未设置奖惩规则")
}
summaryData.ApplySummaryResult(rewardRuleList[0])
summaryData.UpdatedAt = nowTime
_, err = rewardSummaryRepo.Save(summaryData)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}