作者 yangfu

模板详情

... ... @@ -248,6 +248,27 @@ func (this *ChanceController) Templates() {
msg = protocol.NewReturnResponse(chance.Templates(header, request))
}
//Template 模板详情
//@router /template [post]
func (this *ChanceController) Template() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.TemplateRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.Template(header, request))
}
//ChanceSubmit 提交机会
//@router /submit [post]
func (this *ChanceController) ChanceSubmit() {
... ... @@ -266,11 +287,32 @@ func (this *ChanceController) ChanceSubmit() {
return
}
header := controllers.GetRequestHeader(this.Ctx)
if request.Id > 0 {
msg = protocol.NewReturnResponse(chance.ChanceUpdate(header, request))
//if request.Id > 0 {
// msg = protocol.NewReturnResponse(chance.ChanceUpdate(header, request))
// return
//}
msg = protocol.NewReturnResponse(chance.ChanceSubmit(header, request))
}
//ChanceUpdate 机会更新
//@router /update [post]
func (this *ChanceController) ChanceUpdate() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChanceUpdateRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
msg = protocol.NewReturnResponse(chance.ChanceSubmit(header, request))
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceUpdate(header, request))
}
//ChanceStatistics 机会统计
... ...
... ... @@ -139,3 +139,32 @@ func CloseAuditFlowProcess(chanceId int64) (err error) {
}
return
}
//获取当前审批节点 是否已经有人审核通过的
func GetAuditFlowProcessApproved(chanceId int64, level int) (v *AuditFlowProcess, err error) {
o := orm.NewOrm()
sql := "select id from audit_flow_process where chance_id=? and level=? and is_active=1 and review_status<>1 and enable_status=1"
if err = o.Raw(sql, chanceId, level).QueryRow(&v); err != nil {
return
}
return
}
//按审核状态获取审核流程
func GetAuditFlowProcessByReview(chanceId int64, level int, reviewStatus int) (v *AuditFlowProcess, err error) {
o := orm.NewOrm()
sql := "select * from audit_flow_process where chance_id=? and level=? and is_active=1 and review_status=? and enable_status=1"
if err = o.Raw(sql, chanceId, level, reviewStatus).QueryRow(&v); err != nil {
return
}
return
}
//更新提交
func UpdatetAuditFlowProcessToSubmit(o orm.Ormer, chanceId int64, level int, reviewStatus int, userId int64) (err error) {
sql := "update audit_flow_process set enable_status =1,is_active=1,update_at=now(),review_status=? where chance_id=? and uid=? and level=? and and review_status=0 and enable_status=1"
if err = utils.ExecuteSQLWithOrmer(o, sql, reviewStatus, chanceId, userId, level); err != nil {
return
}
return
}
... ...
... ... @@ -100,3 +100,14 @@ func GetAuditTemplateExample(id int64) (v string, err error) {
}
return
}
//按 1.公司编号 2.机会类型编号 3.模板编号
//获取审核模板列表
func GetAuditTemplate(companyId int64, chanceTypeId, templateId int) (v *AuditTemplate, err error) {
o := orm.NewOrm()
sql := "select * from audit_template where id=? and company_id=? and chance_type_id=? and enable_status=1"
if err = o.Raw(sql, templateId, companyId, chanceTypeId).QueryRow(&v); err == nil {
return
}
return
}
... ...
... ... @@ -92,6 +92,15 @@ type TemplatesResponse struct {
Templates []*Template `json:"list"`
}
/*Template 模板详情*/
type TemplateRequest struct {
ChanceTypeId int `json:"chanceTypeId" valid:"Required"`
TemplateId int `json:"templateId" valid:"Required"`
}
type TemplateResponse struct {
Template *Template `json:"template"`
}
/*ChanceExample 机会示例*/
type ChanceExampleRequest struct {
TemplateId int `json:"templateId" valid:"Required"`
... ... @@ -114,6 +123,22 @@ type ChanceSubmitRequest struct {
type ChanceSubmitResponse struct {
}
/*ChanceUpdate 机会更新*/
type ChanceUpdateRequest struct {
Id int64 `json:"id"` // = 0添加 >0 编辑
//AuditTemplateId int64 `json:"auditTemplateId" valid:"Required"`
Content string `json:"content"`
FormList []*Form `json:"formList" valid:"Required"`
Speechs []Speech `json:"speechs"`
Pictures []Picture `json:"pictures"`
Videos []Video `json:"videos"`
RelatedDepartment int64 `json:"relatedDepartments" valid:"Required"`
IsPublish bool `json:"isPublish"` //是否重新发布
}
type ChanceUpdateResponse struct {
}
/*ChanceStatistics 首页-机会池统计*/
type ChanceStatisticsRequest struct {
}
... ... @@ -361,6 +386,8 @@ type ChanceChangeScoreRequest struct {
Score Score `json:"score"`
}
type ChanceChangeScoreResponse struct {
DiscoveryScore float64 `json:"discoveryScore"` //发现分
DiscoveryScorePercent int `json:"discoveryScorePercent"` //发现分-百分比
}
/*ChanceCalculateScore 计算发现分*/
... ...
... ... @@ -54,6 +54,18 @@ func init() {
MapStaticName[MyAuditChanceReturn] = "我审核的机会-已退回"
}
var ApproveLog = map[int]string{
1: "提交了机会", //提交人提交机会
2: "删除了机会", //提交人删除机会
3: "退回了机会", //审批人退回机会
4: "通过了机会;基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:公司公开", //审批人通过机会(公司公开)
5: "通过了机会;基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:%v", //审批人通过机会(部门公开) 测试部、销售部
6: "系统 自动通过了机会;基础评分:0,附加评分:0,价值评分:0,公开状态:公司公开", //审批人通过了机会(系统自动通过)
7: "修改了公开状态:公司公开", //审批通过后修改公开状态(公司公开)
8: "修改了公开状态:%v", //审批通过后修改公开状态(部门公开)
9: "修改了基础评分:“修改后的基础评分%v分,修改后的附加评分%v分,修改后的价值评分%v分“", //审批通过后修改评分
}
//用户项
type UserItem struct {
Uid int64 `json:"uid"`
... ...
... ... @@ -241,6 +241,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Template",
Router: `/template`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Templates",
Router: `/templates`,
AllowHTTPMethods: []string{"post"},
... ... @@ -255,6 +263,14 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceUpdate",
Router: `/update`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"],
beego.ControllerComments{
Method: "Company",
... ...
... ... @@ -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
}
... ...