use of com.tony.billing.entity.FundInfo in project BillingDubbo by TonyJiangWJ.
the class FundInfoServiceImpl method preSalePortion.
@Override
@Transactional(rollbackFor = { Exception.class, BaseBusinessException.class })
public boolean preSalePortion(FundPreSalePortionRequest request) {
FundInfo fundInfo = mapper.getById(request.getId(), UserIdContainer.getUserId());
if (fundInfo != null) {
BigDecimal saleAmount = request.getSaleAmount();
if (saleAmount.compareTo(fundInfo.getPurchaseAmount()) <= 0) {
BigDecimal restAmount = fundInfo.getPurchaseAmount().subtract(saleAmount);
Long saleFundId = null;
if (restAmount.compareTo(BigDecimal.ZERO) > 0) {
BigDecimal oneHundred = new BigDecimal("100");
BigDecimal salePercent = saleAmount.multiply(oneHundred).divide(fundInfo.getPurchaseAmount(), BigDecimal.ROUND_HALF_UP);
BigDecimal salePurchaseCost = salePercent.multiply(fundInfo.getPurchaseCost()).divide(oneHundred, 2, BigDecimal.ROUND_HALF_UP);
BigDecimal salePurchaseFee = salePercent.multiply(fundInfo.getPurchaseFee()).divide(oneHundred, 2, BigDecimal.ROUND_HALF_UP);
FundInfo saleFund = new FundInfo();
BeanUtils.copyProperties(fundInfo, saleFund);
saleFund.setPurchaseAmount(saleAmount);
saleFund.setPurchaseCost(salePurchaseCost);
saleFund.setPurchaseFee(salePurchaseFee);
saleFund.setId(null);
// 售出的记录下来
saleFundId = super.insert(saleFund);
// 记录部分售出基金的历史信息
FundInfoHistory fundInfoHistory = new FundInfoHistory();
BeanUtils.copyProperties(fundInfo, fundInfoHistory);
fundInfoHistory.setId(null);
fundInfoHistory.setOriginId(fundInfo.getId());
fundInfoHistory.setChangeType(EnumFundChangeType.SALE_PORTION.getType());
fundInfoHistory.setCreateTime(new Date());
fundInfoHistory.setModifyTime(new Date());
fundInfoHistoryMapper.insert(fundInfoHistory);
// 更新剩余份额
fundInfo.setPurchaseAmount(restAmount);
fundInfo.setPurchaseCost(fundInfo.getPurchaseCost().subtract(salePurchaseCost));
fundInfo.setPurchaseFee(fundInfo.getPurchaseFee().subtract(salePurchaseFee));
super.update(fundInfo);
} else {
// 全部卖出
saleFundId = fundInfo.getId();
}
// 标记为卖出
if (preMarkFundAsSold(saleFundId, UserIdContainer.getUserId(), request.getSaleFeeRate(), request.getAssessmentDate())) {
return true;
} else {
throw new BaseBusinessException("预售出基金信息保存失败");
}
}
}
return false;
}
use of com.tony.billing.entity.FundInfo in project BillingDubbo by TonyJiangWJ.
the class FundInfoController method updateFundInfo.
@RequestMapping(value = "/fund/info/update", method = RequestMethod.POST)
public BaseResponse updateFundInfo(@ModelAttribute("request") @Validated FundUpdateRequest request) {
FundInfo fundInfo = new FundInfo();
BeanUtils.copyProperties(request, fundInfo);
fundInfo.setConfirmDate(request.getPurchaseConfirmDate());
if (fundInfoService.update(fundInfo)) {
return ResponseUtil.success();
} else {
return ResponseUtil.error();
}
}
use of com.tony.billing.entity.FundInfo in project BillingDubbo by TonyJiangWJ.
the class FundInfoController method addFundInfo.
@RequestMapping(value = "/fund/info/put", method = RequestMethod.POST)
public BaseResponse addFundInfo(@ModelAttribute("request") @Validated FundAddRequest request) {
FundInfo fundInfo = new FundInfo();
fundInfo.setUserId(request.getUserId());
fundInfo.setFundName(request.getFundName());
fundInfo.setFundCode(request.getFundCode());
fundInfo.setPurchaseAmount(new BigDecimal(request.getPurchaseAmount()));
fundInfo.setPurchaseValue(new BigDecimal(request.getPurchaseValue()));
fundInfo.setPurchaseCost(new BigDecimal(request.getPurchaseCost()));
fundInfo.setPurchaseFee(new BigDecimal(request.getPurchaseFee()));
fundInfo.setInStore(EnumYesOrNo.YES.val());
fundInfo.setConfirmDate(request.getPurchaseConfirmDate());
fundInfo.setPurchaseDate(request.getPurchaseDate());
if (fundInfoService.insert(fundInfo) > 0) {
return ResponseUtil.success();
} else {
return ResponseUtil.error();
}
}
use of com.tony.billing.entity.FundInfo in project BillingDubbo by TonyJiangWJ.
the class FundHistoryValueServiceImpl method getFundChangedInfosByAssessmentDate.
@Override
public DailyFundChangedResponse getFundChangedInfosByAssessmentDate(String assessmentDate) {
DailyFundChangedResponse response = ResponseUtil.success(new DailyFundChangedResponse());
Long userId = UserIdContainer.getUserId();
List<FundInfo> userFunds = fundInfoService.listGroupedFundsByUserId(userId);
FundInfo fundInfo = new FundInfo();
fundInfo.setUserId(userId);
fundInfo.setInStore(EnumYesOrNo.YES.val());
List<FundInfo> userFundDetailList = fundInfoService.list(fundInfo);
if (CollectionUtils.isNotEmpty(userFunds)) {
List<FundHistoryValue> latestHistoryValues = mapper.getLatestFundHistoryValueByFundCodes(userFunds.stream().map(FundInfo::getFundCode).collect(Collectors.toList()), assessmentDate);
Map<String, FundHistoryValue> latestHistoryValueMap = new HashMap<>(latestHistoryValues.size());
if (CollectionUtils.isNotEmpty(latestHistoryValues)) {
latestHistoryValues.forEach(fundHistoryValue -> latestHistoryValueMap.put(fundHistoryValue.getFundCode(), fundHistoryValue));
}
response.setSummaryFundInfos(getFundChangedInfos(userFunds, latestHistoryValueMap, assessmentDate));
response.setFundDetailInfos(getFundChangedInfos(userFundDetailList, latestHistoryValueMap, assessmentDate));
response.setAssessmentDate(assessmentDate);
response.calculateIncreaseInfo();
}
return response;
}
use of com.tony.billing.entity.FundInfo in project BillingDubbo by TonyJiangWJ.
the class FundInfoServiceImpl method preMarkFundsAsSold.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean preMarkFundsAsSold(List<Long> fundIds, BigDecimal soldFeeRate, String assessmentDate) {
Preconditions.checkState(CollectionUtils.isNotEmpty(fundIds), "基金id列表不能为空");
Preconditions.checkState(soldFeeRate != null, "基金售出费率不能为空");
Preconditions.checkState(StringUtils.isNotEmpty(assessmentDate), "基金估算日期不能为空");
List<FundInfo> inStoreFunds = mapper.listInStoreFunds(fundIds, UserIdContainer.getUserId());
if (CollectionUtils.isNotEmpty(inStoreFunds)) {
inStoreFunds.forEach(fundInfo -> {
fundInfo.setInStore(EnumYesOrNo.NO.val());
super.update(fundInfo);
});
FundPreSaleInfo preSaleInfo = new FundPreSaleInfo();
preSaleInfo.setConverted(EnumYesOrNo.NO.val());
preSaleInfo.setFundCode(inStoreFunds.get(0).getFundCode());
preSaleInfo.setFundName(inStoreFunds.get(0).getFundName());
preSaleInfo.setUserId(UserIdContainer.getUserId());
BigDecimal purchaseCost = BigDecimal.ZERO;
BigDecimal purchaseFee = BigDecimal.ZERO;
BigDecimal soldAmount = BigDecimal.ZERO;
BigDecimal assessmentSoldIncome = BigDecimal.ZERO;
BigDecimal assessmentSoldFee = BigDecimal.ZERO;
FundHistoryValue latestFundValue = fundHistoryValueService.getFundLatestValue(preSaleInfo.getFundCode(), assessmentDate);
boolean hasAssessmentValue = latestFundValue != null;
for (FundInfo fundInfo : inStoreFunds) {
purchaseCost = purchaseCost.add(fundInfo.getPurchaseCost());
purchaseFee = purchaseFee.add(fundInfo.getPurchaseFee());
soldAmount = soldAmount.add(fundInfo.getPurchaseAmount());
if (hasAssessmentValue) {
assessmentSoldIncome = assessmentSoldIncome.add(latestFundValue.getAssessmentValue().multiply(fundInfo.getPurchaseAmount()));
}
}
if (hasAssessmentValue) {
assessmentSoldFee = assessmentSoldIncome.multiply(soldFeeRate).divide(BigDecimal.valueOf(100), BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP);
assessmentSoldIncome = assessmentSoldIncome.setScale(2, BigDecimal.ROUND_HALF_UP);
preSaleInfo.setAssessmentValue(latestFundValue.getAssessmentValue());
}
preSaleInfo.setAssessmentSoldFee(assessmentSoldFee);
preSaleInfo.setAssessmentSoldIncome(assessmentSoldIncome);
preSaleInfo.setSoldAmount(soldAmount);
preSaleInfo.setPurchaseCost(purchaseCost);
preSaleInfo.setPurchaseFee(purchaseFee);
LocalDate localDate = LocalDate.parse(assessmentDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
// 将估算日期作为卖出日期
preSaleInfo.setSoldDate(Date.from(localDate.atStartOfDay(TimeConstants.CHINA_ZONE).toInstant()));
// 成本净值为买入总支出除以买入(卖出)份额
preSaleInfo.setCostValue(purchaseCost.divide(soldAmount, 4, BigDecimal.ROUND_HALF_UP));
Long preSaleId = preSaleInfoService.insert(preSaleInfo);
if (preSaleId > 0) {
inStoreFunds.forEach(fundInfo -> {
FundPreSaleRef soldRef = new FundPreSaleRef();
soldRef.setFundId(fundInfo.getId());
soldRef.setFundPreSaleId(preSaleId);
fundPreSaleRefService.insert(soldRef);
});
return true;
} else {
throw new BaseBusinessException("保存预售信息失败");
}
}
return false;
}
Aggregations