class MostVotedJob {

    public void calculateThePersonToGetCoin(){
        /** delete before insert*/
        dailyMostVotedRecordMapper.deleteByDate(new Date());

        final ThisLocalizedWeek chinaWeek = new ThisLocalizedWeek(Locale.CHINA);
        List<MostVotedRecord> mostVotedRecords = mostVotedRecordMapper.selectThePersonShouldBeAward(chinaWeek.getFirstDay(), chinaWeek.getLastDay(), new Date());
        for (MostVotedRecord mostVotedRecord : mostVotedRecords) {
            DailyMostVotedRecord dailyMostVotedRecord = dailyMostVotedRecordMapper.selectByawardDateAndMostVotedUserGroupId(new Date(), mostVotedRecord.getUserGroupId());
            if (dailyMostVotedRecord == null) {
                dailyMostVotedRecord = new DailyMostVotedRecord();
                dailyMostVotedRecord.setMostVotedUserGroupId(mostVotedRecord.getUserGroupId());
                dailyMostVotedRecord.setEarnCoin(1);
                dailyMostVotedRecord.setAwardDate(new Date());
                dailyMostVotedRecordMapper.insertSelective(dailyMostVotedRecord);
            }else {
                /** 感觉这句不要也可以诶  不过强迫症就加一下吧(#^.^#)*/
                dailyMostVotedRecord.setEarnCoin(1);
                dailyMostVotedRecordMapper.updateByPrimaryKey(dailyMostVotedRecord);
            }
        }

    }

}