Commit fc861264 authored by suntao's avatar suntao

service 改造

parent 66e78e68
...@@ -31,6 +31,7 @@ import cn.quantgroup.cashloanflowboss.spi.xyqb.entity.Contract; ...@@ -31,6 +31,7 @@ import cn.quantgroup.cashloanflowboss.spi.xyqb.entity.Contract;
import cn.quantgroup.cashloanflowboss.spi.xyqb.entity.LoanApplicationHistory; import cn.quantgroup.cashloanflowboss.spi.xyqb.entity.LoanApplicationHistory;
import cn.quantgroup.cashloanflowboss.spi.xyqb.repository.CancelPreLoanRepository; import cn.quantgroup.cashloanflowboss.spi.xyqb.repository.CancelPreLoanRepository;
import cn.quantgroup.cashloanflowboss.spi.xyqb.service.XYQBCenterService; import cn.quantgroup.cashloanflowboss.spi.xyqb.service.XYQBCenterService;
import cn.quantgroup.cashloanflowboss.spi.xyqb.service.XYQBCenterServiceImpl;
import cn.quantgroup.cashloanflowboss.utils.JSONTools; import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import cn.quantgroup.user.retbean.XUser; import cn.quantgroup.user.retbean.XUser;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
......
...@@ -5,14 +5,17 @@ import cn.quantgroup.cashloanflowboss.api.user.model.Pagination; ...@@ -5,14 +5,17 @@ import cn.quantgroup.cashloanflowboss.api.user.model.Pagination;
import cn.quantgroup.cashloanflowboss.api.user.model.RegisterUserFormModel; import cn.quantgroup.cashloanflowboss.api.user.model.RegisterUserFormModel;
import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo; import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo;
import cn.quantgroup.cashloanflowboss.api.user.model.UserInfoModel; import cn.quantgroup.cashloanflowboss.api.user.model.UserInfoModel;
import cn.quantgroup.cashloanflowboss.api.user.service.UserService;
import cn.quantgroup.cashloanflowboss.api.user.service.UserServiceImpl; import cn.quantgroup.cashloanflowboss.api.user.service.UserServiceImpl;
import cn.quantgroup.cashloanflowboss.component.security.Authority;
import cn.quantgroup.cashloanflowboss.component.security.annotiation.Security; import cn.quantgroup.cashloanflowboss.component.security.annotiation.Security;
import cn.quantgroup.cashloanflowboss.component.validator.constraints.NotEmpty; import cn.quantgroup.cashloanflowboss.component.validator.constraints.NotEmpty;
import cn.quantgroup.cashloanflowboss.core.base.Result; import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.core.base.Tuple; import cn.quantgroup.cashloanflowboss.core.base.Tuple;
import cn.quantgroup.cashloanflowboss.spi.user.service.XyqbUserService; import cn.quantgroup.cashloanflowboss.spi.user.service.XyqbUserService;
import javax.validation.Valid; import javax.validation.Valid;
import cn.quantgroup.cashloanflowboss.spi.xyqb.service.XYQBCenterService;
import cn.quantgroup.cashloanflowboss.spi.xyqb.service.XYQBCenterServiceImpl;
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.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
...@@ -32,10 +35,11 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -32,10 +35,11 @@ import org.springframework.web.bind.annotation.RestController;
public class UserController { public class UserController {
@Autowired @Autowired
private UserServiceImpl userService; private UserService userService;
@Autowired @Autowired
private XyqbUserService xyqbUserService; private XyqbUserService xyqbUserService;
/** /**
* 注册用户 * 注册用户
* *
...@@ -121,7 +125,7 @@ public class UserController { ...@@ -121,7 +125,7 @@ public class UserController {
@PutMapping("/order/clean") @PutMapping("/order/clean")
@Security(authorityId = "User.cleanUserOrder") @Security(authorityId = "User.cleanUserOrder")
public Result<Boolean> cleanUserOrder(@RequestParam @Valid @NotEmpty(message = "无效的用户手机号") String mobile) { public Result<Boolean> cleanUserOrder(@RequestParam @Valid @NotEmpty(message = "无效的用户手机号") String mobile) {
Tuple<Boolean, String> result = this.xyqbUserService.cleanUserOrder(mobile); Tuple<Boolean, String> result = userService.cleanUserActiveOrder(mobile);
return Result.buildSuccess(result.getKey(),result.getValue()); return Result.buildSuccess(result.getKey(),result.getValue());
} }
......
...@@ -3,6 +3,7 @@ package cn.quantgroup.cashloanflowboss.api.user.service; ...@@ -3,6 +3,7 @@ package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.user.entity.User; import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo; import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo;
import cn.quantgroup.cashloanflowboss.api.user.model.UserInfoModel; import cn.quantgroup.cashloanflowboss.api.user.model.UserInfoModel;
import cn.quantgroup.cashloanflowboss.core.base.Tuple;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
/** /**
...@@ -29,4 +30,6 @@ public interface UserService { ...@@ -29,4 +30,6 @@ public interface UserService {
UserDetailInfo getUserDetailInfo(); UserDetailInfo getUserDetailInfo();
User saveUserInfo(UserInfoModel user); User saveUserInfo(UserInfoModel user);
Tuple<Boolean,String> cleanUserActiveOrder(String mobile);
} }
package cn.quantgroup.cashloanflowboss.api.user.service; package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.login.model.Principal; import cn.quantgroup.cashloanflowboss.api.login.model.Principal;
import cn.quantgroup.cashloanflowboss.api.optlog.model.OptEnumName;
import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus; import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import cn.quantgroup.cashloanflowboss.api.user.entity.User; import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo; import cn.quantgroup.cashloanflowboss.api.user.model.UserDetailInfo;
import cn.quantgroup.cashloanflowboss.api.user.model.UserInfoModel; import cn.quantgroup.cashloanflowboss.api.user.model.UserInfoModel;
import cn.quantgroup.cashloanflowboss.api.user.repository.UserRepository; import cn.quantgroup.cashloanflowboss.api.user.repository.UserRepository;
import cn.quantgroup.cashloanflowboss.core.Application; import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.core.annotation.opt.OperationAnno;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert; import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.base.Tuple;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.spi.user.service.XyqbUserService;
import cn.quantgroup.cashloanflowboss.spi.xyqb.service.XYQBCenterService;
import cn.quantgroup.cashloanflowboss.utils.MD5Tools; import cn.quantgroup.cashloanflowboss.utils.MD5Tools;
import cn.quantgroup.user.retbean.XUser;
import cn.quantgroup.user.vo.UserSysResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -17,7 +24,6 @@ import org.springframework.data.domain.Page; ...@@ -17,7 +24,6 @@ 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 java.util.HashSet;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -29,6 +35,12 @@ public class UserServiceImpl implements UserService{ ...@@ -29,6 +35,12 @@ public class UserServiceImpl implements UserService{
@Autowired @Autowired
private UserRepository userRepository; private UserRepository userRepository;
@Autowired
private XYQBCenterService xyqbCenterService;
@Autowired
private XyqbUserService xyqbUserService;
/** /**
* 创建用户 * 创建用户
...@@ -160,4 +172,15 @@ public class UserServiceImpl implements UserService{ ...@@ -160,4 +172,15 @@ public class UserServiceImpl implements UserService{
user1.setRoles(userInfoModel.getRoles()); user1.setRoles(userInfoModel.getRoles());
return userRepository.save(user1); return userRepository.save(user1);
} }
@OperationAnno(channelNo = "#this[0]", opt = OptEnumName.USER_ORDER_CLEAN, succSPEL = "#this.key", optDetailSPEL = "#this.value")
@Override
public Tuple<Boolean,String> cleanUserActiveOrder(String mobile) {
XUser user = xyqbUserService.findUserByPhoneNo(mobile);
if (user == null) {
log.info("cleanUserOrder,清除用户活跃订单失败,未找到用户 phoneNo={}", mobile);
return new Tuple<>(false,"清除用户活跃订单失败,未找到用户");
}
return xyqbCenterService.cleanUserActiveOrder(user.getId());
}
} }
...@@ -2,6 +2,7 @@ package cn.quantgroup.cashloanflowboss.spi.jolyne; ...@@ -2,6 +2,7 @@ package cn.quantgroup.cashloanflowboss.spi.jolyne;
import cn.quantgroup.cashloanflowboss.spi.xyqb.entity.WaitingFundingCorpOperatePeople; import cn.quantgroup.cashloanflowboss.spi.xyqb.entity.WaitingFundingCorpOperatePeople;
import cn.quantgroup.cashloanflowboss.spi.xyqb.service.XYQBCenterService; import cn.quantgroup.cashloanflowboss.spi.xyqb.service.XYQBCenterService;
import cn.quantgroup.cashloanflowboss.spi.xyqb.service.XYQBCenterServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
...@@ -53,13 +53,6 @@ public interface XyqbUserService { ...@@ -53,13 +53,6 @@ public interface XyqbUserService {
UserInfo findUserByUuid(String uuid); UserInfo findUserByUuid(String uuid);
/**
* 清除用户活跃订单
* @param phoneNo
* @return
*/
Tuple<Boolean,String> cleanUserOrder(String phoneNo);
/** /**
* 删除记录 * 删除记录
*/ */
......
...@@ -42,10 +42,6 @@ public class XyqbUserServiceImpl implements XyqbUserService { ...@@ -42,10 +42,6 @@ public class XyqbUserServiceImpl implements XyqbUserService {
@Autowired @Autowired
private UserSysService userSysService; private UserSysService userSysService;
@Autowired @Autowired
private HttpService httpService;
@Autowired
private JolyneCenter jolyneCenter;
@Autowired
private UserDetailRepository userDetailRepository; private UserDetailRepository userDetailRepository;
@Autowired @Autowired
private UserExtInfoRepository userExtInfoRepository; private UserExtInfoRepository userExtInfoRepository;
...@@ -53,7 +49,6 @@ public class XyqbUserServiceImpl implements XyqbUserService { ...@@ -53,7 +49,6 @@ public class XyqbUserServiceImpl implements XyqbUserService {
private StringRedisTemplate redisTemplate; private StringRedisTemplate redisTemplate;
@Value("${passportapi.http}") @Value("${passportapi.http}")
private String passportapiHttp; private String passportapiHttp;
private static final ObjectMapper MAPPER = new ObjectMapper();
...@@ -128,10 +123,6 @@ public class XyqbUserServiceImpl implements XyqbUserService { ...@@ -128,10 +123,6 @@ public class XyqbUserServiceImpl implements XyqbUserService {
} }
} }
/**
* 用户detail信息
*/
@Override @Override
public UserInfo findUserByUuid(String uuid) { public UserInfo findUserByUuid(String uuid) {
UserSysResult<UserInfo> userInfo = userSysService.getService().findUserInfoByUuid(uuid); UserSysResult<UserInfo> userInfo = userSysService.getService().findUserInfoByUuid(uuid);
...@@ -142,34 +133,6 @@ public class XyqbUserServiceImpl implements XyqbUserService { ...@@ -142,34 +133,6 @@ public class XyqbUserServiceImpl implements XyqbUserService {
} }
/**
* 清除用户活跃订单
* @param phoneNo
* @return
*/
@OperationAnno(channelNo = "#this[0]", opt = OptEnumName.USER_ORDER_CLEAN, succSPEL = "#this.key", optDetailSPEL = "#this.value")
public Tuple<Boolean,String> cleanUserOrder(String phoneNo){
UserSysResult<XUser> xUser = userSysService.getService().findUserByPhoneNo(phoneNo);
if (xUser == null || xUser.getData() == null) {
LOGGER.info("cleanUserOrder,清除用户活跃订单失败,未找到用户 phoneNo={}", phoneNo);
return new Tuple<>(false,"清除用户活跃订单失败,未找到用户");
}
Long userId = xUser.getData().getId();
ConcurrentMap<Object, Object> data = Maps.newConcurrentMap();
ArrayList<Object> cancel_list = Lists.newArrayList();
cancel_list.add("update xyqb.quota_credit set is_active=0 where user_id="+userId);
cancel_list.add("update xyqb.quota_account set is_active=0 where user_id="+userId);
cancel_list.add("update xyqb.loan_application_history set progress=16 where user_id="+userId);
cancel_list.add("update xyqb.loan_application_history set is_active=0 where user_id="+userId);
cancel_list.add("delete from apply_quota_record where user_id="+userId);
cancel_list.add("delete from user_operation_history where user_id="+userId);
data.put("sql",cancel_list);
String cancel_result = jolyneCenter.executeXYQBSQL(JSONTools.serialize(data));
JSONObject resp = JSONObject.parseObject(cancel_result);
boolean result = (Objects.nonNull(resp) && resp.containsKey("code")) ? "0000".equals(resp.get("code")) : false;
return new Tuple<>(result,result?"清除用户活跃订单成功":"清除用户活跃订单失败");
}
@OperationAnno(channelNo = "#this[0]", opt = OptEnumName.USER_INFO_CLEAN, succSPEL = "#this.key", optDetailSPEL = "#this.value") @OperationAnno(channelNo = "#this[0]", opt = OptEnumName.USER_INFO_CLEAN, succSPEL = "#this.key", optDetailSPEL = "#this.value")
@Override public Tuple<Boolean,String> deleteByUserId(String phoneNo) { @Override public Tuple<Boolean,String> deleteByUserId(String phoneNo) {
try{ try{
......
...@@ -2,214 +2,49 @@ package cn.quantgroup.cashloanflowboss.spi.xyqb.service; ...@@ -2,214 +2,49 @@ package cn.quantgroup.cashloanflowboss.spi.xyqb.service;
import cn.quantgroup.cashloanflowboss.api.order.model.XyqbCurrentOrderStatusServiceResultModel; import cn.quantgroup.cashloanflowboss.api.order.model.XyqbCurrentOrderStatusServiceResultModel;
import cn.quantgroup.cashloanflowboss.api.order.model.XyqbHistoryOrderStatusServiceResultModel; import cn.quantgroup.cashloanflowboss.api.order.model.XyqbHistoryOrderStatusServiceResultModel;
import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.core.base.ServiceResult; import cn.quantgroup.cashloanflowboss.core.base.ServiceResult;
import cn.quantgroup.cashloanflowboss.spi.xyqb.client.XYQBCenter; import cn.quantgroup.cashloanflowboss.core.base.Tuple;
import cn.quantgroup.cashloanflowboss.spi.xyqb.entity.*; import cn.quantgroup.cashloanflowboss.spi.xyqb.entity.*;
import cn.quantgroup.cashloanflowboss.spi.xyqb.repository.*;
import cn.quantgroup.cashloanflowboss.spi.xyqb.util.SignUtil;
import cn.quantgroup.cashloanflowboss.utils.DateUtil;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
/** /**
* Created by WeiWei on 2019/8/12. * function:
*/ * date: 2019/9/27
@Slf4j
@Service
public class XYQBCenterService {
@Autowired
private WaitingFundingCorpOperatePeopleRepository waitingFundingCorpOperatePeopleRepository;
@Autowired
private ContractRepository contractRepository;
@Autowired
private CancelPreLoanRepository cancelPreLoanRepository;
@Autowired
private FundingCorpPolicyRepository fundingCorpPolicyRepository;
@Autowired
private FundingAssetAllocationsProgramsRepository fundingAssetAllocationsProgramsRepository;
@Autowired
private LoanApplicationHistoryRepository loanApplicationHistoryRepository;
@Autowired
private XYQBCenter xyqbCenter;
/**
* 更新合同状态
* *
* @param userId * @author: suntao
* @return
*/ */
public int updateContractStatus(Long userId, Integer status) { public interface XYQBCenterService {
return this.contractRepository.updateContractStatus(userId, status); int updateContractStatus(Long userId, Integer status);
}
/** Map queryLendingRecordCount(Long fundId);
* 查询放款记录
*
* @param fundId
* @return
*/
public Map queryLendingRecordCount(Long fundId) {
return this.waitingFundingCorpOperatePeopleRepository.queryLendingRecordCount(fundId);
}
Long cancelPreLoan(String channelOrderNumber);
/** Contract findContractByUserId(Long userId);
* 贷前取消借款
* @param channelOrderNumber
* @return
*/
public Long cancelPreLoan(String channelOrderNumber) {
if (Application.isDebug()) {
return cancelPreLoanRepository.cancelPreLoan(channelOrderNumber);
} else {
return -1L;
}
}
/**
* 通过userId获取合同
* @param userId
* @return
*/
public Contract findContractByUserId(Long userId) {
return contractRepository.findByUserIdLastOne(userId);
}
/**
* 保存合同
* @param contract
*/
public void saveContract(Contract contract) {
if (Application.isDebug()) {
contractRepository.save(contract);
}
}
void saveContract(Contract contract);
public WaitingFundingCorpOperatePeople findWaitingFundingCorpOperatePeopleByLoanId(Long loanId) { WaitingFundingCorpOperatePeople findWaitingFundingCorpOperatePeopleByLoanId(Long loanId);
return waitingFundingCorpOperatePeopleRepository.findByLoanApplicationHistoryId(loanId);
}
@Transactional @Transactional
public void saveWaitingFundingCorpOperatePeople(WaitingFundingCorpOperatePeople waitingFundingCorpOperatePeople) { void saveWaitingFundingCorpOperatePeople(WaitingFundingCorpOperatePeople waitingFundingCorpOperatePeople);
if (Application.isDebug()) {
waitingFundingCorpOperatePeopleRepository.saveAndFlush(waitingFundingCorpOperatePeople);
}
}
FundingCorpPolicy findFundingCorpPolicyByCorpPolicyId(Long corpPolicyId);
/** FundingAssetAllocationsPrograms findFundingAssetAllocationsProgramsByCorpPolicyIdAndPlanDate(Long corpPolicyId, String planDate);
* 通过资方id 查找资产计划开关
* @param corpPolicyId
* @return
*/
public FundingCorpPolicy findFundingCorpPolicyByCorpPolicyId(Long corpPolicyId) {
return fundingCorpPolicyRepository.findByFundingCorpId(corpPolicyId);
}
/** LoanApplicationHistory findLoanApplicationHistoryById(Long loanId);
*
* @param corpPolicyId 资方id
* @param planDate 资产计划日期 精确到天
* @return
*/
public FundingAssetAllocationsPrograms findFundingAssetAllocationsProgramsByCorpPolicyIdAndPlanDate(Long corpPolicyId, String planDate) {
return fundingAssetAllocationsProgramsRepository.findByFundCorpIdAndPlanDate(corpPolicyId, planDate);
}
public LoanApplicationHistory findLoanApplicationHistoryById(Long loanId) {
return loanApplicationHistoryRepository.findById(loanId);
}
/**
* 验证资产计划 是否有效
* @param corpPolicyId
* @param planDate 日期 只能要天
* @return
*/
public Boolean validateCorpPolicy(Long corpPolicyId, Date planDate) {
Boolean isValidate = true;
FundingCorpPolicy fundingCorpPolicy = findFundingCorpPolicyByCorpPolicyId(corpPolicyId);
isValidate = isValidate & fundingCorpPolicy.getIsAutoAssign() & fundingCorpPolicy.getIsAutoLoan();
FundingAssetAllocationsPrograms fundingAssetAllocationsPrograms = findFundingAssetAllocationsProgramsByCorpPolicyIdAndPlanDate(corpPolicyId, DateUtil.format(planDate, DateUtil.YYYY_MM_DD));
return isValidate & (fundingAssetAllocationsPrograms != null);
}
/**
* 查询订单当前状态
* @param creditOrderNumber
* @param loanId
* @return
*/
public ServiceResult<XyqbCurrentOrderStatusServiceResultModel> getXyqbOrderStatus(String creditOrderNumber, Long loanId) {
Map paramMap = Maps.newHashMap();
paramMap.put("orderNo", creditOrderNumber);
if (loanId != null && loanId > 1) {
paramMap.put("loanId", loanId);
}
paramMap = SignUtil.sign(SignUtil.KA_API_KEY, paramMap);
final ServiceResult<XyqbCurrentOrderStatusServiceResultModel> orderStatus = xyqbCenter.getOrderStatus(paramMap);
log.info("[getXyqbOrderStatus]xyqb订单状态查询,creditOrderNumber={},result={}", creditOrderNumber, JSONTools.serialize(orderStatus));
return orderStatus;
}
/**
* 查询订单当前状态
* @param creditOrderNumber
* @param loanId
* @return
*/
public ServiceResult<XyqbHistoryOrderStatusServiceResultModel> getXyqbOrderHistoryStatus(String creditOrderNumber, Long loanId) {
Map paramMap = Maps.newHashMap();
paramMap.put("orderNo", creditOrderNumber);
if (loanId != null) {
paramMap.put("loanId", loanId);
}
paramMap = SignUtil.sign(SignUtil.KA_API_KEY, paramMap);
return xyqbCenter.getXyqbOrderHistoryStatus(paramMap);
}
/**
* 放款 放款结果通知
* @param loanId 订单loanId
* @param expectPayResult 期望放款结果 true 放款成功 false 放款失败
* @return
*/
public boolean payResultNotify(Long loanId, Boolean expectPayResult) {
if (Application.isDebug()) {
Map paramMap = Maps.newHashMap();
paramMap.put("orderNo", loanId);
paramMap.put("payOrderNo", loanId);
paramMap.put("payTime", "");
paramMap.put("payStatus", expectPayResult ? 3 : 4);
String result = xyqbCenter.pushLendingResult(paramMap);
log.info("[放款结果通知]xyqb返回结果result={}", result);
return "success".equals(result) || "SUCCESS".equals(result);
} else {
return false;
}
} Boolean validateCorpPolicy(Long corpPolicyId, Date planDate);
ServiceResult<XyqbCurrentOrderStatusServiceResultModel> getXyqbOrderStatus(String creditOrderNumber, Long loanId);
ServiceResult<XyqbHistoryOrderStatusServiceResultModel> getXyqbOrderHistoryStatus(String creditOrderNumber, Long loanId);
boolean payResultNotify(Long loanId, Boolean expectPayResult);
Tuple<Boolean,String> cleanUserActiveOrder(Long userId);
} }
package cn.quantgroup.cashloanflowboss.spi.xyqb.service;
import cn.quantgroup.cashloanflowboss.api.order.model.XyqbCurrentOrderStatusServiceResultModel;
import cn.quantgroup.cashloanflowboss.api.order.model.XyqbHistoryOrderStatusServiceResultModel;
import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.core.base.ServiceResult;
import cn.quantgroup.cashloanflowboss.core.base.Tuple;
import cn.quantgroup.cashloanflowboss.spi.jolyne.JolyneCenter;
import cn.quantgroup.cashloanflowboss.spi.jolyne.JolyneUtil;
import cn.quantgroup.cashloanflowboss.spi.xyqb.client.XYQBCenter;
import cn.quantgroup.cashloanflowboss.spi.xyqb.entity.*;
import cn.quantgroup.cashloanflowboss.spi.xyqb.repository.*;
import cn.quantgroup.cashloanflowboss.spi.xyqb.util.SignUtil;
import cn.quantgroup.cashloanflowboss.utils.DateUtil;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentMap;
/**
* Created by WeiWei on 2019/8/12.
*/
@Slf4j
@Service
public class XYQBCenterServiceImpl implements XYQBCenterService {
@Autowired
private WaitingFundingCorpOperatePeopleRepository waitingFundingCorpOperatePeopleRepository;
@Autowired
private ContractRepository contractRepository;
@Autowired
private CancelPreLoanRepository cancelPreLoanRepository;
@Autowired
private FundingCorpPolicyRepository fundingCorpPolicyRepository;
@Autowired
private FundingAssetAllocationsProgramsRepository fundingAssetAllocationsProgramsRepository;
@Autowired
private LoanApplicationHistoryRepository loanApplicationHistoryRepository;
@Autowired
private JolyneCenter jolyneCenter;
@Autowired
private XYQBCenter xyqbCenter;
/**
* 更新合同状态
*
* @param userId
* @return
*/
@Override
public int updateContractStatus(Long userId, Integer status) {
return this.contractRepository.updateContractStatus(userId, status);
}
/**
* 查询放款记录
*
* @param fundId
* @return
*/
@Override
public Map queryLendingRecordCount(Long fundId) {
return this.waitingFundingCorpOperatePeopleRepository.queryLendingRecordCount(fundId);
}
/**
* 贷前取消借款
* @param channelOrderNumber
* @return
*/
@Override
public Long cancelPreLoan(String channelOrderNumber) {
if (Application.isDebug()) {
return cancelPreLoanRepository.cancelPreLoan(channelOrderNumber);
} else {
return -1L;
}
}
/**
* 通过userId获取合同
* @param userId
* @return
*/
@Override
public Contract findContractByUserId(Long userId) {
return contractRepository.findByUserIdLastOne(userId);
}
/**
* 保存合同
* @param contract
*/
@Override
public void saveContract(Contract contract) {
if (Application.isDebug()) {
contractRepository.save(contract);
}
}
@Override
public WaitingFundingCorpOperatePeople findWaitingFundingCorpOperatePeopleByLoanId(Long loanId) {
return waitingFundingCorpOperatePeopleRepository.findByLoanApplicationHistoryId(loanId);
}
@Override
@Transactional
public void saveWaitingFundingCorpOperatePeople(WaitingFundingCorpOperatePeople waitingFundingCorpOperatePeople) {
if (Application.isDebug()) {
waitingFundingCorpOperatePeopleRepository.saveAndFlush(waitingFundingCorpOperatePeople);
}
}
/**
* 通过资方id 查找资产计划开关
* @param corpPolicyId
* @return
*/
@Override
public FundingCorpPolicy findFundingCorpPolicyByCorpPolicyId(Long corpPolicyId) {
return fundingCorpPolicyRepository.findByFundingCorpId(corpPolicyId);
}
/**
*
* @param corpPolicyId 资方id
* @param planDate 资产计划日期 精确到天
* @return
*/
@Override
public FundingAssetAllocationsPrograms findFundingAssetAllocationsProgramsByCorpPolicyIdAndPlanDate(Long corpPolicyId, String planDate) {
return fundingAssetAllocationsProgramsRepository.findByFundCorpIdAndPlanDate(corpPolicyId, planDate);
}
@Override
public LoanApplicationHistory findLoanApplicationHistoryById(Long loanId) {
return loanApplicationHistoryRepository.findById(loanId);
}
/**
* 验证资产计划 是否有效
* @param corpPolicyId
* @param planDate 日期 只能要天
* @return
*/
@Override
public Boolean validateCorpPolicy(Long corpPolicyId, Date planDate) {
Boolean isValidate = true;
FundingCorpPolicy fundingCorpPolicy = findFundingCorpPolicyByCorpPolicyId(corpPolicyId);
isValidate = isValidate & fundingCorpPolicy.getIsAutoAssign() & fundingCorpPolicy.getIsAutoLoan();
FundingAssetAllocationsPrograms fundingAssetAllocationsPrograms = findFundingAssetAllocationsProgramsByCorpPolicyIdAndPlanDate(corpPolicyId, DateUtil.format(planDate, DateUtil.YYYY_MM_DD));
return isValidate & (fundingAssetAllocationsPrograms != null);
}
/**
* 查询订单当前状态
* @param creditOrderNumber
* @param loanId
* @return
*/
@Override
public ServiceResult<XyqbCurrentOrderStatusServiceResultModel> getXyqbOrderStatus(String creditOrderNumber, Long loanId) {
Map paramMap = Maps.newHashMap();
paramMap.put("orderNo", creditOrderNumber);
if (loanId != null && loanId > 1) {
paramMap.put("loanId", loanId);
}
paramMap = SignUtil.sign(SignUtil.KA_API_KEY, paramMap);
final ServiceResult<XyqbCurrentOrderStatusServiceResultModel> orderStatus = xyqbCenter.getOrderStatus(paramMap);
log.info("[getXyqbOrderStatus]xyqb订单状态查询,creditOrderNumber={},result={}", creditOrderNumber, JSONTools.serialize(orderStatus));
return orderStatus;
}
/**
* 查询订单当前状态
* @param creditOrderNumber
* @param loanId
* @return
*/
@Override
public ServiceResult<XyqbHistoryOrderStatusServiceResultModel> getXyqbOrderHistoryStatus(String creditOrderNumber, Long loanId) {
Map paramMap = Maps.newHashMap();
paramMap.put("orderNo", creditOrderNumber);
if (loanId != null) {
paramMap.put("loanId", loanId);
}
paramMap = SignUtil.sign(SignUtil.KA_API_KEY, paramMap);
return xyqbCenter.getXyqbOrderHistoryStatus(paramMap);
}
/**
* 放款 放款结果通知
* @param loanId 订单loanId
* @param expectPayResult 期望放款结果 true 放款成功 false 放款失败
* @return
*/
@Override
public boolean payResultNotify(Long loanId, Boolean expectPayResult) {
if (Application.isDebug()) {
Map paramMap = Maps.newHashMap();
paramMap.put("orderNo", loanId);
paramMap.put("payOrderNo", loanId);
paramMap.put("payTime", "");
paramMap.put("payStatus", expectPayResult ? 3 : 4);
String result = xyqbCenter.pushLendingResult(paramMap);
log.info("[放款结果通知]xyqb返回结果result={}", result);
return "success".equals(result) || "SUCCESS".equals(result);
} else {
return false;
}
}
@Override
public Tuple<Boolean,String> cleanUserActiveOrder(Long userId) {
ArrayList<String> cancelList = Lists.newArrayList();
cancelList.add("update xyqb.quota_credit set is_active=0 where user_id=" + userId);
cancelList.add("update xyqb.quota_account set is_active=0 where user_id=" + userId);
cancelList.add("update xyqb.loan_application_history set progress=16 where user_id=" + userId);
cancelList.add("update xyqb.loan_application_history set is_active=0 where user_id=" + userId);
cancelList.add("delete from apply_quota_record where user_id=" + userId);
cancelList.add("delete from user_operation_history where user_id=" + userId);
String cancelResult = jolyneCenter.executeXYQBSQL(JolyneUtil.getJolneSql(cancelList));
JSONObject resp = JSONObject.parseObject(cancelResult);
boolean result = (Objects.nonNull(resp) && resp.containsKey("code")) ? "0000".equals(resp.get("code")) : false;
return new Tuple<>(result,result?"清除用户活跃订单成功":"清除用户活跃订单失败");
}
}
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