作者 yangfu

机会详情

@@ -294,6 +294,26 @@ func (this *ChanceController) ChanceDetail() { @@ -294,6 +294,26 @@ func (this *ChanceController) ChanceDetail() {
294 msg = protocol.NewReturnResponse(chance.ChanceDetail(header, request)) 294 msg = protocol.NewReturnResponse(chance.ChanceDetail(header, request))
295 } 295 }
296 296
  297 +//ChanceApproveProcess 机会审核流程信息
  298 +//func(this *ChanceController)ChanceApproveProcess(){
  299 +// var msg *protocol.ResponseMessage
  300 +// defer func() {
  301 +// this.Resp(msg)
  302 +// }()
  303 +// var request *protocol.ChanceApproveProcessRequest
  304 +// if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
  305 +// log.Error(err)
  306 +// msg = protocol.BadRequestParam(1)
  307 +// return
  308 +// }
  309 +// if b,m :=this.Valid(request);!b{
  310 +// msg = m
  311 +// return
  312 +// }
  313 +// header := controllers.GetRequestHeader(this.Ctx)
  314 +// msg = protocol.NewReturnResponse(chance.ChanceApproveProcess(header,request))
  315 +//}
  316 +
297 //ChanceDelete 机会删除 317 //ChanceDelete 机会删除
298 //@router /chanceDelete [post] 318 //@router /chanceDelete [post]
299 func (this *ChanceController) ChanceDelete() { 319 func (this *ChanceController) ChanceDelete() {
@@ -25,6 +25,9 @@ type AuditFlowProcess struct { @@ -25,6 +25,9 @@ type AuditFlowProcess struct {
25 CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` 25 CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
26 UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` 26 UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
27 EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 (被驳回以后,未完成的审核置为无效)"` 27 EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 (被驳回以后,未完成的审核置为无效)"`
  28 + UserName string `orm:"column(user_name);size(50)" description:"用户名-冗余"`
  29 + RoleName string `orm:"column(role_name);size(50)" description:"角色名-冗余"`
  30 + RoleId int `orm:"column(role_id);size(50)" description:"角色id-冗余"`
28 } 31 }
29 32
30 func (t *AuditFlowProcess) TableName() string { 33 func (t *AuditFlowProcess) TableName() string {
@@ -114,3 +117,13 @@ func UpdatetAuditFlowProcessNoApprove(chanceId int64, level int, reviewStatus in @@ -114,3 +117,13 @@ func UpdatetAuditFlowProcessNoApprove(chanceId int64, level int, reviewStatus in
114 } 117 }
115 return 118 return
116 } 119 }
  120 +
  121 +//获取机会审核流信息
  122 +func GetAuditFlowProcessList(chanceId int64) (v []*AuditFlowProcess, err error) {
  123 + o := orm.NewOrm()
  124 + sql := "select * from audit_flow_process where chance_id=? and enable_status=1 order by id,review_status"
  125 + if _, err = o.Raw(sql, chanceId).QueryRows(&v); err == nil {
  126 + return v, nil
  127 + }
  128 + return nil, err
  129 +}
@@ -30,6 +30,7 @@ type Chance struct { @@ -30,6 +30,7 @@ type Chance struct {
30 ValueSorce float64 `orm:"column(value_sorce);null;digits(4);decimals(1)" description:"价值评分"` 30 ValueSorce float64 `orm:"column(value_sorce);null;digits(4);decimals(1)" description:"价值评分"`
31 DiscoverySorce float64 `orm:"column(discovery_sorce);null;digits(4);decimals(1)" description:"发现得分(发现得分=基础评分*系数 + 附加评分*系数 + 价值评分*系数)"` 31 DiscoverySorce float64 `orm:"column(discovery_sorce);null;digits(4);decimals(1)" description:"发现得分(发现得分=基础评分*系数 + 附加评分*系数 + 价值评分*系数)"`
32 PublishStatus int `orm:"column(publish_status)" description:"公开状态 0未公开、1部门公开、2公司公开"` 32 PublishStatus int `orm:"column(publish_status)" description:"公开状态 0未公开、1部门公开、2公司公开"`
  33 + PublishData string `orm:"column(publish_data)" description:"公开数据 冗余"`
33 AuditLevel int `orm:"column(audit_level)" description:"当前审批步骤"` 34 AuditLevel int `orm:"column(audit_level)" description:"当前审批步骤"`
34 } 35 }
35 36
@@ -219,8 +219,10 @@ type ChanceDetailRequest struct { @@ -219,8 +219,10 @@ type ChanceDetailRequest struct {
219 Id int64 `json:"id"` //机会编号 219 Id int64 `json:"id"` //机会编号
220 } 220 }
221 type ChanceDetailResponse struct { 221 type ChanceDetailResponse struct {
222 - ChanceDetail ChanceItem `json:"chanceDetail"`  
223 - ApproveProcess interface{} `json:"approveProcess"` 222 + ChanceDetail ChanceItem `json:"chanceDetail"`
  223 + PublicData *PublicData `json:"publicData"`
  224 + ApproveProcess []*ProcessItem `json:"approveProcess"`
  225 + ApproveAccess *ApproveAccess `json:"approveAccess"` //
224 } 226 }
225 227
226 /*ChanceDelete 机会删除*/ 228 /*ChanceDelete 机会删除*/
@@ -26,3 +26,74 @@ type ChanceApproveRequest struct { @@ -26,3 +26,74 @@ type ChanceApproveRequest struct {
26 } 26 }
27 type ChanceApproveResponse struct { 27 type ChanceApproveResponse struct {
28 } 28 }
  29 +
  30 +/*ChanceApproveProcess 机会审核流程信息*/
  31 +type ChanceApproveProcessRequest struct {
  32 + ChanceId int64 `json:"chanceId"`
  33 +}
  34 +type ChanceApproveProcessResponse struct {
  35 + ApproveProcess []*ProcessItem `json:"approveProcess"`
  36 + ApproveAccess *ApproveAccess `json:"approveOperate"`
  37 +}
  38 +
  39 +//进程项
  40 +type ProcessItem struct {
  41 + Id int64 `json:"id"`
  42 + ReviewStatus int `json:"reviewStatus"` //当前步骤审批状态 0-待处理 1- 待审核 2- 退回 3-通过 4-提交 6-撤销
  43 + ApproveWay int `json:"approveWay"` //审批方式 1 会签 2 或签
  44 + ApproveType int `json:"approveType"` //审批类型 1 业务区域负责人 2 指定成员 3 角色
  45 + ApproveTime int64 `json:"approveTime"` //审核时间
  46 + //Role Role `json:"role"` //角色
  47 + Uid int64 `json:"uid"`
  48 + Name string `json:"name"`
  49 + RoleName string `json:"roleName"`
  50 + Role int `json:"-"`
  51 + ApproveData ApproveData `json:"ApproveData"` //审核数据
  52 + //ApproveUser UserItem `json:"approveUser"` //审核人 //状态不是审核中
  53 + ApproveUsers []UserItem `json:"approveUsers"` //审核人员 //1 会签 2 或签 //审核中 1.部门长 2.角色
  54 +}
  55 +
  56 +//用户项
  57 +type UserItem struct {
  58 + Uid int64 `json:"uid"`
  59 + Name string `json:"name"`
  60 +}
  61 +
  62 +//角色项
  63 +type Role struct {
  64 + Id int `json:"id"`
  65 + Name string `json:"name"`
  66 +}
  67 +
  68 +//审核数据 审核通过
  69 +type ApproveData struct {
  70 + PublicData *PublicData `json:"publicData"` // 公开数据
  71 + Score *Score `json:"score"`
  72 +}
  73 +
  74 +//公开数据
  75 +type PublicData struct {
  76 + PublishStatus int `json:"publishStatus"`
  77 + VisibleObjects []*VisibleObject `json:"visibleObject"`
  78 +}
  79 +
  80 +//可见对象
  81 +type VisibleObject struct {
  82 + Id string `json:"id"`
  83 + Name string `json:"name,omitempty"`
  84 + Type int `json:"type"` //1:部门 2:指定人员
  85 +}
  86 +
  87 +//评分
  88 +type Score struct {
  89 + BasicScore int `json:"basicScore"` //基础评分
  90 + ExtraScore int `json:"extraScore"` //额外分
  91 + ValueScore int `json:"valueScore"` //价值分
  92 + DiscoveryScore int `json:"-"` //发现分
  93 +}
  94 +
  95 +//审核操作权限
  96 +type ApproveAccess struct {
  97 + AllowApprove int `json:"allowApprove"`
  98 + AllowReject int `json:"allowReject"`
  99 +}
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 "github.com/astaxie/beego" 5 "github.com/astaxie/beego"
6 "github.com/astaxie/beego/httplib" 6 "github.com/astaxie/beego/httplib"
  7 + "github.com/astaxie/beego/orm"
7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" 8 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
8 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
9 "io/ioutil" 10 "io/ioutil"
@@ -57,7 +58,7 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces @@ -57,7 +58,7 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
57 approve *Approve 58 approve *Approve
58 approveType int //审批类型 59 approveType int //审批类型
59 approveWay int //审批方式 60 approveWay int //审批方式
60 - approver *models.User 61 + //approver *models.User
61 ) 62 )
62 item := process[i] 63 item := process[i]
63 if relativeId == 0 { 64 if relativeId == 0 {
@@ -81,13 +82,13 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces @@ -81,13 +82,13 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
81 } 82 }
82 mapApproves[item.Level] = approve 83 mapApproves[item.Level] = approve
83 } 84 }
84 - if approver, err = models.GetUserByUcid(item.Uid); err != nil {  
85 - log.Error(err)  
86 - return  
87 - } 85 + //if approver, err = models.GetUserByUcid(item.Uid); err != nil {
  86 + // log.Error(err)
  87 + // return
  88 + //}
88 approve.ApproveUsers = append(approve.ApproveUsers, ApproveUsers{ 89 approve.ApproveUsers = append(approve.ApproveUsers, ApproveUsers{
89 Uid: item.Uid, 90 Uid: item.Uid,
90 - Name: approver.NickName, 91 + Name: item.UserName,
91 }) 92 })
92 } 93 }
93 request.RelativeId = relativeId 94 request.RelativeId = relativeId
@@ -328,6 +329,11 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -328,6 +329,11 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
328 return 329 return
329 } 330 }
330 } 331 }
  332 + //更新同批次的为审核的状态置为无效
  333 + if err = models.UpdatetAuditFlowProcessNoApprove(chance.Id, chance.AuditLevel, protocol.ReviewStatusAuditging); err != nil {
  334 + log.Error(err)
  335 + return
  336 + }
331 } else { 337 } else {
332 //发送下一个消息给下一流程的审核人 338 //发送下一个消息给下一流程的审核人
333 for i := range approveItemResponse.MessageData.ApproveMessage { 339 for i := range approveItemResponse.MessageData.ApproveMessage {
@@ -388,3 +394,85 @@ func ConverTypeToReviewStaus(approveType int) (reviewStatus int) { @@ -388,3 +394,85 @@ func ConverTypeToReviewStaus(approveType int) (reviewStatus int) {
388 } 394 }
389 return 395 return
390 } 396 }
  397 +
  398 +// 机会审核流程信息
  399 +func ChanceApproveProcess(header *protocol.RequestHeader, chance *models.Chance) (rsp *protocol.ChanceApproveProcessResponse, err error) {
  400 + var (
  401 + processList []*models.AuditFlowProcess
  402 + )
  403 + if processList, err = models.GetAuditFlowProcessList(chance.Id); err != nil {
  404 + log.Error(fmt.Sprintf("chance_id :%v 未查询到审核流信息", chance.Id), err)
  405 + if err == orm.ErrNoRows {
  406 + err = nil
  407 + return
  408 + }
  409 + return
  410 + }
  411 + rsp = &protocol.ChanceApproveProcessResponse{}
  412 + newProcessItem := func(process *models.AuditFlowProcess) *protocol.ProcessItem {
  413 + item := &protocol.ProcessItem{
  414 + Id: process.Id,
  415 + ReviewStatus: int(process.ReviewStatus),
  416 + ApproveWay: int(process.AuditFlowType),
  417 + Uid: process.Uid,
  418 + Name: process.UserName,
  419 + }
  420 + if item.ApproveWay == protocol.AuditBySpecailUser {
  421 + item.ApproveWay = protocol.AuditByUser
  422 + }
  423 + if item.ReviewStatus != protocol.ReviewStatusAuditging {
  424 + item.ApproveTime = process.ApproveTime.Unix() * 1000
  425 + }
  426 + switch item.ApproveWay {
  427 + case protocol.AuditByDepartmentor:
  428 + break
  429 + case protocol.AuditByUser:
  430 + //item.Uid=process.Uid
  431 + //item.Name=process.UserName
  432 + break
  433 + case protocol.AuditByRole:
  434 + item.Role = process.RoleId
  435 + item.RoleName = process.RoleName
  436 + break
  437 + }
  438 + return item
  439 + }
  440 + //检查审核权限
  441 + checkApprovePermission := func(process *models.AuditFlowProcess) {
  442 + if chance.ReviewStatus == protocol.ReviewStatusPass {
  443 + return
  444 + }
  445 + if process.ReviewStatus == protocol.ReviewStatusAuditging && process.Uid == header.UserId {
  446 + rsp.ApproveAccess = &protocol.ApproveAccess{
  447 + AllowApprove: 1,
  448 + AllowReject: 1,
  449 + }
  450 + }
  451 + }
  452 + for i := range processList {
  453 + p := processList[i]
  454 + item := newProcessItem(p)
  455 + checkApprovePermission(p)
  456 + //机会已经审核通过的直接添加到审核人列表
  457 + if chance.ReviewStatus == protocol.ReviewStatusPass {
  458 + rsp.ApproveProcess = append(rsp.ApproveProcess, item)
  459 + continue
  460 + }
  461 + //当前再审核的列表
  462 + if p.Level == chance.AuditLevel && item.ReviewStatus == protocol.ReviewStatusAuditging {
  463 + item = newProcessItem(p)
  464 + for j := i; j < len(processList); j++ {
  465 + p = processList[j]
  466 + checkApprovePermission(p)
  467 + item.ApproveUsers = append(item.ApproveUsers, protocol.UserItem{
  468 + Uid: p.Uid,
  469 + Name: p.UserName,
  470 + })
  471 + }
  472 + rsp.ApproveProcess = append(rsp.ApproveProcess, item)
  473 + break
  474 + }
  475 + rsp.ApproveProcess = append(rsp.ApproveProcess, item)
  476 + }
  477 + return
  478 +}
@@ -423,6 +423,12 @@ func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, @@ -423,6 +423,12 @@ func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64,
423 EnableStatus: 1, 423 EnableStatus: 1,
424 ReviewStatus: protocol.ReviewStatusSubmit, 424 ReviewStatus: protocol.ReviewStatusSubmit,
425 } 425 }
  426 + if approver, err := models.GetUsersById(header.Uid); err != nil {
  427 + log.Error(err)
  428 + return
  429 + } else {
  430 + v.UserName = approver.NickName
  431 + }
426 return 432 return
427 } 433 }
428 434
@@ -434,6 +440,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat @@ -434,6 +440,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
434 ids []int64 440 ids []int64
435 groupId int64 441 groupId int64
436 company *models.Company 442 company *models.Company
  443 + roleName string
  444 + approver *models.User
437 ) 445 )
438 if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil { 446 if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
439 if err == orm.ErrNoRows { 447 if err == orm.ErrNoRows {
@@ -511,7 +519,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat @@ -511,7 +519,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
511 return 519 return
512 } 520 }
513 case protocol.AuditByRole: 521 case protocol.AuditByRole:
514 - 522 + //roleName="" //TODO:角色
  523 + return
515 } 524 }
516 if len(userIds) == 0 { //当前步骤没有用户 默认一个空审核人 525 if len(userIds) == 0 { //当前步骤没有用户 默认一个空审核人
517 userIds = append(userIds, 0) 526 userIds = append(userIds, 0)
@@ -525,6 +534,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat @@ -525,6 +534,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
525 log.Info(fmt.Sprintf("生成机会审批流-转给管理员:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId)) 534 log.Info(fmt.Sprintf("生成机会审批流-转给管理员:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId))
526 uid = company.AdminId 535 uid = company.AdminId
527 } 536 }
  537 + if approver, err = models.GetUserByUcid(uid); err != nil {
  538 + log.Error(err)
  539 + return
  540 + }
528 item := &models.AuditFlowProcess{ 541 item := &models.AuditFlowProcess{
529 Id: idgen.Next(), 542 Id: idgen.Next(),
530 ChanceId: chanceId, 543 ChanceId: chanceId,
@@ -535,8 +548,9 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat @@ -535,8 +548,9 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
535 AuditFlowType: config.AuditFlowType, 548 AuditFlowType: config.AuditFlowType,
536 FlowType: config.FlowType, 549 FlowType: config.FlowType,
537 ActionType: int(config.ActionType), 550 ActionType: int(config.ActionType),
538 -  
539 - ReviewStatus: protocol.ReviewStatusAuditging, 551 + RoleName: roleName,
  552 + UserName: approver.NickName,
  553 + ReviewStatus: protocol.ReviewStatusAuditging,
540 } 554 }
541 if config.Level == 1 { 555 if config.Level == 1 {
542 item.IsActive = 1 556 item.IsActive = 1
@@ -680,15 +694,11 @@ func jsonUnmarshal(jsonData string, v interface{}) { @@ -680,15 +694,11 @@ func jsonUnmarshal(jsonData string, v interface{}) {
680 //机会详情 694 //机会详情
681 func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetailRequest) (rsp *protocol.ChanceDetailResponse, err error) { 695 func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetailRequest) (rsp *protocol.ChanceDetailResponse, err error) {
682 var ( 696 var (
683 - chance *models.Chance  
684 - chanceData *models.ChanceData  
685 - provider *protocol.BaseUserInfo 697 + chance *models.Chance
  698 + chanceData *models.ChanceData
  699 + provider *protocol.BaseUserInfo
  700 + approveProcess *protocol.ChanceApproveProcessResponse
686 ) 701 )
687 - //检查是否可见  
688 - if provider, err = agg.GetUserBaseInfo(chance.UserId, header.CompanyId); err != nil {  
689 - log.Error(err)  
690 - return  
691 - }  
692 if chance, err = models.GetChanceById(request.Id); err != nil { 702 if chance, err = models.GetChanceById(request.Id); err != nil {
693 if err == orm.ErrNoRows { 703 if err == orm.ErrNoRows {
694 err = protocol.NewErrWithMessage(5101) 704 err = protocol.NewErrWithMessage(5101)
@@ -697,6 +707,13 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail @@ -697,6 +707,13 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
697 log.Error(err) 707 log.Error(err)
698 return 708 return
699 } 709 }
  710 + //用户信息
  711 + if provider, err = agg.GetUserBaseInfo(chance.UserId, header.CompanyId); err != nil {
  712 + log.Error(err)
  713 + return
  714 + }
  715 +
  716 + rsp = &protocol.ChanceDetailResponse{}
700 item := protocol.ChanceItem{ 717 item := protocol.ChanceItem{
701 Id: chance.Id, 718 Id: chance.Id,
702 Provider: provider, 719 Provider: provider,
@@ -708,7 +725,15 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail @@ -708,7 +725,15 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
708 jsonUnmarshal(chanceData.Speechs, &item.Speechs) 725 jsonUnmarshal(chanceData.Speechs, &item.Speechs)
709 jsonUnmarshal(chanceData.Videos, &item.Videos) 726 jsonUnmarshal(chanceData.Videos, &item.Videos)
710 } 727 }
711 - rsp = &protocol.ChanceDetailResponse{} 728 + jsonUnmarshal(chance.PublishData, &rsp.PublicData)
  729 + rsp.ChanceDetail = item
  730 + if approveProcess, err = ChanceApproveProcess(header, chance); err != nil {
  731 + log.Error(err)
  732 + return
  733 + } else {
  734 + rsp.ApproveProcess = approveProcess.ApproveProcess
  735 + rsp.ApproveAccess = approveProcess.ApproveAccess
  736 + }
712 return 737 return
713 } 738 }
714 739