Commit af94c28d authored by 郑建's avatar 郑建

6.6-2

parent 8bc9f697
package com.quantgroup.asset.distribution.service.approval; package com.quantgroup.asset.distribution.service.approval;
import java.math.BigInteger;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -43,7 +44,7 @@ public interface IApprovalLogService { ...@@ -43,7 +44,7 @@ public interface IApprovalLogService {
public Map<String, Object> getApprovalLogs(String targetName, Integer auditStatus, Integer auditType, Integer auditTarget, public Map<String, Object> getApprovalLogs(String targetName, Integer auditStatus, Integer auditType, Integer auditTarget,
String applyStartTime, String applyEndTime, String user, Integer pageNum, Integer pageSize); String applyStartTime, String applyEndTime, String user, Integer pageNum, Integer pageSize);
List<Long> getFundConfigIds(String channel); List<BigInteger> getFundConfigIds(String channel);
/** /**
* 审批接口 * 审批接口
......
package com.quantgroup.asset.distribution.service.approval.impl; package com.quantgroup.asset.distribution.service.approval.impl;
import java.math.BigInteger;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -107,7 +108,7 @@ public class ApprovalLogServiceImpl implements IApprovalLogService{ ...@@ -107,7 +108,7 @@ public class ApprovalLogServiceImpl implements IApprovalLogService{
} }
@Override @Override
public List<Long> getFundConfigIds(String channel){ public List<BigInteger> getFundConfigIds(String channel){
if (StringUtils.isEmpty(channel)){ if (StringUtils.isEmpty(channel)){
return approvalLogRepository.findAuditConfigIds(); return approvalLogRepository.findAuditConfigIds();
}else { }else {
......
...@@ -16,6 +16,7 @@ import com.quantgroup.asset.distribution.util.fund.module.ChannelFundConfigUtil; ...@@ -16,6 +16,7 @@ import com.quantgroup.asset.distribution.util.fund.module.ChannelFundConfigUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hibernate.jpa.criteria.OrderImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
...@@ -27,10 +28,14 @@ import org.springframework.data.jpa.domain.Specification; ...@@ -27,10 +28,14 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.xml.transform.Source;
import java.math.BigInteger;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -47,6 +52,8 @@ public class FundModuleChannelFundConfigNewServiceImpl implements IFundModuleCha ...@@ -47,6 +52,8 @@ public class FundModuleChannelFundConfigNewServiceImpl implements IFundModuleCha
private IFundModuleChannelFundConfigNewRepository fundModuleChannelFundConfigNewRepository; private IFundModuleChannelFundConfigNewRepository fundModuleChannelFundConfigNewRepository;
@Autowired @Autowired
private IApprovalLogService approvalLogService; private IApprovalLogService approvalLogService;
@Autowired
private EntityManager entityManager;
@Override @Override
public Map<String, Object> getChannelFundConfigsByChannelOrFundId(String bizChannel, Long fundId, Integer pageNum, Integer pageSize) { public Map<String, Object> getChannelFundConfigsByChannelOrFundId(String bizChannel, Long fundId, Integer pageNum, Integer pageSize) {
...@@ -160,32 +167,39 @@ public class FundModuleChannelFundConfigNewServiceImpl implements IFundModuleCha ...@@ -160,32 +167,39 @@ public class FundModuleChannelFundConfigNewServiceImpl implements IFundModuleCha
@Override @Override
public Map<String, Object> getChannelFundConfigsByChannelOrFundIdOrdered(String bizChannel, Long fundId, Integer pageNum, Integer pageSize) { public Map<String, Object> getChannelFundConfigsByChannelOrFundIdOrdered(String bizChannel, Long fundId, Integer pageNum, Integer pageSize) {
List<Long> ids = approvalLogService.getFundConfigIds(bizChannel); List<BigInteger> ids = approvalLogService.getFundConfigIds(bizChannel);
// 分页条件 // 分页条件
Pageable pageable = new PageRequest(pageNum < 0 ? 0 : pageNum, pageSize); Integer start = pageNum * pageSize;
Integer end = (pageNum + 1) * pageSize;
Specification<FundModuleChannelFundConfigNew> specification = new Specification<FundModuleChannelFundConfigNew>() { List<FundModuleChannelFundConfigNew> channelFundConfigs;
@Override StringBuilder idsStr = new StringBuilder();
public Predicate toPredicate(Root<FundModuleChannelFundConfigNew> root, CriteriaQuery<?> query, CriteriaBuilder cb) { for (BigInteger id : ids){
List<Predicate> predicates = new ArrayList<>(); idsStr.append(",").append(id);
predicates.add(cb.equal(root.get("enable"), true)); }
if(StringUtils.isNotEmpty(bizChannel)){ idsStr.delete(0,1);
predicates.add(cb.equal(root.get("bizChannel"), bizChannel)); String fundLike = "";
} if (fundId != null) {
if(fundId != null){ fundLike = "and fund_ids like '%" + fundId + "%'";
predicates.add(cb.like(root.get("fundIds"), "%" + fundId + "%")); }
} String sql = "SELECT * FROM fund_module_channel_fund_config_new where id in ("+idsStr.toString()+") "+ fundLike+" order by field(id,"+idsStr.toString()+") limit "+start+","+end;
query.where(predicates.toArray(new Predicate[predicates.size()])); Query query = entityManager.createNativeQuery(sql,FundModuleChannelFundConfigNew.class);
return query.getRestriction(); channelFundConfigs = query.getResultList();
String total;
if (fundId == null){
total = ids.size() + "";
}else {
if (StringUtils.isEmpty(bizChannel)){
total = fundModuleChannelFundConfigNewRepository.count(fundId,ids) + "";
}else {
total = fundModuleChannelFundConfigNewRepository.count(fundId,bizChannel,ids) + "";
} }
}; }
Page<FundModuleChannelFundConfigNew> channelFundConfigs = fundModuleChannelFundConfigNewRepository.findAll(specification, pageable);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put("total", channelFundConfigs.getTotalElements()); result.put("total", total);
result.put("pages", channelFundConfigs.getTotalPages()); result.put("pages", (int)(new Double(total)%pageSize == 0?new Double(total)/pageSize:new Double(total)/pageSize +1));
result.put("pageSize", channelFundConfigs.getSize()); result.put("pageSize", pageSize);
result.put("pageNum", channelFundConfigs.getNumber()); result.put("pageNum", pageNum);
result.put("list", channelFundConfigs.getContent()); result.put("list", channelFundConfigs);
return result; return result;
} }
......
...@@ -141,7 +141,7 @@ public class FundModuleServiceImpl implements IFundModuleService{ ...@@ -141,7 +141,7 @@ public class FundModuleServiceImpl implements IFundModuleService{
@Override @Override
public GlobalResponse getChannelFundConfigsNew(String bizChannel, Long fundId, Integer pageNum, Integer pageSize,Integer sortMode) { public GlobalResponse getChannelFundConfigsNew(String bizChannel, Long fundId, Integer pageNum, Integer pageSize,Integer sortMode) {
Map<String, Object> result; Map<String, Object> result;
if (sortMode != null && sortMode == 2){ if (sortMode != null && sortMode == 1){
result = fundModuleChannelFundConfigNewService.getChannelFundConfigsByChannelOrFundIdOrdered(bizChannel, fundId, pageNum, pageSize); result = fundModuleChannelFundConfigNewService.getChannelFundConfigsByChannelOrFundIdOrdered(bizChannel, fundId, pageNum, pageSize);
}else{ }else{
result = fundModuleChannelFundConfigNewService.getChannelFundConfigsByChannelOrFundId(bizChannel, fundId, pageNum, pageSize); result = fundModuleChannelFundConfigNewService.getChannelFundConfigsByChannelOrFundId(bizChannel, fundId, pageNum, pageSize);
......
...@@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; ...@@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import com.quantgroup.asset.distribution.service.jpa.entity.ApprovalLog; import com.quantgroup.asset.distribution.service.jpa.entity.ApprovalLog;
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;
public interface IApprovalLogRepository extends JpaRepository<ApprovalLog, Long>, JpaSpecificationExecutor<ApprovalLog>{ public interface IApprovalLogRepository extends JpaRepository<ApprovalLog, Long>, JpaSpecificationExecutor<ApprovalLog>{
...@@ -18,8 +19,8 @@ public interface IApprovalLogRepository extends JpaRepository<ApprovalLog, Long ...@@ -18,8 +19,8 @@ public interface IApprovalLogRepository extends JpaRepository<ApprovalLog, Long
Integer auditStatus); Integer auditStatus);
@Query(value = "select audit_config_id from approval_log where audit_type = 1 and target_name = ?1 and (audit_status = 0 or audit_status = 1) order by audit_status asc,updated_at desc", nativeQuery = true) @Query(value = "select audit_config_id from approval_log where audit_type = 1 and target_name = ?1 and (audit_status = 0 or audit_status = 1) order by audit_status asc,updated_at desc", nativeQuery = true)
List<Long> findAuditConfigIds(String channel); List<BigInteger> findAuditConfigIds(String channel);
@Query(value = "select audit_config_id from approval_log where audit_type = 1 and (audit_status = 0 or audit_status = 1) order by audit_status asc,updated_at desc",nativeQuery = true) @Query(value = "select audit_config_id from approval_log where audit_type = 1 and (audit_status = 0 or audit_status = 1) order by audit_status asc,updated_at desc",nativeQuery = true)
List<Long> findAuditConfigIds(); List<BigInteger> findAuditConfigIds();
} }
...@@ -2,10 +2,14 @@ package com.quantgroup.asset.distribution.service.jpa.repository; ...@@ -2,10 +2,14 @@ package com.quantgroup.asset.distribution.service.jpa.repository;
import com.quantgroup.asset.distribution.service.jpa.entity.FundModuleChannelFundConfig; import com.quantgroup.asset.distribution.service.jpa.entity.FundModuleChannelFundConfig;
import com.quantgroup.asset.distribution.service.jpa.entity.FundModuleChannelFundConfigNew; import com.quantgroup.asset.distribution.service.jpa.entity.FundModuleChannelFundConfigNew;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
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;
/** /**
...@@ -39,10 +43,10 @@ public interface IFundModuleChannelFundConfigNewRepository extends JpaRepository ...@@ -39,10 +43,10 @@ public interface IFundModuleChannelFundConfigNewRepository extends JpaRepository
@Query(value = "select biz_channel from fund_module_channel_fund_config_new where enable = 1", nativeQuery = true) @Query(value = "select biz_channel from fund_module_channel_fund_config_new where enable = 1", nativeQuery = true)
public List<String> getAllBizChannel(); public List<String> getAllBizChannel();
@Query(value = "SELECT * FROM fund_module_channel_fund_config_new where id in ?1 order by field(?1)",nativeQuery = true) @Query(value = "SELECT count(*) FROM fund_module_channel_fund_config_new where id in ?3 and fund_ids LIKE %?1% and biz_channel = ?2", nativeQuery = true)
List<FundModuleChannelFundConfigNew> getByIds(List<Long> ids); Long count(Long fundId,String bizChannel,List<BigInteger> ids);
@Query(value = "SELECT count(*) FROM fund_module_channel_fund_config_new where id in ?2 and fund_ids LIKE %?1%", nativeQuery = true)
Long count(Long fundId,List<BigInteger> ids);
@Query(value = "SELECT * FROM fund_module_channel_fund_config_new where id in ?1 and fund_ids like %?2% order by field(?1)",nativeQuery = true)
List<FundModuleChannelFundConfigNew> getByIds(List<Long> ids,Long fundId);
} }
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