Explorar o código

增加插入文案之前的解析动态词包和校验,以及视频listV2支持下线筛选

huangxuechao %!s(int64=4) %!d(string=hai) anos
pai
achega
12d9070fe2

+ 61 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialInfoController.java

@@ -6,7 +6,9 @@ import cn.com.ctop.common.module.entity.*;
 import cn.com.ctop.common.module.enums.MaterialSupplierEnum;
 import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.*;
+import cn.com.ctop.toutiao.modules.material.entity.ByteDanceCreativeWordPackage;
 import cn.com.ctop.toutiao.modules.material.entity.BytedanceVideoSlogenInfo;
+import cn.com.ctop.toutiao.modules.material.service.IByteDanceCreativeWordPackageService;
 import cn.com.ctop.toutiao.modules.material.service.IBytedanceVideoSlogenInfoService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -31,6 +33,8 @@ import javax.servlet.http.HttpServletRequest;
 import java.net.URLDecoder;
 import java.text.ParseException;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * 素材信息
@@ -74,7 +78,8 @@ public class MaterialInfoController {
     private IProductService productService;
     @Autowired
     private IProjectService projectService;
-
+    @Autowired
+    private IByteDanceCreativeWordPackageService byteDanceGeneralCopywriterService;
 
     @GetMapping("/supplierWatermark")
     public Result<String> supplierWatermark(String id) {
@@ -513,6 +518,57 @@ public class MaterialInfoController {
         if (!Check.isNull(materialInfo.getSlogans())) {
             JSONArray slogans = materialInfo.getSlogans();
             if (null != slogans && !slogans.isEmpty()) {
+
+
+                for (int i = 0;i<slogans.size();i++) {
+                    JSONObject slogenInfo = slogans.getJSONObject(i);
+                    String title = slogenInfo.getString("title");
+                    title = title.trim().replaceAll("[\\{]{2,}","{");
+                    title = title.trim().replaceAll("[\\}]{2,}","}");
+                    slogenInfo.put("title",title);
+                    String reg = "\\{[\\u4e00-\\u9fa5\\-]{2,6}\\}";
+                    Pattern pattern = Pattern.compile(reg);
+                    Matcher matcher = pattern.matcher(title);
+                    JSONArray creativeWordIdsArray = new JSONArray();
+
+                    int len = StringUtils.lengthAsSlogan(title);
+                    int left = title.indexOf("{");
+                    int right = title.indexOf("}");
+                    if(left >= 0 && right >= 0){
+                        int times = 0;
+                        while (matcher.find()) { //此处find()每次被调用后,会偏移到下一个匹配
+                            times++;
+                            if(times>=3){
+                                result.setCode(500);
+                                result.setMessage("动态词包不合法,词包数量超过2个");
+                                return  result;
+                            }
+                            String matchStr = matcher.group();//获取当前匹配的值
+                            title = title.replace(matchStr,"");
+                            ByteDanceCreativeWordPackage creativeWordPackage = byteDanceGeneralCopywriterService.selectCreativeWordPackageByName(matchStr.substring(1,matchStr.length()-1));
+                            if(Check.isNull(creativeWordPackage)){
+                                result.setCode(500);
+                                result.setMessage("动态词包不合法,词包不存在或者含有单独的非词包大括号");
+                                return  result;
+                            }
+                            creativeWordIdsArray.add(creativeWordPackage.getCreativeWordId());
+                            len = len - (right - left) + creativeWordPackage.getMaxWordLen();
+                            left = title.indexOf("{");
+                            right = title.indexOf("}");
+                        }
+                        if(title.contains("{") || title.contains("}")){
+                            return result.error500("大括号单独出现或大括号中内容不合法");
+                        }
+                        slogenInfo.put("creative_word_ids",creativeWordIdsArray.toJSONString());
+                    }
+                    //校验标题长度,长度小于5和大于30的全部过滤
+                    if(len<5 || len>30){
+                        result.setCode(500);
+                        result.setMessage("文案长度不合法,小于5或大于30");
+                        return  result;
+                    }
+                }
+
                 LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
                 slogenInfoService.insertSlogans(materialInfo.getProjectId(), materialInfoEntity.getCode(), slogans, user.getId());
             }
@@ -545,6 +601,7 @@ public class MaterialInfoController {
                 sendMessageService.sendMessage(userId, text);
             }
         }
+        result.setCode(0);
         return result;
 
     }
@@ -567,7 +624,9 @@ public class MaterialInfoController {
                 successNum++;
             }
         }
-        return result.success("批量修改成功" + successNum + "个");
+        result.setCode(0);
+        result.setMessage("批量修改成功" + successNum + "个");
+        return result;
 
     }
 

