作者 Your Name

更新奖惩汇总统计

@@ -159,13 +159,33 @@ func (m *RewardStandard) ShowTargeFault() string { @@ -159,13 +159,33 @@ func (m *RewardStandard) ShowTargeFault() string {
159 } 159 }
160 160
161 // 判定功过, 指标类别 1:产效 161 // 判定功过, 指标类别 1:产效
162 -func (m *RewardStandard) VerdictTargetType1(val1 int, val float64) int {  
163 - return 0 162 +// param1 产效值
  163 +// 功过结果 0 无,1 功 ,-1 过;
  164 +func (m *RewardStandard) VerdictTargetType1(param1 float64) int {
  165 + val1, _ := strconv.ParseFloat(m.TargeVal1, 64)
  166 + val2, _ := strconv.ParseFloat(m.TargeVal2, 64)
  167 + result := 0
  168 + if param1 > val1 {
  169 + result = 1
  170 + } else if param1 < val2 {
  171 + result = -1
  172 + }
  173 + return result
164 } 174 }
165 175
166 // 判定功过, 指标类别 2:合格率 176 // 判定功过, 指标类别 2:合格率
167 -func (m *RewardStandard) VerdictTargetType2(val1 int, val float64) int {  
168 - return 0 177 +// param1 合格率
  178 +// 功过结果 0 无,1 功 ,-1 过;
  179 +func (m *RewardStandard) VerdictTargetType2(param1 float64) int {
  180 + val1, _ := strconv.ParseFloat(m.TargeVal1, 64)
  181 + val2, _ := strconv.ParseFloat(m.TargeVal2, 64)
  182 + result := 0
  183 + if param1 > val1 {
  184 + result = 1
  185 + } else if param1 < val2 {
  186 + result = -1
  187 + }
  188 + return result
169 } 189 }
170 190
171 // 判定功过, 指标类别 3:安全事故; 191 // 判定功过, 指标类别 3:安全事故;
@@ -24,9 +24,8 @@ type RewardSummary struct { @@ -24,9 +24,8 @@ type RewardSummary struct {
24 AccidentAmount2 float64 `json:"accidentAmount2"` //安全事故 损失金额 24 AccidentAmount2 float64 `json:"accidentAmount2"` //安全事故 损失金额
25 AccidentResult2 int `json:"accidentResult2"` //安全事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩` 25 AccidentResult2 int `json:"accidentResult2"` //安全事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
26 AccidentNum3 int `json:"accidentNum3"` //异物金属事故 次数 26 AccidentNum3 int `json:"accidentNum3"` //异物金属事故 次数
27 - AccidentResult3 int `json:"accidentResult3"` //异物金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`  
28 - AccidentNum4 int `json:"accidentNum4"` //异物非金属事故 次数  
29 - AccidentResult4 int `json:"accidentResult4"` //异物非金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩` 27 + AccidentResult3 int `json:"accidentResult3"` //异物事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
  28 + AccidentNum4 int `json:"accidentNum4"` //异物非金属事故次数
30 SummaryResult float64 `json:"summaryResult"` //奖惩金额计算结果(元) 29 SummaryResult float64 `json:"summaryResult"` //奖惩金额计算结果(元)
31 CreatedAt time.Time `json:"createdAt"` // 30 CreatedAt time.Time `json:"createdAt"` //
32 UpdatedAt time.Time `json:"UpdatedAt"` // 31 UpdatedAt time.Time `json:"UpdatedAt"` //
@@ -72,9 +71,7 @@ func (c *RewardSummary) SummaryAccident(trouble *ProductTrouble, rewardStandard @@ -72,9 +71,7 @@ func (c *RewardSummary) SummaryAccident(trouble *ProductTrouble, rewardStandard
72 71
73 case TroubleType4: 72 case TroubleType4:
74 c.AccidentNum4 = +1 73 c.AccidentNum4 = +1
75 - if rewardStandard == nil {  
76 - c.AccidentResult4 = 0  
77 - } else { 74 + if rewardStandard != nil {
78 r := rewardStandard.VerdictTargetType5(0, c.AccidentNum4) 75 r := rewardStandard.VerdictTargetType5(0, c.AccidentNum4)
79 c.AccidentResult2 = r 76 c.AccidentResult2 = r
80 } 77 }
@@ -99,11 +96,6 @@ func (c *RewardSummary) ApplySummaryResult(rule *RewardRule) { @@ -99,11 +96,6 @@ func (c *RewardSummary) ApplySummaryResult(rule *RewardRule) {
99 } else if c.AccidentResult3 > 0 { 96 } else if c.AccidentResult3 > 0 {
100 rewardNum = +1 97 rewardNum = +1
101 } 98 }
102 - if c.AccidentResult4 < 0 {  
103 - faultNum = +1  
104 - } else if c.AccidentResult4 > 0 {  
105 - rewardNum = +1  
106 - }  
107 if c.YieldResult < 0 { 99 if c.YieldResult < 0 {
108 faultNum = +1 100 faultNum = +1
109 } else if c.YieldResult > 0 { 101 } else if c.YieldResult > 0 {
@@ -118,3 +110,25 @@ func (c *RewardSummary) ApplySummaryResult(rule *RewardRule) { @@ -118,3 +110,25 @@ func (c *RewardSummary) ApplySummaryResult(rule *RewardRule) {
118 c.SummaryResult = rule.SumRewardAmount(rewardNum, faultNum) 110 c.SummaryResult = rule.SumRewardAmount(rewardNum, faultNum)
119 111
120 } 112 }
  113 +
  114 +// SummaryYield 汇总产效数据
  115 +func (c *RewardSummary) SummaryYield(yield float64, rewardStandard *RewardStandard) {
  116 + c.Yield = yield
  117 + if rewardStandard == nil {
  118 + c.YieldResult = 0
  119 + } else {
  120 + r := rewardStandard.VerdictTargetType1(c.Yield)
  121 + c.YieldResult = r
  122 + }
  123 +}
  124 +
  125 +// SummaryUpToStandard 汇总合格率数据
  126 +func (c *RewardSummary) SummaryUpToStandard(param float64, rewardStandard *RewardStandard) {
  127 + c.UpToStandard = param
  128 + if rewardStandard == nil {
  129 + c.UpToStandard = 0
  130 + } else {
  131 + r := rewardStandard.VerdictTargetType2(c.Yield)
  132 + c.UpToStandardResult = r
  133 + }
  134 +}
@@ -53,6 +53,49 @@ func (d *RewardSumaryDao) SeachRewardSummaryDay(companyId int, orgId int, record @@ -53,6 +53,49 @@ func (d *RewardSumaryDao) SeachRewardSummaryDay(companyId int, orgId int, record
53 tx := d.transactionContext.PgTx 53 tx := d.transactionContext.PgTx
54 var result []RewardSummaryDay 54 var result []RewardSummaryDay
55 _, err := tx.Query(&result, sqlStr, companyId, orgId, recordDate) 55 _, err := tx.Query(&result, sqlStr, companyId, orgId, recordDate)
  56 +
  57 + for i := range result {
  58 + switch result[i].AccidentResult1 {
  59 + case "1":
  60 + result[i].AccidentResult1 = "功"
  61 + case "0":
  62 + result[i].AccidentResult1 = "不奖不惩"
  63 + case "-1":
  64 + result[i].AccidentResult1 = "过"
  65 + }
  66 + switch result[i].AccidentResult2 {
  67 + case "1":
  68 + result[i].AccidentResult2 = "功"
  69 + case "0":
  70 + result[i].AccidentResult2 = "不奖不惩"
  71 + case "-1":
  72 + result[i].AccidentResult2 = "过"
  73 + }
  74 + switch result[i].AccidentResult3 {
  75 + case "1":
  76 + result[i].AccidentResult3 = "功"
  77 + case "0":
  78 + result[i].AccidentResult3 = "不奖不惩"
  79 + case "-1":
  80 + result[i].AccidentResult3 = "过"
  81 + }
  82 + switch result[i].UpToStandardResult {
  83 + case "1":
  84 + result[i].UpToStandardResult = "功"
  85 + case "0":
  86 + result[i].UpToStandardResult = "不奖不惩"
  87 + case "-1":
  88 + result[i].UpToStandardResult = "过"
  89 + }
  90 + switch result[i].YieldResult {
  91 + case "1":
  92 + result[i].YieldResult = "功"
  93 + case "0":
  94 + result[i].YieldResult = "不奖不惩"
  95 + case "-1":
  96 + result[i].YieldResult = "过"
  97 + }
  98 + }
56 return result, err 99 return result, err
57 } 100 }
58 101
@@ -68,20 +111,61 @@ type RewardSummaryYield struct { @@ -68,20 +111,61 @@ type RewardSummaryYield struct {
68 111
69 // 功过看板-产效 112 // 功过看板-产效
70 func (d *RewardSumaryDao) SeachRewardSummaryYield(companyId int, orgId int, recordDate string) ([]RewardSummaryYield, error) { 113 func (d *RewardSumaryDao) SeachRewardSummaryYield(companyId int, orgId int, recordDate string) ([]RewardSummaryYield, error) {
71 - sqlStr := `SELECT  
72 - record_date_str,  
73 - work_station->>'sectionName' as section_name,  
74 - worker->>'userName' as worker_name,  
75 - yield_result,  
76 - yield,  
77 - '24' as yield_max 114 + // sqlStr := `SELECT
  115 + // record_date_str,
  116 + // work_station->>'sectionName' as section_name,
  117 + // worker->>'userName' as worker_name,
  118 + // yield_result,
  119 + // yield,
  120 + // '24' as yield_max
  121 + // FROM manufacture."reward_summary"
  122 + // WHERE company_id=?
  123 + // and org_id=?
  124 + // and record_date_str=?`
  125 +
  126 + sqlStr := `with
  127 + t1 as( SELECT
  128 + max(yield) as yield_max,
  129 + work_station->>'sectionId' AS section_id,
  130 + worker->>'userId' as worker_id
78 FROM manufacture."reward_summary" 131 FROM manufacture."reward_summary"
79 - WHERE company_id=?  
80 - and org_id=?  
81 - and record_date_str=?` 132 + WHERE company_id=? and org_id=?
  133 + GROUP BY section_id,worker_id
  134 + ),
  135 + t2 as (SELECT
  136 + record_date_str,
  137 + work_station->>'sectionId' AS section_id,
  138 + worker->>'userId' as worker_id,
  139 + work_station->>'sectionName' as section_name,
  140 + worker->>'userName' as worker_name,
  141 + yield_result,
  142 + yield
  143 + FROM manufacture."reward_summary"
  144 + WHERE company_id=? and org_id=?
  145 + and record_date_str=?
  146 + )
  147 + SELECT t2.record_date_str,t2.section_name,t2.worker_name,
  148 + t2.yield_result,t2.yield,t1.yield_max
  149 + FROM t2
  150 + JOIN t1 on t2.section_id=t1.section_id AND t2.worker_id=t2.worker_id`
  151 +
82 tx := d.transactionContext.PgTx 152 tx := d.transactionContext.PgTx
83 var result []RewardSummaryYield 153 var result []RewardSummaryYield
84 - _, err := tx.Query(&result, sqlStr, companyId, orgId, recordDate) 154 + params := []interface{}{
  155 + companyId, orgId,
  156 + companyId, orgId, recordDate,
  157 + }
  158 + _, err := tx.Query(&result, sqlStr, params...)
  159 + for i := range result {
  160 + switch result[i].YieldResult {
  161 + case "1":
  162 + result[i].YieldResult = "功"
  163 + case "0":
  164 + result[i].YieldResult = "不奖不惩"
  165 + case "-1":
  166 + result[i].YieldResult = "过"
  167 + }
  168 + }
85 return result, err 169 return result, err
86 170
87 } 171 }
@@ -98,35 +182,77 @@ type RewardSummaryUpToStandard struct { @@ -98,35 +182,77 @@ type RewardSummaryUpToStandard struct {
98 182
99 // 功过看板-合格率 183 // 功过看板-合格率
100 func (d *RewardSumaryDao) SeachRewardUpToStandard(companyId int, orgId int, recordDate string) ([]RewardSummaryUpToStandard, error) { 184 func (d *RewardSumaryDao) SeachRewardUpToStandard(companyId int, orgId int, recordDate string) ([]RewardSummaryUpToStandard, error) {
101 - sqlStr := `SELECT  
102 - record_date_str,  
103 - work_station->>'sectionName' as section_name,  
104 - worker->>'userName' as worker_name,  
105 - up_to_standard_result,  
106 - up_to_standard,  
107 - '90' as up_to_standard_max 185 + // sqlStr := `SELECT
  186 + // record_date_str,
  187 + // work_station->>'sectionName' as section_name,
  188 + // worker->>'userName' as worker_name,
  189 + // up_to_standard_result,
  190 + // up_to_standard,
  191 + // '90' as up_to_standard_max
  192 + // FROM manufacture."reward_summary"
  193 + // WHERE company_id=23
  194 + // and org_id=487
  195 + // and record_date_str='2022-10-29'`
  196 + sqlStr := `with
  197 + t1 as( SELECT
  198 + max(up_to_standard) as up_to_standard_max,
  199 + work_station->>'sectionId' AS section_id,
  200 + worker->>'userId' as worker_id
108 FROM manufacture."reward_summary" 201 FROM manufacture."reward_summary"
109 - WHERE company_id=23  
110 - and org_id=487  
111 - and record_date_str='2022-10-29'` 202 + WHERE company_id=? and org_id=?
  203 + GROUP BY section_id,worker_id
  204 + ),
  205 + t2 as (SELECT
  206 + record_date_str,
  207 + work_station->>'sectionId' AS section_id,
  208 + worker->>'userId' as worker_id,
  209 + work_station->>'sectionName' as section_name,
  210 + worker->>'userName' as worker_name,
  211 + up_to_standard_result,
  212 + up_to_standard
  213 + FROM manufacture."reward_summary"
  214 + WHERE company_id=? and org_id=?
  215 + and record_date_str=?
  216 + )
  217 + SELECT t2.record_date_str,t2.section_name,t2.worker_name,
  218 + t2.up_to_standard_result,t2.up_to_standard,t1.up_to_standard_max
  219 + FROM t2
  220 + JOIN t1 on t2.section_id=t1.section_id AND t2.worker_id=t2.worker_id`
112 tx := d.transactionContext.PgTx 221 tx := d.transactionContext.PgTx
113 var result []RewardSummaryUpToStandard 222 var result []RewardSummaryUpToStandard
114 - _, err := tx.Query(&result, sqlStr, companyId, orgId, recordDate) 223 + params := []interface{}{
  224 + companyId, orgId,
  225 + companyId, orgId, recordDate,
  226 + }
  227 + _, err := tx.Query(&result, sqlStr, params...)
  228 + for i := range result {
  229 + switch result[i].UpToStandardResult {
  230 + case "1":
  231 + result[i].UpToStandardResult = "功"
  232 + case "0":
  233 + result[i].UpToStandardResult = "不奖不惩"
  234 + case "-1":
  235 + result[i].UpToStandardResult = "过"
  236 + }
  237 + }
115 return result, err 238 return result, err
116 } 239 }
117 240
118 // 功过看板-异常 241 // 功过看板-异常
119 type RewardAccident struct { 242 type RewardAccident struct {
120 - Id string `json:"id"`  
121 - RecordDateStr string `json:"record_date_str"`  
122 - SectionName string `json:"sectionName"` //工段名称  
123 - WorkerName string `json:"workerName"` //员工名称  
124 - SummaryResult string `json:"summaryResult"` //奖惩结果  
125 - YieldResult string `json:"yieldResult"` //产效功过结果  
126 - UpToStandardResult string `json:"upToStandardResult"` //合格率功过结果  
127 - AccidentResult1 string `json:"accidentResult1"` //质量事故功过结果  
128 - AccidentResult2 string `json:"accidentResul2"` //安全事故功过结果  
129 - AccidentResult3 string `json:"accidentResul3"` //异物 功过结果 243 + Id string `json:"id"`
  244 + RecordDateStr string `json:"record_date_str"`
  245 + SectionName string `json:"sectionName"` //工段名称
  246 + WorkerName string `json:"workerName"` //员工名称
  247 + AccidentAmount1 string `json:"accidentAmount1"` //质量事故损失金额
  248 + AccidentNum1 string `json:"accidentNum1"` //质量事故次数
  249 + AccidentResult1 string `json:"accidentResult1"` //质量事故功过结果
  250 + AccidentAmount2 string `json:"accidentAmount2"` //安全事故 损失金额
  251 + AccidentResult2 string `json:"accidentResul2"` //安全事故功过结果
  252 + AccidentNum2 string `json:"accidentNum2"` //安全事故 次数
  253 + AccidentNum3 string `json:"accidentNum3"` //金属异物 次数
  254 + AccidentNum4 string `json:"accidentNum4"` //非属异物事故次数
  255 + AccidentResult3 string `json:"accidentResul3"` //异物 功过结果
130 } 256 }
131 257
132 // 功过看板-异常 258 // 功过看板-异常
@@ -135,9 +261,9 @@ func (d *RewardSumaryDao) SeachRewardAccident(companyId int, orgId int, recordDa @@ -135,9 +261,9 @@ func (d *RewardSumaryDao) SeachRewardAccident(companyId int, orgId int, recordDa
135 "id",record_date_str, 261 "id",record_date_str,
136 work_station->>'sectionName' as section_name, 262 work_station->>'sectionName' as section_name,
137 worker->>'userName' as worker_name, 263 worker->>'userName' as worker_name,
138 - up_to_standard_result,  
139 - up_to_standard,  
140 - '90' as up_to_standard_max 264 + accident_num1,accident_amount1,accident_result1,
  265 + accident_num2,accident_amount2,accident_result2,
  266 + accident_num3,accident_num4,accident_result3
141 FROM manufacture."reward_summary" 267 FROM manufacture."reward_summary"
142 WHERE company_id=? 268 WHERE company_id=?
143 and org_id=? 269 and org_id=?
@@ -145,10 +271,37 @@ func (d *RewardSumaryDao) SeachRewardAccident(companyId int, orgId int, recordDa @@ -145,10 +271,37 @@ func (d *RewardSumaryDao) SeachRewardAccident(companyId int, orgId int, recordDa
145 tx := d.transactionContext.PgTx 271 tx := d.transactionContext.PgTx
146 var result []RewardAccident 272 var result []RewardAccident
147 _, err := tx.Query(&result, sqlStr, companyId, orgId, recordDate) 273 _, err := tx.Query(&result, sqlStr, companyId, orgId, recordDate)
  274 +
  275 + for i := range result {
  276 + switch result[i].AccidentResult1 {
  277 + case "1":
  278 + result[i].AccidentResult1 = "功"
  279 + case "0":
  280 + result[i].AccidentResult1 = "不奖不惩"
  281 + case "-1":
  282 + result[i].AccidentResult1 = "过"
  283 + }
  284 + switch result[i].AccidentResult2 {
  285 + case "1":
  286 + result[i].AccidentResult2 = "功"
  287 + case "0":
  288 + result[i].AccidentResult2 = "不奖不惩"
  289 + case "-1":
  290 + result[i].AccidentResult2 = "过"
  291 + }
  292 + switch result[i].AccidentResult3 {
  293 + case "1":
  294 + result[i].AccidentResult3 = "功"
  295 + case "0":
  296 + result[i].AccidentResult3 = "不奖不惩"
  297 + case "-1":
  298 + result[i].AccidentResult3 = "过"
  299 + }
  300 + }
148 return result, err 301 return result, err
149 } 302 }
150 303
151 -// 功过看板-异常 304 +// 功过看板-月榜
152 type RewardSummaryMonth struct { 305 type RewardSummaryMonth struct {
153 SectionId string `json:"sectionId"` //工段名称 306 SectionId string `json:"sectionId"` //工段名称
154 SectionName string `json:"sectionName"` //工段名称 307 SectionName string `json:"sectionName"` //工段名称
@@ -170,32 +323,35 @@ type RewardSummaryMonth struct { @@ -170,32 +323,35 @@ type RewardSummaryMonth struct {
170 323
171 // 功过看板-月榜 324 // 功过看板-月榜
172 func (d *RewardSumaryDao) SeachRewardSummaryMonth(companyId int, orgId int, recordMonth string) ([]RewardSummaryMonth, error) { 325 func (d *RewardSumaryDao) SeachRewardSummaryMonth(companyId int, orgId int, recordMonth string) ([]RewardSummaryMonth, error) {
173 - sqlStr := `SELECT  
174 -work_station->>'sectionId' AS section_id,  
175 -work_station->>'sectionName' as section_name,  
176 -worker->>'userId' as worker_id,  
177 -worker->>'userName' as worker_name,  
178 -count(accident_num1) as accident_num1,  
179 -count(accident_num2) as accident_num2,  
180 -count(accident_num3) as accident_num3,  
181 -count(accident_num4) as accident_num4,  
182 -count(accident_amount1) as accident_amount1,  
183 -count(accident_amount2) as accident_amount2,  
184 -'12' as yield_avg,  
185 -'13' as yield_max,  
186 -'-39' as amount_fine,  
187 -'25' as amount_reward,  
188 -'-14' as amount_final,  
189 -'12' as up_to_standard,  
190 - FROM manufacture.reward_summary  
191 - WHERE company_id=?  
192 - and org_id=?  
193 - and record_month_str=?  
194 -GROUP BY  
195 -worker->>'userId' ,  
196 -worker->>'userName' ,  
197 -work_station->>'sectionId',  
198 -work_station->>'sectionName' ` 326 + sqlStr := `
  327 + SELECT
  328 + work_station->>'sectionId' AS section_id,
  329 + work_station->>'sectionName' as section_name,
  330 + worker->>'userId' as worker_id,
  331 + worker->>'userName' as worker_name,
  332 + sum(accident_num1) as accident_num1,
  333 + sum(accident_num2) as accident_num2,
  334 + sum(accident_num3) as accident_num3,
  335 + sum(accident_num4) as accident_num4,
  336 + sum(accident_amount1) as accident_amount1,
  337 + sum(accident_amount2) as accident_amount2,
  338 + CAST(sum(summary_result) as decimal(10,2)) as amount_final,
  339 + CAST(
  340 + sum(CASE WHEN summary_result<0 THEN summary_result ELSE 0 END) as decimal(10,2)
  341 + ) as amount_fine,
  342 + CAST(
  343 + sum(CASE WHEN summary_result>0 THEN summary_result ELSE 0 END) as decimal(10,2)
  344 + ) as amount_reward,
  345 + max(yield) as yield_max,
  346 + CAST(avg(yield) as decimal(10,2)) as yield_avg,
  347 + CAST(avg(up_to_standard) as decimal(10,2) ) as up_to_standard
  348 + FROM manufacture.reward_summary
  349 + WHERE company_id=?
  350 + and org_id=?
  351 + and record_month_str=?
  352 + GROUP BY section_id,worker_id,worker_name,section_name
  353 + ;
  354 + `
199 tx := d.transactionContext.PgTx 355 tx := d.transactionContext.PgTx
200 var result []RewardSummaryMonth 356 var result []RewardSummaryMonth
201 _, err := tx.Query(&result, sqlStr, companyId, orgId, recordMonth) 357 _, err := tx.Query(&result, sqlStr, companyId, orgId, recordMonth)
@@ -112,10 +112,121 @@ func (c *PGRewardSummaryStaticService) CreateRewardSummaryByProductTrouble(param @@ -112,10 +112,121 @@ func (c *PGRewardSummaryStaticService) CreateRewardSummaryByProductTrouble(param
112 if err != nil { 112 if err != nil {
113 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取奖惩规则"+err.Error()) 113 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取奖惩规则"+err.Error())
114 } 114 }
115 - if len(rewardRuleList) == 0 {  
116 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未设置奖惩规则") 115 + if len(rewardRuleList) >= 0 {
  116 + summaryData.ApplySummaryResult(rewardRuleList[0])
  117 + }
  118 + summaryData.UpdatedAt = nowTime
  119 + _, err = rewardSummaryRepo.Save(summaryData)
  120 + if err != nil {
  121 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  122 + }
  123 + return nil
  124 +}
  125 +
  126 +// CreateRewardSummaryByEmployeeProductRecord 通过员工生产记录 汇总奖惩结果
  127 +func (c *PGRewardSummaryStaticService) CreateRewardSummaryByEmployeeProductRecord(param *domain.EmployeeProductRecord) error {
  128 + rewardSummaryRepo, _ := repository.NewRewardSummaryRepository(c.transactionContext)
  129 + //查询是否已经有汇总数据
  130 + condtion := map[string]interface{}{
  131 + "orgId": param.OrgId,
  132 + "companyId": param.CompanyId,
  133 + "lineId": param.WorkStation.LineId,
  134 + "sectionId": param.WorkStation.SectionId,
  135 + "workshopId": param.WorkStation.WorkshopId,
  136 + "workerId": param.ProductWorker.UserId,
  137 + "recordDateStr": param.CreatedAt.Format("200-01-02"),
  138 + }
  139 +
  140 + _, summaryList, err := rewardSummaryRepo.Find(condtion)
  141 + if err != nil {
  142 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  143 + }
  144 +
  145 + var summaryData *domain.RewardSummary
  146 + nowTime := time.Now()
  147 + if len(summaryList) > 0 {
  148 + summaryData = summaryList[0]
  149 + } else {
  150 + summaryData = &domain.RewardSummary{
  151 + Id: 0,
  152 + CompanyId: param.CompanyId,
  153 + OrgId: param.OrgId,
  154 + // WorkStation: *param.WorkStation,
  155 + // Worker: *param.ProductWorker,
  156 + RecordDate: param.CreatedAt,
  157 + RecordDateStr: param.CreatedAt.Format("2006-01-02"),
  158 + UpToStandard: 0.0,
  159 + Yield: 0.0,
  160 + AccidentNum1: 0,
  161 + AccidentAmount1: 0.0,
  162 + AccidentNum2: 0,
  163 + AccidentAmount2: 0.0,
  164 + AccidentNum3: 0,
  165 + AccidentNum4: 0,
  166 + SummaryResult: 0.0,
  167 + CreatedAt: nowTime,
  168 + UpdatedAt: nowTime,
  169 + }
  170 + if param.WorkStation != nil {
  171 + summaryData.WorkStation = *param.WorkStation
  172 + }
  173 + if param.ProductWorker != nil {
  174 + summaryData.Worker = *param.ProductWorker
  175 + }
  176 + }
  177 + //获取奖惩标准 按 车间 线别 工段 类型 ;合格率类型
  178 + rewardStandardRepo, _ := repository.NewRewardStandardRepository(c.transactionContext)
  179 + _, rewardStandardList, err := rewardStandardRepo.Find(map[string]interface{}{
  180 + "companyId": param.CompanyId,
  181 + "orgId": param.OrgId,
  182 + "workshopId": param.WorkStation.WorkshopId,
  183 + "lineId": param.WorkStation.LineId,
  184 + "sectionId": param.WorkStation.SectionId,
  185 + "targetType": domain.TargetType2,
  186 + "limit": 1,
  187 + })
  188 + if err != nil {
  189 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  190 + }
  191 + if len(rewardStandardList) > 0 {
  192 + //汇总合格率
  193 + summaryData.SummaryUpToStandard(param.ProductRecordInfo.QualificationRate, rewardStandardList[0])
  194 + } else {
  195 + summaryData.SummaryUpToStandard(param.ProductRecordInfo.QualificationRate, nil)
  196 + }
  197 +
  198 + //获取奖惩标准 按 车间 线别 工段 类型 ;产能类型
  199 + _, rewardStandardList, err = rewardStandardRepo.Find(map[string]interface{}{
  200 + "companyId": param.CompanyId,
  201 + "orgId": param.OrgId,
  202 + "workshopId": param.WorkStation.WorkshopId,
  203 + "lineId": param.WorkStation.LineId,
  204 + "sectionId": param.WorkStation.SectionId,
  205 + "targetType": domain.TargetType1,
  206 + "limit": 1,
  207 + })
  208 + if err != nil {
  209 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  210 + }
  211 + if len(rewardStandardList) > 0 {
  212 + //汇总合格率
  213 + summaryData.SummaryYield(param.ProductRecordInfo.OutputWeight, rewardStandardList[0])
  214 + } else {
  215 + summaryData.SummaryYield(param.ProductRecordInfo.OutputWeight, nil)
  216 + }
  217 + //根据规则算 奖惩金额
  218 + //获取奖惩规则
  219 + rewardRuleRepo, _ := repository.NewRewardRuleRepository(c.transactionContext)
  220 + _, rewardRuleList, err := rewardRuleRepo.Find(map[string]interface{}{
  221 + "companyId": param.CompanyId,
  222 + "orgId": param.OrgId,
  223 + })
  224 + if err != nil {
  225 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取奖惩规则"+err.Error())
  226 + }
  227 + if len(rewardRuleList) >= 0 {
  228 + summaryData.ApplySummaryResult(rewardRuleList[0])
117 } 229 }
118 - summaryData.ApplySummaryResult(rewardRuleList[0])  
119 summaryData.UpdatedAt = nowTime 230 summaryData.UpdatedAt = nowTime
120 _, err = rewardSummaryRepo.Save(summaryData) 231 _, err = rewardSummaryRepo.Save(summaryData)
121 if err != nil { 232 if err != nil {
@@ -17,21 +17,20 @@ type RewardSummary struct { @@ -17,21 +17,20 @@ type RewardSummary struct {
17 RecordMonthStr string //月份 :200601 17 RecordMonthStr string //月份 :200601
18 WorkStation domain.WorkStation // 工作位置 18 WorkStation domain.WorkStation // 工作位置
19 Worker domain.User //员工 19 Worker domain.User //员工
20 - UpToStandard float64 //合格率  
21 - UpToStandardResult int //合格率 功过评定结果 1`功` -1 `过` 0 `不奖不惩`  
22 - Yield float64 //产能  
23 - YieldResult int //产能 功过评定结果 1`功` -1 `过` 0 `不奖不惩`  
24 - AccidentNum1 int //质量事故 次数  
25 - AccidentAmount1 float64 //质量事故 损失金额  
26 - AccidentResult1 int //质量事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`  
27 - AccidentNum2 int //安全事故 次数  
28 - AccidentAmount2 float64 //安全事故 损失金额  
29 - AccidentResult2 int //安全事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`  
30 - AccidentNum3 int //异物金属事故 次数  
31 - AccidentResult3 int //异物金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`  
32 - AccidentNum4 int //异物非金属事故 次数  
33 - AccidentResult4 int //异物非金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`  
34 - SummaryResult float64 //奖惩金额计算结果(元) 20 + UpToStandard float64 `comment:"合格率"` //合格率
  21 + UpToStandardResult int `comment:"合格率功过评定结果 1:功 -1:过 0:不奖不惩"` //合格率功过评定结果1:功 -1:过 0:不奖不惩
  22 + Yield float64 `comment:"产能"` //产能
  23 + YieldResult int `comment:"产能功过评定结果,1:功 -1:过 0:不奖不惩"` //产能功过评定结果,1:功 -1:过 0:不奖不惩
  24 + AccidentNum1 int `comment:"质量事故 次数"` //质量事故 次数
  25 + AccidentAmount1 float64 `comment:"质量事故 损失金额"` //质量事故 损失金额
  26 + AccidentResult1 int `comment:"质量事故 功过评定结果1:功 -1:过 0:不奖不惩"` //质量事故 功过评定结果1:功 -1:过 0:不奖不惩
  27 + AccidentNum2 int `comment:"安全事故 次数"` //安全事故 次数
  28 + AccidentAmount2 float64 `comment:"安全事故 损失金额"` //安全事故 损失金额
  29 + AccidentResult2 int `comment:"安全事故 功过评定结果 1:功 -1:过 0:不奖不惩"` //安全事故 功过评定结果 1:功 -1:过 0:不奖不惩
  30 + AccidentNum3 int `comment:"异物金属事故 次数"` //异物金属事故 次数
  31 + AccidentResult3 int `comment:"异物事故 功过评定结果 1:功 -1:过 0:不奖不惩"` //异物事故 功过评定结果 1:功 -1:过 0:不奖不惩
  32 + AccidentNum4 int `comment:"异物非金属事故 次数"` //异物非金属事故 次数
  33 + SummaryResult float64 `comment:"奖惩金额计算结果(元)"` //奖惩金额计算结果(元)
35 CreatedAt time.Time // 34 CreatedAt time.Time //
36 UpdatedAt time.Time // 35 UpdatedAt time.Time //
37 36