1
|
package service
|
1
|
package service
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "fmt"
|
4
|
"strconv"
|
5
|
"strconv"
|
5
|
"strings"
|
6
|
"strings"
|
6
|
"time"
|
7
|
"time"
|
|
@@ -83,7 +84,7 @@ func (srv ProductTroubleService) SaveProductTrouble(operateInfo *domain.OperateI |
|
@@ -83,7 +84,7 @@ func (srv ProductTroubleService) SaveProductTrouble(operateInfo *domain.OperateI |
83
|
|
84
|
|
84
|
troubleData.AmountLoss = param.AmountLoss
|
85
|
troubleData.AmountLoss = param.AmountLoss
|
85
|
troubleData.ProductWorker = *workerUser
|
86
|
troubleData.ProductWorker = *workerUser
|
86
|
- troubleData.RecordData = recordDate
|
87
|
+ troubleData.RecordDate = recordDate
|
87
|
troubleData.Remark = param.Remark
|
88
|
troubleData.Remark = param.Remark
|
88
|
troubleData.UpdatedAt = time.Now()
|
89
|
troubleData.UpdatedAt = time.Now()
|
89
|
troubleData.WorkStation = *workStation
|
90
|
troubleData.WorkStation = *workStation
|
|
@@ -149,7 +150,7 @@ func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleI |
|
@@ -149,7 +150,7 @@ func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleI |
149
|
SectionId: troubleData.WorkStation.SectionId,
|
150
|
SectionId: troubleData.WorkStation.SectionId,
|
150
|
SectionName: troubleData.WorkStation.SectionName,
|
151
|
SectionName: troubleData.WorkStation.SectionName,
|
151
|
Remark: troubleData.Remark,
|
152
|
Remark: troubleData.Remark,
|
152
|
- ProductDate: troubleData.RecordData.Format("2006-01-02"),
|
153
|
+ ProductDate: troubleData.RecordDate.Format("2006-01-02"),
|
153
|
AmountLoss: troubleData.AmountLoss,
|
154
|
AmountLoss: troubleData.AmountLoss,
|
154
|
Types: string(troubleData.Types),
|
155
|
Types: string(troubleData.Types),
|
155
|
WorkerId: troubleData.ProductWorker.UserId,
|
156
|
WorkerId: troubleData.ProductWorker.UserId,
|
|
@@ -188,10 +189,7 @@ func (srv ProductTroubleService) DeleteProductTrouble(id int64) error { |
|
@@ -188,10 +189,7 @@ func (srv ProductTroubleService) DeleteProductTrouble(id int64) error { |
188
|
return nil
|
189
|
return nil
|
189
|
}
|
190
|
}
|
190
|
|
191
|
|
191
|
-// func (srv ProductTroubleService) approveProductTrouble(operateInfo *domain.OperateInfo, param *domain.ProductTrouble) error {
|
|
|
192
|
-// return nil
|
|
|
193
|
-// }
|
|
|
194
|
-
|
192
|
+// 审核事故
|
195
|
func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.OperateInfo, id int64) error {
|
193
|
func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.OperateInfo, id int64) error {
|
196
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
194
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
197
|
if err != nil {
|
195
|
if err != nil {
|
|
@@ -228,6 +226,11 @@ func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.Opera |
|
@@ -228,6 +226,11 @@ func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.Opera |
228
|
if err != nil {
|
226
|
if err != nil {
|
229
|
return application.ThrowError(application.ARG_ERROR, err.Error())
|
227
|
return application.ThrowError(application.ARG_ERROR, err.Error())
|
230
|
}
|
228
|
}
|
|
|
229
|
+ //汇总奖惩明细
|
|
|
230
|
+ err = srv.CreateRewardSummaryByProductTrouble(troubleData)
|
|
|
231
|
+ if err != nil {
|
|
|
232
|
+ return application.ThrowError(application.ARG_ERROR, "计算功过奖惩明细失败,"+err.Error())
|
|
|
233
|
+ }
|
231
|
if err := transactionContext.CommitTransaction(); err != nil {
|
234
|
if err := transactionContext.CommitTransaction(); err != nil {
|
232
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
235
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
233
|
}
|
236
|
}
|
|
@@ -286,7 +289,7 @@ func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrou |
|
@@ -286,7 +289,7 @@ func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrou |
286
|
SectionId: v.WorkStation.SectionId,
|
289
|
SectionId: v.WorkStation.SectionId,
|
287
|
SectionName: v.WorkStation.SectionName,
|
290
|
SectionName: v.WorkStation.SectionName,
|
288
|
Remark: v.Remark,
|
291
|
Remark: v.Remark,
|
289
|
- ProductDate: v.RecordData.Format("2006-01-02"),
|
292
|
+ ProductDate: v.RecordDate.Format("2006-01-02"),
|
290
|
AmountLoss: v.AmountLoss,
|
293
|
AmountLoss: v.AmountLoss,
|
291
|
Types: v.GetTypesName(),
|
294
|
Types: v.GetTypesName(),
|
292
|
WorkerId: v.ProductWorker.UserId,
|
295
|
WorkerId: v.ProductWorker.UserId,
|
|
@@ -415,7 +418,7 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper |
|
@@ -415,7 +418,7 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper |
415
|
ProductWorker: *worker,
|
418
|
ProductWorker: *worker,
|
416
|
AmountLoss: amountLoss,
|
419
|
AmountLoss: amountLoss,
|
417
|
Types: "",
|
420
|
Types: "",
|
418
|
- RecordData: recordDate,
|
421
|
+ RecordDate: recordDate,
|
419
|
Remark: "",
|
422
|
Remark: "",
|
420
|
ApproveStatus: domain.TroubleIsApprove,
|
423
|
ApproveStatus: domain.TroubleIsApprove,
|
421
|
ApproveAt: &nowTime,
|
424
|
ApproveAt: &nowTime,
|
|
@@ -439,15 +442,180 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper |
|
@@ -439,15 +442,180 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper |
439
|
productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
|
442
|
productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
|
440
|
"transactionContext": transactionContext,
|
443
|
"transactionContext": transactionContext,
|
441
|
})
|
444
|
})
|
442
|
- //添加事故数据
|
445
|
+
|
443
|
for i := range troubleDataList {
|
446
|
for i := range troubleDataList {
|
|
|
447
|
+ //添加事故数据
|
444
|
_, err = productTroubleRepo.Save(troubleDataList[i])
|
448
|
_, err = productTroubleRepo.Save(troubleDataList[i])
|
445
|
if err != nil {
|
449
|
if err != nil {
|
446
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
450
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
447
|
}
|
451
|
}
|
|
|
452
|
+ //汇总奖惩明细
|
|
|
453
|
+ err = srv.CreateRewardSummaryByProductTrouble(troubleDataList[i])
|
|
|
454
|
+ if err != nil {
|
|
|
455
|
+ return nil, application.ThrowError(application.ARG_ERROR, "计算功过奖惩明细失败,"+err.Error())
|
|
|
456
|
+ }
|
448
|
}
|
457
|
}
|
|
|
458
|
+
|
449
|
if err := transactionContext.CommitTransaction(); err != nil {
|
459
|
if err := transactionContext.CommitTransaction(); err != nil {
|
450
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
460
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
451
|
}
|
461
|
}
|
452
|
return nil, nil
|
462
|
return nil, nil
|
453
|
}
|
463
|
}
|
|
|
464
|
+
|
|
|
465
|
+// 奖惩汇总数据列表
|
|
|
466
|
+func (srv ProductTroubleService) ListRewardSummary(param query.ListRewardSummaryQuery) (int64, []dto.RewardSummaryList, error) {
|
|
|
467
|
+
|
|
|
468
|
+ transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
469
|
+ if err != nil {
|
|
|
470
|
+ return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
471
|
+ }
|
|
|
472
|
+ if err := transactionContext.StartTransaction(); err != nil {
|
|
|
473
|
+ return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
474
|
+ }
|
|
|
475
|
+ defer func() {
|
|
|
476
|
+ transactionContext.RollbackTransaction()
|
|
|
477
|
+ }()
|
|
|
478
|
+
|
|
|
479
|
+ rewardSummaryRepo, _ := factory.CreateRewardSummaryRepository(map[string]interface{}{
|
|
|
480
|
+ "transactionContext": transactionContext,
|
|
|
481
|
+ })
|
|
|
482
|
+ limit := param.PageSize
|
|
|
483
|
+ offset := param.PageSize * (param.PageNumber - 1)
|
|
|
484
|
+ condition := map[string]interface{}{
|
|
|
485
|
+ "orgId": param.OrgId,
|
|
|
486
|
+ "companyId": param.CompanyId,
|
|
|
487
|
+ "offset": offset,
|
|
|
488
|
+ "limit": limit,
|
|
|
489
|
+ }
|
|
|
490
|
+ //搜索条件日期
|
|
|
491
|
+ if len(param.BeginDate) > 0 {
|
|
|
492
|
+ _, err = time.Parse("2006-01-02", param.BeginDate)
|
|
|
493
|
+ if err != nil {
|
|
|
494
|
+ return 0, nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
|
|
|
495
|
+ }
|
|
|
496
|
+ condition["beginDate"] = param.BeginDate
|
|
|
497
|
+ }
|
|
|
498
|
+ //搜索条件日期
|
|
|
499
|
+ if len(param.EndDate) > 0 {
|
|
|
500
|
+ _, err = time.Parse("2006-01-02", param.EndDate)
|
|
|
501
|
+ if err != nil {
|
|
|
502
|
+ return 0, nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
|
|
|
503
|
+ }
|
|
|
504
|
+ condition["endDate"] = param.EndDate
|
|
|
505
|
+ }
|
|
|
506
|
+ //搜索条件 车间名称
|
|
|
507
|
+ if len(param.WorkshopName) > 0 {
|
|
|
508
|
+ condition["workshopName"] = param.WorkshopName
|
|
|
509
|
+ }
|
|
|
510
|
+ //搜索条件 线别名称
|
|
|
511
|
+ if len(param.LineName) > 0 {
|
|
|
512
|
+ condition["lineName"] = param.LineName
|
|
|
513
|
+ }
|
|
|
514
|
+
|
|
|
515
|
+ cnt, rewardSummaryList, err := rewardSummaryRepo.Find(condition)
|
|
|
516
|
+ if err != nil {
|
|
|
517
|
+ return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
518
|
+ }
|
|
|
519
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
520
|
+ return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
521
|
+ }
|
|
|
522
|
+
|
|
|
523
|
+ result := []dto.RewardSummaryList{}
|
|
|
524
|
+ for _, v := range rewardSummaryList {
|
|
|
525
|
+ item := dto.RewardSummaryList{
|
|
|
526
|
+ Id: v.Id,
|
|
|
527
|
+ RecordDate: v.RecordDate.Format("2006-01-02"),
|
|
|
528
|
+ WorkshopName: v.WorkStation.WorkshopName,
|
|
|
529
|
+ LineName: v.WorkStation.LineName,
|
|
|
530
|
+ SectionName: v.WorkStation.SectionName,
|
|
|
531
|
+ Yield: fmt.Sprintf("%.2f", v.Yield),
|
|
|
532
|
+ UpToStandard: fmt.Sprintf("%.2f%%", v.UpToStandard),
|
|
|
533
|
+ Accident1: fmt.Sprintf("%d次%.2f元", v.AccidentNum1, v.AccidentAmount1),
|
|
|
534
|
+ Accident2: fmt.Sprintf("%d次%.2f元", v.AccidentNum2, v.AccidentAmount2),
|
|
|
535
|
+ Accident3: fmt.Sprintf("金属%d次,非金属%d次", v.AccidentNum3, v.AccidentNum4),
|
|
|
536
|
+ SummaryResult: fmt.Sprintf("%v", v.SummaryResult),
|
|
|
537
|
+ ResultDesc: "",
|
|
|
538
|
+ }
|
|
|
539
|
+ if v.SummaryResult == 0 {
|
|
|
540
|
+ item.ResultDesc = "不奖不惩"
|
|
|
541
|
+ } else if v.SummaryResult > 0 {
|
|
|
542
|
+ item.ResultDesc = "奖"
|
|
|
543
|
+ } else {
|
|
|
544
|
+ item.ResultDesc = "惩"
|
|
|
545
|
+ }
|
|
|
546
|
+ result = append(result, item)
|
|
|
547
|
+ }
|
|
|
548
|
+ return cnt, result, nil
|
|
|
549
|
+}
|
|
|
550
|
+
|
|
|
551
|
+// 根据事故数据创建奖惩汇总数据
|
|
|
552
|
+func (srv ProductTroubleService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error {
|
|
|
553
|
+ transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
554
|
+ if err != nil {
|
|
|
555
|
+ return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
556
|
+ }
|
|
|
557
|
+ if err := transactionContext.StartTransaction(); err != nil {
|
|
|
558
|
+ return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
559
|
+ }
|
|
|
560
|
+ defer func() {
|
|
|
561
|
+ transactionContext.RollbackTransaction()
|
|
|
562
|
+ }()
|
|
|
563
|
+
|
|
|
564
|
+ rewardSummaryRepo, _ := factory.CreateRewardSummaryRepository(map[string]interface{}{
|
|
|
565
|
+ "transactionContext": transactionContext,
|
|
|
566
|
+ })
|
|
|
567
|
+
|
|
|
568
|
+ //查询是否已经有汇总数据
|
|
|
569
|
+ condtion := map[string]interface{}{
|
|
|
570
|
+ "orgId": param.OrgId,
|
|
|
571
|
+ "companyId": param.CompanyId,
|
|
|
572
|
+ "lineId": param.WorkStation.LineId,
|
|
|
573
|
+ "sectionId": param.WorkStation.SectionId,
|
|
|
574
|
+ "workshopId": param.WorkStation.WorkshopId,
|
|
|
575
|
+ "workerId": param.ProductWorker.UserId,
|
|
|
576
|
+ "recordDateStr": param.RecordDate.Format("200-01-02"),
|
|
|
577
|
+ }
|
|
|
578
|
+
|
|
|
579
|
+ _, summaryList, err := rewardSummaryRepo.Find(condtion)
|
|
|
580
|
+ if err != nil {
|
|
|
581
|
+ return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
582
|
+ }
|
|
|
583
|
+
|
|
|
584
|
+ var summaryData *domain.RewardSummary
|
|
|
585
|
+ nowTime := time.Now()
|
|
|
586
|
+ if len(summaryList) > 0 {
|
|
|
587
|
+ summaryData = summaryList[0]
|
|
|
588
|
+ } else {
|
|
|
589
|
+ summaryData = &domain.RewardSummary{
|
|
|
590
|
+ Id: 0,
|
|
|
591
|
+ CompanyId: param.CompanyId,
|
|
|
592
|
+ OrgId: param.OrgId,
|
|
|
593
|
+ WorkStation: param.WorkStation,
|
|
|
594
|
+ Worker: param.ProductWorker,
|
|
|
595
|
+ RecordDate: param.RecordDate,
|
|
|
596
|
+ RecordDateStr: param.RecordDate.Format("2006-01-02"),
|
|
|
597
|
+ UpToStandard: 0.0,
|
|
|
598
|
+ Yield: 0.0,
|
|
|
599
|
+ AccidentNum1: 0,
|
|
|
600
|
+ AccidentAmount1: 0.0,
|
|
|
601
|
+ AccidentNum2: 0,
|
|
|
602
|
+ AccidentAmount2: 0.0,
|
|
|
603
|
+ AccidentNum3: 0,
|
|
|
604
|
+ AccidentNum4: 0,
|
|
|
605
|
+ SummaryResult: 0.0,
|
|
|
606
|
+ CreatedAt: nowTime,
|
|
|
607
|
+ UpdatedAt: nowTime,
|
|
|
608
|
+ }
|
|
|
609
|
+ }
|
|
|
610
|
+ // 将审核过的事故放入汇总数据计算
|
|
|
611
|
+ summaryData.SummaryAccident(param)
|
|
|
612
|
+ summaryData.UpdatedAt = nowTime
|
|
|
613
|
+ _, err = rewardSummaryRepo.Save(summaryData)
|
|
|
614
|
+ if err != nil {
|
|
|
615
|
+ return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
616
|
+ }
|
|
|
617
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
618
|
+ return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
619
|
+ }
|
|
|
620
|
+ return nil
|
|
|
621
|
+} |