+ 5 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/MaterialInfo.java

@@ -193,4 +193,9 @@ public class MaterialInfo implements Serializable {
     //视频关联广告语信息--头条
     @TableField(exist = false)
     private JSONArray slogans;
+
+    @TableField(exist = false)
+    private Integer slogansCount;
+
+    private Integer offlineFlag;
 }

+ 15 - 1
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/MaterialInfoMapper.xml

@@ -90,8 +90,22 @@
         select
         distinct matInfo.code,
         matInfo.project_id,
-        matInfo.id
+        matInfo.id,
+        t.slogansCount,
+        matInfo.offline_flag
         from ctop_material_info matInfo
+        inner JOIN (
+            SELECT
+                video_code,
+                count(*) AS slogansCount
+            FROM
+                ctop_bytedance_video_slogen_info
+            WHERE
+                status = 1
+            GROUP BY
+                video_code
+        ) t ON matInfo.code = t.video_code
+
         <if test="tagCode!=null">
             left join ctop_material_tag_info tagInfo on tagInfo.code = matInfo.code
         </if>

+ 10 - 3
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialInfoServiceImpl.java

@@ -38,7 +38,6 @@ import java.util.concurrent.Executors;
 
 import static cn.com.ctop.common.module.utils.CloudVideoProcessUtil.getTaskDetailResponse;
 import static cn.com.ctop.common.module.utils.CloudVideoProcessUtil.videoWatermarkHandle;
