zhaoxian 4 лет назад
Родитель
Сommit
36650c1b2e

+ 27 - 5
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/CrowdListQueryJob.java

@@ -5,6 +5,7 @@ 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.batch.service.IKuaishouPopulationService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -22,31 +23,52 @@ import java.util.concurrent.Executors;
 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);
 
     @XxlJob("crowdListQueryJob")
     public void execute() {
         List<Integer> list = new ArrayList<>();
-        for (int i = 0; i <= 7; i++) {
-            list.add(i);
+        for (int i = 0; i <= 6; i++) {
+            if (i != 2) {
+                list.add(i);
+            }
         }
         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(), crowdPack.getStatus());
+                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) {
-                            crowdPackMapper.updateBatch(details);
+                            JSONArray datas = new JSONArray();
+                            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 {
+                                    datas.add(obj);
+                                }
+                            }
+                            crowdPackMapper.updateBatch(datas);
                         }
                     }
                 }

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouCrowdPackController.java

@@ -174,7 +174,7 @@ public class KuaishouCrowdPackController {
         return Result.error("查询失败");
     }
 
-    @PostMapping(value = "/crowdListQuery")
+    @RequestMapping(value = "/crowdListQuery")
     public Result<Object> crowdListQuery() {
         try {
             kuaishouCrowdPackService.crowdListQuery();

+ 8 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouCrowdPackMapper.xml

@@ -191,9 +191,14 @@
     <select id="queryByAccountId" resultType="cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPack">
         SELECT *
         FROM ctop_kuaishou_crowd_package
-        where orientation_id = #{orientationId}
-          AND account_id = #{accountId}
-          and data_status = 1
+        where data_status = 1
+        <if test="accountId!=null">
+            AND account_id = #{accountId}
+        </if>
+        <if test="orientationId!=null">
+            AND orientation_id = #{orientationId}
+        </if>
+        limit 1
     </select>
 
     <update id="updateBatch">

+ 31 - 10
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouCrowdPackServiceImpl.java

@@ -174,16 +174,37 @@ public class KuaishouCrowdPackServiceImpl extends ServiceImpl<KuaishouCrowdPackM
     @Override
     public void crowdListQuery() {
         List<KuaishouCrowdPack> crowdList = crowdPackMapper.queryListByStatus();
-        for (int i = 0; i <= 7; i++) {
-            for (KuaishouCrowdPack crowdPack : crowdList) {
-                CtopOauthToken token = tokenService.getTokenByAccountId(crowdPack.getAccountId());
-                JSONObject jsonObject = iKuaishouPopulationService.getPopulationList(crowdPack.getAccountId(), token.getAccessToken(), i);
-                if (jsonObject.getInteger("code") == 0) {
-                    JSONObject data = jsonObject.getJSONObject("data");
-                    if (!Check.isNull(data)) {
-                        JSONArray details = data.getJSONArray("details");
-                        if (details.size() > 0) {
-                            crowdPackMapper.updateBatch(details);
+        for (int i = 0; i <= 6; i++) {
+            if (i != 2) {
+                for (KuaishouCrowdPack crowdPack : crowdList) {
+                    CtopOauthToken token = tokenService.getTokenByAccountId(crowdPack.getAccountId());
+                    JSONObject jsonObject = iKuaishouPopulationService.getPopulationList(crowdPack.getAccountId(), token.getAccessToken(), i);
+                    if (jsonObject.getInteger("code") == 0) {
+                        JSONObject data = jsonObject.getJSONObject("data");
+                        if (!Check.isNull(data)) {
+                            JSONArray details = data.getJSONArray("details");
+                            if (details.size() > 0) {
+                                JSONArray datas = new JSONArray();
+                                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);
+                                        }
+
+                                        this.save(crowdPackEntity);
+                                    } else {
+                                        datas.add(obj);
+                                    }
+                                }
+                                crowdPackMapper.updateBatch(datas);
+                            }
                         }
                     }
                 }