Prechádzať zdrojové kódy

项目自动投放策略,优化查询总数

zhaoxian 3 rokov pred
rodič
commit
f663726083

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

@@ -1,6 +1,7 @@
 package cn.com.ctop.kuaishou.modules.ai.controller;
 
 import cn.com.ctop.common.module.entity.Project;
+import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.service.IProjectService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.Check;
@@ -200,7 +201,16 @@ public class KuaishouProjectStrategyController {
             if (!Check.isNull(user)) {
                 kuaishouProjectStrategy.setUserId(user.getId());
             }
-            kuaishouProjectStrategyService.saveOrUpdate(kuaishouProjectStrategy);
+            if (Check.isNull(kuaishouProjectStrategy.getId()) && !Check.isNull(kuaishouProjectStrategy.getProjectId())) {
+                QueryWrapper<UserAllocation> wrapper = new QueryWrapper<>();
+                wrapper.eq("project_id", kuaishouProjectStrategy.getProjectId());
+                wrapper.eq("account_status", 0);
+                wrapper.eq("auto_delivery", 0);
+                UserAllocation userAllocation = new UserAllocation();
+                userAllocation.setAutoDelivery(1);
+                userAllocationService.update(userAllocation, wrapper);
+            }
+            boolean b = kuaishouProjectStrategyService.saveOrUpdate(kuaishouProjectStrategy);
             result.success("操作成功!");
         } catch (Exception e) {
             log.error(e.getMessage(), e);

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

@@ -27,4 +27,6 @@ public interface KuaishouProjectStrategyMapper extends BaseMapper<KuaishouProjec
     Integer checkProjectisOpen(Long projectId);
 
     List<KuaishouProjectStrategy> getAllEffectStrategy(@Param("unitType")int unitType, @Param("sourceMaterial")String sourceMaterial);
+
+    List<Long> queryProjectId();
 }

+ 18 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouProjectStrategyMapper.xml

@@ -133,14 +133,22 @@
             IFNULL(ROUND(SUM(t2.charge)/SUM(t2.photo_click),2),0) as 'photoClickCost',
             IFNULL(ROUND(SUM(t2.charge)/SUM(t2.bclick),2),0) as 'actionCost',
             (SELECT COUNT(1) FROM ctop_user_allocation where project_strategy = 1 AND account_status = 0
-            <if test="projectId != null ">
-                 AND project_id = t1.project_id
+            <if test="projectIds != null and projectIds.size()>0 ">
+                 AND project_id in
+                <foreach collection="projectIds" item="item" separator=","
+                         open="(" close=")">
+                    #{item}
+                </foreach>
             </if>
             ) as 'successCount',
             (SELECT COUNT(1) FROM ctop_user_allocation where account_status = 0
-        <if test="projectId != null ">
-            AND project_id = t1.project_id
-        </if>
+            <if test="projectIds != null and projectIds.size()>0 ">
+            AND project_id in
+            <foreach collection="projectIds" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+            </if>
             ) as 'allAccountCount'
         FROM ctop_user_allocation t1
                  LEFT JOIN ctop_etl_kuaishou_report_account_daily t2 ON t2.account_id = t1.account_id and t2.stat_date &gt;=#{startTime}
@@ -173,5 +181,10 @@
         </if>
     </select>
 
+    <select id="queryProjectId" resultType="java.lang.Long">
+        SELECT project_id from ctop_ai_kuaishou_project_strategy
+        WHERE data_status = 1
+        group by project_id
+    </select>
 
 </mapper>

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

@@ -13,6 +13,7 @@ import org.jeecg.common.api.vo.Result;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -33,6 +34,13 @@ public class KuaishouProjectStrategyServiceImpl extends ServiceImpl<KuaishouProj
 
     @Override
     public Result<Object> queryProjectList(JSONObject data) {
+        List<Long> projectIds = new ArrayList<>();
+        if (Check.isNull(data.getLong("projectId"))) {
+            projectIds = kuaishouProjectStrategyMapper.queryProjectId();
+        } else {
+            projectIds.add(data.getLong("projectId"));
+        }
+        data.put("projectIds", projectIds);
         JSONObject result = new JSONObject();
         JSONObject allInfo = kuaishouProjectStrategyMapper.queryProjectAll(data);
         Integer pageNo = Check.isNull(data.getInteger("pageNo")) ? 1 : data.getInteger("pageNo");
@@ -71,7 +79,7 @@ public class KuaishouProjectStrategyServiceImpl extends ServiceImpl<KuaishouProj
     }
 
     @Override
-    public List<KuaishouProjectStrategy> getAllEffectStrategy(int unitType,String sourceMaterial) {
-        return kuaishouProjectStrategyMapper.getAllEffectStrategy(unitType,sourceMaterial);
+    public List<KuaishouProjectStrategy> getAllEffectStrategy(int unitType, String sourceMaterial) {
+        return kuaishouProjectStrategyMapper.getAllEffectStrategy(unitType, sourceMaterial);
     }
 }