songyh 3 лет назад
Родитель
Сommit
74e8b52e25
23 измененных файлов с 772 добавлено и 217 удалено
  1. 2 0
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java
  2. 2 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/mapper/CwjsPolicyInfoMapper.java
  3. 87 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/mapper/xml/CwjsPolicyInfoMapper.xml
  4. 49 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/controller/ImportPolicyController.java
  5. 1 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/entity/pojo/CtopCwjsSlettementReport.java
  6. 105 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/entity/vo/PolicyImportVo.java
  7. 2 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/mapper/ReportSettlementMapper.java
  8. 2 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/mapper/xml/CwjsProfitMapper.xml
  9. 56 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/mapper/xml/ReportSettlementMapper.xml
  10. 6 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/IReportSettlementService.java
  11. 113 4
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/ReportSettlementServiceImpl.java
  12. 9 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/SettlementFileInfoServiceImpl.java
  13. 69 65
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/SettlementInfoServiceImpl.java
  14. 21 4
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/clean/controller/EstimatePepoleNumberController.java
  15. 5 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/clean/mapper/KuaishouAccountCleanTemplateMapper.java
  16. 3 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/clean/mapper/xml/KuaishouAccountCleanTemplateMapper.xml
  17. 45 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/config/ThreadExecutorConfig.java
  18. 15 4
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/NewMonitorController.java
  19. 1 1
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/NewMonitorMapper.java
  20. 33 12
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/NewMonitorMapper.xml
  21. 3 1
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/NewMonitorService.java
  22. 140 123
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/NewMonitorServiceImpl.java
  23. 3 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

+ 2 - 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -216,6 +216,8 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/estimatePeopleNumber/**", "anon");
 
         filterChainDefinitionMap.put("/exportReportController/**", "anon");
+
+        filterChainDefinitionMap.put("/importPolicyController/importPolicyInit", "anon");
         //filterChainDefinitionMap.put("/settLementController/**", "anon");
 //        filterChainDefinitionMap.put("/settLementFileController/**", "anon");
 

+ 2 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/mapper/CwjsPolicyInfoMapper.java

@@ -30,4 +30,6 @@ public interface CwjsPolicyInfoMapper extends BaseMapper<CwjsPolicyInfo> {
     List<JSONObject> getAllSaleByUserId(String userId);
 
     void updatePolicyInfoById(CwjsPolicyInfo policyInfo);
+
+    CwjsPolicyInfo getPolicyInfo(CwjsPolicyInfo policyInfo);
 }

+ 87 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/mapper/xml/CwjsPolicyInfoMapper.xml

@@ -134,4 +134,91 @@
         where id = #{id}
     </update>
 
+
+
+
+
+
+
+
+
+    <select id="getPolicyInfo" resultType="org.jeecg.ctop.finance.policy.entity.CwjsPolicyInfo">
+        SELECT pi.*
+        FROM
+            ctop_cwjs_policy_info pi
+          where pi.del_flag = 0
+        <if test="companyName != null and companyName != ''">
+            and pi.company_name = #{companyName}
+        </if>
+        <if test="advertiserName != null and advertiserName != ''">
+            and pi.advertiser_name = #{advertiserName}
+        </if>
+        <if test="mediaType != null and mediaType != ''">
+            and pi.media_type = #{mediaType}
+        </if>
+
+        <if test="companySubjectId != null">
+            and pi.company_subject_id = #{companySubjectId}
+        </if>
+
+        <if test="groupAbbreviation != null and groupAbbreviation != ''">
+            and pi.group_abbreviation = #{groupAbbreviation}
+        </if>
+
+        <if test="advancePay != null">
+            and pi.advance_pay = #{advancePay}
+        </if>
+        <if test="accountingPeriod != null and accountingPeriod != ''">
+            and pi.accounting_period = #{accountingPeriod}
+        </if>
+
+        <if test="rebateType != null">
+            and pi.rebate_type = #{rebateType}
+        </if>
+
+        <if test="rebateRate != null and rebateRate != ''">
+            and pi.rebate_rate = #{rebateRate}
+        </if>
+
+        <if test="isDianPay != null">
+            and pi.is_dian_pay = #{isDianPay}
+        </if>
+
+        <if test="dianPayCompanyName != null and dianPayCompanyName != ''">
+            and pi.dian_pay_company_name = #{dianPayCompanyName}
+        </if>
+
+        <if test="dianPayCompanyRebateRate != null and dianPayCompanyRebateRate != ''">
+            and pi.dian_pay_company_rebate_rate = #{dianPayCompanyRebateRate}
+        </if>
+
+        <if test="promotionType != null">
+            and pi.promotion_type = #{promotionType}
+        </if>
+
+        <if test="policyStartDate != null and policyStartDate != ''">
+            and pi.policy_start_date = #{policyStartDate}
+        </if>
+
+        <if test="policyEndDate != null and policyEndDate != ''">
+            and pi.policy_end_date = #{policyEndDate}
+        </if>
+
+        <if test="createUserId != null and createUserId != ''">
+            and pi.create_user_id = #{createUserId}
+        </if>
+        limit 1
+
+
+    </select>
+
+
+
+
+
+
+
+
+
+
 </mapper>

+ 49 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/controller/ImportPolicyController.java

@@ -0,0 +1,49 @@
+package org.jeecg.ctop.finance.settlement.controller;
+
+import cn.com.ctop.common.module.service.ISysUserService;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.entity.SysUser;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.ctop.finance.settlement.entity.vo.SettlementFileParamsVo;
+import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
+import org.jeecg.ctop.finance.settlement.service.ISettlementInfoService;
+import org.jeecg.ctop.finance.settlement.service.serviceImpl.ReportSettlementServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.Date;
+
+
+/**
+ * 政策信息 导入
+ * Administrator
+ * 2021/7/28
+ **/
+
+@Slf4j
+@RestController
+@RequestMapping("/importPolicyController")
+public class ImportPolicyController {
+
+    @Autowired
+    private ReportSettlementServiceImpl reportSettlementService;
+    @Autowired
+    private ISysUserService userService;
+
+    @ApiOperation(value = "财务结算-导入政策数据", notes = "财务结算-导入政策数据")
+    @PostMapping(value = "/importPolicyInit")
+    public Result importPolicyInit(@RequestParam("file") MultipartFile files) throws Exception{
+
+        return reportSettlementService.importPolicyInit(files);
+    }
+
+
+
+
+
+
+}

+ 1 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/entity/pojo/CtopCwjsSlettementReport.java

