Bläddra i källkod

人群包2.0bug修复

zhaoxian 4 år sedan
förälder
incheckning
b2106156c3

+ 11 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouPopulationPackageController.java

@@ -212,6 +212,17 @@ public class KuaishouPopulationPackageController {
         }
         return Result.error("查询失败");
     }
+
+    @RequestMapping(value = "/checkPopulationPackage")
+    public Result<Object> checkPopulationPackage(String signature) {
+        try {
+           return kuaishouPopulationPackageService.checkPopulationPackage(signature);
+        } catch (Exception e) {
+            log.error("查询异常,", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
     /**
      * 添加
      *

+ 2 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouPopulationPackageMapper.java

@@ -24,6 +24,7 @@ public interface KuaishouPopulationPackageMapper extends BaseMapper<KuaishouPopu
 
     List<JSONObject> getRelatedGroups(@Param("id") Long id, @Param("accountId") Long accountId);
 
-    List<Long> queryListByStatus();
+    List<JSONObject> queryListByStatus();
 
+    KuaishouPopulationPackage checkPopulationPackage(@Param("signature") String signature);
 }

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouPopulationPackageRelMapper.java

@@ -35,4 +35,6 @@ public interface KuaishouPopulationPackageRelMapper extends BaseMapper<KuaishouP
     List<JSONObject> getAccountByProjectId(@Param("projectId") Long projectId,@Param("id") String id);
 
     void updateStatus(@Param("rel") KuaishouPopulationPackageRel rel);
+
+    KuaishouPopulationPackageRel queryByOrientationId(@Param("orientationId") Long orientationId,@Param("accountId")  Long accountId);
 }

+ 9 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouPopulationPackageMapper.xml

@@ -60,8 +60,8 @@
               )
     </select>
 
-    <select id="queryListByStatus" resultType="java.lang.Long">
-        SELECT account_id
+    <select id="queryListByStatus" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT account_id,project_id
         FROM ctop_kuaishou_population_package_rel
         WHERE data_status =1
         GROUP BY account_id
@@ -86,4 +86,11 @@
         order by t1.create_time desc
     </select>
 
+    <select id="checkPopulationPackage" resultType="cn.com.ctop.kuaishou.modules.ai.entity.KuaishouPopulationPackage">
+        select orientation_name
+        from ctop_kuaishou_population_package
+        where signature = #{signature}
+        AND data_status = 1
+</select>
+
 </mapper>

+ 15 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouPopulationPackageRelMapper.xml

@@ -66,8 +66,9 @@
                    END as 'statusStr',
                cover_num 'coverNum',
                (SELECT COUNT(1)
-                FROM ctop_kuaishou_template
-                where account_id = t1.account_id) as 'populationCount'
+                FROM ctop_kuaishou_population_package_rel t
+                where t.account_id = t1.account_id
+                  AND t.data_status = 1) as 'populationCount'
         FROM ctop_kuaishou_population_package_rel t1
                  LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
         where t1.pop_id = #{id}
@@ -84,6 +85,16 @@
           AND account_id = #{accountId}
     </select>
 
+    <select id="queryByOrientationId" resultType="cn.com.ctop.kuaishou.modules.ai.entity.KuaishouPopulationPackageRel">
+        SELECT pop_id,
+               account_id,
+               orientation_id
+        FROM ctop_kuaishou_population_package_rel
+        WHERE orientation_id = #{orientationId}
+          AND data_status = 1
+          AND account_id = #{accountId}
+    </select>
+
     <insert id="replaceBatch">
         replace into ctop_kuaishou_population_package_rel(
         id,
@@ -157,8 +168,8 @@
             cover_num   =#{rel.coverNum},
             record_size =#{rel.recordSize},
             match_size  =#{rel.matchSize}
-            where orientation_id = #{rel.orientationId}
-                and account_id = #{rel.accountId}
+        where orientation_id = #{rel.orientationId}
+          and account_id = #{rel.accountId}
     </update>
 
 </mapper>

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouPopulationPackageService.java

@@ -32,4 +32,6 @@ public interface IKuaishouPopulationPackageService extends IService<KuaishouPopu
     void crowdListQuery();
 
     Result<Object> getAccountByProjectId(Long projectId, String id);
+
+    Result<Object> checkPopulationPackage(String signature);
 }

+ 35 - 12
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouPopulationPackageServiceImpl.java

@@ -42,7 +42,7 @@ import java.util.UUID;
 public class KuaishouPopulationPackageServiceImpl extends ServiceImpl<KuaishouPopulationPackageMapper, KuaishouPopulationPackage> implements IKuaishouPopulationPackageService {
 
     @Autowired
-    private KuaishouPopulationPackageMapper KuaishouPopulationPackageMapper;
+    private KuaishouPopulationPackageMapper kuaishouPopulationPackageMapper;
     @Autowired
     private KuaishouPopulationPackageRelMapper relMapper;
     @Autowired
@@ -65,7 +65,7 @@ public class KuaishouPopulationPackageServiceImpl extends ServiceImpl<KuaishouPo
         wrapper.eq("orientation_name", kuaishouPopulationPackage.getOrientationName());
         wrapper.eq("data_status", 1);
         wrapper.last("limit 1");
-        KuaishouPopulationPackage checkName = KuaishouPopulationPackageMapper.selectOne(wrapper);
+        KuaishouPopulationPackage checkName = kuaishouPopulationPackageMapper.selectOne(wrapper);
         if (!Check.isNull(checkName)) {
             return Result.error("该项目下已存在人群包名,请重新输入!");
         }
@@ -87,7 +87,7 @@ public class KuaishouPopulationPackageServiceImpl extends ServiceImpl<KuaishouPo
         queryWrapper.eq("signature", md5);
         queryWrapper.eq("data_status", 1);
         queryWrapper.last("limit 1");
-        KuaishouPopulationPackage one = KuaishouPopulationPackageMapper.selectOne(queryWrapper);
+        KuaishouPopulationPackage one = kuaishouPopulationPackageMapper.selectOne(queryWrapper);
         if (!Check.isNull(one)) {
             return Result.error("该项目已上传过此人群包,人群包名为:" + one.getOrientationName());
         }
@@ -113,7 +113,7 @@ public class KuaishouPopulationPackageServiceImpl extends ServiceImpl<KuaishouPo
 
     @Override
     public Result<Object> push(JSONArray accountIds, Long id) {
-        KuaishouPopulationPackage pPackage = KuaishouPopulationPackageMapper.selectById(id);
+        KuaishouPopulationPackage pPackage = kuaishouPopulationPackageMapper.selectById(id);
         if (Check.isNull(pPackage)) {
             return Result.error("没有获取到人群包");
         }
@@ -237,12 +237,12 @@ public class KuaishouPopulationPackageServiceImpl extends ServiceImpl<KuaishouPo
 
     @Override
     public Result<Object> queryPageList(KuaishouPopulationPackage kuaishouPopulationPackage, Integer pageNo, Integer pageSize) {
-        Long total = KuaishouPopulationPackageMapper.queryPageListTotal(kuaishouPopulationPackage.getProjectId(), kuaishouPopulationPackage.getOrientationName());
+        Long total = kuaishouPopulationPackageMapper.queryPageListTotal(kuaishouPopulationPackage.getProjectId(), kuaishouPopulationPackage.getOrientationName());
         PageHelper.startPage(pageNo, pageSize, false);
-        List<JSONObject> list = KuaishouPopulationPackageMapper.queryPageList(kuaishouPopulationPackage.getProjectId(), kuaishouPopulationPackage.getOrientationName());
+        List<JSONObject> list = kuaishouPopulationPackageMapper.queryPageList(kuaishouPopulationPackage.getProjectId(), kuaishouPopulationPackage.getOrientationName());
         if (!Check.isNull(list)) {
             for (JSONObject object : list) {
-                object.put("unitCount", KuaishouPopulationPackageMapper.queryUnitCount(object.getLong("id")));
+                object.put("unitCount", kuaishouPopulationPackageMapper.queryUnitCount(object.getLong("id")));
             }
         }
         PageInfo pageInfo = new PageInfo(list);
@@ -270,16 +270,18 @@ public class KuaishouPopulationPackageServiceImpl extends ServiceImpl<KuaishouPo
 
     @Override
     public Result<Object> getRelatedGroups(Long id, Long accountId) {
-        List<JSONObject> list = KuaishouPopulationPackageMapper.getRelatedGroups(id, accountId);
+        List<JSONObject> list = kuaishouPopulationPackageMapper.getRelatedGroups(id, accountId);
         return Result.ok(new PageInfo<>(list));
     }
 
     @Override
     public void crowdListQuery() {
-        List<Long> accountIds = KuaishouPopulationPackageMapper.queryListByStatus();
+        List<JSONObject> objs = kuaishouPopulationPackageMapper.queryListByStatus();
         for (int i = 0; i <= 7; i++) {
             if (i != 2) {
-                for (Long accountId : accountIds) {
+                for (JSONObject o : objs) {
+                    Long accountId = o.getLong("account_id");
+                    Long projectId = o.getLong("project_id");
                     CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
                     if (!Check.isNull(token)) {
                         JSONObject jsonObject = iKuaishouPopulationService.getPopulationList(accountId, token.getAccessToken(), i);
@@ -290,8 +292,15 @@ public class KuaishouPopulationPackageServiceImpl extends ServiceImpl<KuaishouPo
                                 if (details.size() > 0) {
                                     for (int j = 0; j < details.size(); j++) {
                                         JSONObject obj = details.getJSONObject(j);
-                                        KuaishouPopulationPackageRel rel = JSONObject.parseObject(obj.toJSONString(),KuaishouPopulationPackageRel.class);
-                                        relMapper.updateStatus(rel);
+                                        KuaishouPopulationPackageRel rel = JSONObject.parseObject(obj.toJSONString(), KuaishouPopulationPackageRel.class);
+                                        if (Check.isNull(relMapper.queryByOrientationId(rel.getOrientationId(), rel.getAccountId()))) {
+                                            rel.setProjectId(projectId);
+                                            rel.setDataStatus(1);
+                                            rel.setStatDate(DateUtils.formatDate(new Date()));
+                                            relService.save(rel);
+                                        } else {
+                                            relMapper.updateStatus(rel);
+                                        }
                                     }
                                 }
                             }
@@ -308,4 +317,18 @@ public class KuaishouPopulationPackageServiceImpl extends ServiceImpl<KuaishouPo
         return Result.ok(new PageInfo<>(list));
     }
 
+    @Override
+    public Result<Object> checkPopulationPackage(String signature) {
+        KuaishouPopulationPackage ksPackage = kuaishouPopulationPackageMapper.checkPopulationPackage(signature);
+        if (Check.isNull(ksPackage)) {
+            return Result.ok("success");
+        } else {
+            Result<Object> r = new Result<>();
+            r.setCode(201);
+            r.setMessage("项目已保存过该人群包,名称为:" + ksPackage.getOrientationName());
+            r.setSuccess(true);
+            return r;
+        }
+    }
+
 }