Forráskód Böngészése

快手-新上监控

yumeng 3 éve
szülő
commit
6702f599ac

+ 55 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouCleanNews.java

@@ -0,0 +1,55 @@
+package cn.com.ctop.job.kuaishou.handler;
+
+
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouPlanCreateService;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.jeecg.common.util.DateUtils.getEndDate;
+import static org.jeecg.common.util.DateUtils.getStartDate;
+
+
+@Component
+@Slf4j
+public class KuaishouCleanNews {
+    @Autowired
+    private IUserAllocationService userAllocationService;
+    static ExecutorService cleanService = Executors.newFixedThreadPool(15);
+    @Autowired
+    private IKuaishouPlanCreateService planCreateService;
+
+    @XxlJob("cleanNews")
+    public void cleanNews() {
+        String nowDate = DateUtils.getDate("yyyy-MM-dd");
+        String statDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+        Date startDate = getStartDate(statDate);
+        Date endDate = getEndDate(statDate);
+        List<UserAllocation> userAllocations = userAllocationService.listByMediaId("2", 0);
+        if (!Check.isNull(userAllocations)) {
+            for (UserAllocation allocation : userAllocations) {
+                cleanService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            planCreateService.cleanCreateDetail(allocation.getProjectId(), allocation.getUserId(), allocation.getUserName(), allocation.getAccountId(), statDate, startDate, endDate);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                });
+            }
+        }
+    }
+}
+

+ 115 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouPlanCreate.java

@@ -0,0 +1,115 @@
+package cn.com.ctop.kuaishou.modules.report.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * 快手-计划创建记录
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-11-18
+ */
+@Data
+@TableName("ctop_kuaishou_plan_create")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_kuaishou_plan_create对象", description = "快手-计划创建记录")
+public class KuaishouPlanCreate {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+    private Long id;
+    private String companyId;
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long accountId;
+    /**
+     * 项目ID
+     */
+    @Excel(name = "项目ID", width = 15)
+    @ApiModelProperty(value = "项目ID")
+    private Long projectId;
+    /**
+     * 运营id
+     */
+    @Excel(name = "运营id", width = 15)
+    @ApiModelProperty(value = "运营id")
+    private String userId;
+    /**
+     * 运营姓名
+     */
+    @Excel(name = "运营姓名", width = 15)
+    @ApiModelProperty(value = "运营姓名")
+    private String userName;
+    /**
+     * leader姓名
+     */
+    @Excel(name = "leader姓名", width = 15)
+    @ApiModelProperty(value = "leader姓名")
+    private String leaderName;
+    /**
+     * 日期
+     */
+    @Excel(name = "日期", width = 15)
+    @ApiModelProperty(value = "日期")
+    private String statDate;
+    /**
+     * 新建计划数
+     */
+    @Excel(name = "新建计划数", width = 15)
+    @ApiModelProperty(value = "新建计划数")
+    private Integer newPlan;
+    private Integer newUnit;
+    /**
+     * 自动化新建组数
+     */
+    @Excel(name = "自动化新建组数", width = 15)
+    @ApiModelProperty(value = "自动化新建组数")
+    private Integer autoUnit;
+    /**
+     * 手动新建组数
+     */
+    @Excel(name = "手动新建组数", width = 15)
+    @ApiModelProperty(value = "手动新建组数")
+    private Integer manualUnit;
+    /**
+     * 有效新建组数
+     */
+    @Excel(name = "有效新建组数", width = 15)
+    @ApiModelProperty(value = "有效新建组数")
+    private Integer effectiveUnit;
+    /**
+     * 创建时间
+     */
+    @Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     * 修改时间
+     */
+    @Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+}

+ 29 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouPlanCreateMapper.java

