|
@@ -558,74 +558,98 @@ func (srv ProductTroubleService) ListRewardSummary(param *query.ListRewardSummar |
|
@@ -558,74 +558,98 @@ func (srv ProductTroubleService) ListRewardSummary(param *query.ListRewardSummar |
558
|
return cnt, result, nil
|
558
|
return cnt, result, nil
|
559
|
}
|
559
|
}
|
560
|
|
560
|
|
561
|
-// 根据事故数据创建奖惩汇总数据
|
|
|
562
|
-// func (srv ProductTroubleService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error {
|
|
|
563
|
-// transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
564
|
-// if err != nil {
|
|
|
565
|
-// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
566
|
-// }
|
|
|
567
|
-// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
568
|
-// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
569
|
-// }
|
|
|
570
|
-// defer func() {
|
|
|
571
|
-// transactionContext.RollbackTransaction()
|
|
|
572
|
-// }()
|
|
|
573
|
-
|
|
|
574
|
-// rewardSummaryRepo, _ := factory.CreateRewardSummaryRepository(map[string]interface{}{
|
|
|
575
|
-// "transactionContext": transactionContext,
|
|
|
576
|
-// })
|
|
|
577
|
-
|
|
|
578
|
-// //查询是否已经有汇总数据
|
|
|
579
|
-// condtion := map[string]interface{}{
|
|
|
580
|
-// "orgId": param.OrgId,
|
|
|
581
|
-// "companyId": param.CompanyId,
|
|
|
582
|
-// "lineId": param.WorkStation.LineId,
|
|
|
583
|
-// "sectionId": param.WorkStation.SectionId,
|
|
|
584
|
-// "workshopId": param.WorkStation.WorkshopId,
|
|
|
585
|
-// "workerId": param.ProductWorker.UserId,
|
|
|
586
|
-// "recordDateStr": param.RecordDate.Format("200-01-02"),
|
|
|
587
|
-// }
|
|
|
588
|
-
|
|
|
589
|
-// _, summaryList, err := rewardSummaryRepo.Find(condtion)
|
|
|
590
|
-// if err != nil {
|
|
|
591
|
-// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
592
|
-// }
|
|
|
593
|
-
|
|
|
594
|
-// var summaryData *domain.RewardSummary
|
|
|
595
|
-// nowTime := time.Now()
|
|
|
596
|
-// if len(summaryList) > 0 {
|
|
|
597
|
-// summaryData = summaryList[0]
|
|
|
598
|
-// } else {
|
|
|
599
|
-// summaryData = &domain.RewardSummary{
|
|
|
600
|
-// Id: 0,
|
|
|
601
|
-// CompanyId: param.CompanyId,
|
|
|
602
|
-// OrgId: param.OrgId,
|
|
|
603
|
-// WorkStation: param.WorkStation,
|
|
|
604
|
-// Worker: param.ProductWorker,
|
|
|
605
|
-// RecordDate: param.RecordDate,
|
|
|
606
|
-// RecordDateStr: param.RecordDate.Format("2006-01-02"),
|
|
|
607
|
-// UpToStandard: 0.0,
|
|
|
608
|
-// Yield: 0.0,
|
|
|
609
|
-// AccidentNum1: 0,
|
|
|
610
|
-// AccidentAmount1: 0.0,
|
|
|
611
|
-// AccidentNum2: 0,
|
|
|
612
|
-// AccidentAmount2: 0.0,
|
|
|
613
|
-// AccidentNum3: 0,
|
|
|
614
|
-// AccidentNum4: 0,
|
|
|
615
|
-// SummaryResult: 0.0,
|
|
|
616
|
-// CreatedAt: nowTime,
|
|
|
617
|
-// UpdatedAt: nowTime,
|
|
|
618
|
-// }
|
|
|
619
|
-// }
|
|
|
620
|
-// // 将审核过的事故放入汇总数据计算
|
|
|
621
|
-// summaryData.SummaryAccident(param)
|
|
|
622
|
-// summaryData.UpdatedAt = nowTime
|
|
|
623
|
-// _, err = rewardSummaryRepo.Save(summaryData)
|
|
|
624
|
-// if err != nil {
|
|
|
625
|
-// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
626
|
-// }
|
|
|
627
|
-// if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
628
|
-// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
629
|
-// }
|
|
|
630
|
-// return nil
|
|
|
631
|
-// } |
561
|
+// 创建事故数据
|
|
|
562
|
+func (srv ProductTroubleService) CreateProductTrouble(operateInfo *domain.OperateInfo, param *command.CreateProductTroubleCommand) (map[string]interface{}, error) {
|
|
|
563
|
+ transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
564
|
+ if err != nil {
|
|
|
565
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
566
|
+ }
|
|
|
567
|
+ if err := transactionContext.StartTransaction(); err != nil {
|
|
|
568
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
569
|
+ }
|
|
|
570
|
+ defer func() {
|
|
|
571
|
+ transactionContext.RollbackTransaction()
|
|
|
572
|
+ }()
|
|
|
573
|
+
|
|
|
574
|
+ productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
|
|
|
575
|
+ "transactionContext": transactionContext,
|
|
|
576
|
+ })
|
|
|
577
|
+ workShopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
|
|
|
578
|
+ "transactionContext": transactionContext,
|
|
|
579
|
+ })
|
|
|
580
|
+ //获取车间数据
|
|
|
581
|
+ workShopData, err := workShopRepo.FindOne(map[string]interface{}{
|
|
|
582
|
+ "workshopId": param.WorkshopId,
|
|
|
583
|
+ })
|
|
|
584
|
+ if err != nil {
|
|
|
585
|
+ return nil, application.ThrowError(application.ARG_ERROR, "车间数据不能存在"+err.Error())
|
|
|
586
|
+ }
|
|
|
587
|
+ if workShopData.CompanyId != operateInfo.CompanyId {
|
|
|
588
|
+ return nil, application.ThrowError(application.ARG_ERROR, "车间数据填写错误")
|
|
|
589
|
+ }
|
|
|
590
|
+ workStation, err := workShopData.FindWorkStation(param.WorkshopId, param.LineId, param.SectionId)
|
|
|
591
|
+ if err != nil {
|
|
|
592
|
+ return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
593
|
+ }
|
|
|
594
|
+
|
|
|
595
|
+ recordDate, err := time.ParseInLocation("2006-01-02", param.RecordDate, time.Local)
|
|
|
596
|
+ if err != nil {
|
|
|
597
|
+ return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
|
|
|
598
|
+ }
|
|
|
599
|
+
|
|
|
600
|
+ var operaterUser *domain.User
|
|
|
601
|
+ userService := domainService.NewUserService()
|
|
|
602
|
+ operaterUser, err = userService.User(operateInfo.UserId)
|
|
|
603
|
+ if err != nil {
|
|
|
604
|
+ return nil, application.ThrowError(application.ARG_ERROR, "获取审核人信息失败,"+err.Error())
|
|
|
605
|
+ }
|
|
|
606
|
+ for _, workerId := range param.WorkerId {
|
|
|
607
|
+ var workerUser *domain.User
|
|
|
608
|
+ workerUser, err = userService.User(workerId)
|
|
|
609
|
+ if err != nil {
|
|
|
610
|
+ return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息失败,"+err.Error())
|
|
|
611
|
+ }
|
|
|
612
|
+ var troubleData *domain.ProductTrouble
|
|
|
613
|
+ if param.Id > 0 {
|
|
|
614
|
+ troubleData, err = productTroubleRepo.FindOne(map[string]interface{}{
|
|
|
615
|
+ "id": param.Id,
|
|
|
616
|
+ })
|
|
|
617
|
+ if err != nil {
|
|
|
618
|
+ return nil, application.ThrowError(application.ARG_ERROR, "事故数据填写错误")
|
|
|
619
|
+ }
|
|
|
620
|
+ } else {
|
|
|
621
|
+ troubleData = &domain.ProductTrouble{
|
|
|
622
|
+ CompanyId: operateInfo.CompanyId,
|
|
|
623
|
+ OrgId: operateInfo.OrgId,
|
|
|
624
|
+ CreatedAt: time.Now(),
|
|
|
625
|
+ ApproveStatus: domain.TroubleWaitApprove,
|
|
|
626
|
+ }
|
|
|
627
|
+ }
|
|
|
628
|
+
|
|
|
629
|
+ troubleData.AmountLoss = param.AmountLoss
|
|
|
630
|
+ troubleData.ProductWorker = *workerUser
|
|
|
631
|
+ troubleData.RecordDate = recordDate
|
|
|
632
|
+ troubleData.Remark = param.Remark
|
|
|
633
|
+ troubleData.UpdatedAt = time.Now()
|
|
|
634
|
+ troubleData.WorkStation = *workStation
|
|
|
635
|
+ err = troubleData.SetTypes(param.Types)
|
|
|
636
|
+ if err != nil {
|
|
|
637
|
+ return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
638
|
+ }
|
|
|
639
|
+ if param.SaveAndApprove {
|
|
|
640
|
+ err = troubleData.Approve(operaterUser)
|
|
|
641
|
+ if err != nil {
|
|
|
642
|
+ return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
643
|
+ }
|
|
|
644
|
+ }
|
|
|
645
|
+ _, err = productTroubleRepo.Save(troubleData)
|
|
|
646
|
+ if err != nil {
|
|
|
647
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
648
|
+ }
|
|
|
649
|
+
|
|
|
650
|
+ }
|
|
|
651
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
652
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
653
|
+ }
|
|
|
654
|
+ return map[string]interface{}{}, nil
|
|
|
655
|
+} |