...
|
...
|
@@ -235,6 +235,48 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques |
|
|
return
|
|
|
}
|
|
|
|
|
|
//模板详情
|
|
|
func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) (rsp *protocol.TemplateResponse, err error) {
|
|
|
var (
|
|
|
templates *models.AuditTemplate
|
|
|
forms []*models.AuditForm
|
|
|
)
|
|
|
rsp = &protocol.TemplateResponse{}
|
|
|
if templates, err = models.GetAuditTemplate(header.CompanyId, request.ChanceTypeId, request.TemplateId); err != nil {
|
|
|
log.Error(fmt.Sprintf("公司:%v chance_type_id:%v id:%v无模板 ", header.CompanyId, request.ChanceTypeId, request.TemplateId), err)
|
|
|
return
|
|
|
}
|
|
|
item := templates
|
|
|
//TODO:检查模板可见
|
|
|
//
|
|
|
//查询表单
|
|
|
if forms, err = models.GetAuditForms(header.CompanyId, item.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
template := &protocol.Template{
|
|
|
Id: item.Id,
|
|
|
Name: item.Name,
|
|
|
Icon: item.Icon,
|
|
|
Doc: item.Doc,
|
|
|
FormList: make([]*protocol.Form, len(forms)),
|
|
|
Link: fmt.Sprintf("%v/#/ability/opportunity?id=%v", beego.AppConfig.String("h5_host"), item.Id),
|
|
|
}
|
|
|
for j := range forms {
|
|
|
form := forms[j]
|
|
|
template.FormList[j] = &protocol.Form{
|
|
|
Id: form.Id,
|
|
|
Label: form.Label,
|
|
|
Value: "",
|
|
|
InputType: form.InputType,
|
|
|
SectionType: form.Section,
|
|
|
Required: form.Required,
|
|
|
}
|
|
|
}
|
|
|
rsp.Template = template
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) {
|
|
|
//if template.VisibleType ==
|
|
|
return
|
...
|
...
|
@@ -368,35 +410,57 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
}
|
|
|
|
|
|
//机会编辑
|
|
|
func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmitRequest) (rsp *protocol.ChanceSubmitResponse, err error) {
|
|
|
func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdateRequest) (rsp *protocol.ChanceUpdateResponse, err error) {
|
|
|
var (
|
|
|
template *models.AuditTemplate
|
|
|
chance *models.Chance
|
|
|
auditConfig *protocol.AuditConfig
|
|
|
chanceData *models.ChanceData
|
|
|
//auditFlows []*models.AuditFlowProcess
|
|
|
//auditFlows *models.AuditFlowProcess
|
|
|
updateMap = make(map[string]interface{})
|
|
|
|
|
|
auditFlows []*models.AuditFlowProcess
|
|
|
suplusApprove SuplusApprove
|
|
|
chanceType *models.ChanceType
|
|
|
)
|
|
|
//验证机会是否存在
|
|
|
if chance, err = models.GetChanceById(request.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
log.Error(request.Id, err)
|
|
|
err = protocol.NewErrWithMessage(5101)
|
|
|
return
|
|
|
}
|
|
|
//TODO:非本人 1.需要验证角色权限,是否是审核人
|
|
|
//编辑重新发布 是否可以重新发布
|
|
|
if request.IsPublish && chance.ReviewStatus == protocol.ReviewStatusReturn && chance.UserId == header.UserId {
|
|
|
request.IsPublish = false
|
|
|
//当前没有被人审核过
|
|
|
if _, e := models.GetAuditFlowProcessApproved(request.Id, 1); e == orm.ErrNoRows && chance.AuditLevel == 1 {
|
|
|
//当前状态是退回-待处理
|
|
|
if _, e := models.GetAuditFlowProcessByReview(request.Id, 0, protocol.ReviewStatusWait); e == nil {
|
|
|
request.IsPublish = true
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
request.IsPublish = false
|
|
|
}
|
|
|
//TODO:非本人 1.需要验证角色权限 2是否是审核人 3.是否是本人 (目前本人才可以审核)
|
|
|
if chance.UserId != header.Uid {
|
|
|
err = protocol.NewErrWithMessage(1)
|
|
|
err = protocol.NewErrWithMessage(5206)
|
|
|
log.Error(fmt.Sprintf("user:%v 无权限操作机会 chance:%v", header.Uid, chance.Id))
|
|
|
return
|
|
|
}
|
|
|
//TODO:验证机会当前是否在审核中
|
|
|
//1.模板是否存在
|
|
|
if template, err = models.GetAuditTemplateById(request.AuditTemplateId); err != nil {
|
|
|
log.Error("模板不存在:", request.AuditTemplateId, err)
|
|
|
if template, err = models.GetAuditTemplateById(chance.AuditTemplateId); err != nil {
|
|
|
log.Error("模板不存在:", chance.AuditTemplateId, err)
|
|
|
err = protocol.NewErrWithMessage(5301)
|
|
|
return
|
|
|
}
|
|
|
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)
|
...
|
...
|
@@ -440,11 +504,55 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
orm.Commit()
|
|
|
|
|
|
//6.激活审核流
|
|
|
//TODO:7.发送消息通知给审核人(审核消息)
|
|
|
rsp = &protocol.ChanceSubmitResponse{}
|
|
|
{
|
|
|
if request.IsPublish {
|
|
|
//更新待处理->提交
|
|
|
if err = models.UpdatetAuditFlowProcessToSubmit(orm, request.Id, 0, protocol.ReviewStatusSubmit, header.UserId); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
//4.查询审核配置
|
|
|
//5.生成审核流
|
|
|
if auditFlows, err = GenAuditFlowProcess(header, chance.Id, chance.DepartmentId, template.Id, auditConfig); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
for i := 0; i < len(auditFlows); i++ {
|
|
|
auditFlows[i].ApproveMessage = fmt.Sprintf(protocol.MessageApproving, chanceType.Name)
|
|
|
//auditFlows[i].TemplateId = int(template.Id)
|
|
|
if _, err = orm.Insert(auditFlows[i]); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
if len(auditFlows) > 0 {
|
|
|
//7.发送审批实例给审批服务器
|
|
|
if m, e := suplusApprove.NewApproveInstance(header, auditFlows); e != nil {
|
|
|
log.Error(fmt.Sprintf("uid:%v", header.UserId), "request suplus-approve.NewApproveInstance err", e)
|
|
|
orm.Rollback()
|
|
|
err = e
|
|
|
return
|
|
|
} else {
|
|
|
//7.发送消息通知给审核人(审核消息)
|
|
|
for i := range m.MessageData {
|
|
|
message := m.MessageData[i]
|
|
|
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
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.ChanceUpdateResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -549,7 +657,10 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
|
return
|
|
|
}
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.ChanceChangeScoreResponse{}
|
|
|
rsp = &protocol.ChanceChangeScoreResponse{
|
|
|
DiscoveryScore: result.DiscoveryScore,
|
|
|
DiscoveryScorePercent: result.DiscoveryScorePercent,
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
|