Commit 56d0da8a authored by WeiWei's avatar WeiWei

Merge remote-tracking branch 'cash-loan-flow-boss/v1' into v1

# Conflicts:
#	src/main/java/cn/quantgroup/cashloanflowboss/api/channel/controller/ChannelConfController.java
#	src/main/java/cn/quantgroup/cashloanflowboss/api/log/service/LogService.java
#	src/main/java/cn/quantgroup/cashloanflowboss/api/role/entity/boss/RoleUser.java
#	src/main/java/cn/quantgroup/cashloanflowboss/api/role/service/RoleService.java
parents 678218ce 59c85911
...@@ -79,6 +79,67 @@ ...@@ -79,6 +79,67 @@
<artifactId>commons-core</artifactId> <artifactId>commons-core</artifactId>
</dependency> </dependency>
<!-- user sdk -->
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>quantgroup-user-sdk</artifactId>
<version>1.1.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<!-- <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-core</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
</dependencies> </dependencies>
......
...@@ -3,6 +3,7 @@ package cn.quantgroup.cashloanflowboss; ...@@ -3,6 +3,7 @@ package cn.quantgroup.cashloanflowboss;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
...@@ -12,6 +13,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -12,6 +13,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication(scanBasePackages = {"cn.quantgroup.cashloanflowboss"}) @SpringBootApplication(scanBasePackages = {"cn.quantgroup.cashloanflowboss"})
@Configuration @Configuration
@EnableAutoConfiguration @EnableAutoConfiguration
@EnableFeignClients
public class Bootstrap { public class Bootstrap {
public static void main(String[] args) { public static void main(String[] args) {
......
package cn.quantgroup.cashloanflowboss.api.channel.controller; package cn.quantgroup.cashloanflowboss.api.channel.controller;
import cn.quantgroup.cashloanflowboss.api.channel.entity.clf.ChannelConfiguration; import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfAddModel;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfBaseModel;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfVo;
import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit;
import cn.quantgroup.cashloanflowboss.api.channel.service.ChannelConfService; import cn.quantgroup.cashloanflowboss.api.channel.service.ChannelConfService;
import cn.quantgroup.cashloanflowboss.core.annotation.CheckChannelRole;
import cn.quantgroup.cashloanflowboss.api.user.model.Pagination; import cn.quantgroup.cashloanflowboss.api.user.model.Pagination;
import cn.quantgroup.cashloanflowboss.core.base.Result; import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid; import javax.validation.Valid;
...@@ -26,15 +28,31 @@ public class ChannelConfController { ...@@ -26,15 +28,31 @@ public class ChannelConfController {
private ChannelConfService channelConfService; private ChannelConfService channelConfService;
@GetMapping("/info") /**
public Page<ChannelConfiguration> channelInfo(@RequestParam @Valid Pagination pagination, Integer channelId) { * 查询渠道列表
return channelConfService.getChannelInfo(pagination, channelId); * @param channelId 在接受参数时,必须放到第一个参数位置
* @param pageNumber
* @param pageSize
* @return
*/
@ChannelIdInit
@PostMapping("/info")
public Result channelInfo(Long channelId, Integer pageNumber, Integer pageSize) {
return Result.buildSuccess(channelConfService.getChannelInfo(pageNumber, pageSize, channelId));
} }
@CheckChannelRole
@GetMapping("/cfg/info") @GetMapping("/cfg/info")
public Result channelConfInfo(Integer channelId) { public Result getChannelConfInfo(Long channelId) {
return channelConfService.getChannelConf(channelId); return Result.buildSuccess(channelConfService.getChannelConf(channelId), "success");
}
@CheckChannelRole(isObjParam = true ,paramClazz = ChannelConfVo.class)
@PostMapping("/cfg/info")
public Result editChannelConfInfo(@RequestBody @Valid ChannelConfVo channelConfVo) {
return Result.buildSuccess(channelConfService.editChannelConfInfo(channelConfVo));
} }
......
...@@ -18,7 +18,7 @@ public class ChannelConf extends Primary { ...@@ -18,7 +18,7 @@ public class ChannelConf extends Primary {
* 渠道id * 渠道id
*/ */
@Column(name = "channel_id") @Column(name = "channel_id")
private Integer channelId; private Long channelId;
/** /**
* 渠道code * 渠道code
...@@ -69,10 +69,22 @@ public class ChannelConf extends Primary { ...@@ -69,10 +69,22 @@ public class ChannelConf extends Primary {
private String md5Key; private String md5Key;
/** /**
* env_url * env_path
*/ */
@Column(name = "env_url") @Column(name = "env_path")
private String envUrl; private String envPath;
/**
* authCode
*/
@Column(name = "auth_code")
private String authCode;
/**
* riskCode
*/
@Column(name = "risk_code")
private String riskCode;
/** /**
* channel_ip * channel_ip
......
package cn.quantgroup.cashloanflowboss.api.channel.model.boss; package cn.quantgroup.cashloanflowboss.api.channel.model;
import lombok.Data; import lombok.Data;
...@@ -10,7 +10,7 @@ import lombok.Data; ...@@ -10,7 +10,7 @@ import lombok.Data;
*/ */
@Data @Data
public class ChannelConfAddModel { public class ChannelConfAddModel {
private String envUrl; private String envPath;
private String channelIp; private String channelIp;
private String approveCallBackUrl; private String approveCallBackUrl;
private String orderStatusCallBackUrl; private String orderStatusCallBackUrl;
......
package cn.quantgroup.cashloanflowboss.api.channel.model.boss; package cn.quantgroup.cashloanflowboss.api.channel.model;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
/** /**
* Created with suntao on 2019/8/2 * Created with suntao on 2019/8/2
*/ */
@Data @Data
public class ChannelConfBaseModel { public class ChannelConfBaseModel {
private Integer channelId; @NotNull(message = "渠道id不能为空")
private Long channelId;
private String channelName; private String channelName;
private String channelCode; private String channelCode;
private String env; private String env;
private String fundId; private Integer fundId;
private String p2pFundId; private Integer p2pFundId;
private String bizType; private Integer bizType;
private String aesKey; private String aesKey;
private String md5Key; private String md5Key;
private String authCode;
private String riskCode;
} }
package cn.quantgroup.cashloanflowboss.api.channel.model;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* function:
* date: 2019/8/7
*
* @author: suntao
*/
@Data
public class ChannelConfVo {
@NotNull(message = "基础配置信息不能为空")
private ChannelConfBaseModel basicInfo;
@NotNull(message = "回调地址配置信息不能为空")
private ChannelConfAddModel addInfo;
}
package cn.quantgroup.cashloanflowboss.api.channel.model;
import lombok.Data;
import java.util.Date;
/**
* function:
* date: 2019/8/6
*
* @author: suntao
*/
@Data
public class ChannelListModel {
private Long channelId;
private String channelName;
private String channelCode;
private Integer bizType;
private Date createdAt;
}
package cn.quantgroup.cashloanflowboss.api.channel.model.clf;
/**
* function:
* date: 2019/8/6
*
* @author: suntao
*/
public class ChannelConfigurationPage {
}
...@@ -18,7 +18,7 @@ public interface ChannelConfRepository extends JpaRepository<ChannelConf, Long> ...@@ -18,7 +18,7 @@ public interface ChannelConfRepository extends JpaRepository<ChannelConf, Long>
* @param channelId 用户名 * @param channelId 用户名
* @return * @return
*/ */
ChannelConf getByChannelId(Integer channelId); ChannelConf getByChannelId(Long channelId);
} }
package cn.quantgroup.cashloanflowboss.api.channel.service; package cn.quantgroup.cashloanflowboss.api.channel.service;
import java.sql.Timestamp;
import java.util.*;
import cn.quantgroup.cashloanflowboss.api.channel.entity.boss.ChannelConf; import cn.quantgroup.cashloanflowboss.api.channel.entity.boss.ChannelConf;
import cn.quantgroup.cashloanflowboss.api.channel.entity.clf.ChannelConfiguration; import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfAddModel;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfBaseModel;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfVo;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelListModel;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfCallbackConfiguration;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfChannelConfiguration;
import cn.quantgroup.cashloanflowboss.api.channel.repository.boss.ChannelConfRepository; import cn.quantgroup.cashloanflowboss.api.channel.repository.boss.ChannelConfRepository;
import cn.quantgroup.cashloanflowboss.api.channel.repository.clf.ChannelConfigurationRepository; import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderCallBack;
import cn.quantgroup.cashloanflowboss.spi.clf.repository.ClfCallbackConfigurationRepository;
import cn.quantgroup.cashloanflowboss.spi.clf.repository.ClfChannelConfigurationRepository;
import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil; import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil;
import cn.quantgroup.cashloanflowboss.api.user.model.Pagination; import cn.quantgroup.cashloanflowboss.spi.clf.repository.ClfOrderCallbackRepository;
import cn.quantgroup.cashloanflowboss.core.base.Result; import cn.quantgroup.cashloanflowboss.utils.IgnorePropertiesUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/** /**
* function: * function:
...@@ -29,39 +36,97 @@ public class ChannelConfService { ...@@ -29,39 +36,97 @@ public class ChannelConfService {
@Autowired @Autowired
private ChannelConfRepository channelConfRepository; private ChannelConfRepository channelConfRepository;
@Autowired @Autowired
private ChannelConfigurationRepository clfChannelConfigurationRepository; private ClfChannelConfigurationRepository clfChannelConfigurationRepository;
@Autowired
private ClfCallbackConfigurationRepository clfCallbackConfigurationRepository;
@Autowired
private ClfOrderCallbackRepository clfOrderCallbackRepository;
public Page<ChannelConfiguration> getChannelInfo(Pagination pagination, Integer channelId) { public Page<ChannelListModel> getChannelInfo(Integer pageNumber, Integer pageSize, Long channelId) {
Page<ChannelConfiguration> page = this.clfChannelConfigurationRepository.findAll((root, criteriaQuery, criteriaBuilder) -> { Page<ClfChannelConfiguration> page = this.clfChannelConfigurationRepository.findAll((root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>(); List<Predicate> predicates = new ArrayList<>();
// 指定渠道号 // 指定渠道号
if (Objects.nonNull(channelId)) { if (Objects.nonNull(channelId)) {
predicates.add(criteriaBuilder.equal(root.get("channelId"), channelId)); predicates.add(criteriaBuilder.equal(root.get("registeredFrom"), channelId.longValue()));
} }
// 设置查询条件
criteriaQuery.where(criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()])));
// 指定排序 // 指定排序
criteriaQuery.orderBy(criteriaBuilder.desc(root.get("id"))); criteriaQuery.orderBy(criteriaBuilder.desc(root.get("id")));
return criteriaQuery.getRestriction(); return criteriaQuery.getRestriction();
}, new PageRequest(pagination.getPageNumber(), pagination.getPageSize())); }, new PageRequest(pageNumber, pageSize));
return page; Page<ChannelListModel> channelListModelPage = page.map(it -> {
ChannelListModel channelListModel = new ChannelListModel();
channelListModel.setChannelId(it.getRegisteredFrom());
channelListModel.setChannelName(it.getChannelName());
channelListModel.setChannelCode(it.getChannelCode());
// TODO
channelListModel.setBizType(null);
channelListModel.setCreatedAt(it.getCreatedAt());
return channelListModel;
});
return channelListModelPage;
} }
public Result getChannelConf(Integer channelId) { public ChannelConfVo getChannelConf(Long channelId) {
ChannelConf channelConf = channelConfRepository.getByChannelId(channelId); ChannelConf channelConf = channelConfRepository.getByChannelId(channelId);
return Result.buildSuccess(ChannelConfUtil.channelConfConvertVOModel(channelConf), "success"); return ChannelConfUtil.channelConfConvertVOModel(channelConf);
}
public Boolean editChannelConfInfo(ChannelConfVo confVo) {
ChannelConfBaseModel basicInfo = confVo.getBasicInfo();
ChannelConfAddModel addInfo = confVo.getAddInfo();
ChannelConf channelConf = ChannelConfUtil.voModelConfConvertChannelConf(confVo);
ChannelConf channelConfExsit = channelConfRepository.getByChannelId(basicInfo.getChannelId());
// cash-loan-flow-boss 库
if (channelConfExsit == null) {
// 新保存
channelConf.setCreateTime(new Date());
channelConfRepository.save(channelConf);
} else {
// 更新数据库 数据
BeanUtils.copyProperties(channelConf, channelConfExsit, IgnorePropertiesUtil.getNullPropertyNames(channelConf));
channelConfExsit.setUpdateTime(new Date());
channelConfRepository.save(channelConfExsit);
} }
// clf 库
ClfChannelConfiguration channelConfiguration = ChannelConfUtil.convert2ClfChannelConfiguration(basicInfo);
List<ClfOrderCallBack> clfOrderCallBackList = ChannelConfUtil.convert2ClfOrderCallback(basicInfo.getChannelId(), addInfo);
ClfChannelConfiguration channelConfigurationExsit = clfChannelConfigurationRepository.findByRegisteredFrom(basicInfo.getChannelId());
if (channelConfigurationExsit == null) {
// 新保存
channelConfiguration.setCreatedAt(new Timestamp(System.currentTimeMillis()));
clfChannelConfigurationRepository.save(channelConfiguration);
ClfCallbackConfiguration clfCallbackConfiguration = ChannelConfUtil.convert2ClfCallbackConfiguration(basicInfo);
clfCallbackConfigurationRepository.save(clfCallbackConfiguration);
clfOrderCallbackRepository.save(clfOrderCallBackList);
} else {
// update
BeanUtils.copyProperties(channelConfiguration, channelConfigurationExsit, IgnorePropertiesUtil.getNullPropertyNames(channelConfiguration));
clfChannelConfigurationRepository.save(channelConfigurationExsit);
clfOrderCallbackRepository.save(clfOrderCallBackList);
}
return true;
}
} }
package cn.quantgroup.cashloanflowboss.api.order.controller;
import cn.quantgroup.cashloanflowboss.api.order.model.ApproveVo;
import cn.quantgroup.cashloanflowboss.api.order.service.OrderService;
import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit;
import cn.quantgroup.cashloanflowboss.core.annotation.CheckChannelRole;
import cn.quantgroup.cashloanflowboss.core.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
/**
* function:
* date: 2019/8/8
* @author: suntao
*/
@RestController
@RequestMapping("/order")
public class OrderController {
@Autowired
private OrderService orderService;
@ChannelIdInit
@CheckChannelRole
@GetMapping("/info")
public Result getOrders(Long channelId, String channelOrderNumber, Integer pageNumber, Integer pageSize) {
return Result.buildSuccess(orderService.getOrders(channelId, channelOrderNumber, pageNumber, pageSize));
}
@ChannelIdInit
@CheckChannelRole
@PostMapping("/approve")
public Result approveOpt(@RequestBody @Valid ApproveVo approveVo) {
return Result.buildSuccess(orderService.approveOpt(approveVo));
}
}
package cn.quantgroup.cashloanflowboss.api.order.model;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* function:
* date: 2019/8/8
*
* @author: suntao
*/
@Data
public class ApproveVo {
@NotNull(message = "审批,订单号不能为空")
private String channelOrderNumber;
@NotNull(message = "审批,金额不能为空")
private String amount;
@NotNull(message = "审批,期数不能为空")
private Integer period;
@NotNull(message = "审批,资金类型不能为空")
private Integer fundType;
@NotNull(message = "审批,期望mock结果不能为空")
private Boolean isPass;
}
package cn.quantgroup.cashloanflowboss.api.order.model;
import lombok.Data;
/**
* function:
* date: 2019/8/8
*
* @author: suntao
*/
@Data
public class OrderVo {
private Long id;
private Long channelId;
private String channelOrderNumber;
private Long createdAt;
private String status;
/**
* [ {action:"audit",name:"审核"},{},{}... ]
*/
private String opt;
private String message;
@Data
public static class OptButton {
private String action;
private String name;
}
public enum OptButtonAction {
audit("审批"),
cancel("贷前关单"),
pay_succ("放款成功"),
pay_fail("放款失败"),
withdraw2_succ("二次提现成功"),
cancel_after("贷后关单");
OptButtonAction(String desc) {
this.desc = desc;
}
private String desc;
public String getDesc(){
return this.desc;
}
}
}
package cn.quantgroup.cashloanflowboss.api.order.service;
import cn.quantgroup.cashloanflowboss.api.channel.entity.boss.ChannelConf;
import cn.quantgroup.cashloanflowboss.api.channel.repository.boss.ChannelConfRepository;
import cn.quantgroup.cashloanflowboss.api.order.model.ApproveVo;
import cn.quantgroup.cashloanflowboss.api.order.model.OrderVo;
import cn.quantgroup.cashloanflowboss.api.order.util.OrderUtil;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService;
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.user.service.XyqbUserService;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import cn.quantgroup.user.retbean.XUser;
import lombok.extern.slf4j.Slf4j;
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.stereotype.Service;
import javax.persistence.criteria.Predicate;
import java.util.*;
/**
* function:
* date: 2019/8/8
*
* @author: suntao
*/
@Slf4j
@Service
public class OrderService {
@Autowired
private UserSessionService userSessionService;
@Autowired
private ChannelConfRepository channelConfRepository;
@Autowired
private ClfOrderMappingRepository clfOrderMappingRepository;
@Autowired
private XyqbUserService xyqbUserService;
@Autowired
private ClothoCenter clothoCenter;
public Page<OrderVo> getOrders(Long channelId, String channelOrderNo, Integer pageNumber, Integer pageSize) {
Page<ClfOrderMapping> page = this.clfOrderMappingRepository.findAll((root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
// 指定渠道号
if (Objects.nonNull(channelId)) {
predicates.add(criteriaBuilder.equal(root.get("registeredFrom"), channelId.longValue()));
}
if (StringUtils.isNotEmpty(channelOrderNo)) {
predicates.add(criteriaBuilder.equal(root.get("channelOrderNo"), channelOrderNo));
}
// 设置查询条件
criteriaQuery.where(criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()])));
// 指定排序
criteriaQuery.orderBy(criteriaBuilder.desc(root.get("id")));
return criteriaQuery.getRestriction();
}, new PageRequest(pageNumber, pageSize));
return page.map(it-> {
OrderVo orderVo = new OrderVo();
orderVo.setId(it.getId());
orderVo.setChannelId(it.getRegisteredFrom());
orderVo.setChannelOrderNumber(it.getChannelOrderNo());
orderVo.setCreatedAt(it.getCreatedAt().getTime());
OrderVo.OptButton button = new OrderVo.OptButton();
button.setAction(OrderVo.OptButtonAction.audit.name());
button.setName(OrderVo.OptButtonAction.audit.getDesc());
orderVo.setStatus(OrderVo.OptButtonAction.audit.getDesc());
orderVo.setOpt(JSONTools.serialize(button));
orderVo.setMessage("");
return orderVo;
});
}
public Boolean approveOpt(ApproveVo approveVo) {
ClfOrderMapping orderMapping = clfOrderMappingRepository.findByChannelOrderNoLastOne(approveVo.getChannelOrderNumber());
if (orderMapping == null) {
log.info("approveOpt,审批失败,无订单 channelOrderNumber={}", approveVo.getChannelOrderNumber());
return false;
}
UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
if (!userSessionInfo.getChannelId().equals(orderMapping.getRegisteredFrom())) {
}
XUser xUser = xyqbUserService.findXUserById(orderMapping.getQgUserId());
if (xUser == null) {
log.info("approveOpt,审批失败,未找到用户 channelOrderNumber={}", approveVo.getChannelOrderNumber());
return false;
}
ChannelConf channelConf = channelConfRepository.getByChannelId(orderMapping.getRegisteredFrom());
if (channelConf == null) {
log.info("approveOpt,审批失败,boss渠道配置为空 channelOrderNumber={}", approveVo.getChannelOrderNumber());
return false;
}
// 额度有效期
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.DAY_OF_YEAR, 7);
// 资方 及 期数额度规则
Integer fundType = approveVo.getFundType();
Integer fundId;
if (fundType == 0) {
fundId = channelConf.getFundId();
} else {
fundId = channelConf.getP2pFundId();
}
String fundFormat = String.format(OrderUtil.financeProductsFormat, approveVo.getAmount(), approveVo.getAmount(),
approveVo.getPeriod(), fundId);
Map<String, Object> data = new HashMap<>(16);
data.put("code", 0);
data.put("msg", "success");
data.put("bizChannel", orderMapping.getRegisteredFrom());
data.put("uuid", xUser.getUuid());
data.put("bizNo", orderMapping.getChannelOrderNo());
data.put("bizType", channelConf.getBizType());
data.put("auditResult", approveVo.getIsPass());
data.put("amount", approveVo.getAmount());
data.put("deadLine", calendar.getTime().getTime());
data.put("financeProducts", fundFormat);
String approveResult = clothoCenter.approve(data);
if ("success".equals(approveResult)) {
return true;
} else {
return false;
}
}
}
package cn.quantgroup.cashloanflowboss.api.order.util;
/**
* function:
* date: 2019/8/8
*
* @author: suntao
*/
public class OrderUtil {
public static final String financeProductsFormat = "[{\"min\":%s,\"max\":%s,\"terms\":[{\"term\":%s,\"fundInfo\":[{\"fundId\":%s,\"rate\":\"0\",\"rateType\":1,\"priority\":\"1\",\"feeType\":\"1\"}]}]}]";
}
package cn.quantgroup.cashloanflowboss.api.test.controller; package cn.quantgroup.cashloanflowboss.api.test.controller;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User; import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserService; import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService;
import cn.quantgroup.cashloanflowboss.core.base.Result; import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -14,11 +14,11 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -14,11 +14,11 @@ import org.springframework.web.bind.annotation.RestController;
public class TestController { public class TestController {
@Autowired @Autowired
private UserService userService; private UserSessionService userSessionService;
@GetMapping("/user/info") @GetMapping("/user/info")
public Result findUserFromSession() { public Result findUserFromSession() {
User currentUser = userService.findCurrentUser(); UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
return new Result<>(ApplicationStatus.SUCCESS, currentUser); return new Result<>(ApplicationStatus.SUCCESS, userSessionInfo);
} }
} }
package cn.quantgroup.cashloanflowboss.api.user.entity.boss;
import cn.quantgroup.cashloanflowboss.core.persistence.Primary;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Data
@Entity
@Table(name = "channel_user")
public class ChannelUser extends Primary {
@Column(name = "channel_id")
private Long channelId;
@Column(name = "user_id")
private Long userId;
}
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 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; package cn.quantgroup.cashloanflowboss.api.user.model;
import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@Data @Data
@Builder @Builder
@AllArgsConstructor
public class UserSessionInfo { public class UserSessionInfo {
private String userName; private UserInfo userInfo;
private String roleName; private RoleInfo roleInfo;
private Long channelId; private Long channelId;
} }
package cn.quantgroup.cashloanflowboss.api.user.repository.boss;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.ChannelUser;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
/**
* Created by WeiWei on 2019/7/22.
*/
@Repository
public interface ChannelUserRepository extends PagingAndSortingRepository<ChannelUser, String> {
ChannelUser findByUserId(Long userId);
}
package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.ChannelUser;
import cn.quantgroup.cashloanflowboss.api.user.repository.boss.ChannelUserRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class ChannelUserService {
@Autowired
private ChannelUserRepository channelUserRepository;
public ChannelUser findChannelUserByUserId(Long userId) {
return channelUserRepository.findByUserId(userId);
}
}
...@@ -2,6 +2,7 @@ package cn.quantgroup.cashloanflowboss.api.user.service; ...@@ -2,6 +2,7 @@ package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus; import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User; import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.api.user.repository.boss.UserRepository; import cn.quantgroup.cashloanflowboss.api.user.repository.boss.UserRepository;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert; import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary;
...@@ -137,12 +138,4 @@ public class UserService { ...@@ -137,12 +138,4 @@ public class UserService {
} }
public User findCurrentUser() {
HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
Assert.isNull(session.getAttribute(ApplicationDictionary.USER_KEY), ApplicationStatus.INVALID_USER);
User user = JSONTools.deserialize(String.valueOf(session.getAttribute(ApplicationDictionary.USER_KEY)), new TypeReference<User>() {
});
return user;
}
} }
package cn.quantgroup.cashloanflowboss.api.user.service; package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.role.entity.boss.Permission;
import cn.quantgroup.cashloanflowboss.api.role.entity.boss.Role;
import cn.quantgroup.cashloanflowboss.api.role.service.RoleService;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.ChannelUser;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User; import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User;
import cn.quantgroup.cashloanflowboss.api.user.model.RoleInfo;
import cn.quantgroup.cashloanflowboss.api.user.model.UserInfo;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo; import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.component.security.Authority;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.utils.JSONTools; import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import java.util.Arrays;
@Slf4j @Slf4j
@Service @Service
public class UserSessionService { public class UserSessionService {
@Autowired
private RoleService roleService;
@Autowired
private ChannelUserService channelUserService;
public void setUserSessionInfo(User user) { public void setUserSessionInfo(User user) {
//set user,role,channel or permission info
Role role = roleService.findRoleByUserId(user.getId());
String roleName = null, userName = user.getUsername();
Long roleId = null, channelId = null, userId = user.getId();
if (null != role) {
roleName = role.getName();
roleId = role.getId();
}
ChannelUser channelUser = channelUserService.findChannelUserByUserId(userId);
if (null != channelUser) {
channelId = channelUser.getChannelId();
}
UserSessionInfo userSessionInfo = UserSessionInfo.builder()
.roleInfo(RoleInfo.builder().roleId(roleId).roleName(roleName).build())
.userInfo(UserInfo.builder().userId(userId).userName(userName).build())
.channelId(channelId)
.build();
HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession(); HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
session.setAttribute(ApplicationDictionary.USER_KEY, JSONTools.serialize(user)); session.setAttribute(ApplicationDictionary.USER_KEY, JSONTools.serialize(userSessionInfo));
//query user role info
//UserSessionInfo.builder() Permission permission = new Permission();
// .userName(user.getUsername()) permission.setId("Log.logout");
// .roleName() permission.setAuthorities(Arrays.asList(Authority.READ));
session.setAttribute(ApplicationDictionary.SECURITY_KEY, JSONTools.serialize(Arrays.asList(permission)));
}
public UserSessionInfo findUserSessionInfo() {
HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
Assert.isNull(session.getAttribute(ApplicationDictionary.USER_KEY), ApplicationStatus.INVALID_USER);
UserSessionInfo userSessionInfo = JSONTools.deserialize(String.valueOf(session.getAttribute(ApplicationDictionary.USER_KEY)), new TypeReference<UserSessionInfo>() {
});
return userSessionInfo;
} }
......
...@@ -37,6 +37,6 @@ public @interface EnableSecurity { ...@@ -37,6 +37,6 @@ public @interface EnableSecurity {
* *
* @return * @return
*/ */
int order() default Ordered.LOWEST_PRECEDENCE; int order() default Ordered.HIGHEST_PRECEDENCE;
} }
package cn.quantgroup.cashloanflowboss.core.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* function:
* date: 2019/8/6
*
* @author: suntao
*/
@Target({METHOD})
@Retention(RUNTIME)
public @interface ChannelIdInit {
}
package cn.quantgroup.cashloanflowboss.core.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* function:
* date: 2019/8/6
*
* @author: suntao
*/
@Target({METHOD})
@Retention(RUNTIME)
public @interface CheckChannelRole {
boolean isObjParam() default false;
Class paramClazz() default Object.class;
}
package cn.quantgroup.cashloanflowboss.core.aspect;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfVo;
import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService;
import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit;
import cn.quantgroup.cashloanflowboss.core.annotation.CheckChannelRole;
import cn.quantgroup.cashloanflowboss.core.base.BossPageImpl;
import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.CodeSignature;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* function:
* date: 2019/8/6
*
* @author: suntao
*/
@Slf4j
@Component
@Aspect
@Order(Ordered.LOWEST_PRECEDENCE)
public class RoleLoadAspect {
@Autowired
private UserSessionService userSessionService;
@Pointcut("execution(* cn.quantgroup.cashloanflowboss.api.channel.controller.*.*(..))")
private void channelController() {}
@Pointcut("execution(* cn.quantgroup.cashloanflowboss.api.order.controller.*.*(..))")
private void orderController() {}
@Pointcut("channelController() || orderController() ")
private void doSomeRole() {}
@Around(value = "doSomeRole()")
public Object around(ProceedingJoinPoint pjp) {
Object[] args = pjp.getArgs();
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method method = methodSignature.getMethod();
// if ("login".equals(method.getName())) {
// try {
// return pjp.proceed(args);
// } catch (Throwable throwable) {
// log.error("请求失败,e={}", ExceptionUtils.getStackTrace(throwable));
// return Result.buildFial();
// }
// }
// 如果是渠道用户登陆 默认加载channelId
ChannelIdInit annotation = method.getAnnotation(ChannelIdInit.class);
UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
final Long channelIdInSession = userSessionInfo.getChannelId();
if (annotation != null && ChannelConfUtil.channelRoleName.equals(userSessionInfo.getRoleInfo().getRoleName())) {
String[] paramNames = ((CodeSignature)pjp.getSignature()).getParameterNames();
for (int i = 0; i < paramNames.length; i++) {
if (ChannelConfUtil.channelIdParamName.equals(paramNames[i])) {
args[i] = channelIdInSession;
}
}
}
// 如果是渠道用户登陆,参数中channelId 不是登陆用户channelId,返回 拒绝请求
CheckChannelRole checkChannelRole = method.getAnnotation(CheckChannelRole.class);
if (checkChannelRole != null && ChannelConfUtil.channelRoleName.equals(userSessionInfo.getRoleInfo().getRoleName())) {
Integer requestChannelId = -1;
if (!checkChannelRole.isObjParam()) {
String[] paramNames = ((CodeSignature)pjp.getSignature()).getParameterNames();
for (int i = 0; i < paramNames.length; i++) {
// 是简单类型,多个参数 直接参数channelId
if (ChannelConfUtil.channelIdParamName.equals(paramNames[i])) {
// 找到channelId是第几个参数 i
Object requestChannelIdObj = args[i];
if (requestChannelIdObj == null) {
log.info("[CheckChannelRole]无channelId数据");
return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION);
}
requestChannelId = Integer.valueOf(String.valueOf(requestChannelIdObj));
if (requestChannelId != channelIdInSession.intValue()) {
log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个");
return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY);
}
}
}
} else {
Class paramClazz = checkChannelRole.paramClazz();
if (paramClazz == ChannelConfVo.class) {
ChannelConfVo confVo = (ChannelConfVo) args[0];
final Long channelIdTemp = confVo.getBasicInfo().getChannelId();
if (channelIdTemp == null) {
log.info("[CheckChannelRole]无channelId数据");
return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION);
}
requestChannelId = channelIdTemp.intValue();
}
}
if (requestChannelId != channelIdInSession.intValue()) {
log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个");
return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY);
}
}
// ======================================== CheckChannelRole end ==========================================
try {
return pjp.proceed(args);
} catch (Throwable throwable) {
log.error("请求失败,e={}", ExceptionUtils.getStackTrace(throwable));
return Result.buildFial();
}
}
}
package cn.quantgroup.cashloanflowboss.core.base;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import java.util.Iterator;
import java.util.List;
/**
* function:
* date: 2019/8/6
*
* @author: suntao
*/
public class BossPageImpl<T> implements Page {
@Override
public int getTotalPages() {
return 0;
}
@Override
public long getTotalElements() {
return 0;
}
@Override
public Page map(Converter converter) {
return null;
}
@Override
public int getNumber() {
return 0;
}
@Override
public int getSize() {
return 0;
}
@Override
public int getNumberOfElements() {
return 0;
}
@Override
public List getContent() {
return null;
}
@Override
public boolean hasContent() {
return false;
}
@Override
public Sort getSort() {
return null;
}
@Override
public boolean isFirst() {
return false;
}
@Override
public boolean isLast() {
return false;
}
@Override
public boolean hasNext() {
return false;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public Pageable nextPageable() {
return null;
}
@Override
public Pageable previousPageable() {
return null;
}
@Override
public Iterator iterator() {
return null;
}
}
...@@ -68,6 +68,21 @@ public class Result<T> { ...@@ -68,6 +68,21 @@ public class Result<T> {
return new Result(ApplicationStatus.FAILURE, data); return new Result(ApplicationStatus.FAILURE, data);
} }
@SuppressWarnings("unchecked")
public static<T> Result buildFial(String message) {
return new Result(ApplicationStatus.FAILURE, null, message);
}
@SuppressWarnings("unchecked")
public static<T> Result buildFial() {
return new Result(ApplicationStatus.FAILURE, null, null);
}
@SuppressWarnings("unchecked")
public static<T> Result buildFial(ApplicationStatus applicationStatus) {
return new Result(applicationStatus, null, null);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static<T> Result buildFial(T data, String message) { public static<T> Result buildFial(T data, String message) {
return new Result(ApplicationStatus.FAILURE, data, message); return new Result(ApplicationStatus.FAILURE, data, message);
......
...@@ -20,29 +20,28 @@ import javax.persistence.EntityManagerFactory; ...@@ -20,29 +20,28 @@ import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource; import javax.sql.DataSource;
@Configuration @Configuration
@EntityScan(basePackages = {"cn.quantgroup.cashloanflowboss.api.*.entity.clf"})
@EnableTransactionManagement @EnableTransactionManagement
@EnableJpaRepositories(basePackages = {"cn.quantgroup.cashloanflowboss.api.*.repository.clf"}, @EnableJpaRepositories(basePackages = {"cn.quantgroup.cashloanflowboss.spi.clf.repository"},
entityManagerFactoryRef = "clfEntityManager", entityManagerFactoryRef = "clfEntityManager",
transactionManagerRef = "clfTransactionManager") transactionManagerRef = "clfTransactionManager")
public class ClfDSConfig { public class ClfDSConfig {
@Value("${data.boss.url}") @Value("${data.clf.url}")
private String jdbcUrl; private String jdbcUrl;
@Value("${data.boss.password}") @Value("${data.clf.password}")
private String password; private String password;
@Value("${data.boss.username}") @Value("${data.clf.username}")
private String user; private String user;
private String uniquename = "bossDS"; private String uniquename = "clfDS";
@Value("${data.boss.pool-size}") @Value("${data.clf.pool-size}")
private Integer poolSize; private Integer poolSize;
@Bean(name = "clfDataSource") @Bean(name = "clfDataSource")
@ConfigurationProperties(prefix = "data.boss") @ConfigurationProperties(prefix = "data.clf")
public DataSource createDataSource() { public DataSource createDataSource() {
DruidDataSource source = DruidDataSourceBuilder.create().build(); DruidDataSource source = DruidDataSourceBuilder.create().build();
source.setMaxActive(200); source.setMaxActive(200);
...@@ -63,7 +62,7 @@ public class ClfDSConfig { ...@@ -63,7 +62,7 @@ public class ClfDSConfig {
public LocalContainerEntityManagerFactoryBean entityManager(EntityManagerFactoryBuilder builder) { public LocalContainerEntityManagerFactoryBean entityManager(EntityManagerFactoryBuilder builder) {
return builder.dataSource(createDataSource()) return builder.dataSource(createDataSource())
.packages("cn.quantgroup.cashloanflowboss.api.*.entity.clf") .packages("cn.quantgroup.cashloanflowboss.spi.clf.entity")
.persistenceUnit(uniquename) .persistenceUnit(uniquename)
.build(); .build();
} }
......
package cn.quantgroup.cashloanflowboss.spi.clf.entity;
import cn.quantgroup.cashloanflowboss.spi.clf.model.CallbackRouter;
import lombok.*;
import javax.persistence.*;
import java.io.Serializable;
/**
* Created by liqing on 2017/5/5 0005.
*/
@Setter
@Getter
@Entity
@Table(name = "callback_configuration",catalog = "cash_loan_flow")
public class ClfCallbackConfiguration implements Serializable {
private static final long serialVersionUID = -1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "channel_id")
private Long channelId;
@Column(name = "is_loan_makeup")
private Boolean isLoanMakeup;
@Column(name = "is_repay_makeup")
private Boolean isRepayMakeup;
@Column(name = "loan_makeup_strategy")
private String loanMakeupStrategy;
@Column(name = "repay_makeup_strategy")
private String repayMakeupStrategy;
@Column(name = "is_active")
private Boolean isActive;
@Column(name = "only_new_user")
private Boolean onlyNewUser;
@Column(name = "callback_service_name")
private String callbackServiceName;
@Column(name = "callback_no_push_progress")
private String callbackNoPushProgress;
@Column(name = "pre_progress")
private String preProgress;
@Column(name = "retry_max_times")
private Long retryMaxTimes;
@Enumerated(EnumType.ORDINAL)
@Column(name = "callback_router")
private CallbackRouter callbackRouter;
}
package cn.quantgroup.cashloanflowboss.api.channel.entity.clf; package cn.quantgroup.cashloanflowboss.spi.clf.entity;
import cn.quantgroup.cashloanflowboss.api.channel.model.clf.EncType; import cn.quantgroup.cashloanflowboss.spi.clf.model.EncType;
import lombok.Data; import lombok.Data;
import javax.persistence.*; import javax.persistence.*;
...@@ -13,7 +13,7 @@ import java.sql.Timestamp; ...@@ -13,7 +13,7 @@ import java.sql.Timestamp;
@Data @Data
@Entity @Entity
@Table(name = "channel_configuration", catalog = "cash_loan_flow") @Table(name = "channel_configuration", catalog = "cash_loan_flow")
public class ChannelConfiguration implements Serializable { public class ClfChannelConfiguration implements Serializable {
private static final long serialVersionUID = -1L; private static final long serialVersionUID = -1L;
@Id @Id
......
package cn.quantgroup.cashloanflowboss.spi.clf.entity;
import cn.quantgroup.cashloanflowboss.spi.clf.model.KANoticeType;
import cn.quantgroup.cashloanflowboss.spi.clf.model.LoanProgress;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* Created by 11 on 2016/11/29.
*/
@Data
@Entity
@Table(name = "order_callback")
public class ClfOrderCallBack implements Serializable{
private static final long serialVersionUID = -1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "loan_id")
private Long loanId;
@Column(name = "progress")
private LoanProgress progress;
@Column(name = "callback_status")
@Enumerated(EnumType.STRING)//保存字面值到数据库
private KANoticeType callbackStatus;
@Column(name = "registered_from")
private Long registeredFrom;
@Column(name = "callback_url")
private String callbackUrl;
@Column(name = "is_active")
private Boolean isActive = Boolean.TRUE;
@Column(name = "created_at")
private Timestamp createdAt = new Timestamp(System.currentTimeMillis());
}
\ No newline at end of file
package cn.quantgroup.cashloanflowboss.spi.clf.entity;
import lombok.Data;
import javax.persistence.*;
import java.sql.Timestamp;
/**
*
*/
@Data
@Entity
@Table(name = "order_mapping",catalog = "cash_loan_flow" )
public class ClfOrderMapping {
private static final long serialVersionUID = -1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "channel_order_no")
private String channelOrderNo;
@Column(name = "channel_payment_no")
private String channelPaymentNo;
@Column(name = "apply_no")
private String applyNo;
@Column(name = "loan_id")
private Long loanId;
@Column(name = "registered_from")
private Long registeredFrom;
@Column(name = "order_extend")
private String orderExtend;
@Column(name = "qg_user_id")
private Long qgUserId;
@Column(name = "payment_at")
private Timestamp paymentAt;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updatedAt;
}
package cn.quantgroup.cashloanflowboss.spi.clf.model;
/**
* Created with suntao on 2018/11/14
*/
public enum CallbackRouter {
API,
COMMON
}
package cn.quantgroup.cashloanflowboss.api.channel.model.clf; package cn.quantgroup.cashloanflowboss.spi.clf.model;
/** /**
* Created by liqing on 2017/4/26 0026. * Created by liqing on 2017/4/26 0026.
......
package cn.quantgroup.cashloanflowboss.spi.clf.model;
/**
* 对应 MQ 消息通知类型 的枚举类,在数据库中保存,和QuotaNoticeType 独立,保证xyqb改动的灵活性
* Created with suntao on 2018/4/15
*/
public enum KANoticeType {
CREDIT_SUCC("CREDIT_SUCC", "授信成功"),//0
CREDIT_FAIL("CREDIT_FAIL", "授信失败"),//1
FUAD_ASSIFN_SUCC("FUAD_ASSIFN_SUCC", "分配资金方成功"),//2
FUAD_ASSIFN_FAIL("FUAD_ASSIFN_FAIL", "分配资金方失败"),//3
BIND_SUCC("BIND_SUCC", "绑卡成功"),//4
BIND_FAIL("BIND_FAIL", "绑卡失败"),//5
WAITING_FUND("WAITING_FUND", "进件给资金方成功,等待放款"),//6
FUND_SUCC("FUND_SUCC", "放款成功"),//7
FUND_WITHDRAW_SUCC("FUND_WITHDRAW_SUCC", "放款提现成功,存管提现成功"),//8
FUND_FAIL("FUND_FAIL", "放款失败"),//9
REPAYMENT("REPAYMENT", "还款成功"),//10
ALL_REPAID("ALL_REPAID", "结清"),//11
QUOTA_INCREASE("QUOTA_INCREASE", "额度提升"),//12
QUOTA_DECREASE("QUOTA_DECREASE", "额度下降"),//13
QUOTA_FREEZE("QUOTA_FREEZE", "风控额度冻结"),//14
WITHDRAW("WITHDRAW", "用户提现额度冻结"),//WITHDRAW,创建loanId,//15(BIND_SUCC 同时发送)
REJECT("REJECT", "风控审核不通过"),//16
RISK_PASS("RISK_PASS", "风控审核通过"),//17
INCREASE_CHANGE("INCREASE_CHANGE", "利率调整"),//18
CANCEL_LOAN("CANCEL_LOAN", "关闭订单"),//19
COMPENSATORY("COMPENSATORY", "代偿"),//20
DROP_COURSE("DROP_COURSE", "退课代偿"),//21
CANCEL_AFTER_LOAN("CANCEL_AFTER_LOAN", "贷后关闭订单"),//22
ADD_CARD_SUCCESS("ADD_CARD_SUCCESS", "添加银行卡成功,非提现页面绑卡"), //23
REPAY_FAIL("REPAY_FAIL", "还款失败"), //24
UNKNOWN("UNKNOWN", "没有逻辑意义的数据库兼容的值"),
RP_INIT_F_SUCC("REPAYMENT_INIT_FUND_SUCC", "放款成功推送还款计划"),
APPROVE_ING("APPROVE_ING", "审批中"),
PAY_ING("PAY_ING", "放款中"),
TEST("TEST", "test");
private String type;
private String desc;
KANoticeType(String type, String desc) {
this.type = type;
this.desc = desc;
}
public static KANoticeType getOrdinalValue(Integer ordinal) {
KANoticeType[] values = values();
for (int i = 0; i < values.length; i++) {
if (values[i].ordinal() == ordinal) {
return values[i];
}
}
return null;
}
public String getType() {
return this.type;
}
public String getDesc() {
return this.desc;
}
}
package cn.quantgroup.cashloanflowboss.spi.clf.model;
import com.google.common.collect.Sets;
import java.util.Set;
/**
* Created by Miraculous on 15/7/12.
*/
public enum LoanProgress {
/**
* 不会被持久化到数据库
*/
USERINFO_INCOMPLETE("用户未填写个人信息"),//0
USER_INFORMATION_INCOMPLETE("用户未填写贷款信息"),//1
USER_AUTHENTICATION_INCOMPLETE("用户授权信息未全部完成"),//2
USER_AUTHENTICATION_COMPLETE("授权状态完成"),//3
FURTHER_INFORMATION_INCOMPLETE("用户补充资料未完成"),//4
PRE_SCREENING("初审中"),//5
PRE_SCREENING_REJECT("初审拒绝"),//6
FINAL_SCREENING("终审中"),//7
FINAL_SCREENING_REJECT("终审拒绝"),//8
LOAN_APPLICATION_MANIFEST_COMPLETE("借款清单生成完成"),//9
BIND_BANKCARD("确认借款并且去绑卡"),//10
BIND_BANKCARD_SUCCESS("绑卡成功"),//11
QUIT_AND_SHOW_REASON("放弃借款"),//12
SIGN_CONTRACT("签订协议"),//13
FUND_TRANSFER("打款"),//14
CHECK_REPAYMENT_PLAN("查看还款计划"),//15
LOAN_COMPLETE("借款完成"),//16
FILTERED_BY_BLACKLIST("黑名单过滤"),//17
FINAL_SCREENING_PASSED("后台终审通过"),//18
FILTERING_DECLINED("未通过初筛"),//19
WAITING_FUND("等待资金方放款"),// 20
FINAL_SEND_TO_MASHANG_BEFORE_APPROVAL("已发送给马上金融, 等待放款"),//21, 发邮件后更新使用
FINAL_MASHANG_APPROVAL_SUCCESS("马上金融放款成功"),//22
FINAL_FUNDED_APPROVAL_FAIL("马上金融放款失败"),//23,
ADDRESS_COMPLETE("地址填写完毕,去绑卡"), // 24
BEIYIN_USERINFO_INCOMPLETE("北银消费-用户未填写个人信息"),//25
BEIYIN_USER_FILE_INCOMPLETE("北银消费-用户未上传文件"),//26
BEIYIN_SCREENING("北银消费-审批中"),//27
BEIYIN_SCREENING_FAILED("北银消费-审批失败"),//28
BEIYIN_SCREENING_PASSED("北银消费-审批通过"),//29
BEIYIN_LOAN_COMPLETE("北银消费-借款完成"),//30
BAITIAO_AUTHENTICATION_TAOBAO("白条-淘宝授权"),//31
BAITIAO_AUTHENTICATION_MOBILE("白条-手机运营商授权"),//32
BAITIAO_SCREENING("白条-审核中"),//33
BAITIAO_FILTER_PASSED("白条-初筛通过"),//34
BAITIAO_SCREENING_FAILED("白条-审核拒绝"),//35
BAITIAO_SCREENING_PASSED("白条-审核通过"),//36
BAITIAO_BIND_CARD("白条-绑卡"),//37
BAITIAO_BIND_CARD_ING("白条-绑卡中"),//38
BAITIAO_ACTIVATE_SUCC("白条-激活成功"),//39
/**
* 修改时间 20160104 资金方解耦
*/
// category 4x
/* 易联校验/代收订单 异步通知重构 */
BIND_BANKCARD_IN_PROGRESS("绑卡处理中"),//40
/*REPAY_ORDER_IN_PROGRESS("还款处理中")*/
USER_RELATION_INCOMPLETE("与用户相关联系人信息未完成"),//41,
PLACE_HOLDER_42("占位"),PLACE_HOLDER_43("占位"),PLACE_HOLDER_44("占位"),
PLACE_HOLDER_45("占位"),PLACE_HOLDER_46("占位"),PING_AN_PAGE("跳转平安填写信息页面"),// 47
DROP_SUCC("取消借款"),//48
PLACE_HOLDER_49("占位"),
// category 5x
PLACE_HOLDER_50("占位"),PLACE_HOLDER_51("占位"),PLACE_HOLDER_52("占位"),PLACE_HOLDER_53("占位"),PLACE_HOLDER_54("占位"),
PLACE_HOLDER_55("占位"),PLACE_HOLDER_56("占位"),PLACE_HOLDER_57("占位"),PLACE_HOLDER_58("占位"),PLACE_HOLDER_59("占位"),
// category 6x
PLACE_HOLDER_60("占位"),PLACE_HOLDER_61("占位"),PLACE_HOLDER_62("占位"),PLACE_HOLDER_63("占位"),PLACE_HOLDER_64("占位"),
WAITING_WITHDRAW("待存管提现"),// 65
PLACE_HOLDER_66("占位"),PLACE_HOLDER_67("占位"),PLACE_HOLDER_68("占位"),PLACE_HOLDER_69("占位"),
// category 7x
PLACE_HOLDER_70("占位"),PLACE_HOLDER_71("占位"),PLACE_HOLDER_72("占位"),PLACE_HOLDER_73("占位"),PLACE_HOLDER_74("占位"),
PLACE_HOLDER_75("占位"),PLACE_HOLDER_76("占位"),PLACE_HOLDER_77("占位"),PLACE_HOLDER_78("占位"),PLACE_HOLDER_79("占位"),
// category 8x
PLACE_HOLDER_80("占位"),PLACE_HOLDER_81("占位"),PLACE_HOLDER_82("占位"),PLACE_HOLDER_83("占位"),PLACE_HOLDER_84("占位"),
PLACE_HOLDER_85("占位"),PLACE_HOLDER_86("占位"),PLACE_HOLDER_87("占位"),PLACE_HOLDER_88("占位"),PLACE_HOLDER_89("占位"),
// category 9x
PLACE_HOLDER_90("占位"),PLACE_HOLDER_91("占位"),PLACE_HOLDER_92("占位"),PLACE_HOLDER_93("占位"),PLACE_HOLDER_94("占位"),
PLACE_HOLDER_95("占位"),PLACE_HOLDER_96("占位"),PLACE_HOLDER_97("占位"),PLACE_HOLDER_98("占位"),PLACE_HOLDER_99("占位"),
/**
* 资金方相关
*/
// 等待资金方放款 : 100
WAITING_MASHANG_FUND("等待马上金融放款"),// 100, 发邮件前查询使用
// 已提交给资金方等待放款 : 101
SENDED_TO_FUND_CORP("已提交给资金方"),
// category 10x
PLACE_HOLDER_102("占位"),PLACE_HOLDER_103("占位"),PLACE_HOLDER_104("占位"),PLACE_HOLDER_105("占位"),PLACE_HOLDER_106("占位"),
PLACE_HOLDER_107("占位"),PLACE_HOLDER_108("占位"),PLACE_HOLDER_109("占位"),
JD_BANDCARD_FAIL("京东绑卡失败")//110 京东绑卡失败状态
;
private String description;
LoanProgress(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return description;
}
/**
* 获取审核拒绝状态
* @return
*/
public static Set<LoanProgress> getCheckReject(){
return Sets.newHashSet(LoanProgress.FILTERING_DECLINED, LoanProgress.PRE_SCREENING_REJECT,
LoanProgress.FINAL_SCREENING_REJECT, LoanProgress.FILTERED_BY_BLACKLIST);
}
/**
* 获取推送订单状态
* @return
*/
public static Set<LoanProgress> getFeedBackOrderStatus(){
return Sets.newHashSet(LoanProgress.WAITING_FUND, LoanProgress.FINAL_SEND_TO_MASHANG_BEFORE_APPROVAL,
LoanProgress.FINAL_FUNDED_APPROVAL_FAIL, LoanProgress.CHECK_REPAYMENT_PLAN, LoanProgress.LOAN_COMPLETE);
}
}
package cn.quantgroup.cashloanflowboss.spi.clf.repository;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfCallbackConfiguration;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* function:
* date: 2019/8/7
*
* @author: suntao
*/
public interface ClfCallbackConfigurationRepository extends JpaRepository<ClfCallbackConfiguration, Long> {
}
package cn.quantgroup.cashloanflowboss.api.channel.repository.clf; package cn.quantgroup.cashloanflowboss.spi.clf.repository;
import cn.quantgroup.cashloanflowboss.api.channel.entity.clf.ChannelConfiguration; import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfChannelConfiguration;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface ChannelConfigurationRepository extends PagingAndSortingRepository<ChannelConfiguration, Long>, JpaSpecificationExecutor<ChannelConfiguration> { public interface ClfChannelConfigurationRepository extends PagingAndSortingRepository<ClfChannelConfiguration, Long>, JpaSpecificationExecutor<ClfChannelConfiguration> {
ClfChannelConfiguration findByRegisteredFrom(Long channelId);
} }
package cn.quantgroup.cashloanflowboss.spi.clf.repository;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderCallBack;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* function:
* date: 2019/8/7
*
* @author: suntao
*/
public interface ClfOrderCallbackRepository extends JpaRepository<ClfOrderCallBack, Long> {
}
package cn.quantgroup.cashloanflowboss.spi.clf.repository;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderMapping;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.sql.Timestamp;
import java.util.List;
public interface ClfOrderMappingRepository extends PagingAndSortingRepository<ClfOrderMapping, Long>, JpaSpecificationExecutor<ClfOrderMapping> {
List<ClfOrderMapping> findByChannelOrderNoAndRegisteredFrom(String channelOrderNo, Long registeredFrom);
ClfOrderMapping findByChannelPaymentNoAndRegisteredFrom(String channelOrderNo, Long registeredFrom);
List<ClfOrderMapping> findByApplyNo(String applyNo);
@Query(value = "select * from order_mapping where apply_no =?1 ORDER BY id DESC limit 1", nativeQuery = true)
ClfOrderMapping findByApplyNoLastOne(String applyNo);
ClfOrderMapping findByLoanId(long loanApplicationHistoryId);
ClfOrderMapping findByChannelOrderNoAndChannelPaymentNo(String channelOrderNo, String paymentNo);
@Query(value = "select * from order_mapping where channel_order_no =?1 AND order_extend like ?2 limit 1", nativeQuery = true)
ClfOrderMapping findByChannelOrderNoAndChannelPaymentNoInOrderExtend(String channelOrderNo, String channelPaymentNo);
@Query(value = "select * from order_mapping where loan_id IN ?1 AND registered_from = ?2", nativeQuery = true)
List<ClfOrderMapping> findChannelOrderNoByLoanIdList(List<String> loanIdList, Long registeredFrom);
@Query(value = "select * from order_mapping where channel_order_no = ?1 AND registered_from = ?2 ORDER BY id DESC limit 1", nativeQuery = true)
ClfOrderMapping findByChannelOrderNoAndRegisteredFromLastOne(String channelApplyNo, Long registeredfrom);
@Query(value = "select * from order_mapping where channel_order_no = ?1 ORDER BY id DESC limit 1", nativeQuery = true)
ClfOrderMapping findByChannelOrderNoLastOne(String channelApplyNo);
@Query(value = "select * from order_mapping where loan_id is NULL AND apply_no = ?1", nativeQuery = true)
ClfOrderMapping findByApplyNoAndLoanIdIsNull(String applyNo);
@Query(value = "select * from order_mapping where created_at >?1 and created_at <=?2 and registered_from =?3 and order_extend is null", nativeQuery = true)
List<ClfOrderMapping> findByCreatedAtBeginAndEndAndRegisteredFrom(Timestamp begin, Timestamp end, Long registeredFrom);
@Query(value = "select * from order_mapping where qg_user_id =?1 and registered_from =?2 ORDER BY id DESC limit 1", nativeQuery = true)
ClfOrderMapping findByUserIdAndRegisteredFromLastOne(Long qgUserId, Long registeredFrom);
@Query(value = "select * from order_mapping where apply_no =?1 and registered_from = ?2 ORDER BY id DESC limit 1", nativeQuery = true)
ClfOrderMapping findByApplyNoAndRegisteredFromLastOne(String applyNo, Long registeredFrom);
@Query(value = "select * from order_mapping where qg_user_id =?1 and registered_from = ?2 ORDER BY created_at ASC", nativeQuery = true)
List<ClfOrderMapping> findByQgUserId(Long qgUserId, Long registeredFrom);
// 监控 begin
@Query(value = "select om.registered_from,count(1) from order_mapping om where om.created_at > ?1 AND om.created_at <= ?2 group by om.registered_from", nativeQuery = true)
List<Object[]> findBetweenCreatedAtGroupByRegisteredFrom(Timestamp begin, Timestamp end);
@Query(value = "select count(1) from order_mapping om where om.created_at > ?1 AND om.created_at <= ?2", nativeQuery = true)
Integer findBetweenCreatedAt(Timestamp begin, Timestamp end);
// 监控 end
}
\ No newline at end of file
package cn.quantgroup.cashloanflowboss.spi.clotho.service;
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;
/**
* function:
* date: 2019/8/9
*
* @author: suntao
*/
@Component
@FeignClient(name = "ClothoServiceCenter", url = "${fund.pay.api-host}", fallback = ClothoCenter.Fallback.class)
public interface ClothoCenter {
@PostMapping(value = "/external/quota/auth_amount_audit/notify", consumes = "application/x-www-form-urlencoded")
String approve(@RequestParam Map approveData);
@Component
class Fallback implements ClothoCenter {
@Override
public String approve(Map approveData) {
return "error";
}
}
}
package cn.quantgroup.cashloanflowboss.spi.model;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.io.Serializable;
/**
* Created by suntao on 18/01/15.
*/
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult<T> implements Serializable {
String ZERO_FILL_TEMPLATE = "%04d";
String SUCCESS_BUSINESS_CODE = "0000";
String SUCCESS_STRING_CODE = "0000";
public static final Long SUCCESS_CODE = 0L;
private String msg = "";
private String code = "0000";
// 业务错误码
private String businessCode = "0000";
private T data = null;
public JsonResult(String msg, Long code, T data) {
this.msg = msg;
this.code = String.format(ZERO_FILL_TEMPLATE, code);
this.data = data;
}
public JsonResult(String msg, Long code, T data, Long businessCode) {
this.msg = msg;
this.code = String.format(ZERO_FILL_TEMPLATE, code);
this.data = data;
this.businessCode = String.format(ZERO_FILL_TEMPLATE, businessCode);
}
/**
* 构造成功的JsonResult
* @param msg String
* @param data Object
* @return JsonResult
*/
@SuppressWarnings("unchecked")
public static<T> JsonResult buildSuccess(String msg, T data) {
return new JsonResult(msg, SUCCESS_CODE, data, 0L);
}
/**
* 构造状态不正确的JsonResult
* @param msg String
* @return JsonResult
*/
@SuppressWarnings("unchecked")
public static JsonResult buildError(String msg) {
return new JsonResult(msg, SUCCESS_CODE, null, 1L);
}
/**
* 构造状态不正确的JsonResult
* @param msg String
* @return JsonResult
*/
@SuppressWarnings("unchecked")
public static<T> JsonResult buildError(String msg, T data) {
return new JsonResult(msg, SUCCESS_CODE, data, 1L);
}
@SuppressWarnings("unchecked")
public static JsonResult buildError(String msg, Long busniessId) {
return new JsonResult(msg, SUCCESS_CODE, null, busniessId);
}
@SuppressWarnings("unchecked")
public static<T> JsonResult buildError(String msg, Long busniessId, T data) {
return new JsonResult(msg, SUCCESS_CODE, data, busniessId);
}
/**
* 是否成功状态
* @return
*/
public boolean isSuccess(){
return SUCCESS_STRING_CODE.equals(this.getCode()) && SUCCESS_BUSINESS_CODE.equals(this.getBusinessCode());
}
public String getMessage() {
return this.msg;
}
@Override
public String toString() {
return JSONTools.serialize(this);
}
}
package cn.quantgroup.cashloanflowboss.spi.user.service;
import cn.quantgroup.user.IUserSdkService;
/**
* Created by Miraculous on 2017/2/15.
*/
public interface UserSysService {
/**
* 获取http调用service
* @return
*/
IUserSdkService getService();
/**
* 获取motan调用service
* @return
*/
IUserSdkService getMotanService();
}
package cn.quantgroup.cashloanflowboss.spi.user.service;
import cn.quantgroup.cashloanflowboss.spi.user.service.UserSysService;
import cn.quantgroup.user.IUserSdkService;
import cn.quantgroup.user.UserSdkServiceFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.impl.client.CloseableHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
/**
* Created by Miraculous on 2017/2/15.
*/
@Service
@Slf4j
public class UserSysServiceImpl implements UserSysService {
@Autowired
@Qualifier("httpClient")
private CloseableHttpClient httpClient;
@Value("${passportapi.http}")
private String passportapiHttp;
private IUserSdkService userSdkService; // http调用sdk
@PostConstruct
private void init() {
userSdkService = UserSdkServiceFactory.generateSDKService(passportapiHttp, httpClient);
}
@Override
public IUserSdkService getService() {
return userSdkService;
}
@Override
public IUserSdkService getMotanService() {
return userSdkService;
}
}
package cn.quantgroup.cashloanflowboss.spi.user.service;
import cn.quantgroup.user.bean.UserInfo;
import cn.quantgroup.user.retbean.XUser;
import cn.quantgroup.user.retbean.XUserDetail;
/**
* Created by Rocky on 2016/6/23.
*/
public interface XyqbUserService {
/**
* 查询用户
*/
XUser findXUserById(Long userId);
/**
* 查询用户detail
*/
XUserDetail findUserDetailByUserId(Long userId);
/**
* get uuid
* @param phoneNo 手机号
* @return String token
*/
String getUuid(String phoneNo);
/**
* 通过手机号码 查询xyqb-user
* @param phoneNo
* @return
*/
XUser findUserByPhoneNo(String phoneNo);
/**
* 判断是否老用户
* @param phoneNo 手机号
* @return 老用户 true;新用户 false
*/
boolean isOldUser(String phoneNo);
/**
* 用户detail信息
* @param uuid
* @return
*/
UserInfo findUserByUuid(String uuid);
}
package cn.quantgroup.cashloanflowboss.spi.user.service;
import cn.quantgroup.cashloanflowboss.spi.util.HttpService;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import cn.quantgroup.cashloanflowboss.utils.MD5Tools;
import cn.quantgroup.user.bean.UserInfo;
import cn.quantgroup.user.retbean.XUser;
import cn.quantgroup.user.retbean.XUserDetail;
import cn.quantgroup.user.vo.UserSysResult;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* Created by Rocky on 2016/6/23.
*/
@Service
public class XyqbUserServiceImpl implements XyqbUserService {
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(XyqbUserServiceImpl.class);
@Autowired
private UserSysService userSysService;
@Autowired
private HttpService httpService;
@Value("${passportapi.http}")
private String passportapiHttp;
private static final ObjectMapper MAPPER = new ObjectMapper();
/**
* 查询用户
*
* @param userId
* @return XyqbUser
*/
@Override
public XUser findXUserById(Long userId) {
UserSysResult<XUser> userSysResult = userSysService.getService().findUserByUserId(userId);
if (!userSysResult.isSuccess() || userSysResult.getData() == null) {
LOGGER.error("用户不存在,userId=[{}]", userId);
return null;
}
return userSysResult.getData();
}
@Override
public XUserDetail findUserDetailByUserId(Long userId) {
UserSysResult<XUserDetail> userDetailResult = userSysService.getService().findUserDetailByUserId(userId);
if (!userDetailResult.isSuccess() || userDetailResult.getData() == null) {
LOGGER.error("[findUserDetailByUserId_{}]向用户中心查询用户详情失败,userId={},result={}", userId, JSONTools.serialize(userDetailResult));
return null;
}
return userDetailResult.getData();
}
@Override
public String getUuid(String phoneNo) {
if (StringUtils.isEmpty(phoneNo)) {
return null;
}
UserSysResult<XUser> user = userSysService.getService().findUserByPhoneNo(phoneNo);
if (Objects.isNull(user) || Objects.isNull(user.getData())) {
return null;
}
return user.getData().getUuid();
}
@Override
public XUser findUserByPhoneNo(String phoneNo) {
UserSysResult<XUser> xuserResult = userSysService.getService().findUserByPhoneNo(phoneNo);
if (xuserResult == null || xuserResult.getData() == null || !xuserResult.isSuccess()) {
LOGGER.info("[findUserByPhoneNo]用户中心无用户信息,phoneNo={},phoneDd5={}", phoneNo, MD5Tools.md5(phoneNo));
return null;
}
return xuserResult.getData();
}
/**
* 判断是否老用户
*
* @param phoneNo 手机号
* @return 老用户 true;新用户 false
*/
@Override
public boolean isOldUser(String phoneNo) {
UserSysResult<XUser> userData = userSysService.getService().findUserByPhoneNo(phoneNo);
if (userData == null) {
LOGGER.error("[user_isOldUser]查询用户失败, phoneNo={}", phoneNo);
return false;
}
if (userData.getData() == null) {
LOGGER.info("[user_isOldUser]没有查询到用户, phoneNo={}", phoneNo);
return false;
} else {
return true;
}
}
/**
* 用户detail信息
*/
@Override
public UserInfo findUserByUuid(String uuid) {
UserSysResult<UserInfo> userInfo = userSysService.getService().findUserInfoByUuid(uuid);
if (!userInfo.isSuccess() || userInfo.getData() == null) {
return null;
}
return userInfo.getData();
}
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.model;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderMapping;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 查询订单状态 model
* Created with suntao on 2018/12/26
*/
@Data
@NoArgsConstructor
public class OrderStatusQueryModel {
/** APPROVE 时 非空,元 */
private String drawTryAmount;
/** APPROVE 时 非空,元 */
private String drawTryTerm;
private ClfOrderMapping orderMapping;
/** 可以为空 */
private QueryType queryType;
public OrderStatusQueryModel(ClfOrderMapping orderMapping) {
this.orderMapping = orderMapping;
}
public enum QueryType {
APPROVE("审批状态查询"),
WITHDRAW("提现状态查询,贷前提现"),
CANCEL_LOAN("取消借款"),
CANCEL_AFTER_LOAN("取消借款,贷后,退款"),
PAY("放款状态查询"),
ALL_REPAID("结清状态查询");
private String desc;
public String getDesc(){
return this.desc;
}
QueryType(String desc) {
this.desc = desc;
}
}
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.model;
import cn.quantgroup.cashloanflowboss.spi.clf.model.KANoticeType;
import lombok.Data;
import java.util.Date;
/**
* Created with suntao on 2018/12/26
*/
@Data
public class OrderStatusQueryResultOnlyStatus {
private String applyNo;
private Long loanId;
private KANoticeType kaNoticeType;
private Date updateTime;
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.model;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* Created with suntao on 2018/5/23
*/
public class ProductUtil {
public static String getProductId(Long registeredFrom) {
String productId = product.get(registeredFrom);
if (StringUtils.isNotEmpty(productId)) {
return productId;
} else {
return "1";
}
}
public static Integer getIntProductId(Long registeredFrom) {
String productId = product.get(registeredFrom);
if (StringUtils.isNotEmpty(productId)) {
return Integer.valueOf(productId);
} else {
return 1;
}
}
static Map<Long, String> product = new HashMap<>(4);
static {
product.put(159509L,"3");
product.put(159858L,"900");
}
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.model;
import com.google.gson.annotations.JsonAdapter;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* Created by zhaojiankun on 2018/4/10.
*/
@Data
public class QuotaCreditInfo implements Serializable {
private static final long serialVersionUID = -1L;
private Long id;
/**
* 用户ID
*/
private Long userId;
/**
* 渠道
*/
private Long channel;
/**
* 和授信中心关联字段
*/
private String orderNo;
/**
* 授信状态
*/
private int creditStatus;
/**
* 授信信息来源
*/
private int creditSource;
/**
* 产品id,关联产品表
* KA 渠道来的数据,会提前把这个值传过来,需要存下来之后用
*/
private Long productId;
/**
* 授信状态
*/
private String remark;
/**
* 接收到风控回调时间,yyyy-MM-dd HH:mm:ss
*/
private Timestamp receiveAt;
private Timestamp createdAt;
private Timestamp updatedAt;
/**
* 马甲包数据
*/
private String loanVestInfo;
/**
* app 渠道
*/
private String appChannel;
/**
* 借款用途
*/
private String purpose;
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.model;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.util.*;
/**
* Created with suntao on 2018/4/8
*/
@Data
@Slf4j
public class QuotaInfo {
private Account account;
private Rule rule;
@Data
public class Account {
private Long id;
private Long userId;
private Long productId;
/** 授信额度 */
private BigDecimal totalAmount;
/** 可用额度 */
private BigDecimal availableAmount;
/** 已使用额度 */
private BigDecimal usedAmount;
/** 冻结额度 */
private BigDecimal freezeAmount;
}
@Data
public class Rule {
private Long fundCorpId;
// /** 期数 {\"3000\":[3,6],\"6000\":[3,6,9]} */
// private String terms;
/** 期数 {\"3000\":[3,6],\"6000\":[3,6,9]} */
private Map<String, TreeSet<Integer>> inputRule;
/** 授信额度 */
private BigDecimal maxAmount;
/** 日利率 */
private BigDecimal dayRate;
/** 月利率 */
private BigDecimal monthlyInterestRate;
/** 年利率 == 综合利率 */
private BigDecimal annualInterestRate;
/** 月服务费 */
private BigDecimal serviceFeeRate;
// 外加属性,额度和期数的集合
private List<TermsDetail> termsDetailList;
// 所有期数 用逗号隔开
private String termsStr;
public TermsDetail getMaxAmountAndTerm() {
if (CollectionUtils.isEmpty(termsDetailList)) {
try {
loadTermsDetail();
} catch (Exception e) {
return null;
}
return termsDetailList.get(termsDetailList.size() - 1);
}else {
return termsDetailList.get(termsDetailList.size() - 1);
}
}
/**
* 初始化额度-提现期数关系
*/
public void loadTermsDetail() {
TreeSet<Integer> termsSetAll = new TreeSet<>();
if (CollectionUtils.isEmpty(termsDetailList)) {
termsDetailList = new ArrayList<>();
// Map<String,Integer[]> inputRule = Constants.GSON.fromJson(terms, new TypeToken<Map<String, Integer[]>>() {}.getType());
// for (Map.Entry<String,Integer[]> entry : inputRule.entrySet()) {
// TermsDetail termsDetailInner = new TermsDetail();
// termsDetailInner.setAmount(Long.valueOf(entry.getKey()));
// Integer[] termValues = entry.getValue();
// termsDetailInner.setTermDetail(termValues);
// Arrays.sort(termValues);
// termsDetailInner.setMinTerm(termValues[0]);
// termsDetailInner.setMaxTerm(termValues[termValues.length-1]);
// termsDetail.add(termsDetailInner);
// }
for (Map.Entry<String,TreeSet<Integer>> entry : inputRule.entrySet()) {
TermsDetail termsDetailInner = new TermsDetail();
termsDetailInner.setAmount(Long.valueOf(entry.getKey()));
TreeSet<Integer> termValues = entry.getValue();
termsDetailInner.setTerms(termValues);
termsSetAll.addAll(termValues);
termsDetailInner.setMinTerm(termValues.first());
termsDetailInner.setMaxTerm(termValues.last());
termsDetailList.add(termsDetailInner);
}
// 排序,按照额度升序排序
Collections.sort(termsDetailList,(TermsDetail t1,TermsDetail t2)->{
// 当compareTo的返回值大于0的时候,进行元素的移位,其他情况,不作处理
try {
if (!Objects.isNull(t1.getAmount()) && !Objects.isNull(t2.getAmount())) {
// (x < y) ? -1 : ((x == y) ? 0 : 1);
return t1.getAmount().compareTo(t2.getAmount());
}
else {
return Objects.isNull(t1.getAmount()) ? (Objects.isNull(t2.getAmount()) ? 0 : 1) : -1;
}
} catch (Exception ex) {
return 0;
}
});
}
if (StringUtils.isEmpty(termsStr)) {
if (CollectionUtils.isNotEmpty(termsSetAll)) {
// // 排序,按照额度升序排序
termsStr = StringUtils.join(termsSetAll,",");
}
}
}
}
@Data
public class TermsDetail {
private Long amount;
private TreeSet<Integer> terms;
private int maxTerm;
private int minTerm;
}
/**
* 验证 查询额度 有效性
* @param quotaInfo
* @return
*/
public static boolean validationQuotaInfo(QuotaInfo quotaInfo) {
if (quotaInfo == null) {
return false;
}
if (quotaInfo.getAccount() == null || quotaInfo.getRule() == null) {
return false;
}
if (quotaInfo.getRule().getInputRule() == null) {
return false;
}
try {
QuotaInfo.TermsDetail maxAmountAndTerm = quotaInfo.getRule().getMaxAmountAndTerm();
if (maxAmountAndTerm == null) {
return false;
}
if (StringUtils.isEmpty(quotaInfo.getRule().termsStr)) {
return false;
}
} catch (Exception e) {
log.error("[exception][validationQuotaInfo]",e);
return false;
}
return true;
}
}
package cn.quantgroup.cashloanflowboss.spi.xyqb.service;
/**
* function:
* date: 2019/8/9
*
* @author: suntao
*/
public class XyqbCenter {
}
package cn.quantgroup.cashloanflowboss.utils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import java.beans.PropertyDescriptor;
import java.util.HashSet;
import java.util.Set;
/**
* function:
* date: 2019/8/7
*
* @author: suntao
*/
public class IgnorePropertiesUtil {
public static String[] getNullPropertyNames(Object source) {
BeanWrapper src = new BeanWrapperImpl(source);
PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<>();
for (PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) {
emptyNames.add(pd.getName());
}
}
return emptyNames.toArray(new String[emptyNames.size()]);
}
}
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