Browse Source

结算单关联代理商;利润表关联销售

yangzian 3 years ago
parent
commit
4a4382ab57

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

@@ -50,6 +50,8 @@ public class SettlementReportBytedanceVo implements Serializable {
 
 
 
 
     private String accountName;
     private String accountName;
+    private String agentId;
+    private String agentName;
 
 
 
 
 
 

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

@@ -79,9 +79,9 @@ public interface ReportSettlementMapper {
      * @param
      * @param
      * @return
      * @return
      */
      */
-    List<Map<String,Object>> getProfitBytedance(@Param("productName") String productName,@Param("mediaType") String mediaType,@Param("startTime")String startTime,@Param("endTime")String endTime);
+    List<Map<String,Object>> getProfitBytedance(@Param("advertiserName") String advertiserName,@Param("productName") String productName,@Param("saleId") String saleId,@Param("mediaType") String mediaType,@Param("startTime")String startTime,@Param("endTime")String endTime);
 
 
-    Map<String,Object> getProfitRebate(@Param("productName") String productName,@Param("startTime")String startTime,@Param("endTime")String endTime);
+    Map<String,Object> getProfitRebate(@Param("advertiserName") String advertiserName,@Param("productName") String productName,@Param("saleId") String saleId,@Param("mediaType") String mediaType,@Param("startTime")String startTime,@Param("endTime")String endTime);
 
 
     Map<String,Object> getProfitReportSale(String accountId);
     Map<String,Object> getProfitReportSale(String accountId);
 
 

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

@@ -7,7 +7,27 @@
         select t.*,c.auth_name as accountName from (select id,
         select t.*,c.auth_name as accountName from (select id,
         advertiser_id,
         advertiser_id,
         date,DATE_FORMAT(date,'%Y-%m') as uploadYears,
         date,DATE_FORMAT(date,'%Y-%m') as uploadYears,
-        balance,cash_cost,cost,frozen,income,reward_cost,shared_wallet_cost,transfer_in,transfer_out,create_time
+        balance,cash_cost,cost,frozen,income,reward_cost,shared_wallet_cost,transfer_in,transfer_out,create_time,
+        (
+        SELECT
+        ag.agent_id
+        from
+        ctop_cwjs_agent_info ag
+        LEFT JOIN ctop_agent_account ac on ag.agent_id = ac.agent_id
+        where ac.state = 0
+        and ag.`status` = 0
+        and ag.enabled = 0
+        and ac.account_id = #{accountId}) as agentId,
+        (
+        SELECT
+        ag.name
+        from
+        ctop_cwjs_agent_info ag
+        LEFT JOIN ctop_agent_account ac on ag.agent_id = ac.agent_id
+        where ac.state = 0
+        and ag.`status` = 0
+        and ag.enabled = 0
+        and ac.account_id = #{accountId}) as agentName
          from
          from
         ctop_account_transaction_day
         ctop_account_transaction_day
         where cost >0
         where cost >0
@@ -316,7 +336,9 @@
         <if test="mediaType !=null and mediaType != ''">
         <if test="mediaType !=null and mediaType != ''">
             AND cp.media_type = #{mediaType}
             AND cp.media_type = #{mediaType}
         </if>
         </if>
+            AND r.advertiser_name = #{advertiserName}
             AND r.product_name = #{productName}
             AND r.product_name = #{productName}
+            AND r.create_user_id = #{saleId}
         <if test="startTime !=null and startTime != ''">
         <if test="startTime !=null and startTime != ''">
             AND  r.policy_date &gt;= #{startTime}
             AND  r.policy_date &gt;= #{startTime}
         </if>
         </if>
@@ -339,9 +361,12 @@
         LEFT JOIN ctop_cwjs_policy_info p ON r.policy_id = p.id
         LEFT JOIN ctop_cwjs_policy_info p ON r.policy_id = p.id
         WHERE
         WHERE
         p.del_flag = 0
         p.del_flag = 0
-        <if test="productName !=null and productName != ''">
-            AND r.product_name = #{productName}
+        <if test="mediaType !=null and mediaType != ''">
+            AND p.media_type = #{mediaType}
         </if>
         </if>
+        AND r.advertiser_name = #{advertiserName}
+        AND r.product_name = #{productName}
+        AND r.create_user_id = #{saleId}
         <if test="startTime !=null and startTime != ''">
         <if test="startTime !=null and startTime != ''">
             AND  r.policy_date &gt;= #{startTime}
             AND  r.policy_date &gt;= #{startTime}
         </if>
         </if>
@@ -355,16 +380,8 @@
 
 
     <!-- 查询 利润表  销售人员姓名 -->
     <!-- 查询 利润表  销售人员姓名 -->
     <select id="getProfitReportSale" resultType="java.util.LinkedHashMap">
     <select id="getProfitReportSale" 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
-        where f.del_flag = 0
-        <if test="accountId !=null and accountId != ''">
-            AND f.account_id = #{accountId}
-        </if>
-        limit 1-->
         ( SELECT
         ( SELECT
-        p.sale_id,
+        p.sale_id AS saleId,
         y.realname AS saleName
         y.realname AS saleName
         FROM
         FROM
         ctop_user_allocation u
         ctop_user_allocation u

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

@@ -204,8 +204,8 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                     row.createCell(0).setCellValue(vo.getDate());
                     row.createCell(0).setCellValue(vo.getDate());
                     row.createCell(1).setCellValue(vo.getAccountName());
                     row.createCell(1).setCellValue(vo.getAccountName());
                     row.createCell(2).setCellValue(vo.getAdvertiserId());
                     row.createCell(2).setCellValue(vo.getAdvertiserId());
-                    row.createCell(3).setCellValue("北京汇创思拓数字科技有限公司-ka");
-                    row.createCell(4).setCellValue("73970348172");
+                    row.createCell(3).setCellValue(vo.getAgentName());
+                    row.createCell(4).setCellValue(vo.getAgentId());
                     row.createCell(5).setCellValue(vo.getCost());
                     row.createCell(5).setCellValue(vo.getCost());
                     row.createCell(6).setCellValue(vo.getCashCost());
                     row.createCell(6).setCellValue(vo.getCashCost());
                     row.createCell(7).setCellValue(vo.getRewardCost());
                     row.createCell(7).setCellValue(vo.getRewardCost());
@@ -567,7 +567,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                 List<String> policyDaysList = new ArrayList<>();
                 List<String> policyDaysList = new ArrayList<>();
                 if (!Check.isNull(map.get("productName"))){
                 if (!Check.isNull(map.get("productName"))){
                     //查询 头条利润表  返点类型和比列
                     //查询 头条利润表  返点类型和比列
-                    List<Map<String,Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("productName")+"","1",paramsVo.getStartTime(),paramsVo.getEndTime());
+                    List<Map<String,Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("advertiserName")+"",map.get("productName")+"",slaeMap.get("saleId")+"","1",paramsVo.getStartTime(),paramsVo.getEndTime());
                     List listPolicyTIme = new ArrayList();
                     List listPolicyTIme = new ArrayList();
                     for (Map<String, Object> rate : rateMap) {
                     for (Map<String, Object> rate : rateMap) {
                         listPolicyTIme.add(rate.get("policyStartDate"));
                         listPolicyTIme.add(rate.get("policyStartDate"));
@@ -589,7 +589,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                     for (Map<String, String> stringMap : arrayList) {
                     for (Map<String, String> stringMap : arrayList) {
                         ProfitReportBytedanceVo vo = new ProfitReportBytedanceVo();
                         ProfitReportBytedanceVo vo = new ProfitReportBytedanceVo();
                         //使用政策 返点类型和比例
                         //使用政策 返点类型和比例
-                        Map<String,Object>  policyRateMap = reportSettlementMapper.getProfitRebate(map.get("productName")+"",stringMap.get("startDate"),stringMap.get("endDate"));
+                        Map<String,Object>  policyRateMap = reportSettlementMapper.getProfitRebate(map.get("advertiserName")+"",map.get("productName")+"",slaeMap.get("saleId")+"","1",stringMap.get("startDate"),stringMap.get("endDate"));
                         if (!Check.isNull(policyRateMap)){
                         if (!Check.isNull(policyRateMap)){
                             if(Integer.valueOf(policyRateMap.get("rebateType").toString())== 0){
                             if(Integer.valueOf(policyRateMap.get("rebateType").toString())== 0){
                                 vo.setRebateType("返现");//返点类型
                                 vo.setRebateType("返现");//返点类型
@@ -725,7 +725,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                 List<String> policyDaysList = new ArrayList<>();
                 List<String> policyDaysList = new ArrayList<>();
                 if (!Check.isNull(map.get("productName"))) {
                 if (!Check.isNull(map.get("productName"))) {
                     //查询 快手利润表  返点类型和比列
                     //查询 快手利润表  返点类型和比列
-                    List<Map<String, Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("productName") + "", "2", paramsVo.getStartTime(), paramsVo.getEndTime());
+                    List<Map<String, Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("advertiserName")+"",map.get("productName") + "", slaeMap.get("saleId")+"","2", paramsVo.getStartTime(), paramsVo.getEndTime());
                     List listPolicyTIme = new ArrayList();
                     List listPolicyTIme = new ArrayList();
                     for (Map<String, Object> rate : rateMap) {
                     for (Map<String, Object> rate : rateMap) {
                         listPolicyTIme.add(rate.get("policyStartDate"));
                         listPolicyTIme.add(rate.get("policyStartDate"));
@@ -749,7 +749,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                     for (Map<String, String> stringMap : arrayList) {
                     for (Map<String, String> stringMap : arrayList) {
                         ProfitReportKuaiShouVo vo = new ProfitReportKuaiShouVo();
                         ProfitReportKuaiShouVo vo = new ProfitReportKuaiShouVo();
                         //使用政策 返点类型和比例
                         //使用政策 返点类型和比例
-                        Map<String, Object> policyRateMap = reportSettlementMapper.getProfitRebate(map.get("productName") + "", stringMap.get("startDate"), stringMap.get("endDate"));
+                        Map<String, Object> policyRateMap = reportSettlementMapper.getProfitRebate(map.get("advertiserName")+"",map.get("productName") + "", slaeMap.get("saleId")+"","2",stringMap.get("startDate"), stringMap.get("endDate"));
                         if (!Check.isNull(policyRateMap)) {
                         if (!Check.isNull(policyRateMap)) {
                             if (Integer.valueOf(policyRateMap.get("rebateType").toString()) == 0) {
                             if (Integer.valueOf(policyRateMap.get("rebateType").toString()) == 0) {
                                 vo.setRebateType("返现");//返点类型
                                 vo.setRebateType("返现");//返点类型
@@ -800,11 +800,9 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                     vo.setTime(!Check.isNull(vo.getRebateType()) ? stringMap.get("startDate") + "----" + stringMap.get("endDate") : "");
                     vo.setTime(!Check.isNull(vo.getRebateType()) ? stringMap.get("startDate") + "----" + stringMap.get("endDate") : "");
                     resultList.add(vo);
                     resultList.add(vo);
                 }
                 }
-
             }
             }
 
 
             Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("快手利润单", "快手利润单"), ProfitReportKuaiShouVo.class, resultList);
             Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("快手利润单", "快手利润单"), ProfitReportKuaiShouVo.class, resultList);
-
             try {
             try {
                 response.setCharacterEncoding("UTF-8");
                 response.setCharacterEncoding("UTF-8");
                 response.setHeader("content-Type", "application/vnd.ms-excel");
                 response.setHeader("content-Type", "application/vnd.ms-excel");
@@ -813,7 +811,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             } catch (IOException e) {
             } catch (IOException e) {
                 throw new RuntimeException(e);
                 throw new RuntimeException(e);
             }
             }
-
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
             return Result.errorMsg(e.getMessage());
             return Result.errorMsg(e.getMessage());
@@ -838,7 +835,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
         int accountNum = 0;
         int accountNum = 0;
         String productInfo = null;
         String productInfo = null;
         String message =  "{0},您好!您{1}月份有{2}个产品的账户需要进行媒体后台消耗截图上传,共计{3}个账户。产品分别为:{4}。请及时上传,多谢配合!";
         String message =  "{0},您好!您{1}月份有{2}个产品的账户需要进行媒体后台消耗截图上传,共计{3}个账户。产品分别为:{4}。请及时上传,多谢配合!";
-
         //查询所有 运营绑定的账户
         //查询所有 运营绑定的账户
         List<Map<String,Object>> userList = reportSettlementMapper.getAccountOperateUserId();
         List<Map<String,Object>> userList = reportSettlementMapper.getAccountOperateUserId();
         for (Map<String, Object> userMap : userList) {
         for (Map<String, Object> userMap : userList) {
@@ -853,7 +849,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             productNum = product.size();
             productNum = product.size();
             accountNum = productList.size();
             accountNum = productList.size();
             productInfo = StringUtils.join(product.toArray(),"、");
             productInfo = StringUtils.join(product.toArray(),"、");
-
             //发送微信通知
             //发送微信通知
             JSONObject jsonObject =  mailLogMapper.getWChatIdByUserId(userId);
             JSONObject jsonObject =  mailLogMapper.getWChatIdByUserId(userId);
             String msg = MessageFormat.format(message,userMap.get("userName").toString(),month,productNum,accountNum,productInfo);
             String msg = MessageFormat.format(message,userMap.get("userName").toString(),month,productNum,accountNum,productInfo);
@@ -885,7 +880,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             productNum = product.size();
             productNum = product.size();
             accountNum = productList.size();
             accountNum = productList.size();
             productInfo = StringUtils.join(product.toArray(),"、");
             productInfo = StringUtils.join(product.toArray(),"、");
-
             //发送微信通知
             //发送微信通知
             JSONObject jsonObject =  mailLogMapper.getWChatIdByUserId(Check.isNull(userId) ? "f990f815ecef43fab9cbe1bb22bb6d63" : userId);
             JSONObject jsonObject =  mailLogMapper.getWChatIdByUserId(Check.isNull(userId) ? "f990f815ecef43fab9cbe1bb22bb6d63" : userId);
             String msg = MessageFormat.format(message,userMap.get("userName").toString(),month,productNum,accountNum,productInfo);
             String msg = MessageFormat.format(message,userMap.get("userName").toString(),month,productNum,accountNum,productInfo);
@@ -897,17 +891,14 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
     @Resource
     @Resource
     private CwjsPolicyProductMapper cwjsPolicyProductMapper;
     private CwjsPolicyProductMapper cwjsPolicyProductMapper;
 
 
-
     @Override
     @Override
     public void cwjsPRofit(CwjsPolicyInfo cwjsPolicyInfo) {
     public void cwjsPRofit(CwjsPolicyInfo cwjsPolicyInfo) {
-
         // 获取两个日期之间 所有的 时间 年-月-日
         // 获取两个日期之间 所有的 时间 年-月-日
         List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(cwjsPolicyInfo.getPolicyStartDate(),cwjsPolicyInfo.getPolicyEndDate());
         List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(cwjsPolicyInfo.getPolicyStartDate(),cwjsPolicyInfo.getPolicyEndDate());
         //查看 政策下的产品
         //查看 政策下的产品
         List<CwjsPolicyProduct> productList = cwjsPolicyProductMapper.queryProductsByPolicyId(cwjsPolicyInfo.getId());
         List<CwjsPolicyProduct> productList = cwjsPolicyProductMapper.queryProductsByPolicyId(cwjsPolicyInfo.getId());
         if (!Check.isNull(productList)){
         if (!Check.isNull(productList)){
             if (!Check.isNull(betweenDaysList)){
             if (!Check.isNull(betweenDaysList)){
-
                 List<CtopCwjsSlettementReport> reportList = new ArrayList<>();
                 List<CtopCwjsSlettementReport> reportList = new ArrayList<>();
                 for (CwjsPolicyProduct product : productList) {
                 for (CwjsPolicyProduct product : productList) {
                     for (String day : betweenDaysList) {
                     for (String day : betweenDaysList) {
@@ -927,9 +918,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
         }
         }
     }
     }
 
 
-
-
-
     @Resource
     @Resource
     private CwjsPolicyInfoMapper cwjsPolicyInfoMapper;
     private CwjsPolicyInfoMapper cwjsPolicyInfoMapper;
     @Resource
     @Resource
@@ -937,8 +925,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
     @Resource
     @Resource
     private CwjsCompanySubjectMapper cwjsCompanySubjectMapper;
     private CwjsCompanySubjectMapper cwjsCompanySubjectMapper;
 
 
-
-
     @Override
     @Override
     public Result importPolicyInit(MultipartFile file) {
     public Result importPolicyInit(MultipartFile file) {
         try {
         try {
@@ -946,7 +932,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             //settlementInfo.setCreateUserId(user.getId());
             //settlementInfo.setCreateUserId(user.getId());
             //settlementInfo.setCreateUserId("b161b7d9793942f980dbfe8c931cd1b0");
             //settlementInfo.setCreateUserId("b161b7d9793942f980dbfe8c931cd1b0");
             ImportParams importParams = new ImportParams();
             ImportParams importParams = new ImportParams();
-
             //表头行数
             //表头行数
             importParams.setHeadRows(1);
             importParams.setHeadRows(1);
 
 
@@ -955,17 +940,13 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                 return Result.error("读取Excel失败,数据不能为空,请重新检查数据并导入");
                 return Result.error("读取Excel失败,数据不能为空,请重新检查数据并导入");
             }
             }
 
 
-
             for (PolicyImportVo importVo : importResult.getList()) {
             for (PolicyImportVo importVo : importResult.getList()) {
                 if (cn.com.ctop.common.module.utils.Check.isNull(importVo.getCompanyName())){
                 if (cn.com.ctop.common.module.utils.Check.isNull(importVo.getCompanyName())){
                     continue;
                     continue;
                 }
                 }
-
                 if (cn.com.ctop.common.module.utils.Check.isNull(importVo.getPolicyProductName())){
                 if (cn.com.ctop.common.module.utils.Check.isNull(importVo.getPolicyProductName())){
                     continue;
                     continue;
                 }
                 }
-
-
                 List<String> productNameList = Arrays.asList(importVo.getPolicyProductName().split("-"));
                 List<String> productNameList = Arrays.asList(importVo.getPolicyProductName().split("-"));
 
 
                 CwjsPolicyInfo cwjsPolicyInfo = new CwjsPolicyInfo();
                 CwjsPolicyInfo cwjsPolicyInfo = new CwjsPolicyInfo();
@@ -986,10 +967,8 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                 CwjsCompanySubject companySubject = cwjsCompanySubjectMapper.selectOne(companySubQw);
                 CwjsCompanySubject companySubject = cwjsCompanySubjectMapper.selectOne(companySubQw);
                 cwjsPolicyInfo.setCompanySubjectId(companySubject.getId());
                 cwjsPolicyInfo.setCompanySubjectId(companySubject.getId());
 
 
-
                 cwjsPolicyInfo.setApprovedStatus(3);
                 cwjsPolicyInfo.setApprovedStatus(3);
 
 
-
                 CwjsPolicyInfo policy = cwjsPolicyInfoMapper.getPolicyInfo(cwjsPolicyInfo);
                 CwjsPolicyInfo policy = cwjsPolicyInfoMapper.getPolicyInfo(cwjsPolicyInfo);
 
 
                 if (cn.com.ctop.common.module.utils.Check.isNull(policy)){
                 if (cn.com.ctop.common.module.utils.Check.isNull(policy)){
@@ -1000,9 +979,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                 //查看 政策下的产品
                 //查看 政策下的产品
                 List<CwjsPolicyProduct> productList = cwjsPolicyProductMapper.queryProductsByPolicyId(policy.getId());
                 List<CwjsPolicyProduct> productList = cwjsPolicyProductMapper.queryProductsByPolicyId(policy.getId());
                 List proList = productList.stream().map(CwjsPolicyProduct:: getPolicyProductName).collect(Collectors.toList());
                 List proList = productList.stream().map(CwjsPolicyProduct:: getPolicyProductName).collect(Collectors.toList());
-
                 for (String str : productNameList) {
                 for (String str : productNameList) {
-
                     if (!proList.contains(str)){
                     if (!proList.contains(str)){
                         //新增产品
                         //新增产品
                         CwjsPolicyProduct policyProduct = new CwjsPolicyProduct();
                         CwjsPolicyProduct policyProduct = new CwjsPolicyProduct();
@@ -1013,12 +990,8 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                         cwjsPolicyProductMapper.insert(policyProduct);
                         cwjsPolicyProductMapper.insert(policyProduct);
                     }
                     }
                 }
                 }
-
                 this.cwjsPRofit(policy);
                 this.cwjsPRofit(policy);
-
             }
             }
-
-
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
             return Result.error("政策数据上传失败,请使用正确的模板导入!");
             return Result.error("政策数据上传失败,请使用正确的模板导入!");
@@ -1029,4 +1002,5 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
 
 
 
 
 
 
+
 }
 }