| | |
| | | |
| | | if (delayValue != null) { |
| | | if (delayValue.getSecond() < 0) { |
| | | AdjustmentValueCache.getDelayValue().remove(symbol); |
| | | AdjustmentValueCache.getPreAllocatedAdjustments().remove(symbol); |
| | | AdjustmentValueCache.getCurrentAdjustmentIndex().remove(symbol); |
| | | return; |
| | | clean(symbol); |
| | | continue; |
| | | } |
| | | int frequency = (int) Arith.div(Arith.mul(delayValue.getSecond(), 1000.0D), this.interval); |
| | | Integer frequency = AdjustmentValueCache.getFrequency().get(symbol); |
| | | if (frequency == null) { |
| | | frequency = (int) Arith.div(Arith.mul(delayValue.getSecond(), 1000.0D), this.interval); |
| | | AdjustmentValueCache.getFrequency().put(symbol, frequency); |
| | | } |
| | | if (frequency <= 1) { |
| | | // 单次分配:直接用带符号值,避免符号丢失 |
| | | BigDecimal delayVal = delayValue.getValue().setScale(decimal, RoundingMode.HALF_UP); |
| | | if (currentValue == null) { |
| | | AdjustmentValueCache.getCurrentValue().put(symbol, delayVal); |
| | | } else { |
| | | AdjustmentValueCache.getCurrentValue().put(symbol, currentValue.add(delayVal).setScale(decimal, RoundingMode.HALF_UP)); |
| | | } |
| | | if (!item.getAdjustmentValue().equals(AdjustmentValueCache.getCurrentValue().get(symbol))) { |
| | | item.setAdjustmentValue(AdjustmentValueCache.getCurrentValue().get(symbol)); |
| | | itemService.saveOrUpdate(item); |
| | | } |
| | | clean(symbol); |
| | | } else { |
| | | List<BigDecimal> adjustments = AdjustmentValueCache.getPreAllocatedAdjustments().get(symbol); |
| | | Integer currentIndex = AdjustmentValueCache.getCurrentAdjustmentIndex().get(symbol); |
| | | |
| | |
| | | int nextIndex = currentIndex + 1; |
| | | AdjustmentValueCache.getCurrentAdjustmentIndex().put(symbol, nextIndex); |
| | | if (nextIndex >= frequency) { |
| | | AdjustmentValueCache.getDelayValue().remove(symbol); |
| | | AdjustmentValueCache.getPreAllocatedAdjustments().remove(symbol); |
| | | AdjustmentValueCache.getCurrentAdjustmentIndex().remove(symbol); |
| | | clean(symbol); |
| | | } |
| | | |
| | | // 持久化更新 |
| | |
| | | if (!item.getAdjustmentValue().equals(newAdjustValue)) { |
| | | item.setAdjustmentValue(newAdjustValue); |
| | | itemService.saveOrUpdate(item); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | this.dataDBService.saveAsyn(realtime); |
| | | } |
| | | |
| | | private void clean(String symbol){ |
| | | AdjustmentValueCache.getDelayValue().remove(symbol); |
| | | AdjustmentValueCache.getPreAllocatedAdjustments().remove(symbol); |
| | | AdjustmentValueCache.getCurrentAdjustmentIndex().remove(symbol); |
| | | AdjustmentValueCache.getFrequency().remove(symbol); |
| | | } |
| | | |
| | | private List<BigDecimal> generateRandomAdjustments(BigDecimal totalValue, int count, int decimal) { |
| | | List<BigDecimal> adjustments = new ArrayList<>(count); |