作者 yangfu

机会自动审核

... ... @@ -40,6 +40,8 @@ const (
ReviewStatusPass = 3 //通过
ReviewStatusSubmit = 4 //提交
ReviewStatusAuditg = 5 //审批中
ReviewStatusAutoPass = 99 //自动审批通过
)
//公开状态
... ...
... ... @@ -60,7 +60,7 @@ var ApproveLog = map[int]string{
3: "退回了机会", //审批人退回机会
4: "通过了机会;基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:公司公开", //审批人通过机会(公司公开)
5: "通过了机会;基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:%v", //审批人通过机会(部门公开) 测试部、销售部
6: "系统 自动通过了机会;基础评分:0,附加评分:0,价值评分:0,公开状态:公司公开", //审批人通过了机会(系统自动通过)
6: "系统 自动通过了机会;基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:公司公开", //审批人通过了机会(系统自动通过)
7: "修改了公开状态:公司公开", //审批通过后修改公开状态(公司公开)
8: "修改了公开状态:%v", //审批通过后修改公开状态(部门公开)
9: "修改了基础评分:“修改后的基础评分%v分,修改后的附加评分%v分,修改后的价值评分%v分“", //审批通过后修改评分
... ...
... ... @@ -15,6 +15,7 @@ var (
MessageApproving = "提交了一条%v机会消息,需要您审核"
MessageApproveSuccess = "审核通过你提交的%v机会"
MessageApproveReject = "退回您了提交的%v机会"
MessageApproveAutoPass = "自动审核通过你提交的%v机会"
)
//发送审批消息
... ... @@ -34,6 +35,9 @@ func SendApproveMsg(receiverId int64, name string, companyId int64, chanceId int
case protocol.ReviewStatusPass:
format = MessageApproveSuccess
break
case protocol.ReviewStatusAutoPass:
format = MessageApproveAutoPass
break
default:
format = MessageApproving
break
... ...
... ... @@ -309,6 +309,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
return
}
{
if request.ReviewStatus == protocol.ReviewStatusPass {
//计算发现分
if result, err = ChanceCalculateScore(header, &protocol.ChanceCalculateScoreRequest{Score: request.ApproveData.Score}); err != nil {
log.Error("计算发现分错误:", err)
... ... @@ -318,6 +319,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
request.ApproveData.Score.DiscoveryScore = result.DiscoveryScore
request.ApproveData.Score.DiscoveryScorePercent = result.DiscoveryScorePercent
}
}
{
mapProcess["ReviewStatus"] = int8(request.ReviewStatus)
mapProcess["ApproveTime"] = time.Now()
... ...
... ... @@ -347,12 +347,6 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
DepartmentId: request.RelatedDepartment,
Code: fmt.Sprintf("%v%v", chanceType.Code, template.Code),
}
if _, err = orm.Insert(chance); err != nil {
log.Error(err)
orm.Rollback()
return
}
//生成提交记录
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header.UserId, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
log.Error(err)
... ... @@ -375,6 +369,12 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
return
}
}
//发送提交日志
if err = agg.SaveApproveLog(orm, 1, header.UserId, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
}
if len(auditFlows) > 0 {
//7.发送审批实例给审批服务器
if m, e := suplusApprove.NewApproveInstance(header, auditFlows); e != nil {
... ... @@ -394,8 +394,22 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
}
}
}
} else {
//更新已经审核过
if auditConfig.NoApprover == protocol.NoApproverPass {
if err = setChanceAutoPass(header, chance, orm); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
}
//插入机会
if _, err = orm.Insert(chance); err != nil {
log.Error(err)
orm.Rollback()
return
}
//6.文件
{
data := &models.ChanceData{
... ... @@ -413,15 +427,36 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
return
}
}
//发送提交日志
if err = agg.SaveApproveLog(orm, 1, header.UserId, chance.Id); err != nil {
orm.Commit()
rsp = &protocol.ChanceSubmitResponse{}
return
}
//设置机会自动通过
func setChanceAutoPass(header *protocol.RequestHeader, chance *models.Chance, orm orm.Ormer) (err error) {
var (
approveData protocol.ApproveData
)
if approveData.Score, err = ChanceCalculateDefautlScore(header); err != nil {
log.Error(err)
orm.Rollback()
return
}
orm.Commit()
approveData.PublicData = protocol.PublicData{PublishStatus: protocol.PublicToCompany}
chance.ApproveData = common.AssertJson(approveData)
chance.ApproveTime = time.Now()
if err = agg.SendApproveMsg(chance.UserId, "",
header.CompanyId, chance.Id, chance.ChanceTypeId, protocol.ReviewStatusAutoPass); err != nil {
log.Error(err)
rsp = &protocol.ChanceSubmitResponse{}
return
}
if err = agg.SaveApproveLog(orm, 6, chance.UserId, chance.Id, approveData.Score.BasicScore, approveData.Score.ExtraScore, approveData.Score.ValueScore); err != nil {
log.Error(err)
//orm.Rollback()
return
}
return
}
... ... @@ -488,21 +523,6 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
orm := orm.NewOrm()
orm.Begin()
{
if request.IsPublish {
updateMap["ReviewStatus"] = int8(protocol.ReviewStatusAuditging)
}
updateMap["AuditTemplateConfig"] = common.AssertJson(auditConfig)
updateMap["Content"] = request.Content
updateMap["SourceContent"] = common.AssertJson(request.FormList)
if err = utils.UpdateTableByMapWithOrmer(orm, &models.Chance{Id: chance.Id}, updateMap); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
//6.更新文件
{
if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil {
... ... @@ -579,13 +599,46 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
}
}
}
}
} else {
//发送提交日志
if err = agg.SaveApproveLog(orm, 1, chance.UserId, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
}
//更新已经审核过
if auditConfig.NoApprover == protocol.NoApproverPass {
if err = setChanceAutoPass(header, chance, orm); err != nil {
log.Error(err)
orm.Rollback()
return
}
updateMap["ApproveTime"] = time.Now()
updateMap["ApproveData"] = chance.ApproveData
updateMap["PublishStatus"] = chance.PublishStatus
updateMap["ReviewStatus"] = chance.ReviewStatus
updateMap["BasicScore"] = chance.BasicScore
updateMap["ExtraScore"] = chance.ExtraScore
updateMap["ValueScore"] = chance.ValueScore
updateMap["DiscoveryScore"] = chance.DiscoveryScore
updateMap["PublishStatus"] = chance.PublishStatus
}
}
}
}
{
if request.IsPublish {
updateMap["ReviewStatus"] = int8(protocol.ReviewStatusAuditging)
}
updateMap["AuditTemplateConfig"] = common.AssertJson(auditConfig)
updateMap["Content"] = request.Content
updateMap["SourceContent"] = common.AssertJson(request.FormList)
if err = utils.UpdateTableByMapWithOrmer(orm, &models.Chance{Id: chance.Id}, updateMap); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
orm.Commit()
... ... @@ -802,6 +855,36 @@ func ChanceCalculateScore(header *protocol.RequestHeader, request *protocol.Chan
return
}
//计算默认发现分
func ChanceCalculateDefautlScore(header *protocol.RequestHeader) (rsp protocol.Score, err error) {
var (
config *models.SysConfig
scoreConfig protocol.ScoreConfig
sum float64
)
rsp = protocol.Score{}
if config, err = models.GetSysConfigByCompanyId(int(header.CompanyId), models.KeyScore); err != nil {
err = protocol.NewErrWithMessage(5510)
log.Error(header.CompanyId, err)
return
}
if err = json.Unmarshal([]byte(config.Content), &scoreConfig); err != nil {
err = protocol.NewErrWithMessage(5510)
log.Error(err)
return
}
basic := scoreConfig.BasicScore.Min
sum += scoreConfig.BasicScore.Max * scoreConfig.DiscoveryScore.BasicFactor
extral := scoreConfig.BasicScore.Min
sum += scoreConfig.ExtraScore.Max * scoreConfig.DiscoveryScore.ExtraFactor
value := scoreConfig.BasicScore.Min
sum += scoreConfig.ValueScore.Max * scoreConfig.DiscoveryScore.ValueFactor
rsp.DiscoveryScore = basic*scoreConfig.DiscoveryScore.BasicFactor + extral*scoreConfig.DiscoveryScore.ExtraFactor + value*scoreConfig.DiscoveryScore.ValueFactor
rsp.DiscoveryScorePercent = int((rsp.DiscoveryScore / sum) * 100)
log.Debug(fmt.Sprintf("计算发现-> score_config:%v score:%v 总分:%v 发现分:%v 发现分百分比:%v", common.AssertJson(scoreConfig), common.AssertJson(rsp), sum, rsp.DiscoveryScore, rsp.DiscoveryScorePercent))
return
}
//机会权限
func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePermissionRequest) (rsp *protocol.ChancePermissionResponse, err error) {
var ()
... ... @@ -958,6 +1041,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
}
for j := 0; j < len(userIds); j++ {
uid := userIds[j]
if uid == 0 && auditConfig.NoApprover == protocol.NoApproverPass {
log.Info(fmt.Sprintf("配置审核人为空 自动通过审批 chance_id:%v", chanceId))
continue
}
if uid == 0 && auditConfig.NoApprover == protocol.NoApproverToAdmin { //审批人为空 转交给管理员
uid = admin.Id
}
... ...