Quellcode durchsuchen

Merge branch 'master' into test

# Conflicts:
#	jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/ReportSettlementServiceImpl.java
songyh vor 4 Jahren
Ursprung
Commit
20afe45798

+ 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,
         ROUND(SUM( d.cost ),2) 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,
@@ -300,38 +216,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);
 }

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

@@ -3,8 +3,11 @@ 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.SysLog;
+import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.MailLogMapper;
 import cn.com.ctop.common.module.mapper.SysLogMapper;
+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;
@@ -18,6 +21,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;
@@ -31,6 +36,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;
@@ -53,18 +59,20 @@ 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;
 
     @Resource
     private SysLogMapper sysLogMapper;
@@ -74,12 +82,9 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
     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();
 
@@ -94,7 +99,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("该广告主和产品下无法查询到绑定的账户信息");
@@ -103,7 +108,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);
 
@@ -134,23 +138,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);
@@ -185,9 +189,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开始)
@@ -210,8 +211,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                     row.createCell(12).setCellValue(vo.getFrozen());
                 }
 
-
-
                 //查询 图片 url
                 List<String> imageUrlList = reportSettlementMapper.getAccountImagesBytedance(accountId,paramsVo.getUploadYears());
 
@@ -263,14 +262,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();
 
@@ -285,16 +330,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);
 
