Browse Source

修改结算单导出逻辑

songyh 4 years ago
parent
commit
7491502618

+ 6 - 10
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/controller/ExportReportController.java

@@ -2,7 +2,9 @@ package org.jeecg.ctop.finance.settlement.controller;
 
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.ctop.finance.settlement.entity.vo.SettlementFileParamsVo;
 import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -29,18 +31,16 @@ public class ExportReportController {
     @ApiOperation(value = "财务结算-结算单导出-头条", notes = "财务结算-结算单导出-头条")
     @GetMapping(value = "/settlementReportBytedance")
     public Result settlementReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
-
-        return reportSettlementService.settlementReportBytedance(paramsVo,response);
-
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        return reportSettlementService.settlementReportBytedance(paramsVo,response,user);
     }
 
 
     @ApiOperation(value = "财务结算-结算单导出-快手", notes = "财务结算-结算单导出-快手")
     @GetMapping(value = "/settlementReportKuaiShou")
     public Result settlementReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
-
-        return reportSettlementService.settlementReportKuaiShou(paramsVo,response);
-
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        return reportSettlementService.settlementReportKuaiShou(paramsVo,response,user);
     }
 
 
@@ -48,18 +48,14 @@ public class ExportReportController {
     @ApiOperation(value = "财务结算-利润表导出-头条", notes = "财务结算-利润表导出-头条")
     @GetMapping(value = "/porfitReportBytedance")
     public Result porfitReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
-
         return reportSettlementService.porfitReportBytedance(paramsVo,response);
-
     }
 
 
     @ApiOperation(value = "财务结算-利润表导出-快手", notes = "财务结算-利润表导出-快手")
     @GetMapping(value = "/porfitReportKuaiShou")
     public Result porfitReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
-
         return reportSettlementService.porfitReportKuaiShou(paramsVo,response);
-
     }
 
 

+ 4 - 19
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/controller/SettlementFileController.java

@@ -3,7 +3,9 @@ package org.jeecg.ctop.finance.settlement.controller;
 import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.ctop.finance.policy.utils.Check;
 import org.jeecg.ctop.finance.settlement.entity.pojo.CtopCwjsSettlementFileInfo;
 import org.jeecg.ctop.finance.settlement.entity.vo.SettlementFileParamsVo;
