package com.point.strategy.fourCheck.service; import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.bstek.ureport.Utils; import com.bstek.ureport.export.ExportConfigure; import com.bstek.ureport.export.ExportConfigureImpl; import com.bstek.ureport.export.ExportManager; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.point.strategy.archiveNoSet.bean.ArchiveNoFormat; import com.point.strategy.archiveNoSet.mapper.ArchiveNoFormatMapper; import com.point.strategy.archiveNoSet.service.ArchiveNoFormatService; import com.point.strategy.bean.TentityStructDescription; import com.point.strategy.bean.TtableDescription; import com.point.strategy.bean.TtableStructDescription; import com.point.strategy.dao.TentityStructDescriptionMapper; import com.point.strategy.dao.TtableDescriptionMapper; import com.point.strategy.docSimpleArrange.mapper.DocSimpleMapper; import com.point.strategy.fourCheck.bean.FourCheck; import com.point.strategy.common.AjaxJson; import com.point.strategy.fourCheck.bean.FourCheckSetting; import com.point.strategy.fourCheck.bean.FourCheckStandard; import com.point.strategy.fourCheck.mapper.FourCheckMapper; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.lang.management.ManagementFactory; import java.text.SimpleDateFormat; import java.util.*; import com.point.strategy.fourCheck.mapper.FourCheckSettingMapper; import com.point.strategy.fourCheck.mapper.FourCheckStandardMapper; import com.point.strategy.metaData.bean.MetaDataEntity; import com.point.strategy.metaData.bean.MetadataStandard; import com.point.strategy.metaData.mapper.MetadataEntityMapper; import com.point.strategy.metaData.mapper.MetadataStandardMapper; import com.sun.management.OperatingSystemMXBean; import org.apache.commons.collections.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; @Service public class FourCheckService { @Autowired private FourCheckMapper fourCheckMapper; @Autowired FourCheckSettingMapper fourCheckSettingMapper; @Autowired FourCheckStandardMapper fourCheckStandardMapper; @Autowired TtableDescriptionMapper ttableDescriptionMapper; @Autowired DocSimpleMapper docSimpleMapper; @Autowired ArchiveNoFormatMapper archiveNoFormatMapper; @Autowired ArchiveNoFormatService archiveNoFormatService; @Autowired MetadataEntityMapper metadataEntityMapper; @Autowired TentityStructDescriptionMapper tentityStructDescriptionMapper; @Autowired MetadataStandardMapper metadataStandardMapper; private ObjectMapper objectMapper = new ObjectMapper(); private static final Logger logger = LoggerFactory.getLogger(FourCheckService.class); /** * 对超长字符串进行软换行,避免在PDF中单行过宽/过高造成分页异常。 * 简单实现:按固定列宽断行,同时保留已有的换行符。 */ private static List softWrap(String text, int maxCols) { List lines = new ArrayList<>(); if (text == null) { return lines; } String[] rawLines = text.replace("\r\n", "\n").replace('\r', '\n').split("\n", -1); for (String raw : rawLines) { if (raw.length() <= maxCols) { lines.add(raw); } else { int start = 0; while (start < raw.length()) { int end = Math.min(start + maxCols, raw.length()); lines.add(raw.substring(start, end)); start = end; } } } return lines; } @Transactional public AjaxJson addEntity(FourCheck entity) { AjaxJson result = null; try{ result = new AjaxJson<>(); int count = fourCheckMapper.insertSelective(entity); if(count != 1){ logger.error("FourCheckService=>FourCheck is error"); result = AjaxJson.returnExceptionInfo("新增失败"); } }catch (Exception e){ result = AjaxJson.returnExceptionInfo("新增失败:"+e); } return result; } @Transactional(readOnly=true) public FourCheck queryEntityById(Integer id) { return fourCheckMapper.selectByPrimaryKey(id); } @Transactional public AjaxJson updateEntity(FourCheck entity) { AjaxJson result = null; try { result = new AjaxJson<>(); int count = fourCheckMapper.updateByPrimaryKeySelective(entity); if(count != 1){ logger.error("FourCheckService=>FourCheck is error"); result = AjaxJson.returnExceptionInfo("更新失败"); } }catch (Exception e){ result = AjaxJson.returnExceptionInfo("更新失败:"+e); } return result; } @Transactional public AjaxJson deleteEntity(Integer id) { AjaxJson result = null; try { result = new AjaxJson<>(); int count = fourCheckMapper.deleteByPrimaryKey(id); if(count != 1){ logger.error("FourCheckService=>FourCheck is error"); result = AjaxJson.returnExceptionInfo("删除失败"); } }catch (Exception e){ result = AjaxJson.returnExceptionInfo("删除失败:"+e); } return result; } @Transactional(readOnly=true) public AjaxJson queryEntity(FourCheck entity) { AjaxJson result = null; try { PageHelper.startPage(entity.getPage(), entity.getLimit()); List list = fourCheckMapper.selectByRecord(entity); PageInfo pageInfo = new PageInfo(list); long total = pageInfo.getTotal(); result = new AjaxJson(); result.put("list", list); result.put("total", total); }catch (Exception e){ result = AjaxJson.returnExceptionInfo("查询失败:"+e); } return result; } public String findResultById(Integer id,Object path) { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); FourCheck fourCheck = fourCheckMapper.selectByPrimaryKey(id); JSONArray jsonObject = JSONArray.parseArray(fourCheck.getCheckResult()); JSONArray jSONArray1 = jsonObject; List> returnList = new ArrayList<>(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); List> mapListJson = (List)jSONArray1; for (Map map1 : mapListJson) { String typeChn, link = String.valueOf(map1.get("link")); String type = link.split("-")[1]; switch (type) { case "2": typeChn = "完整性"; break; case "3": typeChn = "可用性"; break; case "4": typeChn = "安全性"; break; default: typeChn = "真实性"; break; } map1.put("key", link); map1.put("checkItem", link); map1.put("type", typeChn); map1.put("userChnName", fourCheck.getCreatedBy()); map1.put("createdDate", dateFormat.format(fourCheck.getCreatedDate())); String checkLink = ""; switch (fourCheck.getCheckLink()) { case 0: checkLink = "数据接收环节"; break; case 1: checkLink = "未入库环节"; break; case 2: checkLink = "已入库环节"; break; } String dataFormat = ""; switch (fourCheck.getDataFormat()) { case 1: dataFormat = "目录文件"; break; case 2: dataFormat = "eep包"; break; case 3: dataFormat = "zip包"; break; } String pass = "通过"; if ("0".equals((new StringBuilder()).append(map1.get("pass")).append("").toString())) pass = "不通过"; Object msgObj = map1.get("msg"); // 将可能很长的列表消息拆分为多行/多条记录,避免单行过高导致 iText 无限循环异常 List msgLines = new ArrayList<>(); if (msgObj instanceof List) { for (Object o : (List) msgObj) { // 对每条内容进行软换行展开 msgLines.addAll(softWrap(String.valueOf(o), 60)); } } else if (msgObj instanceof com.alibaba.fastjson.JSONArray) { com.alibaba.fastjson.JSONArray arr = (com.alibaba.fastjson.JSONArray) msgObj; for (Object o : arr) { msgLines.addAll(softWrap(String.valueOf(o), 60)); } } else if (msgObj != null) { msgLines.addAll(softWrap(String.valueOf(msgObj), 60)); } // 分块,每块最多 N 行,避免某一行高度超过页面 final int CHUNK = 15; if (msgLines.isEmpty()) { Map row = new HashMap<>(); row.putAll(map1); row.put("type", typeChn); row.put("pass", pass); row.put("checkLink", checkLink); row.put("dataFormat", dataFormat); row.put("filePath", fourCheck.getFilePath()); row.put("createdDate", dateFormat.format(fourCheck.getCreatedDate())); row.put("userChnName", fourCheck.getCreatedBy()); row.put("msg", ""); returnList.add(row); } else { for (int i = 0; i < msgLines.size(); i += CHUNK) { int end = Math.min(i + CHUNK, msgLines.size()); String chunkText = String.join("\n", msgLines.subList(i, end)); Map row = new HashMap<>(); row.putAll(map1); row.put("type", typeChn); row.put("pass", pass); row.put("checkLink", checkLink); row.put("dataFormat", dataFormat); row.put("filePath", fourCheck.getFilePath()); row.put("createdDate", dateFormat.format(fourCheck.getCreatedDate())); row.put("userChnName", fourCheck.getCreatedBy()); row.put("msg", chunkText); returnList.add(row); } } } // Collections.sort(returnList, (Comparator>)new Object()); // String pathName = "E:/zzrsda/point-strategy/src/main/webapp/pdffile"; // String pathName = request.getRealPath("/") + "pdffile"; String pathName = ""; if(path==null){ pathName = request.getRealPath("/") + "pdffile"; }else{ pathName = (String)path; } // File file = new File(pathName); // if (file.isDirectory() && file.exists()) // FileUtil.delFile(file); // if (!file.exists()) // file.mkdirs(); Map map = new HashMap<>(); map.put("dataList", returnList); OutputStream outputStream = null; try { SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS"); String currentName = "fourcheck_" + df.format(new Date()); // 确保输出目录存在,避免因目录缺失导致 FileNotFoundException File outDir = new File(pathName); if (!outDir.exists()) { outDir.mkdirs(); } outputStream = new FileOutputStream(new File(pathName + File.separator + currentName + ".pdf")); ExportConfigureImpl exportConfigureImpl = new ExportConfigureImpl("file:四性检测报表.ureport.xml", map, outputStream); ExportManager exportManager = (ExportManager) Utils.getApplicationContext().getBean("ureport.exportManager"); exportManager.exportPdf((ExportConfigure)exportConfigureImpl); return currentName; } catch (Exception e) { logger.error("导出四性检测报表PDF失败(findResultById-默认路径)", e); } return null; } public String findResultById(Integer id,Object path,String filePath) { FourCheck fourCheck = fourCheckMapper.selectByPrimaryKey(id); JSONArray jsonObject = JSONArray.parseArray(fourCheck.getCheckResult()); JSONArray jSONArray1 = jsonObject; List> returnList = new ArrayList<>(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); List> mapListJson = (List)jSONArray1; for (Map map1 : mapListJson) { String typeChn, link = String.valueOf(map1.get("link")); String type = link.split("-")[1]; switch (type) { case "2": typeChn = "完整性"; break; case "3": typeChn = "可用性"; break; case "4": typeChn = "安全性"; break; default: typeChn = "真实性"; break; } map1.put("key", link); map1.put("checkItem", link); map1.put("type", typeChn); map1.put("userChnName", fourCheck.getCreatedBy()); map1.put("createdDate", dateFormat.format(fourCheck.getCreatedDate())); String checkLink = ""; switch (fourCheck.getCheckLink()) { case 0: checkLink = "数据接收环节"; break; case 1: checkLink = "未入库环节"; break; case 2: checkLink = "已入库环节"; break; } String dataFormat = ""; switch (fourCheck.getDataFormat()) { case 1: dataFormat = "目录文件"; break; case 2: dataFormat = "eep包"; break; case 3: dataFormat = "zip包"; break; } String pass = "通过"; if ("0".equals((new StringBuilder()).append(map1.get("pass")).append("").toString())) pass = "不通过"; Object msgObj = map1.get("msg"); List msgLines = new ArrayList<>(); if (msgObj instanceof List) { for (Object o : (List) msgObj) msgLines.addAll(softWrap(String.valueOf(o), 60)); } else if (msgObj instanceof com.alibaba.fastjson.JSONArray) { com.alibaba.fastjson.JSONArray arr = (com.alibaba.fastjson.JSONArray) msgObj; for (Object o : arr) msgLines.addAll(softWrap(String.valueOf(o), 60)); } else if (msgObj != null) { msgLines.addAll(softWrap(String.valueOf(msgObj), 60)); } final int CHUNK = 15; if (msgLines.isEmpty()) { Map row = new HashMap<>(); row.putAll(map1); row.put("type", typeChn); row.put("pass", pass); row.put("checkLink", checkLink); row.put("dataFormat", dataFormat); row.put("filePath", fourCheck.getFilePath()); row.put("createdDate", dateFormat.format(fourCheck.getCreatedDate())); row.put("userChnName", fourCheck.getCreatedBy()); row.put("msg", ""); returnList.add(row); } else { for (int i = 0; i < msgLines.size(); i += CHUNK) { int end = Math.min(i + CHUNK, msgLines.size()); String chunkText = String.join("\n", msgLines.subList(i, end)); Map row = new HashMap<>(); row.putAll(map1); row.put("type", typeChn); row.put("pass", pass); row.put("checkLink", checkLink); row.put("dataFormat", dataFormat); row.put("filePath", fourCheck.getFilePath()); row.put("createdDate", dateFormat.format(fourCheck.getCreatedDate())); row.put("userChnName", fourCheck.getCreatedBy()); row.put("msg", chunkText); returnList.add(row); } } } // Collections.sort(returnList, (Comparator>)new Object()); // String pathName = "E:/zzrsda/point-strategy/src/main/webapp/pdffile"; // String pathName = request.getRealPath("/") + "pdffile"; // File file = new File(pathName); // if (file.isDirectory() && file.exists()) // FileUtil.delFile(file); // if (!file.exists()) // file.mkdirs(); Map map = new HashMap<>(); map.put("dataList", returnList); OutputStream outputStream = null; try { SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS"); String currentName = "fourcheck_" + df.format(new Date()); // 确保输出目录存在 File outDir = new File(filePath); if (!outDir.exists()) { outDir.mkdirs(); } outputStream = new FileOutputStream(new File(filePath + File.separator + currentName + ".pdf")); ExportConfigureImpl exportConfigureImpl = new ExportConfigureImpl("file:四性检测报表.ureport.xml", map, outputStream); ExportManager exportManager = (ExportManager) Utils.getApplicationContext().getBean("ureport.exportManager"); exportManager.exportPdf((ExportConfigure)exportConfigureImpl); return currentName; } catch (Exception e) { logger.error("导出四性检测报表PDF失败(findResultById-指定路径)", e); } return null; } public String check(Map parameters) { HashMap mapTwo = new HashMap<>(); String checkLink = String.valueOf(parameters.get("checkLink").toString()); Integer classId = Integer.parseInt(parameters.get("classId").toString()) ; Integer entityId = Integer.parseInt(parameters.get("entityId").toString()); String fondscode = parameters.get("fondscode").toString(); Integer detection = (Integer)parameters.get("detection"); Object path = parameters.get("pathName"); // //勾选多个 // String ids = parameters.get("ids").toString(); //通过entityId来查询实体结构 AjaxJson ajaxJson = archiveNoFormatService.selectTableStructByclassId3(entityId); Map body = ajaxJson.getBody(); List list1 = (List) body.get("list1"); // List list1 = tentityStructDescriptionMapper.selectColumnNameByEntityId(entityId); //通过entityId来查询元数据实体表(t_metadata_entity) List metaDataEntities = metadataEntityMapper.selectByEntityId(entityId); List archivesNos = new ArrayList<>(); List archivesNosOne = new ArrayList<>(); List archivesNosTwo = new ArrayList<>(); List archivesNosThree = new ArrayList<>(); List archivesNosFour = new ArrayList<>(); String archivesNosFive = ""; //根据门类id和全宗来查询档号标准 ArchiveNoFormat archiveNoFormat = new ArchiveNoFormat(); archiveNoFormat.setClassId(classId); archiveNoFormat.setFondscode(fondscode); //根据当前年来确定年度范围 Calendar date = Calendar.getInstance(); String year = String.valueOf(date.get(Calendar.YEAR)); int pass = 1; int passOne = 1; int passTwo = 0; int passThree = 1; int passFour = 1; int passFive = 1; //2、元数据项数据长度检测 //3、元数据项数据类型、格式检测 for (MetaDataEntity metaDataEntity : metaDataEntities) { String entityField = metaDataEntity.getEntityField(); MetadataStandard standard = metadataStandardMapper.selectByPrimaryKey(metaDataEntity.getStandardId()); for (TtableStructDescription td : list1) { if(td.getColumnName().equals(entityField)){ if(standard.getFieldLength()==null || standard.getFieldLength().intValue() != td.getColumnWidth().intValue()){ passThree = 0; archivesNosThree.add(entityField + "国标长度为:" + standard.getFieldLength()); } Integer columnClass = td.getColumnClass(); String conlumnType = ""; switch (columnClass) { case 1: conlumnType = "字符型"; break; case 2: conlumnType = "整型"; break; case 3: conlumnType = "浮点型"; break; case 4: conlumnType = "时间类型(单个)"; break; case 5: conlumnType = "时间类型(范围)"; break; } if(!standard.getDataType().equals(conlumnType)){ passFour = 0; archivesNosFour.add(entityField + "国标类型为:" + standard.getDataType()); } } } } //软硬件环境合规性检测 OperatingSystemMXBean osmb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); long sizeTwo = osmb.getTotalPhysicalMemorySize(); sizeTwo = sizeTwo / 1024/1024/1024; if(sizeTwo<7){ passFive = 0; archivesNosFive = "本机运行内存小于8G"; } List> maps = archiveNoFormatService.selectYearScope(archiveNoFormat); List archiveNoFormats = new ArrayList<>(); if(CollectionUtils.isNotEmpty(maps)) { for (Map map : maps) { String yearScope = (String) map.get("yearScope"); String[] split = yearScope.split("-"); String filingYearStart = split[0]; String filingYearEnd = split[1]; if (Integer.valueOf(year).intValue() >= Integer.valueOf(filingYearStart).intValue() && Integer.valueOf(year).intValue() <= Integer.valueOf(filingYearEnd).intValue()) { archiveNoFormats = (List) map.get("list"); } } int size = archiveNoFormats.size(); //分隔符 String segmentSeparator = "-"; if(size!=0){ segmentSeparator = archiveNoFormats.get(0).getSegmentSeparator(); } TtableDescription ttableDescription = ttableDescriptionMapper.selectTtableDescription(entityId); String tableName = ttableDescription.getTableName(); if ("GD".equals(checkLink)||"GDD".equals(checkLink)) { tableName = tableName + "_temp"; } // List list = new ArrayList(); // if(StringUtils.isEmpty(ids)){ // //archive_flag = '已组卷' // mapTwo.put("tableName", tableName); // mapTwo.put("conditionSql", "1=1"); // list = docSimpleMapper.selectObject(mapTwo); // }else{ // String conditionSql = "id in (" + ids + ")"; // mapTwo.put("tableName", tableName); // mapTwo.put("conditionSql", conditionSql); // list = docSimpleMapper.selectObject(mapTwo); // } //archive_flag = '已组卷' mapTwo.put("tableName", tableName); mapTwo.put("conditionSql", "1=1"); List list =list = docSimpleMapper.selectObject(mapTwo); int pieceNum = 0; //检测档号规则 // for (Object o : list) { // Map archivesList = (Map) o; // //获取档号 // String archivesNo = (String) archivesList.get("archive_no"); // if(StringUtils.isEmpty(archivesNo)){ // archivesNo = (String) archivesList.get("folder_no"); // } // if(archivesNo.contains(segmentSeparator)){ // String[] split = archivesNo.split(segmentSeparator); // int length = split.length; // if (size == length) { // pass = 1; // } else { // pass = 0; // archivesNos.add(archivesNo + "档号规则不对"); // } // }else { // pass = 0; // archivesNos.add(archivesNo + "档号规则不对"); // } // // } //检测档号连续性 for (Object o : list) { Map archivesList = (Map) o; //获取档号 String archivesNo = (String) archivesList.get("archive_no"); if(StringUtils.isEmpty(archivesNo)){ archivesNo = (String) archivesList.get("folder_no"); } if(archivesNo!=null){ if(archivesNo.contains(segmentSeparator)){ String[] split = archivesNo.split(segmentSeparator); String aa = split[split.length-1]; if(StringUtils.isNumber(aa)){ int last = Integer.valueOf(split[split.length-1]); if (!(last - pieceNum == 1 || pieceNum == 0)) { passOne = 0; archivesNosOne.add(archivesNo + "档号连续性不对"); } pieceNum = last; }else { pass = 0; archivesNos.add(archivesNo + "档号规则不对"); } }else { pass = 0; archivesNos.add(archivesNo + "档号规则不对"); } } } //固化信息有效性检测 for (Object o : list) { Map archivesList = (Map) o; //获取档号 String archivesNo = (String) archivesList.get("archive_no"); //获取标志 String archivesFlag = (String) archivesList.get("archive_flag"); if(archivesNo==null){ archivesNo = ""; } if(archivesFlag==null){ archivesFlag = ""; } if(archivesFlag.equals("已组卷")||archivesFlag.equals("预归档未完成")){ passTwo = 1; }else { passTwo = 0; archivesNosTwo.add(archivesNo + "固化信息有效性"); } } } List> result = new ArrayList<>(); FourCheckSetting fourCheckSetting = new FourCheckSetting(); fourCheckSetting.setCheckLink(checkLink); if ("GDD".equals(checkLink)){ fourCheckSetting.setCheckLink("GD"); } List fourCheckSettings = fourCheckSettingMapper.queryForList(fourCheckSetting); for (FourCheckSetting checkSetting : fourCheckSettings) { String[] checkItems = checkSetting.getCheckItem().split(","); for (String checkItem : checkItems) { Map map = new HashMap<>(); FourCheckStandard fourCheckStandard = fourCheckStandardMapper.selectByNumber(checkItem); if(fourCheckStandard == null){ return "请先设置四性检测条目"; } String testItems = fourCheckStandard.getTestItems(); //根据规则来判断是否通过 // if("目标数据库中的元数据可访问性检测".equals(testItems)){ // if(CollectionUtils.isEmpty(metaDataEntities)){ // map.put("pass",0); // map.put("link",checkItem); // map.put("describe",testItems); // map.put("msg","元数据没有设置"); // result.add(map); // } // } if("系统环境中是否安装杀毒软件检测".equals(testItems)){ map.put("pass",detection); map.put("link",checkItem); map.put("describe",testItems); map.put("msg","需要人工检测杀毒软件"); result.add(map); } if("固化信息有效性检测".equals(testItems)){ map.put("pass",passTwo); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosTwo)){ try { map.put("msg",objectMapper.writeValueAsString(archivesNosTwo)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }else{ map.put("msg",""); } result.add(map); } if("元数据项数据长度检测".equals(testItems)){ map.put("pass",passThree); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosThree)){ try { map.put("msg",objectMapper.writeValueAsString(archivesNosThree)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }else{ map.put("msg",""); } result.add(map); } if("元数据项数据类型、格式检测".equals(testItems)){ map.put("pass",passFour); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosFour)){ try { map.put("msg",objectMapper.writeValueAsString(archivesNosFour)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }else{ map.put("msg",""); } result.add(map); } if("档号规范性检测".equals(testItems)){ map.put("pass",pass); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNos)){ try { map.put("msg",objectMapper.writeValueAsString(archivesNos)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }else{ map.put("msg",""); } result.add(map); } if("连续性元数据项检测".equals(testItems)){ map.put("pass",passOne); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosOne)){ try { map.put("msg",objectMapper.writeValueAsString(archivesNosOne)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }else{ map.put("msg",""); } result.add(map); } if("软硬件环境合规性检测".equals(testItems)){ map.put("pass",passFive); map.put("link",checkItem); map.put("describe",testItems); if(!StringUtils.isEmpty(archivesNosFive)){ try { map.put("msg",objectMapper.writeValueAsString(archivesNosFive)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }else{ map.put("msg",""); } result.add(map); } if(!("系统环境中是否安装杀毒软件检测".equals(testItems) || "固化信息有效性检测".equals(testItems) || "元数据项数据长度检测".equals(testItems) || "元数据项数据类型、格式检测".equals(testItems) ||"档号规范性检测".equals(testItems) || "连续性元数据项检测".equals(testItems)||"软硬件环境合规性检测".equals(testItems))){ map.put("pass",1); map.put("link",checkItem); map.put("describe",testItems); map.put("msg",""); result.add(map); } } } //先把检查的结果插入表中,然后回显到pdf上面 FourCheck fourCheck = new FourCheck(); if ("BC".equals(checkLink)) { fourCheck.setCheckLink(2); } else if("GD".equals(checkLink)) { fourCheck.setCheckLink(3); }else if("YJ".equals(checkLink)) { fourCheck.setCheckLink(1); }else if ("GDD".equals(checkLink)){ fourCheck.setCheckLink(0); } fourCheck.setDataFormat(1); fourCheck.setFilePath(""); fourCheck.setCreatedDate(new Date()); // fourCheck.setRecTotal(archivesList.size()); // fourCheck.setFailNum(failNum); fourCheck.setCheckResult(JSON.toJSONString(result)); fourCheckMapper.insert(fourCheck); Integer id = fourCheck.getId(); return findResultById(id,path); // return findResultById(1,request); } public String checkTime(Map parameters) { HashMap mapTwo = new HashMap<>(); String checkLink = String.valueOf(parameters.get("checkLink").toString()); Integer classId = Integer.parseInt(parameters.get("classId").toString()) ; Integer entityId = Integer.parseInt(parameters.get("entityId").toString()); String fondscode = parameters.get("fondscode").toString(); String filePath = parameters.get("filePath").toString(); Integer detection = (Integer)parameters.get("detection"); Object path = parameters.get("pathName"); // //勾选多个 // String ids = parameters.get("ids").toString(); //通过entityId来查询实体结构 AjaxJson ajaxJson = archiveNoFormatService.selectTableStructByclassId3(entityId); Map body = ajaxJson.getBody(); List list1 = (List) body.get("list1"); // List list1 = tentityStructDescriptionMapper.selectColumnNameByEntityId(entityId); //通过entityId来查询元数据实体表(t_metadata_entity) List metaDataEntities = metadataEntityMapper.selectByEntityId(entityId); List archivesNos = new ArrayList<>(); List archivesNosOne = new ArrayList<>(); List archivesNosTwo = new ArrayList<>(); List archivesNosThree = new ArrayList<>(); List archivesNosFour = new ArrayList<>(); String archivesNosFive = ""; //根据门类id和全宗来查询档号标准 ArchiveNoFormat archiveNoFormat = new ArchiveNoFormat(); archiveNoFormat.setClassId(classId); archiveNoFormat.setFondscode(fondscode); //根据当前年来确定年度范围 Calendar date = Calendar.getInstance(); String year = String.valueOf(date.get(Calendar.YEAR)); int pass = 1; int passOne = 1; int passTwo = 0; int passThree = 1; int passFour = 1; int passFive = 1; //2、元数据项数据长度检测 //3、元数据项数据类型、格式检测 for (MetaDataEntity metaDataEntity : metaDataEntities) { String entityField = metaDataEntity.getEntityField(); MetadataStandard standard = metadataStandardMapper.selectByPrimaryKey(metaDataEntity.getStandardId()); for (TtableStructDescription td : list1) { if(td.getColumnName().equals(entityField)){ if(standard.getFieldLength()==null || standard.getFieldLength().intValue() != td.getColumnWidth().intValue()){ passThree = 0; archivesNosThree.add(entityField + "国标长度为:" + standard.getFieldLength()); } Integer columnClass = td.getColumnClass(); String conlumnType = ""; switch (columnClass) { case 1: conlumnType = "字符型"; break; case 2: conlumnType = "整型"; break; case 3: conlumnType = "浮点型"; break; case 4: conlumnType = "时间类型(单个)"; break; case 5: conlumnType = "时间类型(范围)"; break; } if(!standard.getDataType().equals(conlumnType)){ passFour = 0; archivesNosFour.add(entityField + "国标类型为:" + standard.getDataType()); } } } } //软硬件环境合规性检测 OperatingSystemMXBean osmb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); long sizeTwo = osmb.getTotalPhysicalMemorySize(); sizeTwo = sizeTwo / 1024/1024/1024; if(sizeTwo<7){ passFive = 0; archivesNosFive = "本机运行内存小于8G"; } List> maps = archiveNoFormatService.selectYearScope(archiveNoFormat); List archiveNoFormats = new ArrayList<>(); if(CollectionUtils.isNotEmpty(maps)) { for (Map map : maps) { String yearScope = (String) map.get("yearScope"); String[] split = yearScope.split("-"); String filingYearStart = split[0]; String filingYearEnd = split[1]; if (Integer.valueOf(year).intValue() >= Integer.valueOf(filingYearStart).intValue() && Integer.valueOf(year).intValue() <= Integer.valueOf(filingYearEnd).intValue()) { archiveNoFormats = (List) map.get("list"); } } int size = archiveNoFormats.size(); //分隔符 String segmentSeparator = "-"; if(size!=0){ segmentSeparator = archiveNoFormats.get(0).getSegmentSeparator(); } TtableDescription ttableDescription = ttableDescriptionMapper.selectTtableDescription(entityId); String tableName = ttableDescription.getTableName(); if ("GD".equals(checkLink)||"GDD".equals(checkLink)) { tableName = tableName + "_temp"; } // List list = new ArrayList(); // if(StringUtils.isEmpty(ids)){ // //archive_flag = '已组卷' // mapTwo.put("tableName", tableName); // mapTwo.put("conditionSql", "1=1"); // list = docSimpleMapper.selectObject(mapTwo); // }else{ // String conditionSql = "id in (" + ids + ")"; // mapTwo.put("tableName", tableName); // mapTwo.put("conditionSql", conditionSql); // list = docSimpleMapper.selectObject(mapTwo); // } //archive_flag = '已组卷' mapTwo.put("tableName", tableName); mapTwo.put("conditionSql", "1=1"); List list =list = docSimpleMapper.selectObject(mapTwo); int pieceNum = 0; //检测档号规则 // for (Object o : list) { // Map archivesList = (Map) o; // //获取档号 // String archivesNo = (String) archivesList.get("archive_no"); // if(StringUtils.isEmpty(archivesNo)){ // archivesNo = (String) archivesList.get("folder_no"); // } // if(archivesNo.contains(segmentSeparator)){ // String[] split = archivesNo.split(segmentSeparator); // int length = split.length; // if (size == length) { // pass = 1; // } else { // pass = 0; // archivesNos.add(archivesNo + "档号规则不对"); // } // }else { // pass = 0; // archivesNos.add(archivesNo + "档号规则不对"); // } // // } //检测档号连续性 for (Object o : list) { Map archivesList = (Map) o; //获取档号 String archivesNo = (String) archivesList.get("archive_no"); if(StringUtils.isEmpty(archivesNo)){ archivesNo = (String) archivesList.get("folder_no"); } if(archivesNo!=null){ if(archivesNo.contains(segmentSeparator)){ String[] split = archivesNo.split(segmentSeparator); String aa = split[split.length-1]; if(StringUtils.isNumber(aa)){ int last = Integer.valueOf(split[split.length-1]); if (!(last - pieceNum == 1 || pieceNum == 0)) { passOne = 0; archivesNosOne.add(archivesNo + "档号连续性不对"); } pieceNum = last; }else { pass = 0; archivesNos.add(archivesNo + "档号规则不对"); } }else { pass = 0; archivesNos.add(archivesNo + "档号规则不对"); } } } //固化信息有效性检测 for (Object o : list) { Map archivesList = (Map) o; //获取档号 String archivesNo = (String) archivesList.get("archive_no"); //获取标志 String archivesFlag = (String) archivesList.get("archive_flag"); if(archivesNo==null){ archivesNo = ""; } if(archivesFlag==null){ archivesFlag = ""; } if(archivesFlag.equals("已组卷")||archivesFlag.equals("预归档未完成")){ passTwo = 1; }else { passTwo = 0; archivesNosTwo.add(archivesNo + "固化信息有效性"); } } } List> result = new ArrayList<>(); FourCheckSetting fourCheckSetting = new FourCheckSetting(); fourCheckSetting.setCheckLink(checkLink); if ("GDD".equals(checkLink)){ fourCheckSetting.setCheckLink("GD"); } List fourCheckSettings = fourCheckSettingMapper.queryForList(fourCheckSetting); for (FourCheckSetting checkSetting : fourCheckSettings) { String[] checkItems = checkSetting.getCheckItem().split(","); for (String checkItem : checkItems) { Map map = new HashMap<>(); FourCheckStandard fourCheckStandard = fourCheckStandardMapper.selectByNumber(checkItem); if(fourCheckStandard == null){ return "请先设置四性检测条目"; } String testItems = fourCheckStandard.getTestItems(); //根据规则来判断是否通过 // if("目标数据库中的元数据可访问性检测".equals(testItems)){ // if(CollectionUtils.isEmpty(metaDataEntities)){ // map.put("pass",0); // map.put("link",checkItem); // map.put("describe",testItems); // map.put("msg","元数据没有设置"); // result.add(map); // } // } if("系统环境中是否安装杀毒软件检测".equals(testItems)){ map.put("pass",detection); map.put("link",checkItem); map.put("describe",testItems); map.put("msg","需要人工检测杀毒软件"); result.add(map); } if("固化信息有效性检测".equals(testItems)){ map.put("pass",passTwo); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosTwo)){ map.put("msg",archivesNosTwo); }else{ map.put("msg",""); } result.add(map); } if("元数据项数据长度检测".equals(testItems)){ map.put("pass",passThree); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosThree)){ map.put("msg",archivesNosThree); }else{ map.put("msg",""); } result.add(map); } if("元数据项数据类型、格式检测".equals(testItems)){ map.put("pass",passFour); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosFour)){ map.put("msg",archivesNosFour); }else{ map.put("msg",""); } result.add(map); } if("档号规范性检测".equals(testItems)){ map.put("pass",pass); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNos)){ map.put("msg",archivesNos); }else{ map.put("msg",""); } result.add(map); } if("连续性元数据项检测".equals(testItems)){ map.put("pass",passOne); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosOne)){ map.put("msg",archivesNosOne); }else{ map.put("msg",""); } result.add(map); } if("软硬件环境合规性检测".equals(testItems)){ map.put("pass",passFive); map.put("link",checkItem); map.put("describe",testItems); if(!StringUtils.isEmpty(archivesNosFive)){ map.put("msg",archivesNosFive); }else{ map.put("msg",""); } result.add(map); } if(!("系统环境中是否安装杀毒软件检测".equals(testItems) || "固化信息有效性检测".equals(testItems) || "元数据项数据长度检测".equals(testItems) || "元数据项数据类型、格式检测".equals(testItems) ||"档号规范性检测".equals(testItems) || "连续性元数据项检测".equals(testItems)||"软硬件环境合规性检测".equals(testItems))){ map.put("pass",1); map.put("link",checkItem); map.put("describe",testItems); map.put("msg",""); result.add(map); } } } //先把检查的结果插入表中,然后回显到pdf上面 FourCheck fourCheck = new FourCheck(); if ("BC".equals(checkLink)) { fourCheck.setCheckLink(2); } else if("GD".equals(checkLink)) { fourCheck.setCheckLink(3); }else if("YJ".equals(checkLink)) { fourCheck.setCheckLink(1); }else if ("GDD".equals(checkLink)){ fourCheck.setCheckLink(0); } fourCheck.setDataFormat(1); fourCheck.setFilePath(""); fourCheck.setCreatedDate(new Date()); // fourCheck.setRecTotal(archivesList.size()); // fourCheck.setFailNum(failNum); fourCheck.setCheckResult(JSON.toJSONString(result)); fourCheckMapper.insert(fourCheck); Integer id = fourCheck.getId(); return findResultById(id,path,filePath); // return findResultById(1,request); } public List checkResult(Map parameters) { HashMap mapTwo = new HashMap<>(); String checkLink = String.valueOf(parameters.get("checkLink").toString()); Integer classId = Integer.parseInt(parameters.get("classId").toString()) ; Integer entityId = Integer.parseInt(parameters.get("entityId").toString()); String fondscode = parameters.get("fondscode").toString(); //Integer detection = Integer.parseInt(parameters.get("detection").toString()); Integer detection = (Integer)parameters.get("detection"); Object path = parameters.get("pathName"); // //勾选多个 // String ids = parameters.get("ids").toString(); //通过entityId来查询实体结构 AjaxJson ajaxJson = archiveNoFormatService.selectTableStructByclassId3(entityId); Map body = ajaxJson.getBody(); List list1 = (List) body.get("list1"); // List list1 = tentityStructDescriptionMapper.selectColumnNameByEntityId(entityId); //通过entityId来查询元数据实体表(t_metadata_entity) List metaDataEntities = metadataEntityMapper.selectByEntityId(entityId); List archivesNos = new ArrayList<>(); List archivesNosOne = new ArrayList<>(); List archivesNosTwo = new ArrayList<>(); List archivesNosThree = new ArrayList<>(); List archivesNosFour = new ArrayList<>(); String archivesNosFive = ""; //根据门类id和全宗来查询档号标准 ArchiveNoFormat archiveNoFormat = new ArchiveNoFormat(); archiveNoFormat.setClassId(classId); archiveNoFormat.setFondscode(fondscode); //根据当前年来确定年度范围 Calendar date = Calendar.getInstance(); String year = String.valueOf(date.get(Calendar.YEAR)); int pass = 1; int passOne = 1; int passTwo = 0; int passThree = 1; int passFour = 1; int passFive = 1; //2、元数据项数据长度检测 //3、元数据项数据类型、格式检测 for (MetaDataEntity metaDataEntity : metaDataEntities) { String entityField = metaDataEntity.getEntityField(); MetadataStandard standard = metadataStandardMapper.selectByPrimaryKey(metaDataEntity.getStandardId()); for (TtableStructDescription td : list1) { if(td.getColumnName().equals(entityField)){ if(standard.getFieldLength()==null || standard.getFieldLength().intValue() != td.getColumnWidth().intValue()){ passThree = 0; archivesNosThree.add(entityField + "国标长度为:" + standard.getFieldLength()); } Integer columnClass = td.getColumnClass(); String conlumnType = ""; switch (columnClass) { case 1: conlumnType = "字符型"; break; case 2: conlumnType = "整型"; break; case 3: conlumnType = "浮点型"; break; case 4: conlumnType = "时间类型(单个)"; break; case 5: conlumnType = "时间类型(范围)"; break; } if(!standard.getDataType().equals(conlumnType)){ passFour = 0; archivesNosFour.add(entityField + "国标类型为:" + standard.getDataType()); } } } } //软硬件环境合规性检测 OperatingSystemMXBean osmb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); long sizeTwo = osmb.getTotalPhysicalMemorySize(); sizeTwo = sizeTwo / 1024/1024/1024; if(sizeTwo<7){ passFive = 0; archivesNosFive = "本机运行内存小于8G"; } List> maps = archiveNoFormatService.selectYearScope(archiveNoFormat); List archiveNoFormats = new ArrayList<>(); if(CollectionUtils.isNotEmpty(maps)) { for (Map map : maps) { String yearScope = (String) map.get("yearScope"); String[] split = yearScope.split("-"); String filingYearStart = split[0]; String filingYearEnd = split[1]; if (Integer.valueOf(year).intValue() >= Integer.valueOf(filingYearStart).intValue() && Integer.valueOf(year).intValue() <= Integer.valueOf(filingYearEnd).intValue()) { archiveNoFormats = (List) map.get("list"); } } int size = archiveNoFormats.size(); //分隔符 String segmentSeparator = "-"; if(size!=0){ segmentSeparator = archiveNoFormats.get(0).getSegmentSeparator(); } TtableDescription ttableDescription = ttableDescriptionMapper.selectTtableDescription(entityId); String tableName = ttableDescription.getTableName(); if ("GD".equals(checkLink)) { tableName = tableName + "_temp"; } mapTwo.put("tableName", tableName); mapTwo.put("conditionSql", "1=1"); List list =list = docSimpleMapper.selectObject(mapTwo); int pieceNum = 0; //检测档号连续性 for (Object o : list) { Map archivesList = (Map) o; //获取档号 String archivesNo = (String) archivesList.get("archive_no"); if(StringUtils.isEmpty(archivesNo)){ archivesNo = (String) archivesList.get("folder_no"); } if(archivesNo!=null){ if(archivesNo.contains(segmentSeparator)){ String[] split = archivesNo.split(segmentSeparator); String aa = split[split.length-1]; if(StringUtils.isNumber(aa)){ int last = Integer.valueOf(split[split.length-1]); if (!(last - pieceNum == 1 || pieceNum == 0)) { passOne = 0; archivesNosOne.add(archivesNo + "档号连续性不对"); } pieceNum = last; }else { pass = 0; archivesNos.add(archivesNo + "档号规则不对"); } }else { pass = 0; archivesNos.add(archivesNo + "档号规则不对"); } } } //固化信息有效性检测 for (Object o : list) { Map archivesList = (Map) o; //获取档号 String archivesNo = (String) archivesList.get("archive_no"); //获取标志 String archivesFlag = (String) archivesList.get("archive_flag"); if(archivesNo==null){ archivesNo = ""; } if(archivesFlag==null){ archivesFlag = ""; } if(archivesFlag.equals("已组卷")||archivesFlag.equals("预归档未完成")){ passTwo = 1; }else { passTwo = 0; archivesNosTwo.add(archivesNo + "固化信息有效性"); } } } List> result = new ArrayList<>(); FourCheckSetting fourCheckSetting = new FourCheckSetting(); fourCheckSetting.setCheckLink(checkLink); List fourCheckSettings = fourCheckSettingMapper.queryForList(fourCheckSetting); for (FourCheckSetting checkSetting : fourCheckSettings) { String[] checkItems = checkSetting.getCheckItem().split(","); for (String checkItem : checkItems) { Map map = new HashMap<>(); FourCheckStandard fourCheckStandard = fourCheckStandardMapper.selectByNumber(checkItem); if(fourCheckStandard == null){ map.put("msg","请先设置四性检测条目"); result.add(map); return result; } String testItems = fourCheckStandard.getTestItems(); if("固化信息有效性检测".equals(testItems)){ map.put("pass",passTwo); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosTwo)){ map.put("msg",archivesNosTwo); }else{ map.put("msg",""); } result.add(map); } if("系统环境中是否安装杀毒软件检测".equals(testItems)){ map.put("pass",detection); map.put("link",checkItem); map.put("describe",testItems); map.put("msg","需要人工检测杀毒软件"); result.add(map); } if("元数据项数据长度检测".equals(testItems)){ map.put("pass",passThree); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosThree)){ map.put("msg",archivesNosThree); }else{ map.put("msg",""); } result.add(map); } if("元数据项数据类型、格式检测".equals(testItems)){ map.put("pass",passFour); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosFour)){ map.put("msg",archivesNosFour); }else{ map.put("msg",""); } result.add(map); } if("档号规范性检测".equals(testItems)){ map.put("pass",pass); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNos)){ map.put("msg",archivesNos); }else{ map.put("msg",""); } result.add(map); } if("连续性元数据项检测".equals(testItems)){ map.put("pass",passOne); map.put("link",checkItem); map.put("describe",testItems); if(CollectionUtils.isNotEmpty(archivesNosOne)){ map.put("msg",archivesNosOne); }else{ map.put("msg",""); } result.add(map); } if("软硬件环境合规性检测".equals(testItems)){ map.put("pass",passFive); map.put("link",checkItem); map.put("describe",testItems); if(!StringUtils.isEmpty(archivesNosFive)){ map.put("msg",archivesNosFive); }else{ map.put("msg",""); } result.add(map); } if(!("系统环境中是否安装杀毒软件检测".equals(testItems) || "固化信息有效性检测".equals(testItems) || "元数据项数据长度检测".equals(testItems) || "元数据项数据类型、格式检测".equals(testItems) ||"档号规范性检测".equals(testItems) || "连续性元数据项检测".equals(testItems)||"软硬件环境合规性检测".equals(testItems))){ map.put("pass",1); map.put("link",checkItem); map.put("describe",testItems); map.put("msg",""); result.add(map); } } } return result; } }