package com.nova.sankuai.service.impl;
|
|
import cn.hutool.http.ContentType;
|
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpResponse;
|
import cn.hutool.http.HttpUtil;
|
import cn.hutool.json.JSONArray;
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.nova.sankuai.domain.api.huizhongzhidai.HuiZhongZhiDaiCommitResponse;
|
import com.nova.sankuai.domain.api.huizhongzhidai.HuiZhongZhiDaiHitResponse;
|
import com.nova.sankuai.domain.api.huizhongzhidai.HuiZhongZhiDaiUtil;
|
import com.nova.sankuai.domain.api.jinRiTouTiao.JinRiTouTiaoUtil;
|
import com.nova.sankuai.domain.api.jinxiushuke.JinXiuShuKeResponse;
|
import com.nova.sankuai.domain.api.jinxiushuke.JinXiuShuKeUtil;
|
import com.nova.sankuai.domain.api.jinzhanggui.JinZhangGuiResponse;
|
import com.nova.sankuai.domain.api.jinzhanggui.JinZhangGuiUtil;
|
import com.nova.sankuai.domain.api.minsheng.MinShengUtil;
|
import com.nova.sankuai.domain.api.nanjingmingtuo.NanJingMingTuoUtil;
|
import com.nova.sankuai.domain.api.rongduoduo.RongDuoDuoResponse;
|
import com.nova.sankuai.domain.api.rongduoduo.RongDuoDuoUtil;
|
import com.nova.sankuai.domain.api.rongduoduo.SanKuaiCustomer;
|
import com.nova.sankuai.domain.api.shanghaizhongzan.ShangHaiZhongZanUtil;
|
import com.nova.sankuai.domain.api.tianshi.TianShiResponse;
|
import com.nova.sankuai.domain.api.tianshi.TianShiUtil;
|
import com.nova.sankuai.domain.api.xiamenzhongheyinhua.SignatureUtil;
|
import com.nova.sankuai.domain.api.xiamenzhongheyinhua.XiaMenZhongHeYinHuaResponse;
|
import com.nova.sankuai.domain.api.xiamenzhongheyinhua.XiaMenZhongHeYinHuaUtil;
|
import com.nova.sankuai.domain.api.xinyeyoupin.XinYeYouPinUtil;
|
import com.nova.sankuai.domain.api.yidai.YiDaiResponse;
|
import com.nova.sankuai.domain.api.yidai.YiDaiUtil;
|
import com.nova.sankuai.domain.api.yinsheng.SerialGenerator;
|
import com.nova.sankuai.domain.dto.ApiCompanyPageDto;
|
import com.nova.sankuai.domain.entity.*;
|
import com.nova.sankuai.domain.enums.ApiCompanyCodeEnum;
|
import com.nova.sankuai.domain.enums.SourceTypeEnum;
|
import com.nova.sankuai.domain.vo.ApiCompanyVo;
|
import com.nova.sankuai.infra.config.CommonException;
|
import com.nova.sankuai.infra.constants.Constants;
|
import com.nova.sankuai.infra.mapper.ApiCompanyMapper;
|
import com.nova.sankuai.infra.mapper.ChannelInfoMapper;
|
import com.nova.sankuai.infra.mapper.CustomerMapper;
|
import com.nova.sankuai.infra.utils.ApiCompanyCheckUtil;
|
import com.nova.sankuai.infra.utils.PageRequest;
|
import com.nova.sankuai.infra.utils.PageUtil;
|
import com.nova.sankuai.security.HttpClientUtil;
|
import com.nova.sankuai.service.*;
|
import lombok.AllArgsConstructor;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.http.MediaType;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.Assert;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* @author weikangdi
|
*/
|
@Service
|
@AllArgsConstructor
|
public class ApiCompanyServiceImpl extends ServiceImpl<ApiCompanyMapper, ApiCompany> implements IApiCompanyService {
|
|
private final ApiCompanyMapper mapper;
|
|
private final PageUtil pageUtil;
|
|
private final TianShiUtil tianShiUtil;
|
|
private final HuiZhongZhiDaiUtil huiZhongZhiDaiUtil;
|
|
private final ShangHaiZhongZanUtil shangHaiZhongZanUtil;
|
|
private final NanJingMingTuoUtil nanJingMingTuoUtil;
|
|
private final ICityService cityService;
|
|
private final IApiCompanyRecordService recordService;
|
|
private final IChannelLogService channelLogService;
|
|
private final CustomerMapper customerMapper;
|
|
private final IChannelCompanyConfigService channelCompanyConfigService;
|
|
private final ChannelInfoMapper channelInfoMapper;
|
|
private final ApiCompanyCheckUtil checkUtil;
|
|
private final XinYeYouPinUtil xinYeYouPinUtil;
|
|
private final RongDuoDuoUtil rongDuoDuoUtil;
|
|
private static final Logger log = LoggerFactory.getLogger("apiCompanyInfoLogger");
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void edit(ApiCompany apiCompany) {
|
ApiCompany company = getById(apiCompany.getId());
|
if (company == null) {
|
throw new CommonException("该接口公司不存在");
|
}
|
company.setCustomerNum(apiCompany.getCustomerNum());
|
company.setDeliveryCity(apiCompany.getDeliveryCity());
|
company.setDeliveryCityName(apiCompany.getDeliveryCityName());
|
company.setEnableFlag(apiCompany.getEnableFlag());
|
company.setMinLoanAmount(apiCompany.getMinLoanAmount());
|
company.setAgeLowerLimit(apiCompany.getAgeLowerLimit());
|
company.setAgeUpperLimit(apiCompany.getAgeUpperLimit());
|
company.setMarriageLimit(apiCompany.getMarriageLimit());
|
company.setSesameLimit(apiCompany.getSesameLimit());
|
company.setSocialSecurityLimit(apiCompany.getSocialSecurityLimit());
|
company.setProvidentFundLimit(apiCompany.getProvidentFundLimit());
|
company.setHouseLimit(apiCompany.getHouseLimit());
|
company.setCarLimit(apiCompany.getCarLimit());
|
company.setPolicyLimit(apiCompany.getPolicyLimit());
|
company.setCreditCardLimit(apiCompany.getCreditCardLimit());
|
company.setAmountLowerLimit(apiCompany.getAmountLowerLimit());
|
company.setAmountUpperLimit(apiCompany.getAmountUpperLimit());
|
company.setMonthlyIncomeLimit(apiCompany.getMonthlyIncomeLimit());
|
company.setEducationLimit(apiCompany.getEducationLimit());
|
company.setChannelConfig(apiCompany.getChannelConfig());
|
updateById(company);
|
channelCompanyConfigService.updateConfig(apiCompany);
|
}
|
|
|
@Override
|
public IPage<ApiCompanyVo> pageModel(PageRequest pageRequest, ApiCompanyPageDto pageDto) {
|
IPage<ApiCompanyVo> page = mapper.pageModel(pageUtil.getPage(pageRequest), pageDto);
|
List<ApiCompanyVo> records = page.getRecords();
|
List<ApiCompanyVo> newRecords = new ArrayList<>();
|
for (ApiCompanyVo record : records) {
|
List<Long> channelIds = channelCompanyConfigService.getChannelsByCompanyId(record.getId());
|
record.setChannelIds(channelIds);
|
newRecords.add(record);
|
}
|
page.setRecords(newRecords);
|
return page;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void pushCustomer(Customer customer) {
|
try {
|
City city = cityService.lambdaQuery().eq(City::getCityId, customer.getCity()).one();
|
if (city != null) {
|
List<ApiCompany> result = mapper.getCompanies(city.getCityId(), city.getProvinceId());
|
ChannelInfo channelInfo = channelInfoMapper.getChannelByCode(customer.getSourceChannel());
|
for (ApiCompany apiCompany : result) {
|
// 筛选渠道配置匹配的接口公司
|
String type = "有痕模式";
|
boolean checkChannelConfig = checkUtil.filterCustomer(customer, apiCompany, channelInfo, type);
|
if (!checkChannelConfig) {
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户的不满足推送条件");
|
continue;
|
}
|
chooseApiCompany(apiCompany, customer, true);
|
}
|
} else {
|
log.error("审批分流推送警告:城市信息为空, 客户数据" + customer.toString());
|
}
|
} catch (Exception e) {
|
log.error("审批分流推送异常,原始数据" + customer.toString(), e);
|
}
|
}
|
|
@Override
|
public void pushCustomerNoTrace(Customer customer) {
|
City city = cityService.lambdaQuery().eq(City::getCityId, customer.getCity()).one();
|
if (city != null) {
|
List<ApiCompany> companyList = mapper.getCompanies(city.getCityId(), city.getProvinceId());
|
if (companyList == null || companyList.isEmpty()) {
|
log.error("无痕推送错误:推送城市信息不匹配或推送机构未开启");
|
throw new CommonException("没有符合条件的推送机构");
|
}
|
ChannelInfo channelInfo = channelInfoMapper.getChannelByCode(customer.getSourceChannel());
|
boolean pushResult = false;
|
for (ApiCompany apiCompany : companyList) {
|
// 筛选渠道配置匹配的接口公司
|
String type = "无痕模式";
|
boolean checkChannelConfig = checkUtil.filterCustomer(customer, apiCompany, channelInfo, type);
|
if (!checkChannelConfig) {
|
log.error("无痕推送" + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足推送条件");
|
continue;
|
}
|
ApiCompanyRecord record = chooseApiCompany(apiCompany, customer, false);
|
if (record == null) {
|
log.error("无痕推送" + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:构建的ApiCompanyRecord为空");
|
} else if (record.getStatus() == ApiCompanyRecord.FAIL) {
|
log.error("无痕推送" + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:" + record.toString());
|
} else {
|
pushResult = true;
|
log.info("无痕推送" + apiCompany.getCompanyName() + "成功,用户信息:" + customer.toString());
|
}
|
}
|
if (!pushResult) {
|
throw new CommonException("数据推送失败");
|
}
|
} else {
|
log.error("无痕推送失败,错误:城市信息为空, 用户手机号" + customer.getPhone());
|
throw new CommonException("城市信息不能为空");
|
}
|
}
|
|
/**
|
* 通过公司code判断需要推送的公司
|
*
|
* @param apiCompany
|
* @param customer
|
*/
|
private ApiCompanyRecord chooseApiCompany(ApiCompany apiCompany, Customer customer, boolean saveLog) {
|
try {
|
// 调用接口公司对应API接口
|
if (ApiCompanyCodeEnum.SHANG_HAI_ZHONG_ZAN.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接上海中赞
|
return shangHaiZhongZanInterface(customer, apiCompany.getId(), saveLog);
|
} else if (ApiCompanyCodeEnum.NAN_JING_MING_TUO.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接南京名拓
|
return nanJingMingTuoInterface(customer, apiCompany.getId(), saveLog);
|
} else if (ApiCompanyCodeEnum.XiaMenZhongHeYinHua.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接厦门众合银华
|
return xiaMenZhongHeYinHuaInterface(customer, apiCompany.getId(), saveLog);
|
} else if (ApiCompanyCodeEnum.MIN_SHENG.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接民生
|
return minShengInterface(customer, apiCompany.getId(), saveLog);
|
} else if (ApiCompanyCodeEnum.RONG_DUO_DUO.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接融多多
|
return rongDuoDuoInterface(customer, apiCompany.getId(), saveLog);
|
} else if (ApiCompanyCodeEnum.TIAN_SHI.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接苏州天师
|
return tianShiInterface(customer, apiCompany.getId(), saveLog);
|
} else if (ApiCompanyCodeEnum.HUI_ZHONG_ZHI_DAI.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接惠众直贷
|
return huiZhongZhiDaiInterface(customer, apiCompany.getId(), saveLog);
|
} else if (ApiCompanyCodeEnum.JIN_XIU_SHU_KE.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接锦绣数科
|
return jinXiuShuKeInterface(customer, apiCompany.getId(), saveLog);
|
} else if (ApiCompanyCodeEnum.YI_DAI.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接北京亿代
|
return YiDaiInterface(customer, apiCompany.getId(), saveLog);
|
} else if (ApiCompanyCodeEnum.HUI_RONG.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接汇融
|
return jinRiTouTiaoInterface(customer, apiCompany.getId(), saveLog);
|
} else if (ApiCompanyCodeEnum.XIN_YE_YOU_PIN.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接信业优品
|
return xinyeyoupinInterface(customer, apiCompany.getId(), saveLog);
|
} else if (ApiCompanyCodeEnum.SANDBOX_TEST.getCode().equals(apiCompany.getCompanyCode())) {
|
ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(apiCompany.getId(), customer.getId(), null);
|
apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
|
apiCompanyRecord.setMessage("测试成功");
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.SANDBOX_EXPORT_TEST.getCode(), apiCompanyRecord.getStatus(), customer.getId(), null);
|
}
|
return apiCompanyRecord;
|
} else if (ApiCompanyCodeEnum.JIN_ZHANG_GUI.getCode().equals(apiCompany.getCompanyCode())) {
|
// 对接中银e贷-金掌柜
|
return jinzhangguiInterface(customer, apiCompany.getId(), saveLog);
|
}
|
} catch (Exception e) {
|
log.error("审批分流异常,公司code: " + apiCompany.getCompanyCode(), e);
|
}
|
log.error("未找到匹配的公司code: " + apiCompany.getCompanyCode());
|
return null;
|
}
|
|
private ApiCompanyRecord nanJingMingTuoInterface(Customer customer, Long companyId, boolean saveLog) {
|
String hitReq = nanJingMingTuoUtil.parseHitParam(customer);
|
HttpResponse response = null;
|
try {
|
log.info("南京名拓接口撞库请求数据: {}", hitReq);
|
response = HttpRequest.post(nanJingMingTuoUtil.getHitUrl())
|
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
.body(hitReq)
|
.execute();
|
} catch (Exception e) {
|
log.error("南京名拓接口撞库失败!", e);
|
}
|
Assert.notNull(response, "南京名拓接口撞库数据响应为NULL!");
|
if (nanJingMingTuoUtil.passHitResponse(response)) {
|
try {
|
String req = nanJingMingTuoUtil.parseParam(customer);
|
log.info("南京名拓接口推送请求数据: {}", req);
|
response = HttpRequest.post(nanJingMingTuoUtil.getUrl())
|
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
.body(req)
|
.execute();
|
} catch (Exception e) {
|
log.error("南京名拓接口推送数据失败!", e);
|
}
|
Assert.notNull(response, "南京名拓接口推送数据响应为NULL!");
|
ApiCompanyRecord record = ApiCompanyRecord.getNanJingMingTuoRecord(companyId, customer.getId(), response.body());
|
if (saveLog) {
|
recordService.save(record);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.NanJingMingTuo.getCode(), record.getStatus(), customer.getId(), response.body());
|
}
|
return record;
|
} else {
|
log.warn("南京名拓接口撞库:手机号[{}]已存在", customer.getPhone());
|
ApiCompanyRecord record = ApiCompanyRecord.getNanJingMingTuoRecord(companyId, customer.getId(), response.body());
|
if (saveLog) {
|
recordService.save(record);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.NanJingMingTuo.getCode(), record.getStatus(), customer.getId(), response.body());
|
}
|
return record;
|
}
|
}
|
|
private ApiCompanyRecord shangHaiZhongZanInterface(Customer customer, Long companyId, boolean saveLog) {
|
String body = ShangHaiZhongZanUtil.parseParam(customer);
|
HttpResponse response = null;
|
try {
|
log.info("上海中赞接口推送数据开始,原始数据: {}", body);
|
response = HttpRequest.post(shangHaiZhongZanUtil.getUrl())
|
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
.timeout(Constants.TIME_OUT)
|
.body(body)
|
.execute();
|
} catch (Exception e) {
|
log.error("上海中赞接口数据推送失败!", e);
|
}
|
Assert.notNull(response, "上海中赞接口推送数据响应为NULL!");
|
ApiCompanyRecord record = ApiCompanyRecord.getShangHaiZhongZanRecord(companyId, customer.getId(), response.body());
|
if (saveLog) {
|
recordService.save(record);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.ShangHaiZhongZan.getCode(), record.getStatus(), customer.getId(), response.body());
|
}
|
return record;
|
}
|
|
@Override
|
public ApiCompanyRecord xiaMenZhongHeYinHuaInterface(Customer customer, Long companyId, boolean saveLog) {
|
try {
|
XiaMenZhongHeYinHuaResponse hitResp = XiaMenZhongHeYinHuaUtil.phoneCheckExists(customer.getPhone());
|
if (Objects.equals(hitResp.getCode(), 0)) {
|
JSONArray param = XiaMenZhongHeYinHuaUtil.parseParam(customer);
|
HttpResponse response = null;
|
try {
|
log.info("厦门众合银华推送数据开始,原始数据:" + param);
|
String requestBodyString = param.toString();
|
String timestamp = String.valueOf(System.currentTimeMillis());
|
String nonce = SignatureUtil.getRandomStr();
|
String encryptBody = SignatureUtil.encrypt(requestBodyString, SignatureUtil.SECRET_KEY);
|
response = HttpRequest.post(XiaMenZhongHeYinHuaUtil.PROD_URL_ENC)
|
.header("channel", XiaMenZhongHeYinHuaUtil.CHANNEL)
|
.header("timestamp", timestamp)
|
.header("nonce", nonce)
|
.header("sign", SignatureUtil.getSignature(encryptBody, nonce, SignatureUtil.SECRET_KEY, timestamp))
|
.contentType("text/plain")
|
.timeout(Constants.TIME_OUT)
|
.body(encryptBody).execute();
|
log.info("推送结果:" + response.body());
|
} catch (Exception e) {
|
log.error("数据推送失败:" + e);
|
}
|
assert response != null;
|
ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getXiaMenZhongHeYinHuaRecord(companyId, customer.getId(), response.body());
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.XiaMenZhongHeYinHua.getCode(), apiCompanyRecord.getStatus(), customer.getId(), response.body());
|
}
|
return apiCompanyRecord;
|
} else {
|
if (Objects.equals(hitResp.getCode(), 1)) {
|
hitResp.setMsg("撞库失败:数据已存在");
|
} else {
|
hitResp.setMsg("撞库失败:参数不能为空");
|
}
|
String result = JSON.toJSONString(hitResp);
|
ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getXiaMenZhongHeYinHuaRecord(companyId, customer.getId(), result);
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.XiaMenZhongHeYinHua.getCode(), apiCompanyRecord.getStatus(), customer.getId(), result);
|
}
|
return apiCompanyRecord;
|
}
|
} catch (RuntimeException e) {
|
log.error("厦门众合银华接口报错.", e);
|
return null;
|
}
|
}
|
|
@Override
|
public ApiCompanyRecord rongDuoDuoInterface(Customer customer, Long companyId, boolean saveLog) {
|
try {
|
String result = null;
|
try {
|
result = rongDuoDuoUtil.apiMd5Check(customer);
|
RongDuoDuoResponse rongDuoDuoResponse = RongDuoDuoUtil.getResponse(result);
|
if (rongDuoDuoResponse != null && 200 == rongDuoDuoResponse.getStatus()) {
|
try {
|
SanKuaiCustomer cstm = rongDuoDuoUtil.parseParam(customer);
|
String param = RongDuoDuoUtil.encrypt(JSONObject.toJSONString(cstm));
|
log.info("加密参数:" + param);
|
result = HttpClientUtil.getInstance().postJsonData(rongDuoDuoUtil.url2, JSONObject.toJSONString(param));
|
log.info("融多多推送数据返回:" + result);
|
} catch (Exception e) {
|
log.info("融多多推送数据失败:", e);
|
}
|
}
|
} catch (Exception e) {
|
log.info("融多多撞库失败:", e);
|
}
|
ApiCompanyRecord rongDuoDuoRecord = ApiCompanyRecord.getRongDuoDuoRecord(companyId, customer.getId(), result);
|
if (saveLog) {
|
recordService.save(rongDuoDuoRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.RONG_DUO_DUO.getCode(), rongDuoDuoRecord.getStatus(), customer.getId(), result);
|
}
|
return rongDuoDuoRecord;
|
} catch (Exception e) {
|
log.info("融多多审批分流对接失败:", e);
|
}
|
return null;
|
}
|
|
@Override
|
public ApiCompanyRecord minShengInterface(Customer customer, Long companyId, boolean saveLog) {
|
HashMap<String, Object> param = MinShengUtil.parseParam(customer);
|
String response = null;
|
try {
|
log.info("民生推送数据开始,原始数据:" + param.toString());
|
response = HttpUtil.post(MinShengUtil.MINSHENG_URL, param, Constants.TIME_OUT);
|
log.info("推送结果:" + response);
|
} catch (Exception e) {
|
log.error("民生推送数据失败:" + e);
|
}
|
ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getMinShengRecord(companyId, customer.getId(), response);
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.MIN_SHENG.getCode(), apiCompanyRecord.getStatus(), customer.getId(), response);
|
}
|
return apiCompanyRecord;
|
}
|
|
@Override
|
public ApiCompanyRecord jinRiTouTiaoInterface(Customer customer, Long companyId, boolean saveLog) {
|
String param = JinRiTouTiaoUtil.parseParam(customer);
|
String result = null;
|
try {
|
log.info("汇融推送数据开始,原始数据:" + param);
|
result = HttpUtil.post(JinRiTouTiaoUtil.HUIRONG_URL, param, Constants.TIME_OUT);
|
log.info("推送结果:" + result);
|
} catch (Exception e) {
|
log.error("汇融推送数据失败:" + e);
|
}
|
ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getJinRiTouTiaoRecord(companyId, customer.getId(), result);
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.HUIRONG.getCode(), apiCompanyRecord.getStatus(), customer.getId(), result);
|
}
|
return apiCompanyRecord;
|
}
|
|
@Override
|
public ApiCompanyRecord tianShiInterface(Customer customer, Long companyId, boolean saveLog) {
|
JSONObject hitParam = tianShiUtil.parseHitParam(customer);
|
TianShiResponse hitRes = new TianShiResponse();
|
hitRes.setCode(-1);
|
try {
|
String hitResult = HttpRequest.post(tianShiUtil.hitUrl)
|
.header("secretapi", tianShiUtil.secretapi)
|
.contentType("application/json")
|
.timeout(Constants.TIME_OUT)
|
.body(JSONObject.toJSONString(hitParam), ContentType.JSON.getValue()).execute().body();
|
hitRes.setCode(Integer.valueOf(hitResult));
|
} catch (NumberFormatException e) {
|
log.error("苏州天师撞库接口返回格式有误", e);
|
} catch (Exception e) {
|
log.error("苏州天师撞库接口对接失败", e);
|
}
|
if (TianShiResponse.SUCCESS == hitRes.getCode()) {
|
JSONObject param = tianShiUtil.parseCommitParam(customer);
|
Integer commitResultInt = -1;
|
try {
|
String commitResult = HttpRequest.post(tianShiUtil.commitUrl)
|
.header("secretapi", tianShiUtil.secretapi)
|
.contentType("application/json")
|
.timeout(Constants.TIME_OUT)
|
.body(JSONObject.toJSONString(param), ContentType.JSON.getValue()).execute().body();
|
commitResultInt = Integer.valueOf(commitResult);
|
} catch (NumberFormatException e) {
|
log.error("苏州天师提交数据接口返回格式有误", e);
|
} catch (Exception e) {
|
log.error("苏州天师提交数据接口对接失败", e);
|
}
|
ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getTianShiRecord(companyId, customer.getId(), commitResultInt);
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.TianShi.getCode(), apiCompanyRecord.getStatus(), customer.getId(), Integer.toString(commitResultInt));
|
}
|
return apiCompanyRecord;
|
} else {
|
ApiCompanyRecord failRecord = ApiCompanyRecord.getTianShiRecord(companyId, customer.getId(), hitRes.getCode());
|
if (saveLog) {
|
recordService.save(failRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.TianShi.getCode(), failRecord.getStatus(), customer.getId(), Integer.toString(hitRes.getCode()));
|
}
|
return failRecord;
|
}
|
}
|
|
@Override
|
public ApiCompanyRecord YiDaiInterface(Customer customer, Long companyId, boolean saveLog) {
|
JSONObject jsonObject = YiDaiUtil.parseMd5Param(customer);
|
YiDaiResponse yiDaiResponse = new YiDaiResponse();
|
HttpResponse response = null;
|
try {
|
log.info("北京亿代撞库试验开始,请求参数:" + jsonObject);
|
response = HttpRequest.post(YiDaiUtil.YIDAI_ZC_URL).contentType("application/json")
|
.body(jsonObject.toJSONString())
|
.timeout(Constants.TIME_OUT)
|
.execute();
|
log.info("北京亿代撞库试验结束,返回参数:" + response);
|
yiDaiResponse.setRetCode("-1");
|
try {
|
yiDaiResponse = JSONObject.parseObject(response.body(), YiDaiResponse.class);
|
} catch (Exception e) {
|
log.error("撞库返回参数转换接受类失败");
|
}
|
} catch (Exception e) {
|
log.error("北京亿代撞库对接失败");
|
}
|
if (YiDaiResponse.SUCCESS.equals(yiDaiResponse.getRetCode())) {
|
YiDaiResponse yiDai = new YiDaiResponse();
|
yiDai.setRetCode("-1");
|
JSONObject parseRSAParam = YiDaiUtil.parseRSAParam(YiDaiUtil.parseParam(customer));
|
if (parseRSAParam != null) {
|
String replace = parseRSAParam.getString("encryptionData").replaceAll("\r|\n", "");
|
parseRSAParam.put("encryptionData", replace);
|
}
|
HttpResponse httpResponse = null;
|
try {
|
log.info("北京亿代推送数据开始,数据源:" + parseRSAParam);
|
httpResponse = HttpRequest.post(YiDaiUtil.YIDAI_RSA_URL)
|
.contentType("multipart/form-data")
|
.timeout(Constants.TIME_OUT)
|
.form(parseRSAParam).execute();
|
log.info("推送结果:" + httpResponse.body());
|
} catch (Exception e) {
|
log.error("北京亿代推送数据失败:", e);
|
}
|
if (httpResponse != null) {
|
ApiCompanyRecord yiDaiRecord = ApiCompanyRecord.getYiDaiRecord(companyId, customer.getId(), httpResponse.body());
|
if (saveLog) {
|
recordService.save(yiDaiRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.YIDAI.getCode(), yiDaiRecord.getStatus(), customer.getId(), httpResponse.body());
|
}
|
return yiDaiRecord;
|
}
|
return null;
|
} else {
|
ApiCompanyRecord yiDaiRecord = ApiCompanyRecord.getYiDaiRecord(companyId, customer.getId(), response.body());
|
if (saveLog) {
|
recordService.save(yiDaiRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.YIDAI.getCode(), yiDaiRecord.getStatus(), customer.getId(), yiDaiResponse.getRetCode());
|
}
|
return yiDaiRecord;
|
}
|
}
|
|
@Override
|
public List<ApiCompanyVo> getApiCompany() {
|
List<ApiCompanyVo> apiCompany = mapper.getApiCompany();
|
return apiCompany;
|
}
|
|
private ApiCompanyRecord jinXiuShuKeInterface(Customer customer, Long companyId, boolean saveLog) {
|
JSONObject hitParam = JinXiuShuKeUtil.parseHitParam(customer);
|
log.info("锦绣数科撞库开始,原始数据:" + hitParam);
|
String hitResponse = HttpUtil.post(JinXiuShuKeUtil.HIT_URL, JSONObject.toJSONString(hitParam), Constants.TIME_OUT);
|
log.info("撞库结果:" + hitResponse);
|
JinXiuShuKeResponse hitResp = new JinXiuShuKeResponse();
|
hitResp.setCode(-1);
|
try {
|
hitResp = JSONObject.parseObject(hitResponse, JinXiuShuKeResponse.class);
|
} catch (Exception e) {
|
log.error("锦绣数科撞库对接失败");
|
}
|
if (JinXiuShuKeUtil.SUCCESS.equals(hitResp.getCode())) {
|
JSONObject commitParam = JinXiuShuKeUtil.parseCommitParam(customer);
|
log.info("锦绣数科推送数据开始,原始数据:" + commitParam);
|
String commitResponse = HttpUtil.post(JinXiuShuKeUtil.COMMIT_URL, JSONObject.toJSONString(commitParam), Constants.TIME_OUT);
|
log.info("推送结果:" + commitResponse);
|
ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getJinXiuShuKeRecord(companyId, customer.getId(), commitResponse);
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.JinXiuShuKe.getCode(), apiCompanyRecord.getStatus(), customer.getId(), commitResponse);
|
}
|
return apiCompanyRecord;
|
} else {
|
ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getJinXiuShuKeRecord(companyId, customer.getId(), hitResponse);
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.JinXiuShuKe.getCode(), apiCompanyRecord.getStatus(), customer.getId(), hitResponse);
|
}
|
return apiCompanyRecord;
|
}
|
}
|
|
private ApiCompanyRecord huiZhongZhiDaiInterface(Customer customer, Long companyId, boolean saveLog) {
|
JSONObject hitParam = huiZhongZhiDaiUtil.parseHitParam(customer);
|
String hitResponse = null;
|
try {
|
log.info("惠众直贷撞库开始,原始数据:" + hitParam);
|
hitResponse = HttpUtil.post(huiZhongZhiDaiUtil.hitUrl, JSONObject.toJSONString(hitParam), Constants.TIME_OUT);
|
log.info("惠众直贷撞库结果:" + hitResponse);
|
} catch (Exception e) {
|
log.error("惠众直贷撞库失败:" + e);
|
}
|
HuiZhongZhiDaiHitResponse hitResp = new HuiZhongZhiDaiHitResponse();
|
hitResp.setCode("0001");
|
try {
|
hitResp = JSONObject.parseObject(hitResponse, HuiZhongZhiDaiHitResponse.class);
|
} catch (Exception e) {
|
log.error("惠众直贷深圳撞库响应解析失败", e);
|
}
|
if (HuiZhongZhiDaiHitResponse.SUCCESS_CODE.equals(hitResp.getCode())) {
|
JSONObject commitParam = huiZhongZhiDaiUtil.parseCommitParam(customer);
|
JSONObject encrypt = new JSONObject();
|
encrypt.put("data", huiZhongZhiDaiUtil.encrypt(JSONObject.toJSONString(commitParam)));
|
log.info("惠众直贷数据推送开始,原始数据:" + encrypt);
|
String commitResponse = HttpUtil.post(huiZhongZhiDaiUtil.commitUrl, JSONObject.toJSONString(encrypt), Constants.TIME_OUT);
|
log.info("惠众直贷数据推送结果:" + commitResponse);
|
try {
|
JSONObject.parseObject(commitResponse, HuiZhongZhiDaiCommitResponse.class);
|
} catch (Exception e) {
|
log.error("惠众直贷数据推送响应解析失败", e);
|
}
|
ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getHuiZhongZhiDai(companyId, customer.getId(), commitResponse);
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.HuiZhongZhiDai.getCode(), apiCompanyRecord.getStatus(), customer.getId(), commitResponse);
|
}
|
return apiCompanyRecord;
|
} else {
|
ApiCompanyRecord failRecord = ApiCompanyRecord.getHuiZhongZhiDai(companyId, customer.getId(), hitResponse);
|
if (saveLog) {
|
recordService.save(failRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.HuiZhongZhiDai.getCode(), failRecord.getStatus(), customer.getId(), hitResponse);
|
}
|
return failRecord;
|
}
|
}
|
|
/**
|
* 手动审批分流
|
*
|
* @param customerId
|
* @param apiCompanyId
|
*/
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public String manualApproval(Long customerId, Long apiCompanyId) {
|
String result = null;
|
try {
|
Customer customer = customerMapper.selectById(customerId);
|
if (customer == null) {
|
throw new CommonException("客户不存在");
|
}
|
ApiCompany newApiCompany = getById(apiCompanyId);
|
if (newApiCompany == null) {
|
throw new CommonException("分流公司不存在");
|
}
|
log.info("手动审批分流开始,客户信息:" + customer.getName() + "分流公司:" + newApiCompany.getCompanyName());
|
ApiCompanyRecord record = chooseApiCompany(newApiCompany, customer, true);
|
if (record == null) {
|
result = "数据推送失败,系统错误/网络超时/其他信息";
|
} else if (record.getStatus() == ApiCompanyRecord.FAIL) {
|
result = "数据推送失败," + record.getMessage();
|
}
|
log.info("手动审批分流结束");
|
} catch (Exception e) {
|
log.error("手动审批分流失败:" + e);
|
result = "数据推送失败,系统错误/网络超时/其他信息";
|
}
|
return result;
|
}
|
|
private ApiCompanyRecord xinyeyoupinInterface(Customer customer, Long companyId, boolean saveLog) {
|
String order = SerialGenerator.getOrder();
|
String param = xinYeYouPinUtil.parseParam(customer, order);
|
String result = null;
|
try {
|
log.info("信业优品推送数据开始,原始数据:" + param);
|
result = HttpRequest.post(xinYeYouPinUtil.url)
|
.contentType("application/x-www-form-urlencoded")
|
.timeout(Constants.TIME_OUT)
|
.body(param).execute().body();
|
log.info("信业优品推送结果:" + result);
|
} catch (Exception e) {
|
log.error("信业优品推送数据失败:" + e);
|
}
|
ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getXinYeYouPinRecord(companyId, customer.getId(), result);
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.XinYeYouPin.getCode(), apiCompanyRecord.getStatus(), customer.getId(), result);
|
}
|
return apiCompanyRecord;
|
}
|
|
private ApiCompanyRecord jinzhangguiInterface(Customer customer, Long companyId, boolean saveLog) {
|
HashMap hitParam = JinZhangGuiUtil.parseHitParam(customer);
|
log.info("金掌柜撞库开始,原始数据:" + hitParam);
|
String hitResponse = HttpUtil.get(JinZhangGuiUtil.HIT_URL, hitParam, Constants.TIME_OUT);
|
log.info("金掌柜撞库结果:" + hitResponse);
|
JinZhangGuiResponse jinZhangGuiHitResponse = null;
|
try {
|
jinZhangGuiHitResponse = JSONObject.parseObject(hitResponse, JinZhangGuiResponse.class);
|
} catch (Exception e) {
|
log.error("金掌柜撞库对接失败");
|
}
|
if (jinZhangGuiHitResponse != null && JinZhangGuiUtil.SUCCESS.equals(jinZhangGuiHitResponse.getErrno())) {
|
JSONObject commitParam = JinZhangGuiUtil.parseCommitParam(customer);
|
log.info("金掌柜推送数据开始,原始数据:" + commitParam);
|
String commitResponse = HttpUtil.post(JinZhangGuiUtil.COMMIT_URL, JSONObject.toJSONString(commitParam), Constants.TIME_OUT);
|
log.info("金掌柜推送结果:" + commitResponse);
|
ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getJinZhangGuiRecord(companyId, customer.getId(), commitResponse);
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.JINZHANGGUI.getCode(), apiCompanyRecord.getStatus(), customer.getId(), commitResponse);
|
}
|
return apiCompanyRecord;
|
} else {
|
ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getJinZhangGuiRecord(companyId, customer.getId(), hitResponse);
|
if (saveLog) {
|
recordService.save(apiCompanyRecord);
|
channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.JINZHANGGUI.getCode(), apiCompanyRecord.getStatus(), customer.getId(), hitResponse);
|
}
|
return apiCompanyRecord;
|
}
|
}
|
|
|
}
|