|
|
|
|
|
|
|
|
//我们设置的预警阈值 |
|
|
//我们设置的预警阈值 |
|
|
BigDecimal priceChange = new BigDecimal(zsOperationWarnconfig.getPriceChangeThreshold()); |
|
|
BigDecimal priceChange = new BigDecimal(zsOperationWarnconfig.getPriceChangeThreshold()); |
|
|
// 比较差值比例是否大于等于我们设置的预警阈值 |
|
|
// 比较差值比例是否大于等于我们设置的预警阈值 |
|
|
if (percentageChange.compareTo(priceChange) >= 0) { |
|
|
|
|
|
|
|
|
if ((priceChange.doubleValue()>=0&&percentageChange.compareTo(priceChange) >= 0)|| |
|
|
|
|
|
(priceChange.doubleValue()<0&&percentageChange.compareTo(priceChange) <= 0) |
|
|
|
|
|
) { |
|
|
//5.生成 预警结果数据 |
|
|
//5.生成 预警结果数据 |
|
|
String warnTypes = zsOperationWarnconfig.getWarnTypes(); |
|
|
String warnTypes = zsOperationWarnconfig.getWarnTypes(); |
|
|
ZsOperationWarnresult zsOperationWarnresult = new ZsOperationWarnresult(); |
|
|
ZsOperationWarnresult zsOperationWarnresult = new ZsOperationWarnresult(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 判断价格变化是否超过阈值 |
|
|
|
|
|
|
|
|
* 返回变化的差值比例 |
|
|
* @param curPrice 当前价格(基准价) |
|
|
* @param curPrice 当前价格(基准价) |
|
|
* @param newPrice 新价格 |
|
|
* @param newPrice 新价格 |
|
|
* @return 变化幅度超过阈值返回true,否则false |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public BigDecimal getChangeThreshold(BigDecimal curPrice,BigDecimal newPrice) { |
|
|
|
|
|
|
|
|
/* public BigDecimal getChangeThreshold(BigDecimal curPrice,BigDecimal newPrice) { |
|
|
// 参数校验 |
|
|
// 参数校验 |
|
|
if (curPrice == null || newPrice == null ) { |
|
|
if (curPrice == null || newPrice == null ) { |
|
|
throw new IllegalArgumentException("参数不能为空"); |
|
|
throw new IllegalArgumentException("参数不能为空"); |
|
|
|
|
|
|
|
|
BigDecimal percentageChange = diff.divide(curPrice, 4, RoundingMode.HALF_UP) |
|
|
BigDecimal percentageChange = diff.divide(curPrice, 4, RoundingMode.HALF_UP) |
|
|
.multiply(new BigDecimal("100")); |
|
|
.multiply(new BigDecimal("100")); |
|
|
return percentageChange; |
|
|
return percentageChange; |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
public static BigDecimal getChangeThreshold(BigDecimal curPrice, BigDecimal newPrice) { |
|
|
|
|
|
if (curPrice == null || newPrice == null ) { |
|
|
|
|
|
throw new IllegalArgumentException("价格参数不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 计算差值 |
|
|
|
|
|
BigDecimal difference = newPrice.subtract(curPrice); |
|
|
|
|
|
// 计算百分比 (差值/原价)*100 |
|
|
|
|
|
return difference.divide(curPrice,10, RoundingMode.HALF_UP) |
|
|
|
|
|
.multiply(new BigDecimal(100)); |
|
|
|
|
|
//.setScale(2, RoundingMode.HALF_UP); |
|
|
} |
|
|
} |
|
|
public boolean isBetween9And18() { |
|
|
public boolean isBetween9And18() { |
|
|
LocalTime currentTime = LocalTime.now(); |
|
|
LocalTime currentTime = LocalTime.now(); |