Selaa lähdekoodia

Merge branch 'V2.0.1' into test

zhaoxian 3 vuotta sitten
vanhempi
commit
f06c6591e5

+ 1 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouAdvertiserStrategy.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.kuaishou.modules.ai.entity;
 
+import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItems;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;

+ 2 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/enums/KuaishouCreativeMatTypeEnum.java

@@ -9,7 +9,8 @@ public enum KuaishouCreativeMatTypeEnum {
      * type字段 第一位创意创建方式,第二位素材获取方式
      * 快手创意素材获取类型
      */
-    KUAISHOU_CREATIVE_MAT_TYPE_ENUM_CUSTOM_NEW("41","自定义上新",-10L,-5L),
+//    KUAISHOU_CREATIVE_MAT_TYPE_ENUM_CUSTOM_NEW("41","自定义上新",-10L,-5L),
+    KUAISHOU_CREATIVE_MAT_TYPE_ENUM_CUSTOM_NEW("41","自定义上新",-28*60*24L,-1*60*24L),
     KUAISHOU_CREATIVE_MAT_TYPE_ENUM_CUSTOM_HIGH_quality("42","自定义高质量",-28*60*24L,-1*60*24L),
     KUAISHOU_CREATIVE_MAT_TYPE_ENUM_CUSTOM_MISSING("43","自定义上新",-60*60*24L,-1*60*24L),
     KUAISHOU_CREATIVE_MAT_TYPE_ENUM_CUSTOM_HISTORY("44","自定义历史",-60*60*24L,-1*60*24L),

+ 76 - 33
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouCreateCreativeServiceImpl.java

@@ -38,6 +38,7 @@ import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel;
+import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItems;
 import cn.com.ctop.kuaishou.modules.channel.service.IKuaishouChannelService;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -289,11 +290,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         } else {
             //单一应用
             String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
-            List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
-            if (null == newVideos || newVideos.isEmpty()) {
-                log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
-                return videoCnt;
-            }
             Long appId = null;
             String appName = null;
             if (strategy.getCampaignType() == 2 || strategy.getCampaignType() == 7) {
@@ -312,7 +308,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             KuaishouChannel channel = null;
             if (!Check.isNull(useChannel) && useChannel == 1 && ("account".equals(level) || "plan".equals(level))) {
                 try {
-                    Result<Object> result = channelService.queryChannel(accountId, level, appName);
+                    Result<Object> result = channelService.queryChannel(accountId, level, appName, null);
                     Integer code = result.getCode();
                     if (code == 200) {
                         channel = (KuaishouChannel) result.getResult();
@@ -334,6 +330,29 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             if (null == newCampaignId) {
                 return videoCnt;
             }
+            KuaishouChannel usedchannel = null;
+            if (useChannel == 1) {
+                strategy.setMaterialKeyword(null);
+                if (!"group".equals(level)) {
+                    usedchannel = channelService.queryUsedChannel(accountId, newCampaignId, level);
+                    if (Check.isNull(usedchannel)) {
+                        if ("account".equals(level)) {
+                            usedchannel = channel;
+                        } else {
+                            return videoCnt;
+                        }
+                    }
+                    List<KuaishouChannelItems> items = usedchannel.getItems();
+                    if (!Check.isNull(items) && !items.isEmpty()) {
+                        strategy.setMaterialKeyword(items.get(0).getKeyword());
+                    }
+                }
+            }
+            List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
+            if (null == newVideos || newVideos.isEmpty()) {
+                log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
+                return videoCnt;
+            }
             //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
             for (KuaiShouVideoGet videoItem : newVideos) {
                 Boolean unitOverrun = getUnitOverrun(accountId);
@@ -355,15 +374,15 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 //获取组级渠道号
                 if (!Check.isNull(useChannel) && useChannel == 1 && "group".equals(level)) {
                     try {
-                        Result<Object> result = channelService.queryChannel(accountId, level, appName);
+                        Result<Object> result = channelService.queryChannel(accountId, level, appName, videoItem.getPhotoName());
                         Integer code = result.getCode();
                         if (code == 200) {
-                            channel = (KuaishouChannel) result.getResult();
-                            if (Check.isNull(channel)) {
+                            usedchannel = (KuaishouChannel) result.getResult();
+                            if (Check.isNull(usedchannel)) {
                                 log.info("(组级)账户:{},{}", accountId, result.getMessage());
                                 continue;
                             } else {
-                                log.info("(组级)获取到渠道号:{}", channel.getChannelCode());
+                                log.info("(组级)获取到渠道号:{}", usedchannel.getChannelCode());
                             }
                         } else {
                             log.error("(组级)通过账户(" + accountId + ")未获取到渠道号!!!");
@@ -373,8 +392,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         e.printStackTrace();
                     }
                 }
-                String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId, channel);
-                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, channel);
+                String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId, usedchannel);
+                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, usedchannel);
                 log.info("创建广告组入参:{}", unitParams);
                 Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                 Integer unitCode = (Integer) unitCreateResult.get("code");
@@ -394,8 +413,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 if (unitCode != 0) {
                     log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                    if (!Check.isNull(channel)) {
-                        channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null,0);
+                    if (!Check.isNull(usedchannel)) {
+                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
                     }
                     continue;
                 }
@@ -403,10 +422,10 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitLevelOperationRecord.setUnitId(unitId);
                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                 videoCnt--;
-                if (!Check.isNull(channel)) {
-                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId,1);
+                if (!Check.isNull(usedchannel)) {
+                    channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId, 1);
                 }
-                JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy, channel);//TODO 添加素材
+                JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy, usedchannel);//TODO 添加素材
                 createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
                 if (videoCnt <= 0) {
                     return 0L;
@@ -624,10 +643,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         } else {
             String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
             //单一应用
-            List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
-            if (null == allVideos) {
-                return;
-            }
             Long appId = null;
             String appName = null;
             String appIdString = strategy.getAppIdArray();
@@ -649,7 +664,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             KuaishouChannel channel = null;
             if (!Check.isNull(useChannel) && useChannel == 1 && ("account".equals(level) || "plan".equals(level))) {
                 try {
-                    Result<Object> result = channelService.queryChannel(accountId, level, appName);
+                    Result<Object> result = channelService.queryChannel(accountId, level, appName, null);
                     Integer code = result.getCode();
                     if (code == 200) {
                         channel = (KuaishouChannel) result.getResult();
@@ -671,6 +686,28 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             if (null == newCampaignId) {
                 return;
             }
+            KuaishouChannel usedchannel = null;
+            if (useChannel == 1) {
+                strategy.setMaterialKeyword(null);
+                if (!"group".equals(level)) {
+                    usedchannel = channelService.queryUsedChannel(accountId, newCampaignId, level);
+                    if (Check.isNull(usedchannel)) {
+                        if ("account".equals(level)) {
+                            usedchannel = channel;
+                        } else {
+                            return;
+                        }
+                    }
+                    List<KuaishouChannelItems> items = usedchannel.getItems();
+                    if (!Check.isNull(items) && !items.isEmpty()) {
+                        strategy.setMaterialKeyword(items.get(0).getKeyword());
+                    }
+                }
+            }
+            List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
+            if (null == allVideos) {
+                return;
+            }
             //创意
             List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
             for (int j = 1; j < splitVideos.size() + 1; j++) {
@@ -691,15 +728,19 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 //获取组级渠道号
                 if (!Check.isNull(useChannel) && useChannel == 1 && "group".equals(level)) {
                     try {
-                        Result<Object> result = channelService.queryChannel(accountId, level, appName);
+                        KuaiShouVideoGet videoGet = splitVideos.get(1).get(0);
+                        if (Check.isNull(videoGet)) {
+                            return;
+                        }
+                        Result<Object> result = channelService.queryChannel(accountId, level, appName, videoGet.getPhotoName());
                         Integer code = result.getCode();
                         if (code == 200) {
-                            channel = (KuaishouChannel) result.getResult();
-                            if (Check.isNull(channel)) {
+                            usedchannel = (KuaishouChannel) result.getResult();
+                            if (Check.isNull(usedchannel)) {
                                 log.info("(组级)账户:{},{}", accountId, result.getMessage());
                                 continue;
                             } else {
-                                log.info("(组级)获取到渠道号:{}", channel.getChannelCode());
+                                log.info("(组级)获取到渠道号:{}", usedchannel.getChannelCode());
                             }
                         } else {
                             log.error("(组级)通过账户(" + accountId + ")未获取到渠道号!!!");
@@ -711,8 +752,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 }
 
                 //创建组
-                String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, channel);
-                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, channel);
+                String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, usedchannel);
+                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, usedchannel);
                 log.info("创建广告组入参:{}", unitParams);
                 Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                 Integer unitCode = (Integer) unitCreateResult.get("code");
@@ -732,8 +773,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 if (unitCode != 0) {
                     log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                    if (!Check.isNull(channel)) {
-                        channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null,0);
+                    if (!Check.isNull(usedchannel)) {
+                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
                     }
                     return;
                 }
@@ -741,9 +782,9 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitLevelOperationRecord.setUnitId(unitId);
                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                 if (!Check.isNull(channel)) {
-                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId,1);
+                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId, 1);
                 }
-                JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null, channel);
+                JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null, usedchannel);
                 createProgramCreative(token, creativeParams, strategy);
             }
         }
