...
|
...
|
@@ -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
|
|
|
}
|
...
|
...
|
|