Ver código fonte

修改素材标签接口,可按需同步数据

zhouzeyu@c-top.com.cn 3 anos atrás
pai
commit
0a2a0a5bb9

+ 1 - 1
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/agent/mapper/CtopAccountTransactionDayMapper.java

@@ -9,7 +9,7 @@ import java.util.List;
 @Mapper
 public interface CtopAccountTransactionDayMapper {
 
-    List<String> getAdvertiserIdByDate(@Param("date") String date);
+    List<String> getAdvertiserIdByDate(@Param("date") String date,@Param("advertiserId") String advertiserId);
 
     void saveAccountTransactionDay(@Param("list") List<TransactionDay> list, @Param("date") String date);
 

+ 58 - 57
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/clean/service/impl/KuaiShouAccountCleanServiceImpl.java

@@ -284,67 +284,68 @@ public class KuaiShouAccountCleanServiceImpl implements KuaiShouAccountCleanServ
             List<KuaiShouAccountCleanTemplateInfo> templateListBystatus = kuaishouAccountCleanTemplateMapper.getTemplateListBystatus();
             if (!templateListBystatus.isEmpty()) {
                 templateListBystatus.stream().forEach(ob -> {
-                    //获取各项优化目标
-                    List<String> optimizationObjectiveList = Arrays.asList(ob.getOptimizationObjective().split(";"));
-                    //获取清理时间范围
-                    String cleanTime = ob.getCleanTime();
-                    //计算最早清理时间
-                    Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
-                    calendar.add(Calendar.DATE, -Integer.parseInt(cleanTime));
-                    String startDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
-                    //查询符合模板规则的组
-                    List<String> groupMessage = kuaishouAccountCleanTemplateMapper.getGroupMessage(ob, optimizationObjectiveList, startDate);
-                    AtomicReference<Boolean> falg = new AtomicReference<>(true);
-                    if (!groupMessage.isEmpty()) {
-                        //获取Token
-                        CtopOauthToken ctopOauthToken = ctopOauthTokenMapper.selectByAccountId(Long.parseLong(ob.getAccountId()));
-                        if (ctopOauthToken != null) {
-                            groupMessage.stream().forEach(item -> {
-                                //修改广告组状态
-                                Map<String, Object> resultMap = iKuaiShouUpdateService.updateUnitStatus(ctopOauthToken.getAccessToken(), Long.parseLong(ob.getAccountId()), Long.parseLong(item), Integer.parseInt(ob.getPerformOperations()), null);
-                                Boolean resultFlag = (Boolean) resultMap.get("success");
-                                //判断有没有失败
-                                if (!resultFlag) {
-                                    falg.set(false);
-                                }
-                            });
+                    if(!ob.getAccountId().isEmpty()){
+                        //获取各项优化目标
+                        List<String> optimizationObjectiveList = Arrays.asList(ob.getOptimizationObjective().split(";"));
+                        //获取清理时间范围
+                        String cleanTime = ob.getCleanTime();
+                        //计算最早清理时间
+                        Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
+                        calendar.add(Calendar.DATE, -Integer.parseInt(cleanTime));
+                        String startDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
+                        //查询符合模板规则的组
+                        List<String> groupMessage = kuaishouAccountCleanTemplateMapper.getGroupMessage(ob, optimizationObjectiveList, startDate);
+                        AtomicReference<Boolean> falg = new AtomicReference<>(true);
+                        if (!groupMessage.isEmpty()) {
+                            //获取Token
+                            CtopOauthToken ctopOauthToken = ctopOauthTokenMapper.selectByAccountId(Long.parseLong(ob.getAccountId()));
+                            if (ctopOauthToken != null) {
+                                groupMessage.stream().forEach(item -> {
+                                    //修改广告组状态
+                                    Map<String, Object> resultMap = iKuaiShouUpdateService.updateUnitStatus(ctopOauthToken.getAccessToken(), Long.parseLong(ob.getAccountId()), Long.parseLong(item), Integer.parseInt(ob.getPerformOperations()), null);
+                                    Boolean resultFlag = (Boolean) resultMap.get("success");
+                                    //判断有没有失败
+                                    if (!resultFlag) {
+                                        falg.set(false);
+                                    }
+                                });
 
+                            }
                         }
-                    }
-                    if (!groupMessage.isEmpty() && falg.get()) {
-                        //修改成功插入日志记录
-                        KuaiShouAccountCleanLogInfo kuaiShouAccountCleanLogInfo = new KuaiShouAccountCleanLogInfo();
-                        //设置账户id
-                        kuaiShouAccountCleanLogInfo.setAccountId(ob.getAccountId());
-                        // 1-投放、2-暂停、3-删除
-                        kuaiShouAccountCleanLogInfo.setOperationType(ob.getPerformOperations());
-                        //设置运营
-                        Map<String, String> map = kuaishouAccountCleanTemplateMapper.getUserNameByAccountId(ob.getAccountId());
-                        String authName = "";
-                        if (map != null) {
-                            kuaiShouAccountCleanLogInfo.setUserName(map.get("userName"));
-                            authName = map.get("authName");
-                        }
-                        //设置时间
-                        kuaiShouAccountCleanLogInfo.setCreateTime(sd.format(new Date()));
-                        StringBuilder unitIds = new StringBuilder();
-                        groupMessage.stream().forEach(unid -> {
-                            unitIds.append(unid).append(",");
-                        });
-                        //操作类型
-                        String operationType = null;
-                        if (ob.getPerformOperations().equals("2")) {
-                            operationType = "暂停";
-                        }
-                        if (ob.getPerformOperations().equals("3")) {
-                            operationType = "删除";
+                        if (!groupMessage.isEmpty() && falg.get()) {
+                            //修改成功插入日志记录
+                            KuaiShouAccountCleanLogInfo kuaiShouAccountCleanLogInfo = new KuaiShouAccountCleanLogInfo();
+                            //设置账户id
+                            kuaiShouAccountCleanLogInfo.setAccountId(ob.getAccountId());
+                            // 1-投放、2-暂停、3-删除
+                            kuaiShouAccountCleanLogInfo.setOperationType(ob.getPerformOperations());
+                            //设置运营
+                            Map<String, String> map = kuaishouAccountCleanTemplateMapper.getUserNameByAccountId(ob.getAccountId());
+                            String authName = "";
+                            if (map != null) {
+                                kuaiShouAccountCleanLogInfo.setUserName(map.get("userName"));
+                                authName = map.get("authName");
+                            }
+                            //设置时间
+                            kuaiShouAccountCleanLogInfo.setCreateTime(sd.format(new Date()));
+                            StringBuilder unitIds = new StringBuilder();
+                            groupMessage.stream().forEach(unid -> {
+                                unitIds.append(unid).append(",");
+                            });
+                            //操作类型
+                            String operationType = null;
+                            if (ob.getPerformOperations().equals("2")) {
+                                operationType = "暂停";
+                            }
+                            if (ob.getPerformOperations().equals("3")) {
+                                operationType = "删除";
+                            }
+                            //执行信息
+                            String textMessage = "清理规则执行:  账户:" + ob.getAccountId() + ", 授权名称: " + authName + ",推广组:" + unitIds + "已经被清理规则" + operationType;
+                            kuaiShouAccountCleanLogInfo.setExecutiveInformation(textMessage);
+                            kuaishouAccountCleanTemplateMapper.saveCleamLog(kuaiShouAccountCleanLogInfo);
                         }
-                        //执行信息
-                        String textMessage = "清理规则执行:  账户:" + ob.getAccountId() + ", 授权名称: " + authName + ",推广组:" + unitIds + "已经被清理规则" + operationType;
-                        kuaiShouAccountCleanLogInfo.setExecutiveInformation(textMessage);
-                        kuaishouAccountCleanTemplateMapper.saveCleamLog(kuaiShouAccountCleanLogInfo);
                     }
-
                 });
             }
 

+ 10 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/label/mapper/MaterialLabelMapper.java

@@ -22,6 +22,11 @@ public interface MaterialLabelMapper {
     List<String> getMateriaSignature();
 
     /**
+     * 查询增量素材
+     */
+    List<String> getMateriaSignatureCharge(@Param("date")String date);
+
+    /**
      * 获取素材产生消耗的最早日期
      */
     String getMaterialFirstDate(@Param("signature")String signature);
@@ -55,6 +60,11 @@ public interface MaterialLabelMapper {
     List<LabelStandardInfo> getAllMaterialData();
 
     /**
+     * 查询所有素材标准数据
+     */
+    List<LabelStandardInfo> getAllMaterialDataCharge(@Param("date")String date);
+
+    /**
      * 保存素材标签数据
      */
     void saveMaterialTag(@Param("code")String code,@Param("tagName")String tagName,@Param("tagCode")String tagCode,@Param("tagId")String tagId,@Param("categoryId")String categoryId,@Param("createTime")String createTime);

+ 7 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/label/mapper/xml/MaterialTagMapper.xml

@@ -50,6 +50,9 @@
         SELECT  signature from ctop_etl_kuaishou_video_base_info t  GROUP BY t.signature
     </select>
 
+    <select id="getMateriaSignatureCharge" resultType="String">
+        SELECT  signature from ctop_kuaishou_report_daily_material t  where t.stat_date=#{date}  GROUP BY t.signature
+    </select>
 
   <select id="getMaterialFirstDate" parameterType="String" resultType="String">
         SELECT  MIN(stat_date) from ctop_kuaishou_report_daily_material t where t.charge>0 and  t.signature=#{signature}
@@ -91,6 +94,10 @@
          select * from ctop_label_standard
     </select>
 
+    <select id="getAllMaterialDataCharge" resultMap="BaseResultMap">
+         select * from ctop_label_standard t where t.create_time=#{date}
+    </select>
+
   <update id="updateMaterialRecord">
         update ctop_label_standard set charge_date=#{chargeDate},activation_thirty_days=#{activationThirtyDays},activation_two_days=#{activationTwoDays},
         form_count_thirty_days=#{formCountThirtyDays},form_count_two_days=#{formCountTwoDays},play_3s_ratio=#{play3sRatio},conversion_ratio=#{conversionRatio},

+ 3 - 3
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/label/service/MaterialLabelService.java

@@ -10,10 +10,10 @@ import org.jeecg.common.api.vo.Result;
  */
 public interface MaterialLabelService {
 
-    public Result filterMaterial ();
+    public Result filterMaterial (String type);
 
-    public Result materialSpecificationLabel();
+    public Result materialSpecificationLabel(String type);
 
 
-    public Result SynchronousLabel();
+    public Result SynchronousLabel(String type);
 }

+ 34 - 9
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/label/service/impl/MaterialLabelServiceImpl.java

@@ -40,12 +40,23 @@ public class MaterialLabelServiceImpl implements MaterialLabelService {
      * @return
      */
     @Override
-    public Result filterMaterial() {
+    public Result filterMaterial(String type) {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
         Result result = new Result();
         try {
-            //查询所有素材标签
-            List<String> materiaSignature = materialLabelMapper.getMateriaSignature();
+            List<String> materiaSignature = new ArrayList<>();
+            if (type.equals("1")) {
+                //查询所有素材标签
+                materiaSignature = materialLabelMapper.getMateriaSignature();
+            } else {
+                //查询增量素材
+                Calendar calc = Calendar.getInstance();
+                calc.setTime(new Date());
+                calc.add(Calendar.DAY_OF_MONTH, -1);
+                materiaSignature = materialLabelMapper.getMateriaSignatureCharge(sdf.format(calc.getTime()));
+            }
+
             if (!materiaSignature.isEmpty()) {
                 materiaSignature.stream().forEach(str -> {
                     if (!str.isEmpty()) {
@@ -104,11 +115,11 @@ public class MaterialLabelServiceImpl implements MaterialLabelService {
      * @return
      */
     @Override
-    public Result materialSpecificationLabel() {
+    public Result materialSpecificationLabel(String type) {
         Result result = new Result();
         Map<String, String> tgaMap = new HashMap<>();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-
+        List<LabelStandardInfo> allMaterialData = new ArrayList<>();
         try {
             String date = sdf.format(new Date());
             //查询所有标签
@@ -118,8 +129,13 @@ public class MaterialLabelServiceImpl implements MaterialLabelService {
                     tgaMap.put(tag.getTagName(), tag.getTagCode() + ";" + tag.getId());
                 });
             }
-            //查询素材标签判断标准数据
-            List<LabelStandardInfo> allMaterialData = materialLabelMapper.getAllMaterialData();
+            if (type.equals("0")) {
+                //查询全量素材标签判断标准数据
+                allMaterialData = materialLabelMapper.getAllMaterialData();
+            } else {
+                allMaterialData = materialLabelMapper.getAllMaterialDataCharge(sdf.format(new Date()));
+            }
+
             if (!allMaterialData.isEmpty()) {
                 allMaterialData.stream().forEach(obj -> {
                     //三十天内累计激活数
@@ -338,10 +354,18 @@ public class MaterialLabelServiceImpl implements MaterialLabelService {
      * @return
      */
     @Override
-    public Result SynchronousLabel() {
+    public Result SynchronousLabel(String type) {
         Result result = new Result();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        List<MaterialLabelInfo> materialLabelData = new ArrayList<>();
         try {
-            List<MaterialLabelInfo> materialLabelData = materialLabelMapper.getMaterialLabelData(null);
+            if (type.equals("0")) {
+                //查询所有素材
+                materialLabelData = materialLabelMapper.getMaterialLabelData(null);
+            } else {
+                //查询增量素材
+                materialLabelData = materialLabelMapper.getMaterialLabelData(sdf.format(new Date()));
+            }
             //创建索引
             boolean indexIfNotExist = elasticsearchUtil.createIndexIfNotExist(MaterialLabelInfo.class);
             //同步ES
@@ -357,6 +381,7 @@ public class MaterialLabelServiceImpl implements MaterialLabelService {
                 }
             }
             result.setSuccess(true);
+            log.info("同步标签至es成功:{}");
         } catch (Exception e) {
             result.setSuccess(false);
             log.info("同步标签至ES失败:{}", e.toString());