Commit 87693169 authored by 王俊权's avatar 王俊权

Merge remote-tracking branch 'origin/v1' into v1

# Conflicts:
#	src/main/java/cn/quantgroup/cashloanflowboss/api/order/controller/OrderController.java
#	src/main/java/cn/quantgroup/cashloanflowboss/api/order/service/OrderService.java
#	src/main/java/cn/quantgroup/cashloanflowboss/api/user/controller/UserController.java
parents 1739b6ff bb1edc18
package cn.quantgroup.cashloanflowboss.api.order.controller;
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.service.OrderService;
import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit;
......@@ -14,6 +15,7 @@ import javax.validation.Valid;
/**
* function:
* date: 2019/8/8
*
* @author: suntao
*/
......@@ -27,6 +29,7 @@ public class OrderController {
/**
* 订单查询接口
*
* @param channelId
* @param channelOrderNumber
* @param pageNumber
......@@ -43,6 +46,7 @@ public class OrderController {
/**
* 审批接口
*
* @param approveVo
* @return
*/
......@@ -52,4 +56,18 @@ public class OrderController {
return Result.buildSuccess(orderService.approveOpt(approveVo));
}
/**
* 放款
*
* @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) {
return Result.buildSuccess(orderService.cancel(orderVo));
}
}
......@@ -6,6 +6,8 @@ import javax.persistence.Table;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* function:
......
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;
@CashLoanFlowBossDataSource
@Repository
public interface OrderRepository extends JpaRepository<Order, Long> {
Order findOrderByChannelOrderNumber(String channelOrderNumber);
}
package cn.quantgroup.cashloanflowboss.api.order.service;
import cn.quantgroup.cashloanflowboss.spi.clf.service.CLFCenter;
import java.util.Date;
import cn.quantgroup.cashloanflowboss.api.channel.entity.ChannelConf;
import cn.quantgroup.cashloanflowboss.api.channel.repository.ChannelConfRepository;
import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil;
import cn.quantgroup.cashloanflowboss.api.order.entity.Order;
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.repository.OrderRepository;
import cn.quantgroup.cashloanflowboss.api.order.util.OrderUtil;
import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderMapping;
import cn.quantgroup.cashloanflowboss.spi.clf.repository.ClfOrderMappingRepository;
import cn.quantgroup.cashloanflowboss.spi.clotho.service.ClothoCenter;
import cn.quantgroup.cashloanflowboss.spi.clf.service.CLFCenter;
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.user.service.XyqbUserService;
import cn.quantgroup.cashloanflowboss.spi.xyqb.service.XYQBCenterService;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import cn.quantgroup.user.retbean.XUser;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.concurrent.ConcurrentMap;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.persistence.criteria.Predicate;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -28,9 +36,6 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.Predicate;
import java.util.*;
/**
* function:
* date: 2019/8/8
......@@ -47,17 +52,25 @@ public class OrderService {
@Autowired
private OrderRepository orderRepository;
@Autowired
private ClfOrderMappingRepository clfOrderMappingRepository;
@Autowired
private XyqbUserService xyqbUserService;
@Autowired
private ClothoCenter clothoCenter;
@Autowired
private JolyneCenter jolyneCenter;
@Autowired
private CLFCenter clfCenter;
@Autowired
private ClothoCenterService clothoCenterService;
@Autowired
private XYQBCenterService xyqbCenterService;
@Autowired
private ClfOrderMappingRepository clfOrderMappingRepository;
public Page<OrderVo> getOrders(Long channelId, String channelOrderNo, Integer pageNumber, Integer pageSize) {
......@@ -82,7 +95,7 @@ public class OrderService {
}, new PageRequest(pageNumber, pageSize));
return page.map(it-> {
return page.map(it -> {
OrderVo orderVo = new OrderVo();
orderVo.setId(it.getId());
orderVo.setChannelId(it.getRegisteredFrom());
......@@ -151,7 +164,6 @@ public class OrderService {
orderRepository.save(order);
Map<String, Object> data = new HashMap<>(16);
data.put("code", 0);
data.put("msg", "success");
......@@ -173,6 +185,40 @@ public class OrderService {
log.info("审批申请失败,channelOrderNumber={},requestParam={}", orderMapping.getChannelOrderNo(), JSONTools.serialize(data));
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;
}
}
package cn.quantgroup.cashloanflowboss.api.test.controller;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -12,12 +7,5 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/test")
public class TestController {
// @Autowired
// private UserSessionService userSessionService;
//
// @GetMapping("/user/info")
// public Result findUserFromSession() {
// UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
// return new Result<>(ApplicationStatus.SUCCESS, userSessionInfo);
// }
}
......@@ -3,16 +3,22 @@ package cn.quantgroup.cashloanflowboss.api.user.controller;
import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.api.user.model.Pagination;
import cn.quantgroup.cashloanflowboss.api.user.model.RegisterUserFormModel;
import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserService;
import cn.quantgroup.cashloanflowboss.component.validator.constraints.NotEmpty;
import cn.quantgroup.cashloanflowboss.spi.user.service.UserSysService;
import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.spi.user.service.XyqbUserService;
import cn.quantgroup.user.IUserSdkService;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by WeiWei on 2019/7/22.
......@@ -80,6 +86,15 @@ public class UserController {
return this.userService.removeUser(id);
}
/**
* 获取用户详情
* @return
*/
@GetMapping("/detail/info")
public Result<UserDetailInfo> userDetailInfo() {
return Result.buildSuccess(userService.getUserDetailInfo());
}
/**
* 清除用户信息
*
......
package cn.quantgroup.cashloanflowboss.api.user.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
@AllArgsConstructor
public class RoleInfo {
private Long roleId;
private String roleName;
}
package cn.quantgroup.cashloanflowboss.api.user.model;
import cn.quantgroup.cashloanflowboss.api.log.model.Principal;
import cn.quantgroup.cashloanflowboss.api.role.entity.Role;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import com.google.common.collect.Lists;
import lombok.Data;
import java.util.List;
import java.util.Set;
@Data
public class UserDetailInfo {
private UserInfo userInfo;
private RoleInfo roleInfo;
private Long channelId;
private String rank;
@Data
static class RoleInfo {
List<roleView> roleInfos;
@Data
static class roleView {
private Long roleId;
private String roleName;
}
}
@Data
static class UserInfo {
private Long userId;
private String userName;
}
public static UserDetailInfo valueOf(Principal principal) {
Assert.isNull(principal, ApplicationStatus.INVALID_USER);
UserDetailInfo userDetailInfo = new UserDetailInfo();
Long userId = principal.getUserId();
userDetailInfo.setRank(principal.getRank().name());
userDetailInfo.setChannelId(principal.getChannelId());
Set<Role> roles = principal.getRoles();
if (null != roles && roles.size() > 0) {
RoleInfo roleInfo = new RoleInfo();
List<RoleInfo.roleView> roleInfos = Lists.newArrayList();
roles.forEach(role -> {
RoleInfo.roleView roleView = new RoleInfo.roleView();
roleView.setRoleId(role.getId());
roleView.setRoleName(role.getName());
roleInfos.add(roleView);
});
roleInfo.setRoleInfos(roleInfos);
userDetailInfo.setRoleInfo(roleInfo);
}
UserInfo userInfo = new UserInfo();
userInfo.setUserId(userId);
userDetailInfo.setUserInfo(userInfo);
return userDetailInfo;
}
}
package cn.quantgroup.cashloanflowboss.api.user.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
@AllArgsConstructor
public class UserInfo {
private Long userId;
private String userName;
}
package cn.quantgroup.cashloanflowboss.api.user.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
@AllArgsConstructor
public class UserSessionInfo {
private UserInfo userInfo;
private RoleInfo roleInfo;
private Long channelId;
}
package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.log.model.Principal;
import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo;
import cn.quantgroup.cashloanflowboss.api.user.repository.UserRepository;
import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.utils.MD5Tools;
......@@ -130,4 +133,11 @@ public class UserService {
}
public UserDetailInfo getUserDetailInfo() {
Principal principal = Application.getPrincipal();
Assert.isNull(principal, ApplicationStatus.INVALID_USER);
return UserDetailInfo.valueOf(principal);
}
}
......@@ -29,9 +29,7 @@ public class Result<T> {
*/
private T data;
public Result() {
}
public Result() {}
public Result(Status status) {
this(status, null);
......@@ -52,39 +50,38 @@ public class Result<T> {
}
@SuppressWarnings("unchecked")
public static<T> Result buildSuccess(T data) {
public static <T> Result<T> buildSuccess(T data) {
return new Result(ApplicationStatus.SUCCESS, data);
}
@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);
}
@SuppressWarnings("unchecked")
public static<T> Result buildFial(T data) {
public static <T> Result<T> buildFial(T data) {
return new Result(ApplicationStatus.FAILURE, data);
}
@SuppressWarnings("unchecked")
public static<T> Result buildFial(String message) {
public static <T> Result<T> buildFial(String message) {
return new Result(ApplicationStatus.FAILURE, null, message);
}
@SuppressWarnings("unchecked")
public static<T> Result buildFial() {
public static <T> Result<T> buildFial() {
return new Result(ApplicationStatus.FAILURE, null, null);
}
@SuppressWarnings("unchecked")
public static<T> Result buildFial(ApplicationStatus applicationStatus) {
public static <T> Result<T> buildFial(ApplicationStatus applicationStatus) {
return new Result(applicationStatus, null, null);
}
@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);
}
......
......@@ -63,7 +63,7 @@ public class CashLoanFlowBossDataSourceConfiguration {
public LocalContainerEntityManagerFactoryBean entityManager(EntityManagerFactoryBuilder builder) {
return builder.dataSource(createDataSource())
.packages("cn.quantgroup")
.packages("cn.quantgroup.cashloanflowboss.api")
.persistenceUnit(uniquename)
.build();
}
......
......@@ -31,12 +31,27 @@ public enum ApplicationStatus implements Status<ApplicationStatus> {
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 String message;
/**
* 自身状态对象
*/
private Status status;
ApplicationStatus(int code, String message) {
......@@ -46,7 +61,7 @@ public enum ApplicationStatus implements Status<ApplicationStatus> {
}
/**
* 抛出本状态异常
* 抛出自身态异常
*/
public ApplicationException throwException() {
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.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -21,6 +22,24 @@ public interface ClothoCenter {
@PostMapping(value = "/external/quota/auth_amount_audit/notify", consumes = "application/x-www-form-urlencoded")
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
class Fallback implements ClothoCenter {
......@@ -28,5 +47,16 @@ public interface ClothoCenter {
public String approve(Map approveData) {
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;
import cn.quantgroup.cashloanflowboss.spi.clotho.service.ClothoCenter;
import java.util.Map;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
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 = "${api.https}", 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.*;
/**
* Created by WeiWei on 2019/8/12.
*/
@Data
@Entity
@Table(name = "contract")
public class Contract {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
/**
* 用户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.*;
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 {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
/**
* 借款订单号
*/
@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 cn.quantgroup.cashloanflowboss.spi.xyqb.source.XYQBDataSource;
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.
*/
@XYQBDataSource
@Repository
public interface ContractRepository extends CrudRepository<Contract, Long> {
/**
* 更新合同状态
*
* @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 cn.quantgroup.cashloanflowboss.spi.xyqb.source.XYQBDataSource;
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.
*/
@XYQBDataSource
@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.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
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.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = {"cn.quantgroup.cashloanflowboss.spi.xyqb"}, entityManagerFactoryRef = "xyqbEntityManager", transactionManagerRef = "xyqbTransactionManager", includeFilters = @ComponentScan.Filter(XYQBDataSource.class))
public class XYQBDataSourceConfiguration {
@Bean
@ConfigurationProperties(prefix = "data.xyqb")
public DataSource xyqbDataSource() {
DruidDataSource source = DruidDataSourceBuilder.create().build();
source.setMaxActive(200);
source.setMinIdle(10);
source.setInitialSize(10);
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;
}
@Bean
public LocalContainerEntityManagerFactoryBean xyqbEntityManager(EntityManagerFactoryBuilder builder, DataSource xyqbDataSource) {
return builder.dataSource(xyqbDataSource)
.packages("cn.quantgroup.cashloanflowboss")
.persistenceUnit("XYQB-DataSource")
.build();
}
@Bean
public PlatformTransactionManager xyqbTransactionManager(EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.source;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* Created by WeiWei on 2019/8/12.
*/
@Data
@Component
@ConfigurationProperties("application.database.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;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
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.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
......@@ -105,4 +113,59 @@ public class JSONTools {
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