随表
@RunWith(SpringRunner.class) @SpringBootTest @Slf4j @Transactional @Rollback public class HoldingRepositoryTest { @PersistenceContext EntityManager entityManager; @Autowired private HoldingRepository holdingRepository; @Before public void setup() { holdingRepository.deleteAll(); holdingMergeRepository.deleteAll(); assertThat(holdingRepository.count()).isEqualTo(0); assertThat(holdingMergeRepository.count()).isEqualTo(0); } /** * 成本分析 * 个人指定日期的持股数据查询 * 当前测试主要针对数据库存在此人持股数据的情况 */ @Test public void testFindByRecordIdAndDateAndRosterTypeAndAllCountGreaterThan() { generateFindByRecordIdAndDateAndRosterTypeAndAllCountGreaterThan(); assertThat(holdingRepository.count()).isEqualTo(8); List<Holding> Holdings = holdingRepository.findByRecordIdAndDateAndRosterTypeAndAllCountGreaterThan(1L, "2010-05-22", 0, 0L); assertThat(Holdings.size()).isEqualTo(1); Holdings.forEach(item -> { assertThat(item.getDate()).isEqualTo("2010-05-22"); assertThat(item.getRosterType()).isEqualTo(0); }); } private void generateFindByRecordIdAndDateAndRosterTypeAndAllCountGreaterThan() { String holdingSql = "INSERT INTO `holding`(id,roster_name,roster_type,date,flag,SAcount,CAcount,allcount,ratio,cratio,changeNum,tradingPrice," + "turnover,averageCost,totalbuyamount,profit,profitrate,marketValue,buyCount,sellCount,data1," + "data2,data3,data4,recordId)" + " VALUES " + "('5ea80ba483886bf9e150559a6248d21e','时间范围内个人',0,'2010-05-22',1,0,2192900,2192900,0.16,0.21004789272030652,2192900,5.52,12104807.999999998,5.52,12104807.999999998,0,0,12104807.999999998,1,0,'0',NULL,NULL,NULL,1)," + "('5ea80ba483886bf9e150559a6248d21e','时间范围内个人',0,'2011-05-23',1,0,2292900,2292900,0.2,0.2196264367816092,-3189350,5.2,-16584620,-1.9537755680579187,12104807.999999998,16402892.000000002,1.3550724637681164,11923080,1,1,'0',NULL,NULL,NULL,1)," + "('5ea80ba483886bf9e150559a6248d21e','时间范围内个人',0,'2012-01-24',1,0,1692900,1692900,0.21,0.1621551724137931,-600000,5.28,-3168000,-4.51758048319452,12104807.999999998,16586324.000000002,1.370226111806152,8938512,1,2,'0',NULL,NULL,NULL,1)," + "('12381e79e169d6e8fdaf54829d8ebf','时间范围内机构1',1,'2010-05-22',1,0,2292900,2292900,0.16,0.2196264367816092,2292900,5.52,12656807.999999998,5.52,12656807.999999998,0,0,12656807.999999998,1,0,'0','1','时间范围内机构',NULL,1)," + "('ff65981e79e169d6e8fdaf54829d8ebe','时间范围内机构3',1,'2011-05-23',1,0,2292900,2292900,0.1,0.2196264367816092,-3439350,5.2,-17884620,-2.2800000000000007,12656807.999999998,17150892,1.3550724637681162,11923080,1,1,'0','1','时间范围内机构',NULL,1)," + "('ff65981e79e169d6e8ff54829d8ebf','时间范围内机构4',1,'2012-01-24',1,0,1292900,1292900,0.1,0.12384099616858238,-1000000,5.28,-5280000,-8.12731997834326,12656807.999999998,17334324,1.3695652173913047,6826512,1,2,'0','1','时间范围内机构',NULL,1)," + "('12381e79e169d6e8fdaf54829d8ebf','时间范围内机构2',1,'2012-05-23',1,0,2292900,2292900,0.1,0.2196264367816092,-3439350,5.2,-17884620,-2.2800000000000007,12656807.999999998,17150892,1.3550724637681162,11923080,1,1,'0','1','时间范围内机构',NULL,1)," + "('ee65981e79e169d6e8fdaf','时间范围内机构银行',1,'2011-05-23',1,0,1292900,1292900,0.1,0.12384099616858238,-1000000,5.28,-5280000,-8.12731997834326,12656807.999999998,17334324,1.3695652173913047,6826512,1,2,'0',NULL,NULL,NULL,1);"; entityManager.createNativeQuery(holdingSql).executeUpdate(); String holdingMergeSql = "INSERT INTO `holdingMerge` (id,roster_name,roster_type,date,flag,SAcount,CAcount,allcount,ratio,cratio,changeNum,tradingPrice," + "turnover,averageCost,totalbuyamount,profit,profitrate,marketValue,buyCount,sellCount,data1," + "data2,data3,data4,recordId)" + " VALUES " + "('ff65981e79e169d6e8fdaf54829d8ebg','时间范围内机构',1,'2010-05-22',null,null,null,2292900,0.16,0.2196264367816092,2292900,5.52,null,5.52,null,null,null,12656807.999999998,1,0,'1',NULL,NULL,NULL,1)," + "('ff65981e79e169d6e8fdaf54829d8ebg','时间范围内机构',1,'2011-05-23',null,null,null,2292900,0.1,0.2196264367816092,-3439350,5.2,null,-2.2800000000000007,null,null,null,11923080,1,1,'1',NULL,NULL,NULL,1)," + "('ff65981e79e169d6e8fdaf54829d8ebg','时间范围内机构',1,'2012-01-24',null,null,null,1292900,0.1,0.12384099616858238,-1000000,5.28,null,-8.12731997834326,null,null,null,6826512,1,2,'1',NULL,NULL,NULL,1)," + "('ff65981e79e169d6e8fdaf54829d8ebg','时间范围内机构',1,'2012-05-23',null,null,null,2292900,0.1,0.2196264367816092,-3439350,5.2,null,-2.2800000000000007,null,null,null,11923080,1,1,'1',NULL,NULL,NULL,1);"; entityManager.createNativeQuery(holdingMergeSql).executeUpdate(); } }