Search in sources :

Example 1 with FundHistoryNetValueResponse

use of com.tony.billing.response.fund.FundHistoryNetValueResponse in project BillingDubbo by TonyJiangWJ.

the class FundHistoryNetValueServiceImpl method getHistoryNetValuesByFundCode.

@Override
public FundHistoryNetValueResponse getHistoryNetValuesByFundCode(String fundCode, String dateAfter, String dateBefore) {
    Preconditions.checkState(StringUtils.isNotEmpty(fundCode), "基金编码不能为空");
    if (StringUtils.isEmpty(dateAfter)) {
        LocalDate localDate = LocalDate.now();
        // 大约30个工作日
        localDate = localDate.plusDays(-43);
        dateAfter = DateUtil.formatDateTime(localDate, "yyyy-MM-dd");
    }
    if (StringUtils.isEmpty(dateBefore)) {
        dateBefore = DateUtil.formatDateTime(LocalDate.now(), "yyyy-MM-dd");
    }
    List<FundHistoryNetValue> historyNetValues = mapper.getHistoryNetValueInRange(dateAfter, dateBefore, fundCode);
    if (CollectionUtils.isNotEmpty(historyNetValues)) {
        FundHistoryNetValueResponse response = new FundHistoryNetValueResponse();
        response.setFundCode(fundCode);
        response.setHistoryNetValues(historyNetValues.stream().map(fundHistory -> new HashMap<String, String>(4) {

            {
                put(fundHistory.getConfirmDate(), fundHistory.getFundNetValue().toString());
            }
        }).collect(Collectors.toList()));
        response.setPurchaseDates(fundInfoMapper.listPurchaseDatesInRange(dateAfter, dateBefore, fundCode));
        response.setSoldDates(fundPreSaleInfoMapper.listPurchaseDatesInRange(dateAfter, dateBefore, fundCode));
        return response;
    }
    return ResponseUtil.error(new FundHistoryNetValueResponse());
}
Also used : FundHistoryNetValueResponse(com.tony.billing.response.fund.FundHistoryNetValueResponse) FundHistoryNetValue(com.tony.billing.entity.FundHistoryNetValue) LocalDate(java.time.LocalDate)

Aggregations

FundHistoryNetValue (com.tony.billing.entity.FundHistoryNetValue)1 FundHistoryNetValueResponse (com.tony.billing.response.fund.FundHistoryNetValueResponse)1 LocalDate (java.time.LocalDate)1