Commit af94c28d authored by 郑建's avatar 郑建

6.6-2

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