Commit 9c9827c0 authored by liwenbin's avatar liwenbin

资方审批需求

parent 38741c97
......@@ -74,17 +74,17 @@ public class ConsumerConfig implements RabbitListenerConfigurer {
// || FundingResult.HANG_UP.getCode().equals(noticeType)
|| FundingResult.CANCEL_LOAN.getCode().equals(noticeType)
|| FundingResult.FUAD_ASSIGN_SUCC.getCode().equals(noticeType)){
log.info("助贷资金路由有效MQ消息接收, 消息内容 : {} ",ms);
log.info("资金路由有效MQ消息接收, 消息内容 : {} ",ms);
String applyNo = jo.getJSONObject("data").getString("applyNo");
iAidFundRouteRecordService.fundingResultNotity(applyNo,FundingResult.fromCode(noticeType));
distributeService.receiveFundingResult(applyNo, FundingResult.fromCode(noticeType));
log.info("助贷资金路由有效MQ消息处理结束, bizNo : {} ,noticeType : {} , 耗时 : {} ",applyNo,noticeType,stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
log.info("资金路由有效MQ消息处理结束, bizNo : {} ,noticeType : {} , 耗时 : {} ",applyNo,noticeType,stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
// 采用手动应答模式, 手动确认应答更为安全稳定
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
}catch(IOException e){
log.error("助贷资金路由结果消息处理异常,消息 : {} ",ms,e);
log.error("资金路由结果消息处理异常,消息 : {} ",ms,e);
//害怕队列堵住 暂放开
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
......
......@@ -12,6 +12,7 @@ import com.google.common.base.Stopwatch;
import com.quantgroup.asset.distribution.constant.FundModuleConstants;
import com.quantgroup.asset.distribution.enums.response.FundModuleResponse;
import com.quantgroup.asset.distribution.model.response.GlobalResponse;
import com.quantgroup.asset.distribution.service.approval.IApprovalLogService;
import com.quantgroup.asset.distribution.service.funding.IFundModuleService;
import com.quantgroup.asset.distribution.util.fund.module.ChannelFundConfigUtil;
......@@ -29,6 +30,8 @@ public class FundModuleController {
@Autowired
private IFundModuleService fundModuleService;
@Autowired
private IApprovalLogService approvalLogService;
@RequestMapping("/get_all_funds")
public GlobalResponse getAllFunds() {
......@@ -42,12 +45,13 @@ public class FundModuleController {
public GlobalResponse getAllLimitInfo() {
Stopwatch stopwatch = Stopwatch.createStarted();
GlobalResponse response = fundModuleService.getAllLimitType();
log.info("资方模块接口, 获取所有条件限制类型完成, 耗时 : {}, response : {}", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), response);
log.info("资方模块接口, 获取所有条件限制类型完成, 耗时 : {}, response : {}", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response));
return response;
}
@RequestMapping("save_channel_funds_config")
public GlobalResponse saveChannelFundsConfig(Integer type, Long id, String bizChannel, String funds, String remarks) {
public GlobalResponse saveChannelFundsConfig(Integer type, Long id, String bizChannel, String funds, String remarks,
String auditor, String proposer) {
log.info("资方模块接口, 新增或修改资方配置开始, type : {}, id : {}, bizChannel : {}, funds : {}, remarks : {}", type, id, bizChannel, funds, remarks);
// 参数校验
if (type == null) {
......@@ -68,10 +72,13 @@ public class FundModuleController {
if (!ChannelFundConfigUtil.checkFunds(funds)) {
return GlobalResponse.create(FundModuleResponse.FUNDS_INFO_ERROR);
}
if (StringUtils.isEmpty(auditor) || StringUtils.isEmpty(proposer)) {
return GlobalResponse.create(FundModuleResponse.AUDITOR_OR_PROPOSER_IS_EMPTY);
}
Stopwatch stopwatch = Stopwatch.createStarted();
GlobalResponse response = fundModuleService.saveChannelFundConfig(type, id, bizChannel, funds, remarks);
log.info("资方模块接口, 新增或修改资方配置结束, type : {}, id : {}, bizChannel : {}, funds : {}, remarks : {}, 耗时 : {}, reponse : {}", type, id, bizChannel, funds, remarks, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), response);
return response;
GlobalResponse response = fundModuleService.saveChannelFundConfig(type, id, bizChannel, funds, remarks, auditor, proposer);
log.info("资方模块接口, 新增或修改资方配置结束, type : {}, id : {}, bizChannel : {}, funds : {}, remarks : {}, 耗时 : {}, reponse : {}", type, id, bizChannel, funds, remarks, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response));
return null;
}
@RequestMapping("/get_channel_fund_configs")
......@@ -82,7 +89,49 @@ public class FundModuleController {
}
Stopwatch stopwatch = Stopwatch.createStarted();
GlobalResponse response = fundModuleService.getChannelFundConfigs(bizChannel, fundId, pageNum, pageSize);
log.info("资方模块接口, 查询渠道资方配置信息结束, bizChannel : {}, fundId : {}, pageNum : {}, pageSize : {}, 耗时 : {}, response : {}", bizChannel, fundId, pageNum, pageSize, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), response);
log.info("资方模块接口, 查询渠道资方配置信息结束, bizChannel : {}, fundId : {}, pageNum : {}, pageSize : {}, 耗时 : {}, response : {}", bizChannel, fundId, pageNum, pageSize, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response));
return response;
}
@RequestMapping("/get_audit_infos")
public GlobalResponse getAuditInfos(String targetName, Integer auditStatus, Integer auditType, Integer auditTarget, String applyStartTime, String applyEndTime, String user, Integer pageNum, Integer pageSize) {
log.info("资方模块接口, 获取审批列表开始, targetName : {}, auditStatus : {}, auditType : {}, auditTarget : {}, applyStartTime : {}, applyEndTime : {}, user : {}, pageNum : {}, pageSize : {}", targetName, auditStatus, auditType, auditTarget, applyStartTime, applyEndTime, user, pageNum, pageSize);
if (pageNum == null || pageSize == null) {
return GlobalResponse.create(FundModuleResponse.PAGEING_CONDITIONS_IS_EMPTY);
}
if (StringUtils.isEmpty(user)) {
return GlobalResponse.create(FundModuleResponse.USER_IS_EMPTY);
}
Stopwatch stopwatch = Stopwatch.createStarted();
GlobalResponse response = fundModuleService.getAuditInfos(targetName, auditStatus, auditType, auditTarget, applyStartTime, applyEndTime, user, pageNum, pageSize);
log.info("资方模块接口, 获取审批列表结束, targetName : {}, auditStatus : {}, auditType : {}, auditTarget : {}, applyStartTime : {}, applyEndTime : {}, user : {}, pageNum : {}, pageSize : {}, 耗时 : {}, response : {}", targetName, auditStatus, auditType, auditTarget, applyStartTime, applyEndTime, user, pageNum, pageSize, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response));
return response;
}
@RequestMapping("/find_channel_fund_config")
public GlobalResponse findChannelFundConfig(Long configId) {
log.info("资方模块接口,根据id获取资方配置, configId : {}", configId);
if (configId == null) {
return GlobalResponse.create(FundModuleResponse.ID_IS_EMPTY);
}
Stopwatch stopwatch = Stopwatch.createStarted();
GlobalResponse response = fundModuleService.findChannelFundConfigById(configId);
log.info("资方模块接口, 根据id获取资方配置, configId : {} 耗时 : {}, response : {}", configId, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response));
return response;
}
@RequestMapping("/audit")
public GlobalResponse audit(Long id, Integer auditStatus) {
log.info("资方模块接口,审批执行开始, id : {}, auditStatus : {}", id, auditStatus);
if (id == null) {
return GlobalResponse.create(FundModuleResponse.ID_IS_EMPTY);
}
if (auditStatus == null) {
return GlobalResponse.create(FundModuleResponse.AUDIT_STATUS_IS_EMPTY);
}
Stopwatch stopwatch = Stopwatch.createStarted();
GlobalResponse response = fundModuleService.audit(id, auditStatus);
log.info("资方模块接口,审批执行开始, id : {}, auditStatus : {}, 耗时 : {}, response : {}", id, auditStatus, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), JSON.toJSONString(response));
return response;
}
}
package com.quantgroup.asset.distribution.enums.funding;
import java.util.HashSet;
import java.util.Set;
import lombok.Getter;
/**
* 审批状态枚举
* @author liwenbin
*
*/
public enum AuditStatusEnum {
WAIT(0, "待处理"),
PASS(1, "审批通过"),
REJECT(2, "审批拒绝"),
BACK(3, "撤销");
@Getter
private int code;
@Getter
private String title;
private static final Set<Integer> codeSet = new HashSet<>();
static {
for (AuditStatusEnum auditStatus : AuditStatusEnum.values()) {
codeSet.add(auditStatus.getCode());
}
}
AuditStatusEnum(int code, String title) {
this.code = code;
this.title = title;
}
public static boolean containsCode(int code) {
if (codeSet.contains(code)) {
return true;
} else {
return false;
}
}
}
package com.quantgroup.asset.distribution.enums.funding;
import lombok.Getter;
/**
* 审批对象枚举
* @author liwenbin
*
*/
public enum AuditTargetEnum {
FUND_CONFIG(1, "资金方配置");
@Getter
private int code;
@Getter
private String title;
AuditTargetEnum(int code, String title) {
this.code = code;
this.title = title;
}
}
package com.quantgroup.asset.distribution.enums.funding;
import lombok.Getter;
/**
* 申请类型枚举
* @author liwenbin
*
*/
public enum AuditTypeEnum {
ONLINE(1, "上线");
@Getter
private int code;
@Getter
private String title;
AuditTypeEnum(int code, String title) {
this.code = code;
this.title = title;
}
}
......@@ -19,7 +19,12 @@ public enum FundModuleResponse implements GlobalResponseEnum{
CHANNEL_FUND_CONFIG_IS_EXIST(4007, "渠道资方配置已存在, 添加失败!"),
CHANNEL_FUND_CONFIG_NOT_EXIST(4008, "渠道资方配置修改失败, id不存在!"),
PAGEING_CONDITIONS_IS_EMPTY(4009, "分页条件不能为空"),
HAS_NO_DATA(4010, "未找到数据");
HAS_NO_DATA(4010, "未找到数据"),
AUDITOR_OR_PROPOSER_IS_EMPTY(4011, "申请人或审批人为空, 请检查!"),
USER_IS_EMPTY(4012, "用户信息为空"),
AUDIT_STATUS_IS_EMPTY(4013, "审批状态为空!"),
UKNOW_AUDIT_STATUS(4014, "未知的审批状态"),
CHANNEL_FUND_CONFIG_IS_AUDITING(4015, "该渠道资方配置正在审核中,不允许修改!");
@Getter
private int code;
......
package com.quantgroup.asset.distribution.service.approval;
import java.util.Map;
import com.quantgroup.asset.distribution.enums.funding.AuditTargetEnum;
import com.quantgroup.asset.distribution.enums.funding.AuditTypeEnum;
import com.quantgroup.asset.distribution.service.jpa.entity.ApprovalLog;
/**
*
* @author liwenbin
*
*/
public interface IApprovalLogService {
/**
* 创建审批记录
* @param auditType
* @param auditTarget
* @param targetName
* @param proposer
* @param auditor
* @param preConfigId
* @param auditConfigId
*/
public void createApprovalLog(AuditTypeEnum auditType, AuditTargetEnum auditTarget, String targetName,
String proposer, String auditor, Long preConfigId, Long auditConfigId);
/**
* 获取审批记录
* @param targetName
* @param auditStatus
* @param auditType
* @param auditTarget
* @param applyStartTime
* @param applyEndTime
* @param user
* @param pageNum
* @param pageSize
* @return
*/
public Map<String, Object> getApprovalLogs(String targetName, Integer auditStatus, Integer auditType, Integer auditTarget,
String applyStartTime, String applyEndTime, String user, Integer pageNum, Integer pageSize);
/**
* 审批接口
* @param id 审批记录id
* @param auditStatus
*/
public void audit(ApprovalLog approvalLog, Integer auditStatus);
/**
* 根据id获取审批记录
* @param id
* @return
*/
public ApprovalLog findById(Long id);
/**
* 查询该条配置是否正在审批
* @param channelFundConfigId
* @return
*/
public Boolean isAuditing(Long channelFundConfigId);
}
package com.quantgroup.asset.distribution.service.approval.impl;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.quantgroup.asset.distribution.enums.funding.AuditStatusEnum;
import com.quantgroup.asset.distribution.enums.funding.AuditTargetEnum;
import com.quantgroup.asset.distribution.enums.funding.AuditTypeEnum;
import com.quantgroup.asset.distribution.service.approval.IApprovalLogService;
import com.quantgroup.asset.distribution.service.funding.IFundModuleChannelFundConfigService;
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.repository.IApprovalLogRepository;
import com.quantgroup.asset.distribution.util.DateUtil;
@Service
public class ApprovalLogServiceImpl implements IApprovalLogService{
@Autowired
private IApprovalLogRepository approvalLogRepository;
@Autowired
private IFundModuleChannelFundConfigService fundModuleChannelFundConfigService;
@Override
public void createApprovalLog(AuditTypeEnum auditType, AuditTargetEnum auditTarget, String targetName,
String proposer, String auditor, Long preConfigId, Long auditConfigId) {
ApprovalLog approvalLog = new ApprovalLog();
approvalLog.setAuditType(auditType.getCode());
approvalLog.setAuditTarget(auditTarget.getCode());
approvalLog.setTargetName(targetName);
approvalLog.setProposer(proposer);
approvalLog.setApplyTime(new Timestamp(System.currentTimeMillis()));
approvalLog.setAuditor(auditor);
approvalLog.setAuditStatus(AuditStatusEnum.WAIT.getCode());
approvalLog.setPreConfigId(preConfigId);
approvalLog.setAuditConfigId(auditConfigId);
approvalLog.setEnable(true);
approvalLogRepository.save(approvalLog);
}
@Override
public Map<String, Object> getApprovalLogs(String targetName, Integer auditStatus, Integer auditType,
Integer auditTarget, String applyStartTime, String applyEndTime, String user, Integer pageNum,
Integer pageSize) {
// 分页条件
Pageable pageable = new PageRequest(pageNum < 0 ? 0 : pageNum, pageSize);
Specification<ApprovalLog> specification = new Specification<ApprovalLog>() {
@Override
public Predicate toPredicate(Root<ApprovalLog> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicatesAnd = new ArrayList<>();
List<Predicate> predicatesOr = new ArrayList<>();
predicatesAnd.add(cb.equal(root.get("enable"), true));
if(auditStatus != null){
predicatesAnd.add(cb.equal(root.get("auditStatus"), auditStatus));
}
if(auditType != null){
predicatesAnd.add(cb.equal(root.get("auditType"), auditType));
}
if(auditTarget != null){
predicatesAnd.add(cb.equal(root.get("auditTarget"), auditTarget));
}
if(StringUtils.isNotEmpty(applyStartTime)){
predicatesAnd.add(cb.greaterThanOrEqualTo(root.get("applyTime").as(Timestamp.class), Timestamp.valueOf(applyStartTime)));
}
if(StringUtils.isNotEmpty(applyEndTime)){
predicatesAnd.add(cb.lessThan(root.get("applyTime").as(Timestamp.class), Timestamp.valueOf(applyEndTime)));
}
if(StringUtils.isNotEmpty(targetName)){
predicatesAnd.add(cb.like(root.get("targetName"), "%" + targetName + "%"));
}
if (StringUtils.isNotEmpty(user)) {
predicatesOr.add(cb.equal(root.get("proposer"), user));
predicatesOr.add(cb.equal(root.get("auditor"), user));
}
List<Order> orderList = new ArrayList<>();
orderList.add(cb.asc(root.get("auditStatus")));
return query.where(cb.and(predicatesAnd.toArray(new Predicate[predicatesAnd.size()])), cb.or(predicatesOr.toArray(new Predicate[predicatesOr.size()])))
.orderBy(orderList).getRestriction();
}
};
Page<ApprovalLog> channelFundConfigs = approvalLogRepository.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());
return result;
}
@Transactional(rollbackFor=Exception.class)
@Override
public void audit(ApprovalLog approvalLog, Integer auditStatus) {
if (auditStatus == AuditStatusEnum.PASS.getCode()) {
// 先更改审核记录, 这里返回的是新配置
FundModuleChannelFundConfig config = fundModuleChannelFundConfigService.auditPassConfig(approvalLog.getPreConfigId(), approvalLog.getAuditConfigId());
// 根据新配置清楚渠道缓存
fundModuleChannelFundConfigService.clearChannelFundConfigCache(config.getBizChannel());
}
updateApprovalLogAuditStatus(approvalLog, auditStatus);
}
@Override
public ApprovalLog findById(Long id) {
return approvalLogRepository.findByIdAndEnableIsTrue(id);
}
/**
* 更改审批记录状态和审批时间
* @param approvalLog
* @param s
*/
private void updateApprovalLogAuditStatus(ApprovalLog approvalLog, Integer auditStatus) {
approvalLog.setAuditTime(DateUtil.getCurDateTime());
approvalLog.setAuditStatus(auditStatus);
approvalLogRepository.save(approvalLog);
}
@Override
public Boolean isAuditing(Long channelFundConfigId) {
return approvalLogRepository.findByPreConfigIdAndAuditStatus(channelFundConfigId, AuditStatusEnum.WAIT.getCode()) != null;
}
}
......@@ -251,8 +251,6 @@ public class AssetServiceImpl implements IAssetService{
}
}
}
log.info("资方模块用户命中资方条件, uuid : {}, assetNo : {}, bizNo : {}, fundId : {}, fundProductId : {}",
assetForm.getUuid(), assetForm.getAssetNo(), assetForm.getBizNo(), channelFundConfig.getFundId(), channelFundConfig.getFundProductId());
// 创建并增加资方配置
JSONObject fundInfoJSON = new JSONObject();
fundInfoJSON.put("fundId", channelFundConfig.getFundId());
......@@ -262,6 +260,8 @@ public class AssetServiceImpl implements IAssetService{
fundInfoJSON.put("rateType", channelFundConfig.getRateType());
fundInfoJSON.put("rate", channelFundConfig.getRate());
fundArray.add(fundInfoJSON);
log.info("资方模块用户命中资方条件, uuid : {}, assetNo : {}, bizNo : {}, bizChannel : {}, fundId : {}, fundProductId : {}",
assetForm.getUuid(), assetForm.getAssetNo(), assetForm.getBizNo(), assetForm.getBizChannel(), channelFundConfig.getFundId(), channelFundConfig.getFundProductId());
}
// 如果fundArray为空,未命中任何一个资方
QGPreconditions.checkArgument(fundArray.size() != 0, QGExceptionType.NO_FUND_INFO_BEEN_HIT, assetForm.getBizChannel(), assetForm.getAmount(), assetForm.getTerm());
......@@ -279,7 +279,7 @@ public class AssetServiceImpl implements IAssetService{
bucket[priority] = true;
}
String hitFinanceProduct = JSON.toJSONString(financeProductArray);
log.info("资方模块组成金融产品集完成, uuid : {}, assetNo : {}, bizNo : {}, financeProduct : {}", assetForm.getUuid(), assetForm.getAssetNo(), assetForm.getBizNo(), hitFinanceProduct);
log.info("资方模块组成金融产品集完成, uuid : {}, assetNo : {}, bizNo : {}, bizChannel : {}, financeProduct : {}", assetForm.getUuid(), assetForm.getAssetNo(), assetForm.getBizNo(), assetForm.getBizChannel(), hitFinanceProduct);
// 如果金融产品集为空, 那就用hit的, 保证流程不会出错,并且没有比较
if (StringUtils.isEmpty(assetForm.getFinanceProducts())) {
// 装填金融产品集并返回
......@@ -294,5 +294,4 @@ public class AssetServiceImpl implements IAssetService{
financeProductHitLogService.saveLog(assetForm, oldFinanceProduct, hitFinanceProduct);
}
}
}
......@@ -14,9 +14,15 @@ public interface IFundModuleChannelFundConfigService {
public Map<String, Object> getChannelFundConfigsByChannelOrFundId(String bizChannel, Long fundId, Integer pageNum, Integer pageSize);
public GlobalResponse addChannelFundConfig(String bizChannel, String funds, String remarks);
public GlobalResponse addChannelFundConfig(String bizChannel, String funds, String remarks, String proposer, String auditor);
public GlobalResponse updateChannelFundConfig(Long id, String bizChannel, String funds, String remarks);
public GlobalResponse updateChannelFundConfig(Long id, String bizChannel, String funds, String remarks, String proposer, String auditor);
public FundModuleChannelFundConfig findByBizChannel(String bizChannel);
public FundModuleChannelFundConfig findById(Long id);
public FundModuleChannelFundConfig auditPassConfig(Long preId, Long auditId);
public void clearChannelFundConfigCache(String bizChannel);
}
......@@ -25,7 +25,8 @@ public interface IFundModuleService {
* 保存或更改渠道资方配置
* @return
*/
public GlobalResponse saveChannelFundConfig(Integer type, Long id, String bizChannel, String funds, String remarks);
public GlobalResponse saveChannelFundConfig(Integer type, Long id, String bizChannel, String funds, String remarks,
String auditor, String proposer);
/**
* 获取渠道资方配置信息
......@@ -36,4 +37,34 @@ public interface IFundModuleService {
* @return
*/
public GlobalResponse getChannelFundConfigs(String bizChannel, Long fundId, Integer pageNum, Integer pageSize);
/**
* 获取审批列表
* @param targetName
* @param auditStatus
* @param auditType
* @param auditTarget
* @param applyStartTime
* @param applyEndTime
* @param user
* @param pageNum
* @param pageSize
* @return
*/
public GlobalResponse getAuditInfos(String targetName, Integer auditStatus, Integer auditType, Integer auditTarget, String applyStartTime, String applyEndTime, String user, Integer pageNum, Integer pageSize);
/**
* 根据Id获取资方配置
* @param configId
* @return
*/
public GlobalResponse findChannelFundConfigById(Long configId);
/**
* 审批接口
* @param id 审理log id
* @param auditStatus
* @return
*/
public GlobalResponse audit(Long id, Integer auditStatus);
}
......@@ -19,9 +19,13 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.quantgroup.asset.distribution.enums.funding.AuditTargetEnum;
import com.quantgroup.asset.distribution.enums.funding.AuditTypeEnum;
import com.quantgroup.asset.distribution.enums.response.FundModuleResponse;
import com.quantgroup.asset.distribution.model.response.GlobalResponse;
import com.quantgroup.asset.distribution.service.approval.IApprovalLogService;
import com.quantgroup.asset.distribution.service.funding.IFundModuleChannelFundConfigService;
import com.quantgroup.asset.distribution.service.jpa.entity.FundModuleChannelFundConfig;
import com.quantgroup.asset.distribution.service.jpa.repository.IFundModuleChannelFundConfigRepository;
......@@ -35,6 +39,8 @@ public class FundModuleChannelFundConfigServiceImpl implements IFundModuleChanne
@Autowired
private IFundModuleChannelFundConfigRepository fundModuleChannelFundConfigRepository;
@Autowired
private IApprovalLogService approvalLogService;
/**
* 分页使用
......@@ -69,42 +75,38 @@ public class FundModuleChannelFundConfigServiceImpl implements IFundModuleChanne
return result;
}
@CacheEvict(value = "cacheManager", key="'ASSET_DISTRIBUTION:FUND_MODULE:CHANNEL_FUND_CONFIG:AC8A_'+#bizChannel")
// @CacheEvict(value = "cacheManager", key="'ASSET_DISTRIBUTION:FUND_MODULE:CHANNEL_FUND_CONFIG:AC8A_'+#bizChannel")
@Transactional(rollbackFor=Exception.class)
@Override
public GlobalResponse addChannelFundConfig(String bizChannel, String funds, String remarks) {
public GlobalResponse addChannelFundConfig(String bizChannel, String funds, String remarks, String proposer, String auditor) {
// 新增配置, 根据渠道查询如果库里已存在,返回异常;
FundModuleChannelFundConfig fundModuleChannelFundConfig = fundModuleChannelFundConfigRepository.findByBizChannelAndEnableIsTrue(bizChannel);
if (fundModuleChannelFundConfig != null) {
log.info("资方模块, 渠道 : {}资方配置已存在, 添加失败!", bizChannel);
return GlobalResponse.create(FundModuleResponse.CHANNEL_FUND_CONFIG_IS_EXIST);
}
fundModuleChannelFundConfig = new FundModuleChannelFundConfig();
fundModuleChannelFundConfig.setBizChannel(bizChannel);
fundModuleChannelFundConfig.setFunds(funds);
fundModuleChannelFundConfig.setRemarks(remarks);
fundModuleChannelFundConfig.setFundIds(ChannelFundConfigUtil.getAllFundIds(funds));
// 默认测试
fundModuleChannelFundConfig.setType(0);
fundModuleChannelFundConfig.setEnable(true);
fundModuleChannelFundConfigRepository.save(fundModuleChannelFundConfig);
FundModuleChannelFundConfig newConfig = fundModuleChannelFundConfig = createdNewChannelFundConfig(bizChannel, funds, remarks);
createdChannelFundConfigApprovalLog(bizChannel, proposer, auditor, null, newConfig.getId());
return GlobalResponse.create(FundModuleResponse.SUCCESS);
}
@CacheEvict(value = "cacheManager", key="'ASSET_DISTRIBUTION:FUND_MODULE:CHANNEL_FUND_CONFIG:AC8A_'+#bizChannel")
@Transactional(rollbackFor=Exception.class)
@Override
public GlobalResponse updateChannelFundConfig(Long id, String bizChannel, String funds, String remarks) {
public GlobalResponse updateChannelFundConfig(Long id, String bizChannel, String funds, String remarks, String proposer, String auditor) {
// 更改配置, 根据id查询如果库里不存在,返回异常
FundModuleChannelFundConfig fundModuleChannelFundConfig = fundModuleChannelFundConfigRepository.findByIdAndEnableIsTrue(id);
if (fundModuleChannelFundConfig == null) {
log.info("资方模块, 渠道 : {}, 配置id : {}, 资方配置不存在, 修改失败!", bizChannel, id);
return GlobalResponse.create(FundModuleResponse.CHANNEL_FUND_CONFIG_NOT_EXIST);
}
fundModuleChannelFundConfig.setBizChannel(bizChannel);
fundModuleChannelFundConfig.setFunds(funds);
fundModuleChannelFundConfig.setRemarks(remarks);
fundModuleChannelFundConfig.setFundIds(ChannelFundConfigUtil.getAllFundIds(funds));
fundModuleChannelFundConfig.setEnable(true);
fundModuleChannelFundConfigRepository.save(fundModuleChannelFundConfig);
// 如果该条配置在审批,不允许更改
boolean isAuditing = approvalLogService.isAuditing(id);
if (isAuditing) {
log.info("资方模块, 渠道 : {}, 配置id : {}, 正在审批中, 不允许修改", bizChannel, id);
return GlobalResponse.create(FundModuleResponse.CHANNEL_FUND_CONFIG_IS_AUDITING);
}
FundModuleChannelFundConfig auditConfig = createdNewChannelFundConfig(bizChannel, funds, remarks);
createdChannelFundConfigApprovalLog(bizChannel, proposer, auditor, fundModuleChannelFundConfig.getId(), auditConfig.getId());
return GlobalResponse.create(FundModuleResponse.SUCCESS);
}
......@@ -113,4 +115,64 @@ public class FundModuleChannelFundConfigServiceImpl implements IFundModuleChanne
public FundModuleChannelFundConfig findByBizChannel(String bizChannel) {
return fundModuleChannelFundConfigRepository.findByBizChannelAndEnableIsTrue(bizChannel);
}
@Override
public FundModuleChannelFundConfig findById(Long id) {
return fundModuleChannelFundConfigRepository.findById(id);
}
/**
* 增加一条配置记录,Enable先为false
* @param bizChannel
* @param funds
* @param remarks
* @return
*/
private FundModuleChannelFundConfig createdNewChannelFundConfig(String bizChannel, String funds, String remarks) {
FundModuleChannelFundConfig fundModuleChannelFundConfig = new FundModuleChannelFundConfig();
fundModuleChannelFundConfig.setBizChannel(bizChannel);
fundModuleChannelFundConfig.setFunds(funds);
fundModuleChannelFundConfig.setRemarks(remarks);
fundModuleChannelFundConfig.setFundIds(ChannelFundConfigUtil.getAllFundIds(funds));
// 默认测试
fundModuleChannelFundConfig.setType(0);
fundModuleChannelFundConfig.setEnable(false);
return fundModuleChannelFundConfigRepository.save(fundModuleChannelFundConfig);
}
/**
* 创建渠道资方配置审批记录
* @param bizChannel
* @param proposer
* @param auditor
* @param preConfigId
* @param auditConfigId
*/
private void createdChannelFundConfigApprovalLog(String bizChannel, String proposer, String auditor, Long preConfigId, Long auditConfigId) {
approvalLogService.createApprovalLog(AuditTypeEnum.ONLINE, AuditTargetEnum.FUND_CONFIG, bizChannel, proposer, auditor, preConfigId, auditConfigId);
}
@Override
public FundModuleChannelFundConfig auditPassConfig(Long preId, Long auditId) {
FundModuleChannelFundConfig config = updateEnable(auditId, true);
updateEnable(preId, false);
return config;
}
/**
* 更改配置enable状态
* @param id
* @param enable
*/
private FundModuleChannelFundConfig updateEnable(Long id, Boolean enable) {
FundModuleChannelFundConfig config = fundModuleChannelFundConfigRepository.findById(id);
config.setEnable(enable);
return fundModuleChannelFundConfigRepository.save(config);
}
@CacheEvict(value = "cacheManager", key="'ASSET_DISTRIBUTION:FUND_MODULE:CHANNEL_FUND_CONFIG:AC8A_'+#bizChannel")
@Override
public void clearChannelFundConfigCache(String bizChannel) {
log.info("渠道资方配置缓存清除, bizChannel : {}", bizChannel);
}
}
......@@ -15,15 +15,19 @@ import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Stopwatch;
import com.quantgroup.asset.distribution.config.annotation.HandleException;
import com.quantgroup.asset.distribution.constant.FundModuleConstants;
import com.quantgroup.asset.distribution.enums.funding.AuditStatusEnum;
import com.quantgroup.asset.distribution.enums.response.FundModuleResponse;
import com.quantgroup.asset.distribution.exception.QGExceptionType;
import com.quantgroup.asset.distribution.exception.QGPreconditions;
import com.quantgroup.asset.distribution.model.entity.fund.FundInfo;
import com.quantgroup.asset.distribution.model.response.GlobalResponse;
import com.quantgroup.asset.distribution.service.approval.IApprovalLogService;
import com.quantgroup.asset.distribution.service.funding.IFundModuleChannelFundConfigService;
import com.quantgroup.asset.distribution.service.funding.IFundModuleLimitTypeService;
import com.quantgroup.asset.distribution.service.funding.IFundModuleService;
import com.quantgroup.asset.distribution.service.httpclient.IHttpService;
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.FundModuleLimitTypeConfig;
import lombok.extern.slf4j.Slf4j;
......@@ -43,6 +47,8 @@ public class FundModuleServiceImpl implements IFundModuleService{
private IFundModuleLimitTypeService fundModuleLimitTypeService;
@Autowired
private IFundModuleChannelFundConfigService fundModuleChannelFundConfigService;
@Autowired
private IApprovalLogService approvalLogService;
@Value("${clotho.url}")
private String clothoURL;
......@@ -78,14 +84,14 @@ public class FundModuleServiceImpl implements IFundModuleService{
@HandleException
@Override
public GlobalResponse saveChannelFundConfig(Integer type, Long id, String bizChannel, String funds, String remarks) {
public GlobalResponse saveChannelFundConfig(Integer type, Long id, String bizChannel, String funds, String remarks,
String auditor, String proposer) {
if (type == FundModuleConstants.CHANNEL_FUNDS_OPERAOTR_TYPE_ADD) {
return fundModuleChannelFundConfigService.addChannelFundConfig(bizChannel, funds, remarks);
return fundModuleChannelFundConfigService.addChannelFundConfig(bizChannel, funds, remarks, proposer, auditor);
} else if (type == FundModuleConstants.CHANNEL_FUNDS_OPERATOR_TYPE_UPDATE) {
return fundModuleChannelFundConfigService.updateChannelFundConfig(id, bizChannel, funds, remarks);
} else {
return GlobalResponse.create(FundModuleResponse.SUCCESS);
return fundModuleChannelFundConfigService.updateChannelFundConfig(id, bizChannel, funds, remarks, proposer, auditor);
}
return GlobalResponse.create(FundModuleResponse.SUCCESS);
}
@HandleException
......@@ -97,4 +103,42 @@ public class FundModuleServiceImpl implements IFundModuleService{
}
return GlobalResponse.success(result);
}
@HandleException
@Override
public GlobalResponse getAuditInfos(String targetName, Integer auditStatus, Integer auditType, Integer auditTarget,
String applyStartTime, String applyEndTime, String user, Integer pageNum, Integer pageSize) {
Map<String, Object> result = approvalLogService.getApprovalLogs(targetName, auditStatus, auditType, auditTarget, applyStartTime, applyEndTime, user, pageNum, pageSize);
if (result.size() == 0) {
return GlobalResponse.create(FundModuleResponse.HAS_NO_DATA);
}
return GlobalResponse.success(result);
}
@HandleException
@Override
public GlobalResponse findChannelFundConfigById(Long configId) {
FundModuleChannelFundConfig config = fundModuleChannelFundConfigService.findById(configId);
if (config == null) {
return GlobalResponse.create(FundModuleResponse.HAS_NO_DATA);
}
return GlobalResponse.success(config);
}
@HandleException
@Override
public GlobalResponse audit(Long id, Integer auditStatus) {
// 先获取审批记录
ApprovalLog approvalLog = approvalLogService.findById(id);
if (approvalLog == null) {
return GlobalResponse.create(FundModuleResponse.HAS_NO_DATA);
}
if (AuditStatusEnum.containsCode(auditStatus)) {
approvalLogService.audit(approvalLog, auditStatus);
return GlobalResponse.success();
} else {
return GlobalResponse.create(FundModuleResponse.UKNOW_AUDIT_STATUS);
}
}
}
package com.quantgroup.asset.distribution.service.jpa.entity;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import lombok.Data;
/**
* 审批日志表
* @author liwenbin
*
*/
@Table(name = "approval_log")
@Entity
@Data
public class ApprovalLog implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "audit_type")
private Integer auditType;
@Column(name = "audit_target")
private Integer auditTarget;
@Column(name = "target_name")
private String targetName;
@Column(name = "proposer")
private String proposer;
@Column(name = "apply_time")
private Timestamp applyTime;
@Column(name = "auditor")
private String auditor;
@Column(name = "audit_time")
private String auditTime;
@Column(name = "audit_status")
private Integer auditStatus;
@Column(name = "pre_config_id")
private Long preConfigId;
@Column(name = "audit_config_id")
private Long auditConfigId;
@Column(name = "enable")
private Boolean enable;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updatedAt;
@PrePersist
public void prePersist() {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
createdAt = timestamp;
updatedAt = timestamp;
}
@PreUpdate
public void preUpdate() {
updatedAt = new Timestamp(System.currentTimeMillis());
}
}
package com.quantgroup.asset.distribution.service.jpa.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import com.quantgroup.asset.distribution.service.jpa.entity.ApprovalLog;
public interface IApprovalLogRepository extends JpaRepository<ApprovalLog, Long>, JpaSpecificationExecutor<ApprovalLog>{
public ApprovalLog findByIdAndEnableIsTrue(Long id);
public ApprovalLog findByPreConfigIdAndAuditStatus(Long preConfigId, Integer auditStatus);
}
......@@ -2,6 +2,8 @@ package com.quantgroup.asset.distribution.service.jpa.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import com.quantgroup.asset.distribution.service.jpa.entity.FundModuleChannelFundConfig;
......@@ -25,4 +27,11 @@ public interface IFundModuleChannelFundConfigRepository extends JpaRepository<Fu
* @return
*/
public FundModuleChannelFundConfig findByIdAndEnableIsTrue(Long id);
/**
*
* @param id
* @return
*/
public FundModuleChannelFundConfig findById(Long id);
}
package com.quantgroup.asset.distribution.util;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
/**
......@@ -17,4 +19,12 @@ public class DateUtil {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return df.format(new Date());
}
/**
* 获取当前时间 yyyy-MM-dd HH:mm:ss
* @return
*/
public static String getCurDateTime() {
return DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
}
}
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