ContractRepository.java 10.2 KB
Newer Older
manxiaoqiang committed
1 2 3 4 5 6
package common.repository;

import common.model.Contract;
import common.model.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
kangxiaoshan committed
7
import org.springframework.data.repository.query.Param;
manxiaoqiang committed
8 9 10
import org.springframework.transaction.annotation.Transactional;

import java.math.BigInteger;
kangxiaoshan committed
11
import java.util.Collection;
manxiaoqiang committed
12
import java.util.List;
kangxiaoshan committed
13
import java.util.Map;
manxiaoqiang committed
14 15 16 17

@Transactional
public interface ContractRepository extends JpaRepository<Contract, Long> {

kangxiaoshan committed
18
    @Query(value = "select count(*) from contract where ds = ?1", nativeQuery = true)
manxiaoqiang committed
19 20
    BigInteger countNumByDs(String ds);

kangxiaoshan committed
21
    @Query(value = "select count(*) from contract where email = ?1 and platform = ?2", nativeQuery = true)
manxiaoqiang committed
22
    BigInteger countNumByEmail(String email, String platfrom);
manxiaoqiang committed
23

kangxiaoshan committed
24
    @Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform = ?3 and status!='del' order by ds desc", nativeQuery = true)
manxiaoqiang committed
25
    List<Contract> findByDs(String startDate, String endDate, String platfrom);
manxiaoqiang committed
26

kangxiaoshan committed
27
    @Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform = ?3 and create_account in ?4 and status!='del' order by ds desc", nativeQuery = true)
manxiaoqiang committed
28 29
    List<Contract> findByDsAndRoile(String startDate, String endDate, String platfrom, List<Long> userids);

kangxiaoshan committed
30
    @Query(value = "select * from contract where contract_code = ?1", nativeQuery = true)
manxiaoqiang committed
31
    Contract findByCode(String contract_code);
manxiaoqiang committed
32

kangxiaoshan committed
33
    @Query(value = "SELECT * from contract where platform = ?1 and type = 'main'", nativeQuery = true)
manxiaoqiang committed
34 35
    List<Contract> findByPlatform(String platform);

kangxiaoshan committed
36
    @Query(value = "SELECT * from contract where platform = ?1 and email = ?2 and type = ?3", nativeQuery = true)
manxiaoqiang committed
37 38
    List<Contract> findByPlatformAndEmail(String platform, String email, String type);

kangxiaoshan committed
39 40
    @Query(value = "SELECT * from contract where platform = ?1 and email = ?2 and type = ?3 order by ds,end_date desc limit 1", nativeQuery = true)
    Contract findByPlatformAndEmailLimit1(String platform, String email, String type);
manxiaoqiang committed
41

kangxiaoshan committed
42 43
    @Query(value = "SELECT * from contract where platform = ?1 and email = ?2 and type = ?3 and price_level = ?4 order by ds desc limit 1", nativeQuery = true)
    Contract findByPlatformAndEmailAndPricelevelLimit1(String platform, String email, String type, Long priceLevel);
manxiaoqiang committed
44

kangxiaoshan committed
45
    @Query(value = "SELECT * from contract where platform = ?1 and email = ?2 and (status = 'wait' or status = 'executing') and type = 'main' order by ds desc limit 1", nativeQuery = true)
manxiaoqiang committed
46
    Contract findByPlatformAndEmailLimitVaild(String platform, String email);
manxiaoqiang committed
47

kangxiaoshan committed
48
    @Query(value = "SELECT * from contract where start_date = ?1  and status <> 'cancel'", nativeQuery = true)
manxiaoqiang committed
49 50
    List<Contract> findByStartDate(String startDate);

kangxiaoshan committed
51
    @Query(value = "SELECT * from contract where end_date <= ?1 and (status <> 'end' or status <> 'cancel')", nativeQuery = true)
manxiaoqiang committed
52
    List<Contract> findByEndDate(String endDate);
kangxiaoshan committed
53

kangxiaoshan committed
54
    @Query(value = "select count(*) from contract where my_body_code = ?1", nativeQuery = true)
kangxiaoshan committed
55 56
    BigInteger findcountContract(String platform);

kangxiaoshan committed
57
    @Query(value = "select new map( c.id as id, c.contractCode as contractCode ) from Contract c where c.platform in ?1 and c.contractCode is not null and c.contractCode <> 'null' and c.status <>'del'")
kangxiaoshan committed
58
    List<Map> contractCodePlatform(List<String> platform);
kangxiaoshan committed
59

kangxiaoshan committed
60
    @Query(value = "select * from contract where platform = ?1 and contract_code = ?2", nativeQuery = true)
kangxiaoshan committed
61
    Contract findByCodePlatform(String contractCode, String platform);
kangxiaoshan committed
62

kangxiaoshan committed
63
    @Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform in ?3 and id in ?4 and status!='del' order by ds desc", nativeQuery = true)
kangxiaoshan committed
64
    List<Contract> findByDsRelation(String startDate, String endDate, List<String> platform, List<String> contractIds);
kangxiaoshan committed
65

kangxiaoshan committed
66
    @Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform in ?3 and create_account in ?4 and id in ?5 and status!='del' order by ds desc", nativeQuery = true)
kangxiaoshan committed
67
    List<Contract> findByDsAndRoileRelation(String startDate, String endDate, List<String> platform, List<Long> create_account, List<String> contractIds);
kangxiaoshan committed
68 69 70 71


