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

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

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

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

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

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

kangxiaoshan committed
26
    @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
27
    List<Contract> findByDs(String startDate, String endDate, String platfrom);
manxiaoqiang committed
28

kangxiaoshan committed
29
    @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
30 31
    List<Contract> findByDsAndRoile(String startDate, String endDate, String platfrom, List<Long> userids);

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

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

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

kangxiaoshan committed
41 42
    @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
43

kangxiaoshan committed
44 45
    @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
46

kangxiaoshan committed
47
    @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
48
    Contract findByPlatformAndEmailLimitVaild(String platform, String email);
manxiaoqiang committed
49

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

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

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

kangxiaoshan committed
59
    @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
60
    List<Map> contractCodePlatform(List<String> platform);
kangxiaoshan committed
61

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

kangxiaoshan committed
65
    @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
66
    List<Contract> findByDsRelation(String startDate, String endDate, List<String> platform, List<String> contractIds);
kangxiaoshan committed
67

kangxiaoshan committed
68
    @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
69
    List<Contract> findByDsAndRoileRelation(String startDate, String endDate, List<String> platform, List<Long> create_account, List<String> contractIds);
kangxiaoshan committed
70 71 72 73


    @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
74 75


76 77
    @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
78 79


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

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

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

kangxiaoshan committed
89
    @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
90 91
    List<Contract> findByDsContractBody(String startDate, String endDate, List<String> platforms, List bodyids, List<String> ids);

kangxiaoshan committed
92
    @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
93 94
    List<Contract> findByDsContractBody(String startDate, String endDate, String platform, List bodyids);

kangxiaoshan committed
95
    @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
96 97
    List<Contract> findByDsContractSalse(String startDate, String endDate, String platform, List salseid);

kangxiaoshan committed
98
    @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
99
    List<Contract> findByDsContractSalse(String startDate, String endDate, List<String> platforms, List salseid, List<String> ids);
kangxiaoshan committed
100

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

kangxiaoshan committed
104 105 106
    @Query(value = "select contract_code, my_body_name, customer_body, customer_short, business_type, agreement_type from contract where platform = 'dmp' and  contract_code in ?1", nativeQuery = true)
    List<Object[]> findByDmpContractCode(List<String> codesList);

lzxry committed
107
    @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
108
    List<Contract> findShareContranctByDate3(String startDate, String endDate, String platform);
109

lzxry committed
110
    @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
111
    List<Contract> findShareContranctByDate2(String startDate, String endDate, String platform, String bodyCode);
112

lzxry committed
113
    @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
114
    List<Contract> findShareContranctByDateSerche(String startDate, String endDate, String platform, String serchName);
115

lzxry committed
116
    @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
117
    List<Contract> findShareContranctByDate1(String startDate, String endDate, String platform, String bodyCode, String serchName);
118

lzxry committed
119
    @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
120
    List<Contract> findShareContranctByDateSercheFinace(String startDate, String endDate, String platform, String serchName, List<String> financeBodies);
121

lzxry committed
122
    @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
123
    List<Contract> findShareContranctByDateFinace(String startDate, String endDate, String platform, List<String> financeBodies);
kangxiaoshan committed
124

kangxiaoshan committed
125
    @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
126
    List<String> findContractBodyNames(String customerBody, String contractCode);
127

kangxiaoshan committed
128 129
    @Query(value = "select * from contract where contract_code=?1 limit 1  ", nativeQuery = true)
    Contract checkByCode(String code);
lzxry committed
130 131 132 133 134 135

    @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);
136 137 138 139 140 141 142

    @Query(value = "select id from contract where (email is null or email='null') and ( end_date >= ?1 and end_date <= ?2 )", nativeQuery = true)
    List<Long> findAllEmailIsNull(String startDate, String endDate);

    @Query(value = "SELECT relation_contract FROM contract where contract_type=2 and status!='del'", nativeQuery = true)
    List<Long> findRelationContractBySideAgre();

lzxry committed
143
    @Query(value = "SELECT * from contract where contract_code = ?1 UNION SELECT * from contract where relation_code = ?1 and create_time <= ?2 and id<> ?3 and contract_type = '2'", nativeQuery = true)
kangxiaoshan committed
144
    List<Contract> findByCreateTimeAndCodeNotOwn(String contractCode, String createTime, Long id);
lzxry committed
145

kangxiaoshan committed
146
    @Query(value = "select * from contract where next_signed_contract_code=?1 limit 1  ", nativeQuery = true)
lzxry committed
147
    Contract findByNextSignedContractCode(String contractCode);
lzxry committed
148

kangxiaoshan committed
149
    @Query(value = "select * from contract where platform=?1 and share_sign  = ?2 ", nativeQuery = true)
lzxry committed
150
    List<Contract> findByPlatformAndShareSign(String platform, int share_sign);
lzxry committed
151 152 153

    @Query(value = "select * from contract where contract_code = ?1 and status != 'del'", nativeQuery = true)
    Contract findByCodeAndNotDel(String contractCode);
kangxiaoshan committed
154 155 156

    @Query(value = "select id from contract where contract_code = ?1 ", nativeQuery = true)
    List<Long> findIdByCode(String relationCode);
kangxiaoshan committed
157 158 159 160 161

    @Transactional
    @Modifying
    @Query(value = "delete  from contract where contract_code = ?1 and platform=?2", nativeQuery = true)
    void deleteByCode(String contractCode, String platform);
manxiaoqiang committed
162
}