|
@@ -1,12 +1,29 @@
|
|
|
package org.jeecg.ctop.finance.settlement.service.serviceImpl;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
+import org.apache.poi.ss.usermodel.ClientAnchor;
|
|
|
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.ctop.finance.policy.utils.Check;
|
|
|
+import org.jeecg.ctop.finance.settlement.entity.vo.SettlementFileParamsVo;
|
|
|
import org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportBytedanceVo;
|
|
|
+import org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportKuaiShouVo;
|
|
|
import org.jeecg.ctop.finance.settlement.mapper.ReportSettlementMapper;
|
|
|
import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
|
|
|
+import org.jeecg.ctop.finance.utils.createExcelByTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@@ -19,6 +36,377 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
|
|
|
@Override
|
|
|
public List<SettlementReportBytedanceVo> getAccountTransactionDayBytedance() {
|
|
|
- return reportSettlementMapper.getAccountTransactionDayBytedance();
|
|
|
+ return reportSettlementMapper.getAccountTransactionDayBytedance(null);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result settlementReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ //第一步创建workbook
|
|
|
+ HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
+
|
|
|
+ //设置样式
|
|
|
+ HSSFCellStyle style = wb.createCellStyle();
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);//水平居中
|
|
|
+
|
|
|
+ //设置字体
|
|
|
+ HSSFFont font = wb.createFont();
|
|
|
+ font.setFontName("黑体");
|
|
|
+ font.setFontHeightInPoints((short) 12);//设置字体大小
|
|
|
+ style.setFont(font);
|
|
|
+
|
|
|
+ //查询 账户id
|
|
|
+ List<String> accountIdList = reportSettlementMapper.getAccountIdBytedance(paramsVo);
|
|
|
+
|
|
|
+ if (Check.isNull(accountIdList)){
|
|
|
+ return Result.errorMsg("该广告主和产品下无法查询到绑定的账户信息。");
|
|
|
+ }
|
|
|
+
|
|
|
+ int num = 0;
|
|
|
+
|
|
|
+ for (int k = 0; k < accountIdList.size(); k++) {
|
|
|
+
|
|
|
+ String accountId = accountIdList.get(k);
|
|
|
+ paramsVo.setAccountId(accountId);
|
|
|
+
|
|
|
+ //获取账户 日流水数据 根据账户id 和 年月 查询数据
|
|
|
+ List<SettlementReportBytedanceVo> settlementList = reportSettlementMapper.getAccountTransactionDayBytedance(paramsVo);
|
|
|
+ if (Check.isNull(settlementList)){
|
|
|
+ num++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //2:创建sheet 设置sheet名称
|
|
|
+ HSSFSheet sheet = wb.createSheet(accountId);
|
|
|
+
|
|
|
+ //画图的顶级管理器,一个sheet只能获取一个 (插入图片时 使用)
|
|
|
+ HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
|
|
+
|
|
|
+ //3:添加 第一行单元格
|
|
|
+ HSSFRow row0 = sheet.createRow(0);
|
|
|
+ HSSFCell cell0 = row0.createCell(0);
|
|
|
+ //设置 第一行 表头
|
|
|
+ cell0.setCellValue(paramsVo.getUploadYears()+"-头条结算单");
|
|
|
+ CellRangeAddress region = new CellRangeAddress(0, 0, 0, 10);
|
|
|
+ sheet.addMergedRegion(region);//合并行
|
|
|
+ cell0.setCellStyle(style);
|
|
|
+
|
|
|
+ //4:添加表头2行
|
|
|
+ HSSFRow row = sheet.createRow(1);
|
|
|
+
|
|
|
+ //5:创建第2行的单元格
|
|
|
+ HSSFCell cell = row.createCell(0); //第一个单元格
|
|
|
+ cell.setCellValue(" 日期 "); //设定值
|
|
|
+ cell.setCellStyle(style); //内容居中
|
|
|
+
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellValue(" 账户名称 ");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellValue(" 账户ID ");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellValue(" 所属代理商名称 ");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(4);
|
|
|
+ cell.setCellValue(" 所属代理商ID ");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(5);
|
|
|
+ cell.setCellValue("账户总支出(¥)");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(6);
|
|
|
+ cell.setCellValue("账户现金支出(¥)");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(7);
|
|
|
+ cell.setCellValue("账户赠款支出(¥)");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(8);
|
|
|
+ cell.setCellValue("账户总存入(¥)");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(9);
|
|
|
+ cell.setCellValue("账户总转入(¥)");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(10);
|
|
|
+ cell.setCellValue("账户总转出(¥)");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(11);
|
|
|
+ cell.setCellValue("账户日终结余(¥)");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(12);
|
|
|
+ cell.setCellValue("冻结(¥)");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < settlementList.size(); i++) {
|
|
|
+ SettlementReportBytedanceVo vo = settlementList.get(i);
|
|
|
+ //创建行 (表头占0-1行 所以 从 2开始)
|
|
|
+ row = sheet.createRow(i + 2);
|
|
|
+ sheet.autoSizeColumn(0, true);
|
|
|
+ sheet.autoSizeColumn(i + 1, true);
|
|
|
+ //创建单元格并且添加数据
|
|
|
+ row.createCell(0).setCellValue(vo.getDate());
|
|
|
+ row.createCell(1).setCellValue(vo.getAccountName());
|
|
|
+ row.createCell(2).setCellValue(vo.getAdvertiserId());
|
|
|
+ row.createCell(3).setCellValue("北京汇创思拓数字科技有限公司-ka");
|
|
|
+ row.createCell(4).setCellValue("73970348172");
|
|
|
+ row.createCell(5).setCellValue(vo.getCost());
|
|
|
+ row.createCell(6).setCellValue(vo.getCashCost());
|
|
|
+ row.createCell(7).setCellValue(vo.getRewardCost());
|
|
|
+ row.createCell(8).setCellValue(vo.getIncome());
|
|
|
+ row.createCell(9).setCellValue(vo.getTransferIn());
|
|
|
+ row.createCell(10).setCellValue(vo.getTransferOut());
|
|
|
+ row.createCell(11).setCellValue(vo.getBalance());
|
|
|
+ row.createCell(12).setCellValue(vo.getFrozen());
|
|
|
+ }
|
|
|
+
|
|
|
+ //先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
|
|
|
+ ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ //查询 图片 url
|
|
|
+ List<String> imageUrlList = reportSettlementMapper.getAccountImagesBytedance(accountId);
|
|
|
+
|
|
|
+ if (!Check.isNull(imageUrlList)){
|
|
|
+ for (int j = 0; j < imageUrlList.size(); j++) {
|
|
|
+ String imagePath = imageUrlList.get(j);
|
|
|
+ //通过图片网络地址 获取输入流
|
|
|
+ InputStream is = createExcelByTemplate.getInputStreamByUrl(imagePath);
|
|
|
+ BufferedImage bufferImg = ImageIO.read(is);
|
|
|
+ ImageIO.write(bufferImg, imagePath.substring(imagePath.lastIndexOf(".") + 1), byteArrayOut);
|
|
|
+ //anchor主要用于设置图片的属性
|
|
|
+ HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 2, settlementList.size() + 6 +(j*40), (short) 10, 90*(j+1));
|
|
|
+ //HSSFClientAnchor anchor2 = new HSSFClientAnchor(0, 0, 255, 255, (short) 5, settlementList.size() + 40, (short) 10, 40 * 2);
|
|
|
+ anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
|
|
|
+ //插入图片
|
|
|
+ patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(accountIdList.size() == num){
|
|
|
+ return Result.errorMsg("暂无数据。");
|
|
|
+ }
|
|
|
+
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
|
+ response.setHeader("Pragma", "no-cache");
|
|
|
+ response.setHeader("Cache-Control", "no-cache");
|
|
|
+ response.setDateHeader("Expires", 0);
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(paramsVo.getUploadYears()+"头条结算单.xlsx", "UTF-8"));
|
|
|
+ OutputStream output = response.getOutputStream();
|
|
|
+ BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
|
|
|
+ wb.write(bufferedOutPut);
|
|
|
+ bufferedOutPut.flush();
|
|
|
+ bufferedOutPut.close();
|
|
|
+ output.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("====>>>>", e.getMessage());
|
|
|
+ return Result.errorMsg(e.getMessage());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result settlementReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ //第一步创建workbook
|
|
|
+ HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
+
|
|
|
+ //设置样式
|
|
|
+ HSSFCellStyle style = wb.createCellStyle();
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);//水平居中
|
|
|
+
|
|
|
+ //设置字体
|
|
|
+ HSSFFont font = wb.createFont();
|
|
|
+ font.setFontName("黑体");
|
|
|
+ font.setFontHeightInPoints((short) 12);//设置字体大小
|
|
|
+ style.setFont(font);
|
|
|
+
|
|
|
+ //查询 账户id
|
|
|
+ List<String> accountIdList = reportSettlementMapper.getAccountIdBytedance(paramsVo);
|
|
|
+
|
|
|
+ if (Check.isNull(accountIdList)){
|
|
|
+ return Result.errorMsg("该广告主和产品下无法查询到绑定的快手账户信息。");
|
|
|
+ }
|
|
|
+
|
|
|
+ int num = 0;
|
|
|
+
|
|
|
+ for (int k = 0; k < accountIdList.size(); k++) {
|
|
|
+
|
|
|
+ String accountId = accountIdList.get(k);
|
|
|
+ paramsVo.setAccountId(accountId);
|
|
|
+
|
|
|
+ //获取账户 日流水数据 根据账户id 和 年月 查询数据
|
|
|
+ List<SettlementReportKuaiShouVo> settlementList = reportSettlementMapper.getAccountTransactionDayKuaiShou(paramsVo);
|
|
|
+ if (Check.isNull(settlementList)){
|
|
|
+ num++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //2:创建sheet 设置sheet名称
|
|
|
+ HSSFSheet sheet = wb.createSheet(accountId);
|
|
|
+
|
|
|
+ //画图的顶级管理器,一个sheet只能获取一个 (插入图片时 使用)
|
|
|
+ HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
|
|
+
|
|
|
+ //3:添加 第一行单元格
|
|
|
+ HSSFRow row0 = sheet.createRow(0);
|
|
|
+ HSSFCell cell0 = row0.createCell(0);
|
|
|
+ //设置 第一行 表头
|
|
|
+ cell0.setCellValue(paramsVo.getUploadYears()+"-快手结算单");
|
|
|
+ CellRangeAddress region = new CellRangeAddress(0, 0, 0, 10);
|
|
|
+ sheet.addMergedRegion(region);//合并行
|
|
|
+ cell0.setCellStyle(style);
|
|
|
+
|
|
|
+ //4:添加表头2行
|
|
|
+ HSSFRow row = sheet.createRow(1);
|
|
|
+
|
|
|
+ //5:创建第2行的单元格
|
|
|
+ HSSFCell cell = row.createCell(0); //第一个单元格
|
|
|
+ cell.setCellValue(" 日期 "); //设定值
|
|
|
+ cell.setCellStyle(style); //内容居中
|
|
|
+
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellValue(" 账户快手ID ");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellValue(" 广告主账户ID ");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellValue(" 日总花费 ");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(4);
|
|
|
+ cell.setCellValue(" 充值花费 ");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(5);
|
|
|
+ cell.setCellValue("框返花费");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(6);
|
|
|
+ cell.setCellValue("激励花费");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(7);
|
|
|
+ cell.setCellValue("充值转入");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(8);
|
|
|
+ cell.setCellValue("框返转入");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(9);
|
|
|
+ cell.setCellValue("激励转入");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(10);
|
|
|
+ cell.setCellValue("总转入");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(11);
|
|
|
+ cell.setCellValue("转出");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(12);
|
|
|
+ cell.setCellValue("日终结余");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < settlementList.size(); i++) {
|
|
|
+ SettlementReportKuaiShouVo vo = settlementList.get(i);
|
|
|
+ //创建行 (表头占0-1行 所以 从 2开始)
|
|
|
+ row = sheet.createRow(i + 2);
|
|
|
+ sheet.autoSizeColumn(0, true);
|
|
|
+ sheet.autoSizeColumn(i + 1, true);
|
|
|
+ //创建单元格并且添加数据
|
|
|
+ row.createCell(0).setCellValue(vo.getDate());
|
|
|
+ row.createCell(1).setCellValue(vo.getKsId());
|
|
|
+ row.createCell(2).setCellValue(vo.getAccountId());
|
|
|
+ row.createCell(3).setCellValue(vo.getDailyCharge());
|
|
|
+ row.createCell(4).setCellValue(vo.getRealCharged());
|
|
|
+ row.createCell(5).setCellValue(vo.getContractRebateRealCharged());
|
|
|
+ row.createCell(6).setCellValue(vo.getDirectRebateRealCharged());
|
|
|
+ row.createCell(7).setCellValue(vo.getRealRecharged());
|
|
|
+ row.createCell(8).setCellValue(vo.getContractRebateRealRecharged());
|
|
|
+ row.createCell(9).setCellValue(vo.getDirectRebateRealRecharged());
|
|
|
+ row.createCell(10).setCellValue(vo.getDailyTransferIn());
|
|
|
+ row.createCell(11).setCellValue(vo.getDailyTransferOut());
|
|
|
+ row.createCell(12).setCellValue(vo.getBalance());
|
|
|
+ }
|
|
|
+
|
|
|
+ //先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
|
|
|
+ ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ //查询 图片 url
|
|
|
+ List<String> imageUrlList = reportSettlementMapper.getAccountImagesBytedance(accountId);
|
|
|
+
|
|
|
+ if (!Check.isNull(imageUrlList)){
|
|
|
+ for (int j = 0; j < imageUrlList.size(); j++) {
|
|
|
+ String imagePath = imageUrlList.get(j);
|
|
|
+ //通过图片网络地址 获取输入流
|
|
|
+ InputStream is = createExcelByTemplate.getInputStreamByUrl(imagePath);
|
|
|
+ BufferedImage bufferImg = ImageIO.read(is);
|
|
|
+ ImageIO.write(bufferImg, imagePath.substring(imagePath.lastIndexOf(".") + 1), byteArrayOut);
|
|
|
+ //anchor主要用于设置图片的属性
|
|
|
+ int startIndex = settlementList.size()+7;
|
|
|
+
|
|
|
+ HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 2, startIndex+(5*j)+50*j, (short) 10, startIndex+(5*j)+50*(j+1));
|
|
|
+ //HSSFClientAnchor anchor2 = new HSSFClientAnchor(0, 0, 255, 255, (short) 5, settlementList.size() + 40, (short) 10, 40 * 2);
|
|
|
+ anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
|
|
|
+ //插入图片
|
|
|
+ patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(accountIdList.size() == num){
|
|
|
+ return Result.errorMsg("暂无数据。");
|
|
|
+ }
|
|
|
+
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
|
+ response.setHeader("Pragma", "no-cache");
|
|
|
+ response.setHeader("Cache-Control", "no-cache");
|
|
|
+ response.setDateHeader("Expires", 0);
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(paramsVo.getUploadYears()+"快手结算单.xlsx", "UTF-8"));
|
|
|
+ OutputStream output = response.getOutputStream();
|
|
|
+ BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
|
|
|
+ wb.write(bufferedOutPut);
|
|
|
+ bufferedOutPut.flush();
|
|
|
+ bufferedOutPut.close();
|
|
|
+ output.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("====>>>>", e.getMessage());
|
|
|
+ return Result.errorMsg(e.getMessage());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
}
|