-
 /**
  * 素材信息
  *
@@ -70,7 +69,6 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
     private ISupplierWatermarkService supplierWatermarkService;
     @Resource
     private IProductService productService;
-
     @Value("${oss.replace.download}")
     private String downloadUrl;
 
@@ -788,6 +786,8 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
         if (null != dailyList && !dailyList.isEmpty()) {
             for (MaterialInfo info : dailyList) {
                 MaterialInfo materialInfo = materialInfoMapper.selectById(info.getId());
+                materialInfo.setSlogansCount(info.getSlogansCount());
+                materialInfo.setOfflineFlag(info.getOfflineFlag());
                 //素材名称为空 则使用素材id 同步失败
                 materialInfo.setMaterialName(Check.isNull(materialInfo.getMaterialName()) ? materialInfo.getId() : materialInfo.getMaterialName());
                 //判断是否已经同步到快手平台
@@ -832,7 +832,13 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
                 } else {
                     materialInfo.setWhetherUnaudited(true);
                 }
-
+                //统计广告语数量
+//                List<BytedanceVideoSlogenInfo> slogenInfos = slogenInfoService.listByParams(materialInfo.getCode(), 1);
+//                JSONArray slogenArray = new JSONArray();
+//                if (null != slogenInfos && !slogenInfos.isEmpty()) {
+//                    slogenArray.addAll(slogenInfos);
+//                }
+//                materialInfo.setSlogans(slogenArray);
                 setList.add(materialInfo);
             }
         }
@@ -842,6 +848,7 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
         return result;
     }
 
+
     @Override
     public JSONArray getIdListByProject(Long projectId) {
         return materialInfoMapper.getIdListByProject(projectId);

+ 28 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/StringUtils.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.common.module.utils;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -118,4 +119,31 @@ public class StringUtils {
         }
         return dest;
     }
+
+    public static int lengthAsSlogan(String a)  {
+        char[] c = a.toCharArray();
+        int count=0;
+        for (char d : c) {
+            Character.UnicodeBlock ub = Character.UnicodeBlock.of(d);
+            if (ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
+                    || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
+                    || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
+                    || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS
+                    || ub == Character.UnicodeBlock.VERTICAL_FORMS
+                    || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
+                    || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
+                    || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
+                    || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_C
+                    || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_D
+                    || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
+                    || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT) {
+                count++;
+            }
+
+        }
+        BigDecimal strNum = new BigDecimal(count);
+        BigDecimal strlen = new BigDecimal(a.length());
+        BigDecimal res = strlen.subtract(strNum).divide(new BigDecimal(2),0, BigDecimal.ROUND_UP).add(strNum);
+        return res.intValue();
+    }
 }

+ 69 - 10
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/BytedanceVideoSlogenInfoController.java

@@ -1,8 +1,13 @@
 package cn.com.ctop.toutiao.modules.material.controller;
 
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.QueryGenerator;
+import cn.com.ctop.common.module.utils.StringUtils;
+import cn.com.ctop.toutiao.modules.material.entity.ByteDanceCreativeWordPackage;
 import cn.com.ctop.toutiao.modules.material.entity.BytedanceVideoSlogenInfo;
+import cn.com.ctop.toutiao.modules.material.service.IByteDanceCreativeWordPackageService;
 import cn.com.ctop.toutiao.modules.material.service.IBytedanceVideoSlogenInfoService;
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -17,6 +22,8 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * 头条视频文案信息
@@ -31,7 +38,8 @@ import java.util.Date;
 public class BytedanceVideoSlogenInfoController {
 	@Autowired
 	private IBytedanceVideoSlogenInfoService bytedanceVideoSlogenInfoService;
-
+	@Autowired
+	private IByteDanceCreativeWordPackageService byteDanceGeneralCopywriterService;
 	/**
 	  * 分页列表查询
 	 * @param slogenInfo
@@ -85,17 +93,68 @@ public class BytedanceVideoSlogenInfoController {
 	@PostMapping(value = "/edit")
 	public Result<BytedanceVideoSlogenInfo> edit(@RequestBody BytedanceVideoSlogenInfo slogenInfo) {
 		Result<BytedanceVideoSlogenInfo> result = new Result<>();
-		BytedanceVideoSlogenInfo bytedanceVideoSlogenInfoEntity = bytedanceVideoSlogenInfoService.getById(slogenInfo.getId());
-		if(bytedanceVideoSlogenInfoEntity==null) {
-			result.error500("未找到对应实体");
+		try{
+			BytedanceVideoSlogenInfo bytedanceVideoSlogenInfoEntity = bytedanceVideoSlogenInfoService.getById(slogenInfo.getId());
+			if(bytedanceVideoSlogenInfoEntity==null) {
+				result.error500("未找到对应实体");
+				return result;
+			}
+			LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+			slogenInfo.setUpdateBy(user.getId());
+			slogenInfo.setUpdateTime(new Date());
+
+			String title = slogenInfo.getSlogan();
+			title = title.trim().replaceAll("[\\{]{2,}", "{");
+			title = title.trim().replaceAll("[\\}]{2,}", "}");
+			slogenInfo.setSlogan(title);
+
+
+			String reg = "\\{[\\u4e00-\\u9fa5\\-]{2,6}\\}";
+			Pattern pattern = Pattern.compile(reg);
+			Matcher matcher = pattern.matcher(title);
+			JSONArray creativeWordIdsArray = new JSONArray();
+
+			int len = StringUtils.lengthAsSlogan(title);
+			int left = title.indexOf("{");
+			int right = title.indexOf("}");
+			if (left >= 0 && right >= 0) {
+				int times = 0;
+				while (matcher.find()) { //此处find()每次被调用后,会偏移到下一个匹配
+					times++;
+					if (times >= 3) {
+						result.error500("动态词包不合法,词包数量超过2个");
+						return result;
+					}
+					String matchStr = matcher.group();//获取当前匹配的值
+					title = title.replace(matchStr,"");
+					ByteDanceCreativeWordPackage creativeWordPackage = byteDanceGeneralCopywriterService.selectCreativeWordPackageByName(matchStr.substring(1, matchStr.length() - 1));
+					if (Check.isNull(creativeWordPackage)) {
+						return result.error500("动态词包不合法,词包不存在或者含有单独的非词包大括号");
+					}
+					creativeWordIdsArray.add(creativeWordPackage.getCreativeWordId());
+					len = len - (right - left) + creativeWordPackage.getMaxWordLen();
+					left = title.indexOf("{");
+					right = title.indexOf("}");
+				}
+				if(title.contains("{") || title.contains("}")){
+					return result.error500("大括号单独出现或大括号中内容不合法");
+				}
+				slogenInfo.setCreativeWordIds(creativeWordIdsArray.toJSONString());
+			}
+			//校验标题长度,长度小于5和大于30的全部过滤
+			if (len < 5 || len > 30) {
+				return result.error500("文案长度不合法,小于5或大于30");
+			}
+
+			bytedanceVideoSlogenInfoService.updateById(slogenInfo);
+			result.setCode(0);
+			result.setMessage("修改成功!");
+			return result;
+		} catch (Exception e) {
+			log.error(e.getMessage(),e);
+			result.error500("操作失败");
 			return result;
 		}
-		LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
-		slogenInfo.setUpdateBy(user.getId());
-		slogenInfo.setUpdateTime(new Date());
-		bytedanceVideoSlogenInfoService.updateById(slogenInfo);
-		result.success("修改成功!");
-		return result;
 	}
 
 	/**

+ 2 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/ByteDanceCreativeWordPackageMapper.java

@@ -15,4 +15,6 @@ import java.util.List;
  */
 public interface ByteDanceCreativeWordPackageMapper extends BaseMapper<ByteDanceCreativeWordPackage> {
     void replaceBatch(@Param(value = "creativeWordPackages") List<ByteDanceCreativeWordPackage> creativeWordPackages);
+
+    ByteDanceCreativeWordPackage selectCreativeWordPackageByName(String name);
 }