    @Query(value = "select new map( c.id as id, c.contractCode as contractCode ) from Contract c where c.platform in ?1 and c.contractCode is not null and c.contractCode <> 'null' ")
    List<Contract> contractCodePlatformNot(List<String> plats, List<Long> ids);
kangxiaoshan committed
72 73


74 75
    @Query(value = "select contract_code from contract where my_body_code = ?1 and product=?2  order by code_num desc limit 1", nativeQuery = true)
    String findLastCode(String code, String platform);
kangxiaoshan committed
76 77


kangxiaoshan committed
78
    @Query(value = "select * from contract where id = ?1 union all select * from contract where id = ?2", nativeQuery = true)
kangxiaoshan committed
79
    List<Contract> findByTwoIds(Long relationContract, Long relationContract1);
kangxiaoshan committed
80

kangxiaoshan committed
81
    @Query(value = "SELECT * from contract where platform =?1 and email = ?2  and (status <> 'end' or status <> 'cancel')", nativeQuery = true)
kangxiaoshan committed
82
    List<Contract> findByPlatformAndEmailStatus(String platgorm, String email);
kangxiaoshan committed
83

kangxiaoshan committed
84
    @Query(value = "select * from contract where contract_code =?2 and platform = ?1 ", nativeQuery = true)
kangxiaoshan committed
85
    Contract findOneByCode(String platform, String contractId);
kangxiaoshan committed
86

kangxiaoshan committed
87
    @Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform in ?3 and my_body_code in ?4 and id in ?5 and status!='del' order by ds desc", nativeQuery = true)
kangxiaoshan committed
88 89
    List<Contract> findByDsContractBody(String startDate, String endDate, List<String> platforms, List bodyids, List<String> ids);

kangxiaoshan committed
90
    @Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform = ?3 and my_body_code in ?4 and status!='del' order by ds desc", nativeQuery = true)
kangxiaoshan committed
91 92
    List<Contract> findByDsContractBody(String startDate, String endDate, String platform, List bodyids);

kangxiaoshan committed
93
    @Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform = ?3 and sale in ?4 and status!='del' order by ds desc", nativeQuery = true)
kangxiaoshan committed
94 95
    List<Contract> findByDsContractSalse(String startDate, String endDate, String platform, List salseid);

kangxiaoshan committed
96
    @Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform in ?3 and sale in ?4  and id in ?5 and status!='del' order by ds desc", nativeQuery = true)
kangxiaoshan committed
97
    List<Contract> findByDsContractSalse(String startDate, String endDate, List<String> platforms, List salseid, List<String> ids);
kangxiaoshan committed
98

kangxiaoshan committed
99
    @Query(value = "select contract_code,my_body_code,sale,platform from contract where contract_code in ?1", nativeQuery = true)
kangxiaoshan committed
100
    List<Object[]> findByContractCode(List<String> codesList);
101

lzxry committed
102
    @Query(value = "select * from contract where ((start_date <= ?1 and end_date >= ?1) or (start_date <= ?2 and end_date >= ?2) or (start_date >= ?1 and end_date <= ?2) or (start_date <= ?1 and end_date >= ?2))  and platform=?3 and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true)
kangxiaoshan committed
103
    List<Contract> findShareContranctByDate3(String startDate, String endDate, String platform);
104

lzxry committed
105
    @Query(value = "select * from contract where ((start_date <= ?1 and end_date >= ?1) or (start_date <= ?2 and end_date >= ?2) or (start_date >= ?1 and end_date <= ?2) or (start_date <= ?1 and end_date >= ?2))  and platform=?3   and my_body_code = ?4 and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true)
1  
kangxiaoshan committed
106
    List<Contract> findShareContranctByDate2(String startDate, String endDate, String platform, String bodyCode);
107

lzxry committed
108
    @Query(value = "select * from contract where ((start_date <= ?1 and end_date >= ?1) or (start_date <= ?2 and end_date >= ?2) or (start_date >= ?1 and end_date <= ?2) or (start_date <= ?1 and end_date >= ?2))  and platform=?3 and (my_body_name like %?4% or customer_body like %?4% or contract_code like %?4%)  and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true)
1  
kangxiaoshan committed
109
    List<Contract> findShareContranctByDateSerche(String startDate, String endDate, String platform, String serchName);
110

lzxry committed
111
    @Query(value = "select * from contract where ((start_date <= ?1 and end_date >= ?1) or (start_date <= ?2 and end_date >= ?2) or (start_date >= ?1 and end_date <= ?2) or (start_date <= ?1 and end_date >= ?2))  and platform=?3   and my_body_code = ?4  and (my_body_name like %?5% or customer_body like %?5% or contract_code like %?5%)  and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true)
1  
kangxiaoshan committed
112
    List<Contract> findShareContranctByDate1(String startDate, String endDate, String platform, String bodyCode, String serchName);
113

lzxry committed
114
    @Query(value = "select * from contract where ((start_date <= ?1 and end_date >= ?1) or (start_date <= ?2 and end_date >= ?2) or (start_date >= ?1 and end_date <= ?2) or (start_date <= ?1 and end_date >= ?2)) and platform=?3 and (my_body_name like %?4% or customer_body like %?4% or contract_code like %?5%) and my_body_code in ?5 and status!='del' and (share_sign = 1 or share_sign is null)  ", nativeQuery = true)
1  
kangxiaoshan committed
115
    List<Contract> findShareContranctByDateSercheFinace(String startDate, String endDate, String platform, String serchName, List<String> financeBodies);
116

lzxry committed
117
    @Query(value = "select * from contract where ((start_date <= ?1 and end_date >= ?1) or (start_date <= ?2 and end_date >= ?2) or (start_date >= ?1 and end_date <= ?2) or (start_date <= ?1 and end_date >= ?2))  and platform=?3 and my_body_code in ?4 and status!='del' and (share_sign = 1 or share_sign is null) ", nativeQuery = true)
1  
kangxiaoshan committed
118
    List<Contract> findShareContranctByDateFinace(String startDate, String endDate, String platform, List<String> financeBodies);
kangxiaoshan committed
119

kangxiaoshan committed
120
    @Query(value = "select contract_code from contract where customer_body =?1 and contract_code <> ?2 and  status in ('backfirst','normal','late')    limit 3 ", nativeQuery = true)
kangxiaoshan committed
121
    List<String> findContractBodyNames(String customerBody, String contractCode);
122

kangxiaoshan committed
123 124
    @Query(value = "select * from contract where contract_code=?1 limit 1  ", nativeQuery = true)
    Contract checkByCode(String code);
lzxry committed
125 126 127 128 129 130

    @Query(value = "select distinct email from contract where platform = ?1", nativeQuery = true)
    List<String> findDistinctEmailByPlatform(String platform);

    @Query(value = "SELECT * from contract where platform = ?1 and email = ?2", nativeQuery = true)
    List<Contract> findByPlatformAndEmail(String platform, String email);
manxiaoqiang committed
131
}