导出与导入
easyui+springboot +poi
pom.xml里面引入poi
导出
前端 发送get请求:
$uploadQA.on(“click”, “#btn-downloadDD”, function () {
window.location.href = Util.constants.DOCEDIT_MANAGE_IPO + “地址”;
});
后代control层代码
service层:
/**
* 单独的问答知识导入模版下载
*
* @param request
* @param response
* @return
*/
@Override
public Response exportAloneQAKnwlgExcel(HttpServletRequest request, HttpServletResponse response) {
Response aloneQAKnwlgResponse = new Response();
//表头名
String[] title = {"知识标题(必填)", "知识存储路径(必填)","自定义标签", "问题", "扩展问", "答案"};
//sheet名
String sheetName = "独立知识问答模板";
//下载的文件名
String fileName = "独立知识问答模板.xlsx";
//创建XSSFWorkbook
XSSFWorkbook workbook = getXSSFWorkbook(sheetName, title);
OutputStream os = null;
try {
setResponseHeader(response, fileName);
os = response.getOutputStream();
workbook.write(os);
os.flush();
} catch (IOException e) {
logger.error("下载模板失败!");
aloneQAKnwlgResponse.setRspcode(WebUtil.FAIL);
aloneQAKnwlgResponse.setRspdesc("下载模板失败!");
return aloneQAKnwlgResponse;
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
logger.error("关闭异常!");
}
}
}
aloneQAKnwlgResponse.setRspcode(WebUtil.SUCCESS);
aloneQAKnwlgResponse.setRspdesc("下载模板成功!");
return aloneQAKnwlgResponse;
}
/**
* 单独的问答知识导入模版下载
* 设置Excel的格式
*
* @param
sheetName
* @param title
* @return
*/
public XSSFWorkbook getXSSFWorkbook(String sheetName, String[] title) {
//创建workbook 2007版本
XSSFWorkbook workbook = new XSSFWorkbook();
//创建一个sheet
XSSFSheet sheet = workbook.createSheet(sheetName);
//创建行
XSSFRow row = sheet.createRow(0);
//创建格式
XSSFCellStyle style = workbook.createCellStyle();
//设置边框:
style.setBorderBottom(XSSFCellStyle.BORDER_THIN); //下边框
style.setBorderLeft(XSSFCellStyle.BORDER_THIN);//左边框
style.setBorderTop(XSSFCellStyle.BORDER_THIN);//上边框
style.setBorderRight(XSSFCellStyle.BORDER_THIN);//右边框
//设置格式 居中
style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
//设置单元格内容自动换行 ===强制换行可以使用\n
style.setWrapText(true);
//设置背景色
style.setFillForegroundColor(new XSSFColor(new Color(204, 204, 204)));// 以给单元格着色
style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); //设置单元格填充样式 SOLID_FOREGROUND纯色使用前景颜色填
XSSFFont font = workbook.createFont();
//设置字体
font.setFontName("黑体");
font.setFontHeightInPoints((short) 12);
// 把字体应用到当前的样式
style.setFont(font);
XSSFCell cell = null;
//设置表头
for (int i = 0; i < title.length; i++) {
//设置列的宽度
sheet.setColumnWidth(i, 5000);
cell = row.createCell(i);
cell.setCellValue(title[i]);
cell.setCellStyle(style);
}
return workbook;
}
/**
* 单独的问答知识导入模版下载
* 发送响应流
*
* @param response
* @param fileName
*/
public void setResponseHeader(HttpServletResponse response, String fileName) {
try {
fileName = new String(fileName.getBytes(), "ISO8859-1");
} catch (UnsupportedEncodingException e) {
logger.error("不支持导出!");
}
response.setContentType("application/octet-stream;charset=ISO8859-1");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
response.addHeader("Pargam", "no-cache");
response.addHeader("Cache-Control", "no-cache");
}
/**
* 创建头部公共样式与赋值
* @param sheet
* @param title
* @param style
* @param whiteStyle/
*/
private void createHeadRowStyle(XSSFSheet sheet, String[] title, XSSFCellStyle style, XSSFCellStyle whiteStyle,String sheetName) {
//公共属性样式表格创建- ***先创建单元格,在给单元格赋值。这样样式不容易出问题***
//需要title.length行表格
for (int i = 0; i < title.length; i++) {
XSSFRow row = sheet.createRow(i);
//合并单元格 四个参数-开始行,结束行。开始列,结束列
sheet.addMergedRegion(new CellRangeAddress(i, i, 0, 2));
//设置列的宽度
if(i<3) {
sheet.setColumnWidth(i, 5000);
}else if(i==3){
sheet.setColumnWidth(3, 10000);
}
// 需要4列
for (int j = 0; j < 4; j++) {
if(j<3) {
row.createCell(j).setCellStyle(style);
}else{
row.createCell(j).setCellStyle(whiteStyle);
}
}
}
//公共属性样式赋值
for(int i=0;i<title.length;i++){
XSSFRow row = sheet.getRow(i);
row.getCell(0).setCellValue(title[i]);
}
导入
思想:前台代码通过ajax发送文件流到后端解析
package com.unicom.kc.manage.doc.service.impl;
import com.unicom.kc.common.sso.domain.UserInfo;
import com.unicom.kc.common.sso.util.TokenUtils;
import com.unicom.kc.common.sso.vo.Response;
import com.unicom.kc.manage.dist.domain.TKcDistrictConfig;
import com.unicom.kc.manage.doc.common.sequence.SequenceUtils;
import com.unicom.kc.manage.doc.dao.*;
import com.unicom.kc.manage.doc.domain.*;
import com.unicom.kc.manage.doc.service.*;
import com.unicom.kc.manage.doc.service.IKcTagRemoteSV;
import com.unicom.kc.manage.doc.service.IKcUploadQAknwlgSV;
import com.unicom.kc.manage.doc.util.Constants;
import com.unicom.kc.manage.doc.util.EsConstants;
import com.unicom.kc.manage.doc.util.StringUtil;
import com.unicom.kc.manage.doc.util.WebUtil;
import com.unicom.kc.manage.doc.web.component.DocIndexComponent;
import com.unicom.kc.manage.doc.web.component.KnwlgDocIndexCompoonent;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class KcUploadQAknwlgSVImpl implements IKcUploadQAknwlgSV {
private static Logger logger = LoggerFactory.getLogger(KcUploadQAknwlgSVImpl.class);
@Autowired
private IKcGetRemoteSV iKcGetRemoteSV; //知识地区//知识渠道
@Autowired
private TKcDocEditMapper tKcDocEditDAO;//知识
@Autowired
private TKcCatalogDocRelMapper tKcCatalogDocRelDAO;//知识路径
@Autowired
private TKcDocGroupsMapper KcDocGroupsDAO;//分组
@Autowired
private TKcDocKeysMapper KcDocKeysDAO;//原子DAO
@Autowired
private SequenceUtils sequenceUtils;
@Autowired
private TKcDocRelationMapper tKcDocRelationMapper;//知识关系表
@Autowired
private TKcDocEditPusMapper KcDocEditPusDAO;//发布表
@Autowired
private TKcRelateEditMapper tKcRelateEditMapper;//自定义标签表
@Autowired
private IKcTagRemoteSV iKcTagRemoteSV;
@Autowired
private IKmKnowledgeCoreSV iKmKnowledgeCoreSV;
@Autowired
private IKcDocIndexSV iKcDocIndexSV;
@Autowired
private IKcGetTmpltRemoteSV iKcGetTmpltRemoteSV;
@Autowired
private DocIndexComponent docIndexComponent;
@Autowired
private IKcDocEditPusSV kcDocEditPusSV;
@Autowired
private KnwlgDocIndexCompoonent knwlgDocIndexCompoonent;
/**
* 批量导入问答知识
*
* @param QAknwlgFile
* @return
*/
@Override
public Response uploadQAknwlgFile(MultipartFile QAknwlgFile, UserInfo userInfo) throws Exception {
Response response = new Response();
Set qaKnwlgNm = new HashSet();
if (QAknwlgFile.isEmpty()) {
response.setRspdesc("问答模板文件为空");
response.setRspcode(WebUtil.EXCEPTION);
return response;
}
// HSSFWorkbook workbook = new HSSFWorkbook(QAknwlgFile.getInputStream()); // 2003版本
XSSFWorkbook workbook = new XSSFWorkbook(QAknwlgFile.getInputStream()); // 2007版本
Sheet sheet = workbook.getSheetAt(0);
sheet.getRow(1).getCell(0).setCellType(Cell.CELL_TYPE_STRING);
String flag = sheet.getRow(1).getCell(0).getStringCellValue();
String sheetName = sheet.getSheetName();//页签名
//列
int totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
String SplitId = sequenceUtils.getSequence("t_kc_doc_edit").toString();
int number = 0;
if ("知识存储路径(必填)".equals(flag)) {
int lastRow = sheet.getLastRowNum();
for (int m = 3; m < totalCells; m++) {
if(m>3){
response.setRspdesc("问答模板只支持单列导入,第一列导入成功");
response.setRspcode(WebUtil.FAIL);
return response;
}
Row row_l = sheet.getRow(1);
if (row_l.getCell(m) == null || StringUtil.isEmpty(row_l.getCell(m).toString())) {
break;
}
String knwlgstr = "";//知识标题
String KnwlgType = null;//知识类别(必填)text
String anthRegnNm = null;//知识发布范围(必填)text
String ChnlNm = null;//知识发布渠道(必填)text
Long CatlId = 0L;//知识存储路径(必填)
String KnwlgRegnType = "";//知识类别(必填)
String AuthRegnNo = "";//知识发布范围(必填)
Long TmpltId = 0L;//知识模板(必填)
String ChnlCodes = "";//知识发布渠道(必填)
Date KnwlgEffTime = null;//知识上线时间(必填)
Date KnwlgInvldTime = null;//知识下线时间
Date BusiEffTime = null;//业务上线时间
Date BusiInvldTime = null;//业务下线时间
List<String> urdfTabsId = new ArrayList<>(); // 自定义页签id
for (int i = 0; i <= 10; i++) {
Row row = sheet.getRow(i);
if (row == null) {
continue;
}
row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
String name = row.getCell(0).getStringCellValue();
if ("".equals(name)) {
row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
name = row.getCell(1).getStringCellValue();
}
if ("知识标题(必填)".equals(name)) {
row.getCell(m).setCellType(Cell.CELL_TYPE_STRING);
knwlgstr = row.getCell(m).getStringCellValue();
if ("".equals(knwlgstr)) {
throw new Exception("导入失败,知识标题(必填)");
}
} else if ("知识存储路径(必填)".equals(name)) {
//根据知识路径获取ID
row.getCell(m).setCellType(Cell.CELL_TYPE_STRING);
String catlNm = row.getCell(m).getStringCellValue();
if ("".equals(catlNm)) {
throw new Exception("导入失败,知识存储路径(必填)");
}
CatlId = Long.valueOf(iKcGetRemoteSV.getCatlIdByCatlNmJob(catlNm));
} else if ("知识类别(必填)".equals(name)) {
KnwlgType = row.getCell(m).getStringCellValue();
if ("".equals(KnwlgType)) {
throw new Exception("导入失败,知识类别(必填)");
}
List<TKcStaticData> list = iKcGetRemoteSV.getCodeValueByTypeIdAndNameJob("NGKM.KNWLG.REGN.TYPE", KnwlgType);
if (list.size() == 0 || list.get(0).getDataValue() == null) {
throw new Exception("知识类别查询失败");
}
KnwlgRegnType = list.get(0).getDataValue();
/* String StaffType = userInfo.getStaffType();
int StaffType1 = Integer.parseInt(StaffType)-1;
if(!list.get(0).getDataValue().equals(String.valueOf(StaffType1))){
throw new Exception("此用户没有权限导入知识类别为:"+KnwlgType+"的知识");
}
*/
} else if ("知识发布范围(必填)".equals(name)) {
row.getCell(m).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(m).getStringCellValue();
if ("".equals(str)) {
throw new Exception("导入失败,知识发布范围(必填)");
}
anthRegnNm=str;
String[] strArr = str.split(",");
String AuthRegnNos = "";
for (int n = 0; n < strArr.length; n++) {
List<TKcDistrictConfig> list = iKcGetRemoteSV.getByRegnNmJob(strArr[n]);
if (list.size() == 0 || list.get(0).getRegnId() == null) {
throw new Exception("第" + (m + 1) + "列,知识发布范围:" + str + "不存在,请您确认是否正确");
}
AuthRegnNos += list.get(0).getRegnId() + ",";
}
AuthRegnNo = AuthRegnNos.substring(0, AuthRegnNos.length() - 1);
} else if ("知识模板(必填)".equals(name)) {
row.getCell(m).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(m).getStringCellValue();
TKcTmpltInfo tKmTmpltInfo = iKcGetTmpltRemoteSV.selectTmpltByTmpltNmJob("问答模板");
if (tKmTmpltInfo == null) {
throw new Exception("第" + (m + 1) + "列,知识模板:" + str + "不存在,请您确认是否正确");
}
TmpltId = tKmTmpltInfo.getTmpltId();
} else if ("知识发布渠道(必填)".equals(name)) {
row.getCell(m).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(m).getStringCellValue();
if ("".equals(str)) {
throw new Exception("导入失败,知识渠道(必填)");
}
ChnlNm=str;
String[] strArr = str.split(",");
String ChnlCode = "";
for (int n = 0; n < strArr.length; n++) {
List<TKcStaticData> list = iKcGetRemoteSV.getCodeValueByTypeIdAndNameJob("NGKM.TEMPLET.CHNL", strArr[n]);
if (list.size() == 0 || list.get(0).getDataValue() == null) {
throw new Exception("第" + (m + 1) + "列,知识渠道:" + strArr[n] + "不存在,请您确认是否正确");
}
ChnlCode += list.get(0).getDataValue() + ",";
}
ChnlCodes = ChnlCode.substring(0, ChnlCode.length() - 1);
} else if ("知识上线时间(必填)".equals(name)) {
try {
KnwlgEffTime = row.getCell(m).getDateCellValue();
} catch (Exception e) {
row.getCell(m).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(m).getStringCellValue();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
KnwlgEffTime = format.parse(str);
}
} else if ("知识下线时间".equals(name)) {
try {
KnwlgInvldTime = row.getCell(m).getDateCellValue();
} catch (Exception e) {
row.getCell(m).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(m).getStringCellValue();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
KnwlgInvldTime = format.parse(str);
}
} else if ("业务上线时间".equals(name)) {
try {
BusiEffTime = row.getCell(m).getDateCellValue();
} catch (Exception e) {
row.getCell(m).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(m).getStringCellValue();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
BusiEffTime = format.parse(str);
}
//临时注掉
// if (BusiEffTime == null) {
// throw new Exception("导入失败,业务上线时间(必填)");
// }
} else if ("业务下线时间".equals(name)) {
try {
BusiInvldTime = row.getCell(m).getDateCellValue();
} catch (Exception e) {
row.getCell(m).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(m).getStringCellValue();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
BusiInvldTime = format.parse(str);
}
} else if ("自定义标签".equals(name)) {
row.getCell(m).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(m).getStringCellValue();
if (StringUtil.isNotEmpty(str)) {
String[] strArr = str.split(",");
for (String s : strArr) {
List<TKcCustomtabsInfo> tKcCustomtabsInfoList = iKcTagRemoteSV.getTagLibInfosByTagNmJob(s);
if (tKcCustomtabsInfoList == null || tKcCustomtabsInfoList.size() == 0) {
throw new Exception("不存在名称为【" + s + "】的标签");
}
urdfTabsId.add(tKcCustomtabsInfoList.get(0).getUrdfTabsId().toString());
}
}
}
}
TKcTmpltInfo tKmTmpltInfo = iKcGetTmpltRemoteSV.selectTmpltByTmpltNmJob("问答模板");
Long groupId = 0L;
Long knwlgId = 0L;
List<TKcRelateEdit> tKcRelateEditList = new ArrayList<>();
TKcDocEdit docEdit = null;
TKcCatalogDocRel catalogDocRel = null;
TKcDocGroups docGroups = null;
List<TKcDocKeysWithBLOBs> keysList = new ArrayList<>();
TKcDocRelation tKcDocRelation = null;
int k=0; //判断问答结构 固定的三条
String strutKnwlgId = "";
//判断是否有关联对应的模板
TKcTmpltInfo tkcTmpltInfo = iKcGetTmpltRemoteSV.selectTmpltByTmpltNmJob(sheetName);
if (tkcTmpltInfo != null && tkcTmpltInfo.getTmpltId() != null) {
//关联结构化知识关联表 docIndexComponent
Map<String, Object> condition = new HashMap<>();
condition.put(EsConstants.DOC_INDEX_FAIELD.KNWLG_NM, knwlgstr);//知识标题
condition.put(EsConstants.DOC_INDEX_FAIELD.REGN_ID, userInfo.getProvnce());//地区
condition.put(EsConstants.DOC_INDEX_FAIELD.KNWLG_TYPE, Constants.NGKM_KNWLG_TYPE.NOKNWLG);//结构化知识
condition.put(EsConstants.DOC_INDEX_FAIELD.KNWLG_STS_CD, "1P,2P");//知识状态
List<Map<String, Object>> docIndex = docIndexComponent.getDocIndex(condition);
if(docIndex != null){
strutKnwlgId = (String) docIndex.get(0).get(EsConstants.DOC_INDEX_FAIELD.KNWLG_ID);
}
}
logger.info("--------------------------------------"+knwlgstr + "关联的结构化知识id是:" + strutKnwlgId);
String relationId = String.valueOf(sequenceUtils.getSequence("t_kc_doc_relation"));
if (StringUtil.isNotEmpty(strutKnwlgId)){
TKcDocEditPus docEditPus = knwlgDocIndexCompoonent.getDocEditPusByPrimaryKey(Long.parseLong(strutKnwlgId), EsConstants.TAB_NAME.DOC_PUS);
if (docEditPus != null){
TKcDocRelationExample example = new TKcDocRelationExample();
TKcDocRelationExample.Criteria criteria = example.createCriteria();
criteria.andKnwlgIdEqualTo(Long.parseLong(strutKnwlgId));
criteria.andSplitIdEqualTo(docEditPus.getSplitId());
List<TKcDocRelation> tKcDocRelationList = tKcDocRelationMapper.selectByExample(example);
relationId = String.valueOf(tKcDocRelationList.get(0).getRelationId());
SplitId = docEditPus.getSplitId();
}
}
boolean showAble = true;
int relationSeqNo = 0;
for (int j = 12; j <= lastRow; j++) {
Row row1 = sheet.getRow(j);
if (row1 == null || row1.getCell(0) == null || row1.getCell(1) == null) {
break;
}
if(k>=4){
throw new Exception("问答要素没有获取到或为空,请确认模板[行号:"+(j+1)+"]");
}
row1.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
String group_str = row1.getCell(0).getStringCellValue();
StringBuffer customTab=new StringBuffer(anthRegnNm);
customTab.append(",").append(KnwlgType).append(",").append(ChnlNm).append(",问答知识,问答模板");
logger.info("---------------------生成自动标签:"+ customTab);
if (!"".equals(group_str)) {
k=0;
docEdit = new TKcDocEdit();//问答知识对象
knwlgId = sequenceUtils.getSequence("t_kc_doc_edit");
docEdit.setKnwlgId(knwlgId);
docEdit.setSplitId(SplitId);
docEdit.setKnwlgType("1");//问答知识默认 1
docEdit.setVerno("v1");
docEdit.setKnwlgGathrTypeCd("1");
docEdit.setKnwlgStsCd("1E");
docEdit.setTenantId("-1");
docEdit.setIsSearchable("0");//搜索可见
docEdit.setOpStsCd(Constants.NGKM_KNOWLEDGE_OPERTYPE.INSERT);//操作类型
docEdit.setCreateTime(new Timestamp(System.currentTimeMillis()));
docEdit.setUpdateTime(new Timestamp(System.currentTimeMillis()));
docEdit.setUpdateUser(userInfo.getStaffCode());
docEdit.setCreateUser(userInfo.getStaffCode());
docEdit.setRegnId(userInfo.getScope());
docEdit.setKnwlgNm(knwlgstr);
docEdit.setKnwlgRegnType(KnwlgRegnType);
docEdit.setAuthRegnNo(AuthRegnNo);
docEdit.setTmpltId(TmpltId);
docEdit.setChnlCode(ChnlCodes);
docEdit.setKnwlgEffTime(KnwlgEffTime);
docEdit.setKnwlgInvldTime(KnwlgInvldTime);
docEdit.setBusiEffTime(BusiEffTime);
docEdit.setBusiInvldTime(BusiInvldTime);
docEdit.setUrdfTabs(customTab.toString());
docEdit.setField2(Constants.NGKM_KNWLG_UPDATE_CD.ADD);
catalogDocRel = new TKcCatalogDocRel();//知识路径对象
Long rlId = sequenceUtils.getSequence("t_kc_catalog_doc_rel");
catalogDocRel.setRlId(rlId);
catalogDocRel.setKnwlgId(knwlgId);
catalogDocRel.setSplitId(SplitId);
catalogDocRel.setArgeSeqno(100);
catalogDocRel.setShowFlag("1");
catalogDocRel.setStsCd("1");
catalogDocRel.setTenantId("-1");
catalogDocRel.setCreateTime(new Timestamp(System.currentTimeMillis()));
catalogDocRel.setUpdateTime(new Timestamp(System.currentTimeMillis()));
catalogDocRel.setUpdateUser(userInfo.getStaffCode());
catalogDocRel.setCreateUser(userInfo.getStaffCode());
catalogDocRel.setCatlId(CatlId);
docEdit.setCatlIds(CatlId.toString());
for (String tabId : urdfTabsId) {
TKcRelateEdit tKcRelateEdit = new TKcRelateEdit();//自定义标签对象
Long rltId = sequenceUtils.getSequence("t_kc_relate_edit");
tKcRelateEdit.setRltId(rltId);
tKcRelateEdit.setKnwlgId(knwlgId);
tKcRelateEdit.setSplitId(SplitId);
tKcRelateEdit.setRltTypeCd(Constants.NGKM_KNOWLEDGE_RELATION_TYPE.KLG_RELATION_TAB);
tKcRelateEdit.setRltObjId(tabId);
tKcRelateEdit.setCreateTime(new Date());
tKcRelateEdit.setCreateUser(userInfo.getStaffCode());
tKcRelateEdit.setTenantId(userInfo.getTenantId());
tKcRelateEditList.add(tKcRelateEdit);
}
tKcDocRelation = saveDocRelation(docEdit, relationId,relationSeqNo);
docGroups = new TKcDocGroups();//分组对象
groupId = sequenceUtils.getSequence("t_kc_doc_groups");
docGroups.setGrpngId(groupId);
docGroups.setKnwlgId(knwlgId);
docGroups.setSplitId(SplitId);
List<TKcTmpltGroups> list = iKcGetTmpltRemoteSV.getTmpltGroupsByExampleJob(tKmTmpltInfo.getTmpltId(), "问答要素", "");
if (list.size() == 0 || list.get(0).getGrpngId() == null) {
throw new Exception("问答要素查询失败异常");
}
Long grpngId = list.get(0).getGrpngId();
docGroups.setSrcTmpltGrpngId(grpngId);//原模板id
docGroups.setArgeSeqno(Short.parseShort("0"));
docGroups.setStsCd("1");
docGroups.setTenantId("-1");
docGroups.setGrpngNm(group_str);
docGroups.setUpdateTime(new Timestamp(System.currentTimeMillis()));
docGroups.setCreateTime(new Timestamp(System.currentTimeMillis()));
docGroups.setUpdateUser(userInfo.getStaffCode());
docGroups.setCreateUser(userInfo.getStaffCode());
}
row1.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
String atom_name = row1.getCell(1).getStringCellValue();
TKcDocKeysWithBLOBs docKeys = new TKcDocKeysWithBLOBs();
Long keyId = sequenceUtils.getSequence("t_kc_doc_keys");
docKeys.setKnwlgAttrAtomId(keyId);
docKeys.setKnwlgId(knwlgId);
docKeys.setGrpngId(groupId);
docKeys.setSplitId(SplitId);
docKeys.setParaNm(atom_name);
row1.getCell(m).setCellType(Cell.CELL_TYPE_STRING);
String atom_val = row1.getCell(m).getStringCellValue();
boolean isRepeat = false;
if (StringUtils.isNotEmpty(atom_val) && "问题".equals(atom_name)) {
if (qaKnwlgNm.contains(knwlgstr + atom_val)) {
logger.info("原子查询失败异常:{} [{}:{}] {}", row1.getCell(m).toString(), (row1.getRowNum() + 1), (m + 1));
throw new Exception("问答知识:" + knwlgstr + "在EXCEL中重复!" + "重复问题是:" + atom_val);
}
qaKnwlgNm.add(knwlgstr + atom_val);
isRepeat = isQaRepeat(atom_val, userInfo.getScope(), knwlgstr, ChnlCodes);
}
if (isRepeat) {
logger.info("原子查询失败异常:{} [{}:{}] {}", row1.getCell(m).toString(), (row1.getRowNum() + 1), (m + 1));
throw new Exception("问答知识:" + knwlgstr + "在数据库中重复!" + "重复问题是:" + atom_val);
}
docKeys.setParaVal("");
docKeys.setCntt(atom_val);
TKcTmpltKeys queryKeyByName = new TKcTmpltKeys();
queryKeyByName.setParaNm(atom_name);
List<TKcTmpltKeys> TKmTmpltKeys_list = iKcGetTmpltRemoteSV.selectTmpltKeyByParamsJob(queryKeyByName);
if (TKmTmpltKeys_list.size() == 0 || TKmTmpltKeys_list.get(0).getAtomId() == null) {
throw new Exception("原子查询失败异常");
}
docKeys.setSrcTmpltAttrAtomId(TKmTmpltKeys_list.get(0).getAtomId());
docKeys.setParaTypeCd(TKmTmpltKeys_list.get(0).getParaTypeCd());//设置原子文本类型
docKeys.setAppTypeCd("0");
docKeys.setBrwsPriv("1");
docKeys.setArgeSeqno(1);
docKeys.setStsCd("1");
docKeys.setTenantId(userInfo.getTenantId());
docKeys.setCreateUser(userInfo.getStaffCode());
docKeys.setUpdateUser(userInfo.getStaffCode());
docKeys.setUpdateTime(new Timestamp(System.currentTimeMillis()));
docKeys.setCreateTime(new Timestamp(System.currentTimeMillis()));
keysList.add(docKeys);
k+=1;
if (k % 3 == 0) {
if (isQaEmpty(keysList)) {
keysList.clear();
continue;
}
if (showAble){
showAble = false;
docEdit.setField1(Constants.NGKM_KNWLG_SHOW_ABLE.SHOW);
}else{
docEdit.setField1(Constants.NGKM_KNWLG_SHOW_ABLE.HIDE);
}
tKcDocEditDAO.insertSelective(docEdit);//保存知识
tKcCatalogDocRelDAO.insertSelective(catalogDocRel);//保存知识路径
KcDocGroupsDAO.insertSelective(docGroups);//保存分组
tKcDocRelationMapper.insert(tKcDocRelation);//保存知识关联表
iKcDocIndexSV.insertDocIndex(docEdit, tKcDocRelation);
for (TKcDocKeysWithBLOBs tKcDocKeysWithBLOBs : keysList) {
KcDocKeysDAO.insertSelective(tKcDocKeysWithBLOBs);
}
for (TKcRelateEdit tKcRelateEdit : tKcRelateEditList) {
tKcRelateEditMapper.insertSelective(tKcRelateEdit);//保存自定义标签表
}
tKcRelateEditList.clear();
keysList.clear();
relationSeqNo++;
number += 1;
}
if(number > 30){
throw new Exception("一次只允许导入30条数据");
}
}
}
response.setRspdesc("问答模板文件上传成功");
response.setRspcode(WebUtil.SUCCESS);
} else {
int lastRow = sheet.getLastRowNum();
for (int i = 1; i <= lastRow; i++) {
Row row = sheet.getRow(i);
TKcDocEdit docEdit = new TKcDocEdit();//问答知识对象
Long knwlgId = sequenceUtils.getSequence("t_kc_doc_edit");
docEdit.setKnwlgId(knwlgId);
docEdit.setSplitId(SplitId);
docEdit.setKnwlgType("1");//问答知识默认 1
docEdit.setVerno("v1");
docEdit.setKnwlgGathrTypeCd("1");
docEdit.setKnwlgStsCd("1E");
docEdit.setTenantId("-1");
docEdit.setIsSearchable("0");
docEdit.setOpStsCd(Constants.NGKM_KNOWLEDGE_OPERTYPE.INSERT);//操作类型
docEdit.setCreateTime(new Timestamp(System.currentTimeMillis()));
docEdit.setUpdateTime(new Timestamp(System.currentTimeMillis()));
docEdit.setUpdateUser(userInfo.getStaffCode());
docEdit.setCreateUser(userInfo.getStaffCode());
docEdit.setRegnId(userInfo.getScope());
docEdit.setField1(Constants.NGKM_KNWLG_SHOW_ABLE.SHOW);
docEdit.setField2(Constants.NGKM_KNWLG_UPDATE_CD.ADD);
TKcCatalogDocRel catalogDocRel = new TKcCatalogDocRel();//知识路径对象
Long rlId = sequenceUtils.getSequence("t_kc_catalog_doc_rel");
catalogDocRel.setRlId(rlId);
catalogDocRel.setKnwlgId(knwlgId);
catalogDocRel.setSplitId(SplitId);
catalogDocRel.setArgeSeqno(100);
catalogDocRel.setShowFlag("1");
catalogDocRel.setStsCd("1");
catalogDocRel.setTenantId("-1");
catalogDocRel.setCreateTime(new Timestamp(System.currentTimeMillis()));
catalogDocRel.setUpdateTime(new Timestamp(System.currentTimeMillis()));
catalogDocRel.setUpdateUser(userInfo.getStaffCode());
catalogDocRel.setCreateUser(userInfo.getStaffCode());
//知识标题
row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
String Knwlg_bt = row.getCell(0).getStringCellValue();
if ("".equals(Knwlg_bt)) {
throw new Exception("导入失败,知识标题(必填)");
}
docEdit.setKnwlgNm(Knwlg_bt);
//根据知识路径获取ID
row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
String catlNm = row.getCell(1).getStringCellValue();
if ("".equals(catlNm)) {
throw new Exception("导入失败,知识目录(必填)");
}
Long CatlId = Long.valueOf(iKcGetRemoteSV.getCatlIdByCatlNmJob(catlNm));
catalogDocRel.setCatlId(CatlId);
docEdit.setCatlIds(CatlId.toString());
row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
String KnwlgType = row.getCell(2).getStringCellValue();
if ("".equals(KnwlgType)) {
throw new Exception("导入失败,知识类别(必填)");
}
List<TKcStaticData> list = iKcGetRemoteSV.getCodeValueByTypeIdAndNameJob("NGKM.KNWLG.REGN.TYPE", KnwlgType);
if (list.size() == 0 || list.get(0).getDataValue() == null) {
throw new Exception("知识类别查询失败");
}
docEdit.setKnwlgRegnType(list.get(0).getDataValue());
//知识发布范围
row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
String DistrictConfigestr = row.getCell(3).getStringCellValue();
if ("".equals(DistrictConfigestr)) {
throw new Exception("导入失败,知识发布范围(必填)");
}
String[] DistrictConfigestrArr = DistrictConfigestr.split(",");
String AuthRegnNos = "";
for (int n = 0; n < DistrictConfigestrArr.length; n++) {
List<TKcDistrictConfig> DistrictConfigelist = iKcGetRemoteSV.getByRegnNmJob(DistrictConfigestrArr[n]);
if (DistrictConfigelist.size() == 0 || DistrictConfigelist.get(0).getRegnId() == null) {
throw new Exception("第" + (i + 1) + "行,知识发布:" + DistrictConfigestr + "不存在,请您确认是否正确");
}
AuthRegnNos += DistrictConfigelist.get(0).getRegnId() + ",";
}
docEdit.setAuthRegnNo(AuthRegnNos.substring(0, AuthRegnNos.length() - 1));
TKcTmpltInfo tKmTmpltInfo = iKcGetTmpltRemoteSV.selectTmpltByTmpltNmJob("问答模板");
if (tKmTmpltInfo == null) {
throw new Exception("知识模板查询失败");
}
docEdit.setTmpltId(tKmTmpltInfo.getTmpltId());
//知识渠道
row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
String StaticDatastr = row.getCell(4).getStringCellValue();
StringBuffer customTab=new StringBuffer(DistrictConfigestr);
customTab.append(",").append(KnwlgType).append(",").append(StaticDatastr).append(",问答知识,问答模板");
logger.info("---------------------生成自动标签:"+ customTab);
docEdit.setUrdfTabs(customTab.toString());
if ("".equals(StaticDatastr)) {
throw new Exception("导入失败,知识渠道(必填)");
}
String[] strArr = StaticDatastr.split(",");
String ChnlCode = "";
for (int n = 0; n < strArr.length; n++) {
List<TKcStaticData> list1 = iKcGetRemoteSV.getCodeValueByTypeIdAndNameJob("NGKM.TEMPLET.CHNL", strArr[n]);
if (list1.size() == 0 || list1.get(0).getDataValue() == null) {
throw new Exception("第" + (i + 1) + "行,知识渠道:" + StaticDatastr + "不存在,请您确认是否正确");
}
ChnlCode += list1.get(0).getDataValue() + ",";
}
String ChnlCodes = ChnlCode.substring(0, ChnlCode.length() - 1);
docEdit.setChnlCode(ChnlCodes);
//知识上线时间
Date KnwlgEffdate = null;
try {
KnwlgEffdate = row.getCell(5).getDateCellValue();//知识上线时间
} catch (Exception e) {
row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(5).getStringCellValue();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
KnwlgEffdate = format.parse(str);
}
docEdit.setKnwlgEffTime(KnwlgEffdate);
Date KnwlgInvlddate = null;
try {
KnwlgInvlddate = row.getCell(6).getDateCellValue();//知识下线时间
} catch (Exception e) {
row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(6).getStringCellValue();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
KnwlgInvlddate = format.parse(str);
}
docEdit.setKnwlgInvldTime(KnwlgInvlddate);
Date BusiEffdate = null;
try {
BusiEffdate = row.getCell(7).getDateCellValue();//业务上线时间
} catch (Exception e) {
row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(7).getStringCellValue();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
BusiEffdate = format.parse(str);
}
//临时注掉
// if (BusiEffdate == null) {
// throw new Exception("导入失败,业务上线时间(必填)");
// }
docEdit.setBusiEffTime(BusiEffdate);
Date BusiInvlddate = null;
try {
BusiInvlddate = row.getCell(8).getDateCellValue();//业务下线时间
} catch (Exception e) {
row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
String str = row.getCell(8).getStringCellValue();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
BusiInvlddate = format.parse(str);
}
docEdit.setBusiInvldTime(BusiInvlddate);
row.getCell(9).setCellType(Cell.CELL_TYPE_STRING);
String urdfTabsNms = row.getCell(9).getStringCellValue();//自定义标签
List<String> urdfTabsId = new ArrayList<>();
if (StringUtil.isNotEmpty(urdfTabsNms)) {
String[] strArrNm = urdfTabsNms.split(",");
for (String s : strArrNm) {
List<TKcCustomtabsInfo> tKcCustomtabsInfoList = iKcTagRemoteSV.getTagLibInfosByTagNmJob(s);
if (tKcCustomtabsInfoList == null || tKcCustomtabsInfoList.size() == 0) {
throw new Exception("不存在名称为【" + s + "】的标签");
}
urdfTabsId.add(tKcCustomtabsInfoList.get(0).getUrdfTabsId().toString());
}
}
List<TKcRelateEdit> tKcRelateEditList = new ArrayList<>();
for (String tabId : urdfTabsId) {
TKcRelateEdit tKcRelateEdit = new TKcRelateEdit();//自定义标签对象
Long rltId = sequenceUtils.getSequence("t_kc_relate_edit");
tKcRelateEdit.setRltId(rltId);
tKcRelateEdit.setKnwlgId(knwlgId);
tKcRelateEdit.setSplitId(SplitId);
tKcRelateEdit.setRltTypeCd(Constants.NGKM_KNOWLEDGE_RELATION_TYPE.KLG_RELATION_TAB);
tKcRelateEdit.setRltObjId(tabId);
tKcRelateEdit.setCreateTime(new Date());
tKcRelateEdit.setCreateUser(userInfo.getStaffCode());
tKcRelateEdit.setTenantId(userInfo.getTenantId());
tKcRelateEditList.add(tKcRelateEdit);
}
//默认是有的
TKcDocGroups docGroups = new TKcDocGroups();//分组对象
Long groupId = sequenceUtils.getSequence("t_kc_doc_groups");
docGroups.setGrpngId(groupId);
docGroups.setKnwlgId(knwlgId);
docGroups.setSplitId(SplitId);
List<TKcTmpltGroups> list2 = iKcGetTmpltRemoteSV.getTmpltGroupsByExampleJob(tKmTmpltInfo.getTmpltId(), "问答要素", "");
if (list2.size() == 0 || list2.get(0).getGrpngId() == null) {
throw new Exception("问答要素查询失败");
}
Long grpngId = list2.get(0).getGrpngId();
docGroups.setSrcTmpltGrpngId(grpngId);//原模板id
docGroups.setArgeSeqno(Short.parseShort("0"));
docGroups.setStsCd("1");
docGroups.setTenantId("-1");
// String group_str = row.getCell(10).getStringCellValue();
docGroups.setGrpngNm("问答要素");
docGroups.setUpdateTime(new Timestamp(System.currentTimeMillis()));
docGroups.setCreateTime(new Timestamp(System.currentTimeMillis()));
docGroups.setUpdateUser(userInfo.getStaffCode());
docGroups.setCreateUser(userInfo.getStaffCode());
// KcDocGroupsDAO.insertSelective(docGroups);//保存分组
TKcDocKeysWithBLOBs docKeys = new TKcDocKeysWithBLOBs();//问题原子
Long keyId = sequenceUtils.getSequence("t_kc_doc_keys");
docKeys.setKnwlgAttrAtomId(keyId);
docKeys.setKnwlgId(knwlgId);
docKeys.setGrpngId(groupId);
docKeys.setSplitId(SplitId);
docKeys.setParaNm("问题");
row.getCell(10).setCellType(Cell.CELL_TYPE_STRING);
String atom_val = row.getCell(10).getStringCellValue();
docKeys.setParaVal("");
docKeys.setCntt(atom_val);
if (StringUtils.isEmpty(atom_val)) {
continue;
}
boolean isRepeat = false;
if (qaKnwlgNm.contains(Knwlg_bt + atom_val)) {
throw new Exception("问答知识:" + Knwlg_bt + "在EXCEL中重复");
}
qaKnwlgNm.add(Knwlg_bt + atom_val);
isRepeat = isQaRepeat(atom_val, userInfo.getScope(), Knwlg_bt, ChnlCodes);
if (isRepeat) {
throw new Exception("问答知识:" + Knwlg_bt + "在数据库中重复");
}
TKcTmpltKeys queryQuesTmpltKey = new TKcTmpltKeys();
queryQuesTmpltKey.setParaNm("问题");
List<TKcTmpltKeys> TKmTmpltKeys_list = iKcGetTmpltRemoteSV.selectTmpltKeyByParamsJob(queryQuesTmpltKey);
if (TKmTmpltKeys_list.size() == 0 || TKmTmpltKeys_list.get(0).getAtomId() == null) {
throw new Exception("原子查询失败");
}
docKeys.setSrcTmpltAttrAtomId(TKmTmpltKeys_list.get(0).getAtomId());
docKeys.setParaTypeCd(TKmTmpltKeys_list.get(0).getParaTypeCd());//设置原子文本类型
docKeys.setAppTypeCd("0");
docKeys.setBrwsPriv("1");
docKeys.setArgeSeqno(1);
docKeys.setStsCd("1");
docKeys.setTenantId(userInfo.getTenantId());
docKeys.setCreateUser(userInfo.getStaffCode());
docKeys.setUpdateUser(userInfo.getStaffCode());
docKeys.setUpdateTime(new Timestamp(System.currentTimeMillis()));
docKeys.setCreateTime(new Timestamp(System.currentTimeMillis()));
row.getCell(11).setCellType(Cell.CELL_TYPE_STRING);
String kzwatom_val = row.getCell(11).getStringCellValue();//扩展问原子
TKcDocKeysWithBLOBs kzwdocKeys = new TKcDocKeysWithBLOBs();
Long kzwkeyId = sequenceUtils.getSequence("t_kc_doc_keys");
kzwdocKeys.setKnwlgAttrAtomId(kzwkeyId);
kzwdocKeys.setKnwlgId(knwlgId);
kzwdocKeys.setGrpngId(groupId);
kzwdocKeys.setSplitId(SplitId);
kzwdocKeys.setParaNm("扩展问");
kzwdocKeys.setParaVal("");
kzwdocKeys.setCntt(kzwatom_val);
TKcTmpltKeys queryKzQuesTmpltKey = new TKcTmpltKeys();
queryKzQuesTmpltKey.setParaNm("扩展问");
List<TKcTmpltKeys> kzwTKmTmpltKeys_list = iKcGetTmpltRemoteSV.selectTmpltKeyByParamsJob(queryKzQuesTmpltKey);
if (kzwTKmTmpltKeys_list.size() == 0 || kzwTKmTmpltKeys_list.get(0).getAtomId() == null) {
throw new Exception("原子查询失败");
}
kzwdocKeys.setSrcTmpltAttrAtomId(kzwTKmTmpltKeys_list.get(0).getAtomId());
kzwdocKeys.setParaTypeCd(kzwTKmTmpltKeys_list.get(0).getParaTypeCd());//设置原子文本类型
kzwdocKeys.setAppTypeCd("0");
kzwdocKeys.setBrwsPriv("1");
kzwdocKeys.setArgeSeqno(1);
kzwdocKeys.setStsCd("1");
kzwdocKeys.setTenantId(userInfo.getTenantId());
kzwdocKeys.setCreateUser(userInfo.getStaffCode());
kzwdocKeys.setUpdateUser(userInfo.getStaffCode());
kzwdocKeys.setUpdateTime(new Timestamp(System.currentTimeMillis()));
kzwdocKeys.setCreateTime(new Timestamp(System.currentTimeMillis()));
TKcDocKeysWithBLOBs dadocKeys = new TKcDocKeysWithBLOBs();//答案原子
Long dakeyId = sequenceUtils.getSequence("t_kc_doc_keys");
dadocKeys.setKnwlgAttrAtomId(dakeyId);
dadocKeys.setKnwlgId(knwlgId);
dadocKeys.setGrpngId(groupId);
dadocKeys.setSplitId(SplitId);
dadocKeys.setParaNm("答案");
row.getCell(12).setCellType(Cell.CELL_TYPE_STRING);
String daatom_val = row.getCell(12).getStringCellValue();
dadocKeys.setParaVal("");
dadocKeys.setCntt(daatom_val);
if (StringUtils.isEmpty(daatom_val)) {
continue;
}
TKcTmpltKeys queryAnswerKey = new TKcTmpltKeys();
List<TKcTmpltKeys> daTKmTmpltKeys_list = iKcGetTmpltRemoteSV.selectTmpltKeyByParamsJob(queryAnswerKey);
if (daTKmTmpltKeys_list.size() == 0 || daTKmTmpltKeys_list.get(0).getAtomId() == null) {
throw new Exception("原子查询失败");
}
dadocKeys.setSrcTmpltAttrAtomId(daTKmTmpltKeys_list.get(0).getAtomId());
dadocKeys.setParaTypeCd(daTKmTmpltKeys_list.get(0).getParaTypeCd());//设置原子文本类型
dadocKeys.setAppTypeCd("0");
dadocKeys.setBrwsPriv("1");
dadocKeys.setArgeSeqno(1);
dadocKeys.setStsCd("1");
dadocKeys.setTenantId(userInfo.getTenantId());
dadocKeys.setCreateUser(userInfo.getStaffCode());
dadocKeys.setUpdateUser(userInfo.getStaffCode());
dadocKeys.setUpdateTime(new Timestamp(System.currentTimeMillis()));
dadocKeys.setCreateTime(new Timestamp(System.currentTimeMillis()));
String relationId = String.valueOf(sequenceUtils.getSequence("t_kc_doc_relation"));
int relationSeqNo = 0;
TKcDocRelation tKcDocRelation = saveDocRelation(docEdit, relationId, relationSeqNo);
tKcDocRelationMapper.insert(tKcDocRelation);//保存知识关联表
tKcDocEditDAO.insertSelective(docEdit);//保存知识
tKcCatalogDocRelDAO.insertSelective(catalogDocRel);//保存知识路径
KcDocGroupsDAO.insertSelective(docGroups);//保存分组
for (TKcRelateEdit tKcRelateEdit : tKcRelateEditList) {
tKcRelateEditMapper.insertSelective(tKcRelateEdit);//保存自定义标签表
}
iKcDocIndexSV.insertDocIndex(docEdit, tKcDocRelation);
KcDocKeysDAO.insertSelective(docKeys);
KcDocKeysDAO.insertSelective(kzwdocKeys);
KcDocKeysDAO.insertSelective(dadocKeys);
number += 1;
if(number > 30){
throw new Exception("一次只允许导入30条数据");
}
}
response.setRspdesc("问答模板文件上传成功");
response.setRspcode(WebUtil.SUCCESS);
}
return response;
}
private boolean isQaRepeat(String atom_val, String provnce, String knwlgstr, String chnlCodes) {
Map<String, Object> condition = new HashMap<>();
condition.put(EsConstants.DOC_INDEX_FAIELD.KNWLG_NM, knwlgstr);//知识标题
condition.put(EsConstants.DOC_INDEX_FAIELD.REGN_ID, provnce);//地区
condition.put(EsConstants.DOC_INDEX_FAIELD.KNWLG_TYPE, Constants.NGKM_KNWLG_TYPE.QAKNWLG);
condition.put(EsConstants.DOC_INDEX_FAIELD.KNWLG_STS_CD, "1E,1A,2E,2A");//知识状态
List<Map<String, Object>> list = null;
try {
list = docIndexComponent.getDocIndex(condition);
} catch (Exception e) {
e.printStackTrace();
}
if(list != null){
for (int i = 0; i < list.size(); i++) {
TKcDocKeysExample example = new TKcDocKeysExample();
TKcDocKeysExample.Criteria TKcDocKeysCriteria = example.createCriteria();
TKcDocKeysCriteria.andKnwlgIdEqualTo(Long.parseLong((String)list.get(i).get(EsConstants.DOC_INDEX_FAIELD.KNWLG_ID)));
TKcDocKeysCriteria.andSplitIdEqualTo((String)list.get(i).get(EsConstants.DOC_INDEX_FAIELD.SPLIT_ID));
TKcDocKeysCriteria.andParaNmEqualTo("问题");
List<TKcDocKeysWithBLOBs> TKcDocKeysList = KcDocKeysDAO.selectByExampleWithBLOBs(example);
for (int j = 0; j < TKcDocKeysList.size(); j++) {
String cntt = TKcDocKeysList.get(j).getCntt();
if (atom_val.equals(cntt) && hasSameChanl(chnlCodes, (String)list.get(i).get(EsConstants.DOC_INDEX_FAIELD.CHNL_CODE))) {
return true;
}
}
}
}
return false;
}
private boolean hasSameChanl(String chanle, String chanl) {
if (StringUtil.isNotEmpty(chanl) && StringUtil.isNotEmpty(chanle)) {
String[] chanleArray = chanle.split(",");
String[] chanlArray = chanl.split(",");
for (String chanlIndex : chanlArray) {
for (String chanleIndex : chanleArray) {
if (chanlIndex.equals(chanleIndex)) {
return true;
}
}
}
}
return false;
}
private boolean isQaEmpty(List<TKcDocKeysWithBLOBs> keysList) {
boolean isQaEmpty = false;
for (TKcDocKeysWithBLOBs tKcDocKeysWithBLOBs : keysList) {
if (("问题".equals(tKcDocKeysWithBLOBs.getParaNm())||"答案".equals(tKcDocKeysWithBLOBs.getParaNm()))
&& StringUtil.isEmpty(tKcDocKeysWithBLOBs.getCntt())) {
isQaEmpty = true;
break;
}
}
return isQaEmpty;
}
public TKcDocRelation saveDocRelation(TKcDocEdit tKcDocEdit, String relationId, int relationSeqNo) throws Exception{
logger.info(".........................................关系ID:"+ relationId);
TKcDocRelation tKcDocRelation = new TKcDocRelation();
tKcDocRelation.setRelationSeq(sequenceUtils.getSequence("t_kc_doc_relation"));
tKcDocRelation.setRelationId(Long.parseLong(relationId));
tKcDocRelation.setSplitId(tKcDocEdit.getSplitId());
tKcDocRelation.setKnwlgId(tKcDocEdit.getKnwlgId());
tKcDocRelation.setKnwlgType(tKcDocEdit.getKnwlgType());
tKcDocRelation.setTenantId(tKcDocEdit.getTenantId());
tKcDocRelation.setAreaCode(tKcDocEdit.getAreaCode());
tKcDocRelation.setCityCode(tKcDocEdit.getCityCode());
tKcDocRelation.setCreateTime(tKcDocEdit.getCreateTime());
tKcDocRelation.setUpdateTime(tKcDocEdit.getUpdateTime());
tKcDocRelation.setCreateUser(tKcDocEdit.getUpdateUser());
tKcDocRelation.setUpdateUser(tKcDocEdit.getUpdateUser());
tKcDocRelation.setField1(String.valueOf(relationSeqNo));
return tKcDocRelation;
}
@Override
public List<TKcDocRelation> queryRelationKownledge(Long knwlgId, String splitId) {
List<TKcDocRelation>relationList = tKcDocRelationMapper.selectRelationKonwledge(String.valueOf(knwlgId), splitId);
Collections.sort(relationList, new Comparator<TKcDocRelation>() {
@Override
public int compare(TKcDocRelation o1, TKcDocRelation o2) {
int seqNo1 = StringUtil.isNotEmpty(o1.getField1()) ? Integer.parseInt(o1.getField1()) : 0;
int seqNo2 = StringUtil.isNotEmpty(o2.getField1()) ? Integer.parseInt(o2.getField1()) : 0;
return seqNo1 - seqNo2;
}
});
return relationList;
}
@Override
public List<TKcDocRelation> queryMulRelationKonwledge(Long knwlgId, String splitId) {
List<TKcDocRelation> relationList = tKcDocRelationMapper.selectMulRelationKonwledge(String.valueOf(knwlgId), splitId);
return relationList;
}
}
导入兼容ie8
设置单元格的格式-文本格式
HSSFCellStyle cellStyle2 = demoWorkBook.createCellStyle();
HSSFDataFormat format = demoWorkBook.createDataFormat();
cellStyle2.setDataFormat(format.getFormat("@"));
cell.setCellStyle(cellStyle2);
hutool工具类实现导出(大数据量)
- 引入pom依赖,2个依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.0.6</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.6</version>
</dependency>
- 代码
- 参考
hutool官网地址