添加帮助 @param helpTypeId 帮助分类Id @param name 名称 @param content 内容 @param isMarkdown 是否为Markdown格式数据 @param markdownContent Markdown内容 @param request 请求信息
(Long helpTypeId,String name,String content,Boolean isMarkdown,String markdownContent, HttpServletRequest request)
| 173 | * @param request 请求信息 |
| 174 | */ |
| 175 | public void addHelp(Long helpTypeId,String name,String content,Boolean isMarkdown,String markdownContent, HttpServletRequest request){ |
| 176 | |
| 177 | validateInput(helpTypeId, name,content); |
| 178 | |
| 179 | |
| 180 | //复制文件锁 |
| 181 | List<String> fileLock_list = new ArrayList<String>(); |
| 182 | List<String> oldPathFileList = new ArrayList<String>();//旧路径文件 |
| 183 | |
| 184 | // 处理内容过滤和文件路径 |
| 185 | HtmlFilterResult htmlFilterResult = processAndFilterContent(request, content, isMarkdown, markdownContent); |
| 186 | |
| 187 | if(htmlFilterResult == null){ |
| 188 | throw new BusinessException(Map.of("content", "帮助内容不能为空")); |
| 189 | } |
| 190 | content = htmlFilterResult.content; |
| 191 | |
| 192 | if(content == null || content.trim().isEmpty()){ |
| 193 | throw new BusinessException(Map.of("content", "帮助内容不能为空")); |
| 194 | } |
| 195 | |
| 196 | String value = htmlFilterResult.htmlProcessingResult.getHtmlContent(); |
| 197 | |
| 198 | //修改文件路径 |
| 199 | FilePathUpdateResult filePathUpdateResult = textFilterComponent.updateTypePath(value,"help",helpTypeId); |
| 200 | String new_value = filePathUpdateResult.getHtmlContent(); |
| 201 | Map<String,String> file_path = filePathUpdateResult.getOldToNewPathMap();//key:旧文件路径 value:新文件路径 |
| 202 | |
| 203 | if(file_path != null && file_path.size() >0){ |
| 204 | for(Map.Entry<String,String> entry : file_path.entrySet()) {//key:旧文件路径 value:新文件路径 |
| 205 | |
| 206 | //旧路径 左斜杆路径转为系统路径 |
| 207 | String old_path_Delimiter = FileUtil.toSystemPath(entry.getKey()); |
| 208 | |
| 209 | //新路径 左斜杆路径转为系统路径 |
| 210 | String new_path_Delimiter = FileUtil.toSystemPath(entry.getValue()); |
| 211 | |
| 212 | //替换路径中的..号 |
| 213 | old_path_Delimiter = FileUtil.toRelativePath(old_path_Delimiter); |
| 214 | new_path_Delimiter = FileUtil.toRelativePath(new_path_Delimiter); |
| 215 | |
| 216 | try { |
| 217 | //复制文件到新路径 |
| 218 | fileComponent.copyFile(old_path_Delimiter, new_path_Delimiter); |
| 219 | //取得文件名称 |
| 220 | String fileName = FileUtil.getName(entry.getKey()); |
| 221 | |
| 222 | //新建文件锁到新路径 |
| 223 | //生成锁文件名称 |
| 224 | String lockFileName = Strings.CS.replaceOnce(entry.getValue(), "file/help/", "")+fileName; |
| 225 | lockFileName = lockFileName.replaceAll("/", "_"); |
| 226 | |
| 227 | fileLock_list.add(lockFileName); |
| 228 | //添加文件锁 |
| 229 | fileComponent.addLock("file"+File.separator+"help"+File.separator+"lock"+File.separator,lockFileName); |
| 230 | //旧路径文件 |
| 231 | oldPathFileList.add(old_path_Delimiter); |
| 232 | } catch (IOException e) { |
nothing calls this directly
no test coverage detected