|
@@ -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;
|
|
|
}
|
|
|
|
|
|
/**
|