+ 5 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/xml/ByteDanceCreativeWordPackageMapper.xml

@@ -26,4 +26,9 @@
             )
         </foreach>
     </insert>
+
+    <select id="selectCreativeWordPackageByName" resultType="cn.com.ctop.toutiao.modules.material.entity.ByteDanceCreativeWordPackage">
+        select * from ctop_bytedance_creative_word_package where name = #{name}
+    </select>
+
 </mapper>

+ 1 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/IByteDanceCreativeWordPackageService.java

@@ -17,5 +17,5 @@ import java.util.Map;
  */
 public interface IByteDanceCreativeWordPackageService extends IService<ByteDanceCreativeWordPackage> {
     Map<String, Object> getCreativeWordPackage();
-
+    public ByteDanceCreativeWordPackage selectCreativeWordPackageByName(String name);
 }

+ 4 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceCreativeWordPackageServiceImpl.java

@@ -62,5 +62,8 @@ public class ByteDanceCreativeWordPackageServiceImpl extends ServiceImpl<ByteDan
             byteDanceCreativeWordPackageMapper.replaceBatch(resultList);
         }
     }
-
+    @Override
+    public ByteDanceCreativeWordPackage selectCreativeWordPackageByName(String name){
+        return byteDanceCreativeWordPackageMapper.selectCreativeWordPackageByName(name);
+    }
 }