@@ -26,18 +26,22 @@ public Stat createOrGetStat(Account account){
26
26
Date today = new Date ();
27
27
Stat stat = statRepository .findByAccountIdAndFromDateBeforeAndToDateAfter (account .getId (), today ,today );
28
28
if (stat == null ){
29
- Date fromDate =Utils .formatDate (today ,null );
29
+ synchronized (Utils .getInternersPoll ().intern (account .getAccountNo ())){
30
+ stat = statRepository .findByAccountIdAndFromDateBeforeAndToDateAfter (account .getId (), today ,today );
31
+ if (stat != null ) return stat ;
32
+ Date fromDate =Utils .formatDate (today ,null );
30
33
31
- Integer cycleNum = account .getCycle ();
32
- Date maxToDate = account .getToDate ();
33
- Date nextCycleDate = Utils .getDateBy (fromDate ,cycleNum , Calendar .DAY_OF_YEAR );
34
- if (!maxToDate .after (fromDate )) return null ;
35
- stat = new Stat ();
36
- stat .setAccountId (account .getId ());
37
- stat .setFromDate (fromDate );
38
- stat .setToDate (nextCycleDate );
39
- stat .setFlow (0l );
40
- statRepository .save (stat );
34
+ Integer cycleNum = account .getCycle ();
35
+ Date maxToDate = account .getToDate ();
36
+ Date nextCycleDate = Utils .getDateBy (fromDate ,cycleNum , Calendar .DAY_OF_YEAR );
37
+ if (!maxToDate .after (fromDate )) return null ;
38
+ stat = new Stat ();
39
+ stat .setAccountId (account .getId ());
40
+ stat .setFromDate (fromDate );
41
+ stat .setToDate (nextCycleDate );
42
+ stat .setFlow (0l );
43
+ statRepository .save (stat );
44
+ }
41
45
}
42
46
return stat ;
43
47
}
0 commit comments