|
@@ -10,9 +10,14 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.bytedance.advertise.entity.ByteDanceCreativeWordPackage;
|
|
|
import org.jeecg.modules.bytedance.advertise.entity.ByteDanceGeneralCopywriter;
|
|
|
import org.jeecg.modules.bytedance.advertise.service.IByteDanceGeneralCopywriterService;
|
|
|
+import org.jeecg.modules.bytedance.advertise.service.impl.ByteDanceGeneralCopywriterServiceImpl;
|
|
|
+import org.jeecg.modules.bytedance.common.utils.Check;
|
|
|
import org.jeecg.modules.bytedance.common.utils.ExcelUtil;
|
|
|
+import org.jeecg.modules.bytedance.common.utils.StringUtils;
|
|
|
+import org.jeecg.modules.system.service.ISysRoleService;
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
@@ -28,8 +33,12 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
/**
|
|
|
* 头条通用文案上传接口
|
|
|
* @author jeecg-boot
|
|
@@ -43,6 +52,15 @@ import java.util.*;
|
|
|
public class BytedanceGeneralCopywriterController {
|
|
|
@Autowired
|
|
|
private IByteDanceGeneralCopywriterService byteDanceGeneralCopywriterService;
|
|
|
+ @Autowired
|
|
|
+ private ISysRoleService sysRoleService;
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String str = "测试创意反射,这么玩,你的视觉效果就是这么神奇!{地点}";
|
|
|
+
|
|
|
+ System.out.println(StringUtils.lengthAsSlogan(str));
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
@ApiOperation(value="通用文案库-上传excel", notes="通用文案库-上传excel")
|
|
|
@PostMapping("/loadExcel")
|
|
@@ -50,27 +68,43 @@ public class BytedanceGeneralCopywriterController {
|
|
|
@RequestParam("accountId") Long accountId,
|
|
|
@RequestParam("excelFile") MultipartFile excelFile){
|
|
|
Result<ByteDanceGeneralCopywriter> result = new Result<>();
|
|
|
+ List<ByteDanceGeneralCopywriter> byteDanceGeneralCopywriterList = new ArrayList<ByteDanceGeneralCopywriter>();
|
|
|
try {
|
|
|
List<String> list = ExcelUtil.readExcel(excelFile);
|
|
|
- //去掉null值
|
|
|
- list.removeIf(Objects::isNull);
|
|
|
- //去掉空字符串
|
|
|
- Iterator<String> iterator = list.iterator();
|
|
|
- while (iterator.hasNext()){
|
|
|
- if (iterator.next() == ""){
|
|
|
- iterator.remove();
|
|
|
+
|
|
|
+ for (String str: list) {
|
|
|
+ ByteDanceGeneralCopywriter byteDanceGeneralCopywriter = new ByteDanceGeneralCopywriter(accountId,str);
|
|
|
+ int len = StringUtils.lengthAsSlogan(str);
|
|
|
+ int left = str.indexOf("{");
|
|
|
+ int right = str.indexOf("}");
|
|
|
+ if(left >= 0 && right >= 0){
|
|
|
+ List<String> strs = new ArrayList<>();
|
|
|
+ ByteDanceCreativeWordPackage creativeWordPackage = byteDanceGeneralCopywriterService.selectCreativeWordPackageByName(str.substring(left+1, right));
|
|
|
+ strs.add(creativeWordPackage.getCreativeWordId().toString());
|
|
|
+ len = len - (right - left) + creativeWordPackage.getMaxWordLen();
|
|
|
+ String nextStr = str.substring(right+1,str.length());
|
|
|
+ left = nextStr.indexOf("{");
|
|
|
+ right = nextStr.indexOf("}");
|
|
|
+ if(left >= 0 && right >= 0){
|
|
|
+ ByteDanceCreativeWordPackage creativeWordPackage2 = byteDanceGeneralCopywriterService.selectCreativeWordPackageByName(nextStr.substring(left+1, right));
|
|
|
+ strs.add(creativeWordPackage2.getCreativeWordId().toString());
|
|
|
+ len = len - (right - left) + creativeWordPackage2.getMaxWordLen();
|
|
|
+ }
|
|
|
+ byteDanceGeneralCopywriter.setCreativeWordIds(Arrays.toString(strs.toArray()).replaceAll(" ",""));
|
|
|
+ }
|
|
|
+ //校验标题长度,长度小于5和大于30的全部过滤
|
|
|
+ if(len<5 || len>30){
|
|
|
+ continue;
|
|
|
}
|
|
|
- }
|
|
|
- List<ByteDanceGeneralCopywriter> byteDanceGeneralCopywriterList = new ArrayList<ByteDanceGeneralCopywriter>();
|
|
|
|
|
|
- //遍历list,查看数据
|
|
|
- for (String textCopywriter : list) {
|
|
|
- byteDanceGeneralCopywriterList.add(new ByteDanceGeneralCopywriter(accountId,textCopywriter));
|
|
|
+ //截取{}中的内容,匹配动态词包id,拼接数组存储
|
|
|
+ byteDanceGeneralCopywriterList.add(byteDanceGeneralCopywriter);
|
|
|
}
|
|
|
|
|
|
- byteDanceGeneralCopywriterService.saveBatch(byteDanceGeneralCopywriterList);
|
|
|
- result.success("添加成功!");
|
|
|
|
|
|
+ byteDanceGeneralCopywriterService.saveBatch(byteDanceGeneralCopywriterList);
|
|
|
+ result.success("添加成功"+byteDanceGeneralCopywriterList.size()+"条"+",失败"+(list.size() - byteDanceGeneralCopywriterList.size())+"条");
|
|
|
+ result.setCode(0);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
result.error500("操作失败");
|
|
@@ -104,7 +138,9 @@ public class BytedanceGeneralCopywriterController {
|
|
|
|
|
|
@ApiOperation(value="通用文案报表展示", notes="通用文案报表展示")
|
|
|
@GetMapping(value = "/queryPageListByText")
|
|
|
- public Result queryPageListByText(@RequestParam("accountId") String accountId,
|
|
|
+ public Result queryPageListByText(
|
|
|
+ @RequestParam(value = "userId",defaultValue = "") String userId,
|
|
|
+ @RequestParam(value = "accountId",defaultValue = "") String accountId,
|
|
|
@RequestParam(value = "keyWord",defaultValue = "") String keyWord,
|
|
|
@RequestParam(value = "startTime",defaultValue = "") String startTime,
|
|
|
@RequestParam(value = "endTime",defaultValue = "") String endTime,
|
|
@@ -112,7 +148,18 @@ public class BytedanceGeneralCopywriterController {
|
|
|
@RequestParam(value = "pageSize", defaultValue="10") Integer pageSize
|
|
|
) {
|
|
|
try {
|
|
|
- return byteDanceGeneralCopywriterService.getGeneralCopywriterReport(accountId,keyWord, startTime,endTime,pageNo,pageSize);
|
|
|
+
|
|
|
+ //查询用户角色
|
|
|
+ String roleCode = sysRoleService.getRoleCodeByUserId(userId);
|
|
|
+ if (Check.isNull(roleCode)){
|
|
|
+ return Result.errorMsg("请输入正确的用户id。");
|
|
|
+ }
|
|
|
+ //角色为 管理员 || 销售 || 媒介 查询全部
|
|
|
+ if ("admin".equals(roleCode) || roleCode.contains("sale") || "meidaManager".equals(roleCode)) {
|
|
|
+ userId = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return byteDanceGeneralCopywriterService.getGeneralCopywriterReport(userId,accountId,keyWord, startTime,endTime,pageNo,pageSize);
|
|
|
}catch (Exception e){
|
|
|
log.error("通用文案数据-获取文案维度创意报表数据异常",e);
|
|
|
return Result.error("请求失败,请联系开发人员!");
|