@@ -27,20 +29,13 @@ import java.util.Set;
 @RestController
 @RequestMapping("/settLementFileController")
 public class SettlementFileController {
-
     @Autowired
     private ISettlementFileInfoService settlementFileInfoService;
-
-
     @Autowired
     private ISysRoleService sysRoleService;
-
-
     @Autowired
     private IMaterialReportOverViewService materialReportOverViewService;
 
-
-
     @ApiOperation(value="结算单-结算单列表查询", notes="结算单-结算单列表查询")
     @GetMapping(value = "/getSettlementSheetList")
     public Result<PageInfo<Map<String,String>>> getSettlementSheetList(SettlementFileParamsVo paramsVo,
@@ -89,8 +84,6 @@ public class SettlementFileController {
         return settlementFileInfoService.deleteSettlementFile(paramsVo);
     }
 
-
-
     @ApiOperation(value="结算单-账户截图上传", notes="结算单-账户截图上传")
     @PostMapping(value = "/insertAccountImages")
     public Result insertAccountImages(@RequestBody CtopCwjsSettlementFileInfo settlementFileInfo) {
@@ -100,18 +93,10 @@ public class SettlementFileController {
         return settlementFileInfoService.insertAccountImages(settlementFileInfo);
     }
 
-
     @ApiOperation(value="结算单-查询账户数量以及图片数量", notes="结算单-查询账户数量以及图片数量")
     @PostMapping(value = "/getAccountNumAndImgNum")
     public Result getAccountNumAndImgNum(@RequestBody SettlementFileParamsVo paramsVo) {
-        return settlementFileInfoService.getAccountNumAndImgNum(paramsVo);
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        return settlementFileInfoService.getAccountNumAndImgNum(paramsVo,user);
     }
-
-
-
-
-
-
-
-
 }

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

@@ -32,10 +32,8 @@
         <if test="mediaId !=null and mediaId != ''">
             AND media_id = #{mediaId}
         </if>
-
     </select>
 
-
     <!-- 查询 头条 账户 图片-->
     <select id="getAccountImagesBytedance" resultType="java.lang.String">
         SELECT
@@ -47,10 +45,6 @@
         AND upload_years = #{uploadYears}
     </select>
 
-
-
-
-
     <!-- 获取快手 账户 日流水信息  账户维度-->
     <select id="getAccountTransactionDayKuaiShou" resultType="org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportKuaiShouVo">
         select t.*,c.auth_name as accountName,
@@ -70,9 +64,6 @@
         where uploadYears = #{uploadYears}
     </select>
 
-
-
-
     <!-- 获取快手 账户 日流水信息  代理商维度-->
     <select id="getAccountTransactionDayKuaiShouAgent" resultType="org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportKuaiShouVo">
 
@@ -102,8 +93,6 @@
             t.date
     </select>
 
-
-
     <!-- 获取快手 账户 日流水信息  代理商 和 账户 维度-->
     <select id="getTransactionDayKuaiShouAgentAndAccount" resultType="org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportKuaiShouVo">
         SELECT
@@ -168,56 +157,8 @@
 
     </select>
 
-
-
-
-
     <!-- 查询 头条利润表 所用账户-->
     <select id="getProfitBytedanceAccountCost" resultType="java.util.LinkedHashMap">
-      <!--  SELECT
-        d.advertiser_id AS accountId,
-        SUM( d.cost ) AS cost,
-        SUM( d.cash_cost ) AS cashCost,
-        SUM( d.reward_cost ) rewardCost,
-        pd.id as productId,
-        pd.product_name AS productName
-        FROM
-        ctop_account_transaction_day d
-        LEFT JOIN ctop_user_allocation u ON d.advertiser_id = u.account_id
-        LEFT JOIN ctop_project p ON u.project_id = p.id
-        LEFT JOIN ctop_product pd on pd.id = p.product_id
-        where (u.media_id = 1 or u.media_id = 3)
-            <if test="accountId !=null and accountId != ''">
-                AND d.advertiser_id = #{accountId}
-            </if>
-            <if test="startTime !=null and startTime != ''">
-                AND d.date &gt;= #{startTime}
-            </if>
-            <if test="endTime !=null and endTime != ''">
-                AND d.date &lt;= #{endTime}
-            </if>
-        GROUP BY
-            d.advertiser_id;
--->
-<!--
-
-        SELECT
-        d.advertiser_id AS accountId,
-        SUM( d.cost ) AS cost,
-        SUM( d.cash_cost ) AS cashCost,
-        SUM( d.reward_cost ) rewardCost,
-        p.id AS productId,
-        p.product_name AS productName
-        FROM
-        ctop_account_transaction_day d,
-        ctop_cwjs_settlement_info c,
-        ctop_product p
-        WHERE
-        d.advertiser_id = c.account_id
-        AND c.product_id = p.id
-
--->
-
         SELECT
         d.advertiser_id as accountId,
         SUM( d.cost ) AS cost,
@@ -248,33 +189,8 @@
 
 </select>
 
-
     <!-- 查询 头条利润表 总花费-->
     <select id="getProfitBytedanceCost" resultType="java.util.LinkedHashMap">
-       <!-- SELECT
-        d.advertiser_id AS accountId,
-        SUM( d.cost ) AS cost,
-        SUM( d.cash_cost ) AS cashCost,
-        SUM( d.reward_cost ) rewardCost,
-        pd.id as productId,
-        pd.product_name AS productName
-        FROM
-        ctop_account_transaction_day d
-        LEFT JOIN ctop_user_allocation u ON d.advertiser_id = u.account_id
-        LEFT JOIN ctop_project p ON u.project_id = p.id
-        LEFT JOIN ctop_product pd on pd.id = p.product_id
-        where (u.media_id = 1 or u.media_id = 3)
-            <if test="accountId !=null and accountId != ''">
-                AND d.advertiser_id = #{accountId}
-            </if>
-            <if test="startTime !=null and startTime != ''">
-                AND d.date &gt;= #{startTime}
-            </if>
-            <if test="endTime !=null and endTime != ''">
-                AND d.date &lt;= #{endTime}
-            </if>
--->
-
         SELECT
         d.advertiser_id AS accountId,
         SUM( d.cost ) AS cost,
@@ -298,38 +214,6 @@
 
     <!-- 查询 头条利润表  返点类型和比列-->
     <select id="getProfitBytedance" resultType="java.util.LinkedHashMap">
-<!--
-
-        SELECT
-        pp.create_user_id,
-        cp.rebate_type AS rebateType,
-        cp.rebate_rate AS rebateRate,
-        cp.approved_status AS approvedStatus,
-        cp.policy_start_date as policyStartDate,
-        cp.policy_end_date as policyEndDate,
-        cp.create_time as createTime
-        FROM
-        ctop_cwjs_policy_product pp
-        LEFT JOIN ctop_cwjs_policy_info cp ON cp.id = pp.policy_id
-        WHERE
-        pp.del_flag = 0
-        AND cp.del_flag = 0
-        and cp.approved_status = 3
-        <if test="mediaType !=null and mediaType != ''">
-            AND cp.media_type = #{mediaType}
-        </if>
-        <if test="productName !=null and productName != ''">
-            AND pp.policy_product_name = #{productName}
-        </if>
-        <if test="startTime !=null and startTime != ''">
-            AND  (cp.policy_start_date &gt;= #{startTime} or cp.policy_start_date &lt;= #{endTime})
-        </if>
-        <if test="endTime !=null and endTime != ''">
-            AND (cp.policy_end_date &gt;= #{startTime} or cp.policy_end_date &lt;= #{endTime})
-        </if>
-
--->
-
         SELECT t.* from (
         SELECT
         cp.rebate_type AS rebateType,
@@ -358,9 +242,6 @@
         </if>
         GROUP BY r.policy_id
         ) t
-
-
-
     </select>
 
 
@@ -387,16 +268,10 @@
         GROUP BY
         p.id
         limit 1
-
-
-
-
     </select>
 
-
     <!-- 查询 头条利润表  销售人员姓名 -->
     <select id="getProfitBytedanceSale" resultType="java.util.LinkedHashMap">
-
         SELECT f.create_user_id,u.realname as saleName
         from ctop_cwjs_settlement_info f
         LEFT  JOIN sys_user u on u.id = f.create_user_id
@@ -405,29 +280,10 @@
             AND f.account_id = #{accountId}
         </if>
         limit 1
-
-
     </select>
 
-
-
     <!-- 查询 头条利润表  广告主和运营和运营所属区域-->
     <select id="getProfitBytedanceOperate" resultType="java.util.LinkedHashMap">
-        <!--select
-        u.advertiser_id,
-        u.advertiser_name as advertiserName,
-        u.user_id,
-        u.user_name as operateName,
-        u.auth_name,
-        IFNULL(p.nick_name,'') as operateArea
-        from
-        ctop_user_allocation u
-        LEFT JOIN user_company p on p.user_id = u.user_id
-          <where>
-              <if test="accountId !=null and accountId != ''">
-                  AND u.account_id = #{accountId}
-              </if>
-          </where>-->
         SELECT
         c.create_user_id AS operateUserId,
         p.user_name AS operateName,
@@ -442,63 +298,10 @@
             AND c.account_id = #{accountId}
         </if>
         limit 1
-
     </select>
 
-
-<!-- 查询 快手 利润表 总花费-->
+    <!-- 查询 快手 利润表 总花费-->
     <select id="getProfitKuaiShouAccountCost" resultType="java.util.LinkedHashMap">
-        <!--SELECT
-            d.account_id AS accountId,
-            SUM( d.daily_charge ) AS cost,
-            SUM( d.real_charged ) AS cashCost,
-            pd.id as productId,
-            pd.product_name AS productName
-        FROM
-            ctop_kuaishou_daily_flows d
-        LEFT JOIN ctop_user_allocation u ON d.account_id = u.account_id
-        LEFT JOIN ctop_project p ON u.project_id = p.id
-        LEFT JOIN ctop_product pd on pd.id = p.product_id
-        where (u.media_id = 2 or u.media_id = 4)
-        <if test="accountId !=null and accountId != ''">
-            AND d.account_id = #{accountId}
-        </if>
-        <if test="startTime !=null and startTime != ''">
-            AND d.date &gt;= #{startTime}
-        </if>
-        <if test="endTime !=null and endTime != ''">
-            AND d.date &lt;= #{endTime}
-        </if>
-        GROUP BY
-            d.account_id;-->
-
-     <!--   SELECT
-        d.account_id as accountId,
-        d.user_id AS ksId,
-        SUM(d.total_charged_in_yuan) AS cost,
-        SUM((d.real_charged_in_yuan + d.total_rebate_real_charged_in_yuan + d.credit_real_charged_in_yuan)) as cashCost,
-        c.product_id as productId,
-        (SELECT p.product_name from ctop_product p where p.id = c.product_id) AS productName,
-        (SELECT d.name as advertiserName from ctop_advertiser d where d.id = c.advertiser_id) advertiserName
-        FROM
-        ctop_kuaishou_daily_agent d
-        RIGHT JOIN	ctop_cwjs_settlement_info c
-        on d.account_id = c.account_id
-        and c.kuai_shou_id = d.user_id
-        <where>
-            <if test="accountId !=null and accountId != ''">
-                AND d.account_id = #{accountId}
-            </if>
-            <if test="startTime !=null and startTime != ''">
-                AND d.date_time &gt;= #{startTime}
-            </if>
-            <if test="endTime !=null and endTime != ''">
-                AND d.date_time &lt;= #{endTime}
-            </if>
-        </where>
-
-        GROUP BY d.account_id-->
-
         SELECT
         d.account_id as accountId,
         d.user_id AS ksId,
@@ -525,33 +328,10 @@
             </if>
         </where>
         GROUP BY d.account_id
-
     </select>
 
-
-<!-- 查询 快手 利润表 总花费-->
+    <!-- 查询 快手 利润表 总花费-->
     <select id="getProfitKuaiShouCost" resultType="java.util.LinkedHashMap">
-        <!--SELECT
-        d.account_id AS accountId,
-        SUM( d.daily_charge ) AS cost,
-        SUM( d.real_charged ) AS cashCost,
-        pd.id as productId,
-        pd.product_name AS productName
-        FROM
-        ctop_kuaishou_daily_flows d
-        LEFT JOIN ctop_user_allocation u ON d.account_id = u.account_id
-        LEFT JOIN ctop_project p ON u.project_id = p.id
-        LEFT JOIN ctop_product pd on pd.id = p.product_id
-        where (u.media_id = 2 or u.media_id = 4)
-        <if test="accountId !=null and accountId != ''">
-            AND d.account_id = #{accountId}
-        </if>
-        <if test="startTime !=null and startTime != ''">
-            AND d.date &gt;= #{startTime}
-        </if>
-        <if test="endTime !=null and endTime != ''">
-            AND d.date &lt;= #{endTime}
-        </if>-->
         SELECT
         d.account_id,
         d.user_id AS ksId,
@@ -570,34 +350,11 @@
                 AND d.date_time &lt;= #{endTime}
             </if>
         </where>
-
-
     </select>
 
 
-
     <!-- 查询 快手 利润表  广告主和运营和运营所属区域-->
     <select id="getProfitKuaiShouOperate" resultType="java.util.LinkedHashMap">
-       <!-- select
-        u.advertiser_id,
-        u.account_id,
-        b.user_id as ksId,
-        d.name as advertiserName,
-        u.user_id,
-        u.user_name as operateName,
-        u.auth_name,
-        IFNULL(p.nick_name,'') as operateArea
-        from
-        ctop_user_allocation u
-        LEFT JOIN ctop_kuaishou_advertiser_base_info b on u.account_id = b.account_id
-        LEFT JOIN user_company p on p.user_id = u.user_id
-        LEFT JOIN ctop_advertiser d on u.advertiser_id = d.id
-    <where>
-        <if test="accountId !=null and accountId != ''">
-            AND u.account_id = #{accountId}
-        </if>
-    </where>-->
-
         SELECT
         c.create_user_id AS operateUserId,
         p.user_name AS operateName,
@@ -614,14 +371,7 @@
             limit 1
     </select>
 
-
-
-
-
-    <!--  给运营人员发送微信通知 -->
-
-
-<!--  查询 所有已绑定用户的运营人员id -->
+    <!--  查询 所有已绑定用户的运营人员id -->
     <select id="getAccountOperateUserId" resultType="java.util.LinkedHashMap">
         SELECT user_id userId,user_name userName
         from ctop_user_allocation
@@ -647,11 +397,4 @@
 	AND c.user_id = #{userId}
     </select>
 
-
-
-
-
-    <!--  给运营人员发送微信通知 -->
-
-
 </mapper>

+ 5 - 13
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/IReportSettlementService.java

@@ -1,6 +1,7 @@
 package org.jeecg.ctop.finance.settlement.service;
 
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.ctop.finance.policy.entity.CwjsPolicyInfo;
 import org.jeecg.ctop.finance.settlement.entity.vo.SettlementFileParamsVo;
 import org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportBytedanceVo;
@@ -12,28 +13,19 @@ public interface IReportSettlementService {
 
     List<SettlementReportBytedanceVo> getAccountTransactionDayBytedance();
 
-    Result settlementReportBytedance(SettlementFileParamsVo paramsVo,HttpServletResponse response);
-
-    Result settlementReportKuaiShou(SettlementFileParamsVo paramsVo,HttpServletResponse response);
-
-
+    Result settlementReportBytedance(SettlementFileParamsVo paramsVo,HttpServletResponse response,LoginUser user);
 
+    Result settlementReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response, LoginUser user);
 
     Result porfitReportBytedance(SettlementFileParamsVo paramsVo,HttpServletResponse response);
 
     Result porfitReportKuaiShou(SettlementFileParamsVo paramsVo,HttpServletResponse response);
 
-
-
-
     Result sendMessageToOperate();
-    Result sendMessageToOperateDemo(String userId);
-
-
-
 
+    Result sendMessageToOperateDemo(String userId);
 
     void cwjsPRofit(CwjsPolicyInfo cwjsPolicyInfo);
 
-
+    List<String> getAccountId(SettlementFileParamsVo paramsVo,LoginUser user);
 }

+ 2 - 4
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/ISettlementFileInfoService.java

@@ -3,6 +3,7 @@ package org.jeecg.ctop.finance.settlement.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.github.pagehelper.PageInfo;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.ctop.finance.settlement.entity.pojo.CtopCwjsSettlementFileInfo;
 import org.jeecg.ctop.finance.settlement.entity.vo.SettlementFileParamsVo;
 
@@ -12,12 +13,9 @@ public interface ISettlementFileInfoService extends IService<CtopCwjsSettlementF
 
     Result<PageInfo<Map<String,String>>> getSettlementSheetList(SettlementFileParamsVo paramsVo, Integer pageNo, Integer pageSize);
 
-
     Result deleteSettlementFile(SettlementFileParamsVo paramsVo);
 
     Result insertAccountImages(CtopCwjsSettlementFileInfo settlementFileInfo);
 
-    Result getAccountNumAndImgNum(SettlementFileParamsVo paramsVo);
-
-
+    Result getAccountNumAndImgNum(SettlementFileParamsVo paramsVo, LoginUser user);
 }

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

@@ -2,7 +2,10 @@ package org.jeecg.ctop.finance.settlement.service.serviceImpl;
 
 import cn.afterturn.easypoi.excel.ExcelExportUtil;
 import cn.afterturn.easypoi.excel.entity.ExportParams;
+import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.MailLogMapper;
+import cn.com.ctop.common.module.mapper.SysRoleMapper;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.utils.CorpWexinUtils;
 import cn.com.ctop.common.module.utils.ImageUtils;
 import com.alibaba.fastjson.JSONObject;
@@ -16,6 +19,8 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.ctop.finance.policy.entity.CwjsPolicyInfo;
 import org.jeecg.ctop.finance.policy.entity.CwjsPolicyProduct;
 import org.jeecg.ctop.finance.policy.mapper.CwjsPolicyProductMapper;
@@ -29,6 +34,7 @@ import org.jeecg.ctop.finance.settlement.mapper.SettlementInfoMapper;
 import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
 import org.jeecg.ctop.finance.utils.SettlementUtil;
 import org.jeecg.ctop.finance.utils.createExcelByTemplate;
+import org.jeecg.modules.ctop.service.IMaterialReportOverViewService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -51,29 +57,28 @@ import java.util.stream.Collectors;
 @Slf4j
 @Service
 public class ReportSettlementServiceImpl implements IReportSettlementService {
-
     @Resource
     private ReportSettlementMapper reportSettlementMapper;
-
     @Resource
     private CorpWexinUtils corpWexinUtils;
     @Resource
     private MailLogMapper mailLogMapper;
-
     @Resource
     private CwjsProfitMapper cwjsProfitMapper;
-
+    @Resource
+    private UserAllocationMapper userAllocationMapper;
+    @Resource
+    private SysRoleMapper roleMapper;
+    @Autowired
+    private IMaterialReportOverViewService materialReportOverViewService;
 
     @Override
     public List<SettlementReportBytedanceVo> getAccountTransactionDayBytedance() {
         return reportSettlementMapper.getAccountTransactionDayBytedance(null);
     }
-
     @Override
-    public Result settlementReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
-
+    public Result settlementReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response,LoginUser user) {
         try {
-
             //第一步创建workbook
             HSSFWorkbook wb = new HSSFWorkbook();
 
@@ -88,7 +93,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             style.setFont(font);
 
             //查询 账户id
-            List<String> accountIdList = reportSettlementMapper.getAccountIdBytedance(paramsVo);
+            List<String> accountIdList = this.getAccountId(paramsVo,user);
 
             if (Check.isNull(accountIdList)){
                 return Result.errorMsg("该广告主和产品下无法查询到绑定的账户信息");
@@ -97,7 +102,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             int num = 0;
 
             for (int k = 0; k < accountIdList.size(); k++) {
-
                 String accountId = accountIdList.get(k);
                 paramsVo.setAccountId(accountId);
 
@@ -128,23 +132,23 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
 
                 //5:创建第2行的单元格
                 HSSFCell cell = row.createCell(0);     //第一个单元格
-                cell.setCellValue("   日期   ");         //设定值
+                cell.setCellValue("日期");         //设定值
                 cell.setCellStyle(style);          //内容居中
 
                 cell = row.createCell(1);
-                cell.setCellValue("      账户名称      ");
+                cell.setCellValue("账户名称");
                 cell.setCellStyle(style);
 
                 cell = row.createCell(2);
-                cell.setCellValue("      账户ID      ");
+                cell.setCellValue("账户ID");
                 cell.setCellStyle(style);
 
                 cell = row.createCell(3);
-                cell.setCellValue("      所属代理商名称      ");
+                cell.setCellValue("所属代理商名称");
                 cell.setCellStyle(style);
 
                 cell = row.createCell(4);
-                cell.setCellValue("      所属代理商ID      ");
+                cell.setCellValue("所属代理商ID");
                 cell.setCellStyle(style);
 
                 cell = row.createCell(5);
@@ -179,9 +183,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                 cell.setCellValue("冻结(¥)");
                 cell.setCellStyle(style);
 
-
-
-
                 for (int i = 0; i < settlementList.size(); i++) {
                     SettlementReportBytedanceVo vo = settlementList.get(i);
                     //创建行 (表头占0-1行 所以 从 2开始)
@@ -204,8 +205,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                     row.createCell(12).setCellValue(vo.getFrozen());
                 }
 
-
-
                 //查询 图片 url
                 List<String> imageUrlList = reportSettlementMapper.getAccountImagesBytedance(accountId,paramsVo.getUploadYears());
 
@@ -257,14 +256,60 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
         }
         return null;
     }
+    /**
+     * @param paramsVo
+     * @param user
+     * @return
+     */
+    @Override
+    public List<String> getAccountId(SettlementFileParamsVo paramsVo,LoginUser user) {
+        String uploadYears = paramsVo.getUploadYears();
+        //1:区分媒体(头条:1 快手:2)
+        Integer mediaId = paramsVo.getMediaId();
+        List<String> settlementAccountList = reportSettlementMapper.getAccountIdBytedance(paramsVo);
+        String roleCode = roleMapper.getRoleCodeByUserId(user.getId());
+        Set<String>sales = new HashSet<>();
+        List<UserAllocation>allocations ;
+        if("admin".equals(roleCode)|| "finance".equals(roleCode)){
+            //查询所有可用的账户
+        }else if("saleDirector".equals(roleCode)){
+            //查询自己下辖的所有销售绑定的账户
+            sales = materialReportOverViewService.recursiveQuerySubordinate(paramsVo.getCreateUserId());
+        }else if("saleAssistant".equals(roleCode)|| "sale".equals(roleCode)|| "saleAm".equals(roleCode)){
+            //查询自己名绑定下的账户
+            sales.add(user.getId());
+        }
+        if(sales.isEmpty()){
+            sales = null;
+        }
+        allocations = userAllocationMapper.getAccountInfoBySalesId(sales,mediaId+"");
+        return mergeAccountId(settlementAccountList,allocations,uploadYears);
+    }
 
-
+    private List<String> mergeAccountId(List<String> settlementAccountList, List<UserAllocation> allocations,String uploadYears) {
+        List<String>salesAccount = new ArrayList<>();
+        for(UserAllocation allocation:allocations){
+            if(allocation.getAccountStatus() == 0){
+                salesAccount.add(allocation.getAccountId()+"");
+            }
+            if(allocation.getAccountStatus() == 1){
+                //被关停的账户
+                Long updateDateNum = Long.parseLong(DateUtils.formatDate(allocation.getUpdateTime(),"yyyymm"));
+                uploadYears = uploadYears.replace("-","");
+                Long uploadYearNum = Long.parseLong(uploadYears);
+                if(updateDateNum>=uploadYearNum){
+                    salesAccount.add(allocation.getAccountId()+"");
+                }
+            }
+        }
+        settlementAccountList.removeAll(salesAccount);
+        settlementAccountList.addAll(salesAccount);
+        return settlementAccountList;
+    }
 
     @Override
-    public Result settlementReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
-
+    public Result settlementReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response, LoginUser user) {
         try {
-
             //第一步创建workbook
             HSSFWorkbook wb = new HSSFWorkbook();
 
@@ -279,16 +324,14 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             style.setFont(font);
 
             //查询 需要导出的数据的账户id
-            List<String> accountIdList = reportSettlementMapper.getAccountIdBytedance(paramsVo);
+            List<String> accountIdList = this.getAccountId(paramsVo,user);
 
             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);
 
@@ -598,8 +641,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
         return null;
     }
 
-
-
     /**
      *
      * @description: 财务结算 利润表导出 快手
@@ -819,10 +860,8 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
     @Resource
     private CwjsPolicyProductMapper cwjsPolicyProductMapper;
 
-
     @Override
     public void cwjsPRofit(CwjsPolicyInfo cwjsPolicyInfo) {
-
         // 获取两个日期之间 所有的 时间 年-月-日
         List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(cwjsPolicyInfo.getPolicyStartDate(),cwjsPolicyInfo.getPolicyEndDate());
         //查看 政策下的产品
@@ -846,5 +885,4 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             }
         }
     }
-
 }

+ 12 - 2
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/SettlementFileInfoServiceImpl.java

@@ -6,14 +6,17 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.ctop.finance.policy.utils.Check;
 import org.jeecg.ctop.finance.settlement.entity.pojo.CtopCwjsSettlementFileInfo;
 import org.jeecg.ctop.finance.settlement.entity.vo.SettlementFileParamsVo;
 import org.jeecg.ctop.finance.settlement.mapper.SettlementFileInfoMapper;
 import org.jeecg.ctop.finance.settlement.mapper.SettlementInfoMapper;
+import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
 import org.jeecg.ctop.finance.settlement.service.ISettlementFileInfoService;
 import org.jeecg.ctop.finance.utils.SettlementUtil;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
@@ -179,6 +182,8 @@ public class SettlementFileInfoServiceImpl extends ServiceImpl<SettlementFileInf
         return Result.successMsg("账户截图上传成功",null);
     }
 
+    @Autowired
+    private IReportSettlementService reportSettlementService;
 
     /**
      * @description: 查询账户数量以及图片数量
@@ -187,10 +192,15 @@ public class SettlementFileInfoServiceImpl extends ServiceImpl<SettlementFileInf
      * @author: zianY
      */
     @Override
-    public Result getAccountNumAndImgNum(SettlementFileParamsVo paramsVo) {
+    public Result getAccountNumAndImgNum(SettlementFileParamsVo paramsVo, LoginUser user) {
         Map<String,String> map =  settlementFileInfoMapper.getAccountNumAndImgNum(paramsVo);
+        List<String>accountIds = reportSettlementService.getAccountId(paramsVo,user);
+        if(null == accountIds||accountIds.isEmpty()){
+            map.put("accountNum","0");
+        }else{
+            map.put("accountNum",accountIds.size()+"");
+        }
         return Result.successMsg("查询账户数量以及图片数量成功",map);
-
     }
 
 

+ 3 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java

@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * @Description: 用户分配
@@ -66,4 +67,6 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
 
     Map<String,Object>getCwjsSettlementByAccountId(String accountId);
     void updCwjsSettlementStatus(@Param("id") String id, @Param("status") Integer status);
+
+    List<UserAllocation> getAccountInfoBySalesId(@Param("sales")Set<String> sales,@Param("mediaId")String mediaId);
 }

+ 15 - 5
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml

@@ -239,22 +239,32 @@
         AND auto_delivery = 1
     </select>
 
-
-
-
     <!-- 根据账户id 查看财务账户 -->
     <select id="getCwjsSettlementByAccountId" resultType="java.util.LinkedHashMap">
         select * from ctop_cwjs_settlement_info
         WHERE del_flag = 0
           and account_id = #{accountId}
     </select>
-<!-- 修改状态 -->
+    <select id="getAccountInfoBySalesId" resultType="cn.com.ctop.common.module.entity.UserAllocation">
+        select cua.*
+            from ctop_user_allocation cua
+            left join ctop_project cp on cp.id = cua.project_id
+        where 1=1
+          and media_id = #{mediaId}
+        <if test="sales !=null and sales != ''">
+            AND cp.sale_id in
+            <foreach collection="sales" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+    </select>
+    <!-- 修改状态 -->
     <update id="updCwjsSettlementStatus">
         UPDATE ctop_cwjs_settlement_info
         SET STATUS = #{status}
         WHERE
             id = #{id}
-
     </update>