java8 stream record

Directly on the code

forEach () method, for loop

 

stream (). filter (). collect (Collectors.toList ()) display the required elements, into the corresponding list

stream (). map (WechatUser :: getUin) .collect (Collectors.toList ()) take into list uin

user -> Math.abs (.. Period.between (localDate, user.getLastLoginTime () toLocalDate ()) getDays ())> 89), WechatUser :: getUin anonymous expression, functional programming


 

    / ** 
     * Delete expired 90 days user information 
     * Remove basis: After the failure of all orders, all online micro-channel users forced offline, historical information risk control modules for 15 days, 90 days administrator user does not renew, unknown the system will clean up the account; 
     * regular tasks 
     * // TODO run `update timer expiration time task - after updateCompanyLimitWxAndEndDate ()` execution 
     * @return 
     * / 
    the @Transactional 
    public the Result expDeleteUserData () { 
        // query expired corporate user 
        List < Company> = companyMapper.expDateGt90DaysCompany companies (); 
        List <the User> = new new companyUsers the ArrayList <> (); 
        companies.forEach (Company -> companyUsers.add (userMapper.selectCompanyUserByCompanyId (company.getCompanyId ()))); 
        // management members login time filter, add all users in the company  
        LocalDate localDate = LocalDate.now ();
        List <Integer> userIds = new ArrayList <> ();
        List<User> users = companyUsers.stream().filter(user -> Math.abs(Period.between(localDate, user.getLastLoginTime().toLocalDate()).getDays()) > 89).collect(Collectors.toList());
        users.forEach(user -> userIds.addAll(userMapper.selectUserIdsByCompanyId(user.getCompanyId())));
        //批量软删除用户
        userMapper.updateDeletedByIds(userIds);
        return new Result().success();
    }

  

 


  / ** 
     * Clear the expired 15-day risk control user data 
     * Remove basis: After the failure of all orders, all online micro-channel users forced offline, risk control module history information for 15 days, 90 days, the user is not an administrator renewals, not logged system will clean up the account; 
     * regular tasks 
     * // TODO run `update timer expiration time task - after updateCompanyLimitWxAndEndDate ()` execution 
     * @return 
     * / 
    the @Transactional 
    public the Result expDeleteWxHistoryData () { 
        // query expired 15 days of corporate users 
        List <company> = companyMapper.expDateGt15DaysCompany companies (); 
        List <the user> = new new companyUsers the ArrayList <> (); 
        companies.forEach (company -> companyUsers.add (userMapper.selectCompanyUserByCompanyId (company.getCompanyId ())) ); 
        LocalDate localDate = LocalDate.now (); 
        // all those expired
        The ArrayList <Integer> = new new userIds the ArrayList <> (); 
        companyUsers.forEach (User -> userIds.addAll (userMapper.selectUserIdsByCompanyId (user.getCompanyId ()))); 

        // Clear the TODO wind control data performed here 
        // Get in all micro-channel users 
        List <WechatUser> wechatUsers = wechatUserMapper.getWeChatUserAccountByUserIds (userIds); 
        List <Integer> = uins wechatUsers.stream () Map (WechatUser :: getUin) .collect (Collectors.toList ());. 
        // delete wind control data 
        //wechatMessageMapper.deleteByUins(uins); 
        return new new the Result () Success ();. 
    }

  

 

Guess you like

Origin www.cnblogs.com/meijsuger/p/11534010.html