@@ -0,0 +1,29 @@
+package cn.com.ctop.kuaishou.modules.report.mapper;
+
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouPlanCreate;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Date;
+
+/**
+ * 快手-计划创建记录
+ *
+ * @author jeecg-boot
+ * 2021-11-18
+ * @version V1.0
+ */
+public interface KuaishouPlanCreateMapper extends BaseMapper<KuaishouPlanCreate> {
+
+    String getLeaderNameByUserId(@Param("userId") String userId);
+
+    Integer getNewPlan(@Param("accountId") Long accountId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
+
+    Integer getNewUnit(@Param("accountId") Long accountId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
+
+    Integer getAutoUnit(@Param("accountId") Long accountId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
+
+    Integer getEffectiveUnit(@Param("accountId") Long accountId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
+
+    String getCompanyId(@Param("userId") String userId);
+}

+ 44 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouPlanCreateMapper.xml

@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.kuaishou.modules.report.mapper.KuaishouPlanCreateMapper">
+
+    <select id="getLeaderNameByUserId" resultType="java.lang.String">
+        select  leader_name  from  sys_user where  id = #{userId}
+    </select>
+    <select id="getNewPlan" resultType="java.lang.Integer">
+       SELECT count(1)  from  ctop_kuaishou_campaign WHERE account_id = #{accountId}
+       and put_create_time &gt;= #{startDate}
+       and put_create_time &lt;= #{endDate}
+    </select>
+    <select id="getNewUnit" resultType="java.lang.Integer">
+         SELECT count(1)  from  ctop_kuaishou_group WHERE account_id = #{accountId}
+       and group_create_time &gt;= #{startDate}
+       and group_create_time &lt;= #{endDate}
+    </select>
+    <select id="getAutoUnit" resultType="java.lang.Integer">
+        SELECT
+        count(1)
+        FROM
+        ctop_ai_kuaishou_unit_level_operation_record
+        WHERE
+        account_id = #{accountId}
+        AND create_time &gt;= #{startDate}
+        AND create_time  &lt;= #{endDate}
+        AND `status` = 0
+    </select>
+    <select id="getEffectiveUnit" resultType="java.lang.Integer">
+        SELECT
+        count(1)
+        FROM
+        ctop_kuaishou_group t1
+        LEFT JOIN ctop_kuaishou_report_daily_group t2 ON t1.unit_id = t2.unit_id
+        WHERE
+        t1.account_id = #{accountId}
+        AND t1.group_create_time &gt;= #{startDate}
+        AND t1.group_create_time &lt;= #{endDate}
+        AND t2.charge > 0
+    </select>
+    <select id="getCompanyId" resultType="java.lang.String">
+       SELECT company_id  from  user_company WHERE user_id = #{userId}
+    </select>
+</mapper>

+ 19 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKuaishouPlanCreateService.java

@@ -0,0 +1,19 @@
+package cn.com.ctop.kuaishou.modules.report.service;
+
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouPlanCreate;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.Date;
+
+/**
+ * 快手-计划创建记录
+ *
+ * @author jeecg-boot
+ * 2021-11-18
+ * @version V1.0
+ */
+public interface IKuaishouPlanCreateService extends IService<KuaishouPlanCreate> {
+    void cleanCreateDetail(Long projectId, String userId, String userName, Long accountId, String statDate, Date startDate, Date endDate);
+
+
+}

+ 70 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouPlanCreateServiceImpl.java

@@ -0,0 +1,70 @@
+package cn.com.ctop.kuaishou.modules.report.service.impl;
+
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouPlanCreate;
+import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouPlanCreateMapper;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouPlanCreateService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 快手-计划创建记录
+ *
+ * @author jeecg-boot
+ * 2021-11-18
+ * @version V1.0
+ */
+@Service
+@Slf4j
+public class KuaishouPlanCreateServiceImpl extends ServiceImpl<KuaishouPlanCreateMapper, KuaishouPlanCreate> implements IKuaishouPlanCreateService {
+    @Autowired
+    private KuaishouPlanCreateMapper planCreateMapper;
+
+    @Override
+    public void cleanCreateDetail(Long projectId, String userId, String userName, Long accountId, String statDate, Date startDate, Date endDate) {
+        Map<String, Object> deleteMap = new HashMap<>();
+        deleteMap.put("account_id", accountId);
+        deleteMap.put("stat_date", statDate);
+        planCreateMapper.deleteByMap(deleteMap);
+        KuaishouPlanCreate create = new KuaishouPlanCreate();
+        create.setAccountId(accountId);
+        create.setUserId(userId);
+        create.setUserName(userName);
+        create.setProjectId(projectId);
+        create.setStatDate(statDate);
+        String companyId = planCreateMapper.getCompanyId(userId);
+        create.setCompanyId(companyId);
+        String leaderName = planCreateMapper.getLeaderNameByUserId(userId);
+        create.setLeaderName(leaderName);
+        Integer planCount = planCreateMapper.getNewPlan(accountId, startDate, endDate);
+        create.setNewPlan(planCount);
+        Integer newUnitCount = planCreateMapper.getNewUnit(accountId, startDate, endDate);
+        create.setNewUnit(newUnitCount);
+        Integer autoUnitCount = planCreateMapper.getAutoUnit(accountId, startDate, endDate);
+        create.setAutoUnit(autoUnitCount);
+        if (newUnitCount != 0) {
+            Integer manualUnit = newUnitCount - autoUnitCount;
+            if (manualUnit > 0) {
+                create.setManualUnit(manualUnit);
+            } else {
+                create.setManualUnit(0);
+            }
+        } else {
+            create.setManualUnit(0);
+        }
+        Integer effectiveUnitCount = planCreateMapper.getEffectiveUnit(accountId, startDate, endDate);
+        create.setEffectiveUnit(effectiveUnitCount);
+        int insert = planCreateMapper.insert(create);
+        if (insert > 0) {
+            log.info("账户创建汇总清洗完成,accountId:{},stat_date:{}", accountId, statDate);
+        }
+
+    }
+
+
+}