正在显示
4 个修改的文件
包含
75 行增加
和
19 行删除
internal/utils/math.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "math" | ||
6 | + "strconv" | ||
7 | +) | ||
8 | + | ||
9 | +func decimal(value float64) float64 { | ||
10 | + return math.Trunc(value*1e1+0.5) * 1e-1 | ||
11 | +} | ||
12 | + | ||
13 | +func Decimal(value float64) float64 { | ||
14 | + value = decimal(value) | ||
15 | + value, _ = strconv.ParseFloat(fmt.Sprintf("%.1f", value), 64) | ||
16 | + return value | ||
17 | +} |
internal/utils/math_test.go
0 → 100644
@@ -8,20 +8,22 @@ import ( | @@ -8,20 +8,22 @@ import ( | ||
8 | ) | 8 | ) |
9 | 9 | ||
10 | type AuditTemplate struct { | 10 | type AuditTemplate struct { |
11 | - Id int64 `orm:"column(id);pk" description:"唯一编号"` | ||
12 | - CompanyId int `orm:"column(company_id)" description:"公司id"` | ||
13 | - ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型编号"` | ||
14 | - Name string `orm:"column(name);size(20)" description:"子分类名称"` | ||
15 | - Code string `orm:"column(code);size(50);null" description:"编码"` | ||
16 | - Doc string `orm:"column(doc);size(255)" description:"说明"` | ||
17 | - Icon string `orm:"column(icon);size(255)" description:"图标"` | ||
18 | - NoticeType int8 `orm:"column(notice_type)" description:"通知方式"` | ||
19 | - NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"` | ||
20 | - SortNum int `orm:"column(sort_num)" description:"自定义排序编号"` | ||
21 | - VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "` | ||
22 | - EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"` | ||
23 | - CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
24 | - UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | 11 | + Id int64 `orm:"column(id);pk" description:"唯一编号"` |
12 | + CompanyId int `orm:"column(company_id)" description:"公司id"` | ||
13 | + ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型 chance_type.id"` | ||
14 | + Name string `orm:"column(name);size(20)" description:"子分类名称"` | ||
15 | + Doc string `orm:"column(doc);size(255)" description:"说明"` | ||
16 | + Icon string `orm:"column(icon);size(255)" description:"图标"` | ||
17 | + Code string `orm:"column(code);size(50);null" description:" 编码"` | ||
18 | + NoticeType int8 `orm:"column(notice_type)" description:"通知方式"` | ||
19 | + NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"` | ||
20 | + SortNum int `orm:"column(sort_num)" description:"自定义排序编号"` | ||
21 | + VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "` | ||
22 | + VisibleObject string `orm:"column(visible_object);size(1000);null" description:"可见的对象 部门 指定人 json"` | ||
23 | + EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"` | ||
24 | + Example string `orm:"column(example);null" description:"示例"` | ||
25 | + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
26 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | ||
25 | } | 27 | } |
26 | 28 | ||
27 | func (t *AuditTemplate) TableName() string { | 29 | func (t *AuditTemplate) TableName() string { |
@@ -214,8 +214,9 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques | @@ -214,8 +214,9 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques | ||
214 | } | 214 | } |
215 | for i := range templates { | 215 | for i := range templates { |
216 | item := templates[i] | 216 | item := templates[i] |
217 | - //TODO:检查模板可见 | ||
218 | - // | 217 | + if !checkVisible(header, item.VisibleObject) { |
218 | + continue | ||
219 | + } | ||
219 | //查询表单 | 220 | //查询表单 |
220 | if forms, err = models.GetAuditForms(header.CompanyId, item.Id); err != nil { | 221 | if forms, err = models.GetAuditForms(header.CompanyId, item.Id); err != nil { |
221 | log.Error(err) | 222 | log.Error(err) |
@@ -227,7 +228,9 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques | @@ -227,7 +228,9 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques | ||
227 | Icon: item.Icon, | 228 | Icon: item.Icon, |
228 | Doc: item.Doc, | 229 | Doc: item.Doc, |
229 | FormList: make([]*protocol.Form, len(forms)), | 230 | FormList: make([]*protocol.Form, len(forms)), |
230 | - Link: fmt.Sprintf("%v/#/ability/opportunity?id=%v", beego.AppConfig.String("h5_host"), item.Id), | 231 | + } |
232 | + if len(item.Example) > 0 { | ||
233 | + template.Link = fmt.Sprintf("%v/#/ability/opportunity?id=%v", beego.AppConfig.String("h5_host"), item.Id) | ||
231 | } | 234 | } |
232 | for j := range forms { | 235 | for j := range forms { |
233 | form := forms[j] | 236 | form := forms[j] |
@@ -270,7 +273,9 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) | @@ -270,7 +273,9 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) | ||
270 | Icon: item.Icon, | 273 | Icon: item.Icon, |
271 | Doc: item.Doc, | 274 | Doc: item.Doc, |
272 | FormList: make([]*protocol.Form, len(forms)), | 275 | FormList: make([]*protocol.Form, len(forms)), |
273 | - Link: fmt.Sprintf("%v/#/ability/opportunity?id=%v", beego.AppConfig.String("h5_host"), item.Id), | 276 | + } |
277 | + if len(item.Example) > 0 { | ||
278 | + template.Link = fmt.Sprintf("%v/#/ability/opportunity?id=%v", beego.AppConfig.String("h5_host"), item.Id) | ||
274 | } | 279 | } |
275 | for j := range forms { | 280 | for j := range forms { |
276 | form := forms[j] | 281 | form := forms[j] |
@@ -287,6 +292,27 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) | @@ -287,6 +292,27 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) | ||
287 | return | 292 | return |
288 | } | 293 | } |
289 | 294 | ||
295 | +func checkVisible(header *protocol.RequestHeader, vb string) (result bool) { | ||
296 | + var ( | ||
297 | + vObject []*protocol.VisibleObject | ||
298 | + ) | ||
299 | + result = true | ||
300 | + if len(vb) == 0 { | ||
301 | + return | ||
302 | + } | ||
303 | + utils.JsonUnmarshal(vb, &vObject) | ||
304 | + if len(vObject) == 0 { | ||
305 | + return | ||
306 | + } | ||
307 | + for i := range vObject { | ||
308 | + if vObject[i].Id == header.UserId { | ||
309 | + return | ||
310 | + } | ||
311 | + } | ||
312 | + result = false | ||
313 | + return | ||
314 | +} | ||
315 | + | ||
290 | func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) { | 316 | func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) { |
291 | //if template.VisibleType == | 317 | //if template.VisibleType == |
292 | return | 318 | return |
@@ -843,7 +869,7 @@ func ChanceCalculateScore(header *protocol.RequestHeader, request *protocol.Chan | @@ -843,7 +869,7 @@ func ChanceCalculateScore(header *protocol.RequestHeader, request *protocol.Chan | ||
843 | } | 869 | } |
844 | sum += scoreConfig.ValueScore.Max * scoreConfig.DiscoveryScore.ValueFactor | 870 | sum += scoreConfig.ValueScore.Max * scoreConfig.DiscoveryScore.ValueFactor |
845 | } | 871 | } |
846 | - rsp.DiscoveryScore = request.Score.BasicScore*scoreConfig.DiscoveryScore.BasicFactor + request.Score.ExtraScore*scoreConfig.DiscoveryScore.ExtraFactor + request.Score.ValueScore*scoreConfig.DiscoveryScore.ValueFactor | 872 | + rsp.DiscoveryScore = utils.Decimal(request.Score.BasicScore*scoreConfig.DiscoveryScore.BasicFactor + request.Score.ExtraScore*scoreConfig.DiscoveryScore.ExtraFactor + request.Score.ValueScore*scoreConfig.DiscoveryScore.ValueFactor) |
847 | rsp.DiscoveryScorePercent = int((rsp.DiscoveryScore / sum) * 100) | 873 | rsp.DiscoveryScorePercent = int((rsp.DiscoveryScore / sum) * 100) |
848 | log.Debug(fmt.Sprintf("计算发现-> score_config:%v score:%v 总分:%v 发现分:%v 发现分百分比:%v", common.AssertJson(scoreConfig), common.AssertJson(request.Score), sum, rsp.DiscoveryScore, rsp.DiscoveryScorePercent)) | 874 | log.Debug(fmt.Sprintf("计算发现-> score_config:%v score:%v 总分:%v 发现分:%v 发现分百分比:%v", common.AssertJson(scoreConfig), common.AssertJson(request.Score), sum, rsp.DiscoveryScore, rsp.DiscoveryScorePercent)) |
849 | //发现分不为0 | 875 | //发现分不为0 |
-
请 注册 或 登录 后发表评论