Browse Source

人群定时更改

zhaoxian 4 years ago
parent
commit
f4578a3e02

+ 16 - 32
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/CrowdListQueryJob.java

@@ -3,9 +3,7 @@ package cn.com.ctop.job.kuaishou.handler;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
-import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPack;
-import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouCrowdPackMapper;
-import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouCrowdPackService;
+import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouPopulationPackageMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -24,13 +22,10 @@ public class CrowdListQueryJob {
     @Autowired
     private ICtopOauthTokenService tokenService;
     @Autowired
-    private KuaishouCrowdPackMapper crowdPackMapper;
-    @Autowired
     private IKuaishouPopulationService iKuaishouPopulationService;
     @Autowired
-    private IKuaishouCrowdPackService crowdPackService;
-
-    static ExecutorService executorService = Executors.newFixedThreadPool(5);
+    private KuaishouPopulationPackageMapper KuaishouPopulationPackageMapper;
+    static ExecutorService executorService = Executors.newFixedThreadPool(3);
 
     @XxlJob("crowdListQueryJob")
     public void execute() {
@@ -40,31 +35,20 @@ public class CrowdListQueryJob {
                 list.add(i);
             }
         }
+        List<Long> accountIds = KuaishouPopulationPackageMapper.queryListByStatus();
         list.forEach(status -> executorService.submit(() -> {
-            List<KuaishouCrowdPack> crowdList = crowdPackMapper.queryListByStatus();
-            for (KuaishouCrowdPack crowdPack : crowdList) {
-                CtopOauthToken token = tokenService.getTokenByAccountId(crowdPack.getAccountId());
-                JSONObject jsonObject = iKuaishouPopulationService.getPopulationList(crowdPack.getAccountId(), token.getAccessToken(), status);
-                if (jsonObject.getInteger("code") == 0) {
-                    JSONObject data = jsonObject.getJSONObject("data");
-                    if (!Check.isNull(data)) {
-                        JSONArray details = data.getJSONArray("details");
-                        if (details.size() > 0) {
-                            for (int j = 0; j < details.size(); j++) {
-                                JSONObject obj = details.getJSONObject(j);
-                                if (Check.isNull(crowdPackMapper.queryByAccountId(obj.getLong("account_id"), obj.getLong("orientation_id")))) {
-                                    KuaishouCrowdPack oldPack = crowdPackMapper.queryByAccountId(null, obj.getLong("orientation_id"));
-                                    KuaishouCrowdPack crowdPackEntity = JSONObject.toJavaObject(obj, KuaishouCrowdPack.class);
-                                    if (!Check.isNull(oldPack)) {
-                                        crowdPackEntity.setStatDate(oldPack.getStatDate());
-                                        crowdPackEntity.setUrl(oldPack.getUrl());
-                                        crowdPackEntity.setSignature(oldPack.getSignature());
-                                    }
-                                    crowdPackEntity.setMessage("PUSH OK");
-                                    crowdPackEntity.setDataStatus(1);
-                                    crowdPackService.save(crowdPackEntity);
-                                } else {
-                                    crowdPackMapper.update(obj);
+            for (Long accountId : accountIds) {
+                CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+                if (!Check.isNull(token)) {
+                    JSONObject jsonObject = iKuaishouPopulationService.getPopulationList(accountId, token.getAccessToken(), status);
+                    if (jsonObject.getInteger("code") == 0) {
+                        JSONObject data = jsonObject.getJSONObject("data");
+                        if (!Check.isNull(data)) {
+                            JSONArray details = data.getJSONArray("details");
+                            if (details.size() > 0) {
+                                for (int j = 0; j < details.size(); j++) {
+                                    JSONObject obj = details.getJSONObject(j);
+                                    KuaishouPopulationPackageMapper.updateStatus(obj.getLong("account_id"), obj.getLong("orientation_id"), obj.getInteger("status"));
                                 }
                             }
                         }