@@ -20,6 +20,7 @@ public class CtopCwjsSlettementReport implements Serializable {
     private Long id;
     private Integer policyId;
     private String advertiserName;
+    private String companyName;
     private String productName;
     private String policyDate;
     private Integer mediaType;

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

@@ -0,0 +1,105 @@
+package org.jeecg.ctop.finance.settlement.entity.vo;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import com.alibaba.fastjson.JSONArray;
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ *
+ * @description: 政策 上传 数据 excel
+ * @return:
+ * @author: zianY
+ */
+@Data
+public class PolicyImportVo implements Serializable {
+    /**公司名称*/
+    @Excel(name = "公司名称")
+    private String companyName;
+    /**广告主id*/
+    @Excel(name = "广告主")
+    private String advertiserName;
+
+    @Excel(name = "产品名称(多个产品名称使用英文'-'分割)")
+    private String policyProductName;
+
+
+    /**媒体类型*/
+    @Excel(name = "媒体(1-头条 2-快手)")
+    private Integer mediaType;
+
+    @Excel(name = "销售人员名称")
+    private String createUserName;
+    /**区域 华北,华南,华东*/
+    @Excel(name = "区域(华北,石家庄,华南,骄阳,杭州,华东)")
+    private String areaInfo;
+
+    /**我司主体*/
+    @Excel(name = "我司主体(北京汇创思拓数字科技有限公司,广州汇创思拓数字科技有限公司,骄阳,上海贯月,舟山有梗)")
+    private String companySubjectIdStr;
+
+
+    /**运营方式: 0:自运营  1:代运营*/
+    @Excel(name = "运营方式(0:自运营  1:代运营)")
+    private Integer promotionType;
+
+    /**集团简称*/
+    @Excel(name = "集团简称")
+    private String groupAbbreviation;
+    /**状态 0:待审核 1:审核中 2:审核通过3:审核拒绝*/
+
+    @ApiModelProperty(value = "状态 0:待审核 1:审核中 2:审核通过3:审核拒绝")
+    private Integer approvedStatus;
+
+    /**是否预付:0:否  1:是 */
+    @Excel(name = "是否预付(0:否  1:是)")
+    private Integer advancePay;
+
+    /**返点类型:0:返现  1:返货   2:返现+返货*/
+    @Excel(name = "返点类型(0:返现  1:返货   2:返现+返货)")
+    private Integer rebateType;
+
+    /**返点比例*/
+    @Excel(name = "返点比列(保留2位小数,不需要带'%')")
+    private java.math.BigDecimal rebateRate;
+
+    /**账期*/
+    @Excel(name = "账期")
+    private String accountingPeriod;
+
+    /**是否垫付:0:否  1:是 */
+    @Excel(name = "是否第三方垫付(0:否  1:是)")
+    private Integer isDianPay;
+    /**垫付公司名称*/
+    @Excel(name = "垫付公司")
+    private String dianPayCompanyName;
+    /**垫付公司返点比例*/
+    @Excel(name = "垫付返点(保留4位小数)")
+    private java.math.BigDecimal dianPayCompanyRebateRate;
+
+    /**政策开始时间*/
+    @Excel(name = "政策开始时间(年-月-日)")
+    private String policyStartDate;
+    /**政策结束时间*/
+    @Excel(name = "政策结束时间(年-月-日)")
+    private String policyEndDate;
+    /**备注:如果没人填的话记录被拒次数*/
+    @Excel(name = "备注")
+    private String remarks;
+
+
+    @ApiModelProperty(value = "删除状态(0,正常,1已删除)")
+    private Integer delFlag;
+    /**创建时间*/
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**更新时间*/
+    @ApiModelProperty(value = "更新时间")
+    private Date updateTime;
+
+}

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

@@ -44,6 +44,8 @@ public interface ReportSettlementMapper {
      * @return
      */
    List<String> getAccountIdBytedance(@Param("sales") Set<String> sales, @Param("mediaId")String mediaId, @Param("advertiserId")String advertiserId, @Param("productId")String productId);
+   List<String> getAccountIdBytedanceRepeat(@Param("accountIds") List<String> accountIds,@Param("uploadYears")String uploadYears);
+   List<String> getAccountIdKuaiShouRepeat(@Param("accountIds") List<String> accountIds,@Param("uploadYears")String uploadYears);
 
     /**
      * 查询 头条 账户 图片

+ 2 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/mapper/xml/CwjsProfitMapper.xml

@@ -6,6 +6,7 @@
     <insert id="replaceCwjsSlettementProfit">
             replace into ctop_cwjs_slettement_report(
             advertiser_name,
+            company_name,
             product_name,
             policy_date,
             create_user_id,
@@ -15,6 +16,7 @@
             values
             <foreach collection="list" item="l" separator=",">
                 (#{l.advertiserName},
+                #{l.companyName},
                 #{l.productName},
                 #{l.policyDate},
                 #{l.createUserId},

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

@@ -15,6 +15,7 @@
             )t
       LEFT JOIN ctop_user_allocation c on t.advertiser_id = c.account_id
         where uploadYears = #{uploadYears}
+        ORDER BY date
     </select>
 
     <!-- 查询 头条 账户id-->
@@ -43,6 +44,61 @@
 
     </select>
 
+
+    <!-- 查询  账户id 消耗不为0-->
+    <select id="getAccountIdBytedanceRepeat" resultType="java.lang.String">
+        SELECT
+        advertiser_id
+        FROM
+        ctop_account_transaction_day
+        WHERE
+        cost > 0
+    <if test="uploadYears !=null and uploadYears != ''">
+        AND DATE_FORMAT( date, '%Y-%m' ) =  #{uploadYears}
+    </if>
+    <if test="accountIds !=null and accountIds != ''">
+        AND advertiser_id in
+        <foreach collection="accountIds" item="item" separator=","
+                 open="(" close=")">
+            #{item}
+        </foreach>
+    </if>
+        GROUP BY
+        advertiser_id
+    </select>
+
+    <!-- 查询  账户id 消耗不为0-->
+    <select id="getAccountIdKuaiShouRepeat" resultType="java.lang.String">
+        SELECT
+        account_id AS accountId
+        FROM
+        ctop_kuaishou_daily_agent
+        WHERE
+        total_charged_in_yuan > 0
+     <if test="uploadYears !=null and uploadYears != ''">
+        AND DATE_FORMAT( date_time, '%Y-%m' ) =  #{uploadYears}
+    </if>
+    <if test="accountIds !=null and accountIds != ''">
+        AND account_id in
+        <foreach collection="accountIds" item="item" separator=","
+                 open="(" close=")">
+            #{item}
+        </foreach>
+    </if>
+        GROUP BY
+        account_id
+    </select>
+
+
+
+
+
+
+
+
+
+
+
     <!-- 查询 头条 账户 图片-->
     <select id="getAccountImagesBytedance" resultType="java.lang.String">
         SELECT

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

@@ -6,6 +6,7 @@ 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;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
@@ -29,4 +30,9 @@ public interface IReportSettlementService {
     void cwjsPRofit(CwjsPolicyInfo cwjsPolicyInfo);
 
     List<String> getAccountId(SettlementFileParamsVo paramsVo,SysUser user);
+
+
+
+    Result importPolicyInit(MultipartFile file);
+
 }

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

@@ -1,13 +1,13 @@
 package org.jeecg.ctop.finance.settlement.service.serviceImpl;
 
 import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
 import cn.afterturn.easypoi.excel.entity.ExportParams;
+import cn.afterturn.easypoi.excel.entity.ImportParams;
+import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
 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.mapper.*;
 import cn.com.ctop.common.module.utils.CorpWexinUtils;
 import cn.com.ctop.common.module.utils.ImageUtils;
 import com.alibaba.fastjson.JSONObject;
@@ -24,8 +24,11 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.entity.SysUser;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
+import org.jeecg.ctop.finance.policy.entity.CwjsCompanySubject;
 import org.jeecg.ctop.finance.policy.entity.CwjsPolicyInfo;
 import org.jeecg.ctop.finance.policy.entity.CwjsPolicyProduct;
+import org.jeecg.ctop.finance.policy.mapper.CwjsCompanySubjectMapper;
+import org.jeecg.ctop.finance.policy.mapper.CwjsPolicyInfoMapper;
 import org.jeecg.ctop.finance.policy.mapper.CwjsPolicyProductMapper;
 import org.jeecg.ctop.finance.policy.utils.Check;
 import org.jeecg.ctop.finance.settlement.entity.pojo.CtopCwjsSettlementInfo;
@@ -41,6 +44,7 @@ import org.jeecg.modules.ctop.service.IMaterialReportOverViewService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.imageio.ImageIO;
@@ -903,12 +907,14 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
         List<CwjsPolicyProduct> productList = cwjsPolicyProductMapper.queryProductsByPolicyId(cwjsPolicyInfo.getId());
         if (!Check.isNull(productList)){
             if (!Check.isNull(betweenDaysList)){
+
                 List<CtopCwjsSlettementReport> reportList = new ArrayList<>();
                 for (CwjsPolicyProduct product : productList) {
                     for (String day : betweenDaysList) {
                         CtopCwjsSlettementReport report = new CtopCwjsSlettementReport();
                         report.setPolicyId(cwjsPolicyInfo.getId());
                         report.setAdvertiserName(cwjsPolicyInfo.getAdvertiserName());
+                        report.setCompanyName(cwjsPolicyInfo.getCompanyName());
                         report.setProductName(product.getPolicyProductName());
                         report.setMediaType(cwjsPolicyInfo.getMediaType());
                         report.setCreateUserId(cwjsPolicyInfo.getCreateUserId());
@@ -920,4 +926,107 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
             }
         }
     }
+
+
+
+
+    @Resource
+    private CwjsPolicyInfoMapper cwjsPolicyInfoMapper;
+    @Resource
+    private SysUserMapper sysUserMapper;
+    @Resource
+    private CwjsCompanySubjectMapper cwjsCompanySubjectMapper;
+
+
+
+    @Override
+    public Result importPolicyInit(MultipartFile file) {
+        try {
+            //LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            //settlementInfo.setCreateUserId(user.getId());
+            //settlementInfo.setCreateUserId("b161b7d9793942f980dbfe8c931cd1b0");
+            ImportParams importParams = new ImportParams();
+
+            //表头行数
+            importParams.setHeadRows(1);
+
+            ExcelImportResult<PolicyImportVo> importResult = ExcelImportUtil.importExcelMore(file.getInputStream(), PolicyImportVo.class, importParams);
+            if (importResult.getList().size() < 1) {
+                return Result.error("读取Excel失败,数据不能为空,请重新检查数据并导入");
+            }
+
+
+            for (PolicyImportVo importVo : importResult.getList()) {
+                if (cn.com.ctop.common.module.utils.Check.isNull(importVo.getCompanyName())){
+                    continue;
+                }
+
+                if (cn.com.ctop.common.module.utils.Check.isNull(importVo.getPolicyProductName())){
+                    continue;
+                }
+
+
+                List<String> productNameList = Arrays.asList(importVo.getPolicyProductName().split("-"));
+
+                CwjsPolicyInfo cwjsPolicyInfo = new CwjsPolicyInfo();
+                BeanUtils.copyProperties(importVo, cwjsPolicyInfo);
+
+                // 销售 - 创建人
+                QueryWrapper<SysUser> sysUserQw = new QueryWrapper<>();
+                sysUserQw.eq("realname", importVo.getCreateUserName());
+                sysUserQw.last("limit 1");
+                SysUser user = sysUserMapper.selectOne(sysUserQw);
+                cwjsPolicyInfo.setCreateUserId(user.getId());
+
+                //公司主体
+                QueryWrapper<CwjsCompanySubject> companySubQw = new QueryWrapper<>();
+                companySubQw.eq("company_subject_name", importVo.getCompanySubjectIdStr());
+                companySubQw.eq("area_info", importVo.getAreaInfo());
+                companySubQw.last("limit 1");
+                CwjsCompanySubject companySubject = cwjsCompanySubjectMapper.selectOne(companySubQw);
+                cwjsPolicyInfo.setCompanySubjectId(companySubject.getId());
+
+
+                cwjsPolicyInfo.setApprovedStatus(3);
+
+
+                CwjsPolicyInfo policy = cwjsPolicyInfoMapper.getPolicyInfo(cwjsPolicyInfo);
+
+                if (cn.com.ctop.common.module.utils.Check.isNull(policy)){
+                    cwjsPolicyInfoMapper.insert(cwjsPolicyInfo);
+                    policy = cwjsPolicyInfoMapper.getPolicyInfo(cwjsPolicyInfo);
+                }
+
+                //查看 政策下的产品
+                List<CwjsPolicyProduct> productList = cwjsPolicyProductMapper.queryProductsByPolicyId(policy.getId());
+                List proList = productList.stream().map(CwjsPolicyProduct:: getPolicyProductName).collect(Collectors.toList());
+
+                for (String str : productNameList) {
+
+                    if (!proList.contains(str)){
+                        //新增产品
+                        CwjsPolicyProduct policyProduct = new CwjsPolicyProduct();
+                        policyProduct.setPolicyId(policy.getId());
+                        policyProduct.setPolicyProductName(str);
+                        policyProduct.setCreateUserId(cwjsPolicyInfo.getCreateUserId());
+                        policyProduct.setDelFlag(0);
+                        cwjsPolicyProductMapper.insert(policyProduct);
+                    }
+                }
+
+                this.cwjsPRofit(policy);
+
+            }
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("政策数据上传失败,请使用正确的模板导入!");
+        }
+        return Result.successMsg("政策数据上传成功", null);
+    }
+
+
+
+
 }

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

@@ -11,6 +11,7 @@ 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.ReportSettlementMapper;
 import org.jeecg.ctop.finance.settlement.mapper.SettlementFileInfoMapper;
 import org.jeecg.ctop.finance.settlement.mapper.SettlementInfoMapper;
 import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
@@ -185,6 +186,8 @@ public class SettlementFileInfoServiceImpl extends ServiceImpl<SettlementFileInf
 
     @Autowired
     private IReportSettlementService reportSettlementService;
+    @Autowired
+    private ReportSettlementMapper reportSettlementMapper;
 
     /**
      * @description: 查询账户数量以及图片数量
@@ -196,6 +199,12 @@ public class SettlementFileInfoServiceImpl extends ServiceImpl<SettlementFileInf
     public Result getAccountNumAndImgNum(SettlementFileParamsVo paramsVo, SysUser user) {
         Map<String,String> map =  settlementFileInfoMapper.getAccountNumAndImgNum(paramsVo);
         List<String>accountIds = reportSettlementService.getAccountId(paramsVo,user);
+        //过滤消耗为0 的账户 1-头条 2-快手
+        if (paramsVo.getMediaId().equals(1)){
+            accountIds = reportSettlementMapper.getAccountIdBytedanceRepeat(accountIds,paramsVo.getUploadYears());
+        }else if (paramsVo.getMediaId().equals(2)){
+            accountIds = reportSettlementMapper.getAccountIdKuaiShouRepeat(accountIds,paramsVo.getUploadYears());
+        }
         if(null == accountIds||accountIds.isEmpty()){
             map.put("accountNum","0");
         }else{

+ 69 - 65
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/SettlementInfoServiceImpl.java

@@ -8,6 +8,7 @@ import cn.com.ctop.alarm.modules.service.impl.RuleAccountTemplateServiceImpl;
 import cn.com.ctop.common.module.entity.SysLog;
 import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.SysLogMapper;
+import cn.com.ctop.common.module.mapper.SysUserMapper;
 import cn.com.ctop.common.module.service.impl.UserAllocationServiceImpl;
 import cn.com.ctop.common.module.utils.Check;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -19,9 +20,18 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.entity.SysUser;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.ctop.finance.policy.entity.CwjsCompanySubject;
+import org.jeecg.ctop.finance.policy.entity.CwjsPolicyInfo;
+import org.jeecg.ctop.finance.policy.entity.CwjsPolicyProduct;
+import org.jeecg.ctop.finance.policy.mapper.CwjsCompanySubjectMapper;
+import org.jeecg.ctop.finance.policy.mapper.CwjsPolicyInfoMapper;
+import org.jeecg.ctop.finance.policy.mapper.CwjsPolicyProductMapper;
+import org.jeecg.ctop.finance.policy.service.impl.CwjsPolicyProductServiceImpl;
 import org.jeecg.ctop.finance.settlement.entity.pojo.CtopCwjsSettlementInfo;
 import org.jeecg.ctop.finance.settlement.entity.vo.AccountImportVo;
+import org.jeecg.ctop.finance.settlement.entity.vo.PolicyImportVo;
 import org.jeecg.ctop.finance.settlement.mapper.SettlementInfoMapper;
 import org.jeecg.ctop.finance.settlement.service.ISettlementInfoService;
 import org.jeecg.modules.ctop.entity.ProjectMember;
@@ -38,6 +48,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import java.util.*;
+import java.util.stream.Collectors;
 
 
 @Slf4j
@@ -53,12 +64,10 @@ public class SettlementInfoServiceImpl extends ServiceImpl<SettlementInfoMapper,
 
 
     /**
-     *
-     * @description: 查询 财务结算-账户列表
-     *
      * @param settlementInfo
      * @param pageNo
      * @param pageSize
+     * @description: 查询 财务结算-账户列表
      * @return: org.jeecg.common.api.vo.Result
      * @author: zianY
      */
@@ -73,26 +82,27 @@ public class SettlementInfoServiceImpl extends ServiceImpl<SettlementInfoMapper,
 
     @Autowired
     private UserAllocationServiceImpl userAllocationService;
+
     /**
-     * @description: 财务结算-修改账户状态
      * @param id
      * @param status 账户状态 0-开 1-关
+     * @description: 财务结算-修改账户状态
      * @return: org.jeecg.common.api.vo.Result
      * @author: zianY
      */
     @Override
     public Result updSettlementStatusById(Long id, Integer status) {
         // 修改状态
-        settlementInfoMapper.updSettlementStatusById(id,status);
+        settlementInfoMapper.updSettlementStatusById(id, status);
 
         //同步 状态
-       CtopCwjsSettlementInfo settlementInfo =  settlementInfoMapper.selectById(id);
+        CtopCwjsSettlementInfo settlementInfo = settlementInfoMapper.selectById(id);
 
         UserAllocation userAllocation = userAllocationService.getByAccountId(new Long(settlementInfo.getAccountId()));
-        if (!Check.isNull(userAllocation)){
+        if (!Check.isNull(userAllocation)) {
             userAllocation.setAccountStatus(status);
             userAllocationService.editUserAlloCation(userAllocation);
-        }else{
+        } else {
             LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
             SysLog sysLog = new SysLog();
             sysLog.setLogType(2);
@@ -155,10 +165,8 @@ public class SettlementInfoServiceImpl extends ServiceImpl<SettlementInfoMapper,
     */
 
     /**
-     *
-     * @description: 删除
-     *
      * @param id
+     * @description: 删除
      * @return: org.jeecg.common.api.vo.Result
      * @author: zianY
      */
@@ -170,11 +178,9 @@ public class SettlementInfoServiceImpl extends ServiceImpl<SettlementInfoMapper,
 
 
     /**
-     *
-     * @description:
-     *
      * @param settlementInfo
      * @param file
+     * @description:
      * @return: org.jeecg.common.api.vo.Result
      * @author: zianY
      * @time: 2021/7/30 16:26
@@ -182,69 +188,67 @@ public class SettlementInfoServiceImpl extends ServiceImpl<SettlementInfoMapper,
     @Override
     public Result settlementAccountImport(CtopCwjsSettlementInfo settlementInfo, MultipartFile file) {
 
-            try {
-                //LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
-                //settlementInfo.setCreateUserId(user.getId());
-                //settlementInfo.setCreateUserId("b161b7d9793942f980dbfe8c931cd1b0");
-                ImportParams importParams = new ImportParams();
-                //表格标题行数
-                importParams.setTitleRows(1);
-                //表头行数
-                importParams.setHeadRows(1);
-
-                //校验表头 头条
-                if (StringUtils.equals("1",String.valueOf(settlementInfo.getMediaId()))){
-                    importParams.setImportFields(new String[]{"账户ID","账户名称"});
-                    //快手
-                }else if (StringUtils.equals("2",String.valueOf(settlementInfo.getMediaId()))){
-                    importParams.setImportFields(new String[]{"快手ID","账户ID","账户名称"});
+        try {
+            //LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            //settlementInfo.setCreateUserId(user.getId());
+            //settlementInfo.setCreateUserId("b161b7d9793942f980dbfe8c931cd1b0");
+            ImportParams importParams = new ImportParams();
+            //表格标题行数
+            importParams.setTitleRows(1);
+            //表头行数
+            importParams.setHeadRows(1);
+
+            //校验表头 头条
+            if (StringUtils.equals("1", String.valueOf(settlementInfo.getMediaId()))) {
+                importParams.setImportFields(new String[]{"账户ID", "账户名称"});
+                //快手
+            } else if (StringUtils.equals("2", String.valueOf(settlementInfo.getMediaId()))) {
+                importParams.setImportFields(new String[]{"快手ID", "账户ID", "账户名称"});
+            }
+            //校验excel的标题列顺序
+            importParams.setNeedCheckOrder(true);
+            ExcelImportResult<AccountImportVo> importResult = ExcelImportUtil.importExcelMore(file.getInputStream(), AccountImportVo.class, importParams);
+            if (importResult.getList().size() < 1) {
+                return Result.error("读取Excel失败,数据不能为空,请重新检查数据并导入");
+            }
+            for (AccountImportVo importVo : importResult.getList()) {
+                if (Check.isNull(importVo.getAccountId())) {
+                    continue;
                 }
-                //校验excel的标题列顺序
-                importParams.setNeedCheckOrder(true);
-                ExcelImportResult<AccountImportVo> importResult = ExcelImportUtil.importExcelMore(file.getInputStream(), AccountImportVo.class,importParams);
-                if (importResult.getList().size() < 1){
-                    return Result.error("读取Excel失败,数据不能为空,请重新检查数据并导入");
+                //查询 账户 状态
+                UserAllocation userAllocation = userAllocationService.getByAccountId(new Long(importVo.getAccountId()));
+                if (Check.isNull(userAllocation)) {
+                    settlementInfo.setStatus(0);
+                } else {
+                    settlementInfo.setStatus(userAllocation.getAccountStatus());
                 }
-                for (AccountImportVo importVo : importResult.getList()) {
-                    if (Check.isNull(importVo.getAccountId())){
-                        continue;
-                    }
-                    //查询 账户 状态
-                    UserAllocation userAllocation = userAllocationService.getByAccountId(new Long(importVo.getAccountId()));
-                    if (Check.isNull(userAllocation)){
-                        settlementInfo.setStatus(0);
-                    }else {
-                        settlementInfo.setStatus(userAllocation.getAccountStatus());
-                    }
-                    BeanUtils.copyProperties(importVo,settlementInfo);
-                    //根据账户id 查看
-                    CtopCwjsSettlementInfo cwjs = settlementInfoMapper.getSettlementByAccountId(importVo.getAccountId());
-                    if (Check.isNull(cwjs)){
-                       // BeanUtils.copyProperties(importVo,settlementInfo);
-                        settlementInfoMapper.insert(settlementInfo);
-                    }else {
-                        settlementInfo.setId(cwjs.getId());
-                        settlementInfoMapper.updateById(settlementInfo);
-                    }
+                BeanUtils.copyProperties(importVo, settlementInfo);
+                //根据账户id 查看
+                CtopCwjsSettlementInfo cwjs = settlementInfoMapper.getSettlementByAccountId(importVo.getAccountId());
+                if (Check.isNull(cwjs)) {
+                    // BeanUtils.copyProperties(importVo,settlementInfo);
+                    settlementInfoMapper.insert(settlementInfo);
+                } else {
+                    settlementInfo.setId(cwjs.getId());
+                    settlementInfoMapper.updateById(settlementInfo);
                 }
-            }catch (Exception e){
-                e.printStackTrace();
-                return Result.error("账户数据上传失败,请使用正确的模板导入!");
             }
-            return Result.successMsg("账户数据上传成功",null);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("账户数据上传失败,请使用正确的模板导入!");
         }
+        return Result.successMsg("账户数据上传成功", null);
+    }
 
 
     /**
-     *
-     * @description: 查询多个用户信息
-     *
      * @param userIds
-     * @return: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
+     * @description: 查询多个用户信息
+     * @return: java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
      * @author: zianY
      */
     @Override
-    public List<Map<String,Object>> getUserByIds(Set userIds) {
+    public List<Map<String, Object>> getUserByIds(Set userIds) {
         return settlementInfoMapper.getUserByIds(userIds);
     }
 

+ 21 - 4
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/clean/controller/EstimatePepoleNumberController.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.clean.controller;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
+import cn.com.ctop.kuaishou.modules.clean.mapper.KuaishouAccountCleanTemplateMapper;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.client.ClientProtocolException;
@@ -11,10 +12,9 @@ import org.apache.http.entity.ContentType;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.apache.ibatis.annotations.Param;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.io.BufferedReader;
@@ -41,6 +41,9 @@ public class EstimatePepoleNumberController {
     @Resource
     CtopOauthTokenMapper ctopOauthTokenMapper;
 
+    @Resource
+    KuaishouAccountCleanTemplateMapper kuaishouAccountCleanTemplateMapper;
+
 
     /**
      * 获取人群预估数量
@@ -54,6 +57,20 @@ public class EstimatePepoleNumberController {
     }
 
     /**
+     * 根据账户ID获取项目ID
+     *
+     * @param accountId
+     * @return
+     */
+    @GetMapping("/getProjectId")
+    public Result getProjectId(@Param("accountId") String accountId) {
+        Result result=new Result();
+        String projectId = kuaishouAccountCleanTemplateMapper.getProjectId(accountId);
+        result.setSuccess(true);
+        result.setMessage(projectId);
+        return result;
+    }
+    /**
      * 根据地址请求巨量殷勤,返回响应结果
      *
      * @author zzy

+ 5 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/clean/mapper/KuaishouAccountCleanTemplateMapper.java

@@ -54,4 +54,9 @@ public interface KuaishouAccountCleanTemplateMapper {
      * 根据模板名称查询
      */
     int getTemplateName(@Param("templateName") String templateName);
+
+    /**
+     * 根据模板名称查询
+     */
+    String getProjectId(@Param("accountId") String accountId);
 }

+ 3 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/clean/mapper/xml/KuaishouAccountCleanTemplateMapper.xml

@@ -189,4 +189,7 @@
     <select id="getGroupByAccount" resultType="Map">
         select  t.unit_id as 'unitId',t.ocpx_action_type  as 'type' from ctop_kuaishou_group t  where t.account_id=#{accountId}
     </select>
+    <select id="getProjectId" resultType="String">
+        SELECT t.project_id from ctop_user_allocation t where t.account_id=#{accountId}
+    </select>
 </mapper>

+ 45 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/config/ThreadExecutorConfig.java

@@ -0,0 +1,45 @@
+package cn.com.ctop.kuaishou.modules.config;
+
+import com.alibaba.dubbo.common.logger.Logger;
+import com.alibaba.dubbo.common.logger.LoggerFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadPoolExecutor;
+
+/**
+ * @description: 线程池配置
+ * @author: zzy
+ * @create: 2021-09-02
+ * EnableAsync : 开启异步调用
+ **/
+@Configuration
+@EnableAsync
+public class ThreadExecutorConfig {
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+    /** 核心线程数 */
+    private int corePoolSize = 10;
+    /** 最大线程数 */
+    private int maxPoolSize = 25;
+    /** 队列数 */
+    private int queueCapacity = 15;
+    @Bean
+    public ExecutorService calcThreadExecutor(){
+        logger.info("start build threadPoolTaskExecutor");
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(corePoolSize);
+        executor.setMaxPoolSize(maxPoolSize);
+        executor.setQueueCapacity(queueCapacity);
+        executor.setThreadNamePrefix("calc-thread");
+
+        // rejection-policy:当pool已经达到max size的时候,如何处理新任务
+        // CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        // 执行初始化
+        executor.initialize();
+        return executor.getThreadPoolExecutor();
+    }
+}

+ 15 - 4
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/NewMonitorController.java

@@ -1,14 +1,16 @@
 package cn.com.ctop.kuaishou.modules.report.controller;
 
+import cn.com.ctop.kuaishou.modules.report.mapper.NewMonitorMapper;
 import cn.com.ctop.kuaishou.modules.report.service.NewMonitorService;
 import org.apache.ibatis.annotations.Param;
 import org.jeecg.common.api.vo.Result;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 /**
  * @Description: 新上监控
  * @Author: zzy
@@ -21,15 +23,24 @@ public class NewMonitorController {
 
     @Autowired
     NewMonitorService newMonitorService;
+    @Autowired
+    NewMonitorMapper NewMonitorMapperl;
 
     /**
-     *
-     *
      * @param type
      * @return
      */
     @GetMapping("/synchronousMonitor")
     public Result synchronousMonitor(@Param("type") String type) {
-        return newMonitorService.synchronousMonitor(type);
+        List<Long> kuaiShouallAccountId = NewMonitorMapperl.getAllAccountId("2");
+        List<Long> touTiaoAccountId = NewMonitorMapperl.getAllAccountId("1");
+        for (Long aLong : kuaiShouallAccountId) {
+            newMonitorService.synchronousKuaiShouMonitor(type, aLong);
+        }
+        for (Long aLong : touTiaoAccountId) {
+            newMonitorService.synchronousKuaiShouMonitor(type, aLong);
+        }
+
+        return new Result();
     }
 }

+ 1 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/NewMonitorMapper.java

@@ -13,7 +13,7 @@ import java.util.Map;
 @Mapper
 public interface NewMonitorMapper {
 
-    List<Long> getAllAccountId();
+    List<Long> getAllAccountId(@Param("type") String type);
 
     List<Map> getKuaiShouGroup(@Param("date") String date, @Param("accountId") String accountId);
 

+ 33 - 12
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/NewMonitorMapper.xml

@@ -17,18 +17,19 @@
     </select>
 
     <select id="getAllAccountId" resultType="Long">
-        SELECT DISTINCT t.account_id  as 'accountId' from ctop_user_allocation t where  account_status=0
+        SELECT DISTINCT t.account_id  as 'accountId' from ctop_user_allocation t where  account_status=0 and media_id=#{type}
     </select>
     <select id="getKuaiShouGroup" resultType="Map">
     SELECT t1.account_id as 'accountId',t1.auth_name as 'accountName',t1.user_name as 'userName',t.unit_id as 'unitId',t.group_create_time as 'groupCreatTime',DATE_FORMAT(DATE_ADD(t.group_create_time,INTERVAL 7 DAY),'%Y-%m-%d') as 'afterTime'
-     from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_group t on t1.account_id=t.account_id and t.account_id=#{accountId}
+     from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_group t on t1.account_id=t.account_id
      <where>
+         and t.account_id=#{accountId}
          <choose>
              <when test="date!= null and date!=''">
                  and  t.group_create_time &gt;= DATE_SUB(#{date},INTERVAL 7 DAY)
              </when>
              <otherwise>
-                 t.group_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
+                 and  t.group_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
              </otherwise>
          </choose>
      </where>
@@ -36,14 +37,15 @@
 
     <select id="getKuaiShouCampaign" resultType="Map">
         SELECT t1.account_id as 'accountId',t1.auth_name as 'accountName',t1.user_name as 'userName',t.campaign_id as 'campaignId',t.put_create_time as 'campaignCreatTime',DATE_FORMAT(DATE_ADD(t.put_create_time,INTERVAL 7 DAY),'%Y-%m-%d') as 'afterTime'
-        from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_campaign t on t1.account_id=t.account_id and t.account_id=#{accountId}
+        from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_campaign t on t1.account_id=t.account_id
         <where>
+            and t.account_id=#{accountId}
             <choose>
                 <when test="date != null and date !=''">
                     and  t.put_create_time &gt;= DATE_SUB(#{date},INTERVAL 7 DAY)
                 </when>
                 <otherwise>
-                    t.put_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
+                    and  t.put_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
                 </otherwise>
             </choose>
         </where>
@@ -51,30 +53,31 @@
 
     <select id="getTouTiaoCampaign" resultType="Map">
         SELECT t1.account_id as 'accountId',t1.auth_name as 'accountName',t1.user_name as 'userName',t.id as 'campaignId',t.ad_create_time as 'campaignCreatTime',DATE_FORMAT(DATE_ADD(t.ad_create_time,INTERVAL 7 DAY),'%Y-%m-%d') as 'afterTime'
-        from ctop_user_allocation t1 LEFT JOIN  ctop_bytedance_advertise_plan t on t1.account_id=t.account_id and t.account_id=#{accountId}
+        from ctop_user_allocation t1 LEFT JOIN  ctop_bytedance_advertise_plan t on t1.account_id=t.account_id
         <where>
+            and t.account_id=#{accountId}
             <choose>
                 <when test="date != null and date !=''">
                     and  t.ad_create_time &gt;= DATE_SUB(#{date},INTERVAL 7 DAY)
                 </when>
                 <otherwise>
-                    t.ad_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
+                    and  t.ad_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
                 </otherwise>
             </choose>
         </where>
     </select>
 
-    <select id="getGroupCharge" resultType="BigDecimal">
+    <select id="getGroupCharge" resultType="java.math.BigDecimal">
 
         select sum(charge) from ctop_kuaishou_report_daily_group t where t.stat_date &lt; #{afterDate} and t.unit_id=#{unitId}
     </select>
 
-    <select id="getCampaignCharge" resultType="BigDecimal">
+    <select id="getCampaignCharge" resultType="java.math.BigDecimal">
 
         select sum(charge) from ctop_kuaishou_report_daily_campaign t where t.stat_date &lt; #{afterDate} and t.campaign_id=#{campaignId}
     </select>
 
-    <select id="getCampaignChargeTouTiao" resultType="BigDecimal">
+    <select id="getCampaignChargeTouTiao" resultType="java.math.BigDecimal">
 
         select sum(cost) from ctop_bytedance_report_plan_daily t where t.stat_datetime &lt; #{afterDate} and t.ad_id=#{campaignId}
     </select>
@@ -147,7 +150,16 @@
     </select>
 
     <select id="getKuaiShouGroupMessageGroup" resultType="com.alibaba.fastjson.JSONObject" >
-    SELECT DATE_FORMAT(t.create_time,'%Y-%m-%d') as 'statDate',COUNT(t.effective) as 'new',COUNT(IF(t.effective ='1', TRUE, NULL))  as 'valid' from ctop_new_monitor_group t
+    SELECT
+        <choose>
+            <when test='group=="1"'>
+                DATE_FORMAT(t.create_time,'%Y-%m') as 'statDate',
+            </when>
+            <otherwise>
+                DATE_FORMAT(t.create_time,'%Y-%m-%d') as 'statDate',
+            </otherwise>
+        </choose>
+     COUNT(t.effective) as 'new',COUNT(IF(t.effective ='1', TRUE, NULL))  as 'valid' from ctop_new_monitor_group t
      where  (create_time between #{startDate}  and #{endDate}) and t.account_id in
         <foreach item="item" collection="array" separator="," open="(" close=")" index="">
             #{item}
@@ -164,7 +176,16 @@
     </select>
 
     <select id="getPlanMessageGroup" resultType="com.alibaba.fastjson.JSONObject" >
-        SELECT DATE_FORMAT(t.create_time,'%Y-%m-%d') as 'statDate',COUNT(t.effective) as 'new',COUNT(IF(t.effective ='1', TRUE, NULL))  as 'valid' from ctop_new_monitor_campaign t
+        SELECT
+        <choose>
+            <when test='group=="1"'>
+                DATE_FORMAT(t.create_time,'%Y-%m') as 'statDate',
+            </when>
+            <otherwise>
+                DATE_FORMAT(t.create_time,'%Y-%m-%d') as 'statDate',
+            </otherwise>
+        </choose>
+        COUNT(t.effective) as 'new',COUNT(IF(t.effective ='1', TRUE, NULL))  as 'valid' from ctop_new_monitor_campaign t
         where project_type=#{project} and  (create_time between #{startDate}  and #{endDate}) and t.account_id in
         <foreach item="item" collection="array" separator="," open="(" close=")" index="">
             #{item}

+ 3 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/NewMonitorService.java

@@ -7,7 +7,9 @@ import org.jeecg.common.api.vo.Result;
 import java.util.List;
 
 public interface NewMonitorService {
-    public Result synchronousMonitor(String type);
+    public Result synchronousKuaiShouMonitor(String type, Long accId);
+
+    public Result synchronousTouTiaoMonitor(String type, Long accId);
 
     List<JSONObject> getKuaiShouGroupMessage(JSONArray array, String startDate, String endDate, String target);
 

+ 140 - 123
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/NewMonitorServiceImpl.java

@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.util.DateUtils;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -26,153 +27,169 @@ public class NewMonitorServiceImpl implements NewMonitorService {
     NewMonitorMapper newMonitorMapper;
 
     /**
-     * 同步新上监控数据
+     * 同步快手新上监控数据
      *
      * @param
      * @return
      */
-    public Result synchronousMonitor(String type) {
+    @Async("calcThreadExecutor")
+    public Result synchronousKuaiShouMonitor(String type, Long accId) {
+        log.info("同步快手新上数据:{}",accId);
         Result result = new Result();
         List<Map> kuaiShouGroup = new ArrayList<>();
         List<Map> kuaiShouCampaign = new ArrayList<>();
         List<Map> TouTiaoCampaign = new ArrayList<>();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        List<Long> allAccountId = newMonitorMapper.getAllAccountId();
-        if (!allAccountId.isEmpty()) {
-            for (Long accId : allAccountId) {
-                if (accId != null) {
-                    /*--------------------快手广告组-----------------------*/
-                    if (type.equals("0")) {
-                        //查询创建不满7天的快手组信息
-                        kuaiShouGroup = newMonitorMapper.getKuaiShouGroup(sdf.format(new Date()), String.valueOf(accId));
-                    } else {
-                        //查询全量快手组信息
-                        kuaiShouGroup = newMonitorMapper.getKuaiShouGroup(null, String.valueOf(accId));
-                    }
-                    //处理快手组数据
-                    if (!kuaiShouGroup.isEmpty()) {
-                        kuaiShouGroup.stream().forEach(obj -> {
-                            if (obj != null) {
-                                String unitId = obj.get("unitId") == null ? null : String.valueOf(obj.get("unitId"));
-                                String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
-                                String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
-                                String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
-                                String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
-                                String groupCreatTime = obj.get("groupCreatTime") == null ? null : (String) obj.get("groupCreatTime");
-                                if (unitId != null && afterTime != null) {
-                                    BigDecimal groupCharge = newMonitorMapper.getGroupCharge(unitId, afterTime);
-                                    //大于500为有效广告组
-                                    String effective = "0";
-                                    if (groupCharge != null && groupCharge.compareTo(new BigDecimal(500)) == 1) {
-                                        //有效
-                                        effective = "1";
-                                    }
-                                    String effectiveResult = newMonitorMapper.getMonitorGroupByUnitId(unitId);
-                                    //判断是否存在
-                                    if (effectiveResult != null) {
-                                        if (!effectiveResult.equals(effective)) {
-                                            //存在更新
-                                            newMonitorMapper.updateMonitorGroupByUnitId(unitId, effective);
-                                        }
-
-                                    } else {
-                                        //不存在插入
-                                        newMonitorMapper.saveMonitorGroup(accountId, accountName, userName, unitId, groupCreatTime, "1", effective);
-                                    }
+        if (accId != null) {
+            /*--------------------快手广告组-----------------------*/
+            if (type.equals("0")) {
+                //查询创建不满7天的快手组信息
+                kuaiShouGroup = newMonitorMapper.getKuaiShouGroup(sdf.format(new Date()), String.valueOf(accId));
+            } else {
+                //查询全量快手组信息
+                kuaiShouGroup = newMonitorMapper.getKuaiShouGroup(null, String.valueOf(accId));
+            }
+            //处理快手组数据
+            if (!kuaiShouGroup.isEmpty()) {
+                kuaiShouGroup.stream().forEach(obj -> {
+                    if (obj != null) {
+                        String unitId = obj.get("unitId") == null ? null : String.valueOf(obj.get("unitId"));
+                        String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
+                        String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
+                        String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
+                        String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
+                        String groupCreatTime = obj.get("groupCreatTime") == null ? null : (String) obj.get("groupCreatTime");
+                        if (unitId != null && afterTime != null) {
+                            BigDecimal groupCharge = newMonitorMapper.getGroupCharge(unitId, afterTime);
+                            //大于500为有效广告组
+                            String effective = "0";
+                            if (groupCharge != null && groupCharge.compareTo(new BigDecimal(500)) == 1) {
+                                //有效
+                                effective = "1";
+                            }
+                            String effectiveResult = newMonitorMapper.getMonitorGroupByUnitId(unitId);
+                            //判断是否存在
+                            if (effectiveResult != null) {
+                                if (!effectiveResult.equals(effective)) {
+                                    //存在更新
+                                    newMonitorMapper.updateMonitorGroupByUnitId(unitId, effective);
                                 }
+
+                            } else {
+                                //不存在插入
+                                newMonitorMapper.saveMonitorGroup(accountId, accountName, userName, unitId, groupCreatTime, "1", effective);
                             }
-                        });
+                        }
                     }
+                });
+            }
 
 
-                    /*---------------快手广告计划------------------*/
-                    if (type.equals("0")) {
-                        //查询创建不满7天的快手广告计划
-                        kuaiShouCampaign = newMonitorMapper.getKuaiShouCampaign(sdf.format(new Date()), String.valueOf(accId));
-                    } else {
-                        //查询全量快手广告计划
-                        kuaiShouCampaign = newMonitorMapper.getKuaiShouCampaign(null, String.valueOf(accId));
-                    }
-                    //处理快手广告计划数据
-                    if (!kuaiShouCampaign.isEmpty()) {
-                        kuaiShouCampaign.stream().forEach(obj -> {
-                            if (obj != null) {
-                                String campaignId = obj.get("campaignId") == null ? null : String.valueOf(obj.get("campaignId"));
-                                String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
-                                String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
-                                String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
-                                String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
-                                String campaignCreatTime = obj.get("campaignCreatTime") == null ? null : (String) obj.get("campaignCreatTime");
-                                if (campaignId != null && afterTime != null) {
-                                    BigDecimal campaignCharge = newMonitorMapper.getCampaignCharge(campaignId, afterTime);
-                                    //大于500为有效广告计划
-                                    String effective = "0";
-                                    if (campaignCharge != null && campaignCharge.compareTo(new BigDecimal(500)) == 1) {
-                                        //有效
-                                        effective = "1";
-                                    }
-                                    String effectiveResult = newMonitorMapper.getMonitorPlanByCampaignId(campaignId);
-                                    //判断是否存在
-                                    if (effectiveResult != null) {
-                                        if (!effectiveResult.equals(effective)) {
-                                            //存在更新
-                                            newMonitorMapper.updateMonitorPlanByCampaignId(campaignId, effective);
-                                        }
-                                    } else {
-                                        //不存在插入
-                                        newMonitorMapper.saveMonitorCampaign(accountId, accountName, userName, campaignId, campaignCreatTime, "1", effective);
-                                    }
+            /*---------------快手广告计划------------------*/
+            if (type.equals("0")) {
+                //查询创建不满7天的快手广告计划
+                kuaiShouCampaign = newMonitorMapper.getKuaiShouCampaign(sdf.format(new Date()), String.valueOf(accId));
+            } else {
+                //查询全量快手广告计划
+                kuaiShouCampaign = newMonitorMapper.getKuaiShouCampaign(null, String.valueOf(accId));
+            }
+            //处理快手广告计划数据
+            if (!kuaiShouCampaign.isEmpty()) {
+                kuaiShouCampaign.stream().forEach(obj -> {
+                    if (obj != null) {
+                        String campaignId = obj.get("campaignId") == null ? null : String.valueOf(obj.get("campaignId"));
+                        String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
+                        String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
+                        String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
+                        String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
+                        String campaignCreatTime = obj.get("campaignCreatTime") == null ? null : (String) obj.get("campaignCreatTime");
+                        if (campaignId != null && afterTime != null) {
+                            BigDecimal campaignCharge = newMonitorMapper.getCampaignCharge(campaignId, afterTime);
+                            //大于500为有效广告计划
+                            String effective = "0";
+                            if (campaignCharge != null && campaignCharge.compareTo(new BigDecimal(500)) == 1) {
+                                //有效
+                                effective = "1";
+                            }
+                            String effectiveResult = newMonitorMapper.getMonitorPlanByCampaignId(campaignId);
+                            //判断是否存在
+                            if (effectiveResult != null) {
+                                if (!effectiveResult.equals(effective)) {
+                                    //存在更新
+                                    newMonitorMapper.updateMonitorPlanByCampaignId(campaignId, effective);
                                 }
+                            } else {
+                                //不存在插入
+                                newMonitorMapper.saveMonitorCampaign(accountId, accountName, userName, campaignId, campaignCreatTime, "1", effective);
                             }
-                        });
+                        }
                     }
+                });
+            }
+        }
 
-                    /*---------------头条广告计划------------------*/
-                    if (type.equals("0")) {
-                        //查询创建不满7天的头条广告计划
-                        TouTiaoCampaign = newMonitorMapper.getTouTiaoCampaign(sdf.format(new Date()), String.valueOf(accId));
-                    } else {
-                        //查询全量头条广告计划
-                        TouTiaoCampaign = newMonitorMapper.getTouTiaoCampaign(null, String.valueOf(accId));
-                    }
-                    //处理快手广告计划数据
-                    if (!TouTiaoCampaign.isEmpty()) {
-                        TouTiaoCampaign.stream().forEach(obj -> {
-                            if (obj != null) {
-                                String campaignId = obj.get("campaignId") == null ? null : String.valueOf(obj.get("campaignId"));
-                                String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
-                                String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
-                                String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
-                                String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
-                                String campaignCreatTime = obj.get("campaignCreatTime") == null ? null : (String) obj.get("campaignCreatTime");
-                                if (campaignId != null && afterTime != null) {
-                                    BigDecimal campaignCharge = newMonitorMapper.getCampaignChargeTouTiao(campaignId, afterTime);
-                                    //大于500为有效广告计划
-                                    String effective = "0";
-                                    if (campaignCharge != null && campaignCharge.compareTo(new BigDecimal(500)) == 1) {
-                                        //有效
-                                        effective = "1";
-                                    }
-                                    String effectiveResult = newMonitorMapper.getMonitorPlanByCampaignId(campaignId);
-                                    //判断是否存在
-                                    if (effectiveResult != null) {
-                                        if (!effectiveResult.equals(effective)) {
-                                            //存在更新
-                                            newMonitorMapper.updateMonitorPlanByCampaignId(campaignId, effective);
-                                        }
-                                    } else {
-                                        //不存在插入
-                                        newMonitorMapper.saveMonitorCampaign(accountId, accountName, userName, campaignId, campaignCreatTime, "0", effective);
-                                    }
+
+        return result;
+    }
+
+
+    /**
+     * 同步头条新上监控数据
+     *
+     * @param
+     * @return
+     */
+    public Result synchronousTouTiaoMonitor(String type, Long accId) {
+        log.info("同步头条新上数据:{}",accId);
+        Result result = new Result();
+        List<Map> kuaiShouGroup = new ArrayList<>();
+        List<Map> kuaiShouCampaign = new ArrayList<>();
+        List<Map> TouTiaoCampaign = new ArrayList<>();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        if (accId != null) {
+            /*---------------头条广告计划------------------*/
+            if (type.equals("0")) {
+                //查询创建不满7天的头条广告计划
+                TouTiaoCampaign = newMonitorMapper.getTouTiaoCampaign(sdf.format(new Date()), String.valueOf(accId));
+            } else {
+                //查询全量头条广告计划
+                TouTiaoCampaign = newMonitorMapper.getTouTiaoCampaign(null, String.valueOf(accId));
+            }
+            //处理快手广告计划数据
+            if (!TouTiaoCampaign.isEmpty()) {
+                TouTiaoCampaign.stream().forEach(obj -> {
+                    if (obj != null) {
+                        String campaignId = obj.get("campaignId") == null ? null : String.valueOf(obj.get("campaignId"));
+                        String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
+                        String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
+                        String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
+                        String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
+                        String campaignCreatTime = obj.get("campaignCreatTime") == null ? null : (String) obj.get("campaignCreatTime");
+                        if (campaignId != null && afterTime != null) {
+                            BigDecimal campaignCharge = newMonitorMapper.getCampaignChargeTouTiao(campaignId, afterTime);
+                            //大于500为有效广告计划
+                            String effective = "0";
+                            if (campaignCharge != null && campaignCharge.compareTo(new BigDecimal(500)) == 1) {
+                                //有效
+                                effective = "1";
+                            }
+                            String effectiveResult = newMonitorMapper.getMonitorPlanByCampaignId(campaignId);
+                            //判断是否存在
+                            if (effectiveResult != null) {
+                                if (!effectiveResult.equals(effective)) {
+                                    //存在更新
+                                    newMonitorMapper.updateMonitorPlanByCampaignId(campaignId, effective);
                                 }
+                            } else {
+                                //不存在插入
+                                newMonitorMapper.saveMonitorCampaign(accountId, accountName, userName, campaignId, campaignCreatTime, "0", effective);
                             }
-                        });
+                        }
                     }
-                }
+                });
             }
         }
 
-
         return result;
     }
 

+ 3 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -1362,12 +1362,12 @@ public class TestController {
         }
         List<CtopOauthToken> tokens = tokenService.getByProjectId(458L);    //淘特项目
         for (CtopOauthToken token : tokens) {
-            Date startDate = DateUtils.getNowDate();
+            Date startDate = DateUtils.addDay(DateUtils.getNowDate(), -1);
             if(startDate.after(token.getAccessTokenExpiresIn())){   //过期跳过
                 continue;
             }
-            Date enDate = DateUtils.addDay(startDate, 30);
-            List<AiKuaishouUnitLevelOperationRecord> planIdsAndUnitIds = kuaishouUnitLevelOperationRecordMapper.selectAllByAccountIdAndDate(token.getAccountId(), startDate, enDate);
+            Date enDate = DateUtils.addDay(startDate, -30);
+            List<AiKuaishouUnitLevelOperationRecord> planIdsAndUnitIds = kuaishouUnitLevelOperationRecordMapper.selectAllByAccountIdAndDate(token.getAccountId(), enDate, startDate);
             if(Check.isNull(planIdsAndUnitIds)){
                 continue;
             }