提交 0c25f2e7 作者: obcy

Merge remote-tracking branch 'origin/master'

...@@ -29,14 +29,12 @@ import javax.servlet.http.HttpServletRequest; ...@@ -29,14 +29,12 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.net.URLEncoder;
import java.util.Date; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
/** /**
* @Description: 知识 * 知识
* @Author: chenshiqiang * @Author: chenshiqiang
* @Version: V1.0 * @Version: V1.0
*/ */
...@@ -54,6 +52,9 @@ public class KnowledgeController { ...@@ -54,6 +52,9 @@ public class KnowledgeController {
@Autowired @Autowired
private ILocalFileService localFileService; private ILocalFileService localFileService;
@Autowired
private RedisUtil redisUtil;
/** /**
* 分页列表查询 * 分页列表查询
*/ */
...@@ -78,6 +79,9 @@ public class KnowledgeController { ...@@ -78,6 +79,9 @@ public class KnowledgeController {
public Result<?> getById(@RequestParam String id) { public Result<?> getById(@RequestParam String id) {
log.info("{}===query begin", new Date()); log.info("{}===query begin", new Date());
KnowledgeVO knowledgeVO = knowledgeService.getById(id); KnowledgeVO knowledgeVO = knowledgeService.getById(id);
if(knowledgeVO==null){
return Result.OK("nothing");
}
if (null != knowledgeVO.getPublishDate() && (!knowledgeVO.getPublishDate().isEmpty())) { if (null != knowledgeVO.getPublishDate() && (!knowledgeVO.getPublishDate().isEmpty())) {
knowledgeVO.setPublishDate(EsDateUtil.esFieldDateMapping(knowledgeVO.getPublishDate())); knowledgeVO.setPublishDate(EsDateUtil.esFieldDateMapping(knowledgeVO.getPublishDate()));
} }
...@@ -154,7 +158,7 @@ public class KnowledgeController { ...@@ -154,7 +158,7 @@ public class KnowledgeController {
* @return * @return
*/ */
@PostMapping(value = "/delete") @PostMapping(value = "/delete")
public Result<?> delete( @RequestBody DeleteParam deleteParam) { public Result<?> delete(@RequestBody DeleteParam deleteParam) {
knowledgeService.deleteKnowledge(deleteParam.getKnowledgeList()); knowledgeService.deleteKnowledge(deleteParam.getKnowledgeList());
return Result.OK("删除成功!"); return Result.OK("删除成功!");
} }
...@@ -177,6 +181,7 @@ public class KnowledgeController { ...@@ -177,6 +181,7 @@ public class KnowledgeController {
params.put("score_threshold", intelligentQaParam.getScoreThreshold()); params.put("score_threshold", intelligentQaParam.getScoreThreshold());
params.put("question", intelligentQaParam.getQuestion()); params.put("question", intelligentQaParam.getQuestion());
params.put("knowledge_base_id", intelligentQaParam.getKbKnowledgeIds().split(",")); params.put("knowledge_base_id", intelligentQaParam.getKbKnowledgeIds().split(","));
params.put("size", intelligentQaParam.getSize());
String result = HttpUtil.doPost(intelligentQaUrl, params, 120000); String result = HttpUtil.doPost(intelligentQaUrl, params, 120000);
if (!result.isEmpty()) { if (!result.isEmpty()) {
JSONObject jsonObject = JSON.parseObject(result); JSONObject jsonObject = JSON.parseObject(result);
...@@ -194,7 +199,7 @@ public class KnowledgeController { ...@@ -194,7 +199,7 @@ public class KnowledgeController {
public Result<?> importInfo(HttpServletRequest request, HttpServletResponse response) { public Result<?> importInfo(HttpServletRequest request, HttpServletResponse response) {
KbAuthorizedUser userInfo = SpringContextUtils.getUserInfo(); KbAuthorizedUser userInfo = SpringContextUtils.getUserInfo();
assert userInfo != null; assert userInfo != null;
return knowledgeService.doImportInfo(request, userInfo.getId()); return knowledgeService.doImportInfo(request, userInfo.getId());
} }
...@@ -214,8 +219,89 @@ public class KnowledgeController { ...@@ -214,8 +219,89 @@ public class KnowledgeController {
} }
return Result.OK(); return Result.OK();
} }
/**
* 预导出
*
* @param newsIds 资讯知识ids
* @param fileIds 文件知识ids
*/
@PostMapping(value = "/export")
public Result<?> exportCollectionXls(HttpServletRequest request,
String newsIds, String fileIds) {
log.info("newsIds:{},fileIds:{}",newsIds,fileIds);
if(!newsIds.isEmpty()){
knowledgeService.exportExcel(newsIds);
}
if(!fileIds.isEmpty()){
knowledgeService.exportPackage(fileIds);
}
return Result.OK(true);
}
/**
* 导出
*
* @param newsIds 资讯知识ids
* @param fileIds 文件知识ids
*/
@RequestMapping(value = "/downloadFile")
public void downloadXls(HttpServletResponse response, String newsIds, String fileIds) {
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
//获取下载路径
Object newsObject = redisUtil.get(newsIds);
Object fileObject = redisUtil.get(fileIds);
String fileName = UUID.randomUUID().toString().replace("-", "");
String newsFilePath = null;
String fileFilePath = null;
if (newsObject != null) {
newsFilePath = newsObject.toString();
}
if (fileObject != null) {
fileFilePath = fileObject.toString();
}
try {
if ((!newsIds.isEmpty())&&(!fileIds.isEmpty())) {
log.info("files and news package downloading ");
List<String> list=new ArrayList<>();
list.add(newsFilePath);
list.add(fileFilePath);
log.info("newsFilePath:{},fileFilePath:{}",newsFilePath,fileFilePath);
String filePath = knowledgeService.comprocessByName(list,fileName );
log.info("filePath:{}",filePath);
response.setHeader("content-Disposition", "attachment;filename=" + URLEncoder.encode(filePath, "UTF-8"));
ExcelExportUtil.download(response, filePath, true);
return;
}
if (fileIds.isEmpty()) {//news
log.info("only news downloading");
redisUtil.del(newsIds);
if(newsFilePath==null){
log.error("nothing");
return;
}
log.info("newsFilePath:{}",newsFilePath);
response.setHeader("content-Disposition", "attachment;filename=" + URLEncoder.encode(newsFilePath, "UTF-8"));
ExcelExportUtil.download(response, newsFilePath, true);
return;
}
log.info("only files downloading");
String s = knowledgeService.exportPackage(fileIds);
log.info("packageFile:{}",s);
response.setHeader("content-Disposition", "attachment;filename=" + URLEncoder.encode(s, "UTF-8"));
ExcelExportUtil.download(response, s, true);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
}
}
} }
@Data @Data
class DeleteParam{ class DeleteParam {
private List<Knowledge> knowledgeList; private List<Knowledge> knowledgeList;
} }
\ No newline at end of file
...@@ -53,4 +53,12 @@ public interface IKnowledgeService { ...@@ -53,4 +53,12 @@ public interface IKnowledgeService {
Result<?> doImportInfo(HttpServletRequest request,String userId); Result<?> doImportInfo(HttpServletRequest request,String userId);
void doExcel(HttpServletRequest request, String fileSuffix,String userId); void doExcel(HttpServletRequest request, String fileSuffix,String userId);
List<KnowledgeVO> listByIds(String ids);
void exportExcel(String ids);
String exportPackage(String ids);
String comprocessByName(List<String> list, String filePath);
} }
...@@ -112,6 +112,7 @@ public class LocalFileServiceImpl implements ILocalFileService { ...@@ -112,6 +112,7 @@ public class LocalFileServiceImpl implements ILocalFileService {
return result; // create user metadata and return it return result; // create user metadata and return it
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(e.getMessage());
} }
// if the operation of file uploading is unsuccessful, an error occurs // if the operation of file uploading is unsuccessful, an error occurs
Result result = Result.error("上传文件时出现问题!"); Result result = Result.error("上传文件时出现问题!");
......
...@@ -415,6 +415,7 @@ public class EsOpUtil { ...@@ -415,6 +415,7 @@ public class EsOpUtil {
public Boolean docDeleteById(String index, String id) { public Boolean docDeleteById(String index, String id) {
try { try {
DeleteRequest deleteRequest = new DeleteRequest(index, id); DeleteRequest deleteRequest = new DeleteRequest(index, id);
deleteRequest.setRefreshPolicy("true");
DeleteResponse delete = client.delete(deleteRequest, RequestOptions.DEFAULT); DeleteResponse delete = client.delete(deleteRequest, RequestOptions.DEFAULT);
if (delete.status() == RestStatus.OK) { if (delete.status() == RestStatus.OK) {
log.info("DELETE /{}/_doc/{}/\r\n", index, id); log.info("DELETE /{}/_doc/{}/\r\n", index, id);
......
...@@ -12,14 +12,8 @@ import org.apache.commons.lang3.StringUtils; ...@@ -12,14 +12,8 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -255,4 +249,90 @@ public class ExcelExportUtil { ...@@ -255,4 +249,90 @@ public class ExcelExportUtil {
} }
//多个sheet
public static void exportExcelData(XSSFWorkbook workbook, int sheetNum, List<String> keyList, List<List<String>> rows, String sheetName) {
Sheet sheet = workbook.createSheet();
//多个sheet
workbook.setSheetName(sheetNum,sheetName);
sheet.setDefaultColumnWidth(20);
sheet.setDefaultRowHeight((short) 400);
XSSFCellStyle titleStyle = ExcelExportUtil.getHeaderStyle(workbook);
XSSFCellStyle rowStrStyle = ExcelExportUtil.getRowStrStyle(workbook);
// 产生表格标题行
Row row = sheet.createRow(0);
row.setHeight((short) 400);
Cell cell;
List<String> colData = new ArrayList<>(keyList);
for (int i = 0; i < colData.size(); i++) {
cell = row.createCell(i, CellType.STRING);
cell.setCellStyle(titleStyle);
cell.setCellValue(new XSSFRichTextString(colData.get(i)));
}
// 数据行
for (int m = 0; m < rows.size(); m++) {
List<String> rowData = rows.get(m);
row = sheet.createRow(m + 1);
row.setHeight((short) 400);
int i=0;
for (String rowDatum : rowData) {
createCell(rowStrStyle, row, i, rowDatum);
i++;
}
}
}
private static void createCell(XSSFCellStyle rowStrStyle, Row row, int index , String value){
Cell cell = row.createCell(index, CellType.STRING);
cell.setCellStyle(rowStrStyle);
cell.setCellValue(value);
}
/**
* 获取标题栏样式
*
* @param workbook
* @return
*/
private static XSSFCellStyle getHeaderStyle(XSSFWorkbook workbook) {
// 生成一个样式
XSSFCellStyle style = workbook.createCellStyle();
// 设置这些样式
style.setFillForegroundColor(IndexedColors.SKY_BLUE.index);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setAlignment(HorizontalAlignment.CENTER);
// style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00"));
// 生成一个字体
XSSFFont font = workbook.createFont();
font.setColor(IndexedColors.BLACK.index);
font.setFontHeightInPoints((short) 9);
// 把字体应用到当前的样式
style.setFont(font);
return style;
}
/**
* 获取字符串型内容栏样式
*
* @return
*/
private static XSSFCellStyle getRowStrStyle(XSSFWorkbook workbook) {
// 生成一个样式
XSSFCellStyle style = workbook.createCellStyle();
// 设置这些样式
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setAlignment(HorizontalAlignment.CENTER);
// 生成一个字体
XSSFFont font = workbook.createFont();
font.setColor(IndexedColors.BLACK.index);
font.setFontHeightInPoints((short) 9);
font.setBold(true);
// 把字体应用到当前的样式
style.setFont(font);
return style;
}
} }
package com.zzsn.knowbase.util;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* @Description
* @ClassName ZipUtils
* @Author yuhuofei
* @Date 2022/8/10 20:37
* @Version 1.0
*/
@Slf4j
public class ZipUtils {
/**
* @param zipPathDir 压缩包路径 ,如 /home/data/zip-folder/
* @param zipFileName 压缩包名称 ,如 测试文件.zip
* @param fileList 要压缩的文件列表(绝对路径),如 /home/person/test/测试.doc,/home/person/haha/测试.doc
* @return
*/
public static void compressFiles(String zipPathDir, String zipFileName, List<String> fileList) {
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(new File(zipPathDir + zipFileName+".zip")))) {
File zipFile = new File(zipPathDir);
if (!zipFile.exists()) {
zipFile.mkdirs();
}
for (String filePath : fileList) {
log.info("file package file :{}",filePath);
File file = new File(filePath);
if (file.exists()) {
int index = file.getName().lastIndexOf('.');
ZipEntry zipEntry = new ZipEntry(file.getName().substring(0, index) + "-" + dateRandom18() + file.getName().substring(index));
zos.putNextEntry(zipEntry);
byte[] buffer = new byte[2048];
compressSingleFile(file, zos, buffer);
}
}
zos.flush();
} catch (Exception e) {
log.error("压缩所有文件成zip包出错{}" , e.getMessage());
}
}
//压缩单个文件
public static void compressSingleFile(File file, ZipOutputStream zos, byte[] buffer) {
int len;
try (FileInputStream fis = new FileInputStream(file)) {
while ((len = fis.read(buffer)) > 0) {
zos.write(buffer, 0, len);
zos.flush();
}
zos.closeEntry();
} catch (IOException e) {
System.out.println("====压缩单个文件异常====" + e);
}
}
//生成随机数
public static String dateRandom18() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
String date = simpleDateFormat.format(new Date());
String timeMillis = String.valueOf(System.currentTimeMillis());
String fiveNumber = timeMillis.substring(timeMillis.length() - 6);
String tempRandom = String.valueOf(Math.random());
String number = tempRandom.substring(tempRandom.length() - 4);
return date + fiveNumber + number;
}
//测试方法
public static void main(String[] args) {
String zipPathDir = "D:/";
String zipFileName = "测试文件.zip";
List<String> list = new ArrayList<>();
list.add("D:/a.txt");
list.add("D:/b.txt");
compressFiles(zipPathDir, zipFileName, list);
}
}
...@@ -16,5 +16,6 @@ public class IntelligentQaParam { ...@@ -16,5 +16,6 @@ public class IntelligentQaParam {
private String question; private String question;
private String kbKnowledgeIds; private String kbKnowledgeIds;
private Integer scoreThreshold=700; private Integer scoreThreshold=700;
private Integer size=20;
} }
...@@ -27,7 +27,9 @@ public class KnowledgeVO { ...@@ -27,7 +27,9 @@ public class KnowledgeVO {
private String publishDate; private String publishDate;
private String createTime; private String createTime;
private String kbKnowledgeId; private String kbKnowledgeId;
private String KnowledgeProjectId;
private String type; private String type;
private String typeId;
private String verifierName; private String verifierName;
private String origin; private String origin;
private String author; private String author;
......
...@@ -24,7 +24,7 @@ spring: ...@@ -24,7 +24,7 @@ spring:
requiredAcks: 1 requiredAcks: 1
redis: redis:
database: 0 database: 0
host: 114.115.236.206 host: 114.116.90.53
lettuce: lettuce:
pool: pool:
max-active: 8 #最大连接数据库连接数,设 0 为没有限制 max-active: 8 #最大连接数据库连接数,设 0 为没有限制
...@@ -32,7 +32,7 @@ spring: ...@@ -32,7 +32,7 @@ spring:
max-wait: -1ms #最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。 max-wait: -1ms #最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。
min-idle: 0 #最小等待连接中的数量,设 0 为没有限制 min-idle: 0 #最小等待连接中的数量,设 0 为没有限制
shutdown-timeout: 100ms shutdown-timeout: 100ms
port: 6379 port: 6380
password: clbzzsn password: clbzzsn
thymeleaf: thymeleaf:
...@@ -58,11 +58,14 @@ know: ...@@ -58,11 +58,14 @@ know:
document: document:
server: server:
host: http://114.116.116.241:9088 host: http://114.116.116.241:9088
# host: http://192.168.1.71:9088
files: files:
storage: /storage/know/ storage: /storage/know/
# storage: C:/know/
docservice: docservice:
url: url:
site: http://114.116.116.241:80/ site: http://114.116.116.241:80/
# site: http://192.168.1.216:80/
converter: ConvertService.ashx converter: ConvertService.ashx
command: coauthoring/CommandService.ashx command: coauthoring/CommandService.ashx
api: web-apps/apps/api/documents/api.js api: web-apps/apps/api/documents/api.js
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论