| | |
| | | @Component |
| | | public class TaskUtil { |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | @Autowired |
| | | private TAppUserService appUserService; |
| | | @Autowired |
| | | private TAppUserPositioningService appUserPositioningService; |
| | | |
| | | //每天0点30分执行 |
| | | @Scheduled(cron = "0 30 0 * * ?") |
| | | public void dayOfSavePositioning() { |
| | | try { |
| | | // 获取前一天时间 |
| | | LocalDate localDate = LocalDate.now().minusDays(1); |
| | | // 查询所有的用户 |
| | | List<TAppUser> appUserList = appUserService.list(Wrappers.lambdaQuery(TAppUser.class) |
| | | .eq(TAppUser::getState, 1) |
| | | .eq(TAppUser::getState, 1)); |
| | | |
| | | List<TAppUserPositioning> appUserPositioningList = new ArrayList<>(); |
| | | |
| | | for (TAppUser appUser : appUserList) { |
| | | TAppUserPositioning appUserPositioning = new TAppUserPositioning(); |
| | | // 获取定位 |
| | | String location = redisCache.getCacheObject(Constants.LOCATION + appUser.getId() + ":" + localDate); |
| | | if(StringUtils.hasLength(location)){ |
| | | appUserPositioning.setAppUserId(appUser.getId()); |
| | | appUserPositioning.setUserLocation(location); |
| | | appUserPositioning.setCreateTime(localDate.atStartOfDay()); |
| | | appUserPositioningList.add(appUserPositioning); |
| | | } |
| | | } |
| | | if(!CollectionUtils.isEmpty(appUserPositioningList)){ |
| | | appUserPositioningService.saveBatch(appUserPositioningList); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |