Browse Source

Merge remote-tracking branch 'origin/test' into test

zhouzeyu@c-top.com.cn 3 years ago
parent
commit
9de112a4b0

+ 5 - 167
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/controller/ExportReportController.java

@@ -2,22 +2,13 @@ package org.jeecg.ctop.finance.settlement.controller;
 
 import io.swagger.annotations.ApiOperation;
 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.ctop.finance.settlement.entity.vo.SettlementReportBytedanceVo;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.ctop.finance.settlement.entity.vo.SettlementFileParamsVo;
 import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
-import org.jeecg.ctop.finance.utils.createExcelByTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
-import java.awt.image.BufferedImage;
-import java.io.*;
-import java.net.URLEncoder;
-import java.util.List;
 
 
 /**
@@ -35,166 +26,13 @@ public class ExportReportController {
     private IReportSettlementService reportSettlementService;
 
 
-
-    @ApiOperation(value="财务结算-结算单导出", notes="财务结算-结算单导出")
+    @ApiOperation(value = "财务结算-结算单导出-头条", notes = "财务结算-结算单导出-头条")
     @GetMapping(value = "/settlementReportBytedance")
-    public String settlementReportBytedance(HttpServletResponse response) throws Exception {
-        //第一步创建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);
-
-
-
-        for (int j = 0; j< 2;j++){
-
-
-
-
-        //2:创建sheet
-        HSSFSheet sheet = wb.createSheet("账户id"+j);
-
-
-        //3:添加 第一行单元格
-        HSSFRow row0 = sheet.createRow(0);
-        HSSFCell cell0 = row0.createCell(0);
-        //设置 第一行 表头
-        cell0.setCellValue("头条结算单");
-        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("      广告主ID      ");         //设定值
-        cell.setCellStyle(style);          //内容居中
-
-
-        cell = row.createCell(1);
-        cell.setCellValue("   日期   ");
-        cell.setCellStyle(style);
-
-        cell = row.createCell(2);
-        cell.setCellValue("日终结余(单位元)");
-        cell.setCellStyle(style);
-
-        cell = row.createCell(3);
-        cell.setCellValue("现金支出(单位元)");
-        cell.setCellStyle(style);
+    public Result settlementReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
 
-        cell = row.createCell(4);
-        cell.setCellValue("总支出(单位元)");
-        cell.setCellStyle(style);
+        return reportSettlementService.settlementReportBytedance(paramsVo,response);
 
-        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);
-
-
-
-        //添加数据
-        List<SettlementReportBytedanceVo> list = reportSettlementService.getAccountTransactionDayBytedance();
-        for (int i = 0; i < list.size(); i++) {
-            SettlementReportBytedanceVo vo = list.get(i);
-            //创建行 (表头占0-1行 所以 从 2开始)
-            row = sheet.createRow(i+2);
-            sheet.autoSizeColumn(0,true);
-            sheet.autoSizeColumn(i+1,true);
-
-            //创建单元格并且添加数据
-            row.createCell(0).setCellValue(vo.getAdvertiserId());
-            row.createCell(1).setCellValue(vo.getDate());
-            row.createCell(2).setCellValue(vo.getBalance());
-            row.createCell(3).setCellValue(vo.getCashCost());
-            row.createCell(4).setCellValue(vo.getCost());
-            row.createCell(5).setCellValue(vo.getFrozen());
-            row.createCell(6).setCellValue(vo.getIncome());
-            row.createCell(7).setCellValue(vo.getRewardCost());
-            row.createCell(8).setCellValue(vo.getSharedWalletCost());
-            row.createCell(9).setCellValue(vo.getTransferIn());
-            row.createCell(10).setCellValue(vo.getTransferOut());
-
-        }
-
-
-
-        //先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
-        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
-        //bufferImg = ImageIO.read(new File("C:\\Users\\Administrator\\Desktop\\汇创\\20210507161223.jpg"));
-        //bufferImg = ImageIO.read(new File(URLDecoder.decode("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg","utf-8")));
-        String imagePath = "https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg";
-        //InputStream is = new FileInputStream(imagePath);
-        //通过图片网络地址 获取输入流
-        InputStream is = createExcelByTemplate.getInputStreamByUrl(imagePath);
-        BufferedImage bufferImg = ImageIO.read(is);
-
-        ImageIO.write(bufferImg, imagePath.substring(imagePath.lastIndexOf(".")+1), byteArrayOut);
-
-        //画图的顶级管理器,一个sheet只能获取一个
-        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
-        //anchor主要用于设置图片的属性
-        //HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255,(short) 1, 1, (short) 5, 8);
-        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255,(short) 5, list.size()+6, (short) 10, 40);
-        HSSFClientAnchor anchor2 = new HSSFClientAnchor(0, 0, 255, 255,(short) 5, list.size()+40, (short) 10, 40*2);
-        anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
-        anchor2.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
-        //插入图片
-        patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
-        patriarch.createPicture(anchor2, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
-
-
-
-        }
-        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("文件名称.xlsx", "UTF-8"));
-        OutputStream output = response.getOutputStream();
-        BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
-        wb.write(bufferedOutPut);
-        bufferedOutPut.flush();
-        bufferedOutPut.close();
-        output.close();
-
-       return "success";
     }
 
 
-
 }

+ 2 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/entity/vo/SettlementReportBytedanceVo.java

@@ -49,6 +49,8 @@ public class SettlementReportBytedanceVo implements Serializable {
     private String transferOut;
 
 
+    private String accountName;
+
 
 
 

+ 17 - 2
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/mapper/ReportSettlementMapper.java

@@ -3,6 +3,7 @@ package org.jeecg.ctop.finance.settlement.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import io.lettuce.core.dynamic.annotation.Param;
 import org.jeecg.ctop.finance.settlement.entity.pojo.ctopCwjsSettlementInfo;
+import org.jeecg.ctop.finance.settlement.entity.vo.SettlementFileParamsVo;
 import org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportBytedanceVo;
 
 import java.util.List;
@@ -19,10 +20,24 @@ import java.util.List;
 public interface ReportSettlementMapper {
 
     /**
-     *获取头条 账户 日流水信息
+     *获取头条 账户 日流水信息 根据账户id 和 年月 查询数据
      * @param
      * @return
      */
-    List<SettlementReportBytedanceVo> getAccountTransactionDayBytedance();
+    List<SettlementReportBytedanceVo> getAccountTransactionDayBytedance(SettlementFileParamsVo paramsVo);
+
+
+    /**
+     * 查询 头条 账户id
+     * @return
+     */
+   List<String> getAccountIdBytedance(SettlementFileParamsVo paramsVo);
+
+    /**
+     * 查询 头条 账户 图片
+     * @param paramsVo
+     * @return
+     */
+   List<String> getAccountImagesBytedance(String accountId);
 
 }

+ 43 - 4
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/mapper/xml/ReportSettlementMapper.xml

@@ -3,15 +3,54 @@
 <mapper namespace="org.jeecg.ctop.finance.settlement.mapper.ReportSettlementMapper">
 
     <!-- 获取头条 账户 日流水信息 -->
-
     <select id="getAccountTransactionDayBytedance" resultType="org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportBytedanceVo">
-        select * from
-            ctop_account_transaction_day
-limit 10
+        select t.*,c.auth_name as accountName from (select id,
+        advertiser_id,
+        date,DATE_FORMAT(date,'%Y-%m') as uploadYears,
+        balance,cash_cost,cost,frozen,income,reward_cost,shared_wallet_cost,transfer_in,transfer_out,create_time
+         from
+        ctop_account_transaction_day
+        where advertiser_id = #{accountId}
+            )t
+      LEFT JOIN ctop_user_allocation c on t.advertiser_id = c.account_id
+        where uploadYears = #{uploadYears}
+    </select>
+
+    <!-- 查询 头条 账户id-->
+    <select id="getAccountIdBytedance" resultType="java.lang.String">
+        SELECT
+         account_id as accountId
+        FROM
+        ctop_cwjs_settlement_info
+        where del_flag = 0
+        <if test="advertiserId !=null and advertiserId != ''">
+            AND advertiser_id = #{advertiserId}
+        </if>
+        <if test="productId !=null and productId != ''">
+            AND product_id = #{productId}
+        </if>
+        <if test="mediaId !=null and mediaId != ''">
+            AND media_id = #{mediaId}
+        </if>
+
+    </select>
 
 
+    <!-- 查询 头条 账户 图片-->
+    <select id="getAccountImagesBytedance" resultType="java.lang.String">
+        SELECT
+        file_url as fileUrl
+        FROM
+        ctop_cwjs_settlement_file_info
+        where del_flag = 0
+        AND account_id = #{accountId}
+
     </select>
 
 
 
+
+
+
+
 </mapper>

+ 4 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/IReportSettlementService.java

@@ -3,13 +3,17 @@ package org.jeecg.ctop.finance.settlement.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.ctop.finance.settlement.entity.pojo.ctopCwjsSettlementInfo;
+import org.jeecg.ctop.finance.settlement.entity.vo.SettlementFileParamsVo;
 import org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportBytedanceVo;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 public interface IReportSettlementService {
 
     List<SettlementReportBytedanceVo> getAccountTransactionDayBytedance();
 
+    Result settlementReportBytedance(SettlementFileParamsVo paramsVo,HttpServletResponse response);
+
 }

+ 201 - 1
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/ReportSettlementServiceImpl.java

@@ -1,12 +1,28 @@
 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.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 +35,190 @@ 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("文件名称.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;
+    }
+
 }