作者 yangfu

模板可见修改 发现分精度问题

package utils
import (
"fmt"
"math"
"strconv"
)
func decimal(value float64) float64 {
return math.Trunc(value*1e1+0.5) * 1e-1
}
func Decimal(value float64) float64 {
value = decimal(value)
value, _ = strconv.ParseFloat(fmt.Sprintf("%.1f", value), 64)
return value
}
... ...
package utils
import "testing"
func TestDecimal(t *testing.T) {
t.Log(Decimal(1.7999999))
t.Log(Decimal(1.7444444))
t.Log(Decimal(1.7555555))
t.Log(Decimal(1.3555555))
t.Log(Decimal(1.3000001))
}
... ...
... ... @@ -8,20 +8,22 @@ import (
)
type AuditTemplate struct {
Id int64 `orm:"column(id);pk" description:"唯一编号"`
CompanyId int `orm:"column(company_id)" description:"公司id"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型编号"`
Name string `orm:"column(name);size(20)" description:"子分类名称"`
Code string `orm:"column(code);size(50);null" description:"编码"`
Doc string `orm:"column(doc);size(255)" description:"说明"`
Icon string `orm:"column(icon);size(255)" description:"图标"`
NoticeType int8 `orm:"column(notice_type)" description:"通知方式"`
NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"`
SortNum int `orm:"column(sort_num)" description:"自定义排序编号"`
VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
Id int64 `orm:"column(id);pk" description:"唯一编号"`
CompanyId int `orm:"column(company_id)" description:"公司id"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型 chance_type.id"`
Name string `orm:"column(name);size(20)" description:"子分类名称"`
Doc string `orm:"column(doc);size(255)" description:"说明"`
Icon string `orm:"column(icon);size(255)" description:"图标"`
Code string `orm:"column(code);size(50);null" description:" 编码"`
NoticeType int8 `orm:"column(notice_type)" description:"通知方式"`
NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"`
SortNum int `orm:"column(sort_num)" description:"自定义排序编号"`
VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "`
VisibleObject string `orm:"column(visible_object);size(1000);null" description:"可见的对象 部门 指定人 json"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"`
Example string `orm:"column(example);null" description:"示例"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
}
func (t *AuditTemplate) TableName() string {
... ...
... ... @@ -214,8 +214,9 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques
}
for i := range templates {
item := templates[i]
//TODO:检查模板可见
//
if !checkVisible(header, item.VisibleObject) {
continue
}
//查询表单
if forms, err = models.GetAuditForms(header.CompanyId, item.Id); err != nil {
log.Error(err)
... ... @@ -227,7 +228,9 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques
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),
}
if len(item.Example) > 0 {
template.Link = fmt.Sprintf("%v/#/ability/opportunity?id=%v", beego.AppConfig.String("h5_host"), item.Id)
}
for j := range forms {
form := forms[j]
... ... @@ -270,7 +273,9 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest)
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),
}
if len(item.Example) > 0 {
template.Link = fmt.Sprintf("%v/#/ability/opportunity?id=%v", beego.AppConfig.String("h5_host"), item.Id)
}
for j := range forms {
form := forms[j]
... ... @@ -287,6 +292,27 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest)
return
}
func checkVisible(header *protocol.RequestHeader, vb string) (result bool) {
var (
vObject []*protocol.VisibleObject
)
result = true
if len(vb) == 0 {
return
}
utils.JsonUnmarshal(vb, &vObject)
if len(vObject) == 0 {
return
}
for i := range vObject {
if vObject[i].Id == header.UserId {
return
}
}
result = false
return
}
func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) {
//if template.VisibleType ==
return
... ... @@ -843,7 +869,7 @@ func ChanceCalculateScore(header *protocol.RequestHeader, request *protocol.Chan
}
sum += scoreConfig.ValueScore.Max * scoreConfig.DiscoveryScore.ValueFactor
}
rsp.DiscoveryScore = request.Score.BasicScore*scoreConfig.DiscoveryScore.BasicFactor + request.Score.ExtraScore*scoreConfig.DiscoveryScore.ExtraFactor + request.Score.ValueScore*scoreConfig.DiscoveryScore.ValueFactor
rsp.DiscoveryScore = utils.Decimal(request.Score.BasicScore*scoreConfig.DiscoveryScore.BasicFactor + request.Score.ExtraScore*scoreConfig.DiscoveryScore.ExtraFactor + request.Score.ValueScore*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(request.Score), sum, rsp.DiscoveryScore, rsp.DiscoveryScorePercent))
//发现分不为0
... ...