...
|
...
|
@@ -4,12 +4,16 @@ 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"
|
|
|
"net/http"
|
|
|
"opp/internal/utils"
|
|
|
"opp/models"
|
|
|
"opp/protocol"
|
|
|
"opp/services/agg"
|
|
|
"time"
|
|
|
|
|
|
"encoding/json"
|
|
|
)
|
...
|
...
|
@@ -26,14 +30,15 @@ const ( |
|
|
ApproveIntegrate = "/approve-processes/integrate"
|
|
|
)
|
|
|
|
|
|
//素加审批系统
|
|
|
type SuplusApprove struct {
|
|
|
}
|
|
|
|
|
|
//新增审批实例
|
|
|
func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, process []*models.AuditFlowProcess) (err error) {
|
|
|
func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, process []*models.AuditFlowProcess) (response NewApproveInstanceResponse, err error) {
|
|
|
var (
|
|
|
request NewApproveInstanceRequest
|
|
|
response NewApproveInstanceResponse
|
|
|
request NewApproveInstanceRequest
|
|
|
//response NewApproveInstanceResponse
|
|
|
mapApproves map[int]*Approve = make(map[int]*Approve)
|
|
|
relativeId int64
|
|
|
userCompany *models.UserCompany
|
...
|
...
|
@@ -54,14 +59,14 @@ 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 {
|
|
|
relativeId = item.ChanceId
|
|
|
}
|
|
|
if _, ok := mapApproves[i]; ok {
|
|
|
approve = mapApproves[i]
|
|
|
if _, ok := mapApproves[item.Level]; ok {
|
|
|
approve = mapApproves[item.Level]
|
|
|
} else {
|
|
|
approveType = item.AuditFlowType
|
|
|
if approveType == protocol.AuditBySpecailUser {
|
...
|
...
|
@@ -76,21 +81,19 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces |
|
|
ApproveType: item.AuditFlowType,
|
|
|
ApproveWay: approveWay,
|
|
|
}
|
|
|
mapApproves[i] = approve
|
|
|
}
|
|
|
if approver, err = models.GetUserByUcid(item.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
mapApproves[item.Level] = approve
|
|
|
}
|
|
|
//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,
|
|
|
//RoleId:5,
|
|
|
RoleId: 0,
|
|
|
Name: item.UserName,
|
|
|
})
|
|
|
}
|
|
|
request.RelativeId = relativeId
|
|
|
for i := 0; i < len(mapApproves); i++ {
|
|
|
for i := 1; i <= len(mapApproves); i++ {
|
|
|
if v, ok := mapApproves[i]; ok {
|
|
|
request.Approves = append(request.Approves, v)
|
|
|
}
|
...
|
...
|
@@ -102,19 +105,20 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces |
|
|
}
|
|
|
|
|
|
//审批操作
|
|
|
func (s SuplusApprove) ApproveItem(header *protocol.RequestHeader, approveType int, chanceId int64) (response ApproveItemResponse, err error) {
|
|
|
func (s SuplusApprove) ApproveItem(header *protocol.RequestHeader, approveType int, chanceId int64, processId int64) (response ApproveItemResponse, err error) {
|
|
|
var (
|
|
|
request ApproveItemRequest = ApproveItemRequest{
|
|
|
RelativeId: chanceId,
|
|
|
Type: approveType,
|
|
|
Suggestion: "",
|
|
|
Sign: ApproveSign,
|
|
|
ApproveType: 2,
|
|
|
Uid: header.UserId,
|
|
|
RelativeId: chanceId,
|
|
|
Type: approveType,
|
|
|
Suggestion: "",
|
|
|
Sign: ApproveSign,
|
|
|
ApproveType: 2, //编辑
|
|
|
Uid: header.UserId,
|
|
|
ExtendRelativeId: processId,
|
|
|
}
|
|
|
)
|
|
|
if s.DoRequest(ApproveItem, http.MethodPost, request, &response); err != nil {
|
|
|
log.Error(err)
|
|
|
if err = s.DoRequest(ApproveItem, http.MethodPost, request, &response); err != nil {
|
|
|
return
|
|
|
}
|
|
|
log.Info(fmt.Sprintf("success request suplus-approve:%v request:%v response:%v", ApproveItem, common.AssertJson(request), common.AssertJson(response)))
|
|
|
return
|
...
|
...
|
@@ -178,7 +182,7 @@ func (s SuplusApprove) DoRequest(method string, methodType string, request inter |
|
|
log.Error(e)
|
|
|
return
|
|
|
}
|
|
|
log.Debug(fmt.Sprintf("request-%v request:%v rsp:%v", url, common.AssertJson(request), common.AssertJson(response)))
|
|
|
log.Debug(fmt.Sprintf("request-%v request:%v rsp:%v", url, common.AssertJson(request), string(responseData)))
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -193,38 +197,60 @@ type NewApproveInstanceRequest struct { |
|
|
RelativeId int64 `json:"relativeId"` //关联id
|
|
|
|
|
|
}
|
|
|
type NewApproveInstanceResponse interface{}
|
|
|
type NewApproveInstanceResponse struct {
|
|
|
MessageData []MessageDataItem `json:"messageData"`
|
|
|
}
|
|
|
|
|
|
//审批节点
|
|
|
type Approve struct {
|
|
|
ApproveWay int `json:"approveWay"` //审批方式 1 会签 2 或签 3 发起人从角色成员中自选
|
|
|
ApproveType int `json:"approveType"` //审批类型 1 业务区域负责人 2 指定成员 3 角色
|
|
|
IsDefault int `json:"isDefault"` //1 是默认 0 不是
|
|
|
RoleName string `json:"roleName"` //角色名/负责人
|
|
|
RoleId int `json:"roleId"` //角色id
|
|
|
ApproveUsers []ApproveUsers `json:"approveUsers"` //审批人
|
|
|
}
|
|
|
|
|
|
//审批人
|
|
|
type ApproveUsers struct {
|
|
|
Uid int64 `json:"uid"` //用户id
|
|
|
Name string `json:"name"` //用户名
|
|
|
IsDefault int `json:"isDefault"` //1 是默认 0 不是
|
|
|
RoleName string `json:"roleName"` //角色名/负责人
|
|
|
RoleId int `json:"roleId"` //角色id
|
|
|
Uid int64 `json:"uid"` //用户id
|
|
|
Name string `json:"name"` //用户名
|
|
|
ParentIds []int `json:"parentIds"`
|
|
|
}
|
|
|
|
|
|
//审批 消息列表
|
|
|
type MessageDataItem struct {
|
|
|
MessageContent contentItem `json:"messageContent"`
|
|
|
ReceiverInfo receiverInfo `json:"receiverInfo"`
|
|
|
}
|
|
|
type contentItem struct {
|
|
|
ApproveInstanceId int `json:"approveInstanceId"` //审批实例-id
|
|
|
ApproveProcessId int `json:"approveProcessId"` //审批进程节点-id
|
|
|
RelativeId int `json:"relativeId"` //机会编号
|
|
|
MsgApproveStatus int `json:"msgApproveStatus"` //审核状态
|
|
|
}
|
|
|
type receiverInfo struct {
|
|
|
ReceiverUid int64 `json:"receiverUid"` //用户id
|
|
|
ReceiverName string `json:"receiverName"` //接收人
|
|
|
}
|
|
|
|
|
|
/*ApproveItem 审批操作*/
|
|
|
type ApproveItemRequest struct {
|
|
|
RelativeId int64 `json:"relativeId"` //关联id
|
|
|
Type int `json:"type"` //审批类型 2 同意 3 驳回 4 撤回 5 直接提交
|
|
|
Suggestion string `json:"suggestion"` //原因/建议
|
|
|
Sign string `json:"sign"` //CHANCE
|
|
|
ApproveType int `json:"approveType"` //1-新增(订单用新增) 2-编辑
|
|
|
Uid int64 `json:"uid"` //用户id
|
|
|
RelativeId int64 `json:"relativeId"` //关联id
|
|
|
Type int `json:"type"` //审批类型 2 同意 3 驳回 4 撤回 5 直接提交
|
|
|
Suggestion string `json:"suggestion"` //原因/建议
|
|
|
Sign string `json:"sign"` //CHANCE
|
|
|
ApproveType int `json:"approveType"` //1-新增(订单用新增) 2-编辑
|
|
|
Uid int64 `json:"uid"` //用户id
|
|
|
ExtendRelativeId int64 `json:"extendRelativeId"` //业务管理id
|
|
|
}
|
|
|
type ApproveItemResponse struct {
|
|
|
Status int `json:"status"` //状态1-待确认2-已确认3-已驳回4-已撤回
|
|
|
ApproveStatus int `json:"approveStatus"` //审批状态0 待审批 1 审批中 2 同意 3 驳回 4 提交订单 5 已被其他人处理 (0这个状态不存在审批后)
|
|
|
IsApprove int `json:"isApprove"` //是否需要审批 1是 0 否
|
|
|
MessageData ApproveMessageItem `json:"messageData"`
|
|
|
IsOver int `json:"isOver"` //是否结束1
|
|
|
}
|
|
|
type ApproveMessageItem struct {
|
|
|
ApproveMessage []MessageDataItem `json:"approveMessage"`
|
|
|
ApplyUserMessage []MessageDataItem `json:"applyUserMessage"`
|
|
|
}
|
|
|
|
|
|
/*ApproveIntegrate 审核列表*/
|
...
|
...
|
@@ -237,3 +263,218 @@ type AppproveProcess struct { |
|
|
ExtendRelativeId int64 `json:"extendRelativeId"`
|
|
|
Status int `json:"status"`
|
|
|
}
|
|
|
|
|
|
//机会审核
|
|
|
func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceApproveRequest) (rsp *protocol.ChanceApproveResponse, err error) {
|
|
|
var (
|
|
|
process *models.AuditFlowProcess
|
|
|
chance *models.Chance
|
|
|
suplusApprove SuplusApprove
|
|
|
approveType int
|
|
|
approveItemResponse ApproveItemResponse
|
|
|
)
|
|
|
//TODO:测试注入
|
|
|
if request.Uid != 0 {
|
|
|
header.UserId = request.Uid
|
|
|
}
|
|
|
approveType = ConverReviewStatus(request.ReviewStatus)
|
|
|
if approveType == 0 {
|
|
|
log.Error("request.reviewStatus error :", request.ReviewStatus)
|
|
|
err = protocol.NewErrWithMessage(2)
|
|
|
return
|
|
|
}
|
|
|
if chance, err = models.GetChanceById(request.ChanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
err = protocol.NewErrWithMessage(5101)
|
|
|
return
|
|
|
}
|
|
|
if process, err = models.GetAuditFlowProcessBy(request.ProcessId, header.UserId); err != nil {
|
|
|
log.Error(request.ProcessId, header.UserId, err)
|
|
|
err = protocol.NewErrWithMessage(5202)
|
|
|
return
|
|
|
}
|
|
|
if chance.ReviewStatus != protocol.ReviewStatusAuditging {
|
|
|
log.Error(fmt.Sprintf("机会已经被审核 chance_id:%v review_status:%v", chance.Id, chance.ReviewStatus))
|
|
|
err = protocol.NewErrWithMessage(5202)
|
|
|
return
|
|
|
}
|
|
|
log.Info(fmt.Sprintf("用户:%v 提交审核 机会编号:%v 审批流编号:%v 审批状态:%v", header.UserId, chance.Id, process.Id, request.ReviewStatus))
|
|
|
if approveItemResponse, err = suplusApprove.ApproveItem(header, approveType, chance.Id, process.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
err = protocol.NewErrWithMessage(5203)
|
|
|
return
|
|
|
}
|
|
|
if err = utils.UpdateTableByMap(process, map[string]interface{}{
|
|
|
"ReviewStatus": int8(request.ReviewStatus), "ApproveTime": time.Now()}); err != nil {
|
|
|
log.Error("更新机会审核状态失败 process_id:", process.Id, err)
|
|
|
return
|
|
|
}
|
|
|
log.Info(fmt.Sprintf("用户%v 更新机会审核状态 process_id:%v 状态:%v", header.UserId, process.Id, request.ReviewStatus))
|
|
|
{
|
|
|
//更新下一批次的审核人
|
|
|
var nextApprovers []int64
|
|
|
if approveItemResponse.IsOver == 1 {
|
|
|
//结束审批
|
|
|
if err = utils.UpdateTableByMap(chance, map[string]interface{}{
|
|
|
"ReviewStatus": int8(request.ReviewStatus), "AuditLevel": chance.AuditLevel}); err != nil {
|
|
|
log.Error("更新机会审核状态失败 chance_id:", chance.Id, err)
|
|
|
return
|
|
|
}
|
|
|
//发送审核结果消息给提交人
|
|
|
for i := range approveItemResponse.MessageData.ApplyUserMessage {
|
|
|
message := approveItemResponse.MessageData.ApplyUserMessage[i]
|
|
|
nextApprovers = append(nextApprovers, message.ReceiverInfo.ReceiverUid)
|
|
|
if err = agg.SendApproveMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,
|
|
|
header.CompanyId, chance.Id, chance.ChanceTypeId, request.ReviewStatus); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
//更新同批次的为审核的状态置为无效
|
|
|
if err = models.UpdatetAuditFlowProcessNoApprove(chance.Id, chance.AuditLevel, protocol.ReviewStatusAuditging); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
|
//发送下一个消息给下一流程的审核人
|
|
|
for i := range approveItemResponse.MessageData.ApproveMessage {
|
|
|
message := approveItemResponse.MessageData.ApproveMessage[i]
|
|
|
nextApprovers = append(nextApprovers, message.ReceiverInfo.ReceiverUid)
|
|
|
if err = agg.SendApproveMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,
|
|
|
header.CompanyId, chance.Id, chance.ChanceTypeId, protocol.ReviewStatusAuditging); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
//更新下一批次的审核人 同批次的为审核的状态置为无效
|
|
|
if len(nextApprovers) != 0 {
|
|
|
if err = models.UpdatetAuditFlowProcessToNext(chance.Id, chance.AuditLevel+1, nextApprovers); err != nil {
|
|
|
log.Error(err)
|
|
|
log.Info(fmt.Sprintf("更新机会失败 chance_id:%v 下一批次审批人员:%v", chance.Id, nextApprovers))
|
|
|
return
|
|
|
}
|
|
|
log.Info(fmt.Sprintf("更新机会 chance_id:%v 下一批次审批人员:%v", chance.Id, nextApprovers))
|
|
|
if err = models.UpdatetAuditFlowProcessNoApprove(chance.Id, chance.AuditLevel, protocol.ReviewStatusAuditging); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
rsp = &protocol.ChanceApproveResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
/*ProcessIntegrate */
|
|
|
type ProcessIntegrateRequest struct {
|
|
|
}
|
|
|
type ProcessIntegrateResponse struct {
|
|
|
}
|
|
|
|
|
|
func ProcessIntegrate(header *protocol.RequestHeader, request *ProcessIntegrateRequest) (rsp *ProcessIntegrateResponse, err error) {
|
|
|
var ()
|
|
|
rsp = &ProcessIntegrateResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//系统审核状态转为审核类型 reviewStatus - > approveType
|
|
|
func ConverReviewStatus(reviewStatus int) (approveType int) {
|
|
|
if reviewStatus == protocol.ReviewStatusPass {
|
|
|
approveType = protocol.ApproveTypePass
|
|
|
} else if reviewStatus == protocol.ReviewStatusReturn {
|
|
|
approveType = protocol.ApproveTypeReject
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func ConverTypeToReviewStaus(approveType int) (reviewStatus int) {
|
|
|
if approveType == protocol.ApproveTypePass {
|
|
|
reviewStatus = protocol.ReviewStatusPass
|
|
|
} else if approveType == protocol.ApproveTypeReject {
|
|
|
reviewStatus = protocol.ReviewStatusReturn
|
|
|
}
|
|
|
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,
|
|
|
ProcessId: process.Id,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
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
|
|
|
} |
...
|
...
|
|