@@ -484,93 +527,80 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             }
             List<ProfitReportBytedanceVo> resultList = new ArrayList<>(list.size());
             for (Map<String, Object> map : 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", map.get("accountId").toString());
-                sysLogQw.orderByDesc("create_time");
-                sysLogQw.last("limit 1");
-                SysLog sysLog = sysLogMapper.selectOne(sysLogQw);
-                if (Check.isNull(sysLog)) {
+              /*  //查看该账户 状态信息
+                QueryWrapper<CtopCwjsSettlementInfo> settlementAccountQw = new QueryWrapper<>();
+                settlementAccountQw.eq("account_id",map.get("accountId"));
+                //账户状态 0-开 1-关
+                settlementAccountQw.eq("status",0);
+                //(0,正常,1已删除)
+                settlementAccountQw.eq("del_flag",0);
+                List<CtopCwjsSettlementInfo> settlementAccountList =  settlementInfoMapper.selectList(settlementAccountQw);
+                if (Check.isNull(settlementAccountList)){
                     continue;
-                }
-                if (sysLog.getLogContent().equals("1")){
-                    continue;
-                }
-                ProfitReportBytedanceVo voSource = new ProfitReportBytedanceVo();
-                voSource.setAccountId(map.get("accountId")+"");
+                }*/
 
+                ProfitReportBytedanceVo voSource = new ProfitReportBytedanceVo();
                 //查询销售
                 Map<String,Object> slaeMap = reportSettlementMapper.getProfitBytedanceSale(map.get("accountId")+"");
                 voSource.setSaleName(Check.isNull(slaeMap) ? "" : slaeMap.getOrDefault("saleName","")+"");//销售
 
-                voSource.setAdvertiserName(!Check.isNull(map.get("advertiserName")) ? map.getOrDefault("advertiserName","")+"" : "" );//广告主名称
                 //产品名称
-                voSource.setProductName(!Check.isNull(map.get("productName")) ? map.getOrDefault("productName","")+"" : "" );
+                voSource.setProductName(map.getOrDefault("productName","")+"");
 
                 Map<String,Object> operateMap = reportSettlementMapper.getProfitBytedanceOperate(map.get("accountId")+"");
                 if (!Check.isNull(operateMap)){
+                    voSource.setAdvertiserName(operateMap.getOrDefault("advertiserName","")+"");//广告主名称
                     voSource.setOperateName(operateMap.getOrDefault("operateName","")+"");//运营
                     voSource.setOperateArea(operateMap.getOrDefault("operateArea","")+"");//运营所属区域
                 }
-                //政策所有时间点
-                List<String> policyDaysList = new ArrayList<>();
-                if (!Check.isNull(map.get("productName"))){
-                    //查询 头条利润表  返点类型和比列
-                    List<Map<String,Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("productName")+"","1",paramsVo.getStartTime(),paramsVo.getEndTime());
-                    List listPolicyTIme = new ArrayList();
-                    for (Map<String, Object> rate : rateMap) {
-                        listPolicyTIme.add(rate.get("policyStartDate"));
-                        listPolicyTIme.add(rate.get("policyEndDate"));
-                    }
-                    //政策时间 去重 排序
-                    List<Object> times = SettlementUtil.sortlistTest(listPolicyTIme);
-                    // 使用政策的时间段 拼接 开始 和 截至 时间
-                    List<Map<String, String>> arrayList = new ArrayList<>();
-                    for ( int i = 0; i < times.size(); i++) {
-                        HashMap<String, String> mapTime = new HashMap<>();
-                        mapTime.put("startDate", times.get(i).toString());
-                        mapTime.put("endDate",  times.size() < 2 ? times.get(i).toString() : times.get(i + 1).toString());
-                        i += 1;
-                        arrayList.add(mapTime);
-                    }
 
+                //查询 头条利润表  返点类型和比列
+                List<Map<String,Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("productName")+"","1",paramsVo.getStartTime(),paramsVo.getEndTime());
+                List listPolicyTIme = new ArrayList();
+                for (Map<String, Object> rate : rateMap) {
+                    listPolicyTIme.add(rate.get("policyStartDate"));
+                    listPolicyTIme.add(rate.get("policyEndDate"));
+                }
+                //政策时间 去重 排序
+                List<Object> times = SettlementUtil.sortlistTest(listPolicyTIme);
+                // 使用政策的时间段 拼接 开始 和 截至 时间
+                List<Map<String, String>> arrayList = new ArrayList<>();
+                for ( int i = 0; i < times.size(); i++) {
+                    HashMap<String, String> mapTime = new HashMap<>();
+                    mapTime.put("startDate", times.get(i).toString());
+                    mapTime.put("endDate",  times.get(i+1).toString());
+                    i += 1;
+                    arrayList.add(mapTime);
+                }
 
-                    for (Map<String, String> stringMap : arrayList) {
-                        ProfitReportBytedanceVo vo = new ProfitReportBytedanceVo();
-                        //使用政策 返点类型和比例
-                        Map<String,Object>  policyRateMap = reportSettlementMapper.getProfitRebate(map.get("productName")+"",stringMap.get("startDate"),stringMap.get("endDate"));
-                        if (!Check.isNull(policyRateMap)){
-                            if(Integer.valueOf(policyRateMap.get("rebateType").toString())== 0){
-                                vo.setRebateType("返现");//返点类型
-                            }else if (Integer.valueOf(policyRateMap.get("rebateType").toString())== 1){
-                                vo.setRebateType("返货");
-                            }else if (Integer.valueOf(policyRateMap.get("rebateType").toString())== 2){
-                                vo.setRebateType("返现+返货");
-                            }
-                            vo.setRebateRate(policyRateMap.getOrDefault("rebateRate","")+"%");//返点比列
-                        }else {
-                            vo.setRebateType("");
+                //政策所有时间点
+                List<String> policyDaysList = new ArrayList<>();
+                for (Map<String, String> stringMap : arrayList) {
+                    ProfitReportBytedanceVo vo = new ProfitReportBytedanceVo();
+                    //使用政策 返点类型和比例
+                    Map<String,Object>  policyRateMap = reportSettlementMapper.getProfitRebate(map.get("productName")+"",stringMap.get("startDate"),stringMap.get("endDate"));
+                    if (!Check.isNull(policyRateMap)){
+                        if(Integer.valueOf(policyRateMap.get("rebateType").toString())== 0){
+                            vo.setRebateType("返现");//返点类型
+                        }else if (Integer.valueOf(policyRateMap.get("rebateType").toString())== 1){
+                            vo.setRebateType("返货");
+                        }else if (Integer.valueOf(policyRateMap.get("rebateType").toString())== 2){
+                            vo.setRebateType("返现+返货");
                         }
-                        // 时间段内 账户流水 信息
-                        List<Map<String,Object>> listAccount = reportSettlementMapper.getProfitBytedanceCost(map.get("accountId")+"",stringMap.get("startDate"),stringMap.get("endDate"));
-                        listAccount.removeAll(Collections.singleton(null));
-                        vo.setCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cost","")+"");//总消耗
-                        vo.setCost(String.format("%.3f",new Double(vo.getCost())));
-                        vo.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost","")+"");//现金消耗
-                        vo.setCashCost(String.format("%.3f",new Double(vo.getCashCost())));
-                        vo.setRewardCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("rewardCost","")+"");//赠款消耗
-                        vo.setRewardCost(String.format("%.3f",new Double(vo.getRewardCost())));
-                        BeanUtils.copyProperties(voSource,vo,SettlementUtil.getNullPropertyNames(voSource));
-                        vo.setTime(stringMap.get("startDate")+"----"+stringMap.get("endDate"));
-                        resultList.add(vo);
-                        policyDaysList.addAll(SettlementUtil.getAllDatesOfTwoTimes(stringMap.get("startDate"),stringMap.get("endDate")));
+                        vo.setRebateRate(policyRateMap.getOrDefault("rebateRate","")+"%");//返点比列
+                    }else {
+                        vo.setRebateType("");
                     }
-
+                    // 时间段内 账户流水 信息
+                    List<Map<String,Object>> listAccount = reportSettlementMapper.getProfitBytedanceCost(map.get("accountId")+"",stringMap.get("startDate"),stringMap.get("endDate"));
+                    listAccount.removeAll(Collections.singleton(null));
+                    vo.setCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cost","")+"");//总消耗
+                    vo.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost","")+"");//现金消耗
+                    vo.setRewardCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("rewardCost","")+"");//赠款消耗
+                    BeanUtils.copyProperties(voSource,vo,SettlementUtil.getNullPropertyNames(voSource));
+                    vo.setTime(stringMap.get("startDate")+"----"+stringMap.get("endDate"));
+                    resultList.add(vo);
+                    policyDaysList.addAll(SettlementUtil.getAllDatesOfTwoTimes(stringMap.get("startDate"),stringMap.get("endDate")));
                 }
 
                 //不使用政策 的时间段
@@ -592,13 +622,10 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                     List<Map<String,Object>> listAccount = reportSettlementMapper.getProfitBytedanceCost(map.get("accountId")+"",stringMap.get("startDate"),stringMap.get("endDate"));
                     listAccount.removeAll(Collections.singleton(null));
                     vo.setCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cost","")+"");//总消耗
-                    vo.setCost(String.format("%.3f",new Double(vo.getCost())));
                     vo.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost","")+"");//现金消耗
-                    vo.setCashCost(String.format("%.3f",new Double(vo.getCashCost())));
                     vo.setRewardCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("rewardCost","")+"");//赠款消耗
