Commit bcbeee19 by kangxiaoshan

关联合同

parent a0f98c4c
......@@ -4,6 +4,7 @@ import common.model.ContractRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.math.BigInteger;
import java.util.List;
......@@ -12,8 +13,8 @@ import java.util.List;
*/
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)
List<Long> findRelationIds(String contractId);
@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<BigInteger> findRelationIds(List contractId);
@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);
......
......@@ -60,10 +60,10 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
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)
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)
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' ")
......
......@@ -748,11 +748,15 @@ public class ContractServiceImpl implements ContractService {
List<Long> contractIds = null;
List<String> platforms = new ArrayList<>();
Map<String,String> idsDic = new HashMap<>();
platforms.add(platform);
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)){
platforms.add("tkio");
}
......@@ -760,7 +764,7 @@ public class ContractServiceImpl implements ContractService {
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())) {
......@@ -777,7 +781,7 @@ public class ContractServiceImpl implements ContractService {
if(!StringUtils.isEmpty(contractId)){
//查看关联合同
if (contractIds != null && contractIds.size() > 0) {
contractList = contractRepository.findByDsAndRoileRelation(startDate, endDate, platforms, idList, contractIds);
contractList = contractRepository.findByDsAndRoileRelation(startDate, endDate, platforms, idList, ids);
}
}else{
......@@ -790,7 +794,7 @@ public class ContractServiceImpl implements ContractService {
if(!StringUtils.isEmpty(contractId)){
if (contractIds != null && contractIds.size() > 0) {
contractList = contractRepository.findByDsRelation(startDate, endDate, platforms, contractIds);
contractList = contractRepository.findByDsRelation(startDate, endDate, platforms, ids);
}
}else{
contractList = contractRepository.findByDs(startDate, endDate, platform);
......@@ -827,44 +831,31 @@ public class ContractServiceImpl implements ContractService {
return result;
}
// @Override
// public List<Contract> findAllContract(User loginAccount, String startDate, String endDate, String platform, String contractId) {
//
// List<Long> contractIds = null;
//
// if (!StringUtils.isEmpty(contractId)) {
// //获取 关联合同列表
// contractIds = contractRelationRepository.findRelationIds(contractId);
// }
//
// List<Contract> contractList;
// if (!loginAccount.getRole().equals(RoleEnum.MANAGER.getKey())) {
// //非 管理员
// List<User> userList = userService.findAllSons(loginAccount.getId());
// List<Long> idList = new ArrayList<>();
// idList.add(loginAccount.getId());
// for (User u : userList) {
// idList.add(u.getId());
// }
//
// if (contractIds != null && contractIds.size() > 0) {
// 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;
// }
private void getContractRelationIds (List<String> contractId,Map<String,String> idsDic){
//获取 关联合同 id
List<String> contractIds = new ArrayList<>();
List<BigInteger> ids = contractRelationRepository.findRelationIds(contractId);
if (ids != null && ids.size() > 0) {
for(BigInteger id : ids){
String idss = id.toString();
if (idsDic.get(idss) == null) {
contractIds.add(idss);
idsDic.put(idss,"0");
}
}
if(contractIds.size()>0){
//递归 查询 id 查询所有相关联的合同
this.getContractRelationIds(contractIds,idsDic);
}
}
}
@Override
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