Commit bcbeee19 by kangxiaoshan

关联合同

parent a0f98c4c
...@@ -4,6 +4,7 @@ import common.model.ContractRelation; ...@@ -4,6 +4,7 @@ import common.model.ContractRelation;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import java.math.BigInteger;
import java.util.List; import java.util.List;
...@@ -12,8 +13,8 @@ import java.util.List; ...@@ -12,8 +13,8 @@ import java.util.List;
*/ */
public interface ContractRelationRepository extends JpaRepository<ContractRelation, Long> { public interface ContractRelationRepository extends JpaRepository<ContractRelation, Long> {
@Query(value = "select relation_id id from contract_relation where main_contract = ?1 union all select main_contract id from contract_relation where relation_id = ?1",nativeQuery = true) @Query(value = "select relation_id id from contract_relation where main_contract in ?1 union all select main_contract id from contract_relation where relation_id in ?1",nativeQuery = true)
List<Long> findRelationIds(String contractId); List<BigInteger> findRelationIds(List contractId);
@Query(value = "select * from contract_relation where main_contract = ?1 and relation_id = ?2 and platform = ?3",nativeQuery = true) @Query(value = "select * from contract_relation where main_contract = ?1 and relation_id = ?2 and platform = ?3",nativeQuery = true)
ContractRelation findByRelationData(Long mainContract, Long relationId, String platform); ContractRelation findByRelationData(Long mainContract, Long relationId, String platform);
......
...@@ -60,10 +60,10 @@ public interface ContractRepository extends JpaRepository<Contract, Long> { ...@@ -60,10 +60,10 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
Contract findByCodePlatform(String contractCode, String platform); Contract findByCodePlatform(String contractCode, String platform);
@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) @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)
List<Contract> findByDsRelation(String startDate, String endDate, List<String> platform, List<Long> contractIds); List<Contract> findByDsRelation(String startDate, String endDate, List<String> platform, List<String> contractIds);
@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) @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)
List<Contract> findByDsAndRoileRelation(String startDate, String endDate, List<String> platform, List<Long> create_account, List<Long> contractIds); List<Contract> findByDsAndRoileRelation(String startDate, String endDate, List<String> platform, List<Long> create_account, List<String> contractIds);
@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' ") @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' ")
......
...@@ -748,11 +748,15 @@ public class ContractServiceImpl implements ContractService { ...@@ -748,11 +748,15 @@ public class ContractServiceImpl implements ContractService {
List<Long> contractIds = null; List<Long> contractIds = null;
List<String> platforms = new ArrayList<>(); List<String> platforms = new ArrayList<>();
Map<String,String> idsDic = new HashMap<>();
platforms.add(platform); platforms.add(platform);
if (!StringUtils.isEmpty(contractId)) { if (!StringUtils.isEmpty(contractId)) {
//获取 关联合同列表 //获取 关联合同列表
contractIds = contractRelationRepository.findRelationIds(contractId); List<String> conIds = new ArrayList<>();
conIds.add(contractId);
this.getContractRelationIds(conIds,idsDic);
idsDic.remove(contractId);
if("fake".equals(platform)){ if("fake".equals(platform)){
platforms.add("tkio"); platforms.add("tkio");
} }
...@@ -760,7 +764,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -760,7 +764,7 @@ public class ContractServiceImpl implements ContractService {
List<Contract> contractList = new ArrayList<>(); List<Contract> contractList = new ArrayList<>();
List<String> ids = new ArrayList<>(idsDic.keySet());
if (loginAccount.getRole().equals(RoleEnum.SOUTH_BUSSINUSS.getKey()) || loginAccount.getRole().equals(RoleEnum.NORTH_BUSSINUSS.getKey())) { if (loginAccount.getRole().equals(RoleEnum.SOUTH_BUSSINUSS.getKey()) || loginAccount.getRole().equals(RoleEnum.NORTH_BUSSINUSS.getKey())) {
...@@ -777,7 +781,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -777,7 +781,7 @@ public class ContractServiceImpl implements ContractService {
if(!StringUtils.isEmpty(contractId)){ if(!StringUtils.isEmpty(contractId)){
//查看关联合同 //查看关联合同
if (contractIds != null && contractIds.size() > 0) { if (contractIds != null && contractIds.size() > 0) {
contractList = contractRepository.findByDsAndRoileRelation(startDate, endDate, platforms, idList, contractIds); contractList = contractRepository.findByDsAndRoileRelation(startDate, endDate, platforms, idList, ids);
} }
}else{ }else{
...@@ -790,7 +794,7 @@ public class ContractServiceImpl implements ContractService { ...@@ -790,7 +794,7 @@ public class ContractServiceImpl implements ContractService {
if(!StringUtils.isEmpty(contractId)){ if(!StringUtils.isEmpty(contractId)){
if (contractIds != null && contractIds.size() > 0) { if (contractIds != null && contractIds.size() > 0) {
contractList = contractRepository.findByDsRelation(startDate, endDate, platforms, contractIds); contractList = contractRepository.findByDsRelation(startDate, endDate, platforms, ids);
} }
}else{ }else{
contractList = contractRepository.findByDs(startDate, endDate, platform); contractList = contractRepository.findByDs(startDate, endDate, platform);
...@@ -827,44 +831,31 @@ public class ContractServiceImpl implements ContractService { ...@@ -827,44 +831,31 @@ public class ContractServiceImpl implements ContractService {
return result; return result;
} }
// @Override
// public List<Contract> findAllContract(User loginAccount, String startDate, String endDate, String platform, String contractId) { private void getContractRelationIds (List<String> contractId,Map<String,String> idsDic){
//
// List<Long> contractIds = null; //获取 关联合同 id
// List<String> contractIds = new ArrayList<>();
// if (!StringUtils.isEmpty(contractId)) {
// //获取 关联合同列表 List<BigInteger> ids = contractRelationRepository.findRelationIds(contractId);
// contractIds = contractRelationRepository.findRelationIds(contractId);
// } if (ids != null && ids.size() > 0) {
// for(BigInteger id : ids){
// List<Contract> contractList;
// if (!loginAccount.getRole().equals(RoleEnum.MANAGER.getKey())) { String idss = id.toString();
// //非 管理员 if (idsDic.get(idss) == null) {
// List<User> userList = userService.findAllSons(loginAccount.getId()); contractIds.add(idss);
// List<Long> idList = new ArrayList<>(); idsDic.put(idss,"0");
// idList.add(loginAccount.getId()); }
// for (User u : userList) { }
// idList.add(u.getId());
// } if(contractIds.size()>0){
// //递归 查询 id 查询所有相关联的合同
// if (contractIds != null && contractIds.size() > 0) { this.getContractRelationIds(contractIds,idsDic);
// contractList = contractRepository.findByDsAndRoileRelation(startDate, endDate, platform, idList, contractIds); }
// } else { }
// contractList = contractRepository.findByDsAndRoile(startDate, endDate, platform, idList); }
// }
//
// } else {
//
// if (contractIds != null && contractIds.size() > 0) {
// contractList = contractRepository.findByDsRelation(startDate, endDate, platform, contractIds);
// } else {
// contractList = contractRepository.findByDs(startDate, endDate, platform);
// }
//
// }
//
// return contractList;
// }
@Override @Override
public Contract contractStatusUpdate(String platform, String contractId, String status) { public Contract contractStatusUpdate(String platform, String contractId, String status) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment