Browse Source

财务-结算单添加汇总sheet页-头条

yangzian 3 years ago
parent
commit
7628cde9d7

+ 20 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/service/ICreateSheetService.java

@@ -0,0 +1,20 @@
+package org.jeecg.ctop.finance.policy.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.jeecg.ctop.finance.policy.entity.CwjsPolicyInfo;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ * @author jeecg-boot
+ * 2021-07-27
+ * @version V1.0
+ */
+public interface ICreateSheetService {
+    void createBytedance(HSSFWorkbook wb, HSSFCellStyle style, List<String> accountIdList,String uploadYears);
+}

+ 136 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/service/impl/CreateSheetServiceImpl.java

@@ -0,0 +1,136 @@
+package org.jeecg.ctop.finance.policy.service.impl;
+
+import cn.com.ctop.common.module.mapper.SysUserMapper;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.jeecg.common.system.entity.SysUser;
+import org.jeecg.ctop.finance.policy.entity.CwjsPolicyInfo;
+import org.jeecg.ctop.finance.policy.mapper.CwjsPolicyInfoMapper;
+import org.jeecg.ctop.finance.policy.service.ICreateSheetService;
+import org.jeecg.ctop.finance.policy.service.ICwjsPolicyInfoService;
+import org.jeecg.ctop.finance.policy.utils.Check;
+import org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportBytedanceVo;
+import org.jeecg.ctop.finance.settlement.mapper.ReportSettlementMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.text.DecimalFormat;
+import java.util.*;
+
+/**
+ *
+ * @author jeecg-boot
+ * 2021-07-27
+ * @version V1.0
+ */
+@Service
+public class CreateSheetServiceImpl implements ICreateSheetService {
+
+    @Resource
+    private ReportSettlementMapper reportSettlementMapper;
+
+
+    public void createBytedance(HSSFWorkbook wb, HSSFCellStyle style, List<String> accountIdList,String uploadYears){
+
+        DecimalFormat sf  = new DecimalFormat("#.####");//保留四位小数
+        //2:创建sheet 设置sheet名称
+        HSSFSheet sheet = wb.createSheet("汇总页");
+
+        //3:添加 第一行单元格
+        HSSFRow row0 = sheet.createRow(0);
+        HSSFCell cell0 = row0.createCell(0);
+        //设置 第一行 表头
+        cell0.setCellValue(uploadYears+"-头条结算单汇总");
+        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);
+        sheet.autoSizeColumn(0, true);
+        List<Map<String,Object>> list = reportSettlementMapper.getAccountTransactionDayBytedanceSheet(accountIdList,uploadYears);
+
+        for (int i = 0; i < list.size(); i++) {
+            Map<String,Object> 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(uploadYears);
+            row.createCell(1).setCellValue(vo.get("accountName")+"");
+            row.createCell(2).setCellValue(vo.get("advertiser_id")+"");
+            row.createCell(3).setCellValue(vo.get("agentName")+"");
+            row.createCell(4).setCellValue(vo.get("agentId")+"");
+            row.createCell(5).setCellValue(sf.format(vo.get("cost")));
+            row.createCell(6).setCellValue(sf.format(vo.get("cash_cost")));
+            row.createCell(7).setCellValue(sf.format(vo.get("reward_cost")));
+            row.createCell(8).setCellValue(sf.format(vo.get("income")));
+            row.createCell(9).setCellValue(sf.format(vo.get("transfer_in")));
+            row.createCell(10).setCellValue(sf.format(vo.get("transfer_out")));
+            row.createCell(11).setCellValue(sf.format(vo.get("balance")));
+            row.createCell(12).setCellValue(sf.format(vo.get("frozen")));
+           // row.setRowStyle(style);
+        }
+    }
+
+
+
+}

+ 6 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/mapper/ReportSettlementMapper.java

@@ -27,6 +27,12 @@ public interface ReportSettlementMapper {
      */
     List<SettlementReportBytedanceVo> getAccountTransactionDayBytedance(SettlementFileParamsVo paramsVo);
 
+    List<Map<String,Object>> getAccountTransactionDayBytedanceSheet(@Param("accountIds") List<String> accountIds,@Param("uploadYears")String uploadYears);
+
+
+
+
+
     /**
      * 获取快手 账户 日流水信息 根据账户id 和 年月 查询数据
      * @param paramsVo

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

@@ -10,24 +10,22 @@
         balance,cash_cost,cost,frozen,income,reward_cost,shared_wallet_cost,transfer_in,transfer_out,create_time,
         (
         SELECT
-        ag.agent_id
+        DISTINCT ag.agent_id
         from
         ctop_cwjs_agent_info ag
         LEFT JOIN ctop_agent_account ac on ag.agent_id = ac.agent_id
-        where ac.state = 0
-        and ag.`status` = 0
+        where ag.`status` = 0
         and ag.enabled = 0
-        and ac.account_id = #{accountId}) as agentId,
+        and ac.account_id = #{accountId} limit 1) as agentId,
         (
         SELECT
-        ag.name
+        DISTINCT ag.name
         from
         ctop_cwjs_agent_info ag
         LEFT JOIN ctop_agent_account ac on ag.agent_id = ac.agent_id
-        where ac.state = 0
-        and ag.`status` = 0
+        where ag.`status` = 0
         and ag.enabled = 0
-        and ac.account_id = #{accountId}) as agentName
+        and ac.account_id = #{accountId} limit 1) as agentName
          from
         ctop_account_transaction_day
         where cost >0
@@ -37,6 +35,48 @@
         where uploadYears = #{uploadYears}
         ORDER BY date
     </select>
+<!-- 获取头条 账户 日流水信息 汇总页数据 -->
+    <select id="getAccountTransactionDayBytedanceSheet" resultType="java.util.LinkedHashMap">
+        SELECT
+            t.advertiser_id,
+        ua.auth_name accountName,
+        ROUND( SUM( t.balance ), 3 ) balance,
+            ROUND( SUM( t.cash_cost ), 3 ) cash_cost,
+            ROUND( SUM( t.cost ), 3 ) cost,
+            ROUND( SUM( t.frozen ), 3 ) frozen,
+            ROUND( SUM( t.income ), 3 ) income,
+            ROUND( SUM( t.reward_cost ), 3 ) reward_cost,
+            ROUND( SUM( t.shared_wallet_cost ), 3 ) shared_wallet_cost,
+            ROUND( SUM( t.transfer_in ), 3 ) transfer_in,
+            ROUND( SUM( t.transfer_out ), 3 ) transfer_out,
+            ag.agent_id agentId,
+            ag.NAME agentName
+        FROM
+            ctop_account_transaction_day t
+        LEFT JOIN (SELECT DISTINCT account_id,agent_id from ctop_agent_account where 1 = 1
+        <if test='accountIds != null and accountIds.size() > 0'>
+            AND account_id in
+            <foreach collection="accountIds" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+            ) ac ON t.advertiser_id = ac.account_id
+                LEFT JOIN ctop_cwjs_agent_info ag ON ag.agent_id = ac.agent_id
+                LEFT JOIN ctop_user_allocation ua on ua.account_id = t.advertiser_id
+        WHERE
+            t.cost > 0
+          AND DATE_FORMAT( t.date, '%Y-%m' ) = #{uploadYears}
+        <if test='accountIds != null and accountIds.size() > 0'>
+            AND t.advertiser_id in
+            <foreach collection="accountIds" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY
+            t.advertiser_id
+    </select>
 
     <!-- 查询 头条 账户id-->
     <select id="getAccountIdBytedance" resultType="java.lang.String">
@@ -57,7 +97,7 @@
             AND u.project_id = #{projectId}
         </if>
         <if test="mediaId !=null and mediaId != ''">
-            AND media_id = #{mediaId}
+            AND c.media_id = #{mediaId}
         </if>
         <if test='sales !=null and sales.size() >0'>
             AND create_user_id in

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

@@ -30,6 +30,7 @@ import org.jeecg.ctop.finance.policy.entity.CwjsPolicyProduct;
 import org.jeecg.ctop.finance.policy.mapper.CwjsCompanySubjectMapper;
 import org.jeecg.ctop.finance.policy.mapper.CwjsPolicyInfoMapper;
 import org.jeecg.ctop.finance.policy.mapper.CwjsPolicyProductMapper;
+import org.jeecg.ctop.finance.policy.service.ICreateSheetService;
 import org.jeecg.ctop.finance.policy.service.impl.CwjsSaleAssistantInfoServiceImpl;
 import org.jeecg.ctop.finance.policy.utils.Check;
 import org.jeecg.ctop.finance.settlement.entity.pojo.CtopCwjsSettlementInfo;
@@ -86,6 +87,9 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
     @Autowired
     private CwjsSaleAssistantInfoServiceImpl cwjsSaleAssistantInfoService;
 
+    @Autowired
+    private ICreateSheetService createSheetService;
+
 
     @Override
     public List<SettlementReportBytedanceVo> getAccountTransactionDayBytedance() {
@@ -107,6 +111,10 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             font.setFontHeightInPoints((short) 12);//设置字体大小
             style.setFont(font);
 
+            HSSFDataFormat format = wb.createDataFormat();
+            style.setDataFormat(format.getFormat("@"));
+
+
             //查询 账户id
             List<String> accountIdList = this.getAccountId(paramsVo,user);
 
@@ -116,6 +124,13 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
 
             int num = 0;
 
+
+            //设置第一个sheet页 汇总页
+            createSheetService.createBytedance(wb,style,accountIdList,paramsVo.getUploadYears());
+
+
+
+
             for (int k = 0; k < accountIdList.size(); k++) {
                 String accountId = accountIdList.get(k);
                 paramsVo.setAccountId(accountId);
@@ -351,15 +366,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                 String accountId = accountIdList.get(k);
                 paramsVo.setAccountId(accountId);
 
-                //获取账户 日流水数据  根据账户id 和 年月 查询数据
-               /* List<SettlementReportKuaiShouVo> settlementList = new ArrayList<>();
-                //查询账户维度
-                settlementList = reportSettlementMapper.getAccountTransactionDayKuaiShou(paramsVo);
-                if (Check.isNull(settlementList)){
-                    //查询代理商维度
-                    settlementList = reportSettlementMapper.getAccountTransactionDayKuaiShouAgent(paramsVo);
-                }
-*/
                 List<SettlementReportKuaiShouVo> settlementList = reportSettlementMapper.getTransactionDayKuaiShouAgentAndAccount(paramsVo);
                 if (Check.isNull(settlementList)){
                     num++;
@@ -531,23 +537,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             }
             List<ProfitReportBytedanceVo> resultList = new ArrayList<>(list.size());
             for (Map<String, Object> mapList : list) {
-              //查看该账户 状态信息
-                /*QueryWrapper<SysLog> sysLogQw = new QueryWrapper<>();
-                sysLogQw.eq("log_type", 2);
-                //操作类型
-                sysLogQw.eq("operate_type", 10001);
-                sysLogQw.eq("log_content", "0");//0开 1关
-                sysLogQw.eq("request_param", mapList.get("accountId").toString());
-                sysLogQw.orderByDesc("create_time");
-                sysLogQw.last("limit 1");
-                SysLog sysLog = sysLogMapper.selectOne(sysLogQw);
-                if (!Check.isNull(sysLog)) {
-                    SimpleDateFormat m = new SimpleDateFormat("MM");
-                    String createMonth = m.format(sysLog.getCreateTime());
-                    int crate = Integer.valueOf(createMonth);
-                    Calendar cal = Calendar.getInstance();
-                    int month = cal.get(Calendar.MONTH) + 1;
-                }*/
+
                 //查看账户数据
                 Map<String,Object> map = reportSettlementMapper.getProfitBytedanceAccountCost(mapList.get("accountId").toString(),paramsVo.getStartTime(),paramsVo.getEndTime());