|
@@ -235,6 +235,48 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques |
|
@@ -235,6 +235,48 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques |
235
|
return
|
235
|
return
|
236
|
}
|
236
|
}
|
237
|
|
237
|
|
|
|
238
|
+//模板详情
|
|
|
239
|
+func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) (rsp *protocol.TemplateResponse, err error) {
|
|
|
240
|
+ var (
|
|
|
241
|
+ templates *models.AuditTemplate
|
|
|
242
|
+ forms []*models.AuditForm
|
|
|
243
|
+ )
|
|
|
244
|
+ rsp = &protocol.TemplateResponse{}
|
|
|
245
|
+ if templates, err = models.GetAuditTemplate(header.CompanyId, request.ChanceTypeId, request.TemplateId); err != nil {
|
|
|
246
|
+ log.Error(fmt.Sprintf("公司:%v chance_type_id:%v id:%v无模板 ", header.CompanyId, request.ChanceTypeId, request.TemplateId), err)
|
|
|
247
|
+ return
|
|
|
248
|
+ }
|
|
|
249
|
+ item := templates
|
|
|
250
|
+ //TODO:检查模板可见
|
|
|
251
|
+ //
|
|
|
252
|
+ //查询表单
|
|
|
253
|
+ if forms, err = models.GetAuditForms(header.CompanyId, item.Id); err != nil {
|
|
|
254
|
+ log.Error(err)
|
|
|
255
|
+ return
|
|
|
256
|
+ }
|
|
|
257
|
+ template := &protocol.Template{
|
|
|
258
|
+ Id: item.Id,
|
|
|
259
|
+ Name: item.Name,
|
|
|
260
|
+ Icon: item.Icon,
|
|
|
261
|
+ Doc: item.Doc,
|
|
|
262
|
+ FormList: make([]*protocol.Form, len(forms)),
|
|
|
263
|
+ Link: fmt.Sprintf("%v/#/ability/opportunity?id=%v", beego.AppConfig.String("h5_host"), item.Id),
|
|
|
264
|
+ }
|
|
|
265
|
+ for j := range forms {
|
|
|
266
|
+ form := forms[j]
|
|
|
267
|
+ template.FormList[j] = &protocol.Form{
|
|
|
268
|
+ Id: form.Id,
|
|
|
269
|
+ Label: form.Label,
|
|
|
270
|
+ Value: "",
|
|
|
271
|
+ InputType: form.InputType,
|
|
|
272
|
+ SectionType: form.Section,
|
|
|
273
|
+ Required: form.Required,
|
|
|
274
|
+ }
|
|
|
275
|
+ }
|
|
|
276
|
+ rsp.Template = template
|
|
|
277
|
+ return
|
|
|
278
|
+}
|
|
|
279
|
+
|
238
|
func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) {
|
280
|
func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) {
|
239
|
//if template.VisibleType ==
|
281
|
//if template.VisibleType ==
|
240
|
return
|
282
|
return
|
|
@@ -302,7 +344,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
@@ -302,7 +344,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
302
|
}
|
344
|
}
|
303
|
|
345
|
|
304
|
//生成提交记录
|
346
|
//生成提交记录
|
305
|
- if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
|
347
|
+ if _, err = orm.Insert(GenAuditFlowProcess_Submit(header.UserId, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
|
306
|
log.Error(err)
|
348
|
log.Error(err)
|
307
|
orm.Rollback()
|
349
|
orm.Rollback()
|
308
|
return
|
350
|
return
|
|
@@ -368,35 +410,67 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
@@ -368,35 +410,67 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
368
|
}
|
410
|
}
|
369
|
|
411
|
|
370
|
//机会编辑
|
412
|
//机会编辑
|
371
|
-func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmitRequest) (rsp *protocol.ChanceSubmitResponse, err error) {
|
413
|
+func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdateRequest) (rsp *protocol.ChanceUpdateResponse, err error) {
|
372
|
var (
|
414
|
var (
|
373
|
template *models.AuditTemplate
|
415
|
template *models.AuditTemplate
|
374
|
chance *models.Chance
|
416
|
chance *models.Chance
|
375
|
auditConfig *protocol.AuditConfig
|
417
|
auditConfig *protocol.AuditConfig
|
376
|
chanceData *models.ChanceData
|
418
|
chanceData *models.ChanceData
|
377
|
- //auditFlows []*models.AuditFlowProcess
|
419
|
+ //auditFlows *models.AuditFlowProcess
|
378
|
updateMap = make(map[string]interface{})
|
420
|
updateMap = make(map[string]interface{})
|
|
|
421
|
+
|
|
|
422
|
+ auditFlows []*models.AuditFlowProcess
|
|
|
423
|
+ suplusApprove SuplusApprove
|
|
|
424
|
+ chanceType *models.ChanceType
|
379
|
)
|
425
|
)
|
|
|
426
|
+ //验证机会是否存在
|
380
|
if chance, err = models.GetChanceById(request.Id); err != nil {
|
427
|
if chance, err = models.GetChanceById(request.Id); err != nil {
|
381
|
- log.Error(err)
|
428
|
+ log.Error(request.Id, err)
|
|
|
429
|
+ err = protocol.NewErrWithMessage(5101)
|
|
|
430
|
+ return
|
|
|
431
|
+ }
|
|
|
432
|
+ //1.模板是否存在
|
|
|
433
|
+ if template, err = models.GetAuditTemplateById(int64(chance.AuditTemplateId)); err != nil {
|
|
|
434
|
+ log.Error("模板不存在:", chance.AuditTemplateId, err)
|
382
|
return
|
435
|
return
|
383
|
}
|
436
|
}
|
384
|
- //TODO:非本人 1.需要验证角色权限,是否是审核人
|
437
|
+ if chanceType, err = models.GetChanceTypeById(chance.ChanceTypeId); err != nil {
|
|
|
438
|
+ log.Error("一级分类不存在:", chance.ChanceTypeId, err)
|
|
|
439
|
+ return
|
|
|
440
|
+ }
|
|
|
441
|
+ //编辑重新发布 是否可以重新发布
|
|
|
442
|
+ if request.IsPublish && chance.ReviewStatus == protocol.ReviewStatusReturn && chance.UserId == header.UserId {
|
|
|
443
|
+ request.IsPublish = false
|
|
|
444
|
+ //当前没有被人审核过
|
|
|
445
|
+ //if _, e := models.GetAuditFlowProcessApproved(request.Id, 1); e == orm.ErrNoRows && chance.AuditLevel == 1 {
|
|
|
446
|
+ // //当前状态是退回-待处理
|
|
|
447
|
+ //
|
|
|
448
|
+ //}
|
|
|
449
|
+ if _, e := models.GetAuditFlowProcessByReview(request.Id, 0, protocol.ReviewStatusWait); e == nil {
|
|
|
450
|
+ request.IsPublish = true
|
|
|
451
|
+ }
|
|
|
452
|
+ } else {
|
|
|
453
|
+ request.IsPublish = false
|
|
|
454
|
+ }
|
|
|
455
|
+ //TODO:非本人 1.需要验证角色权限 2是否是审核人 3.是否是本人 (目前本人才可以审核)
|
385
|
if chance.UserId != header.Uid {
|
456
|
if chance.UserId != header.Uid {
|
386
|
- err = protocol.NewErrWithMessage(1)
|
457
|
+ err = protocol.NewErrWithMessage(5206)
|
387
|
log.Error(fmt.Sprintf("user:%v 无权限操作机会 chance:%v", header.Uid, chance.Id))
|
458
|
log.Error(fmt.Sprintf("user:%v 无权限操作机会 chance:%v", header.Uid, chance.Id))
|
388
|
return
|
459
|
return
|
389
|
}
|
460
|
}
|
390
|
- //TODO:验证机会当前是否在审核中
|
|
|
391
|
//1.模板是否存在
|
461
|
//1.模板是否存在
|
392
|
- if template, err = models.GetAuditTemplateById(request.AuditTemplateId); err != nil {
|
|
|
393
|
- log.Error("模板不存在:", request.AuditTemplateId, err)
|
462
|
+ if template, err = models.GetAuditTemplateById(chance.AuditTemplateId); err != nil {
|
|
|
463
|
+ log.Error("模板不存在:", chance.AuditTemplateId, err)
|
|
|
464
|
+ err = protocol.NewErrWithMessage(5301)
|
394
|
return
|
465
|
return
|
395
|
}
|
466
|
}
|
396
|
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
|
467
|
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
|
397
|
orm := orm.NewOrm()
|
468
|
orm := orm.NewOrm()
|
398
|
orm.Begin()
|
469
|
orm.Begin()
|
399
|
{
|
470
|
{
|
|
|
471
|
+ if request.IsPublish {
|
|
|
472
|
+ updateMap["ReviewStatus"] = int8(protocol.ReviewStatusAuditging)
|
|
|
473
|
+ }
|
400
|
updateMap["AuditTemplateConfig"] = common.AssertJson(auditConfig)
|
474
|
updateMap["AuditTemplateConfig"] = common.AssertJson(auditConfig)
|
401
|
updateMap["Content"] = request.Content
|
475
|
updateMap["Content"] = request.Content
|
402
|
updateMap["SourceContent"] = common.AssertJson(request.FormList)
|
476
|
updateMap["SourceContent"] = common.AssertJson(request.FormList)
|
|
@@ -440,11 +514,56 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
@@ -440,11 +514,56 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
440
|
}
|
514
|
}
|
441
|
}
|
515
|
}
|
442
|
}
|
516
|
}
|
443
|
- orm.Commit()
|
|
|
444
|
|
517
|
|
445
|
- //6.激活审核流
|
|
|
446
|
- //TODO:7.发送消息通知给审核人(审核消息)
|
|
|
447
|
- rsp = &protocol.ChanceSubmitResponse{}
|
518
|
+ {
|
|
|
519
|
+ if request.IsPublish {
|
|
|
520
|
+
|
|
|
521
|
+ //更新待处理->提交
|
|
|
522
|
+ if err = models.UpdatetAuditFlowProcessToSubmit(orm, request.Id, 0, protocol.ReviewStatusSubmit, header.UserId); err != nil {
|
|
|
523
|
+ log.Error(err)
|
|
|
524
|
+ orm.Rollback()
|
|
|
525
|
+ return
|
|
|
526
|
+ }
|
|
|
527
|
+ //4.查询审核配置
|
|
|
528
|
+ //5.生成审核流
|
|
|
529
|
+ if auditFlows, err = GenAuditFlowProcess(header, chance.Id, chance.DepartmentId, template.Id, auditConfig); err != nil {
|
|
|
530
|
+ log.Error(err)
|
|
|
531
|
+ orm.Rollback()
|
|
|
532
|
+ return
|
|
|
533
|
+ }
|
|
|
534
|
+ for i := 0; i < len(auditFlows); i++ {
|
|
|
535
|
+ auditFlows[i].ApproveMessage = fmt.Sprintf(protocol.MessageApproving, chanceType.Name)
|
|
|
536
|
+ //auditFlows[i].TemplateId = int(template.Id)
|
|
|
537
|
+ if _, err = orm.Insert(auditFlows[i]); err != nil {
|
|
|
538
|
+ log.Error(err)
|
|
|
539
|
+ orm.Rollback()
|
|
|
540
|
+ return
|
|
|
541
|
+ }
|
|
|
542
|
+ }
|
|
|
543
|
+ if len(auditFlows) > 0 {
|
|
|
544
|
+ //7.发送审批实例给审批服务器
|
|
|
545
|
+ if m, e := suplusApprove.NewApproveInstance(header, auditFlows); e != nil {
|
|
|
546
|
+ log.Error(fmt.Sprintf("uid:%v", header.UserId), "request suplus-approve.NewApproveInstance err", e)
|
|
|
547
|
+ orm.Rollback()
|
|
|
548
|
+ err = e
|
|
|
549
|
+ return
|
|
|
550
|
+ } else {
|
|
|
551
|
+ //7.发送消息通知给审核人(审核消息)
|
|
|
552
|
+ for i := range m.MessageData {
|
|
|
553
|
+ message := m.MessageData[i]
|
|
|
554
|
+ if err = agg.SendApproveMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,
|
|
|
555
|
+ header.CompanyId, chance.Id, chance.ChanceTypeId, protocol.ReviewStatusAuditging); err != nil {
|
|
|
556
|
+ log.Error(err)
|
|
|
557
|
+ orm.Rollback()
|
|
|
558
|
+ return
|
|
|
559
|
+ }
|
|
|
560
|
+ }
|
|
|
561
|
+ }
|
|
|
562
|
+ }
|
|
|
563
|
+ }
|
|
|
564
|
+ }
|
|
|
565
|
+ orm.Commit()
|
|
|
566
|
+ rsp = &protocol.ChanceUpdateResponse{}
|
448
|
return
|
567
|
return
|
449
|
}
|
568
|
}
|
450
|
|
569
|
|
|
@@ -549,7 +668,10 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
@@ -549,7 +668,10 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
549
|
return
|
668
|
return
|
550
|
}
|
669
|
}
|
551
|
orm.Commit()
|
670
|
orm.Commit()
|
552
|
- rsp = &protocol.ChanceChangeScoreResponse{}
|
671
|
+ rsp = &protocol.ChanceChangeScoreResponse{
|
|
|
672
|
+ DiscoveryScore: result.DiscoveryScore,
|
|
|
673
|
+ DiscoveryScorePercent: result.DiscoveryScorePercent,
|
|
|
674
|
+ }
|
553
|
return
|
675
|
return
|
554
|
}
|
676
|
}
|
555
|
|
677
|
|
|
@@ -626,18 +748,19 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe |
|
@@ -626,18 +748,19 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe |
626
|
}
|
748
|
}
|
627
|
|
749
|
|
628
|
//生成审批流-提交记录
|
750
|
//生成审批流-提交记录
|
629
|
-func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) {
|
751
|
+func GenAuditFlowProcess_Submit(userId, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) {
|
630
|
v = &models.AuditFlowProcess{
|
752
|
v = &models.AuditFlowProcess{
|
631
|
Id: idgen.Next(),
|
753
|
Id: idgen.Next(),
|
632
|
ChanceId: chanceId,
|
754
|
ChanceId: chanceId,
|
633
|
- Uid: header.UserId,
|
755
|
+ Uid: userId,
|
634
|
CreateAt: time.Now(),
|
756
|
CreateAt: time.Now(),
|
635
|
UpdateAt: time.Now(),
|
757
|
UpdateAt: time.Now(),
|
636
|
ApproveTime: time.Now(),
|
758
|
ApproveTime: time.Now(),
|
637
|
EnableStatus: 1,
|
759
|
EnableStatus: 1,
|
|
|
760
|
+ IsActive: 1,
|
638
|
ReviewStatus: int8(reviewStatus),
|
761
|
ReviewStatus: int8(reviewStatus),
|
639
|
}
|
762
|
}
|
640
|
- if approver, err := models.GetUsersById(header.Uid); err != nil {
|
763
|
+ if approver, err := models.GetUsersById(userId); err != nil {
|
641
|
log.Error(err)
|
764
|
log.Error(err)
|
642
|
return
|
765
|
return
|
643
|
} else {
|
766
|
} else {
|
|
@@ -656,7 +779,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
@@ -656,7 +779,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
656
|
company *models.Company
|
779
|
company *models.Company
|
657
|
roleName string
|
780
|
roleName string
|
658
|
approver *models.User
|
781
|
approver *models.User
|
659
|
- roleId []int
|
782
|
+ roleIds []int
|
|
|
783
|
+ roleId int
|
660
|
)
|
784
|
)
|
661
|
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
|
785
|
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
|
662
|
if err == orm.ErrNoRows {
|
786
|
if err == orm.ErrNoRows {
|
|
@@ -738,11 +862,15 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
@@ -738,11 +862,15 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
738
|
}
|
862
|
}
|
739
|
break
|
863
|
break
|
740
|
case protocol.AuditByRole:
|
864
|
case protocol.AuditByRole:
|
741
|
- if e := json.Unmarshal([]byte(config.ToRole), &roleId); e == nil {
|
|
|
742
|
- if userIds, err = getRoleUsers(header, roleId[0]); err != nil {
|
865
|
+ if e := json.Unmarshal([]byte(config.ToRole), &roleIds); e == nil {
|
|
|
866
|
+ if userIds, err = getRoleUsers(header, roleIds[0]); err != nil {
|
743
|
log.Error(err)
|
867
|
log.Error(err)
|
744
|
return
|
868
|
return
|
745
|
}
|
869
|
}
|
|
|
870
|
+ if role, e := models.GetRoleById(roleIds[0]); e == nil {
|
|
|
871
|
+ roleName = role.Name
|
|
|
872
|
+ roleId = role.Id
|
|
|
873
|
+ }
|
746
|
} else {
|
874
|
} else {
|
747
|
log.Error(config.ToRole, e)
|
875
|
log.Error(config.ToRole, e)
|
748
|
}
|
876
|
}
|
|
@@ -779,6 +907,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
@@ -779,6 +907,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
779
|
ActionType: int(config.ActionType),
|
907
|
ActionType: int(config.ActionType),
|
780
|
RoleName: roleName,
|
908
|
RoleName: roleName,
|
781
|
UserName: approver.NickName,
|
909
|
UserName: approver.NickName,
|
|
|
910
|
+ RoleId: roleId,
|
782
|
ReviewStatus: protocol.ReviewStatusAuditging,
|
911
|
ReviewStatus: protocol.ReviewStatusAuditging,
|
783
|
TemplateId: int(templateId),
|
912
|
TemplateId: int(templateId),
|
784
|
}
|
913
|
}
|
|
@@ -786,7 +915,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
@@ -786,7 +915,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
786
|
item.IsActive = 1
|
915
|
item.IsActive = 1
|
787
|
item.EnableStatus = 1
|
916
|
item.EnableStatus = 1
|
788
|
}
|
917
|
}
|
789
|
- log.Info(fmt.Sprintf("生成机会审批流:chance_id:%v audit_id:%v audit_level:%v audit_user:%v action_type:%v", chanceId, item.Id, config.Level, uid, resolveActionType(config.ActionType)))
|
918
|
+ log.Info(fmt.Sprintf("生成机会审批流:chance_id:%v audit_id:%v audit_level:%v audit_user:%v action_type:%v is_active:%v", chanceId, item.Id, config.Level, uid, resolveActionType(config.ActionType), item.IsActive))
|
790
|
v = append(v, item)
|
919
|
v = append(v, item)
|
791
|
}
|
920
|
}
|
792
|
}
|
921
|
}
|
|
@@ -794,10 +923,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
@@ -794,10 +923,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
794
|
}
|
923
|
}
|
795
|
func resolveActionType(t uint) string {
|
924
|
func resolveActionType(t uint) string {
|
796
|
if t == 1 {
|
925
|
if t == 1 {
|
797
|
- return "or"
|
926
|
+ return "and"
|
798
|
}
|
927
|
}
|
799
|
if t == 2 {
|
928
|
if t == 2 {
|
800
|
- return "and"
|
929
|
+ return "or"
|
801
|
}
|
930
|
}
|
802
|
return fmt.Sprintf("%v", t)
|
931
|
return fmt.Sprintf("%v", t)
|
803
|
}
|
932
|
}
|