|
@@ -84,82 +84,36 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
|
|
|
WbsTreePrivate privateInfo = wbsTreePrivateMapper.getByPKeyId(Func.toLong(textdictInfo.getTabId() + ""));
|
|
|
String htmlUrl = privateInfo.getHtmlUrl();
|
|
|
try {
|
|
|
- InputStream fileInputStream = FileUtils.getInputStreamByUrl(htmlUrl);
|
|
|
- String htmlString = IoUtil.readToString(fileInputStream);
|
|
|
- Document doc = Jsoup.parse(htmlString);
|
|
|
- Elements table = doc.getElementsByAttribute("dqid");
|
|
|
- List<String> dqid = new ArrayList<>();
|
|
|
- Map<String, String> dqIdMap = new HashMap<>();
|
|
|
- Map<String, String> keys = new HashMap<>();
|
|
|
- for(Element ek:table){
|
|
|
- List<String> list = Func.toStrList("\\|\\|", ek.attr("dqid"));
|
|
|
- dqid.addAll(list);
|
|
|
- Elements keyname = ek.getElementsByAttributeValueStarting("keyname", "key_");
|
|
|
- if (keyname != null && !keyname.isEmpty()) {
|
|
|
- String key = keyname.get(0).attr("keyname");
|
|
|
- for (String s : list) {
|
|
|
- dqIdMap.put(s, key);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Elements keyNames = doc.getElementsByAttribute("keyname");
|
|
|
- if(Func.isNotEmpty(keyNames)){
|
|
|
- for(Element keyName:keyNames){
|
|
|
- keys.put(keyName.attr("keyname"), keyName.attr("placeholder"));
|
|
|
- }
|
|
|
- }
|
|
|
if(Func.isNotEmpty(textdictInfo.getShowType()) && textdictInfo.getShowType() == 1){
|
|
|
- List<TextdictInfo> textdictInfos = new ArrayList<>();
|
|
|
- if(Func.isNotEmpty(dqid) && dqid.size() > 0){
|
|
|
- textdict = baseMapper.selectTextdictBYIds(dqid,privateInfo.getProjectId());
|
|
|
- // 系统推荐方案一:根据dqId、col_key和col_name查询
|
|
|
- textdict = getTextdictInfoByDqIdAndKeyName(textdict, dqIdMap, keys, textdictInfos);
|
|
|
- }else {
|
|
|
- // 系统推荐方法二:根据excel_id, col_key, col_name查询
|
|
|
- textdict = getTextDictInfoBySystem(textdictInfo, keys, textdict, doc, privateInfo, dqid);
|
|
|
+ textdict = baseMapper.selectTextDictInfoByProjectIdAndTabId(page, privateInfo);
|
|
|
+ if (textdict == null || textdict.isEmpty()) {
|
|
|
+ textdict = baseMapper.selectTextdictInfoByExcelIdAndProjectIdAndHtmlUrl(page, privateInfo);
|
|
|
}
|
|
|
- if (!keys.isEmpty()) {
|
|
|
- TextdictInfoVO temp = null;
|
|
|
- if (textdict != null && !textdict.isEmpty()) {
|
|
|
- temp = textdict.get(0);
|
|
|
- }
|
|
|
- if (temp == null) {
|
|
|
- temp = new TextdictInfoVO();
|
|
|
- temp.setProjectId(privateInfo.getProjectId());
|
|
|
- temp.setExcelId(privateInfo.getExcelId() + "");
|
|
|
- temp.setTabId(privateInfo.getPKeyId() + "");
|
|
|
- temp.setType(2);
|
|
|
- }
|
|
|
- // 查询电签库配置
|
|
|
- List<TextdictInfoVO> textdictConfigList = iSignConfigService.hasSignConfig(privateInfo.getInitTableName(), keys.keySet(), temp);
|
|
|
- saveSignTextDictInfo(textdictInfos, textdictConfigList, keys);
|
|
|
- if (textdict == null || textdict.isEmpty()) {
|
|
|
- textdict = textdictConfigList;
|
|
|
- } else {
|
|
|
- Map<String, Map<String, TextdictInfoVO>> map = textdict.stream().filter(vo -> vo.getColKey() != null && vo.getColKey().contains("__")).collect(Collectors.groupingBy(vo -> vo.getColKey().split("__")[1], Collectors.toMap(TextdictInfoVO::getSigRoleId, v -> v, (v1, v2) -> v1)));
|
|
|
- List<TextdictInfoVO> collect = textdictConfigList.stream().filter(textdictInfoVO -> {
|
|
|
- if (textdictInfoVO.getColKey() == null || !textdictInfoVO.getColKey().contains("__")) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- Map<String, TextdictInfoVO> voMap = map.get(textdictInfoVO.getColKey().split("__")[1]);
|
|
|
- if (voMap != null && !voMap.isEmpty() ) {
|
|
|
- return voMap.get(textdictInfoVO.getSigRoleId()) == null;
|
|
|
+ if (textdict != null && !textdict.isEmpty()) {
|
|
|
+ Map<String, TextdictInfoVO> map = textdict.stream().collect(Collectors.toMap(item -> item.getProjectId() + item.getTabId() + item.getColKey() + item.getColName(), item -> item, (v1, v2) -> v1));
|
|
|
+ textdict = new ArrayList<>(map.values());
|
|
|
+ InputStream fileInputStream = FileUtils.getInputStreamByUrl(htmlUrl);
|
|
|
+ String htmlString = IoUtil.readToString(fileInputStream);
|
|
|
+ Document doc = Jsoup.parse(htmlString);
|
|
|
+ for (TextdictInfoVO vo : textdict) {
|
|
|
+ Elements keyName = doc.getElementsByAttributeValue("keyname", vo.getColKey());
|
|
|
+ if (keyName == null || keyName.isEmpty()) {
|
|
|
+ vo.setIsMatch(0);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (Element element : keyName) {
|
|
|
+ String placeholder = element.attr("placeholder");
|
|
|
+ if (placeholder != null && !placeholder.equals(vo.getColName())) {
|
|
|
+ vo.setIsMatch(0);
|
|
|
+ } else {
|
|
|
+ vo.setIsMatch(1);
|
|
|
+ break;
|
|
|
}
|
|
|
- return true;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- textdict.addAll(collect);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
- if (!keys.isEmpty()) {
|
|
|
- // 根据excel_id 和col_key 查询
|
|
|
- List<TextdictInfoVO> textdictList= baseMapper.selectTextdictInfoByExcelIdAndColKey(textdictInfo.getExcelId(),keys.keySet());
|
|
|
- if (textdictList != null) {
|
|
|
- Map<String, TextdictInfoVO> map = textdictList.stream().filter(vo -> vo.getColName() != null && vo.getColName().equals(keys.get(vo.getColKey())))
|
|
|
- .collect(Collectors.toMap(vo -> vo.getColKey() + vo.getSigRoleId(), v -> v, (v1, v2) -> v1));
|
|
|
- textdict = new ArrayList<>(map.values());
|
|
|
- }
|
|
|
- }
|
|
|
+ textdict = baseMapper.selectTextdictInfoByExcelId(page, textdictInfo);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
@@ -170,180 +124,6 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
|
|
|
return page.setRecords(textdict);
|
|
|
}
|
|
|
|
|
|
- private void saveSignTextDictInfo(List<TextdictInfo> textdictInfos, List<TextdictInfoVO> textdictRecommendedList, Map<String, String> keys) {
|
|
|
- if (!textdictInfos.isEmpty()) {
|
|
|
- // 保存到数据库,从系统推荐中获取roleId
|
|
|
- if (textdictRecommendedList != null && !textdictRecommendedList.isEmpty()) {
|
|
|
- Map<String, TextdictInfoVO> map = textdictRecommendedList.stream().filter(vo -> vo.getColName() != null && vo.getColName().equals(keys.get(vo.getColKey()))).collect(Collectors.toMap(vo -> vo.getColKey() + vo.getSigRoleId(), v -> v, (v1, v2) -> v1));
|
|
|
- Collection<TextdictInfoVO> values = map.values();
|
|
|
- Map<String, TextdictInfo> collect = textdictInfos.stream().collect(Collectors.toMap(info -> info.getColKey() + info.getColName(), v -> v, (v1, v2) -> v1));
|
|
|
- for (TextdictInfoVO vo : values) {
|
|
|
- TextdictInfo info = collect.get(vo.getColKey() + vo.getColName());
|
|
|
- if (info != null) {
|
|
|
- vo.setId(info.getId());
|
|
|
- vo.setProjectId("0");
|
|
|
- BeanUtil.copyProperties(vo, info);
|
|
|
- vo.setIsSystem(2);
|
|
|
- }
|
|
|
- }
|
|
|
- List<TextdictInfo> list = textdictInfos.stream().filter(info -> StringUtil.hasText(info.getSigRoleId())).collect(Collectors.toList());
|
|
|
- this.saveBatch( list);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 系统推荐
|
|
|
- */
|
|
|
- @Nullable
|
|
|
- private List<TextdictInfoVO> getTextDictInfoBySystem(TextdictInfoVO textdictInfo, Map<String, String> keys, List<TextdictInfoVO> textdict, Document doc, WbsTreePrivate privateInfo, List<String> dqid) {
|
|
|
- // 根据excel_id 和col_key 查询
|
|
|
- List<TextdictInfoVO> textdictList= baseMapper.selectTextdictInfoByExcelIdAndColKey(textdictInfo.getExcelId(), keys.keySet());
|
|
|
- if (textdictList != null) {
|
|
|
- Map<String, TextdictInfoVO> map = textdictList.stream().filter(vo -> vo.getColName() != null && vo.getColName().equals(keys.get(vo.getColKey()))).collect(Collectors.toMap(vo -> vo.getColKey() + vo.getSigRoleId(), v -> v, (v1, v2) -> v1));
|
|
|
- textdictList = new ArrayList<>(map.values());
|
|
|
- }
|
|
|
- if (textdict.isEmpty()) {
|
|
|
- textdict = textdictList;
|
|
|
- if (textdict != null) {
|
|
|
- textdict.forEach(textdictInfoVO -> textdictInfoVO.setIsSystem(2));
|
|
|
- }
|
|
|
- addSign(textdict, doc, privateInfo, dqid, textdict);
|
|
|
- } else if (textdictList != null && !textdictList.isEmpty()) {
|
|
|
- Map<String, Map<String, TextdictInfoVO>> map = textdict.stream().filter(vo -> vo.getColKey() != null && vo.getColKey().contains("__")).collect(Collectors.groupingBy(vo -> vo.getColKey().split("__")[1], Collectors.toMap(TextdictInfoVO::getSigRoleId, v -> v, (v1, v2) -> v1)));
|
|
|
- List<TextdictInfoVO> collect = textdictList.stream().filter(textdictInfoVO -> {
|
|
|
- if (textdictInfoVO.getColKey() == null || !textdictInfoVO.getColKey().contains("__")) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- Map<String, TextdictInfoVO> voMap = map.get(textdictInfoVO.getColKey().split("__")[1]);
|
|
|
- textdictInfoVO.setIsSystem(2);
|
|
|
- if (voMap != null && !voMap.isEmpty() ) {
|
|
|
- return voMap.get(textdictInfoVO.getSigRoleId()) == null;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- textdict.addAll(collect);
|
|
|
- addSign(collect, doc, privateInfo, dqid, textdict);
|
|
|
- }
|
|
|
- return textdict;
|
|
|
- }
|
|
|
-
|
|
|
- @NotNull
|
|
|
- private List<TextdictInfoVO> getTextdictInfoByDqIdAndKeyName(List<TextdictInfoVO> textdict, Map<String, String> dqIdMap, Map<String, String> keys, List<TextdictInfo> textdictInfos) {
|
|
|
- if (textdict == null) {
|
|
|
- textdict = new ArrayList<>();
|
|
|
- }
|
|
|
- Map<String, TextdictInfoVO> idsMap = textdict.stream().collect(Collectors.toMap(item -> item.getId() + "", v -> v, (v1, v2) -> v2));
|
|
|
- Map<String, TextdictInfoVO> colKeyMap = textdict.stream().collect(Collectors.toMap(item -> item.getId() + "", v -> v, (v1, v2) -> v2));
|
|
|
- dqIdMap.forEach((k, v) -> {
|
|
|
- if (idsMap.containsKey(k) || colKeyMap.containsKey(v)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Long id = null;
|
|
|
- try {
|
|
|
- id = Long.parseLong(k);
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn(e.getMessage());
|
|
|
- }
|
|
|
- String colName = keys.get(v);
|
|
|
- if (id == null || v == null || colName == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- TextdictInfo info = new TextdictInfo();
|
|
|
- info.setId(id);
|
|
|
- info.setColKey(v);
|
|
|
- textdictInfos.add(info);
|
|
|
- });
|
|
|
- if (!textdictInfos.isEmpty()) {
|
|
|
- List<TextdictInfoVO> list = baseMapper.selectTextDictInfoByIdAndColKeyAndColName(textdictInfos);
|
|
|
- Map<String, List<TextdictInfoVO>> voMap = list.stream().collect(Collectors.groupingBy(item -> item.getId() + item.getColKey()));
|
|
|
- List<TextdictInfoVO> tempList = new ArrayList<>();
|
|
|
- voMap.forEach((key, values) -> {
|
|
|
- TextdictInfoVO temp = null;
|
|
|
- if (values.size() == 1) {
|
|
|
- temp = values.get(0);
|
|
|
- } else {
|
|
|
- for (TextdictInfoVO value : values) {
|
|
|
- String colName = keys.get(value.getColKey());
|
|
|
- if (colName == null || colName.equals(value.getColName())) {
|
|
|
- temp = value;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (temp == null) {
|
|
|
- // 出现次数最多
|
|
|
- Map<String, List<TextdictInfoVO>> collect = values.stream().collect(Collectors.groupingBy(TextdictInfoVO::getColName));
|
|
|
- temp = collect.entrySet().stream().max(Comparator.comparingInt(entry -> entry.getValue().size())).get().getValue().get(0);
|
|
|
- }
|
|
|
- }
|
|
|
- temp.setIsSystem(2);
|
|
|
- tempList.add(temp);
|
|
|
- colKeyMap.put(temp.getColKey(), temp);
|
|
|
- });
|
|
|
- textdict.addAll(tempList);
|
|
|
- textdictInfos.removeIf(item -> voMap.containsKey(item.getId() + item.getColKey()) || colKeyMap.containsKey(item.getColKey()));
|
|
|
- }
|
|
|
- return textdict;
|
|
|
- }
|
|
|
-
|
|
|
- private void addSign(List<TextdictInfoVO> collect, Document doc, WbsTreePrivate privateInfo, List<String> dqid,List<TextdictInfoVO> allTextdict) {
|
|
|
- if (collect == null || collect.isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (dqid != null && !dqid.isEmpty()) {
|
|
|
- collect = collect.stream().filter(textdictInfoVO -> !dqid.contains(textdictInfoVO.getId() + "")).collect(Collectors.toList());
|
|
|
- if (collect.isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- //解析
|
|
|
- Element table = doc.select("table").first();
|
|
|
- Elements trs = table.select("tr");
|
|
|
- AtomicBoolean isUpdate = new AtomicBoolean(false);
|
|
|
- Map<String, List<TextdictInfoVO>> colKeyMap = allTextdict.stream().collect(Collectors.groupingBy(TextdictInfoVO::getColKey));
|
|
|
- colKeyMap.forEach((colKey, textdictInfoVOs) -> {
|
|
|
- if (StringUtil.hasText(colKey)) {
|
|
|
- try {
|
|
|
- String[] trtd = colKey.split("__")[1].split("_");
|
|
|
- Element element = trs.get(Integer.parseInt(trtd[0])).select("td").get(Integer.parseInt(trtd[1]));
|
|
|
- String dqIds = textdictInfoVOs.stream().map(vo -> vo.getId() + "").distinct().collect(Collectors.joining("||"));
|
|
|
- if (StringUtil.hasText(dqIds)) {
|
|
|
- element.removeAttr("dqId");
|
|
|
- element.attr("dqId", dqIds);
|
|
|
- if (textdictInfoVOs.get(0).getType() == 2) { //个人签字 不能用户输入
|
|
|
- if (element.html().contains("el-tooltip")) {
|
|
|
- element.children().get(0).children().get(0).attr(":readonly", "true");
|
|
|
- } else {
|
|
|
- element.children().get(0).attr(":readonly", "true");
|
|
|
- }
|
|
|
- }
|
|
|
- isUpdate.set(true);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("解析失败: ", e);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- if (!isUpdate.get() || !SystemUtils.isLinux()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- try {
|
|
|
- String thmlUrl = privateInfo.getHtmlUrl().replace("Desktop//privateUrl", "Desktop/privateUrl");
|
|
|
- thmlUrl = thmlUrl.replace("\\", "\\\\");
|
|
|
- File file_out = ResourceUtil.getFile(thmlUrl);
|
|
|
- if(!file_out.exists()){
|
|
|
- FileUtils.ensureFileExists(thmlUrl);
|
|
|
- }
|
|
|
- File writefile = new File(thmlUrl);
|
|
|
- FileUtil.writeToFile(writefile, doc.html(), Boolean.parseBoolean("UTF-8"));
|
|
|
- wbsTreePrivateMapper.update(null,Wrappers.<WbsTreePrivate>lambdaUpdate().eq(WbsTreePrivate::getPKeyId, privateInfo.getPKeyId()).set(WbsTreePrivate::getHtmlUrl, thmlUrl));
|
|
|
- privateInfo.setHtmlUrl(thmlUrl);
|
|
|
- baseMapper.updateHtmlUrl(thmlUrl, privateInfo.getProjectId(), privateInfo.getPKeyId());
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public TextdictInfoVO selectTextdictInfoById(TextdictInfo textdictInfo) {
|
|
|
List<TextdictInfoVO> dataInfo = baseMapper.selectTextdictInfoById(textdictInfo.getId()+"");
|