PrivatelyOfferedFundNavDao.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package com.smppw.analysis.domain.dao;
  2. import com.smppw.analysis.domain.dataobject.NavDo;
  3. import com.smppw.analysis.infrastructure.consts.NavConst;
  4. import com.smppw.analysis.domain.persistence.NavDoMapper;
  5. import com.smppw.common.pojo.dto.NavDto;
  6. import com.smppw.common.pojo.enums.NavType;
  7. import com.smppw.constants.DateConst;
  8. import com.smppw.utils.DateUtil;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Repository;
  11. import java.util.*;
  12. @Repository
  13. public class PrivatelyOfferedFundNavDao {
  14. @Autowired
  15. private NavDoMapper navDoMapper;
  16. public Map<String, List<NavDto>> getNav(List<String> fundIdList, String startDate, String endDate, NavType navType, boolean needUpdateAndCreateTime) {
  17. String navFieldSql = "";
  18. List<NavDo> navDoList = null;
  19. if (NavType.CumulativeNav == navType) {
  20. navFieldSql = NavConst.CUMULATIVE_NAV_SQL_FIELD;
  21. } else if (NavType.OriginalNav == navType) {
  22. navFieldSql = NavConst.NAV_SQL_FIELD;
  23. } else if (NavType.WithdrawalNav == navType) {
  24. navFieldSql = NavConst.CUMULATIVE_NAV_WITHDRAWAL_SQL_FIELD;
  25. } else if (NavType.All == navType) {
  26. navFieldSql = NavConst.CUMULATIVE_NAV_SQL_FIELD + "," + NavConst.NAV_SQL_FIELD + "," + NavConst.CUMULATIVE_NAV_WITHDRAWAL_SQL_FIELD;
  27. }
  28. navDoList = navDoMapper.listNavByTimeInterval(fundIdList, startDate, endDate, navFieldSql, needUpdateAndCreateTime);
  29. Map<String, List<NavDto>> fundIdNavDtoListMap = navDoListToNavDtoMap(navDoList);
  30. return fundIdNavDtoListMap;
  31. }
  32. /**
  33. * 领域对象集合转为数据传输对象集合
  34. *
  35. * @param navDoList 领域对象集合
  36. * @return 数据传输对象集合 key-基金ID value-数据传输对象集合
  37. */
  38. private Map<String, List<NavDto>> navDoListToNavDtoMap(List<NavDo> navDoList) {
  39. Map<String, List<NavDto>> fundIdNavDtoListMap = new HashMap<>();
  40. if (navDoList == null) {
  41. return fundIdNavDtoListMap;
  42. }
  43. for (NavDo navDo : navDoList) {
  44. NavDto navDto = new NavDto();
  45. navDto.setFundId(navDo.getFundId());
  46. if (navDo.getPriceDate() == null) {
  47. continue;
  48. }
  49. navDto.setPriceDate(DateUtil.DateToString(navDo.getPriceDate(), DateConst.YYYY_MM_DD));
  50. navDto.setOriginalNav(navDo.getNav());
  51. navDto.setCumulativeNav(navDo.getCumulativeNav());
  52. navDto.setCumulativeNavWithdrawal(navDo.getCumulativeNavWithdrawal());
  53. if (navDo.getUpdatetime() != null) {
  54. navDto.setUpdatetime(DateUtil.DateToString(navDo.getUpdatetime(), DateConst.YYYY_MM_DD_HH_MM_SS));
  55. }
  56. if (navDo.getCreatetime() != null) {
  57. navDto.setCreatetime(DateUtil.DateToString(navDo.getCreatetime(), DateConst.YYYY_MM_DD));
  58. }
  59. if (fundIdNavDtoListMap.containsKey(navDo.getFundId())) {
  60. List<NavDto> navDtoList = fundIdNavDtoListMap.get(navDo.getFundId());
  61. navDtoList.add(navDto);
  62. } else {
  63. List<NavDto> navDtoList = new ArrayList<>();
  64. navDtoList.add(navDto);
  65. fundIdNavDtoListMap.put(navDo.getFundId(), navDtoList);
  66. }
  67. }
  68. return fundIdNavDtoListMap;
  69. }
  70. /**
  71. * 获取基金净值更新时间 大于 传入的开始时间的基金id
  72. *
  73. * @param startTime 开始时间
  74. * @return 基金id列表
  75. */
  76. public List<NavDo> selectFundIdByStartTime(Date startTime) {
  77. return navDoMapper.selectFundIdByStartTime(startTime);
  78. }
  79. }