package project.monitor.loan.internal;
|
|
import java.io.Serializable;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.HashSet;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Set;
|
import java.util.regex.Pattern;
|
import java.util.stream.Collectors;
|
|
import org.springframework.cglib.beans.BeanMap;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import kernel.exception.BusinessException;
|
import kernel.web.ApplicationUtil;
|
import kernel.web.Page;
|
import project.monitor.loan.LoanParam;
|
import project.monitor.loan.LoanService;
|
import project.monitor.loan.SimpleLoanOrder;
|
import project.party.model.Party;
|
|
/**
|
* @author JORGE
|
* @description 借贷服务接口实现类
|
*/
|
@SuppressWarnings("unchecked")
|
public class LoanServiceImpl implements LoanService{
|
/**
|
* 借贷状态字典
|
*/
|
private static HashMap<Integer,String> stateMap;
|
|
/**
|
* 付款方式字典
|
*/
|
private static HashMap<Integer,String> repayments;
|
|
/**
|
* 逗号正则表达式
|
*/
|
private static Pattern commaPattern=Pattern.compile(",");
|
|
/**
|
* 冒号正则表达式
|
*/
|
private static Pattern colonPattern=Pattern.compile(":");
|
|
/**
|
* 放款机构字典
|
*/
|
private static HashMap<Integer,String> lendingInstitutions;
|
|
public LoanServiceImpl() {
|
stateMap=new HashMap<Integer,String>();
|
repayments=new HashMap<Integer,String>();
|
lendingInstitutions=new HashMap<Integer,String>();
|
|
stateMap.put(1, "未审");
|
stateMap.put(2, "通过");
|
stateMap.put(3, "驳回");
|
|
repayments.put(1,"到期还本息");
|
repayments.put(2,"到期还本金");
|
repayments.put(3,"到期还利息");
|
|
lendingInstitutions.put(1,"LOAN1");
|
lendingInstitutions.put(2,"LOAN2");
|
lendingInstitutions.put(3,"LOAN3");
|
}
|
|
@Override
|
public Boolean addLoanOrder(SimpleLoanOrder simpleLoanOrder) {
|
Object primaryKey=ApplicationUtil.executeInsert(simpleLoanOrder);
|
return null!=primaryKey;
|
}
|
|
@Override
|
public HashMap<String,Object> getLoanParams(String uuid) {
|
LoanParam loanParam=null;
|
if(null==uuid || (uuid=uuid.trim()).isEmpty()) {
|
List<LoanParam> loanParamList=ApplicationUtil.executeSelect(LoanParam.class);
|
loanParam=(null==loanParamList || loanParamList.isEmpty())?null:loanParamList.get(0);
|
}else {
|
loanParam=ApplicationUtil.executeGet(uuid, LoanParam.class);
|
}
|
|
if(null==loanParam) return null;
|
|
HashMap<String,Object> paramMap=new HashMap<String,Object>(BeanMap.create(loanParam));
|
String term=(String)paramMap.get("term");
|
if(null==term || (term=term.trim()).isEmpty()) {
|
paramMap.put("termList",new Object[0]);
|
}else {
|
paramMap.put("termList",commaPattern.splitAsStream(term).map(tr->new String[] {tr,tr}).collect(Collectors.toList()));
|
}
|
|
String repayCycle=(String)paramMap.get("repayCycle");
|
if(null==repayCycle || (repayCycle=repayCycle.trim()).isEmpty()) {
|
paramMap.put("repayCycleList",new Object[0]);
|
}else {
|
paramMap.put("repayCycleList",commaPattern.splitAsStream(repayCycle).map(rc->new String[] {rc,rc}).collect(Collectors.toList()));
|
}
|
|
String dailyRate=(String)paramMap.get("dailyRate");
|
if(null==dailyRate || (dailyRate=dailyRate.trim()).isEmpty()) {
|
paramMap.put("dailyRateList",new Object[0]);
|
}else {
|
paramMap.put("dailyRateList",commaPattern.splitAsStream(dailyRate).map(dr->new String[] {dr,dr}).collect(Collectors.toList()));
|
}
|
|
String repayment=(String)paramMap.get("repayment");
|
if(null==repayment || (repayment=repayment.trim()).isEmpty()) {
|
paramMap.put("repaymentList",new Object[0]);
|
}else {
|
paramMap.put("repaymentList",commaPattern.splitAsStream(repayment).map(rep->colonPattern.split(rep)).collect(Collectors.toList()));
|
}
|
|
String lendingInstitution=(String)paramMap.get("lendingInstitution");
|
if(null==lendingInstitution || (lendingInstitution=lendingInstitution.trim()).isEmpty()) {
|
paramMap.put("lendingList",new Object[0]);
|
}else {
|
paramMap.put("lendingList",commaPattern.splitAsStream(lendingInstitution).map(led->colonPattern.split(led)).collect(Collectors.toList()));
|
}
|
|
paramMap.put("stateList",commaPattern.splitAsStream("1:未审,2:通过,3:驳回").map(stat->colonPattern.split(stat)).collect(Collectors.toList()));
|
|
return paramMap;
|
}
|
|
@Override
|
public Page pagedQuery(Map<String, Object> queryParams) {
|
int pageSize=(Integer)queryParams.get("pageSize");
|
int pageNo=(Integer)queryParams.get("pageNo");
|
if (pageNo <= 0) pageNo = 1;
|
|
Page page = new Page(pageNo, pageSize, Integer.MAX_VALUE);
|
String userName=(String)queryParams.get("userName");
|
String orderNo=(String)queryParams.get("orderNo");
|
int status=(Integer)queryParams.get("status");
|
|
ArrayList<Object> paramList=new ArrayList<Object>();
|
StringBuilder whereStatement=new StringBuilder("WHERE 1=1 ");
|
|
if(0!=status) {
|
whereStatement.append("AND STATE=? ");
|
paramList.add(status);
|
}
|
|
if(null!=orderNo && !(orderNo=orderNo.trim()).isEmpty()) {
|
whereStatement.append("AND UUID=? ");
|
paramList.add(orderNo);
|
}
|
|
if(null!=userName && !(userName=userName.trim()).isEmpty()) {
|
whereStatement.append("AND PARTY_ID=(SELECT UUID FROM PAT_PARTY WHERE USERNAME=?) ");
|
paramList.add(userName);
|
}
|
|
whereStatement.append("LIMIT ?,?");
|
paramList.add(page.getFirstElementNumber());
|
paramList.add(pageSize);
|
|
List<SimpleLoanOrder> orderList=ApplicationUtil.executeSelect(SimpleLoanOrder.class,whereStatement.toString(),paramList.toArray(new Object[paramList.size()]));
|
if(null==orderList || orderList.isEmpty()) return page;
|
|
String partyIds=orderList.stream().map(order->order.getPartyId()).collect(Collectors.joining(","));
|
List<Party> partyList=ApplicationUtil.executeSelect(Party.class,"WHERE FIND_IN_SET(UUID,?)",new Object[] {partyIds});
|
Map<?,?> idToNameMap=partyList.stream().collect(Collectors.toMap(party->party.getId(),party->party.getUsername(),(oldname,newname)->newname));
|
|
List<HashMap<String,Object>> transferList=orderList.stream().map(order->{
|
Integer state=order.getState();
|
Integer rep=order.getRepayment();
|
String houseImgs=order.getHouseImgs();
|
Integer led=order.getLendingInstitution();
|
houseImgs=null==houseImgs?null:(houseImgs=houseImgs.trim()).isEmpty()?null:houseImgs;
|
HashMap<String,Object> transferMap=new HashMap<String,Object>(BeanMap.create(order));
|
transferMap.put("state", new Object[] {state,stateMap.get(state)});
|
transferMap.put("userName", idToNameMap.get(order.getPartyId()));
|
transferMap.put("repayment", new Object[] {rep,repayments.get(rep)});
|
transferMap.put("houseImgs", null==houseImgs?null:commaPattern.split(houseImgs)[0]);
|
transferMap.put("lendingInstitution", new Object[] {led,lendingInstitutions.get(led)});
|
return transferMap;
|
}).collect(Collectors.toList());
|
|
page.setElements(transferList);
|
|
return page;
|
}
|
|
@Override
|
public boolean deleteLoanOrder(String orderId) {
|
if(null==orderId || (orderId=orderId.trim()).isEmpty()) {
|
throw new BusinessException("申请单ID不能为空!");
|
}
|
|
int count=ApplicationUtil.executeDel(orderId,SimpleLoanOrder.class);
|
if(1!=count) {
|
throw new BusinessException("根据申请单ID删除了多条记录,说明申请单ID重复!");
|
}
|
|
return count==1?true:false;
|
}
|
|
@Override
|
public boolean updateLoanOrderState(String orderId, String status) {
|
if(null==orderId || (orderId=orderId.trim()).isEmpty()) {
|
throw new BusinessException("申请单ID不能为空!");
|
}
|
|
if(null==status || (status=status.trim()).isEmpty()) {
|
throw new BusinessException("审核状态不能为空!");
|
}
|
|
int state="true".equalsIgnoreCase(status)?2:3;
|
int count=ApplicationUtil.getBean(JdbcTemplate.class).update("UPDATE T_SIMPLE_LOAN_ORDER SET state=? WHERE UUID=?",state,orderId);
|
if(1!=count) {
|
throw new BusinessException("根据申请单ID修改了多条记录,说明申请单ID重复!");
|
}
|
|
return true;
|
}
|
|
@Override
|
public Boolean modLoanOrder(SimpleLoanOrder simpleLoanOrder) {
|
Serializable id=simpleLoanOrder.getId();
|
if(null==id) {
|
throw new BusinessException("申请单ID不能为空!");
|
}
|
|
Set<String> excludeFields=new HashSet<String>();
|
excludeFields.add("id");
|
excludeFields.add("partyId");
|
excludeFields.add("state");
|
excludeFields.add("houseImgs");
|
excludeFields.add("incomeImg");
|
|
int count=ApplicationUtil.executeUpdate(simpleLoanOrder,excludeFields);
|
if(1!=count) {
|
throw new BusinessException("根据申请单ID修改了多条记录,说明申请单ID重复!");
|
}
|
|
return true;
|
}
|
|
@Override
|
public SimpleLoanOrder getLoanOrder(String orderId) {
|
if(null==orderId || (orderId=orderId.trim()).isEmpty()) {
|
throw new BusinessException("申请单ID不能为空!");
|
}
|
return ApplicationUtil.executeGet(orderId,SimpleLoanOrder.class);
|
}
|
}
|