Selaa lähdekoodia

Merge remote-tracking branch 'origin/master'

yumeng 4 vuotta sitten
vanhempi
commit
beacfda1c3

+ 4 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java

@@ -207,8 +207,9 @@ public class CallbackController {
                     userAllocation.setWarningAmount(warningAmount);
                     userAllocation.setCreateTime(new Date());
                     userAllocation.setUpdateTime(new Date());
-                    //同步物料,0关闭,1开启
+                    //自动投放,0关闭,1开启
                     userAllocation.setAutoDelivery(json.getInteger("autoDelivery"));
+                    userAllocation.setMaterialType(json.getString("materialType"));
                     allocationMapper.deleteById(userAllocation.getId());
                     Map<String, Object> deleteUserMap = new HashMap<>();
                     deleteUserMap.put("advertiser_id", advertiserId);
@@ -219,7 +220,8 @@ public class CallbackController {
                         log.info("同步分配用户表完成,task_id:{},accountId:{}", state, accountId);
                     }
                     //物料类型,0-不同步,1应用包,(2人群包,3定向包)
-                    Integer materialType = json.getInteger("materialType");
+                    JSONArray materialTypeArr = json.getJSONArray("materialType");
+                    Integer materialType = materialTypeArr.getInteger(0);
                     //账号绑定
                     bindAccountAuthService.addBindAccount(accountId, KuaishouInterfaceConstant.LOGIN_TYPE_KUAISHOU, advertiserId);
                     Thread t = new Thread() {

+ 5 - 1
module-common/src/main/java/cn/com/ctop/common/module/entity/UserAllocation.java

@@ -139,9 +139,13 @@ public class UserAllocation implements Serializable {
      */
     private Integer deleteComment;
     /**
-     * 同步物料,0关闭,1开启
+     * 自动投放,0关闭,1开启
      */
     private Integer autoDelivery;
+    /**
+     * 物料类型 0-不同步,1应用包,(2人群包,3定向包)
+     */
+    private String materialType;
 
     /**
      * 修改时间

+ 51 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouAutoSynchronousProjectMaterialJob.java

@@ -0,0 +1,51 @@
+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.ai.service.IKuaishouAppPackageService;
+import com.alibaba.fastjson.JSONArray;
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Slf4j
+@Component
+public class KuaishouAutoSynchronousProjectMaterialJob {
+    @Autowired
+    private IUserAllocationService userAllocationService;
+    @Autowired
+    private IKuaishouAppPackageService kuaishouAppPackageService;
+    static ExecutorService executorService = Executors.newFixedThreadPool(5);
+
+    @XxlJob("autoSynchronousProjectMaterialJob")
+    public void execute() {
+        List<UserAllocation> userAllocations = userAllocationService.listByMediaId("2", 0);
+        userAllocations.forEach(userAllocation -> executorService.submit(() ->
+                synchronMaterials(userAllocation.getMaterialType(), userAllocation.getAccountId(), userAllocation.getProjectId())
+        ));
+        XxlJobHelper.log("快手物料数据同步完成");
+    }
+
+
+    private void synchronMaterials(String materialType, Long accountId, Long projectId) {
+        if (!Check.isNull(materialType) && materialType.contains("1")) {
+            JSONArray accountIds = new JSONArray();
+            accountIds.add(accountId);
+            //1 有效项目模板
+            List<Long> ids = kuaishouAppPackageService.queryByAppVersion(projectId, null, 1);
+            log.info("同步账户应用,应用模板={}", ids);
+            if (!Check.isNull(ids)) {
+                for (Long id : ids) {
+                    kuaishouAppPackageService.pushAppPackage(id, accountIds);
+                }
+            }
+        }
+    }
+}