-                    vo.setRewardCost(String.format("%.3f",new Double(vo.getRewardCost())));
                     BeanUtils.copyProperties(voSource,vo,SettlementUtil.getNullPropertyNames(voSource));
-                    vo.setTime((!Check.isNull(vo.getRebateType()) ? stringMap.get("startDate")+"----"+stringMap.get("endDate") : ""));
+                    vo.setTime(stringMap.get("startDate")+"----"+stringMap.get("endDate"));
                     resultList.add(vo);
                 }
             }
@@ -621,6 +648,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
     }
 
 
+
     /**
      *
      * @description: 财务结算 利润表导出 快手
@@ -641,99 +669,88 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             List<ProfitReportKuaiShouVo> resultList = new ArrayList<>(list.size());
             for (Map<String, Object> map : 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", map.get("accountId").toString());
-                sysLogQw.orderByDesc("create_time");
-                sysLogQw.last("limit 1");
-                SysLog sysLog = sysLogMapper.selectOne(sysLogQw);
-                if (Check.isNull(sysLog)) {
-                    continue;
-                }
-                if (sysLog.getLogContent().equals("1")){
+                QueryWrapper<CtopCwjsSettlementInfo> settlementAccountQw = new QueryWrapper<>();
+                settlementAccountQw.eq("account_id",map.get("accountId"));
+                //账户状态 0-开 1-关
+                settlementAccountQw.eq("status",0);
+                //(0,正常,1已删除)
+                settlementAccountQw.eq("del_flag",0);
+                List<CtopCwjsSettlementInfo> settlementAccountList =  settlementInfoMapper.selectList(settlementAccountQw);
+                if (Check.isNull(settlementAccountList)){
                     continue;
                 }
-
                 ProfitReportKuaiShouVo voSource = new ProfitReportKuaiShouVo();
 
-                voSource.setAccountId(map.getOrDefault("accountId", "") + "");//账户id
-                voSource.setProductName( !Check.isNull(map.get("productName")) ? map.getOrDefault("productName", "") + "" : "");//产品名称
-                voSource.setKsId(map.getOrDefault("ksId", "") + "");//快手id
-                voSource.setAdvertiserName(!Check.isNull(map.get("advertiserName")) ? map.getOrDefault("advertiserName", "") + "" : "");//广告主名称
+                voSource.setAccountId(map.getOrDefault("accountId","")+"");//账户id
+                voSource.setProductName(map.getOrDefault("productName","")+"");//产品名称
+                voSource.setKsId(map.getOrDefault("ksId","")+"");//快手id
+                voSource.setAdvertiserName(map.getOrDefault("advertiserName","")+"");//广告主名称
 
                 //查询销售
-                Map<String, Object> slaeMap = reportSettlementMapper.getProfitBytedanceSale(map.get("accountId") + "");
-                voSource.setSaleName(Check.isNull(slaeMap) ? "" : slaeMap.getOrDefault("saleName", "") + "");//销售
+                Map<String,Object> slaeMap = reportSettlementMapper.getProfitBytedanceSale(map.get("accountId")+"");
+                voSource.setSaleName(Check.isNull(slaeMap) ? "" : slaeMap.getOrDefault("saleName","")+"");//销售
+
+                Map<String,Object> operateMap = reportSettlementMapper.getProfitKuaiShouOperate(map.get("accountId")+"");
+                if (!Check.isNull(operateMap)){
+                    voSource.setOperateName(operateMap.getOrDefault("operateName","")+"");//运营
+                    voSource.setOperateArea(operateMap.getOrDefault("operateArea","")+"");//运营所属区域
+                }
 
-                Map<String, Object> operateMap = reportSettlementMapper.getProfitKuaiShouOperate(map.get("accountId") + "");
-                if (!Check.isNull(operateMap)) {
-                    voSource.setOperateName(operateMap.getOrDefault("operateName", "") + "");//运营
-                    voSource.setOperateArea(operateMap.getOrDefault("operateArea", "") + "");//运营所属区域
+                //查询 快手利润表  返点类型和比列
+                List<Map<String,Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("productName")+"","2",paramsVo.getStartTime(),paramsVo.getEndTime());
+                List listPolicyTIme = new ArrayList();
+                for (Map<String, Object> rate : rateMap) {
+                    listPolicyTIme.add(rate.get("policyStartDate"));
+                    listPolicyTIme.add(rate.get("policyEndDate"));
+                }
+
+                //政策时间 去重 排序
+                List<Object> times = SettlementUtil.sortlistTest(listPolicyTIme);
+                // 使用政策的时间段 拼接 开始 和 截至 时间
+                List<Map<String, String>> arrayList = new ArrayList<>();
+                for ( int i = 0; i < times.size(); i++) {
+                    HashMap<String, String> mapTime = new HashMap<>();
+                    mapTime.put("startDate", times.get(i).toString());
+                    mapTime.put("endDate",  times.get(i+1).toString());
+                    i += 1;
+                    arrayList.add(mapTime);
                 }
 
                 //政策所有时间点
                 List<String> policyDaysList = new ArrayList<>();
-                if (!Check.isNull(map.get("productName"))) {
-                    //查询 快手利润表  返点类型和比列
-                    List<Map<String, Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("productName") + "", "2", paramsVo.getStartTime(), paramsVo.getEndTime());
-                    List listPolicyTIme = new ArrayList();
-                    for (Map<String, Object> rate : rateMap) {
-                        listPolicyTIme.add(rate.get("policyStartDate"));
-                        listPolicyTIme.add(rate.get("policyEndDate"));
-                    }
-
-                    //政策时间 去重 排序
-                    List<Object> times = SettlementUtil.sortlistTest(listPolicyTIme);
-                    // 使用政策的时间段 拼接 开始 和 截至 时间
-                     List<Map<String, String>> arrayList = new ArrayList<>();
-                    if (!Check.isNull(times)){
-                        for (int i = 0; i < times.size(); i++) {
-                            HashMap<String, String> mapTime = new HashMap<>();
-                            mapTime.put("startDate", times.get(i).toString());
-                            mapTime.put("endDate", times.size() < 2 ? times.get(i).toString() : times.get(i + 1).toString());
-                            i += 1;
-                            arrayList.add(mapTime);
+                for (Map<String, String> stringMap : arrayList) {
+                    ProfitReportKuaiShouVo vo = new ProfitReportKuaiShouVo();
+                    //使用政策 返点类型和比例
+                    Map<String,Object>  policyRateMap = reportSettlementMapper.getProfitRebate(map.get("productName")+"",stringMap.get("startDate"),stringMap.get("endDate"));
+                    if (!Check.isNull(policyRateMap)){
+                        if(Integer.valueOf(policyRateMap.get("rebateType").toString())== 0){
+                            vo.setRebateType("返现");//返点类型
+                        }else if (Integer.valueOf(policyRateMap.get("rebateType").toString())== 1){
+                            vo.setRebateType("返货");
+                        }else if (Integer.valueOf(policyRateMap.get("rebateType").toString())== 2){
+                            vo.setRebateType("返现+返货");
                         }
+                        vo.setRebateRate(policyRateMap.getOrDefault("rebateRate","")+"%");//返点比列
+                    }else {
+                        vo.setRebateType("");
                     }
 
-                    for (Map<String, String> stringMap : arrayList) {
-                        ProfitReportKuaiShouVo vo = new ProfitReportKuaiShouVo();
-                        //使用政策 返点类型和比例
-                        Map<String, Object> policyRateMap = reportSettlementMapper.getProfitRebate(map.get("productName") + "", stringMap.get("startDate"), stringMap.get("endDate"));
-                        if (!Check.isNull(policyRateMap)) {
-                            if (Integer.valueOf(policyRateMap.get("rebateType").toString()) == 0) {
-                                vo.setRebateType("返现");//返点类型
-                            } else if (Integer.valueOf(policyRateMap.get("rebateType").toString()) == 1) {
-                                vo.setRebateType("返货");
-                            } else if (Integer.valueOf(policyRateMap.get("rebateType").toString()) == 2) {
-                                vo.setRebateType("返现+返货");
-                            }
-                            vo.setRebateRate(policyRateMap.getOrDefault("rebateRate", "") + "%");//返点比列
-                        } else {
-                            vo.setRebateType("");
-                        }
-
-                        // 时间段内 账户流水 信息
-                        List<Map<String, Object>> listAccount = reportSettlementMapper.getProfitKuaiShouCost(map.get("accountId") + "", stringMap.get("startDate"), stringMap.get("endDate"));
-                        listAccount.removeAll(Collections.singleton(null));
-                        vo.setCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cost", "") + "");//总消耗
-                        vo.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost", "") + "");//现金消耗
-                        BeanUtils.copyProperties(voSource, vo, SettlementUtil.getNullPropertyNames(voSource));
-                        vo.setTime(stringMap.get("startDate") + "----" + stringMap.get("endDate"));
-                        resultList.add(vo);
-                        policyDaysList.addAll(SettlementUtil.getAllDatesOfTwoTimes(stringMap.get("startDate"), stringMap.get("endDate")));
-                    }
+                    // 时间段内 账户流水 信息
+                    List<Map<String,Object>> listAccount = reportSettlementMapper.getProfitKuaiShouCost(map.get("accountId")+"",stringMap.get("startDate"),stringMap.get("endDate"));
+                    listAccount.removeAll(Collections.singleton(null));
+                    vo.setCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cost","")+"");//总消耗
+                    vo.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost","")+"");//现金消耗
+                    BeanUtils.copyProperties(voSource,vo,SettlementUtil.getNullPropertyNames(voSource));
+                    vo.setTime(stringMap.get("startDate")+"----"+stringMap.get("endDate"));
+                    resultList.add(vo);
+                    policyDaysList.addAll(SettlementUtil.getAllDatesOfTwoTimes(stringMap.get("startDate"),stringMap.get("endDate")));
                 }
 
-
                 //不使用政策 的时间段
                 // 获取两个日期之间 所有的 时间 年-月-日
-                List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(paramsVo.getStartTime(), paramsVo.getEndTime());
+                List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(paramsVo.getStartTime(),paramsVo.getEndTime());
                 // 时间差集(所有时间段 - 使用政策的时间段)
-                List<String> reduceList = betweenDaysList.stream().filter(item -> !policyDaysList.contains(item)).collect(Collectors.toList());
+                List<String>  reduceList = betweenDaysList.stream().filter(item -> !policyDaysList.contains(item)).collect(Collectors.toList());
                 //差集拼接  开始 和 结束时间
                 List<Map<String, String>> stringList = SettlementUtil.getTime(reduceList);
                 for (Map<String, String> stringMap : stringList) {
@@ -745,12 +762,12 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                     vo.setRebateType("");//返点类型
                     vo.setRebateRate("");//返点比列
                     //账户流水 信息
-                    List<Map<String, Object>> listAccount = reportSettlementMapper.getProfitKuaiShouCost(map.get("accountId") + "", stringMap.get("startDate"), stringMap.get("endDate"));
+                    List<Map<String,Object>> listAccount = reportSettlementMapper.getProfitKuaiShouCost(map.get("accountId")+"",stringMap.get("startDate"),stringMap.get("endDate"));
                     listAccount.removeAll(Collections.singleton(null));
-                    vo.setCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cost", "") + "");//总消耗
-                    vo.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost", "") + "");//现金消耗
-                    BeanUtils.copyProperties(voSource, vo, SettlementUtil.getNullPropertyNames(voSource));
-                    vo.setTime(!Check.isNull(vo.getRebateType()) ? stringMap.get("startDate") + "----" + stringMap.get("endDate") : "");
+                    vo.setCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cost","")+"");//总消耗
+                    vo.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost","")+"");//现金消耗
+                    BeanUtils.copyProperties(voSource,vo,SettlementUtil.getNullPropertyNames(voSource));
+                    vo.setTime(stringMap.get("startDate")+"----"+stringMap.get("endDate"));
                     resultList.add(vo);
                 }
 
@@ -851,10 +868,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());
         //查看 政策下的产品
@@ -878,5 +893,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);
 }

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

@@ -25,7 +25,7 @@
         <if test="userId != null and userId != ''">
             and cua.user_id = #{userId}
         </if>
-
+        and account_status = 0
     </select>
 
     <select id="queryAdvertiserId" resultType="String">
@@ -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>
 
 

+ 36 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadServiceImpl.java

@@ -94,6 +94,42 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
         for (int j = 0; j < materialArray.size(); j++) {
             String materialId = materialArray.getString(j);
             MaterialInfo materialInfo = materialInfoMapper.selectById(materialId);
+            if (null == materialInfo||materialInfo.getStatus()!=1) {
+                log.info("头条视频素材推送异常=>id:{};message:{}",materialId,"素材不存在或者未审核通过");
+                continue;
+            }
+            try {
+                String url = materialInfo.getUrl();
+                String localUrl = LoadFileUtil.downLoadFromUrl(url, downloadUrl);
+                for (int i = 0; i < accountArray.size(); i++) {
+                    Long accountId = accountArray.getLong(i);
+                    if (Check.isNull(accountId)) {
+                        continue;
+                    }
+                    touTiaoExecutorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            try {
+                                log.info("头条文件多线程上传:{},accountId:{}", Thread.currentThread().getName(), accountId);
+                                if ("VIDEO".equals(materialInfo.getType())) {
+                                    fileInfoService.uploadVideoToBytedance(String.valueOf(accountId), localUrl, userId, materialInfo.getMaterialName());
+                                }
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
+                        }
+                    });
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    private void touTiaoUploadV2(String mediaId, JSONArray materialArray, JSONArray accountArray, String userId) {
+        for (int j = 0; j < materialArray.size(); j++) {
+            String materialId = materialArray.getString(j);
+            MaterialInfo materialInfo = materialInfoMapper.selectById(materialId);
             MaterialImageInfo materialImageInfo = materialImageInfoMapper.selectById(materialId);
             if (Check.isNull(materialInfo) && Check.isNull(materialImageInfo)) {
                 continue;

+ 0 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ProjectMemberController.java

@@ -515,7 +515,6 @@ public class ProjectMemberController {
     public Result<List<Map<String, Object>>> getProjectAccountBy(String mediaType,String userId) {
         Result<List<Map<String, Object>>> resultBody = new Result<>();
         try {
-
             List<Map<String, Object>> result = projectMemberService.getProjectAccountByUserId(userId, mediaType);
             resultBody.setSuccess(true);
             resultBody.setResult(result);

+ 0 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java

@@ -164,7 +164,6 @@ public class UserAllocationController {
         mediaList.add(mediaId);
         //    List<ProjectMember> projectList = projectMemberService.getOwnProjects(mediaList);
         List<ProjectMember> productList = projectMemberService.getOwnProducts(mediaList, productId);
-        log.info("產品列表:{}", productList);
 
         //  projectMemberService.getOwnProjects(mediaList);
         List<ProjectMember> projectMemberList = new ArrayList<>();