|
@@ -347,12 +347,6 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
@@ -347,12 +347,6 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
347
|
DepartmentId: request.RelatedDepartment,
|
347
|
DepartmentId: request.RelatedDepartment,
|
348
|
Code: fmt.Sprintf("%v%v", chanceType.Code, template.Code),
|
348
|
Code: fmt.Sprintf("%v%v", chanceType.Code, template.Code),
|
349
|
}
|
349
|
}
|
350
|
- if _, err = orm.Insert(chance); err != nil {
|
|
|
351
|
- log.Error(err)
|
|
|
352
|
- orm.Rollback()
|
|
|
353
|
- return
|
|
|
354
|
- }
|
|
|
355
|
-
|
|
|
356
|
//生成提交记录
|
350
|
//生成提交记录
|
357
|
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header.UserId, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
|
351
|
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header.UserId, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
|
358
|
log.Error(err)
|
352
|
log.Error(err)
|
|
@@ -375,6 +369,12 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
@@ -375,6 +369,12 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
375
|
return
|
369
|
return
|
376
|
}
|
370
|
}
|
377
|
}
|
371
|
}
|
|
|
372
|
+ //发送提交日志
|
|
|
373
|
+ if err = agg.SaveApproveLog(orm, 1, header.UserId, chance.Id); err != nil {
|
|
|
374
|
+ log.Error(err)
|
|
|
375
|
+ orm.Rollback()
|
|
|
376
|
+ return
|
|
|
377
|
+ }
|
378
|
if len(auditFlows) > 0 {
|
378
|
if len(auditFlows) > 0 {
|
379
|
//7.发送审批实例给审批服务器
|
379
|
//7.发送审批实例给审批服务器
|
380
|
if m, e := suplusApprove.NewApproveInstance(header, auditFlows); e != nil {
|
380
|
if m, e := suplusApprove.NewApproveInstance(header, auditFlows); e != nil {
|
|
@@ -394,8 +394,22 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
@@ -394,8 +394,22 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
394
|
}
|
394
|
}
|
395
|
}
|
395
|
}
|
396
|
}
|
396
|
}
|
|
|
397
|
+ } else {
|
|
|
398
|
+ //更新已经审核过
|
|
|
399
|
+ if auditConfig.NoApprover == protocol.NoApproverPass {
|
|
|
400
|
+ if err = setChanceAutoPass(header, chance, orm); err != nil {
|
|
|
401
|
+ log.Error(err)
|
|
|
402
|
+ orm.Rollback()
|
|
|
403
|
+ return
|
|
|
404
|
+ }
|
|
|
405
|
+ }
|
|
|
406
|
+ }
|
|
|
407
|
+ //插入机会
|
|
|
408
|
+ if _, err = orm.Insert(chance); err != nil {
|
|
|
409
|
+ log.Error(err)
|
|
|
410
|
+ orm.Rollback()
|
|
|
411
|
+ return
|
397
|
}
|
412
|
}
|
398
|
-
|
|
|
399
|
//6.文件
|
413
|
//6.文件
|
400
|
{
|
414
|
{
|
401
|
data := &models.ChanceData{
|
415
|
data := &models.ChanceData{
|
|
@@ -413,15 +427,36 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
@@ -413,15 +427,36 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
413
|
return
|
427
|
return
|
414
|
}
|
428
|
}
|
415
|
}
|
429
|
}
|
416
|
- //发送提交日志
|
|
|
417
|
- if err = agg.SaveApproveLog(orm, 1, header.UserId, chance.Id); err != nil {
|
430
|
+ orm.Commit()
|
|
|
431
|
+
|
|
|
432
|
+ rsp = &protocol.ChanceSubmitResponse{}
|
|
|
433
|
+ return
|
|
|
434
|
+}
|
|
|
435
|
+
|
|
|
436
|
+//设置机会自动通过
|
|
|
437
|
+func setChanceAutoPass(header *protocol.RequestHeader, chance *models.Chance, orm orm.Ormer) (err error) {
|
|
|
438
|
+ var (
|
|
|
439
|
+ approveData protocol.ApproveData
|
|
|
440
|
+ )
|
|
|
441
|
+ if approveData.Score, err = ChanceCalculateDefautlScore(header); err != nil {
|
418
|
log.Error(err)
|
442
|
log.Error(err)
|
419
|
- orm.Rollback()
|
|
|
420
|
return
|
443
|
return
|
421
|
}
|
444
|
}
|
422
|
- orm.Commit()
|
445
|
+ approveData.PublicData = protocol.PublicData{PublishStatus: protocol.PublicToCompany}
|
|
|
446
|
+ chance.ApproveData = common.AssertJson(approveData)
|
|
|
447
|
+ chance.ApproveTime = time.Now()
|
423
|
|
448
|
|
424
|
- rsp = &protocol.ChanceSubmitResponse{}
|
449
|
+ if err = agg.SendApproveMsg(chance.UserId, "",
|
|
|
450
|
+ header.CompanyId, chance.Id, chance.ChanceTypeId, protocol.ReviewStatusAutoPass); err != nil {
|
|
|
451
|
+ log.Error(err)
|
|
|
452
|
+
|
|
|
453
|
+ return
|
|
|
454
|
+ }
|
|
|
455
|
+ if err = agg.SaveApproveLog(orm, 6, chance.UserId, chance.Id, approveData.Score.BasicScore, approveData.Score.ExtraScore, approveData.Score.ValueScore); err != nil {
|
|
|
456
|
+ log.Error(err)
|
|
|
457
|
+ //orm.Rollback()
|
|
|
458
|
+ return
|
|
|
459
|
+ }
|
425
|
return
|
460
|
return
|
426
|
}
|
461
|
}
|
427
|
|
462
|
|
|
@@ -488,21 +523,6 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate |
|
@@ -488,21 +523,6 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate |
488
|
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
|
523
|
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
|
489
|
orm := orm.NewOrm()
|
524
|
orm := orm.NewOrm()
|
490
|
orm.Begin()
|
525
|
orm.Begin()
|
491
|
- {
|
|
|
492
|
- if request.IsPublish {
|
|
|
493
|
- updateMap["ReviewStatus"] = int8(protocol.ReviewStatusAuditging)
|
|
|
494
|
- }
|
|
|
495
|
- updateMap["AuditTemplateConfig"] = common.AssertJson(auditConfig)
|
|
|
496
|
- updateMap["Content"] = request.Content
|
|
|
497
|
- updateMap["SourceContent"] = common.AssertJson(request.FormList)
|
|
|
498
|
-
|
|
|
499
|
- if err = utils.UpdateTableByMapWithOrmer(orm, &models.Chance{Id: chance.Id}, updateMap); err != nil {
|
|
|
500
|
- log.Error(err)
|
|
|
501
|
- orm.Rollback()
|
|
|
502
|
- return
|
|
|
503
|
- }
|
|
|
504
|
- }
|
|
|
505
|
-
|
|
|
506
|
//6.更新文件
|
526
|
//6.更新文件
|
507
|
{
|
527
|
{
|
508
|
if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil {
|
528
|
if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil {
|
|
@@ -579,15 +599,48 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate |
|
@@ -579,15 +599,48 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate |
579
|
}
|
599
|
}
|
580
|
}
|
600
|
}
|
581
|
}
|
601
|
}
|
582
|
- }
|
|
|
583
|
- //发送提交日志
|
|
|
584
|
- if err = agg.SaveApproveLog(orm, 1, chance.UserId, chance.Id); err != nil {
|
|
|
585
|
- log.Error(err)
|
|
|
586
|
- orm.Rollback()
|
|
|
587
|
- return
|
602
|
+ } else {
|
|
|
603
|
+ //发送提交日志
|
|
|
604
|
+ if err = agg.SaveApproveLog(orm, 1, chance.UserId, chance.Id); err != nil {
|
|
|
605
|
+ log.Error(err)
|
|
|
606
|
+ orm.Rollback()
|
|
|
607
|
+ return
|
|
|
608
|
+ }
|
|
|
609
|
+ //更新已经审核过
|
|
|
610
|
+ if auditConfig.NoApprover == protocol.NoApproverPass {
|
|
|
611
|
+ if err = setChanceAutoPass(header, chance, orm); err != nil {
|
|
|
612
|
+ log.Error(err)
|
|
|
613
|
+ orm.Rollback()
|
|
|
614
|
+ return
|
|
|
615
|
+ }
|
|
|
616
|
+ updateMap["ApproveTime"] = time.Now()
|
|
|
617
|
+ updateMap["ApproveData"] = chance.ApproveData
|
|
|
618
|
+ updateMap["PublishStatus"] = chance.PublishStatus
|
|
|
619
|
+ updateMap["ReviewStatus"] = chance.ReviewStatus
|
|
|
620
|
+ updateMap["BasicScore"] = chance.BasicScore
|
|
|
621
|
+ updateMap["ExtraScore"] = chance.ExtraScore
|
|
|
622
|
+ updateMap["ValueScore"] = chance.ValueScore
|
|
|
623
|
+ updateMap["DiscoveryScore"] = chance.DiscoveryScore
|
|
|
624
|
+ updateMap["PublishStatus"] = chance.PublishStatus
|
|
|
625
|
+ }
|
588
|
}
|
626
|
}
|
589
|
}
|
627
|
}
|
590
|
}
|
628
|
}
|
|
|
629
|
+
|
|
|
630
|
+ {
|
|
|
631
|
+ if request.IsPublish {
|
|
|
632
|
+ updateMap["ReviewStatus"] = int8(protocol.ReviewStatusAuditging)
|
|
|
633
|
+ }
|
|
|
634
|
+ updateMap["AuditTemplateConfig"] = common.AssertJson(auditConfig)
|
|
|
635
|
+ updateMap["Content"] = request.Content
|
|
|
636
|
+ updateMap["SourceContent"] = common.AssertJson(request.FormList)
|
|
|
637
|
+
|
|
|
638
|
+ if err = utils.UpdateTableByMapWithOrmer(orm, &models.Chance{Id: chance.Id}, updateMap); err != nil {
|
|
|
639
|
+ log.Error(err)
|
|
|
640
|
+ orm.Rollback()
|
|
|
641
|
+ return
|
|
|
642
|
+ }
|
|
|
643
|
+ }
|
591
|
orm.Commit()
|
644
|
orm.Commit()
|
592
|
rsp = &protocol.ChanceUpdateResponse{}
|
645
|
rsp = &protocol.ChanceUpdateResponse{}
|
593
|
return
|
646
|
return
|
|
@@ -802,6 +855,36 @@ func ChanceCalculateScore(header *protocol.RequestHeader, request *protocol.Chan |
|
@@ -802,6 +855,36 @@ func ChanceCalculateScore(header *protocol.RequestHeader, request *protocol.Chan |
802
|
return
|
855
|
return
|
803
|
}
|
856
|
}
|
804
|
|
857
|
|
|
|
858
|
+//计算默认发现分
|
|
|
859
|
+func ChanceCalculateDefautlScore(header *protocol.RequestHeader) (rsp protocol.Score, err error) {
|
|
|
860
|
+ var (
|
|
|
861
|
+ config *models.SysConfig
|
|
|
862
|
+ scoreConfig protocol.ScoreConfig
|
|
|
863
|
+ sum float64
|
|
|
864
|
+ )
|
|
|
865
|
+ rsp = protocol.Score{}
|
|
|
866
|
+ if config, err = models.GetSysConfigByCompanyId(int(header.CompanyId), models.KeyScore); err != nil {
|
|
|
867
|
+ err = protocol.NewErrWithMessage(5510)
|
|
|
868
|
+ log.Error(header.CompanyId, err)
|
|
|
869
|
+ return
|
|
|
870
|
+ }
|
|
|
871
|
+ if err = json.Unmarshal([]byte(config.Content), &scoreConfig); err != nil {
|
|
|
872
|
+ err = protocol.NewErrWithMessage(5510)
|
|
|
873
|
+ log.Error(err)
|
|
|
874
|
+ return
|
|
|
875
|
+ }
|
|
|
876
|
+ basic := scoreConfig.BasicScore.Min
|
|
|
877
|
+ sum += scoreConfig.BasicScore.Max * scoreConfig.DiscoveryScore.BasicFactor
|
|
|
878
|
+ extral := scoreConfig.BasicScore.Min
|
|
|
879
|
+ sum += scoreConfig.ExtraScore.Max * scoreConfig.DiscoveryScore.ExtraFactor
|
|
|
880
|
+ value := scoreConfig.BasicScore.Min
|
|
|
881
|
+ sum += scoreConfig.ValueScore.Max * scoreConfig.DiscoveryScore.ValueFactor
|
|
|
882
|
+ rsp.DiscoveryScore = basic*scoreConfig.DiscoveryScore.BasicFactor + extral*scoreConfig.DiscoveryScore.ExtraFactor + value*scoreConfig.DiscoveryScore.ValueFactor
|
|
|
883
|
+ rsp.DiscoveryScorePercent = int((rsp.DiscoveryScore / sum) * 100)
|
|
|
884
|
+ log.Debug(fmt.Sprintf("计算发现-> score_config:%v score:%v 总分:%v 发现分:%v 发现分百分比:%v", common.AssertJson(scoreConfig), common.AssertJson(rsp), sum, rsp.DiscoveryScore, rsp.DiscoveryScorePercent))
|
|
|
885
|
+ return
|
|
|
886
|
+}
|
|
|
887
|
+
|
805
|
//机会权限
|
888
|
//机会权限
|
806
|
func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePermissionRequest) (rsp *protocol.ChancePermissionResponse, err error) {
|
889
|
func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePermissionRequest) (rsp *protocol.ChancePermissionResponse, err error) {
|
807
|
var ()
|
890
|
var ()
|
|
@@ -958,6 +1041,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
@@ -958,6 +1041,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
958
|
}
|
1041
|
}
|
959
|
for j := 0; j < len(userIds); j++ {
|
1042
|
for j := 0; j < len(userIds); j++ {
|
960
|
uid := userIds[j]
|
1043
|
uid := userIds[j]
|
|
|
1044
|
+ if uid == 0 && auditConfig.NoApprover == protocol.NoApproverPass {
|
|
|
1045
|
+ log.Info(fmt.Sprintf("配置审核人为空 自动通过审批 chance_id:%v", chanceId))
|
|
|
1046
|
+ continue
|
|
|
1047
|
+ }
|
961
|
if uid == 0 && auditConfig.NoApprover == protocol.NoApproverToAdmin { //审批人为空 转交给管理员
|
1048
|
if uid == 0 && auditConfig.NoApprover == protocol.NoApproverToAdmin { //审批人为空 转交给管理员
|
962
|
uid = admin.Id
|
1049
|
uid = admin.Id
|
963
|
}
|
1050
|
}
|