| | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.util.*; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import opennlp.tools.dictionary.serializer.Entry; |
| | | import org.jeecg.modules.system.entity.SysUser; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.core.io.ByteArrayResource; |
| | | import org.springframework.http.*; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.http.client.SimpleClientHttpRequestFactory; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | private ICopywritingService copywritingService; |
| | | @Autowired |
| | | private ISemanticWordService semanticWordService;; |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | |
| | | /** |
| | | * 分页列表查询 |
| | |
| | | } |
| | | return Result.OK(pageList); |
| | | } |
| | | |
| | | |
| | | @Operation(summary="文案-查询发送门户文章总量") |
| | | @GetMapping(value = "/count") |
| | | public Result<IPage<Copywriting>> count(Copywriting copywriting, |
| | | @RequestParam(name="role", defaultValue="无") String role, |
| | | @RequestParam(name="user", defaultValue="无") String user, |
| | | HttpServletRequest req) { |
| | | |
| | | QueryWrapper<Copywriting> queryWrapper = QueryGenerator.initQueryWrapper(copywriting, req.getParameterMap()); |
| | | |
| | | if (StringUtils.isNotBlank(copywriting.getTitleLike())) { |
| | | queryWrapper.like("title", copywriting.getTitleLike()); |
| | | } |
| | | if (StringUtils.isNotBlank(copywriting.getTitleLike()) && StringUtils.isNotBlank(copywriting.getWordLike())) { |
| | | queryWrapper.or(); |
| | | } |
| | | if (StringUtils.isNotBlank(copywriting.getWordLike())){ |
| | | queryWrapper.exists("SELECT 1 FROM semantic_word WHERE semantic_word.id = copywriting.word_id " + |
| | | "AND semantic_word.word LIKE '%" + copywriting.getWordLike() + "%'"); |
| | | |
| | | } |
| | | |
| | | if (!user.equals("无")){ |
| | | QueryWrapper qw = new QueryWrapper<SysUser>(); |
| | | qw.eq("id", user); |
| | | String userName = ((SysUser)((Page) sysUserService.queryPageList(req, qw, 1, 1).getResult()).getRecords().get(0)).getUsername(); |
| | | queryWrapper.eq("create_by", userName); |
| | | } |
| | | long count = copywritingService.count(queryWrapper); |
| | | return Result.OK(count+""); |
| | | } |
| | | |
| | | |
| | | |
| | | @Operation(summary="文案-查询发送门户文章总量") |
| | | @GetMapping(value = "/upAvgTime") |
| | | public Result<IPage<Copywriting>> upAvgTime(Copywriting copywriting, |
| | | HttpServletRequest req) { |
| | | return Result.OK("5"); |
| | | } |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | requestBody.put("inputs", inputs); // 顶层 inputs 容器 |
| | | requestBody.put("user", user); // 顶层 inputs 容器 |
| | | |
| | | SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); |
| | | // 连接超时:建立TCP连接的超时时间,单位毫秒(建议设5秒) |
| | | factory.setConnectTimeout(5000); |
| | | // 读取超时:等待服务端响应数据的超时时间,单位毫秒(根据接口耗时调整,这里设30秒) |
| | | factory.setReadTimeout(100000); |
| | | // 步骤4:调用工作流接口 |
| | | RestTemplate restTemplate = new RestTemplate(); |
| | | RestTemplate restTemplate = new RestTemplate(factory); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | headers.set("Authorization", "Bearer " + authToken); |
| | | |
| | | HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers); |
| | | ResponseEntity<String> response = restTemplate.postForEntity(workflowUrl, requestEntity, String.class); |
| | | |
| | |
| | | return Result.error(JSONObject.parseObject(response.getBody()).getJSONObject("data").getString("error")); |
| | | } |
| | | else{ |
| | | return Result.OK("文案生成成功", JSONObject.parseObject(response.getBody()).getJSONObject("data").getJSONObject("outputs").getString("http")); |
| | | String test = JSONObject.parseObject(response.getBody()).getJSONObject("data").getJSONObject("outputs").getString("http"); |
| | | |
| | | // ========== 中间操作:MD转HTML格式文本(保留所有回车,新增####四级标题处理) ========== |
| | | // 1. 定义MD语法正则(补充####四级标题,其他保留) |
| | | Pattern h1Pattern = Pattern.compile("^# (.*)", Pattern.MULTILINE); |
| | | Pattern h2Pattern = Pattern.compile("^## (.*)", Pattern.MULTILINE); |
| | | Pattern h3Pattern = Pattern.compile("^### (.*)", Pattern.MULTILINE); |
| | | Pattern h4Pattern = Pattern.compile("^#### (.*)", Pattern.MULTILINE); // 新增:四级标题正则 |
| | | Pattern ulStartPattern = Pattern.compile("^- (.*)", Pattern.MULTILINE); |
| | | Pattern boldPattern = Pattern.compile("\\*\\*(.*?)\\*\\*"); |
| | | Pattern hrPattern = Pattern.compile("^---+$", Pattern.MULTILINE); |
| | | |
| | | // 2. 逐步替换MD语法为HTML标签(保留所有换行,新增四级标题转换) |
| | | test = h1Pattern.matcher(test).replaceAll("<h1>$1</h1>"); // 一级标题→<h1> |
| | | test = h2Pattern.matcher(test).replaceAll("<h2>$1</h2>"); // 二级标题→<h2> |
| | | test = h3Pattern.matcher(test).replaceAll("<h3>$1</h3>"); // 三级标题→<h3> |
| | | test = h4Pattern.matcher(test).replaceAll("<h4>$1</h4>"); // 新增:四级标题→<h4> |
| | | test = boldPattern.matcher(test).replaceAll("<strong>$1</strong>"); // 加粗→<strong> |
| | | test = hrPattern.matcher(test).replaceAll("<hr/>"); // 分隔线→<hr/> |
| | | |
| | | // 处理无序列表(先标记列表项,再包裹<ul>) |
| | | test = ulStartPattern.matcher(test).replaceAll("<li>$1</li>"); |
| | | test = test.replaceAll("(<li>.*?</li>\\r?\\n?)+", "<ul>$0</ul>"); |
| | | |
| | | // 保留原有回车(将\n转为HTML换行<br>,同时保留原始换行符) |
| | | test = test.replaceAll("\\r?\\n", "<br/>\n"); |
| | | |
| | | // ========== 转换结束,test为HTML格式且处理了####四级标题 ========== |
| | | |
| | | return Result.OK("文案生成成功", test); |
| | | } |
| | | |
| | | } else { |