Commit c58b71fd authored by 111's avatar 111

对账单打印

parent efbf12be
......@@ -11,8 +11,13 @@ import com.hand.hls.hlcm.cont.service.ConExportService;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.*;
import javax.imageio.ImageIO;
......@@ -22,14 +27,14 @@ import javax.servlet.http.HttpServletResponse;
import com.hand.hls.hlcm.cont.util.ExcelFormatUtil;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.*;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFDataFormat;
import org.codehaus.jackson.annotate.JsonSubTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -61,7 +66,7 @@ public class ConExportServiceImpl implements ConExportService {
//return null;
}
private void export(HashMap map, LinkedList list, HttpServletResponse response) {
private void export(HashMap map, LinkedList list, HttpServletResponse response) throws ParseException {
//logger.info(">>>>>>>>>>>>>>>>>>>>开始进入导出方法>>>>>>>>>>");
SXSSFWorkbook wb = new SXSSFWorkbook(1000);// 保留1000条数据在内存中
SXSSFSheet sheet = wb.createSheet();
......@@ -75,7 +80,6 @@ public class ConExportServiceImpl implements ConExportService {
ClassLoader classLoader = this.getClass().getClassLoader();
URL resource = classLoader.getResource("/");
String path = resource.getPath();
System.out.println(path);
bufferImg = ImageIO.read(new File(path + "com/hand/hls/hlcm/cont/img/HonglingNew.jpg"));
ImageIO.write(bufferImg, "jpg", byteArrayOut);
......@@ -178,52 +182,103 @@ public class ConExportServiceImpl implements ConExportService {
//logger.info(">>>>>>>>>>>>>>>>>>>>开始遍历数据组装单元格内容>>>>>>>>>>");
// 每一列字段名
String[] strs = new String[]{"款项性质", "期次", "约定支付日", "应付金额", "实际收款日", "收款金额", "实收违约金", "未收金额"};
// String[] strs = new String[]{"款项性质", "期次", "约定支付日", "应付金额", "实际收款日", "收款金额", "实收违约金", "未收金额"};
// modify by lihh 20210308 修改描述为当期逾期金额
String[] strs = new String[]{"款项性质", "期次", "约定支付日", "应付金额", "实际收款日", "收款金额", "实收违约金", "当期逾期金额"};
// 字段名所在表格的宽度
int[] ints = new int[]{2500, 1800, 3000, 3000, 3000, 3000, 3000, 3000};
// 设置表头样式
ExcelFormatUtil.initColumn(sheet, contentTable, strs, ints, 16);
//logger.info(">>>>>>>>>>>>>>>>>>>>表头样式设置完成>>>>>>>>>>");
double amount = 0;
for (int i = 0; i < list.size(); i++) {
LinkedHashMap<String, Object> map1 = (LinkedHashMap<String, Object>) list.get(i);
SXSSFRow row = sheet.createRow(i + 17);
int j = 1;
SXSSFCell cell = row.createCell(j++);
if (map1.get("CF_ITEM_N") != null) {
// add by lihh 判断记录是否重复
if(i>=1&&map1.get("TIMES") != null){
// 获取上一条记录
LinkedHashMap<String, Object> temp = (LinkedHashMap<String, Object>) list.get(i - 1);
if(!map1.get("TIMES").equals( temp.get("TIMES")) || !(map1.get("CF_ITEM_N").equals(temp.get("CF_ITEM_N")))) {
cell.setCellValue((String) map1.get("CF_ITEM_N")); // 款项性质
} else {
}else {
// 重复记录的金额
amount += new DecimalFormat().parse(map1.get("DUE_AMOUNT").toString()).doubleValue();
cell.setCellValue(""); // 款项性质
}
}else {
cell.setCellValue((String) map1.get("CF_ITEM_N")); // 款项性质
}
}
cell.setCellStyle(contentTable);
cell = row.createCell(j++);
if (map1.get("TIMES") != null) {
cell.setCellValue(ExcelFormatUtil.getBigDecimal(map1.get("TIMES")).toString()); // 期次
} else {
if(i>=1){
LinkedHashMap<String, Object> temp = (LinkedHashMap<String, Object>) list.get(i - 1);
if(!map1.get("TIMES").equals( temp.get("TIMES"))|| !(map1.get("CF_ITEM_N").equals(temp.get("CF_ITEM_N")))) {
cell.setCellValue(map1.get("TIMES").toString()); // 期次
}else {
cell.setCellValue(""); // 期次
}
}else {
cell.setCellValue(map1.get("TIMES").toString()); // 期次
}
}
cell.setCellStyle(contentTable);
cell = row.createCell(j++);
if (map1.get("DUE_DATE") != null) {
if (i>=1) {
LinkedHashMap<String, Object> temp = (LinkedHashMap<String, Object>) list.get(i - 1);
if (!map1.get("TIMES").equals(temp.get("TIMES"))|| !(map1.get("CF_ITEM_N").equals(temp.get("CF_ITEM_N")))) {
cell.setCellValue((String) map1.get("DUE_DATE")); // 应付日
} else {
cell.setCellValue(""); // 应付日
}
}else {
cell.setCellValue((String) map1.get("DUE_DATE")); // 应付日
}
}
cell.setCellStyle(contentTable);
cell = row.createCell(j++);
if (map1.get("DUE_AMOUNT") != null) {
cell.setCellValue((String) map1.get("DUE_AMOUNT")); // 应付金额
if (i>=1) {
// 取上一条记录
LinkedHashMap<String, Object> temp = (LinkedHashMap<String, Object>) list.get(i - 1);
BigDecimal x = new BigDecimal(100);
//如果CF_ITEM = 100, 打印计算后的合计金额
if(x.compareTo((BigDecimal) map1.get("CF_ITEM")) ==0){
DataFormat df = wb.createDataFormat(); // 此处设置数据格式
contentTable.setDataFormat(df.getFormat("#,##0.00"));//保留两位小数点
cell.setCellStyle(contentTable);
cell.setCellValue(new DecimalFormat().parse(map1.get("DUE_AMOUNT").toString()).doubleValue()- amount);
//如果期次和性质跟上条记录不一样,则打印
}else if(!map1.get("TIMES").equals(temp.get("TIMES"))|| !(map1.get("CF_ITEM_N").equals(temp.get("CF_ITEM_N")))) {
DataFormat df = wb.createDataFormat(); // 此处设置数据格式
contentTable.setDataFormat(df.getFormat("#,##0.00"));//保留两位小数点
cell.setCellStyle(contentTable);
cell.setCellValue(new DecimalFormat().parse(map1.get("DUE_AMOUNT").toString()).doubleValue());
//否则置空
}else{
cell.setCellValue("");
}
//如果是首付款,直接打印
}else {
DataFormat df = wb.createDataFormat(); // 此处设置数据格式
contentTable.setDataFormat(df.getFormat("#,##0.00"));//保留两位小数点
cell.setCellStyle(contentTable);
cell.setCellValue(new DecimalFormat().parse(map1.get("DUE_AMOUNT").toString()).doubleValue());
}
} else {
cell.setCellValue(""); // 应付金额
}
cell.setCellStyle(contentTable);
cell = row.createCell(j++);
if (map1.get("TRANSACTION_DATE") != null) {
cell.setCellValue((String) map1.get("TRANSACTION_DATE")); // 实际收款日
......@@ -234,7 +289,10 @@ public class ConExportServiceImpl implements ConExportService {
cell = row.createCell(j++);
if (map1.get("RECEIVED_AMOUNT") != null) {
cell.setCellValue((String) map1.get("RECEIVED_AMOUNT")); // 收款金额
DataFormat df = wb.createDataFormat(); // 此处设置数据格式
contentTable.setDataFormat(df.getFormat("#,##0.00"));//保留两位小数点
cell.setCellStyle(contentTable);
cell.setCellValue(new DecimalFormat().parse(map1.get("RECEIVED_AMOUNT").toString()).doubleValue());// 收款金额
} else {
cell.setCellValue(""); // 收款金额
}
......@@ -242,7 +300,10 @@ public class ConExportServiceImpl implements ConExportService {
cell = row.createCell(j++);
if (map1.get("RECEIVED_AMOUNT_9") != null) {
cell.setCellValue((String) map1.get("RECEIVED_AMOUNT_9")); // 实收违约金
DataFormat df = wb.createDataFormat(); // 此处设置数据格式
contentTable.setDataFormat(df.getFormat("#,##0.00"));//保留两位小数点
cell.setCellStyle(contentTable);
cell.setCellValue(new DecimalFormat().parse(map1.get("RECEIVED_AMOUNT_9").toString()).doubleValue());// 实收违约金
} else {
cell.setCellValue(""); // 实收违约金
}
......@@ -250,7 +311,16 @@ public class ConExportServiceImpl implements ConExportService {
cell = row.createCell(j++);
if (map1.get("UNRECEIVED_AMOUNT") != null) {
cell.setCellValue((String) map1.get("UNRECEIVED_AMOUNT")); // 未收金额
// 合计
BigDecimal x = new BigDecimal(100);
if(x.compareTo((BigDecimal) map1.get("CF_ITEM")) ==0){
cell.setCellValue("");
}else {
DataFormat df = wb.createDataFormat(); // 此处设置数据格式
contentTable.setDataFormat(df.getFormat("#,##0.00"));//保留两位小数点
cell.setCellStyle(contentTable);
cell.setCellValue(new DecimalFormat().parse(map1.get("UNRECEIVED_AMOUNT").toString()).doubleValue());// 未收金额
}
} else {
cell.setCellValue(""); // 未收金额
}
......
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