正在显示
5 个修改的文件
包含
230 行增加
和
21 行删除
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | -import "time" | 3 | +import ( |
| 4 | + "strconv" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 4 | 7 | ||
| 5 | // RewardStandard 奖惩规则 | 8 | // RewardStandard 奖惩规则 |
| 6 | type RewardRule struct { | 9 | type RewardRule struct { |
| @@ -25,7 +28,7 @@ type RewardRuleRepository interface { | @@ -25,7 +28,7 @@ type RewardRuleRepository interface { | ||
| 25 | } | 28 | } |
| 26 | 29 | ||
| 27 | func (m *RewardRule) ValidRewardTag() bool { | 30 | func (m *RewardRule) ValidRewardTag() bool { |
| 28 | - switch m.FaultTag { | 31 | + switch m.RewardTag { |
| 29 | case ">": | 32 | case ">": |
| 30 | default: | 33 | default: |
| 31 | return false | 34 | return false |
| @@ -41,3 +44,17 @@ func (m *RewardRule) ValidFaultTag() bool { | @@ -41,3 +44,17 @@ func (m *RewardRule) ValidFaultTag() bool { | ||
| 41 | } | 44 | } |
| 42 | return true | 45 | return true |
| 43 | } | 46 | } |
| 47 | + | ||
| 48 | +// 计算奖惩 的金额 | ||
| 49 | +func (m *RewardRule) SumRewardAmount(rewardNum int, faultNum int) float64 { | ||
| 50 | + result := float64(0) | ||
| 51 | + rewardAmount, _ := strconv.ParseFloat(m.RewardAmount, 64) | ||
| 52 | + faultAmount, _ := strconv.ParseFloat(m.FaultAmount, 64) | ||
| 53 | + if rewardNum > m.RewardNum { | ||
| 54 | + result += rewardAmount | ||
| 55 | + } | ||
| 56 | + if faultNum > m.FaultNum { | ||
| 57 | + result -= faultAmount | ||
| 58 | + } | ||
| 59 | + return result | ||
| 60 | +} |
| @@ -145,19 +145,109 @@ func (m *RewardStandard) ShowTargeFault() string { | @@ -145,19 +145,109 @@ func (m *RewardStandard) ShowTargeFault() string { | ||
| 145 | show := "" | 145 | show := "" |
| 146 | switch m.TargetType { | 146 | switch m.TargetType { |
| 147 | case TargetType1: | 147 | case TargetType1: |
| 148 | - show = fmt.Sprintf("<%skg/小时", m.TargeVal1) | 148 | + show = fmt.Sprintf("<%skg/小时", m.TargeVal2) |
| 149 | case TargetType2: | 149 | case TargetType2: |
| 150 | - show = fmt.Sprintf("<%s%%", m.TargeVal1) | 150 | + show = fmt.Sprintf("<%s%%", m.TargeVal2) |
| 151 | case TargetType3: | 151 | case TargetType3: |
| 152 | - show = fmt.Sprintf(">%s次或损失>%s元", m.TargeVal1, m.TargeVal2) | 152 | + show = fmt.Sprintf(">%s次或损失>%s元", m.TargeVal3, m.TargeVal4) |
| 153 | case TargetType4: | 153 | case TargetType4: |
| 154 | - show = fmt.Sprintf("<=%s次或损失>%s元", m.TargeVal1, m.TargeVal2) | 154 | + show = fmt.Sprintf("<=%s次或损失>%s元", m.TargeVal3, m.TargeVal4) |
| 155 | case TargetType5: | 155 | case TargetType5: |
| 156 | - show = fmt.Sprintf("金属>%s次或非金属>%s", m.TargeVal1, m.TargeVal2) | 156 | + show = fmt.Sprintf("金属>%s次或非金属>%s", m.TargeVal3, m.TargeVal4) |
| 157 | } | 157 | } |
| 158 | return show | 158 | return show |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | -func (m *RewardStandard) VerdictTarget(val1 int, val float64) int { | 161 | +// 判定功过, 指标类别 1:产效 |
| 162 | +func (m *RewardStandard) VerdictTargetType1(val1 int, val float64) int { | ||
| 162 | return 0 | 163 | return 0 |
| 163 | } | 164 | } |
| 165 | + | ||
| 166 | +// 判定功过, 指标类别 2:合格率 | ||
| 167 | +func (m *RewardStandard) VerdictTargetType2(val1 int, val float64) int { | ||
| 168 | + return 0 | ||
| 169 | +} | ||
| 170 | + | ||
| 171 | +// 判定功过, 指标类别 3:安全事故; | ||
| 172 | +// param1 安全事故次数; | ||
| 173 | +// param1 损失金额; | ||
| 174 | +// 功过结果 0 无,1 功 ,-1 过; | ||
| 175 | +func (m *RewardStandard) VerdictTargetType3(param1 int, param2 float64) int { | ||
| 176 | + val1, _ := strconv.Atoi(m.TargeVal1) | ||
| 177 | + val2, _ := strconv.ParseFloat(m.TargeVal2, 64) | ||
| 178 | + result := 0 | ||
| 179 | + //判定功 | ||
| 180 | + if param1 <= val1 { | ||
| 181 | + result = 1 | ||
| 182 | + } | ||
| 183 | + if param2 <= val2 { | ||
| 184 | + result = 1 | ||
| 185 | + } | ||
| 186 | + //判定过 | ||
| 187 | + val3, _ := strconv.Atoi(m.TargeVal3) | ||
| 188 | + val4, _ := strconv.ParseFloat(m.TargeVal4, 64) | ||
| 189 | + | ||
| 190 | + if param1 > val3 { | ||
| 191 | + result = -1 | ||
| 192 | + } | ||
| 193 | + if param2 > val4 { | ||
| 194 | + result = -1 | ||
| 195 | + } | ||
| 196 | + return result | ||
| 197 | +} | ||
| 198 | + | ||
| 199 | +// 判定功过, 指标类别 4:质量事故; | ||
| 200 | +// param1 质量事故 次数; | ||
| 201 | +// param1 损失金额; | ||
| 202 | +// 功过结果 0 无,1 功 ,-1 过; | ||
| 203 | +func (m *RewardStandard) VerdictTargetType4(param1 int, param2 float64) int { | ||
| 204 | + val1, _ := strconv.Atoi(m.TargeVal1) | ||
| 205 | + val2, _ := strconv.ParseFloat(m.TargeVal2, 64) | ||
| 206 | + result := 0 | ||
| 207 | + //判定功 | ||
| 208 | + if param1 <= val1 { | ||
| 209 | + result = 1 | ||
| 210 | + } | ||
| 211 | + if param2 <= val2 { | ||
| 212 | + result = 1 | ||
| 213 | + } | ||
| 214 | + //判定过 | ||
| 215 | + val3, _ := strconv.Atoi(m.TargeVal3) | ||
| 216 | + val4, _ := strconv.ParseFloat(m.TargeVal4, 64) | ||
| 217 | + | ||
| 218 | + if param1 > val3 { | ||
| 219 | + result = -1 | ||
| 220 | + } | ||
| 221 | + if param2 > val4 { | ||
| 222 | + result = -1 | ||
| 223 | + } | ||
| 224 | + return result | ||
| 225 | +} | ||
| 226 | + | ||
| 227 | +// 判定功过, 指标类别 5:异物次数; | ||
| 228 | +// param1 金属异物 次数; | ||
| 229 | +// param2 非金属 次数; | ||
| 230 | +// 功过结果 0 无,1 功 ,-1 过; | ||
| 231 | +func (m *RewardStandard) VerdictTargetType5(param1 int, param2 int) int { | ||
| 232 | + val1, _ := strconv.Atoi(m.TargeVal1) | ||
| 233 | + val2, _ := strconv.Atoi(m.TargeVal2) | ||
| 234 | + result := 0 | ||
| 235 | + //判定功 | ||
| 236 | + if param1 <= val1 { | ||
| 237 | + result = 1 | ||
| 238 | + } | ||
| 239 | + if param2 <= val2 { | ||
| 240 | + result = 1 | ||
| 241 | + } | ||
| 242 | + //判定过 | ||
| 243 | + val3, _ := strconv.Atoi(m.TargeVal3) | ||
| 244 | + val4, _ := strconv.Atoi(m.TargeVal4) | ||
| 245 | + | ||
| 246 | + if param1 > val3 { | ||
| 247 | + result = -1 | ||
| 248 | + } | ||
| 249 | + if param2 > val4 { | ||
| 250 | + result = -1 | ||
| 251 | + } | ||
| 252 | + return result | ||
| 253 | +} |
| @@ -14,19 +14,19 @@ type RewardSummary struct { | @@ -14,19 +14,19 @@ type RewardSummary struct { | ||
| 14 | WorkStation WorkStation `json:"workStation"` //工作位置 | 14 | WorkStation WorkStation `json:"workStation"` //工作位置 |
| 15 | Worker User `json:"user"` //员工 | 15 | Worker User `json:"user"` //员工 |
| 16 | UpToStandard float64 `json:"upToStandard"` //合格率 | 16 | UpToStandard float64 `json:"upToStandard"` //合格率 |
| 17 | - UpToStandardResult float64 `json:"upToStandardResult"` //合格率 功过评定结果 `功` `过` `不奖不惩` | 17 | + UpToStandardResult int `json:"upToStandardResult"` //合格率 功过评定结果 1`功` -1 `过` 0 `不奖不惩` |
| 18 | Yield float64 `json:"yield"` //产能 | 18 | Yield float64 `json:"yield"` //产能 |
| 19 | - YieldResult float64 `json:"yieldResult"` //产能 功过评定结果 | 19 | + YieldResult int `json:"yieldResult"` //产能 功过评定结果 1`功` -1 `过` 0 `不奖不惩` |
| 20 | AccidentNum1 int `json:"accidentNum1"` //质量事故 次数 | 20 | AccidentNum1 int `json:"accidentNum1"` //质量事故 次数 |
| 21 | AccidentAmount1 float64 `json:"accidentAmount1"` //质量事故 损失金额 | 21 | AccidentAmount1 float64 `json:"accidentAmount1"` //质量事故 损失金额 |
| 22 | - AccidentResult1 string `json:"accidentResult1"` //质量事故 功过评定结果 | 22 | + AccidentResult1 int `json:"accidentResult1"` //质量事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩` |
| 23 | AccidentNum2 int `json:"accidentNum2"` //安全事故 次数 | 23 | AccidentNum2 int `json:"accidentNum2"` //安全事故 次数 |
| 24 | AccidentAmount2 float64 `json:"accidentAmount2"` //安全事故 损失金额 | 24 | AccidentAmount2 float64 `json:"accidentAmount2"` //安全事故 损失金额 |
| 25 | - AccidentResult2 string `json:"accidentResult2"` //安全事故 功过评定结果 | 25 | + AccidentResult2 int `json:"accidentResult2"` //安全事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩` |
| 26 | AccidentNum3 int `json:"accidentNum3"` //异物金属事故 次数 | 26 | AccidentNum3 int `json:"accidentNum3"` //异物金属事故 次数 |
| 27 | - AccidentResult3 string `json:"accidentResult3"` //异物金属事故 功过评定结果 | 27 | + AccidentResult3 int `json:"accidentResult3"` //异物金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩` |
| 28 | AccidentNum4 int `json:"accidentNum4"` //异物非金属事故 次数 | 28 | AccidentNum4 int `json:"accidentNum4"` //异物非金属事故 次数 |
| 29 | - AccidentResult4 string `json:"accidentResult4"` //异物非金属事故 功过评定结果 | 29 | + AccidentResult4 int `json:"accidentResult4"` //异物非金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩` |
| 30 | SummaryResult float64 `json:"summaryResult"` //奖惩金额计算结果(元) | 30 | SummaryResult float64 `json:"summaryResult"` //奖惩金额计算结果(元) |
| 31 | CreatedAt time.Time `json:"createdAt"` // | 31 | CreatedAt time.Time `json:"createdAt"` // |
| 32 | UpdatedAt time.Time `json:"UpdatedAt"` // | 32 | UpdatedAt time.Time `json:"UpdatedAt"` // |
| @@ -39,17 +39,82 @@ type RewardSummaryRepository interface { | @@ -39,17 +39,82 @@ type RewardSummaryRepository interface { | ||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | // SummaryAccident 汇总事故数据 | 41 | // SummaryAccident 汇总事故数据 |
| 42 | -func (c *RewardSummary) SummaryAccident(trouble *ProductTrouble) { | 42 | +func (c *RewardSummary) SummaryAccident(trouble *ProductTrouble, rewardStandard *RewardStandard) { |
| 43 | switch trouble.Types { | 43 | switch trouble.Types { |
| 44 | case TroubleType1: | 44 | case TroubleType1: |
| 45 | c.AccidentNum2 = +1 | 45 | c.AccidentNum2 = +1 |
| 46 | c.AccidentAmount2 = +trouble.AmountLoss | 46 | c.AccidentAmount2 = +trouble.AmountLoss |
| 47 | + if rewardStandard == nil { | ||
| 48 | + c.AccidentResult2 = 0 | ||
| 49 | + } else { | ||
| 50 | + r := rewardStandard.VerdictTargetType3(c.AccidentNum2, c.AccidentAmount2) | ||
| 51 | + c.AccidentResult2 = r | ||
| 52 | + } | ||
| 53 | + | ||
| 47 | case TroubleType2: | 54 | case TroubleType2: |
| 48 | c.AccidentNum1 = +1 | 55 | c.AccidentNum1 = +1 |
| 49 | c.AccidentAmount1 = +trouble.AmountLoss | 56 | c.AccidentAmount1 = +trouble.AmountLoss |
| 57 | + if rewardStandard == nil { | ||
| 58 | + c.AccidentResult1 = 0 | ||
| 59 | + } else { | ||
| 60 | + r := rewardStandard.VerdictTargetType4(c.AccidentNum1, c.AccidentAmount1) | ||
| 61 | + c.AccidentResult2 = r | ||
| 62 | + } | ||
| 63 | + | ||
| 50 | case TroubleType3: | 64 | case TroubleType3: |
| 51 | c.AccidentNum3 = +1 | 65 | c.AccidentNum3 = +1 |
| 66 | + if rewardStandard == nil { | ||
| 67 | + c.AccidentResult3 = 0 | ||
| 68 | + } else { | ||
| 69 | + r := rewardStandard.VerdictTargetType5(c.AccidentNum3, 0) | ||
| 70 | + c.AccidentResult2 = r | ||
| 71 | + } | ||
| 72 | + | ||
| 52 | case TroubleType4: | 73 | case TroubleType4: |
| 53 | c.AccidentNum4 = +1 | 74 | c.AccidentNum4 = +1 |
| 75 | + if rewardStandard == nil { | ||
| 76 | + c.AccidentResult4 = 0 | ||
| 77 | + } else { | ||
| 78 | + r := rewardStandard.VerdictTargetType5(0, c.AccidentNum4) | ||
| 79 | + c.AccidentResult2 = r | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | +} | ||
| 83 | + | ||
| 84 | +func (c *RewardSummary) ApplySummaryResult(rule *RewardRule) { | ||
| 85 | + rewardNum := 0 | ||
| 86 | + faultNum := 0 | ||
| 87 | + if c.AccidentResult1 < 0 { | ||
| 88 | + faultNum = +1 | ||
| 89 | + } else if c.AccidentResult1 > 0 { | ||
| 90 | + rewardNum = +1 | ||
| 91 | + } | ||
| 92 | + if c.AccidentResult2 < 0 { | ||
| 93 | + faultNum = +1 | ||
| 94 | + } else if c.AccidentResult2 > 0 { | ||
| 95 | + rewardNum = +1 | ||
| 54 | } | 96 | } |
| 97 | + if c.AccidentResult3 < 0 { | ||
| 98 | + faultNum = +1 | ||
| 99 | + } else if c.AccidentResult3 > 0 { | ||
| 100 | + rewardNum = +1 | ||
| 101 | + } | ||
| 102 | + if c.AccidentResult4 < 0 { | ||
| 103 | + faultNum = +1 | ||
| 104 | + } else if c.AccidentResult4 > 0 { | ||
| 105 | + rewardNum = +1 | ||
| 106 | + } | ||
| 107 | + if c.YieldResult < 0 { | ||
| 108 | + faultNum = +1 | ||
| 109 | + } else if c.YieldResult > 0 { | ||
| 110 | + rewardNum = +1 | ||
| 111 | + } | ||
| 112 | + if c.UpToStandardResult < 0 { | ||
| 113 | + faultNum = +1 | ||
| 114 | + } else if c.UpToStandardResult > 0 { | ||
| 115 | + rewardNum = +1 | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + c.SummaryResult = rule.SumRewardAmount(rewardNum, faultNum) | ||
| 119 | + | ||
| 55 | } | 120 | } |
| @@ -26,7 +26,7 @@ func NewPGRewardSummaryStaticService(transactionContext *pgTransaction.Transacti | @@ -26,7 +26,7 @@ func NewPGRewardSummaryStaticService(transactionContext *pgTransaction.Transacti | ||
| 26 | } | 26 | } |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | -// 根据 | 29 | +// 根据事故数据 |
| 30 | func (c *PGRewardSummaryStaticService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error { | 30 | func (c *PGRewardSummaryStaticService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error { |
| 31 | rewardSummaryRepo, _ := repository.NewRewardSummaryRepository(c.transactionContext) | 31 | rewardSummaryRepo, _ := repository.NewRewardSummaryRepository(c.transactionContext) |
| 32 | //查询是否已经有汇总数据 | 32 | //查询是否已经有汇总数据 |
| @@ -71,17 +71,51 @@ func (c *PGRewardSummaryStaticService) CreateRewardSummaryByProductTrouble(param | @@ -71,17 +71,51 @@ func (c *PGRewardSummaryStaticService) CreateRewardSummaryByProductTrouble(param | ||
| 71 | UpdatedAt: nowTime, | 71 | UpdatedAt: nowTime, |
| 72 | } | 72 | } |
| 73 | } | 73 | } |
| 74 | - // 将审核过的事故放入汇总数据计算 | ||
| 75 | - summaryData.SummaryAccident(param) | ||
| 76 | 74 | ||
| 77 | - //获取奖惩标准 按 | 75 | + var targetType int |
| 76 | + switch param.Types { | ||
| 77 | + case domain.TroubleType1: | ||
| 78 | + targetType = domain.TargetType3 | ||
| 79 | + case domain.TroubleType2: | ||
| 80 | + targetType = domain.TargetType4 | ||
| 81 | + case domain.TroubleType3: | ||
| 82 | + targetType = domain.TargetType5 | ||
| 83 | + case domain.TroubleType4: | ||
| 84 | + targetType = domain.TargetType5 | ||
| 85 | + } | ||
| 86 | + //获取奖惩标准 按 车间 线别 工段 类型 | ||
| 78 | rewardStandardRepo, _ := repository.NewRewardStandardRepository(c.transactionContext) | 87 | rewardStandardRepo, _ := repository.NewRewardStandardRepository(c.transactionContext) |
| 88 | + _, rewardStandardList, err := rewardStandardRepo.Find(map[string]interface{}{ | ||
| 89 | + "companyId": param.CompanyId, | ||
| 90 | + "orgId": param.OrgId, | ||
| 91 | + "workshopId": param.WorkStation.WorkshopId, | ||
| 92 | + "lineId": param.WorkStation.LineId, | ||
| 93 | + "sectionId": param.WorkStation.SectionId, | ||
| 94 | + "targetType": targetType, | ||
| 95 | + "limit": 1, | ||
| 96 | + }) | ||
| 97 | + if err != nil { | ||
| 98 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 99 | + } | ||
| 100 | + if len(rewardStandardList) > 0 { | ||
| 101 | + summaryData.SummaryAccident(param, rewardStandardList[0]) | ||
| 102 | + } else { | ||
| 103 | + summaryData.SummaryAccident(param, nil) | ||
| 104 | + } | ||
| 79 | 105 | ||
| 80 | - rewardStandardRepo.Find(map[string]interface{}{ | 106 | + //获取奖惩规则 |
| 107 | + rewardRuleRepo, _ := repository.NewRewardRuleRepository(c.transactionContext) | ||
| 108 | + _, rewardRuleList, err := rewardRuleRepo.Find(map[string]interface{}{ | ||
| 81 | "companyId": param.CompanyId, | 109 | "companyId": param.CompanyId, |
| 82 | "orgId": param.OrgId, | 110 | "orgId": param.OrgId, |
| 83 | }) | 111 | }) |
| 84 | - | 112 | + if err != nil { |
| 113 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取奖惩规则"+err.Error()) | ||
| 114 | + } | ||
| 115 | + if len(rewardRuleList) == 0 { | ||
| 116 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未设置奖惩规则") | ||
| 117 | + } | ||
| 118 | + summaryData.ApplySummaryResult(rewardRuleList[0]) | ||
| 85 | summaryData.UpdatedAt = nowTime | 119 | summaryData.UpdatedAt = nowTime |
| 86 | _, err = rewardSummaryRepo.Save(summaryData) | 120 | _, err = rewardSummaryRepo.Save(summaryData) |
| 87 | if err != nil { | 121 | if err != nil { |
| @@ -115,6 +115,9 @@ func (repo *RewardRuleRepository) Find(queryOptions map[string]interface{}) (int | @@ -115,6 +115,9 @@ func (repo *RewardRuleRepository) Find(queryOptions map[string]interface{}) (int | ||
| 115 | if v, ok := queryOptions["companyId"]; ok { | 115 | if v, ok := queryOptions["companyId"]; ok { |
| 116 | query.Where("company_id=?", v) | 116 | query.Where("company_id=?", v) |
| 117 | } | 117 | } |
| 118 | + if v, ok := queryOptions["orgId"]; ok { | ||
| 119 | + query.Where("org_id=?", v) | ||
| 120 | + } | ||
| 118 | cnt, err := query.SelectAndCount() | 121 | cnt, err := query.SelectAndCount() |
| 119 | if err != nil { | 122 | if err != nil { |
| 120 | return 0, nil, err | 123 | return 0, nil, err |
-
请 注册 或 登录 后发表评论