AccountRepository.java 3.79 KB
Newer Older
manxiaoqiang committed
1 2 3 4 5 6 7 8 9 10 11
package tkio.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import tkio.model.Account;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;
12
import java.util.Map;
manxiaoqiang committed
13 14 15 16 17 18 19

@Transactional
public interface AccountRepository extends JpaRepository<Account, Long> {

    @Query(value = "select root_parent from account where id=?1", nativeQuery = true)
    BigInteger findRootParentByAccountId(Long accountId);

2  
manxiaoqiang committed
20 21 22
    @Query(value = "SELECT * from account where is_super_user is true and `status` = 1 and DATE_FORMAT(pub_date,'%Y-%m-%d') = ?1", nativeQuery = true)
    List<Account> findRootParentsByPubDate(String date);

manxiaoqiang committed
23 24 25 26 27 28
    @Query(value = "SELECT * from account where is_super_user is true and `status` = 1 and past_date > ?1", nativeQuery = true)
    List<Account> findRootParentsUnPast(String today);

    @Query(value = "SELECT * from account where is_super_user is true and `status` = 1 and past_date < ?1", nativeQuery = true)
    List<Account> findRootParentsPast(String today);

manxiaoqiang committed
29 30 31
    @Query(value = "SELECT * from account where is_super_user is true and `status` = 0", nativeQuery = true)
    List<Account> findRootParentsForbiden();

manxiaoqiang committed
32
    @Query(value = "SELECT * from account where is_super_user is true and  bussinessman in ?1", nativeQuery = true)
manxiaoqiang committed
33 34
    List<Account> findBussnissMan(List<Integer> bussinussIds);

35 36 37 38 39
    @Query(value = "select * from account where root_parent = ?1", nativeQuery = true)
    List<Account> findByRootParent(Long accountId);

    @Query(value = "select count(*) from account where root_parent = ?1 and create_time > ?2 and create_time < ?3", nativeQuery = true)
    BigInteger countByRootParent(Long accountId, String startDate, String endDate);
manxiaoqiang committed
40 41 42

    @Query(value = "select * from account where email = ?1", nativeQuery = true)
    Account findByEmail(String email);
kangxiaoshan committed
43 44 45

    @Query(value = "select email from account where is_super_user is true and  email in ?1", nativeQuery = true)
    List<String> findEmailByEmails(List<String> accountsEmail);
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

    @Query(value = "" +
            "select xy.email,IF(group_concat(xy.appkey separator ',') is not NULL,group_concat(xy.appkey separator ','),'') as appkey  " +
            "from(" +
            "  select x.appkey,y.pid,y.email,y.id" +
            "  from(" +
            "    select DISTINCT a.id pid,a.email,b.id" +
            "    from(select id,email from account where id = root_parent and role_category <> 5 and email not in (select distinct email from manager.contract where platform='tkio'))a " +
            "    join(select id,root_parent from account)b on a.id=b.root_parent " +
            "  )y " +
            "  left join app x " +
            "  on x.account=y.id " +
            ")xy " +
            "group by xy.pid,xy.email", nativeQuery = true)
    List<Map<String,String>> findAllAccountAppKeys();

    @Query(value = "" +
            "select xy.email,IF(group_concat(xy.appkey separator ',') is not NULL,group_concat(xy.appkey separator ','),'') as appkey  " +
            "from(" +
            "  select x.appkey,y.pid,y.email,y.id" +
            "  from(" +
            "    select DISTINCT a.id pid,a.email,b.id" +
            "    from(select id,email from account where id = root_parent and role_category <> 5 and email not in (select distinct email from manager.contract where platform='tkio')and email=?1)a " +
            "    join(select id,root_parent from account)b on a.id=b.root_parent " +
            "  )y " +
            "  left join app x " +
            "  on x.account=y.id " +
            ")xy " +
            "group by xy.pid,xy.email", nativeQuery = true)
    List<Map<String, String>> findAccountAppKeysByEmail(String email);
    
manxiaoqiang committed
77
}