@@ -1090,8 +1131,10 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             aiKuaishouCampaignLevelOperationRecordService.saveOrUpdate(record);
             return null;
         }
-
         campaignId = (Long) campaignCreateResult.get("campaignId");
+        if (!Check.isNull(channel)) {
+            channelService.callBackUpdateChannelRel("plan", channel.getChannelCode(), token.getAccountId(), campaignId, null, 1);
+        }
         record.setCampaignId(campaignId);
         aiKuaishouCampaignLevelOperationRecordService.saveOrUpdate(record);
         Integer campaignStatus = strategy.getCampaignStatus();

+ 3 - 3
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/controller/KuaishouChannelController.java

@@ -258,12 +258,12 @@ public class KuaishouChannelController {
      * 通过账户查询渠道号接口
      */
     @PostMapping(value = "/queryChannel")
-    public Result<Object> queryChannel(Long accountId, String usageLevel,String appName) {
+    public Result<Object> queryChannel(Long accountId, String usageLevel, String appName, String photoName) {
         try {
-            if (Check.isNull(accountId) || Check.isNull(usageLevel)|| Check.isNull(appName)) {
+            if (Check.isNull(accountId) || Check.isNull(usageLevel) || Check.isNull(appName)) {
                 return Result.error("缺失参数");
             }
-            return kuaishouChannelService.queryChannel(accountId, usageLevel,appName);
+            return kuaishouChannelService.queryChannel(accountId, usageLevel, appName, photoName);
         } catch (Exception e) {
             e.printStackTrace();
             log.error("通过账户查询渠道号异常", e);

+ 3 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/mapper/KuaishouChannelMapper.java

@@ -32,7 +32,7 @@ public interface KuaishouChannelMapper extends BaseMapper<KuaishouChannel> {
 
     List<KuaishouChannel> queryFollowOrder(@Param("accountId") Long accountId, @Param("usedId") Long usedId, @Param("usageRange") Integer usageRange);
 
-    KuaishouChannel queryByAccountId(@Param("accountId") Long accountId);
+    KuaishouChannel queryByAccountId(@Param("accountId") Long accountId, @Param("isHaveItem") Integer isHaveItem);
 
     List<KuaishouChannel> queryMaxChannelNumber(@Param("strategyId") Long strategyId);
 
@@ -45,4 +45,6 @@ public interface KuaishouChannelMapper extends BaseMapper<KuaishouChannel> {
     List<KuaishouChannel> queryChannelByHaveCycleTimes(@Param("haveCycleTimes") Integer haveCycleTimes, @Param("usageLevel") String usageLevel, @Param("strategys") List<KuaishouChannelCreateStrategy> strategys);
 
     List<JSONObject> queryItemsListByAccountId(@Param("accountId") Long accountId, @Param("appName") String appName);
+
+    KuaishouChannel queryUsedChannel(@Param("accountId") Long accountId, @Param("campaignId") Long campaignId, @Param("level") String level);
 }

+ 48 - 38
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/mapper/xml/KuaishouChannelMapper.xml

@@ -17,7 +17,7 @@
         LEFT JOIN sys_user t2 ON t1.user_id = t2.id
         where account_id is not null
         <if test="userId != null">
-        and t1.user_id = #{userId}
+            and t1.user_id = #{userId}
         </if>
         <if test="projectId != null">
             and project_id = #{projectId}
@@ -116,25 +116,18 @@
     </select>
 
     <select id="channelNumberUsageDetailsList" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT
-            CASE
-                t1.usage_range
-                WHEN 1 THEN
-                    '账户'
-                WHEN 2 THEN
-                    '项目' ELSE ''
-                END AS 'usageRange',
-            IFNULL( t3.channel_code, '' ) AS 'channelCode',
-            IFNULL( t1.project_name, '' ) AS 'projectName',
-            IFNULL( t2.auth_name, '' ) AS 'authName',
-            IFNULL( t3.account_id, '' ) AS 'accountId',
-            IFNULL( t3.campaign_id, '' ) AS 'campaignId',
-            IFNULL( t3.unit_id, '' ) AS 'unitId'
-        FROM
-            ctop_kuaishou_channel_rel t3
-                INNER JOIN ctop_kuaishou_channel t1 ON t1.account_id = t3.account_id
-                AND t1.channel_code = t3.channel_code
-                LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        SELECT CASE
+                   t1.usage_range
+                   WHEN 1 THEN
+                       '账户'
+                   WHEN 2 THEN
+                       '项目'
+                   ELSE ''
+                   END AS 'usageRange', IFNULL(t3.channel_code, '') AS 'channelCode', IFNULL(t1.project_name, '') AS 'projectName', IFNULL(t2.auth_name, '') AS 'authName', IFNULL(t3.account_id, '') AS 'accountId', IFNULL(t3.campaign_id, '') AS 'campaignId', IFNULL(t3.unit_id, '') AS 'unitId'
+        FROM ctop_kuaishou_channel_rel t3
+                 INNER JOIN ctop_kuaishou_channel t1 ON t1.account_id = t3.account_id
+            AND t1.channel_code = t3.channel_code
+                 LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
         WHERE t3.account_id = #{accountId}
           AND t3.channel_code = #{channelCode}
           AND t3.unit_id is not null
@@ -174,12 +167,16 @@
 
     <select id="queryByAccountId" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel">
         SELECT id,
-               channel_code,
-               usage_level,
-               usage_range,
-               is_have_item
+        channel_code,
+        usage_level,
+        usage_range,
+        is_have_item
         FROM `ctop_kuaishou_channel`
         WHERE account_id = #{accountId}
+        AND state = 1
+        <if test="isHaveItem != null">
+            and is_have_item = #{isHaveItem}
+        </if>
         ORDER BY usage_range limit 1
     </select>
 
@@ -237,7 +234,7 @@
         AND state = 1
         and usage_level = #{usageLevel}
         and channel_lock = 1
-        ORDER BY usage_times
+        ORDER BY usage_times,is_have_item Desc
     </select>
 
 
@@ -254,19 +251,32 @@
     </select>
 
     <select id="queryItemsListByAccountId" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT
-            tt2.item_name as 'itemName',
-            tt1.channel_code as 'channelCode',
-            tt4.app_name as 'appName'
-        FROM
-            ctop_kuaishou_channel_rel tt1
-                INNER JOIN ( SELECT t3.item_name, t1.channel_code FROM ctop_kuaishou_channel t1 INNER JOIN ctop_kuaishou_channel_items_rel t2 ON t1.id = t2.channel_id LEFT JOIN ctop_kuaishou_channel_items t3 ON t2.item_id = t3.id WHERE t1.is_have_item = 1 AND t3.item_name IS NOT NULL ) tt2 ON tt2.channel_code = tt1.channel_code
-                INNER JOIN ctop_kuaishou_channel_app_info tt4 ON tt1.app_id = tt4.app_id
-        WHERE
-            tt1.account_id = #{accountId}
-          AND tt4.app_name = #{appName}
-        GROUP BY
-            tt2.item_name
+        SELECT tt2.keyword as 'keyword', tt1.channel_code as 'channelCode', tt3.app_name as 'appName'
+        FROM ctop_kuaishou_channel_rel tt1
+                 INNER JOIN (
+            SELECT t3.keyword, t1.channel_code
+            FROM ctop_kuaishou_channel t1
+                     INNER JOIN ctop_kuaishou_channel_items_rel t2 ON t1.id = t2.channel_id
+                     LEFT JOIN ctop_kuaishou_channel_items t3 ON t2.item_id = t3.id
+            WHERE t1.is_have_item = 1
+              AND t3.state = 1
+        ) tt2 ON tt2.channel_code = tt1.channel_code
+                 INNER JOIN ctop_kuaishou_channel_app_info tt3 ON tt1.app_id = tt3.app_id
+        WHERE tt1.account_id = #{accountId}
+          AND tt3.app_name = #{appName}
+        GROUP BY tt2.keyword
+    </select>
+
+
+    <select id="queryUsedChannel" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel">
+        SELECT t2.*
+        FROM ctop_kuaishou_channel_rel t1
+                 INNER JOIN ctop_kuaishou_channel t2
+                            ON t1.account_id = t2.account_id AND t1.channel_code = t2.channel_code
+        WHERE t2.account_id = #{accountId}
+          AND t2.usage_level = #{level}
+          AND t2.state = 1
+          AND t1.campaign_id = #{campaignId} LIMIT 1
     </select>
 
 </mapper>

+ 1 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/IKuaishouChannelRelService.java

@@ -12,7 +12,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IKuaishouChannelRelService extends IService<KuaishouChannelRel> {
 
-    KuaishouChannelRel queryByAccountChannelCode(String channelCode, Long accountId,String appName);
+    KuaishouChannelRel queryByAccountChannelCode(String channelCode, Long accountId, String appName);
 
     Integer queryUsePlanCount(Long accountId, String channelCode);
 

+ 4 - 2
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/IKuaishouChannelService.java

@@ -30,9 +30,11 @@ public interface IKuaishouChannelService extends IService<KuaishouChannel> {
 
     Result<Object> customizedCreate(JSONObject request, Integer createType) throws Exception;
 
-    Result<Object> queryChannel(Long accountId, String usageLevel,String appName) throws Exception;
+    Result<Object> queryChannel(Long accountId, String usageLevel, String appName, String photoName) throws Exception;
 
     Result<Object> queryChannelLevel(JSONObject request);
 
-    void callBackUpdateChannelRel(String level, String channelCode, Long accoountId, Long planId, Long groupId,Integer state);
+    void callBackUpdateChannelRel(String level, String channelCode, Long accoountId, Long planId, Long groupId, Integer state);
+
+    KuaishouChannel queryUsedChannel(Long accountId, Long newCampaignId, String level);
 }

+ 3 - 3
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/impl/KuaishouChannelRelServiceImpl.java

@@ -20,17 +20,17 @@ public class KuaishouChannelRelServiceImpl extends ServiceImpl<KuaishouChannelRe
     private KuaishouChannelRelMapper channelRelMapper;
 
     @Override
-    public KuaishouChannelRel queryByAccountChannelCode(String channelCode, Long accountId,String appName) {
+    public KuaishouChannelRel queryByAccountChannelCode(String channelCode, Long accountId, String appName) {
         return channelRelMapper.queryByAccountChannelCode(channelCode, accountId, appName);
     }
 
     @Override
     public Integer queryUsePlanCount(Long accountId, String channelCode) {
-        return channelRelMapper.queryUsePlanCount(accountId,  channelCode);
+        return channelRelMapper.queryUsePlanCount(accountId, channelCode);
     }
 
     @Override
     public Integer queryUseGroupCount(Long accountId, String channelCode) {
-        return channelRelMapper.queryUseGroupCount(accountId,  channelCode);
+        return channelRelMapper.queryUseGroupCount(accountId, channelCode);
     }
 }

+ 67 - 26
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/impl/KuaishouChannelServiceImpl.java

@@ -56,6 +56,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -152,7 +153,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         List<JSONObject> list = channelMapper.channelNumberUsageDetailsList(kuaishouChannel);
         for (JSONObject jsonObject : list) {
             String time = kuaiShouCreativeService.querMaxCreateTime(jsonObject.getLong("unitId"));
-            jsonObject.put("createTime",time);
+            jsonObject.put("createTime", time);
         }
         PageInfo pageInfo = new PageInfo(list);
         pageInfo.setTotal(total);
@@ -248,7 +249,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                                     Long accountId = accountList.get(length);
                                     if (!Check.isNull(accountId)) {
                                         //获取token
-                                        CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
+                                        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
                                         //获取应用图片token
                                         JSONObject tokenJson = appInfoService.uploadAppIconImage(strategy.getAppIconUrl(), token.getAccountId(), token.getAccessToken());
                                         if (!Check.isNull(tokenJson) && tokenJson.getInteger("code") != 0) {
@@ -272,7 +273,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                                         Long accountId = accountList.get(length);
                                         if (!Check.isNull(accountId)) {
                                             //获取token
-                                            CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
+                                            CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
                                             //获取应用图片token
                                             JSONObject tokenJson = appInfoService.uploadAppIconImage(strategy.getAppIconUrl(), token.getAccountId(), token.getAccessToken());
                                             if (!Check.isNull(tokenJson) && tokenJson.getInteger("code") != 0) {
@@ -307,7 +308,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                                                 Long accountId = accountSubList.get(k);
                                                 if (!Check.isNull(accountId)) {
                                                     //获取token
-                                                    CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
+                                                    CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
                                                     //获取应用图片token
                                                     JSONObject tokenJson = appInfoService.uploadAppIconImage(strategy.getAppIconUrl(), token.getAccountId(), token.getAccessToken());
                                                     if (!Check.isNull(tokenJson) && tokenJson.getInteger("code") != 0) {
@@ -374,8 +375,8 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                     log.error("通过账户ID(" + token.getAccountId() + ")获取图片Token失败,返回信息:" + tokenJson.getString("message"));
                 }
                 //使用范围是账户时,查询旧app来做匹配
-                kuaishouInterfaceService.getAppList(strategy.getAccountId(), token.getAccessToken());
-                List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(strategy.getAccountId());
+                kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
+                List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(token.getAccountId());
                 strategy.setImageToken(tokenJson.getString("imageToken"));
                 if (url.contains(CHANNEL_STR)) {
                     ilist.forEach(i -> executorService.submit(() -> {
@@ -504,7 +505,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         channelAppInfo.setImageToken(String.valueOf(app.getImageToken()));
         JSONObject requestJson = new JSONObject();
         requestJson.put("app_id", app.getAppId());
-        requestJson.put("advertiser_id", strategy.getAccountId());
+        requestJson.put("advertiser_id", token.getAccountId());
         requestJson.put("app_version", strategy.getAppVersion());
         requestJson.put("app_privacy_url", strategy.getAppPrivacyUrl());
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.APP_UPDATE;
@@ -544,7 +545,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         if (!Check.isNull(token)) {
             String accessToken = token.getAccessToken();
             JSONObject requestJson = new JSONObject();
-            requestJson.put("advertiser_id", strategy.getAccountId());
+            requestJson.put("advertiser_id", token.getAccountId());
             requestJson.put("app_version", strategy.getAppVersion());
             requestJson.put("app_name", strategy.getAppName());
             requestJson.put("image_token", strategy.getImageToken());
@@ -792,7 +793,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                 obj.put("clickTrackUrl", clickTrackUrl);
                 obj.put("isHaveItem", isHaveItem);
                 obj.put("itemName", itemName);
-                obj.put("usageLevel", usageLevel);
+                obj.put("usageLevel", usageLevel.toLowerCase());
                 obj.put("isCycle", isCycleTimes);
                 obj.put("cycleTimes", cycleTimes);
                 obj.put("schemaUri", schemaUri);
@@ -882,7 +883,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                             /**-----------------项目维度:循环次数 大于 项目下账户总数-----------------*/
                             for (Long accountId : accountList) {
                                 //获取token
-                                CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
+                                CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
                                 //获取应用图片token
                                 JSONObject tokenJson = appInfoService.uploadAppIconImage(strategy.getAppIconUrl(), token.getAccountId(), token.getAccessToken());
                                 if (!Check.isNull(tokenJson) && tokenJson.getInteger("code") != 0) {
@@ -897,6 +898,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                             List<List<Long>> accountSubLists = Lists.partition(accountList, cycleTimes);
                             List<Long> list = accountSubLists.get(0);
                             for (int i = 0; i < list.size(); i++) {
+                                strategy.setAccountId(list.get(i));
                                 //获取token
                                 CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
                                 //获取应用图片token
@@ -905,7 +907,6 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                                     log.error("通过账户ID(" + token.getAccountId() + ")获取图片Token失败,返回信息:" + tokenJson.getString("message"));
                                 }
                                 strategy.setImageToken(tokenJson.getString("imageToken"));
-                                strategy.setAccountId(list.get(i));
                                 createApp(strategy, token, null);
                                 createChannel(strategy, 0, i + 1);
                             }
@@ -921,7 +922,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                                 log.error("通过账户ID(" + token.getAccountId() + ")获取图片Token失败,返回信息:" + tokenJson.getString("message"));
                             }
                             //使用范围是账户时,查询旧app来做匹配
-                            kuaishouInterfaceService.getAppList(strategy.getAccountId(), token.getAccessToken());
+                            kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
                             List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(accountId);
                             strategy.setImageToken(tokenJson.getString("imageToken"));
                             strategy.setAccountId(accountId);
@@ -943,8 +944,8 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                         log.error("通过账户ID(" + token.getAccountId() + ")获取图片Token失败,返回信息:" + tokenJson.getString("message"));
                     }
                     //使用范围是账户时,查询旧app来做匹配
-                    kuaishouInterfaceService.getAppList(strategy.getAccountId(), token.getAccessToken());
-                    List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(strategy.getAccountId());
+                    kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
+                    List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(token.getAccountId());
                     strategy.setImageToken(tokenJson.getString("imageToken"));
                     try {
                         createApp(strategy, token, oldAppList);
@@ -962,7 +963,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
     }
 
     @Override
-    public Result<Object> queryChannel(Long accountId, String level, String appName) throws Exception {
+    public Result<Object> queryChannel(Long accountId, String level, String appName, String photoName) throws Exception {
         //查询账户策略
         List<KuaishouChannelCreateStrategy> strategys = channelCreateStrategyService.queryChannelStrategyByAccountId(accountId);
         if (Check.isNull(strategys) || strategys.isEmpty()) {
@@ -989,7 +990,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                 return doPlanLevel(accountId, strategys, appName, 0);
             } else if ("group".equals(usageLevel)) {
                 //---------------------组层级---------------------
-                return doGroupLevel(accountId, strategys, appName, 0);
+                return doGroupLevel(accountId, strategys, appName, 0, photoName);
             }
         } else {
             /**============================项目范围============================*/
@@ -1001,7 +1002,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                 return doPlanLevel(accountId, strategys, appName, 0);
             } else if ("group".equals(usageLevel)) {
                 //---------------------组层级---------------------
-                return doGroupLevel(accountId, strategys, appName, 0);
+                return doGroupLevel(accountId, strategys, appName, 0, photoName);
             }
         }
         return Result.error("未查到渠道号");
@@ -1012,14 +1013,15 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         Long accountId = data.getLong("accountId");
         JSONArray appNameArray = data.getJSONArray("appNameArray");
         String appName = appNameArray.getString(0);
-        KuaishouChannel channel = channelMapper.queryByAccountId(accountId);
-        if (Check.isNull(channel)) {
-            return Result.ok("没有渠道号");
-        }
+        KuaishouChannel channel = channelMapper.queryByAccountId(accountId, 1);
         JSONObject request = new JSONObject();
-        if (channel.getIsHaveItem() == 1) {
-            List<JSONObject> list = channelMapper.queryItemsListByAccountId(accountId, appName);
-            request.put("list", list);
+        if (!Check.isNull(channel)) {
+            request.put("list", channelMapper.queryItemsListByAccountId(accountId, appName));
+        } else {
+            channel = channelMapper.queryByAccountId(accountId, null);
+            if (Check.isNull(channel)) {
+                return Result.error("该账户没有配置渠道号");
+            }
         }
         request.put("channel", channel);
         return Result.ok(request);
@@ -1068,10 +1070,30 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         }
     }
 
+    @Override
+    public KuaishouChannel queryUsedChannel(Long accountId, Long newCampaignId, String level) {
+        KuaishouChannel channel = channelMapper.queryUsedChannel(accountId, newCampaignId, level);
+        if (!Check.isNull(channel) && channel.getIsHaveItem() == 1) {
+            List<KuaishouChannelItems> list = channelItemsRelService.queryItems(channel.getId());
+            if (Check.isNull(list) || list.isEmpty()) {
+                return null;
+            }
+            channel.setItems(list);
+        }
+        return channel;
+    }
+
     private Result<Object> doAccountRangeAccountLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName) throws Exception {
         List<KuaishouChannel> channelList = channelMapper.queryByAccountIdLevel(accountId, "account");
         if (!Check.isNull(channelList)) {
             for (KuaishouChannel channel : channelList) {
+                if (channel.getIsHaveItem() == 1) {
+                    List<KuaishouChannelItems> list = channelItemsRelService.queryItems(channel.getId());
+                    if (Check.isNull(list) || list.isEmpty()) {
+                        continue;
+                    }
+                    channel.setItems(list);
+                }
                 KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
                 if (Check.isNull(channelRel)) {
                     continue;
@@ -1112,6 +1134,13 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                 Integer usageTimes = channel.getUsageTimes();//使用次数
                 //优先判断已经循环的次数 大于 使用次数
                 if (haveCycleTimes > usageTimes) {
+                    if (channel.getIsHaveItem() == 1) {
+                        List<KuaishouChannelItems> items = channelItemsRelService.queryItems(channel.getId());
+                        if (Check.isNull(items) || items.isEmpty()) {
+                            continue;
+                        }
+                        channel.setItems(items);
+                    }
                     // 符合条件,获取该渠道号
                     KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
                     if (Check.isNull(channelRel)) {
@@ -1153,7 +1182,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
     }
 
     //通过项目范围广告组层级查询
-    private Result<Object> doGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName, int count) throws Exception {
+    private Result<Object> doGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName, int count, String photoName) throws Exception {
         List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
         if (Check.isNull(haveCycleTimesList)) {
             return Result.error("渠道号已无效");
@@ -1169,6 +1198,18 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                 Integer usageTimes = channel.getUsageTimes();//使用次数
                 //优先判断已经循环的次数 大于 使用次数
                 if (haveCycleTimes > usageTimes) {
+                    if (!Check.isNull(channel.getIsHaveItem()) && channel.getIsHaveItem() == 1) {
+                        //有单品
+                        List<KuaishouChannelItems> itemsList = channelItemsRelService.queryItems(channel.getId());
+                        if (Check.isNull(itemsList) || itemsList.isEmpty()) {
+                            continue;
+                        }
+                        //素材名字和单品关键字做匹配
+                        String keyword = itemsList.get(0).getKeyword();
+                        if (!photoName.contains(keyword)) {
+                            continue;
+                        }
+                    }
                     // 符合条件,获取该渠道号
                     KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
                     if (Check.isNull(channelRel)) {
@@ -1204,7 +1245,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
             }
         }
         if (count == 0) {
-            return doGroupLevel(accountId, strategys, appName, 1);
+            return doGroupLevel(accountId, strategys, appName, 1, photoName);
         }
         return Result.ok("未查询到渠道号");
     }