|
@@ -1,27 +1,41 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import java.io.InputStream;
|
|
|
+import java.text.DecimalFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import org.apache.commons.lang.time.DateFormatUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+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.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.diagbot.client.UserServiceClient;
|
|
|
import com.diagbot.dto.GetRetrievalsByTagDTO;
|
|
|
import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.dto.RetrievalExcelImDTO;
|
|
|
import com.diagbot.dto.RetrievalListDTO;
|
|
|
+import com.diagbot.entity.QuestionInfo;
|
|
|
import com.diagbot.entity.Retrieval;
|
|
|
import com.diagbot.entity.RetrievalMapping;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.service.impl.RetrievalServiceImpl;
|
|
|
import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
import com.diagbot.util.UserUtils;
|
|
|
import com.diagbot.vo.AddTagRetrievalDetailVO;
|
|
|
import com.diagbot.vo.AddTagRetrievalVO;
|
|
@@ -40,6 +54,8 @@ public class RetrievalFacade extends RetrievalServiceImpl {
|
|
|
@Autowired
|
|
|
private RetrievalMappingFacade retrievalMappingFacade;
|
|
|
@Autowired
|
|
|
+ private QuestionInfoFacade questionInfoFacade;
|
|
|
+ @Autowired
|
|
|
private UserServiceClient userServiceClient;
|
|
|
|
|
|
/**
|
|
@@ -80,6 +96,11 @@ public class RetrievalFacade extends RetrievalServiceImpl {
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean addTagRetrieval(AddTagRetrievalVO addTagRetrievalVO) {
|
|
|
+ if(addTagRetrievalVO.getItemList().stream().distinct().count()!=addTagRetrievalVO.getItemList().size()){
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR,
|
|
|
+ "同义词中存在重复数据!");
|
|
|
+ }
|
|
|
+
|
|
|
Date now = DateUtil.now();
|
|
|
String userId = UserUtils.getCurrentPrincipleID();
|
|
|
|
|
@@ -166,14 +187,180 @@ public class RetrievalFacade extends RetrievalServiceImpl {
|
|
|
*/
|
|
|
public IPage<RetrievalListDTO> retrievalList(RetrievalListVO retrievalListVO) {
|
|
|
IPage<RetrievalListDTO> ipage = this.getRetrievalList(retrievalListVO);
|
|
|
- List<String> ids = ipage.getRecords().stream().map(i->i.getOperatorName()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<RetrievalListDTO> retrievalListDTOList = ipage.getRecords();
|
|
|
+ if(retrievalListDTOList.size()==0){
|
|
|
+ return ipage;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> questionIds = retrievalListDTOList.stream().map(i->i.getQuestionId()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ QueryWrapper<RetrievalMapping> retrievalMappingQe = new QueryWrapper<RetrievalMapping>();
|
|
|
+ retrievalMappingQe.in("question_id", questionIds);
|
|
|
+ List<RetrievalMapping> retrievalMappings = retrievalMappingFacade.list(retrievalMappingQe);
|
|
|
+ Map<Long,List<RetrievalMapping>> retrievalMappingListMap = retrievalMappings.stream().collect(Collectors.groupingBy(RetrievalMapping::getQuestionId));
|
|
|
+
|
|
|
+ List<Long> retrievalIds = retrievalMappings.stream().map(i->i.getRetrievalId()).distinct().collect(Collectors.toList());
|
|
|
+ Map<Long,Retrieval> retrievalMap = this.listByIds(retrievalIds).stream().filter(i->i.getIsDeleted().equals("N")).collect(Collectors.toMap(Retrieval::getId,i->i));
|
|
|
+
|
|
|
+ retrievalListDTOList.forEach(retrievalListDTO->{
|
|
|
+ List<RetrievalMapping> retrievalMappingList = retrievalMappingListMap.get(retrievalListDTO.getQuestionId());
|
|
|
+ retrievalMappingList = retrievalMappingList.stream().filter(i->retrievalMap.get(i.getRetrievalId())==null).sorted((t1,t2)->t2.getGmtModified().compareTo(t1.getGmtModified())).collect(Collectors.toList());
|
|
|
+ retrievalListDTO.setOperatorName(retrievalMappingList.get(0).getModifier());
|
|
|
+ retrievalListDTO.setRetrievalSelfName(retrievalMappingList.stream().filter(i->i.getShowType()==1&&i.getIsDeleted().equals("N")).map(i->retrievalMap.get(i.getRetrievalId()).getName()).collect(Collectors.joining()));
|
|
|
+ retrievalListDTO.setRetrievalNames(retrievalMappingList.stream().filter(i->i.getShowType()==2&&i.getIsDeleted().equals("N")).map(i->retrievalMap.get(i.getRetrievalId()).getName()).collect(Collectors.joining()));
|
|
|
+ retrievalListDTO.setRetrievalSonNames(retrievalMappingList.stream().filter(i->i.getShowType()==3&&i.getIsDeleted().equals("N")).map(i->retrievalMap.get(i.getRetrievalId()).getName()).collect(Collectors.joining()));
|
|
|
+ });
|
|
|
+
|
|
|
+ List<String> ids = retrievalListDTOList.stream().map(i->i.getOperatorName()).collect(Collectors.toList());
|
|
|
RespDTO<Map<String, String>> respDTO = userServiceClient.getUserInfoByIds(ids);
|
|
|
if (respDTO == null || !CommonErrorCode.OK.getCode().equals(respDTO.code)) {
|
|
|
throw new CommonException(CommonErrorCode.RPC_ERROR,
|
|
|
"获取用户信息失败");
|
|
|
}
|
|
|
- ipage.getRecords().forEach(i->i.setOperatorName(respDTO.data.get(i.getOperatorName())));
|
|
|
+
|
|
|
+ retrievalListDTOList.forEach(i->i.setOperatorName(respDTO.data.get(i.getOperatorName())));
|
|
|
+ ipage.setRecords(retrievalListDTOList);
|
|
|
return ipage;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同义词excel文件导入
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public RetrievalExcelImDTO retrievalExcelIm(MultipartFile file){
|
|
|
+ List<AddTagRetrievalVO> addTagRetrievalVOList = new ArrayList<>();
|
|
|
+ List<String> messages = new ArrayList<>();
|
|
|
+ InputStream inputStream = null;
|
|
|
+ Workbook wb = null;
|
|
|
+ try{
|
|
|
+ if(!file.isEmpty()){
|
|
|
+ inputStream = file.getInputStream();
|
|
|
+ if(inputStream.available() > 512000){
|
|
|
+ messages.add("文件最大支持500KB!");
|
|
|
+ }else{
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ if(fileName.lastIndexOf(".") != -1){
|
|
|
+ String type = fileName.substring(fileName.lastIndexOf("."));
|
|
|
+ if (type.equals(".xls")) {
|
|
|
+ wb = new HSSFWorkbook(inputStream);
|
|
|
+ } else if (type.equals(".xlsx")) {
|
|
|
+ wb = new XSSFWorkbook(inputStream);
|
|
|
+ }
|
|
|
+ if(wb!=null){
|
|
|
+ List<AddTagRetrievalDetailVO> detailList = new ArrayList<>();
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ int count = 0;
|
|
|
+ String questionName,retrievalName,retrievalSpell,retrievalType;
|
|
|
+ for(Row row : sheet){
|
|
|
+ count++;
|
|
|
+ if (count == 1||row==null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ questionName = getValue(row.getCell(0)).trim().replace(" ", "");
|
|
|
+ retrievalName = getValue(row.getCell(1)).trim().replace(" ", "");
|
|
|
+ retrievalSpell = getValue(row.getCell(2)).trim().replace(" ", "");
|
|
|
+ retrievalType = getValue(row.getCell(3)).trim().replace(" ", "");
|
|
|
+ if(StringUtil.isEmpty(questionName) || StringUtil.isEmpty(retrievalName)
|
|
|
+ || StringUtil.isEmpty(retrievalSpell) || StringUtil.isEmpty(retrievalType)){
|
|
|
+ messages.add("第"+count+"行数据不完整!");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ AddTagRetrievalDetailVO addTagRetrievalDetailVO = new AddTagRetrievalDetailVO();
|
|
|
+ addTagRetrievalDetailVO.setQuestionName(questionName);
|
|
|
+ addTagRetrievalDetailVO.setRetrievalName(retrievalName);
|
|
|
+ addTagRetrievalDetailVO.setRetrievalSpell(retrievalSpell);
|
|
|
+ addTagRetrievalDetailVO.setRetrievalType(Integer.parseInt(retrievalType));
|
|
|
+ detailList.add(addTagRetrievalDetailVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(detailList.size()>0){
|
|
|
+ List<String> questionNames = detailList.stream().map(i->i.getQuestionName()).distinct().collect(Collectors.toList());
|
|
|
+ QueryWrapper<QuestionInfo> questionInfoQe = new QueryWrapper<>();
|
|
|
+ questionInfoQe.in("tag_name",questionNames);
|
|
|
+ List<QuestionInfo> questionInfos = questionInfoFacade.list(questionInfoQe);
|
|
|
+ if(questionInfos.size()>0){
|
|
|
+ Map<String,Long> questionIdMap = questionInfos.stream().collect(Collectors.toMap(QuestionInfo::getTagName, i->i.getId()));
|
|
|
+ detailList.forEach(i->{
|
|
|
+ i.setQuestionId(questionIdMap.get(i.getQuestionName()));
|
|
|
+ });
|
|
|
+ Map<Long,List<AddTagRetrievalDetailVO>> detailMap = detailList.stream().collect(Collectors.groupingBy(AddTagRetrievalDetailVO::getQuestionId));
|
|
|
+ for(Long key : detailMap.keySet()){
|
|
|
+ AddTagRetrievalVO addTagRetrievalVO = new AddTagRetrievalVO();
|
|
|
+ addTagRetrievalVO.setQuestionId(key);
|
|
|
+ addTagRetrievalVO.setItemList(detailMap.get(key));
|
|
|
+ addTagRetrievalVOList.add(addTagRetrievalVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ messages.add("非excel文件无法解析!");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ messages.add("未知文件无法解析!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ messages.add("无文件上传!");
|
|
|
+ }
|
|
|
+ }catch(Exception e){
|
|
|
+ messages.add("解析失败!");
|
|
|
+ }finally{
|
|
|
+ try{
|
|
|
+ if(wb!=null){
|
|
|
+ wb.close();
|
|
|
+ }
|
|
|
+ if(inputStream!=null){
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+ }catch(Exception e){
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ addTagRetrievalVOList.forEach(i->{
|
|
|
+ addTagRetrieval(i);
|
|
|
+ });
|
|
|
+
|
|
|
+ RetrievalExcelImDTO retrievalExcelImDTO = new RetrievalExcelImDTO();
|
|
|
+ retrievalExcelImDTO.setMessages(messages);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("deprecation")
|
|
|
+ private String getValue(Cell cell) {
|
|
|
+ try {
|
|
|
+ Object obj = null;
|
|
|
+ switch (cell.getCellTypeEnum()) {
|
|
|
+ case BOOLEAN:
|
|
|
+ obj = cell.getBooleanCellValue();
|
|
|
+ break;
|
|
|
+ case ERROR:
|
|
|
+ obj = cell.getErrorCellValue();
|
|
|
+ break;
|
|
|
+ case NUMERIC:
|
|
|
+ if (HSSFDateUtil.isCellDateFormatted(cell)) {
|
|
|
+ Date date = cell.getDateCellValue();
|
|
|
+ obj = DateFormatUtils.format(date, "yyyy-MM-dd");
|
|
|
+ } else {
|
|
|
+ obj = cell.getNumericCellValue();
|
|
|
+ DecimalFormat df = new DecimalFormat("0");
|
|
|
+ obj = df.format(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+ // obj = cell.getNumericCellValue();
|
|
|
+ break;
|
|
|
+ case STRING:
|
|
|
+ obj = cell.getStringCellValue();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return obj.toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|