作者 yangfu

审批退回

... ... @@ -103,8 +103,7 @@ func GetAuditFlowProcessBy(processId, uid int64) (v *AuditFlowProcess, err error
}
//当前审批批次已经结束 唤醒下一批次审批人
func UpdatetAuditFlowProcessToNext(chanceId int64, level int, uids []int64) (err error) {
o := orm.NewOrm()
func UpdatetAuditFlowProcessToNext(o orm.Ormer, chanceId int64, level int, uids []int64) (err error) {
sql := "update audit_flow_process set enable_status =1,is_active=1,update_at=now() where chance_id=? and level=? and uid in (?)"
if err = utils.ExecuteSQLWithOrmer(o, sql, chanceId, level, utils.JoinInt64s(uids, ",")); err != nil {
return
... ... @@ -113,8 +112,7 @@ func UpdatetAuditFlowProcessToNext(chanceId int64, level int, uids []int64) (err
}
//或签 有一人已经通过 同批次在审核状态置为无效
func UpdatetAuditFlowProcessNoApprove(chanceId int64, level int, reviewStatus int) (err error) {
o := orm.NewOrm()
func UpdatetAuditFlowProcessNoApprove(o orm.Ormer, chanceId int64, level int, reviewStatus int) (err error) {
sql := "update audit_flow_process set enable_status =0,is_active=0,update_at=now() where chance_id=? and level=? and review_status=?"
if err = utils.ExecuteSQLWithOrmer(o, sql, chanceId, level, reviewStatus); err != nil {
return
... ...
... ... @@ -52,7 +52,7 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
Approver: userCompany.NickName,
Uid: userCompany.Id,
Sign: ApproveSign,
Type: 1,
Type: 2,
}
for i := range process {
var (
... ... @@ -343,29 +343,42 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
return
}
log.Info(fmt.Sprintf("用户%v 更新机会审核状态 process_id:%v 状态:%v", header.UserId, process.Id, request.ReviewStatus))
orm := orm.NewOrm()
orm.Begin()
if request.ReviewStatus == protocol.ReviewStatusReturn {
mapChance["ReviewStatus"] = int8(request.ReviewStatus) //退回也要更新审核状态
//增加一条待处理记录到审核列表
//生成提交记录
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, chance.AuditTemplateId, protocol.ReviewStatusWait)); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
{
//更新下一批次的审核人
var nextApprovers []int64
if err = agg.SendApprovedMsg(chance.UserId, "",
header.CompanyId, chance.Id, chance.ChanceTypeId, request.ReviewStatus, protocol.MsgTypeAuditBy); err != nil {
log.Error(err)
orm.Rollback()
return
}
if approveItemResponse.IsOver == 1 {
//结束审批
{
mapChance["ReviewStatus"] = int8(request.ReviewStatus)
}
//发送审核结果消息给提交人
for i := range approveItemResponse.MessageData.ApplyUserMessage {
message := approveItemResponse.MessageData.ApplyUserMessage[i]
nextApprovers = append(nextApprovers, message.ReceiverInfo.ReceiverUid)
if err = agg.SendApprovedMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,
header.CompanyId, chance.Id, chance.ChanceTypeId, request.ReviewStatus, protocol.MsgTypeAuditBy); err != nil {
log.Error(err)
return
}
}
//更新同批次的为审核的状态置为无效
if err = models.UpdatetAuditFlowProcessNoApprove(chance.Id, chance.AuditLevel, protocol.ReviewStatusAuditging); err != nil {
log.Error(err)
return
}
//for i := range approveItemResponse.MessageData.ApplyUserMessage {
// message := approveItemResponse.MessageData.ApplyUserMessage[i]
// nextApprovers = append(nextApprovers, message.ReceiverInfo.ReceiverUid)
// if err = agg.SendApprovedMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,
// header.CompanyId, chance.Id, chance.ChanceTypeId, request.ReviewStatus, protocol.MsgTypeAuditBy); err != nil {
// log.Error(err)
// return
// }
//}
} else {
//发送下一个消息给下一流程的审核人
for i := range approveItemResponse.MessageData.ApproveMessage {
... ... @@ -374,26 +387,27 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
if err = agg.SendApproveMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,
header.CompanyId, chance.Id, chance.ChanceTypeId, protocol.ReviewStatusAuditging); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
//更新下一批次的审核人 同批次的为审核的状态置为无效
if len(nextApprovers) != 0 {
if err = models.UpdatetAuditFlowProcessToNext(chance.Id, chance.AuditLevel+1, nextApprovers); err != nil {
if err = models.UpdatetAuditFlowProcessToNext(orm, chance.Id, chance.AuditLevel+1, nextApprovers); err != nil {
log.Error(err)
orm.Rollback()
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 {
if err = models.UpdatetAuditFlowProcessNoApprove(orm, chance.Id, chance.AuditLevel, protocol.ReviewStatusAuditging); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
}
}
orm := orm.NewOrm()
orm.Begin()
if err = utils.UpdateTableByMapWithOrmer(orm, process, mapProcess); err != nil {
log.Error("更新机会审核流程 状态失败 process_id:", process.Id, err)
orm.Rollback()
... ... @@ -404,6 +418,14 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
log.Error("更新机会审核状态失败 chance_id:", chance.Id, err)
return
}
if request.ReviewStatus == protocol.ReviewStatusReturn || approveItemResponse.IsOver == 1 {
//更新同批次的为审核的状态置为无效
if err = models.UpdatetAuditFlowProcessNoApprove(orm, chance.Id, chance.AuditLevel, protocol.ReviewStatusAuditging); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
if request.ApproveData.PublicData.PublishStatus == protocol.PublicToDepartment {
if err = utils.ExecuteSQLWithOrmer(orm, models.SqlDeleteChanceDepartment, chance.Id); err != nil {
log.Error(err)
... ...
... ... @@ -283,7 +283,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
}
//生成提交记录
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id)); err != nil {
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
log.Error(err)
orm.Rollback()
return
... ... @@ -607,7 +607,7 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe
}
//生成审批流-提交记录
func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64) (v *models.AuditFlowProcess) {
func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) {
v = &models.AuditFlowProcess{
Id: idgen.Next(),
ChanceId: chanceId,
... ... @@ -616,7 +616,7 @@ func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64,
UpdateAt: time.Now(),
ApproveTime: time.Now(),
EnableStatus: 1,
ReviewStatus: protocol.ReviewStatusSubmit,
ReviewStatus: int8(reviewStatus),
}
if approver, err := models.GetUsersById(header.Uid); err != nil {
log.Error(err)
... ...