|
|
@ -1,13 +1,36 @@ |
|
|
|
package com.yxt.anrui.riskcenter.biz.loanrepaymenthistory; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import com.yxt.anrui.riskcenter.api.loanrepaymenthistory.LoanRepaymentHistory; |
|
|
|
import com.yxt.anrui.riskcenter.api.loanrepaymenthistory.LoanRepaymentHistoryDto; |
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
import com.yxt.anrui.base.api.basemodelmodprice.BaseModelModpriceImportReturn; |
|
|
|
import com.yxt.anrui.base.api.basemodelmodprice.BaseModelModpriceImportVo; |
|
|
|
import com.yxt.anrui.riskcenter.api.loanrepaymenthistory.*; |
|
|
|
import com.yxt.anrui.riskcenter.api.loanrepaymentplandetails.LoanRepaymentPlanDetails; |
|
|
|
import com.yxt.anrui.riskcenter.api.loanrepaymentplandetails.LoanRepaymentPlanDetailsDto; |
|
|
|
import com.yxt.anrui.riskcenter.biz.loanrepaymentplandetails.LoanRepaymentPlanDetailsService; |
|
|
|
import com.yxt.common.base.service.MybatisBaseService; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
|
import org.apache.poi.ss.usermodel.Sheet; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@ -18,6 +41,8 @@ import org.springframework.stereotype.Service; |
|
|
|
@Service |
|
|
|
public class LoanRepaymentHistoryService extends MybatisBaseService<LoanRepaymentHistoryMapper, LoanRepaymentHistory> { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private LoanRepaymentPlanDetailsService loanRepaymentPlanDetailsService; |
|
|
|
|
|
|
|
public ResultBean<String> saveHistory(LoanRepaymentHistoryDto dto) { |
|
|
|
ResultBean<String> rb = ResultBean.fireFail(); |
|
|
@ -32,4 +57,223 @@ public class LoanRepaymentHistoryService extends MybatisBaseService<LoanRepaymen |
|
|
|
int i = baseMapper.deleteHistory(scheduleSid); |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
|
|
|
|
public List<LoanRepaymentHistory> selHistoryByPlanSid(String planSid) { |
|
|
|
return baseMapper.selHistoryByPlanSid(planSid); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public ResultBean getExcelInfo(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException, ParseException { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String temp = request.getSession().getServletContext().getRealPath(File.separator) + "temp";// 临时目录
|
|
|
|
File tempFile = new File(temp); |
|
|
|
if (!tempFile.exists()) { |
|
|
|
tempFile.mkdirs(); |
|
|
|
} |
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) { |
|
|
|
return rb.fail().setMsg("上传文件不正确"); |
|
|
|
} |
|
|
|
|
|
|
|
int[] resultCell = new int[]{0, 1, 2, 3}; |
|
|
|
List<RepaymentExcelInfo> resultList = new ArrayList<>(); |
|
|
|
boolean isExcel2003 = true; |
|
|
|
if (fileName.matches("^.+\\.(?i)(xlsx)$")) { |
|
|
|
isExcel2003 = false; |
|
|
|
} |
|
|
|
InputStream is = file.getInputStream(); |
|
|
|
Workbook wb = null; |
|
|
|
if (isExcel2003) { |
|
|
|
wb = new HSSFWorkbook(is); |
|
|
|
} else { |
|
|
|
wb = new XSSFWorkbook(is); |
|
|
|
} |
|
|
|
Sheet sheet = wb.getSheetAt(0); |
|
|
|
ReturnExcelInfo importReturn = getSheetVal(sheet, resultCell); |
|
|
|
resultList = importReturn.getInfos(); |
|
|
|
System.out.println("结果是--->" + resultList); |
|
|
|
importReturn.setInfos(resultList); |
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
|
|
|
String currentTime = simpleDateFormat.format(System.currentTimeMillis()); |
|
|
|
StringBuffer checkBankNo = new StringBuffer(); |
|
|
|
if (!resultList.isEmpty()) { |
|
|
|
int size = resultList.size(); |
|
|
|
importReturn.setCheckInfo(currentTime + " " + "录入成功" + String.valueOf(size) + "条记录。"); |
|
|
|
//保存还款记录
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
for (RepaymentExcelInfo repaymentExcelInfo : resultList) { |
|
|
|
List<LoanRepaymentPlanDetails> planDetails = loanRepaymentPlanDetailsService.selPlanByNoAndPeriod(repaymentExcelInfo.getBankContractNo(), repaymentExcelInfo.getPeriod()); |
|
|
|
if (!planDetails.isEmpty()) { |
|
|
|
for (LoanRepaymentPlanDetails planDetail : planDetails) { |
|
|
|
LoanRepaymentHistory repaymentHistory = new LoanRepaymentHistory(); |
|
|
|
repaymentHistory.setBuckle("未申请"); |
|
|
|
repaymentHistory.setBuckleKey("001"); |
|
|
|
repaymentHistory.setScheduleSid(planDetail.getScheduleSid()); |
|
|
|
repaymentHistory.setPlanDetailSid(planDetail.getSid()); |
|
|
|
repaymentHistory.setActualDate(sdf.parse(repaymentExcelInfo.getRealReturnTime())); |
|
|
|
BigDecimal realMoney = new BigDecimal(repaymentExcelInfo.getRealMoney()); |
|
|
|
BigDecimal divide = realMoney.divide(new BigDecimal(planDetails.size()), 2, BigDecimal.ROUND_HALF_UP); |
|
|
|
repaymentHistory.setActualMoney(divide); |
|
|
|
repaymentHistory.setDataTime(new DateTime()); |
|
|
|
List<LoanRepaymentHistory> histories = baseMapper.selHistoryByPlanSid(planDetail.getSid()); |
|
|
|
BigDecimal returned = new BigDecimal(0); |
|
|
|
if (!histories.isEmpty()) { |
|
|
|
for (LoanRepaymentHistory history : histories) { |
|
|
|
returned = history.getActualMoney().add(returned); |
|
|
|
} |
|
|
|
} |
|
|
|
BigDecimal decimal = returned.add(divide); |
|
|
|
BigDecimal dueMoney = planDetail.getDueMoney(); |
|
|
|
BigDecimal subtract = dueMoney.subtract(decimal); |
|
|
|
repaymentHistory.setOutstandingMoney(subtract); |
|
|
|
baseMapper.insert(repaymentHistory); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return rb.success().setData(importReturn); |
|
|
|
} else { |
|
|
|
String checkResult = importReturn.getCheckInfo(); |
|
|
|
return rb.fail().setMsg(checkResult); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private ReturnExcelInfo getSheetVal(Sheet sheet, int[] resultCell) { |
|
|
|
ReturnExcelInfo importReturn = new ReturnExcelInfo(); |
|
|
|
List<RepaymentExcelInfo> importVoList = new ArrayList<>(); |
|
|
|
int[] resultIndex = new int[resultCell.length]; |
|
|
|
StringBuffer sb = new StringBuffer(); |
|
|
|
for (int r = 1; r <= sheet.getLastRowNum(); r++) { |
|
|
|
Row row = sheet.getRow(r); |
|
|
|
if (row == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
RepaymentExcelInfo importVo = new RepaymentExcelInfo(); |
|
|
|
for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) { |
|
|
|
String trim = new String(); |
|
|
|
try { |
|
|
|
trim = getCellVal(row.getCell(i)).toString().trim(); |
|
|
|
if (StringUtils.isBlank(trim)) { |
|
|
|
NullPointerException nullPointerException = new NullPointerException(); |
|
|
|
} |
|
|
|
String temp = getCellVal(row.getCell(i)).toString().trim(); |
|
|
|
for (int j = 0; j < resultCell.length; j++) { |
|
|
|
if (i == resultCell[j]) { |
|
|
|
switch (i) { |
|
|
|
case 0: |
|
|
|
importVo.setBankContractNo(temp); |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
importVo.setPeriod(temp); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
importVo.setRealReturnTime(temp); |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
importVo.setRealMoney(temp); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
} else { |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
if (StringUtils.isBlank(trim)) { |
|
|
|
String word = new String(); |
|
|
|
switch (i) { |
|
|
|
case 0: |
|
|
|
word = "资方合同号"; |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
word = "期数"; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
word = "实还日期"; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
word = "实还金额"; |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
String checkResult = "第" + (r + 1) + "行" + word + "为空"; |
|
|
|
sb.append(checkResult).append(";"); |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
importVoList.add(importVo); |
|
|
|
} |
|
|
|
importReturn.setInfos(importVoList); |
|
|
|
if (StringUtils.isNotBlank(sb.toString())) { |
|
|
|
sb.delete(sb.length() - 1, sb.length()); |
|
|
|
importReturn.setCheckInfo(sb.toString()); |
|
|
|
importReturn.setInfos(new ArrayList<>()); |
|
|
|
return importReturn; |
|
|
|
} |
|
|
|
return importReturn; |
|
|
|
} |
|
|
|
|
|
|
|
public Object getCellVal(Cell cell) { |
|
|
|
Object obj = null; |
|
|
|
if (cell != null) { |
|
|
|
switch (cell.getCellTypeEnum()) { |
|
|
|
case BOOLEAN: |
|
|
|
obj = cell.getBooleanCellValue(); |
|
|
|
break; |
|
|
|
case ERROR: |
|
|
|
obj = cell.getErrorCellValue(); |
|
|
|
break; |
|
|
|
case NUMERIC: |
|
|
|
obj = cell.getNumericCellValue(); |
|
|
|
break; |
|
|
|
case STRING: |
|
|
|
obj = cell.getStringCellValue(); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
return obj; |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<String> updateRecord(LoanRepaymentHistoryUpdate dto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String sid = dto.getSid(); |
|
|
|
LoanRepaymentHistory repaymentHistory = fetchBySid(sid); |
|
|
|
if (StringUtils.isNotBlank(dto.getReturnWay())) { |
|
|
|
repaymentHistory.setReturnWay(dto.getReturnWay()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(dto.getReturnWayKey())) { |
|
|
|
repaymentHistory.setReturnWayKey(dto.getReturnWayKey()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(dto.getActualMoney())) { |
|
|
|
BigDecimal realMoney = new BigDecimal(dto.getActualMoney()); |
|
|
|
repaymentHistory.setActualMoney(realMoney); |
|
|
|
List<LoanRepaymentHistory> histories = baseMapper.selHistoryByPlanSid(repaymentHistory.getPlanDetailSid()); |
|
|
|
BigDecimal returned = new BigDecimal(0); |
|
|
|
if (!histories.isEmpty()) { |
|
|
|
for (LoanRepaymentHistory history : histories) { |
|
|
|
returned = history.getActualMoney().add(returned); |
|
|
|
} |
|
|
|
} |
|
|
|
LoanRepaymentPlanDetails loanRepaymentPlanDetails = loanRepaymentPlanDetailsService.fetchBySid(repaymentHistory.getPlanDetailSid()); |
|
|
|
if (null != loanRepaymentPlanDetails) { |
|
|
|
BigDecimal decimal = returned.add(realMoney); |
|
|
|
BigDecimal dueMoney = loanRepaymentPlanDetails.getDueMoney(); |
|
|
|
BigDecimal subtract = dueMoney.subtract(decimal); |
|
|
|
repaymentHistory.setOutstandingMoney(subtract); |
|
|
|
} |
|
|
|
} |
|
|
|
baseMapper.updateById(repaymentHistory); |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<LoanRepaymentHistoryUpdate> updateRecordInfo(String sid) { |
|
|
|
ResultBean<LoanRepaymentHistoryUpdate> rb = ResultBean.fireFail(); |
|
|
|
LoanRepaymentHistoryUpdate vo = baseMapper.updateRecordInfo(sid); |
|
|
|
return rb.success().setData(vo); |
|
|
|
} |
|
|
|
} |
|
|
|