Commit 83f15dd8 authored by WeiWei's avatar WeiWei

初步完成放款功能

parent c268bf75
package cn.quantgroup.cashloanflowboss.api.order.controller; package cn.quantgroup.cashloanflowboss.api.order.controller;
import cn.quantgroup.cashloanflowboss.api.order.model.ApproveVo; import cn.quantgroup.cashloanflowboss.api.order.model.ApproveVo;
import cn.quantgroup.cashloanflowboss.api.order.model.LendingFormModel;
import cn.quantgroup.cashloanflowboss.api.order.model.OrderVo; import cn.quantgroup.cashloanflowboss.api.order.model.OrderVo;
import cn.quantgroup.cashloanflowboss.api.order.service.OrderService; import cn.quantgroup.cashloanflowboss.api.order.service.OrderService;
import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit; import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit;
...@@ -14,6 +15,7 @@ import javax.validation.Valid; ...@@ -14,6 +15,7 @@ import javax.validation.Valid;
/** /**
* function: * function:
* date: 2019/8/8 * date: 2019/8/8
*
* @author: suntao * @author: suntao
*/ */
...@@ -27,6 +29,7 @@ public class OrderController { ...@@ -27,6 +29,7 @@ public class OrderController {
/** /**
* 订单查询接口 * 订单查询接口
*
* @param channelId * @param channelId
* @param channelOrderNumber * @param channelOrderNumber
* @param pageNumber * @param pageNumber
...@@ -43,6 +46,7 @@ public class OrderController { ...@@ -43,6 +46,7 @@ public class OrderController {
/** /**
* 审批接口 * 审批接口
*
* @param approveVo * @param approveVo
* @return * @return
*/ */
...@@ -52,7 +56,17 @@ public class OrderController { ...@@ -52,7 +56,17 @@ public class OrderController {
return Result.buildSuccess(orderService.approveOpt(approveVo)); return Result.buildSuccess(orderService.approveOpt(approveVo));
} }
@PostMapping(value = "/cancel/loan",consumes = "application/json") /**
* 放款
*
* @return
*/
@PostMapping("/lending")
public Result<Boolean> lending(@RequestBody @Valid LendingFormModel lendingFormModel) {
return Result.buildSuccess(this.orderService.lending(lendingFormModel));
}
@PostMapping(value = "/cancel/loan", consumes = "application/json")
public Result cancel(@RequestBody @Valid OrderVo orderVo) { public Result cancel(@RequestBody @Valid OrderVo orderVo) {
return Result.buildSuccess(orderService.cancel(orderVo)); return Result.buildSuccess(orderService.cancel(orderVo));
} }
......
package cn.quantgroup.cashloanflowboss.api.order.model;
import cn.quantgroup.cashloanflowboss.component.validator.constraints.NotEmpty;
import lombok.Data;
/**
* Created by WeiWei on 2019/8/13.
*/
@Data
public class LendingFormModel {
/**
* 渠道ID
*/
@NotEmpty(message = "无效的渠道ID")
private Long channelId;
/**
* 渠道订单号
*/
@NotEmpty(message = "无效的渠道订单号")
private String channelOrderNumber;
/**
* 结果:true(成功)、false(失败)
*/
@NotEmpty(message = "无效的放款结果")
private Boolean result;
}
...@@ -14,4 +14,7 @@ import org.springframework.stereotype.Repository; ...@@ -14,4 +14,7 @@ import org.springframework.stereotype.Repository;
@CashLoanFlowBossDataSource @CashLoanFlowBossDataSource
@Repository @Repository
public interface OrderRepository extends JpaRepository<Order, Long> { public interface OrderRepository extends JpaRepository<Order, Long> {
Order findOrderByChannelOrderNumber(String channelOrderNumber);
} }
package cn.quantgroup.cashloanflowboss.api.order.service; package cn.quantgroup.cashloanflowboss.api.order.service;
import java.util.Date;
import cn.quantgroup.cashloanflowboss.api.channel.entity.ChannelConf; import cn.quantgroup.cashloanflowboss.api.channel.entity.ChannelConf;
import cn.quantgroup.cashloanflowboss.api.channel.repository.ChannelConfRepository; import cn.quantgroup.cashloanflowboss.api.channel.repository.ChannelConfRepository;
import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil; import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil;
import cn.quantgroup.cashloanflowboss.api.order.entity.Order; import cn.quantgroup.cashloanflowboss.api.order.entity.Order;
import cn.quantgroup.cashloanflowboss.api.order.model.ApproveVo; import cn.quantgroup.cashloanflowboss.api.order.model.ApproveVo;
import cn.quantgroup.cashloanflowboss.api.order.model.LendingFormModel;
import cn.quantgroup.cashloanflowboss.api.order.model.OrderVo; import cn.quantgroup.cashloanflowboss.api.order.model.OrderVo;
import cn.quantgroup.cashloanflowboss.api.order.repository.OrderRepository; import cn.quantgroup.cashloanflowboss.api.order.repository.OrderRepository;
import cn.quantgroup.cashloanflowboss.api.order.util.OrderUtil; import cn.quantgroup.cashloanflowboss.api.order.util.OrderUtil;
import cn.quantgroup.cashloanflowboss.core.Application; import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderMapping; import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderMapping;
import cn.quantgroup.cashloanflowboss.spi.clf.repository.ClfOrderMappingRepository; import cn.quantgroup.cashloanflowboss.spi.clf.repository.ClfOrderMappingRepository;
import cn.quantgroup.cashloanflowboss.spi.clotho.service.ClothoCenter; import cn.quantgroup.cashloanflowboss.spi.clotho.client.ClothoCenter;
import cn.quantgroup.cashloanflowboss.spi.clotho.service.ClothoCenterService;
import cn.quantgroup.cashloanflowboss.spi.jolyne.JolyneCenter; import cn.quantgroup.cashloanflowboss.spi.jolyne.JolyneCenter;
import cn.quantgroup.cashloanflowboss.spi.user.service.XyqbUserService; import cn.quantgroup.cashloanflowboss.spi.user.service.XyqbUserService;
import cn.quantgroup.cashloanflowboss.spi.xyqb.service.XYQBCenterService;
import cn.quantgroup.cashloanflowboss.utils.JSONTools; import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import cn.quantgroup.user.retbean.XUser; import cn.quantgroup.user.retbean.XUser;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import java.util.concurrent.ConcurrentMap;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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;
...@@ -28,7 +29,9 @@ import org.springframework.data.domain.PageRequest; ...@@ -28,7 +29,9 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentMap;
/** /**
* function: * function:
...@@ -46,15 +49,23 @@ public class OrderService { ...@@ -46,15 +49,23 @@ public class OrderService {
@Autowired @Autowired
private OrderRepository orderRepository; private OrderRepository orderRepository;
@Autowired
private ClfOrderMappingRepository clfOrderMappingRepository;
@Autowired @Autowired
private XyqbUserService xyqbUserService; private XyqbUserService xyqbUserService;
@Autowired @Autowired
private ClothoCenter clothoCenter; private ClothoCenter clothoCenter;
@Autowired @Autowired
private JolyneCenter jolyneCenter; private JolyneCenter jolyneCenter;
@Autowired
private ClothoCenterService clothoCenterService;
@Autowired
private XYQBCenterService xyqbCenterService;
@Autowired
private ClfOrderMappingRepository clfOrderMappingRepository;
public Page<OrderVo> getOrders(Long channelId, String channelOrderNo, Integer pageNumber, Integer pageSize) { public Page<OrderVo> getOrders(Long channelId, String channelOrderNo, Integer pageNumber, Integer pageSize) {
...@@ -79,7 +90,7 @@ public class OrderService { ...@@ -79,7 +90,7 @@ public class OrderService {
}, new PageRequest(pageNumber, pageSize)); }, new PageRequest(pageNumber, pageSize));
return page.map(it-> { return page.map(it -> {
OrderVo orderVo = new OrderVo(); OrderVo orderVo = new OrderVo();
orderVo.setId(it.getId()); orderVo.setId(it.getId());
orderVo.setChannelId(it.getRegisteredFrom()); orderVo.setChannelId(it.getRegisteredFrom());
...@@ -148,7 +159,6 @@ public class OrderService { ...@@ -148,7 +159,6 @@ public class OrderService {
orderRepository.save(order); orderRepository.save(order);
Map<String, Object> data = new HashMap<>(16); Map<String, Object> data = new HashMap<>(16);
data.put("code", 0); data.put("code", 0);
data.put("msg", "success"); data.put("msg", "success");
...@@ -170,9 +180,43 @@ public class OrderService { ...@@ -170,9 +180,43 @@ public class OrderService {
log.info("审批申请失败,channelOrderNumber={},requestParam={}", orderMapping.getChannelOrderNo(), JSONTools.serialize(data)); log.info("审批申请失败,channelOrderNumber={},requestParam={}", orderMapping.getChannelOrderNo(), JSONTools.serialize(data));
return false; return false;
} }
}
/**
* 放款
*
* @param lendingFormModel
* @return
*/
public boolean lending(LendingFormModel lendingFormModel) {
boolean result;
Order order = this.orderRepository.findOrderByChannelOrderNumber(lendingFormModel.getChannelOrderNumber());
ClfOrderMapping orderMapping = this.clfOrderMappingRepository.findByChannelOrderNoAndRegisteredFromLastOne(lendingFormModel.getChannelOrderNumber(), lendingFormModel.getChannelId());
// 更新合同状态
this.xyqbCenterService.updateContractStatus(orderMapping.getQgUserId(), 2);
// 更新待放款时间
this.xyqbCenterService.updateFundLendingTime(orderMapping.getLoanId());
Map data = this.xyqbCenterService.queryLendingRecordCount(order.getFundId(), 0);
result = this.clothoCenterService.lending(order.getFundId(), new BigDecimal(String.valueOf(data.get("totalAmount"))), Integer.valueOf(String.valueOf(data.get("totalCount"))));
// 如果是非存管,创建放款MQ
if (order.getFundType() == 0) {
this.xyqbCenterService.pushLendingResult(orderMapping.getLoanId(), lendingFormModel.getResult() ? 3 : 4);
}
return result;
} }
public boolean cancel(OrderVo orderVo){ public boolean cancel(OrderVo orderVo) {
ClfOrderMapping orderMapping = clfOrderMappingRepository.findByChannelOrderNoLastOne(orderVo.getChannelOrderNumber()); ClfOrderMapping orderMapping = clfOrderMappingRepository.findByChannelOrderNoLastOne(orderVo.getChannelOrderNumber());
if (orderMapping == null) { if (orderMapping == null) {
log.info("cancel,关单失败,无订单 channelOrderNumber={}", orderVo.getChannelOrderNumber()); log.info("cancel,关单失败,无订单 channelOrderNumber={}", orderVo.getChannelOrderNumber());
...@@ -187,13 +231,13 @@ public class OrderService { ...@@ -187,13 +231,13 @@ public class OrderService {
Long userId = xUser.getId(); Long userId = xUser.getId();
ConcurrentMap<Object, Object> data = Maps.newConcurrentMap(); ConcurrentMap<Object, Object> data = Maps.newConcurrentMap();
ArrayList<Object> cancel_list = Lists.newArrayList(); ArrayList<Object> cancel_list = Lists.newArrayList();
cancel_list.add("update xyqb.quota_credit set is_active=0 where user_id="+userId); cancel_list.add("update xyqb.quota_credit set is_active=0 where user_id=" + userId);
cancel_list.add("update xyqb.quota_account set is_active=0 where user_id="+userId); cancel_list.add("update xyqb.quota_account set is_active=0 where user_id=" + userId);
cancel_list.add("update xyqb.loan_application_history set progress=16 where user_id="+userId); cancel_list.add("update xyqb.loan_application_history set progress=16 where user_id=" + userId);
cancel_list.add("update xyqb.loan_application_history set is_active=0 where user_id="+userId); cancel_list.add("update xyqb.loan_application_history set is_active=0 where user_id=" + userId);
cancel_list.add("delete from apply_quota_record where user_id="+userId); cancel_list.add("delete from apply_quota_record where user_id=" + userId);
cancel_list.add("delete from user_operation_history where user_id="+userId); cancel_list.add("delete from user_operation_history where user_id=" + userId);
data.put("sql",cancel_list); data.put("sql", cancel_list);
String cancel_result = jolyneCenter.cancel(JSONTools.serialize(data)); String cancel_result = jolyneCenter.cancel(JSONTools.serialize(data));
return "success".equals(cancel_result); return "success".equals(cancel_result);
} }
......
...@@ -29,9 +29,7 @@ public class Result<T> { ...@@ -29,9 +29,7 @@ public class Result<T> {
*/ */
private T data; private T data;
public Result() { public Result() {}
}
public Result(Status status) { public Result(Status status) {
this(status, null); this(status, null);
...@@ -52,39 +50,38 @@ public class Result<T> { ...@@ -52,39 +50,38 @@ public class Result<T> {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static<T> Result buildSuccess(T data) { public static <T> Result<T> buildSuccess(T data) {
return new Result(ApplicationStatus.SUCCESS, data); return new Result(ApplicationStatus.SUCCESS, data);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static<T> Result buildSuccess(T data, String message) { public static <T> Result<T> buildSuccess(T data, String message) {
return new Result(ApplicationStatus.SUCCESS, data, message); return new Result(ApplicationStatus.SUCCESS, data, message);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static<T> Result buildFial(T data) { public static <T> Result<T> buildFial(T data) {
return new Result(ApplicationStatus.FAILURE, data); return new Result(ApplicationStatus.FAILURE, data);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static<T> Result buildFial(String message) { public static <T> Result<T> buildFial(String message) {
return new Result(ApplicationStatus.FAILURE, null, message); return new Result(ApplicationStatus.FAILURE, null, message);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static<T> Result buildFial() { public static <T> Result<T> buildFial() {
return new Result(ApplicationStatus.FAILURE, null, null); return new Result(ApplicationStatus.FAILURE, null, null);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static<T> Result buildFial(ApplicationStatus applicationStatus) { public static <T> Result<T> buildFial(ApplicationStatus applicationStatus) {
return new Result(applicationStatus, null, null); return new Result(applicationStatus, null, null);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static<T> Result buildFial(T data, String message) { public static <T> Result<T> buildFial(T data, String message) {
return new Result(ApplicationStatus.FAILURE, data, message); return new Result(ApplicationStatus.FAILURE, data, message);
} }
......
...@@ -31,12 +31,27 @@ public enum ApplicationStatus implements Status<ApplicationStatus> { ...@@ -31,12 +31,27 @@ public enum ApplicationStatus implements Status<ApplicationStatus> {
DISABLED_USER(501003, "用户已被禁用"), DISABLED_USER(501003, "用户已被禁用"),
USERNAME_OR_PASSWORD_ERROR(501004, "用户名或密码错误"); USERNAME_OR_PASSWORD_ERROR(501004, "用户名或密码错误"),
// ---------------- SPI异常配置信息 ---------------- //
CLOTHO_CENTER_EXCEPTION(510000, "资金系统异常"),
XYQB_CENTER_EXCEPTION(511000, "信用钱包系统异常");
/**
* 状态码
*/
private int code; private int code;
/**
* 状态码描述信息
*/
private String message; private String message;
/**
* 自身状态对象
*/
private Status status; private Status status;
ApplicationStatus(int code, String message) { ApplicationStatus(int code, String message) {
...@@ -46,7 +61,7 @@ public enum ApplicationStatus implements Status<ApplicationStatus> { ...@@ -46,7 +61,7 @@ public enum ApplicationStatus implements Status<ApplicationStatus> {
} }
/** /**
* 抛出本状态异常 * 抛出自身态异常
*/ */
public ApplicationException throwException() { public ApplicationException throwException() {
throw new ApplicationException(this); throw new ApplicationException(this);
......
package cn.quantgroup.cashloanflowboss.spi.clotho.service; package cn.quantgroup.cashloanflowboss.spi.clotho.client;
import cn.quantgroup.cashloanflowboss.spi.clotho.exception.ClothoCenterException;
import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -21,6 +22,24 @@ public interface ClothoCenter { ...@@ -21,6 +22,24 @@ public interface ClothoCenter {
@PostMapping(value = "/external/quota/auth_amount_audit/notify", consumes = "application/x-www-form-urlencoded") @PostMapping(value = "/external/quota/auth_amount_audit/notify", consumes = "application/x-www-form-urlencoded")
String approve(@RequestParam Map approveData); String approve(@RequestParam Map approveData);
/**
* 生成放款MQ消息
*
* @param data
* @return
*/
@PostMapping(value = "/ex/paycenter/pay_notify", consumes = "application/x-www-form-urlencoded")
String generatorLendingMessage(@RequestParam Map data);
/**
* 放款
*
* @param data
* @return
*/
@PostMapping(value = "clotho/funds/plan/loan/apply", consumes = "application/x-www-form-urlencoded")
String lending(@RequestParam Map data);
@Component @Component
class Fallback implements ClothoCenter { class Fallback implements ClothoCenter {
...@@ -28,5 +47,16 @@ public interface ClothoCenter { ...@@ -28,5 +47,16 @@ public interface ClothoCenter {
public String approve(Map approveData) { public String approve(Map approveData) {
return "error1"; return "error1";
} }
@Override
public String generatorLendingMessage(Map data) {
throw new ClothoCenterException();
}
@Override
public String lending(Map data) {
return null;
}
} }
} }
package cn.quantgroup.cashloanflowboss.spi.clotho.exception;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.core.exception.ApplicationException;
/**
* Created by WeiWei on 2019/8/12.
*/
public class ClothoCenterException extends ApplicationException {
public ClothoCenterException() {
super(ApplicationStatus.CLOTHO_CENTER_EXCEPTION);
}
}
package cn.quantgroup.cashloanflowboss.spi.clotho.model;
import lombok.Data;
import java.util.Date;
/**
* 放款参数模型
* <p>
* Created by WeiWei on 2019/8/12.
*/
@Data
public class LendingServiceModel {
/**
* 借款ID
*/
private Long loanId;
/**
* 放款订单号(等同LoanId)
*/
private Long orderNumber;
/**
* 放款时间
*/
private Date lendingTime;
/**
* 放款状态:3(成功)、4(失败)
*/
private Date status;
}
package cn.quantgroup.cashloanflowboss.spi.clotho.service;
import cn.quantgroup.cashloanflowboss.spi.clotho.client.ClothoCenter;
import cn.quantgroup.cashloanflowboss.spi.clotho.model.LendingServiceModel;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.HashMap;
/**
* Created by WeiWei on 2019/8/12.
*/
@Slf4j
@Service
public class ClothoCenterService {
@Autowired
private ClothoCenter clothoCenter;
/**
* 生成放款MQ消息
*
* @return
*/
public String generatorLendingMessage(LendingServiceModel lendingServiceModel) {
return this.clothoCenter.generatorLendingMessage(JSONTools.toMap(lendingServiceModel));
}
/**
* 放款
*
* @return
*/
public boolean lending(Integer fundId, BigDecimal amountLimit, Integer pepoleLimit) {
// TODO WEIWEI 根据返回的数据结构补充判断逻辑
String data = this.clothoCenter.lending(new HashMap() {{
put("fundingCorpId", fundId);
put("amountLimit", amountLimit);
put("peopleLimit", pepoleLimit);
}});
return false;
}
}
package cn.quantgroup.cashloanflowboss.spi.jolyne; package cn.quantgroup.cashloanflowboss.spi.jolyne;
import cn.quantgroup.cashloanflowboss.spi.clotho.service.ClothoCenter;
import java.util.Map;
import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
......
package cn.quantgroup.cashloanflowboss.spi.xyqb.client;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
/**
* Created by WeiWei on 2019/8/12.
*/
@Component
@FeignClient(name = "XYQBCenter", url = "${}", fallback = XYQBCenter.Fallback.class)
public interface XYQBCenter {
@PostMapping(value = "/ex/paycenter/pay_notify", consumes = "application/x-www-form-urlencoded")
String pushLendingResult(@RequestParam Map parameter);
@Component
class Fallback implements XYQBCenter {
@Override
public String pushLendingResult(Map parameter) {
return null;
}
}
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* Created by WeiWei on 2019/8/12.
*/
@Data
@Entity
@Table(name = "contract")
public class Contract {
/**
* 用户ID
*/
@Column(name = "user_id")
private Long userId;
/**
* 状态
*/
@Column(name = "generate_status")
private Integer generate_status;
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;
/**
* Created by WeiWei on 2019/8/12.
*/
@Data
@Entity
@Table(name = "waiting_funding_corp_operate_people")
public class FundLending {
/**
* 借款订单号
*/
@Column(name = "loan_application_history_id")
private String loanId;
/**
* 放款金额
*/
@Column(name = "fund_amount")
private BigDecimal amount;
/**
* 资方ID
*/
@Column(name = "funding_corp_id")
private Integer fundId;
/**
* 进度
*/
@Column(name = "funding_corp_progress")
private Integer progress;
/**
* 创建时间
*/
@Column(name = "created_at")
private Date createTime;
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.exception;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.core.exception.ApplicationException;
/**
* Created by WeiWei on 2019/8/12.
*/
public class XYQBException extends ApplicationException {
public XYQBException() {
super(ApplicationStatus.XYQB_CENTER_EXCEPTION);
}
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.repository;
import cn.quantgroup.cashloanflowboss.spi.xyqb.entity.Contract;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
/**
* Created by WeiWei on 2019/8/13.
*/
@Repository
public interface ContractRepository extends CrudRepository<Contract, Integer> {
/**
* 更新合同状态
*
* @param userId
* @param status
* @return
*/
@Query("update Contract set generate_status = :status where userId = :userId")
boolean updateContractStatus(Long userId, Integer status);
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.repository;
import cn.quantgroup.cashloanflowboss.spi.xyqb.entity.FundLending;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.Map;
/**
* Created by WeiWei on 2019/8/12.
*/
@Repository
public interface FundLendingRepository extends CrudRepository<FundLending, Integer> {
/**
* 更新资方待放款创建时间
*
* @param loanId
* @param time
* @return
*/
@Query("update FundLending set createTime = :createTime where loanId = :loanId")
boolean updateCreateTime(@Param("loanId") Long loanId, @Param("createTime") Date time);
/**
* 查询待放款记录
*
* @param fundId
* @param progress
* @return
*/
@Query("select sum(amount) as totalAmount ,count(fundId) as totalCount from FundLending where progress = :progress and fundId = :fundId")
Map queryLendingRecordCount(Integer fundId, Integer progress);
}
\ No newline at end of file
package cn.quantgroup.cashloanflowboss.spi.xyqb.service;
import cn.quantgroup.cashloanflowboss.spi.xyqb.client.XYQBCenter;
import cn.quantgroup.cashloanflowboss.spi.xyqb.repository.ContractRepository;
import cn.quantgroup.cashloanflowboss.spi.xyqb.repository.FundLendingRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* Created by WeiWei on 2019/8/12.
*/
@Service
public class XYQBCenterService {
@Autowired
private FundLendingRepository fundLendingRepository;
@Autowired
private ContractRepository contractRepository;
@Autowired
private XYQBCenter xyqbCenter;
/**
* 更新资方待放款创建时间
*
* @return
*/
public boolean updateFundLendingTime(Long loanId) {
return this.fundLendingRepository.updateCreateTime(loanId, new Date());
}
/**
* 更新合同状态
*
* @param userId
* @return
*/
public boolean updateContractStatus(Long userId, Integer status) {
return this.contractRepository.updateContractStatus(userId, status);
}
/**
* 查询放款记录
*
* @param fundId
* @param progress
* @return
*/
public Map queryLendingRecordCount(Integer fundId, Integer progress) {
return this.fundLendingRepository.queryLendingRecordCount(fundId, progress);
}
/**
* 生成放款结果MQ
*
* @param loanId
* @param status
* @return
*/
public boolean pushLendingResult(Long loanId, Integer status) {
// TODO WEIWEI 查看返回的数据结构,补充判断逻辑
String data = this.xyqbCenter.pushLendingResult(new HashMap() {{
put("orderNo", loanId);
put("payOrderNo", loanId);
put("payTime", new Date().getTime());
put("payStatus", status);
}});
return false;
}
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.service;
/**
* function:
* date: 2019/8/9
*
* @author: suntao
*/
public class XyqbCenter {
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.source;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by WeiWei on 2019/8/12.
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface XYQBDataSource {
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.source;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = {"cn.quantgroup"}, includeFilters = @ComponentScan.Filter(XYQBDataSource.class))
public class XYQBDataSourceConfiguration {
@Bean
public DataSource xyqbDataSource(@Autowired XYQBDataSourceProperty dataSourceProperty) {
DruidDataSource source = DruidDataSourceBuilder.create().build();
source.setMaxActive(dataSourceProperty.getMaxActive());
source.setMinIdle(dataSourceProperty.getMinIdle());
source.setInitialSize(dataSourceProperty.getInitialSize());
source.setMaxWait(500000);
source.setTimeBetweenEvictionRunsMillis(60000);
source.setMinEvictableIdleTimeMillis(300000);
source.setValidationQuery("SELECT 'x'");
source.setTestWhileIdle(true);
source.setTestOnBorrow(false);
source.setTestOnReturn(false);
source.setPoolPreparedStatements(Boolean.FALSE);
return source;
}
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.source;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Created by WeiWei on 2019/8/12.
*/
@Data
@ConfigurationProperties("application.datasource.xyqb")
public class XYQBDataSourceProperty {
/**
* JDBC连接URL
*/
private String jdbcURL;
/**
* 数据库用户名
*/
private String username;
/**
* 数据库密码
*/
private String password;
/**
* 最大连接数
*/
private Integer maxActive = 30;
/**
* 最小连接数
*/
private Integer minIdle = 1;
/**
* 初始连接数
*/
private Integer initialSize = 5;
}
...@@ -6,8 +6,16 @@ import cn.quantgroup.cashloanflowboss.core.exception.ApplicationException; ...@@ -6,8 +6,16 @@ import cn.quantgroup.cashloanflowboss.core.exception.ApplicationException;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -105,4 +113,59 @@ public class JSONTools { ...@@ -105,4 +113,59 @@ public class JSONTools {
return deserialize(JSONTools.serialize(data), type); return deserialize(JSONTools.serialize(data), type);
} }
/**
* 将对象转成Map
*
* @param data
* @return
*/
public static Map toMap(Object data) {
return convert(data, Map.class);
}
/**
* 将Map对象转成URL请求参数
*
* @param data
* @return
*/
public static String toParameter(Map<String, Object> data) {
List<NameValuePair> parameters = new ArrayList<>();
data.keySet().forEach(key -> parameters.add(new BasicNameValuePair(key, String.class.isInstance(data.get(key)) ? String.valueOf(data.get(key)) : JSONTools.serialize(data.get(key)))));
return URLEncodedUtils.format(parameters, "UTF-8");
}
/**
* 将Map对象转成URL请求参数
*
* @param data
* @param isEncode
* @return
*/
public static String toParameter(Map<String, Object> data, boolean isEncode) {
String parameter = toParameter(data);
try {
return !isEncode ? URLDecoder.decode(parameter, "UTF-8") : parameter;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
/**
* 将Model对象转成URL请求参数
*
* @param model
* @return
*/
public static String toParameter(Object model) {
return toParameter(toMap(model));
}
} }
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