作者 yangfu

机会详情

... ... @@ -294,6 +294,26 @@ func (this *ChanceController) ChanceDetail() {
msg = protocol.NewReturnResponse(chance.ChanceDetail(header, request))
}
//ChanceApproveProcess 机会审核流程信息
//func(this *ChanceController)ChanceApproveProcess(){
// var msg *protocol.ResponseMessage
// defer func() {
// this.Resp(msg)
// }()
// var request *protocol.ChanceApproveProcessRequest
// if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
// log.Error(err)
// msg = protocol.BadRequestParam(1)
// return
// }
// if b,m :=this.Valid(request);!b{
// msg = m
// return
// }
// header := controllers.GetRequestHeader(this.Ctx)
// msg = protocol.NewReturnResponse(chance.ChanceApproveProcess(header,request))
//}
//ChanceDelete 机会删除
//@router /chanceDelete [post]
func (this *ChanceController) ChanceDelete() {
... ...
... ... @@ -25,6 +25,9 @@ type AuditFlowProcess struct {
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 (被驳回以后,未完成的审核置为无效)"`
UserName string `orm:"column(user_name);size(50)" description:"用户名-冗余"`
RoleName string `orm:"column(role_name);size(50)" description:"角色名-冗余"`
RoleId int `orm:"column(role_id);size(50)" description:"角色id-冗余"`
}
func (t *AuditFlowProcess) TableName() string {
... ... @@ -114,3 +117,13 @@ func UpdatetAuditFlowProcessNoApprove(chanceId int64, level int, reviewStatus in
}
return
}
//获取机会审核流信息
func GetAuditFlowProcessList(chanceId int64) (v []*AuditFlowProcess, err error) {
o := orm.NewOrm()
sql := "select * from audit_flow_process where chance_id=? and enable_status=1 order by id,review_status"
if _, err = o.Raw(sql, chanceId).QueryRows(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -30,6 +30,7 @@ type Chance struct {
ValueSorce float64 `orm:"column(value_sorce);null;digits(4);decimals(1)" description:"价值评分"`
DiscoverySorce float64 `orm:"column(discovery_sorce);null;digits(4);decimals(1)" description:"发现得分(发现得分=基础评分*系数 + 附加评分*系数 + 价值评分*系数)"`
PublishStatus int `orm:"column(publish_status)" description:"公开状态 0未公开、1部门公开、2公司公开"`
PublishData string `orm:"column(publish_data)" description:"公开数据 冗余"`
AuditLevel int `orm:"column(audit_level)" description:"当前审批步骤"`
}
... ...
... ... @@ -219,8 +219,10 @@ type ChanceDetailRequest struct {
Id int64 `json:"id"` //机会编号
}
type ChanceDetailResponse struct {
ChanceDetail ChanceItem `json:"chanceDetail"`
ApproveProcess interface{} `json:"approveProcess"`
ChanceDetail ChanceItem `json:"chanceDetail"`
PublicData *PublicData `json:"publicData"`
ApproveProcess []*ProcessItem `json:"approveProcess"`
ApproveAccess *ApproveAccess `json:"approveAccess"` //
}
/*ChanceDelete 机会删除*/
... ...
... ... @@ -26,3 +26,74 @@ type ChanceApproveRequest struct {
}
type ChanceApproveResponse struct {
}
/*ChanceApproveProcess 机会审核流程信息*/
type ChanceApproveProcessRequest struct {
ChanceId int64 `json:"chanceId"`
}
type ChanceApproveProcessResponse struct {
ApproveProcess []*ProcessItem `json:"approveProcess"`
ApproveAccess *ApproveAccess `json:"approveOperate"`
}
//进程项
type ProcessItem struct {
Id int64 `json:"id"`
ReviewStatus int `json:"reviewStatus"` //当前步骤审批状态 0-待处理 1- 待审核 2- 退回 3-通过 4-提交 6-撤销
ApproveWay int `json:"approveWay"` //审批方式 1 会签 2 或签
ApproveType int `json:"approveType"` //审批类型 1 业务区域负责人 2 指定成员 3 角色
ApproveTime int64 `json:"approveTime"` //审核时间
//Role Role `json:"role"` //角色
Uid int64 `json:"uid"`
Name string `json:"name"`
RoleName string `json:"roleName"`
Role int `json:"-"`
ApproveData ApproveData `json:"ApproveData"` //审核数据
//ApproveUser UserItem `json:"approveUser"` //审核人 //状态不是审核中
ApproveUsers []UserItem `json:"approveUsers"` //审核人员 //1 会签 2 或签 //审核中 1.部门长 2.角色
}
//用户项
type UserItem struct {
Uid int64 `json:"uid"`
Name string `json:"name"`
}
//角色项
type Role struct {
Id int `json:"id"`
Name string `json:"name"`
}
//审核数据 审核通过
type ApproveData struct {
PublicData *PublicData `json:"publicData"` // 公开数据
Score *Score `json:"score"`
}
//公开数据
type PublicData struct {
PublishStatus int `json:"publishStatus"`
VisibleObjects []*VisibleObject `json:"visibleObject"`
}
//可见对象
type VisibleObject struct {
Id string `json:"id"`
Name string `json:"name,omitempty"`
Type int `json:"type"` //1:部门 2:指定人员
}
//评分
type Score struct {
BasicScore int `json:"basicScore"` //基础评分
ExtraScore int `json:"extraScore"` //额外分
ValueScore int `json:"valueScore"` //价值分
DiscoveryScore int `json:"-"` //发现分
}
//审核操作权限
type ApproveAccess struct {
AllowApprove int `json:"allowApprove"`
AllowReject int `json:"allowReject"`
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/httplib"
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"io/ioutil"
... ... @@ -57,7 +58,7 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
approve *Approve
approveType int //审批类型
approveWay int //审批方式
approver *models.User
//approver *models.User
)
item := process[i]
if relativeId == 0 {
... ... @@ -81,13 +82,13 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
}
mapApproves[item.Level] = approve
}
if approver, err = models.GetUserByUcid(item.Uid); err != nil {
log.Error(err)
return
}
//if approver, err = models.GetUserByUcid(item.Uid); err != nil {
// log.Error(err)
// return
//}
approve.ApproveUsers = append(approve.ApproveUsers, ApproveUsers{
Uid: item.Uid,
Name: approver.NickName,
Name: item.UserName,
})
}
request.RelativeId = relativeId
... ... @@ -328,6 +329,11 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
return
}
}
//更新同批次的为审核的状态置为无效
if err = models.UpdatetAuditFlowProcessNoApprove(chance.Id, chance.AuditLevel, protocol.ReviewStatusAuditging); err != nil {
log.Error(err)
return
}
} else {
//发送下一个消息给下一流程的审核人
for i := range approveItemResponse.MessageData.ApproveMessage {
... ... @@ -388,3 +394,85 @@ func ConverTypeToReviewStaus(approveType int) (reviewStatus int) {
}
return
}
// 机会审核流程信息
func ChanceApproveProcess(header *protocol.RequestHeader, chance *models.Chance) (rsp *protocol.ChanceApproveProcessResponse, err error) {
var (
processList []*models.AuditFlowProcess
)
if processList, err = models.GetAuditFlowProcessList(chance.Id); err != nil {
log.Error(fmt.Sprintf("chance_id :%v 未查询到审核流信息", chance.Id), err)
if err == orm.ErrNoRows {
err = nil
return
}
return
}
rsp = &protocol.ChanceApproveProcessResponse{}
newProcessItem := func(process *models.AuditFlowProcess) *protocol.ProcessItem {
item := &protocol.ProcessItem{
Id: process.Id,
ReviewStatus: int(process.ReviewStatus),
ApproveWay: int(process.AuditFlowType),
Uid: process.Uid,
Name: process.UserName,
}
if item.ApproveWay == protocol.AuditBySpecailUser {
item.ApproveWay = protocol.AuditByUser
}
if item.ReviewStatus != protocol.ReviewStatusAuditging {
item.ApproveTime = process.ApproveTime.Unix() * 1000
}
switch item.ApproveWay {
case protocol.AuditByDepartmentor:
break
case protocol.AuditByUser:
//item.Uid=process.Uid
//item.Name=process.UserName
break
case protocol.AuditByRole:
item.Role = process.RoleId
item.RoleName = process.RoleName
break
}
return item
}
//检查审核权限
checkApprovePermission := func(process *models.AuditFlowProcess) {
if chance.ReviewStatus == protocol.ReviewStatusPass {
return
}
if process.ReviewStatus == protocol.ReviewStatusAuditging && process.Uid == header.UserId {
rsp.ApproveAccess = &protocol.ApproveAccess{
AllowApprove: 1,
AllowReject: 1,
}
}
}
for i := range processList {
p := processList[i]
item := newProcessItem(p)
checkApprovePermission(p)
//机会已经审核通过的直接添加到审核人列表
if chance.ReviewStatus == protocol.ReviewStatusPass {
rsp.ApproveProcess = append(rsp.ApproveProcess, item)
continue
}
//当前再审核的列表
if p.Level == chance.AuditLevel && item.ReviewStatus == protocol.ReviewStatusAuditging {
item = newProcessItem(p)
for j := i; j < len(processList); j++ {
p = processList[j]
checkApprovePermission(p)
item.ApproveUsers = append(item.ApproveUsers, protocol.UserItem{
Uid: p.Uid,
Name: p.UserName,
})
}
rsp.ApproveProcess = append(rsp.ApproveProcess, item)
break
}
rsp.ApproveProcess = append(rsp.ApproveProcess, item)
}
return
}
... ...
... ... @@ -423,6 +423,12 @@ func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64,
EnableStatus: 1,
ReviewStatus: protocol.ReviewStatusSubmit,
}
if approver, err := models.GetUsersById(header.Uid); err != nil {
log.Error(err)
return
} else {
v.UserName = approver.NickName
}
return
}
... ... @@ -434,6 +440,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
ids []int64
groupId int64
company *models.Company
roleName string
approver *models.User
)
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
if err == orm.ErrNoRows {
... ... @@ -511,7 +519,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
return
}
case protocol.AuditByRole:
//roleName="" //TODO:角色
return
}
if len(userIds) == 0 { //当前步骤没有用户 默认一个空审核人
userIds = append(userIds, 0)
... ... @@ -525,6 +534,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
log.Info(fmt.Sprintf("生成机会审批流-转给管理员:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId))
uid = company.AdminId
}
if approver, err = models.GetUserByUcid(uid); err != nil {
log.Error(err)
return
}
item := &models.AuditFlowProcess{
Id: idgen.Next(),
ChanceId: chanceId,
... ... @@ -535,8 +548,9 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
AuditFlowType: config.AuditFlowType,
FlowType: config.FlowType,
ActionType: int(config.ActionType),
ReviewStatus: protocol.ReviewStatusAuditging,
RoleName: roleName,
UserName: approver.NickName,
ReviewStatus: protocol.ReviewStatusAuditging,
}
if config.Level == 1 {
item.IsActive = 1
... ... @@ -680,15 +694,11 @@ func jsonUnmarshal(jsonData string, v interface{}) {
//机会详情
func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetailRequest) (rsp *protocol.ChanceDetailResponse, err error) {
var (
chance *models.Chance
chanceData *models.ChanceData
provider *protocol.BaseUserInfo
chance *models.Chance
chanceData *models.ChanceData
provider *protocol.BaseUserInfo
approveProcess *protocol.ChanceApproveProcessResponse
)
//检查是否可见
if provider, err = agg.GetUserBaseInfo(chance.UserId, header.CompanyId); err != nil {
log.Error(err)
return
}
if chance, err = models.GetChanceById(request.Id); err != nil {
if err == orm.ErrNoRows {
err = protocol.NewErrWithMessage(5101)
... ... @@ -697,6 +707,13 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
log.Error(err)
return
}
//用户信息
if provider, err = agg.GetUserBaseInfo(chance.UserId, header.CompanyId); err != nil {
log.Error(err)
return
}
rsp = &protocol.ChanceDetailResponse{}
item := protocol.ChanceItem{
Id: chance.Id,
Provider: provider,
... ... @@ -708,7 +725,15 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
jsonUnmarshal(chanceData.Speechs, &item.Speechs)
jsonUnmarshal(chanceData.Videos, &item.Videos)
}
rsp = &protocol.ChanceDetailResponse{}
jsonUnmarshal(chance.PublishData, &rsp.PublicData)
rsp.ChanceDetail = item
if approveProcess, err = ChanceApproveProcess(header, chance); err != nil {
log.Error(err)
return
} else {
rsp.ApproveProcess = approveProcess.ApproveProcess
rsp.ApproveAccess = approveProcess.ApproveAccess
}
return
}
... ...