放款通知导出

master
chen 4 years ago
parent af532f936e
commit ebfae36313
  1. 43
      dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/controller/DgLoanNoticeController.java
  2. 127
      dq-framework-utils/src/main/java/com/daqing/framework/utils/NumberToCN.java

@ -2,10 +2,17 @@ package com.daqing.financial.guarantee.controller;
import com.daqing.financial.guarantee.model.request.*;
import com.daqing.financial.guarantee.model.response.GuaranteeLetterListResponse;
import com.daqing.financial.guarantee.model.response.LoanNoticeListResponse;
import com.daqing.financial.guarantee.service.IDgGuaranteeLetterAssignUserService;
import com.daqing.financial.guarantee.service.IDgLoanNoticeService;
import com.daqing.financial.guarantee.service.impl.DgGuaranteeLetterAssignUserServiceImpl;
import com.daqing.framework.domain.guarantee.DgGuaranteeLetterAssignUser;
import com.daqing.framework.model.response.ResponseResult;
import com.daqing.framework.utils.DateUtil;
import com.daqing.framework.utils.NumberToCN;
import com.daqing.framework.utils.PageUtils;
import com.deepoove.poi.XWPFTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -14,6 +21,9 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
/**
* <p>
@ -31,6 +41,9 @@ public class DgLoanNoticeController {
@Autowired
private IDgLoanNoticeService loanNoticeService;
@Autowired
private IDgGuaranteeLetterAssignUserService guaranteeLetterAssignUserService;
@ApiOperation(value = "放款通知记录列表",response = LoanNoticeListResponse.class)
@PostMapping("/loanNoticeList")
public ResponseResult loanNoticeList(
@ -61,4 +74,34 @@ public class DgLoanNoticeController {
return result ? ResponseResult.SUCCESS("更新成功!"):ResponseResult.FAIL(40005,"更新失败!");
}
@ApiOperation(value = "导出放款通知")
@GetMapping("/exportLoanNotice")
public void exportLoanNotice(
@ApiParam(name = "businessId", value = "业务id", required = true)
@RequestParam String businessId,HttpServletResponse httpServletResponse){
GuaranteeLetterListResponse response = guaranteeLetterAssignUserService.selectGuaranteeLetter(businessId);
String bank = response.getBank();
String name = response.getName();
Double loanMoney = response.getLoanMoney();
BigDecimal numberOfMoney = new BigDecimal(loanMoney*10000);
String money = NumberToCN.number2CNMontrayUnit(numberOfMoney);
XWPFTemplate template = XWPFTemplate.compile("D:\\template\\templateTwo.docx").render(
new HashMap<String, Object>(){{
put("bankName", bank);
put("clientName", name);
put("loanMoney", money);
}});
try {
httpServletResponse.setContentType("application/msword");
String filePath = name + "放款通知.docx";
String fileName = new String(filePath.getBytes(), "ISO-8859-1");
httpServletResponse.addHeader("Content-Disposition", "filename=" + fileName);
template.write(httpServletResponse.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,127 @@
package com.daqing.framework.utils;
import java.math.BigDecimal;
/**
* @Author chen
* @DATE 2020/12/2 16:32
* @Version 1.0
*/
public class NumberToCN {
/**
* 汉语中数字大写
*/
private static final String[] CN_UPPER_NUMBER = { "零", "壹", "贰", "叁", "肆",
"伍", "陆", "柒", "捌", "玖" };
/**
* 汉语中货币单位大写这样的设计类似于占位符
*/
private static final String[] CN_UPPER_MONETRAY_UNIT = { "分", "角", "元",
"拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾",
"佰", "仟" };
/**
* 特殊字符
*/
private static final String CN_FULL = "整";
/**
* 特殊字符
*/
private static final String CN_NEGATIVE = "负";
/**
* 金额的精度默认值为2
*/
private static final int MONEY_PRECISION = 2;
/**
* 特殊字符零元整
*/
private static final String CN_ZEOR_FULL = "零元" + CN_FULL;
/**
* 把输入的金额转换为汉语中人民币的大写
*
* @param numberOfMoney
* 输入的金额
* @return 对应的汉语大写
*/
public static String number2CNMontrayUnit(BigDecimal numberOfMoney) {
StringBuffer sb = new StringBuffer();
// -1, 0, or 1 as the value of this BigDecimal is negative, zero, or
// positive.
int signum = numberOfMoney.signum();
// 零元整的情况
if (signum == 0) {
return CN_ZEOR_FULL;
}
// 这里会进行金额的四舍五入
long number = numberOfMoney.movePointRight(MONEY_PRECISION)
.setScale(0, 4).abs().longValue();
// 得到小数点后两位值
long scale = number % 100;
int numUnit = 0;
int numIndex = 0;
boolean getZero = false;
// 判断最后两位数,一共有四中情况:00 = 0, 01 = 1, 10, 11
if (!(scale > 0)) {
numIndex = 2;
number = number / 100;
getZero = true;
}
if ((scale > 0) && (!(scale % 10 > 0))) {
numIndex = 1;
number = number / 10;
getZero = true;
}
int zeroSize = 0;
while (true) {
if (number <= 0) {
break;
}
// 每次获取到最后一个数
numUnit = (int) (number % 10);
if (numUnit > 0) {
if ((numIndex == 9) && (zeroSize >= 3)) {
sb.insert(0, CN_UPPER_MONETRAY_UNIT[6]);
}
if ((numIndex == 13) && (zeroSize >= 3)) {
sb.insert(0, CN_UPPER_MONETRAY_UNIT[10]);
}
sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
sb.insert(0, CN_UPPER_NUMBER[numUnit]);
getZero = false;
zeroSize = 0;
} else {
++zeroSize;
if (!(getZero)) {
sb.insert(0, CN_UPPER_NUMBER[numUnit]);
}
if (numIndex == 2) {
if (number > 0) {
sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
}
} else if (((numIndex - 2) % 4 == 0) && (number % 1000 > 0)) {
sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
}
getZero = true;
}
// 让number每次都去掉最后一个数
number = number / 10;
++numIndex;
}
// 如果signum == -1,则说明输入的数字为负数,就在最前面追加特殊字符:负
if (signum == -1) {
sb.insert(0, CN_NEGATIVE);
}
// 输入的数字小数点后两位为"00"的情况,则要在最后追加特殊字符:整
if (!(scale > 0)) {
sb.append(CN_FULL);
}
return sb.toString();
}
public static void main(String[] args) {
double money = 10;
BigDecimal numberOfMoney = new BigDecimal(money);
String s = NumberToCN.number2CNMontrayUnit(numberOfMoney);
System.out.println("你输入的金额为:【" + money + "】 #--# [" + s.toString() + "]");
}
}
Loading…
Cancel
Save