Commit 1dc15f97 authored by 李文彬's avatar 李文彬

Merge branch 'zj-6.6-2' into 'master'

Zj 6.6 2

See merge request !1
parents e31a8859 b1e9c89d
...@@ -20,17 +20,16 @@ import com.alibaba.druid.pool.DruidDataSource; ...@@ -20,17 +20,16 @@ import com.alibaba.druid.pool.DruidDataSource;
*/ */
@Configuration @Configuration
public class DataSourceConfig { public class DataSourceConfig {
@Value("${spring.datasource.primary.url}") @Value("${spring.datasource.primary.url}")
private String dbUrl; private String dbUrl;
@Value("${spring.datasource.primary.username}") @Value("${spring.datasource.primary.username}")
private String username; private String username;
@Value("${spring.datasource.primary.password}") @Value("${spring.datasource.primary.password}")
private String password; private String password;
@Value("${spring.datasource.primary.driver-class-name}") @Value("${spring.datasource.primary.driver-class-name}")
private String driverClassName; private String driverClassName;
@Value("${spring.datasource.initialSize}")
@Value("${spring.datasource.initialSize}")
private int initialSize; private int initialSize;
@Value("${spring.datasource.minIdle}") @Value("${spring.datasource.minIdle}")
private int minIdle; private int minIdle;
......
package com.quantgroup.asset.distribution.controller; package com.quantgroup.asset.distribution.controller;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import com.quantgroup.asset.distribution.model.entity.fund.FundConfigCondition;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -18,6 +22,8 @@ import com.quantgroup.asset.distribution.util.fund.module.ChannelFundConfigUtil; ...@@ -18,6 +22,8 @@ import com.quantgroup.asset.distribution.util.fund.module.ChannelFundConfigUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.persistence.criteria.CriteriaBuilder;
/** /**
* 资方模块Controller * 资方模块Controller
* @author liwenbin * @author liwenbin
...@@ -55,7 +61,7 @@ public class FundModuleController { ...@@ -55,7 +61,7 @@ public class FundModuleController {
@RequestMapping("/get_channel_fund_configs") @RequestMapping("/get_channel_fund_configs")
public GlobalResponse getChannelFundConfigs(String bizChannel, Long fundId, Integer pageNum, Integer pageSize) { public GlobalResponse getChannelFundConfigs(String bizChannel, Long fundId, Integer pageNum, Integer pageSize) {
return getChannelFundsConfigCommon(bizChannel, fundId, pageNum, pageSize, 1); return getChannelFundsConfigCommon(bizChannel, fundId, pageNum, pageSize, 1,null);
} }
@RequestMapping("/get_audit_infos") @RequestMapping("/get_audit_infos")
...@@ -100,8 +106,8 @@ public class FundModuleController { ...@@ -100,8 +106,8 @@ public class FundModuleController {
} }
@RequestMapping("/get_channel_fund_configs_new") @RequestMapping("/get_channel_fund_configs_new")
public GlobalResponse getChannelFundConfigsNew(String bizChannel, Long fundId, Integer pageNum, Integer pageSize) { public GlobalResponse getChannelFundConfigsNew(String bizChannel, Long fundId, Integer pageNum, Integer pageSize,Integer sortMode) {
return getChannelFundsConfigCommon(bizChannel, fundId, pageNum, pageSize, 2); return getChannelFundsConfigCommon(bizChannel, fundId, pageNum, pageSize, 2,sortMode);
} }
@RequestMapping("/find_channel_fund_config_new") @RequestMapping("/find_channel_fund_config_new")
...@@ -109,6 +115,23 @@ public class FundModuleController { ...@@ -109,6 +115,23 @@ public class FundModuleController {
return findChannelFundConfigCommon(configId, 2); return findChannelFundConfigCommon(configId, 2);
} }
@RequestMapping("/simulation/conditions")
public GlobalResponse allConditions(Long configId){
return fundConfigConditions(configId);
}
@RequestMapping("/simulation/result")
public GlobalResponse simulationResult(String configConditions, Long configId){
return simulation(JSON.parseArray(configConditions,FundConfigCondition.class),configId);
}
@RequestMapping("/get_all_channel")
public GlobalResponse getAllConfigingChannels() {
Stopwatch stopwatch = Stopwatch.createStarted();
GlobalResponse response = fundModuleService.getAllConfigChannel();
log.info("资方模块接口, 获取所有已进行资方配置的渠道号结束, response : {}, 耗时 : {}", JSON.toJSONString(response), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
return response;
}
private GlobalResponse saveChannelFundsConfigCommon(Integer type, Long id, String bizChannel, String funds, String remarks, private GlobalResponse saveChannelFundsConfigCommon(Integer type, Long id, String bizChannel, String funds, String remarks,
String auditor, String proposer, int oldOrNew) { String auditor, String proposer, int oldOrNew) {
...@@ -148,7 +171,7 @@ public class FundModuleController { ...@@ -148,7 +171,7 @@ public class FundModuleController {
return response; return response;
} }
private GlobalResponse getChannelFundsConfigCommon(String bizChannel, Long fundId, Integer pageNum, Integer pageSize, int oldOrNew) { private GlobalResponse getChannelFundsConfigCommon(String bizChannel, Long fundId, Integer pageNum, Integer pageSize, int oldOrNew,Integer sortMode) {
log.info("资方模块接口, 查询渠道资方配置信息开始, bizChannel : {}, fundId : {}, pageNum : {}, pageSize : {}", bizChannel, fundId, pageNum, pageSize); log.info("资方模块接口, 查询渠道资方配置信息开始, bizChannel : {}, fundId : {}, pageNum : {}, pageSize : {}", bizChannel, fundId, pageNum, pageSize);
if (pageNum == null || pageSize == null) { if (pageNum == null || pageSize == null) {
return GlobalResponse.create(FundModuleResponse.PAGEING_CONDITIONS_IS_EMPTY); return GlobalResponse.create(FundModuleResponse.PAGEING_CONDITIONS_IS_EMPTY);
...@@ -159,7 +182,7 @@ public class FundModuleController { ...@@ -159,7 +182,7 @@ public class FundModuleController {
// 老接口 // 老接口
response = fundModuleService.getChannelFundConfigs(bizChannel, fundId, pageNum, pageSize); response = fundModuleService.getChannelFundConfigs(bizChannel, fundId, pageNum, pageSize);
} else { } else {
response = fundModuleService.getChannelFundConfigsNew(bizChannel, fundId, pageNum, pageSize); response = fundModuleService.getChannelFundConfigsNew(bizChannel, fundId, pageNum, pageSize,sortMode);
} }
log.info("资方模块接口, 查询渠道资方配置信息结束, bizChannel : {}, fundId : {}, pageNum : {}, pageSize : {}, 耗时 : {}, response : {}", bizChannel, fundId, pageNum, pageSize, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response)); log.info("资方模块接口, 查询渠道资方配置信息结束, bizChannel : {}, fundId : {}, pageNum : {}, pageSize : {}, 耗时 : {}, response : {}", bizChannel, fundId, pageNum, pageSize, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response));
...@@ -182,4 +205,26 @@ public class FundModuleController { ...@@ -182,4 +205,26 @@ public class FundModuleController {
log.info("资方模块接口, 根据id获取资方配置, configId : {} 耗时 : {}, response : {}", configId, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response)); log.info("资方模块接口, 根据id获取资方配置, configId : {} 耗时 : {}, response : {}", configId, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response));
return response; return response;
} }
private GlobalResponse fundConfigConditions(Long configId){
log.info("资方模块接口,根据id获取所有案例, configId : {}", configId);
if (configId == null) {
return GlobalResponse.create(FundModuleResponse.ID_IS_EMPTY);
}
Stopwatch stopwatch = Stopwatch.createStarted();
GlobalResponse response = fundModuleService.getAllConditionsOfFundConfig(configId);
log.info("资方模块接口,根据id获取所有案例, configId : {} 耗时 : {}, response : {}", configId, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response));
return response;
}
private GlobalResponse simulation(List<FundConfigCondition> configConditions,Long configId){
log.info("资方模块接口,根据案例进行空跑, configConditions : {}, configId:{}", configConditions,configId);
if (CollectionUtils.isEmpty(configConditions)) {
return GlobalResponse.create(FundModuleResponse.ID_IS_EMPTY);
}
Stopwatch stopwatch = Stopwatch.createStarted();
GlobalResponse response = fundModuleService.simulationCases(configConditions,configId);
log.info("资方模块接口,根据id获取所有案例, configConditions : {}, configId:{}, 耗时 : {}, response : {}", configConditions, configId,stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response));
return response;
}
} }
...@@ -43,4 +43,8 @@ public enum RuleOperator { ...@@ -43,4 +43,8 @@ public enum RuleOperator {
log.error("枚举不存在,code={}", code); log.error("枚举不存在,code={}", code);
throw new QGException(QGExceptionType.COMMON_ILLEGAL_PARAM); throw new QGException(QGExceptionType.COMMON_ILLEGAL_PARAM);
} }
public String getCode() {
return this.code;
}
} }
package com.quantgroup.asset.distribution.model.entity.fund;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class FundConfigCondition implements Serializable {
private static final long serialVersionUID = 1L;
private String conditionTempId;
private List<Condition> condition;
private Result result;
@Data
public static class Condition{
private String conditionCode;
private String conditionName;
private String conditionValue;
}
@Data
public static class Result{
private Boolean success;
private String fundInfo;
private String message;
}
}
package com.quantgroup.asset.distribution.model.entity.fund;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class FundConfigSimulationVO implements Serializable {
private static final long serialVersionUID = 1L;
private List<FundConfigCondition> conditionsCase;
private List<FundConfigCondition.Condition> conditionsType;
}
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.Map; import java.util.Map;
import com.quantgroup.asset.distribution.enums.funding.AuditTargetEnum; import com.quantgroup.asset.distribution.enums.funding.AuditTargetEnum;
...@@ -41,10 +43,11 @@ public interface IApprovalLogService { ...@@ -41,10 +43,11 @@ 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<BigInteger> getFundConfigIds(String channel);
/** /**
* 审批接口 * 审批接口
* @param id 审批记录id
* @param auditStatus * @param auditStatus
*/ */
public void audit(ApprovalLog approvalLog, Integer auditStatus); public void audit(ApprovalLog approvalLog, Integer auditStatus);
......
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;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.*;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.quantgroup.asset.distribution.service.funding.IFundModuleChannelFundConfigNewService; import com.quantgroup.asset.distribution.service.funding.IFundModuleChannelFundConfigNewService;
import com.quantgroup.asset.distribution.service.jpa.entity.FundModuleChannelFundConfigNew; import com.quantgroup.asset.distribution.service.jpa.entity.FundModuleChannelFundConfigNew;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hibernate.jpa.criteria.predicate.InPredicate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification; 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;
...@@ -108,6 +107,15 @@ public class ApprovalLogServiceImpl implements IApprovalLogService{ ...@@ -108,6 +107,15 @@ public class ApprovalLogServiceImpl implements IApprovalLogService{
return result; return result;
} }
@Override
public List<BigInteger> getFundConfigIds(String channel){
if (StringUtils.isEmpty(channel)){
return approvalLogRepository.findAuditConfigIds();
}else {
return approvalLogRepository.findAuditConfigIds(channel);
}
}
@Transactional(rollbackFor=Exception.class) @Transactional(rollbackFor=Exception.class)
@Override @Override
public void audit(ApprovalLog approvalLog, Integer auditStatus) { public void audit(ApprovalLog approvalLog, Integer auditStatus) {
......
...@@ -4,6 +4,7 @@ import com.quantgroup.asset.distribution.model.response.GlobalResponse; ...@@ -4,6 +4,7 @@ import com.quantgroup.asset.distribution.model.response.GlobalResponse;
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 java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -26,4 +27,8 @@ public interface IFundModuleChannelFundConfigNewService { ...@@ -26,4 +27,8 @@ public interface IFundModuleChannelFundConfigNewService {
public FundModuleChannelFundConfigNew auditPassConfig(Long preId, Long auditId); public FundModuleChannelFundConfigNew auditPassConfig(Long preId, Long auditId);
public void clearChannelFundConfigCache(String bizChannel); public void clearChannelFundConfigCache(String bizChannel);
Map<String,Object> getChannelFundConfigsByChannelOrFundIdOrdered(String bizChannel, Long fundId, Integer pageNum, Integer pageSize);
public List<String> getAllConfigChanels();
} }
package com.quantgroup.asset.distribution.service.funding; package com.quantgroup.asset.distribution.service.funding;
import com.quantgroup.asset.distribution.config.annotation.HandleException;
import com.quantgroup.asset.distribution.model.entity.fund.FundConfigCondition;
import com.quantgroup.asset.distribution.model.response.GlobalResponse; import com.quantgroup.asset.distribution.model.response.GlobalResponse;
import java.util.List;
/** /**
* 资方模块Service * 资方模块Service
* @author liwenbin * @author liwenbin
...@@ -61,7 +65,7 @@ public interface IFundModuleService { ...@@ -61,7 +65,7 @@ public interface IFundModuleService {
* @param pageSize * @param pageSize
* @return * @return
*/ */
public GlobalResponse getChannelFundConfigsNew(String bizChannel, Long fundId, Integer pageNum, Integer pageSize); public GlobalResponse getChannelFundConfigsNew(String bizChannel, Long fundId, Integer pageNum, Integer pageSize,Integer sortMode);
/** /**
* 获取审批列表 * 获取审批列表
...@@ -99,4 +103,14 @@ public interface IFundModuleService { ...@@ -99,4 +103,14 @@ public interface IFundModuleService {
* @return * @return
*/ */
public GlobalResponse audit(Long id, Integer auditStatus); public GlobalResponse audit(Long id, Integer auditStatus);
/**
* 获取所有已进行资方配置的渠道
* @return
*/
public GlobalResponse getAllConfigChannel();
GlobalResponse getAllConditionsOfFundConfig(Long configId);
GlobalResponse simulationCases(List<FundConfigCondition> configConditions,Long configId);
} }
...@@ -8,6 +8,7 @@ import com.quantgroup.asset.distribution.exception.QGExceptionType; ...@@ -8,6 +8,7 @@ import com.quantgroup.asset.distribution.exception.QGExceptionType;
import com.quantgroup.asset.distribution.model.response.GlobalResponse; import com.quantgroup.asset.distribution.model.response.GlobalResponse;
import com.quantgroup.asset.distribution.service.approval.IApprovalLogService; import com.quantgroup.asset.distribution.service.approval.IApprovalLogService;
import com.quantgroup.asset.distribution.service.funding.IFundModuleChannelFundConfigNewService; import com.quantgroup.asset.distribution.service.funding.IFundModuleChannelFundConfigNewService;
import com.quantgroup.asset.distribution.service.jpa.entity.ApprovalLog;
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 com.quantgroup.asset.distribution.service.jpa.repository.IFundModuleChannelFundConfigNewRepository; import com.quantgroup.asset.distribution.service.jpa.repository.IFundModuleChannelFundConfigNewRepository;
...@@ -15,21 +16,28 @@ import com.quantgroup.asset.distribution.util.fund.module.ChannelFundConfigUtil; ...@@ -15,21 +16,28 @@ 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;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification; 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;
/** /**
* @author : Hyuk * @author : Hyuk
...@@ -44,6 +52,8 @@ public class FundModuleChannelFundConfigNewServiceImpl implements IFundModuleCha ...@@ -44,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) {
...@@ -155,6 +165,49 @@ public class FundModuleChannelFundConfigNewServiceImpl implements IFundModuleCha ...@@ -155,6 +165,49 @@ public class FundModuleChannelFundConfigNewServiceImpl implements IFundModuleCha
log.info("渠道资方配置缓存清除, bizChannel : {}", bizChannel); log.info("渠道资方配置缓存清除, bizChannel : {}", bizChannel);
} }
@Override
public Map<String, Object> getChannelFundConfigsByChannelOrFundIdOrdered(String bizChannel, Long fundId, Integer pageNum, Integer pageSize) {
List<BigInteger> ids = approvalLogService.getFundConfigIds(bizChannel);
// 分页条件
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) + "";
}
}
Map<String, Object> result = new HashMap<>();
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;
}
@Override
public List<String> getAllConfigChanels() {
return fundModuleChannelFundConfigNewRepository.getAllBizChannel();
}
/** /**
* 更改配置enable状态 * 更改配置enable状态
* @param id * @param id
......
package com.quantgroup.asset.distribution.service.funding.impl; package com.quantgroup.asset.distribution.service.funding.impl;
import java.util.ArrayList; import java.math.BigDecimal;
import java.util.List; import java.math.RoundingMode;
import java.util.Map; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.quantgroup.asset.distribution.enums.RuleOperator;
import com.quantgroup.asset.distribution.enums.UnionType;
import com.quantgroup.asset.distribution.exception.QGException;
import com.quantgroup.asset.distribution.model.entity.fund.ChannelFundConfigNew;
import com.quantgroup.asset.distribution.model.entity.fund.FundConfigCondition;
import com.quantgroup.asset.distribution.model.entity.fund.FundConfigSimulationVO;
import com.quantgroup.asset.distribution.service.funding.IFundModuleChannelFundConfigNewService; import com.quantgroup.asset.distribution.service.funding.IFundModuleChannelFundConfigNewService;
import com.quantgroup.asset.distribution.service.jpa.entity.FundModuleChannelFundConfigNew; import com.quantgroup.asset.distribution.service.jpa.entity.FundModuleChannelFundConfigNew;
import com.quantgroup.asset.distribution.service.rule.IRuleService;
import com.quantgroup.asset.distribution.service.rule.vo.BaseRuleVO;
import com.quantgroup.asset.distribution.service.rule.vo.IRuleVO;
import com.quantgroup.asset.distribution.service.rule.vo.UnionRuleVO;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.apache.commons.collections.Bag;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.bag.HashBag;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -53,6 +71,8 @@ public class FundModuleServiceImpl implements IFundModuleService{ ...@@ -53,6 +71,8 @@ public class FundModuleServiceImpl implements IFundModuleService{
private IFundModuleChannelFundConfigNewService fundModuleChannelFundConfigNewService; private IFundModuleChannelFundConfigNewService fundModuleChannelFundConfigNewService;
@Autowired @Autowired
private IApprovalLogService approvalLogService; private IApprovalLogService approvalLogService;
@Autowired
private IRuleService ruleService;
@Value("${clotho.url}") @Value("${clotho.url}")
private String clothoURL; private String clothoURL;
...@@ -121,8 +141,13 @@ public class FundModuleServiceImpl implements IFundModuleService{ ...@@ -121,8 +141,13 @@ public class FundModuleServiceImpl implements IFundModuleService{
@HandleException @HandleException
@Override @Override
public GlobalResponse getChannelFundConfigsNew(String bizChannel, Long fundId, Integer pageNum, Integer pageSize) { public GlobalResponse getChannelFundConfigsNew(String bizChannel, Long fundId, Integer pageNum, Integer pageSize,Integer sortMode) {
Map<String, Object> result = fundModuleChannelFundConfigNewService.getChannelFundConfigsByChannelOrFundId(bizChannel, fundId, pageNum, pageSize); Map<String, Object> result;
if (sortMode != null && sortMode == 1){
result = fundModuleChannelFundConfigNewService.getChannelFundConfigsByChannelOrFundIdOrdered(bizChannel, fundId, pageNum, pageSize);
}else{
result = fundModuleChannelFundConfigNewService.getChannelFundConfigsByChannelOrFundId(bizChannel, fundId, pageNum, pageSize);
}
if (result == null || result.size() == 0) { if (result == null || result.size() == 0) {
return GlobalResponse.create(FundModuleResponse.HAS_NO_DATA); return GlobalResponse.create(FundModuleResponse.HAS_NO_DATA);
} }
...@@ -176,4 +201,382 @@ public class FundModuleServiceImpl implements IFundModuleService{ ...@@ -176,4 +201,382 @@ public class FundModuleServiceImpl implements IFundModuleService{
return GlobalResponse.create(FundModuleResponse.UKNOW_AUDIT_STATUS); return GlobalResponse.create(FundModuleResponse.UKNOW_AUDIT_STATUS);
} }
} }
@HandleException
@Override
public GlobalResponse getAllConfigChannel() {
List<String> channels = fundModuleChannelFundConfigNewService.getAllConfigChanels();
if (channels == null) {
channels = Lists.newArrayList();
}
return GlobalResponse.success(channels);
}
@HandleException
@Override
public GlobalResponse getAllConditionsOfFundConfig(Long configId){
FundModuleChannelFundConfigNew config = fundModuleChannelFundConfigNewService.findById(configId);
// 未找到资方渠道配置直接通知
if (config == null) {
return GlobalResponse.error("未找到相关配置");
}
List<ChannelFundConfigNew> fundConfigList = JSONArray.parseArray(config.getFunds(), ChannelFundConfigNew.class);
List<FundModuleLimitTypeConfig> typeConfigs = fundModuleLimitTypeService.getAllLimitType();
Map<String,String> codeToNameMap = new HashMap<>();
for (FundModuleLimitTypeConfig typeConfig : typeConfigs){
codeToNameMap.put(typeConfig.getCode(),typeConfig.getName());
}
List<BaseRuleVO> baseRuleList = new ArrayList<>();
for (ChannelFundConfigNew channelFundConfig : fundConfigList) {
IRuleVO ruleVO = ruleService.getIRuleVo(channelFundConfig.getLimits());
getAllBaseRule(baseRuleList,ruleVO);
}
Map<String,List<String>> keyValueMap = collectValueMap(baseRuleList);
//去掉相同的值 例如 amount>3000 和amount>=3000在生成案例时 3001都可以满足 此时会有两个3001
for (Map.Entry<String,List<String>> entry : keyValueMap.entrySet()){
entry.setValue(new ArrayList<>(new LinkedHashSet<>(entry.getValue())));
}
List<FundConfigCondition> configConditions = createCondition(keyValueMap,codeToNameMap);
FundConfigSimulationVO vo = new FundConfigSimulationVO();
vo.setConditionsCase(configConditions);
List<FundConfigCondition.Condition> type = new ArrayList<>();
for (String key : keyValueMap.keySet()){
FundConfigCondition.Condition condition = new FundConfigCondition.Condition();
condition.setConditionCode(key);
condition.setConditionName(codeToNameMap.get(key));
type.add(condition);
}
vo.setConditionsType(type);
return GlobalResponse.success(vo);
}
@Override
public GlobalResponse simulationCases(List<FundConfigCondition> configConditions,Long configId) {
FundModuleChannelFundConfigNew config = fundModuleChannelFundConfigNewService.findById(configId);
if (config == null) {
return GlobalResponse.error("未找到相关配置");
}
List<ChannelFundConfigNew> fundConfigList = JSONArray.parseArray(config.getFunds(), ChannelFundConfigNew.class);
B:for (FundConfigCondition configCondition : configConditions){
Map<String,Object> data = new HashMap<>();
for (FundConfigCondition.Condition condition : configCondition.getCondition()){
String value = condition.getConditionValue();
Class<?> clazz = getType(value);
if (clazz.isAssignableFrom(BigDecimal.class)){
data.put(condition.getConditionCode(),new BigDecimal(value));
}else{
data.put(condition.getConditionCode(),value);
}
}
// 资方去重, 可能存在多条件同一个资方
Set<String> fundSet = new HashSet<>();
JSONArray fundArray = new JSONArray();
List<String> fundIds = new ArrayList<>();
A:for (ChannelFundConfigNew channelFundConfig : fundConfigList) {
IRuleVO ruleVO = ruleService.getIRuleVo(channelFundConfig.getLimits());
if (ruleVO == null) { throw new QGException(QGExceptionType.CRATE_RULE_VO_ERROR); }
Set<String> params = ruleVO.getParamNames();
for (String key : params) {
if (!data.containsKey(key)) {
continue A;
}
}
if (!ruleVO.valid(data)) {
continue;
}
String key = channelFundConfig.getFundId() + "_" + channelFundConfig.getFundProductId() + "_" + channelFundConfig.getPriority();
if (!fundSet.contains(key)) {
// 创建并增加资方配置
JSONObject fundInfoJSON = new JSONObject();
fundInfoJSON.put("fundId", channelFundConfig.getFundId());
fundInfoJSON.put("fundProductId", channelFundConfig.getFundProductId());
fundInfoJSON.put("priority", channelFundConfig.getPriority());
fundArray.add(fundInfoJSON);
fundSet.add(key);
}
//命中一次增加一条
fundIds.add(channelFundConfig.getFundId().toString());
}
FundConfigCondition.Result result = new FundConfigCondition.Result();
if (CollectionUtils.isEmpty(fundArray)){
result.setSuccess(false);
result.setMessage("不存在输出结果");
configCondition.setResult(result);
continue;
}
QGPreconditions.checkArgument(fundArray.size() != 0, QGExceptionType.NO_FUND_INFO_BEEN_HIT);
// 看命中优先级是否符合要求
if (fundArray.size() > 1){
Bag priBag = new HashBag(fundIds);
List<Integer> priList = new ArrayList<>();
for (int i = 0, len = fundArray.size(); i < len; i++) {
Integer pri = fundArray.getJSONObject(i).getIntValue("priority");
priList.add(pri);
priBag.add(pri);
}
for (Integer pri : priList) {
if (priBag.getCount(pri) > 1) {
result.setSuccess(false);
result.setMessage("多个资方配置存在交集");
configCondition.setResult(result);
continue B;
}
}
}
// 查看是否两个资方ID相同且条件存在交集
Bag bag = new HashBag(fundIds);
boolean hasSameResultTotal = false;
for (String id : fundIds){
if (bag.getCount(id) > 1 ){
hasSameResultTotal = true;
break;
}
}
if (hasSameResultTotal){
result.setSuccess(false);
result.setMessage("同资方存在配置交集");
configCondition.setResult(result);
continue ;
}
result.setSuccess(true);
fundArray = JSONArray.parseArray(JSON.toJSONString(fundArray.stream().sorted(Comparator.comparingInt(o -> ((JSONObject) o).getInteger("priority"))).collect(Collectors.toList())));
String fundProductId = fundArray.getJSONObject(0).getString("fundProductId");
String fundId = fundArray.getJSONObject(0).getString("fundId");
result.setFundInfo(("null".equals(fundProductId) || StringUtils.isEmpty(fundProductId))?fundId:fundId+"_"+fundProductId);
configCondition.setResult(result);
}
FundConfigSimulationVO vo = new FundConfigSimulationVO();
vo.setConditionsCase(configConditions);
return GlobalResponse.success(vo);
}
private static void getAllBaseRule(List<BaseRuleVO> ruleVOList,IRuleVO ruleVO){
if (ruleVO.getClass().isAssignableFrom(UnionRuleVO.class)){
UnionRuleVO uRuleVo = (UnionRuleVO)ruleVO;
ruleVOList.addAll(uRuleVo.getBaseRules());
if (CollectionUtils.isNotEmpty(uRuleVo.getUnionRules())){
for (UnionRuleVO vo : uRuleVo.getUnionRules()){
getAllBaseRule(ruleVOList,vo);
}
}
}else {
ruleVOList.add((BaseRuleVO)ruleVO);
}
}
private static List<String> createValue(String operator,String value){
List<String> list = new ArrayList<>();
switch (RuleOperator.fromCode(operator)) {
case Equal:
case NotEqual:
list.add(getValue(RuleOperator.Equal.getCode(),value));
list.add(getValue(RuleOperator.NotEqual.getCode(),value));
return list;
case In:
case NotIn:
list.add(getValue(RuleOperator.In.getCode(),value));
list.add(getValue(RuleOperator.NotIn.getCode(),value));
return list;
case LessThan:
case GreaterThanOrEqual:
list.add(getValue(RuleOperator.LessThan.getCode(),value));
list.add(getValue(RuleOperator.GreaterThanOrEqual.getCode(),value));
return list;
case GreaterThan:
case LessThanOrEqual:
list.add(getValue(RuleOperator.GreaterThan.getCode(),value));
list.add(getValue(RuleOperator.LessThanOrEqual.getCode(),value));
return list;
default:
throw new QGException(QGExceptionType.RULE_OPERATOR_NOT_EXIST);
}
}
/**
* 根据操作符和值生成新值 exp. > 3000 生成 3001 not in {9,10} 生成 8
* @param operator 操作符 参照 {@link RuleOperator}
* @param value 参与对比的值 若返回结果为x 则 x满足 x operator value
* @return 参照上述x
* @auth jian.zheng
* @update 2020-4-10 11:35:38
* @updatedBy jian.zheng
*/
private static String getValue(String operator,String value){
Class<?> clazz = getType(value);
switch (RuleOperator.fromCode(operator)) {
case Equal:
case LessThanOrEqual:
case GreaterThanOrEqual:
return value;
case NotEqual:
if (clazz.isAssignableFrom(BigDecimal.class)) {
return new BigDecimal(value).add(new BigDecimal(1)).toString();
}else if (clazz.isAssignableFrom(Boolean.class)){
return Boolean.toString(!Boolean.parseBoolean(value));
}else {
if (RandomUtils.nextInt(0,10) <5){
if ("a".equals(value) || "A".equals(value)){
return getValue(">",value);
}else {
return getValue("<",value);
}
}else {
if ("z".equals(value) || "Z".equals(value)){
return getValue("<",value);
}else {
return getValue(">",value);
}
}
}
case In:
if (value.contains(",")){
List<String> list = Arrays.asList(value.split(","));
return list.get(RandomUtils.nextInt(0,list.size()-1));
}else {
return value;
}
case NotIn:
if (value.contains(",")){
List<String> list = Arrays.asList(value.split(","));
String start = getValue(operator,list.get(0));
while (list.contains(start)){
start = getValue("!=",start);
}
return start;
}else {
return getValue("!=",value);
}
case LessThan:
if (BigDecimal.class.isAssignableFrom(clazz)){
if (new BigDecimal(value).doubleValue() < 1 && new BigDecimal(value).doubleValue() > 0){
return new BigDecimal(value).divide(new BigDecimal(10),value.split(".")[1].length(), RoundingMode.HALF_UP).toString();
}else {
return new BigDecimal(value).subtract(new BigDecimal(1)).toString();
}
}else if (String.class.isAssignableFrom(clazz)){
if (value.length() == 1){
if ("a".equals(value) || "A".equals(value)){
return value + "-1";
}else {
return String.valueOf((char) (value.charAt(0) - 1));
}
}else {
String front = value.substring(0,value.length() - 1);
String last = String.valueOf(value.charAt(value.length() -1));
String newLast = getValue("<",last);
return front + newLast;
}
}
case GreaterThan:
if (BigDecimal.class.isAssignableFrom(clazz)){
return new BigDecimal(value).add(new BigDecimal(1)).toString();
}else if (String.class.isAssignableFrom(clazz)){
if (value.length() == 1){
if ("z".equals(value) || "Z".equals(value)){
return value + "+1";
}else {
return String.valueOf((char) (value.charAt(0) + 1));
}
}else {
String front = value.substring(0,value.length() - 1);
String last = String.valueOf(value.charAt(value.length() + 1));
String newLast = getValue(">",last);
return front + newLast;
}
}
default:
throw new QGException(QGExceptionType.RULE_OPERATOR_NOT_EXIST);
}
}
public static void main(String[] args) {
System.out.println(getValue(">=","3000"));
System.out.println(getValue("<=","3000"));
}
private static Class<?> getType(String value){
if (StringUtils.isNumeric(value)){
return BigDecimal.class;
}
if ("true".equals(value) || "false".equals(value)){
return Boolean.class;
}
return String.class;
}
private static Map<String,List<String>> collectValueMap(List<BaseRuleVO> vos){
Map<String,List<String>> keyValueMap = new HashMap<>();
for (BaseRuleVO vo : vos){
if (keyValueMap.containsKey(vo.getKey())){
keyValueMap.get(vo.getKey()).addAll(createValue(vo.getOperator(),vo.getValue()));
}else {
keyValueMap.put(vo.getKey(),new ArrayList<>(createValue(vo.getOperator(),vo.getValue())));
}
}
return keyValueMap;
}
/**
* 对map中的每个key的list做笛卡儿积
* @param map
* @return
*/
private static List<FundConfigCondition> createCondition(Map<String,List<String>> map,Map<String,String> codeToNameMap){
List<FundConfigCondition> configConditions = new ArrayList<>();
List<String> keyList = new ArrayList<>(map.keySet());
List<List<String>> dimensionValue = new ArrayList<>();
for (String key:keyList){
dimensionValue.add(map.get(key));
}
List<List<String>> results = new ArrayList<>();
descartes(dimensionValue,results,0,new ArrayList<>());
for (int i = 0;i<results.size();i++){
FundConfigCondition configCondition = new FundConfigCondition();
List<FundConfigCondition.Condition> conditions = new ArrayList<>();
for (int j = 0;j<results.get(i).size();j++){
FundConfigCondition.Condition condition = new FundConfigCondition.Condition();
condition.setConditionCode(keyList.get(j));
condition.setConditionValue(results.get(i).get(j));
condition.setConditionName(codeToNameMap.get(keyList.get(j)));
conditions.add(condition);
}
configCondition.setConditionTempId(String.valueOf(i));
configCondition.setCondition(conditions);
configConditions.add(configCondition);
}
return configConditions;
}
/**
* 笛卡尔积演算
* @param dimensionValue
* @param result
* @param layer
* @param currentList
* @param <T>
*/
private static <T> void descartes(List<List<T>> dimensionValue, List<List<T>> result, int layer, List<T> currentList) {
if (layer < dimensionValue.size() - 1) {
if (dimensionValue.get(layer).size() == 0) {
descartes(dimensionValue, result, layer + 1, currentList);
} else {
for (int i = 0; i < dimensionValue.get(layer).size(); i++) {
List<T> list = new ArrayList<>(currentList);
list.add(dimensionValue.get(layer).get(i));
descartes(dimensionValue, result, layer + 1, list);
}
}
} else if (layer == dimensionValue.size() - 1) {
if (dimensionValue.get(layer).size() == 0) {
result.add(currentList);
} else {
for (int i = 0; i < dimensionValue.get(layer).size(); i++) {
List<T> list = new ArrayList<>(currentList);
list.add(dimensionValue.get(layer).get(i));
result.add(list);
}
}
}
}
} }
...@@ -4,6 +4,10 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -4,6 +4,10 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 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 java.math.BigInteger;
import java.util.List;
public interface IApprovalLogRepository extends JpaRepository<ApprovalLog, Long>, JpaSpecificationExecutor<ApprovalLog>{ public interface IApprovalLogRepository extends JpaRepository<ApprovalLog, Long>, JpaSpecificationExecutor<ApprovalLog>{
...@@ -13,4 +17,10 @@ public interface IApprovalLogRepository extends JpaRepository<ApprovalLog, Long ...@@ -13,4 +17,10 @@ public interface IApprovalLogRepository extends JpaRepository<ApprovalLog, Long
Integer auditTarget, Integer auditTarget,
String targetName, String targetName,
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)
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<BigInteger> findAuditConfigIds();
} }
...@@ -2,9 +2,14 @@ package com.quantgroup.asset.distribution.service.jpa.repository; ...@@ -2,9 +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 java.math.BigInteger;
import java.util.List; import java.util.List;
/** /**
...@@ -35,4 +40,13 @@ public interface IFundModuleChannelFundConfigNewRepository extends JpaRepository ...@@ -35,4 +40,13 @@ public interface IFundModuleChannelFundConfigNewRepository extends JpaRepository
*/ */
public FundModuleChannelFundConfigNew findById(Long id); public FundModuleChannelFundConfigNew findById(Long id);
@Query(value = "select biz_channel from fund_module_channel_fund_config_new where enable = 1", nativeQuery = true)
public List<String> getAllBizChannel();
@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);
} }
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