Commit 893ad7e8 authored by fengjunkai's avatar fengjunkai

新增 limit同比模块

parent 9e8a8b5d
......@@ -49,6 +49,19 @@ func (Compare) Equal(alter string, real []string) bool {
return rs
}
//限制同比
func (Compare) LimitComparedWithSame(alter string, old []string, current []string) bool {
logger.Info.Println("old:", strings.Join(old, ","), "new: ", strings.Join(current, ","))
rs := true
lastIndex := len(current) - 1
for i, r := range current {
if i != 0 || i != lastIndex {
rs = rs && limitCompareSame(alter, old[i], r)
}
}
return rs
}
/**
同比超过alter
*/
......@@ -65,6 +78,15 @@ func (Compare) ComparedWithSame(alter string, old []string, current []string) bo
}
func limitCompareSame(alter string, old string, current string) bool {
cf := parseToFloat(current)
of := parseToFloat(old)
if cf < 200 && of < 200 {
return false
}
return (cf-of)/of > parseToFloat(alter)
}
func compareSame(alter string, old string, current string) bool {
cf := parseToFloat(current)
of := parseToFloat(old)
......@@ -106,3 +128,9 @@ func (MsgBuilder) Equal(alter string) string {
func (MsgBuilder) ComparedWithSame(alter string) string {
return "同比超过" + alter
}
//限制同比
func (MsgBuilder) LimitComparedWithSame(alter string) string {
return "同比超过" + alter
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment