class TargetFreshJob {

    @Scheduled(cron = "1 0 0 ? * 1")
    public void executeTargetFresh() {

        Date day=new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("Fresh Target Job start ："+df.format(day));

        ThisLocalizedWeek thisLocalizedWeek = new ThisLocalizedWeek(Locale.CHINA);

        List<TargetDistance> targetDistances = targetDistanceMapper.selectByTimeRange(thisLocalizedWeek.getPreFirstDay(), thisLocalizedWeek.getPreLastDay());

        for (TargetDistance targetDistance : targetDistances) {


            /**
             * 为了保证数据一周只能有一次 先删除然后再插入
             */
            List<TargetDistance> targetDistanceolds = targetDistanceMapper.selectByUserGroupIdAndTimeRangeReturnList(targetDistance.getUserGroupId(), thisLocalizedWeek.getFirstDay(), thisLocalizedWeek.getLastDay());
            if (targetDistanceolds!=null){
                for (TargetDistance targetDistanceold : targetDistanceolds) {
                    targetDistanceMapper.deleteByPrimaryKey(targetDistanceold.getTargetDistanceId());
                }
            }

            targetDistance.setCreationTime(new Date());
            targetDistance.setTargetDistanceId(null);
            log.info("Generate Target"+ targetDistance.toString());
            targetDistanceMapper.insert(targetDistance);
        }

        day = new Date();
        log.info("Fresh Target Job Finished ："+df.format(day));

    }

}