package com.zbooksoft.gdmis.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruili.wcp.common.CustomConfigUtil; import com.ruili.wcp.data.entity.config.View; import com.ruili.wcp.data.entity.management.User; import com.ruili.wcp.engine.ExpressionParser; import com.ruili.wcp.service.config.ViewService; import com.ruili.wcp.web.model.AjaxResponse; import com.ruili.wcp.web.model.ErrorInfo; import com.zbooksoft.gdmis.config.ArchivesCustomConfig; import com.zbooksoft.gdmis.data.entity.*; import com.zbooksoft.gdmis.service.*; import org.apache.commons.lang.StringUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.RequiresUser; import org.apache.shiro.session.Session; import org.apache.shiro.subject.Subject; import org.dom4j.Document; import org.dom4j.Element; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import java.io.File; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.zip.ZipFile; import static cn.hutool.core.util.ZipUtil.unzip; import static com.zbooksoft.gdmis.common.XmlUtil.getDocument; /** * @author 15280 secretLedger */ @Controller @RequestMapping("/catAjjxx") public class CatAjjxxController { @Autowired ViewService viewService; @Autowired JdbcTemplate jdbcTemplate; @Autowired CatYswjxxService catYswjxxService; @Autowired ReadXml2017Service readXml2017Service; @Autowired ReadXml2023Service readXml2023Service; @Autowired UpdateXml2017Service updateXml2017Service; @Autowired UpdateXml2023Service updateXml2023Service; @Autowired XmlService xmlService; @Autowired CheckQuestionService checkQuestionService; @Autowired SaveQuestionService saveQuestionService; @Autowired CustomConfigUtil customConfigUtil; @Autowired CatCheckService catCheckService; private static final Logger logger = LoggerFactory.getLogger(CatAjjxxController.class); /** * 小工具xml导入页面 * * @return */ @RequestMapping(value = "/importXmlIndex") @RequiresUser public ModelAndView importXmlIndex() { ArchivesCustomConfig archivesCustomConfig = customConfigUtil.getConfigObj(ArchivesCustomConfig.class); ModelAndView mv = new ModelAndView("gh/catAjjxx/importXmlIndex"); mv.addObject("archivesCustomConfig", archivesCustomConfig); return mv; } /** * XML导入 * * @param file * @param startData * @return */ @RequestMapping({"/importXML"}) @ResponseBody @RequiresUser public Object importXML(@RequestParam(value = "file", required = false) MultipartFile file, String startData, String endData) { try { ArchivesCustomConfig archivesCustomConfig = customConfigUtil.getConfigObj(ArchivesCustomConfig.class); String uploadPath = archivesCustomConfig.getOriginalPath(); //判断传过来的文件是不是压缩包 if (file.getOriginalFilename().endsWith(".zip")) { String tempDir = System.getProperty("java.io.tmpdir"); String extractPath = tempDir + File.separator + "temp_" + System.currentTimeMillis(); File extractDir = new File(extractPath); extractDir.mkdirs(); String originalFilename = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")); try { // 保存上传的 ZIP 文件到临时位置 File zipFile = new File(extractPath + File.separator + file.getOriginalFilename()); file.transferTo(zipFile); // 解压 ZIP 文件 unzip(zipFile.getAbsolutePath(), uploadPath); String xmlPath = uploadPath + File.separator + originalFilename + File.separator + "管理性文件" + File.separator + "资料文件目录.xml"; Document document = getDocument(xmlPath); xmlService.readXml(document, startData, endData); } finally { // 清理临时文件 deleteDir(extractDir); } } else { Document document = getDocument(file); xmlService.readXml(document, startData, endData); } return new AjaxResponse(true); } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * xml更新页面 * * @return */ @RequestMapping(value = "/updateXmlIndex") @RequiresUser public ModelAndView updateXmlIndex() { ModelAndView mv = new ModelAndView("gh/catAjjxx/updateXmlIndex"); return mv; } /** * 需更新xml文件 * * @param file * @param checkData * @param ajId * @return */ @RequestMapping({"/updateXML"}) @ResponseBody @RequiresUser public Object updateXML(@RequestParam(value = "file", required = false) MultipartFile file, String checkData, String ajId) { try { Document document = getDocument(file); Long updateId = Long.parseLong(ajId); Element rootElement = document.getRootElement(); String rootName = rootElement.getName(); if ("AJXX".equals(rootName)) { updateXml2017Service.updateXml(document, checkData, updateId); } else if ("DZZLXX".equals(rootName)) { updateXml2023Service.updateXml(document, checkData, updateId); } if (checkData != null && !"".equals(checkData)) { QueryWrapper catCheckQueryWrapper = new QueryWrapper<>(); catCheckQueryWrapper.eq("aj_id", Long.parseLong(ajId)); catCheckQueryWrapper.isNull("check_date"); CatCheck catCheck = catCheckService.getOne(catCheckQueryWrapper); catCheck.setAjId(Long.parseLong(ajId)); // catCheck.setCheckDate(stringToDate(checkData)); catCheckService.saveOrUpdate(catCheck); } return new AjaxResponse(true); } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * XML导入 * * @param file * @param startData * @return */ @RequestMapping({"/importBaoPanXML"}) @ResponseBody @RequiresUser public Object importBaoPanXML(@RequestParam(value = "file", required = false) MultipartFile file, String startData, String endData) { try { Document document = getDocument(file); Element rootElement = document.getRootElement(); String rootName = rootElement.getName(); //暂时不判断重复 if ("AJXX".equals(rootName)) { readXml2017Service.readXml(document, startData, endData); } else if ("DZZLXX".equals(rootName)) { readXml2023Service.readXml(document, startData, endData); } return new AjaxResponse(true); } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * 关联附件 * * @param viewId * @param idList * @return */ @RequestMapping({"/relationFile"}) @ResponseBody @RequiresUser public AjaxResponse relationFile(Long viewId, @RequestBody List idList) { try { //查询业务数据 //获取文件信息 Map resultMap = new HashMap<>(); int ysTotal = 0; int ysSuccess = 0; int ysFailed = 0; ArchivesCustomConfig archivesCustomConfig = customConfigUtil.getConfigObj(ArchivesCustomConfig.class); View view = viewService.getViewById(viewId); String strIds = ""; String strParam = ""; if (idList != null && idList.size() > 0) { strIds = " and id in( " + StringUtils.join(idList, ",") + ")"; } else { String sqlWhere = view.getSqlWhere(); if (sqlWhere != null && !"".equals(sqlWhere)) { //添加表达式解析,去掉${CurUserName}等之类的参数 if (sqlWhere.contains("$")) { ExpressionParser expressionParser = new ExpressionParser(); sqlWhere = expressionParser.parsing(sqlWhere); } strParam = " and " + sqlWhere; } } String strSql = "select * from " + view.getMainTableName() + " where 1=1 " + strIds + strParam; // 查询业务数据 List> list = jdbcTemplate.queryForList(strSql); // String uploadPath = archivesCustomConfig.getOriginalPath(); String newUploadPath = archivesCustomConfig.getViewPath(); String provinceCode = archivesCustomConfig.getProvinceCode(); for (Map map : list) { String pathIn = ""; String sgdh = map.get("SGDH").toString(); boolean enableSimple = archivesCustomConfig.getEnableSimple(); if (enableSimple) { pathIn = sgdh; } else { //取第一层文件夹(省馆档号取前三位,形成5位数字前加hn) String pr = sgdh.substring(0, 3); int num = Integer.parseInt(pr); String fistFileName = String.format("%05d", num); pathIn = provinceCode + fistFileName + "/"; //取第二层文件夹(省馆档号,形成6位数字前加hn) String secondFileName = String.format("%06d", Long.parseLong(sgdh)); pathIn = pathIn + provinceCode + secondFileName; } //d/省馆档号 String filePath = uploadPath + pathIn + File.separator; String newFilePath = newUploadPath + sgdh + File.separator; Long id = Long.parseLong(map.get("ID").toString()); QueryWrapper catCgwjxxQueryWrapper = new QueryWrapper<>(); catCgwjxxQueryWrapper.eq("aj_id", id); //d/省馆档号/ String path = filePath + "源电子文件"; String cdPath = filePath + "存档电子文件"; String newCdPath = newFilePath + "存档电子文件"; QueryWrapper catYswjxxQueryWrapper = new QueryWrapper<>(); catYswjxxQueryWrapper.eq("aj_id", id); List catYswjxxList = catYswjxxService.list(catYswjxxQueryWrapper); String ysPath = filePath + "原始资料电子文件"; String newYsPath = newFilePath + "原始资料电子文件"; ysTotal += catYswjxxList.size(); for (CatYswjxx catYswjxx : catYswjxxList) { String wjm = catYswjxx.getWjm(); String yswjPath = ysPath + File.separator + wjm; String newYswjPath = newYsPath + File.separator + wjm; File file = new File(yswjPath); if (file.exists() && file.isFile()) { catYswjxx.setWjlj(yswjPath); ysSuccess++; } else { ysFailed++; } catYswjxxService.saveOrUpdate(catYswjxx); } } resultMap.put("ysTotal", ysTotal); resultMap.put("ysSuccess", ysSuccess); resultMap.put("ysFailed", ysFailed); AjaxResponse ajaxResponse = new AjaxResponse(true); if (resultMap != null) { StringBuilder sb = new StringBuilder(); sb.append("top.layer.open({"); sb.append(" title : '提示',"); sb.append(" type : 2,"); sb.append(" area : [ '700px', '180px' ],"); sb.append(" fixed : true, "); sb.append(" content : 'common/relationFileTips?ysTotal=" + resultMap.get("ysTotal") + "&ysSuccess=" + resultMap.get("ysSuccess") + "&ysFailed=" + resultMap.get("ysFailed") + "'"); sb.append("});"); Map result = new HashMap(); result.put("jsExpression", sb.toString()); ajaxResponse.setResult(result); } return ajaxResponse; } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * 关联附件 * * @param viewId * @param idList * @return */ @RequestMapping({"/relationFiles"}) @ResponseBody @RequiresUser public AjaxResponse relationFiles(Long viewId, @RequestBody List idList) { try { //查询业务数据 //获取文件信息 Map resultMap = new HashMap<>(); int ysTotal = 0; int ysSuccess = 0; int ysFailed = 0; ArchivesCustomConfig archivesCustomConfig = customConfigUtil.getConfigObj(ArchivesCustomConfig.class); View view = viewService.getViewById(viewId); String strIds = ""; String strParam = ""; if (idList != null && idList.size() > 0) { strIds = " and id in( " + StringUtils.join(idList, ",") + ")"; } else { String sqlWhere = view.getSqlWhere(); if (sqlWhere != null && !"".equals(sqlWhere)) { //添加表达式解析,去掉${CurUserName}等之类的参数 if (sqlWhere.contains("$")) { ExpressionParser expressionParser = new ExpressionParser(); sqlWhere = expressionParser.parsing(sqlWhere); } strParam = " and " + sqlWhere; } } String strSql = "select * from " + view.getMainTableName() + " where 1=1 " + strIds + strParam; // 查询业务数据 List> list = jdbcTemplate.queryForList(strSql); // String uploadPath = archivesCustomConfig.getOriginalPath(); for (Map map : list) { // String dh = map.get("DH").toString(); String dh = map.get("XMKYQBH").toString()+"["+map.get("XMKYQMC")+"]"; //d/省馆档号 String filePath = uploadPath + dh + File.separator + "电子文件" + File.separator; Long id = Long.parseLong(map.get("ID").toString()); QueryWrapper catYswjxxQueryWrapper = new QueryWrapper<>(); catYswjxxQueryWrapper.eq("aj_id", id); List catYswjxxList = catYswjxxService.list(catYswjxxQueryWrapper); ysTotal += catYswjxxList.size(); for (CatYswjxx catYswjxx : catYswjxxList) { String yswjPath = ""; String wjtm = catYswjxx.getWjtm(); String wjgs = catYswjxx.getWjgs(); if (wjgs != null && !"".equals(wjgs)) { String wjm = wjtm + wjgs; yswjPath = filePath + wjm; } else { yswjPath = filePath + wjtm; } File file = new File(yswjPath); if (file.exists()) { Long folderSize = getFolderSize(file); double fileSizeMB = (double) folderSize / 1024 / 1024; String fileSizeStr = String.format("%.2f", fileSizeMB); catYswjxx.setWjdx(fileSizeStr); catYswjxx.setWjlj(yswjPath); ysSuccess++; } catYswjxx.setWjm(wjtm); catYswjxxService.saveOrUpdate(catYswjxx); } } resultMap.put("ysTotal", ysTotal); resultMap.put("ysSuccess", ysSuccess); resultMap.put("ysFailed", ysFailed); AjaxResponse ajaxResponse = new AjaxResponse(true); if (resultMap != null) { StringBuilder sb = new StringBuilder(); sb.append("top.layer.open({"); sb.append(" title : '提示',"); sb.append(" type : 2,"); sb.append(" area : [ '700px', '180px' ],"); sb.append(" fixed : true, "); sb.append(" content : 'common/relationFileTips?ysTotal=" + resultMap.get("ysTotal") + "&ysSuccess=" + resultMap.get("ysSuccess") + "&ysFailed=" + resultMap.get("ysFailed") + "'"); sb.append("});"); Map result = new HashMap(); result.put("jsExpression", sb.toString()); ajaxResponse.setResult(result); } return ajaxResponse; } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * 关联附件 * * @param viewId * @param idList * @return */ @RequestMapping({"/digitalRelationFiles"}) @ResponseBody @RequiresUser public AjaxResponse digitalRelationFiles(Long viewId, @RequestBody List idList) { try { //查询业务数据 //获取文件信息 Map resultMap = new HashMap<>(); int ysTotal = 0; int ysSuccess = 0; int ysFailed = 0; ArchivesCustomConfig archivesCustomConfig = customConfigUtil.getConfigObj(ArchivesCustomConfig.class); View view = viewService.getViewById(viewId); String strIds = ""; String strParam = ""; if (idList != null && idList.size() > 0) { strIds = " and id in( " + StringUtils.join(idList, ",") + ")"; } else { String sqlWhere = view.getSqlWhere(); if (sqlWhere != null && !"".equals(sqlWhere)) { //添加表达式解析,去掉${CurUserName}等之类的参数 if (sqlWhere.contains("$")) { ExpressionParser expressionParser = new ExpressionParser(); sqlWhere = expressionParser.parsing(sqlWhere); } strParam = " and " + sqlWhere; } } String strSql = "select * from " + view.getMainTableName() + " where 1=1 " + strIds + strParam; // 查询业务数据 List> list = jdbcTemplate.queryForList(strSql); // String uploadPath = archivesCustomConfig.getOriginalPath(); for (Map map : list) { String dh = map.get("DH").toString(); //d/省馆档号 String filePath = uploadPath + dh + File.separator; Long id = Long.parseLong(map.get("ID").toString()); QueryWrapper catYswjxxQueryWrapper = new QueryWrapper<>(); catYswjxxQueryWrapper.eq("aj_id", id); List catYswjxxList = catYswjxxService.list(catYswjxxQueryWrapper); ysTotal += catYswjxxList.size(); for (CatYswjxx catYswjxx : catYswjxxList) { String wjDh = catYswjxx.getDh(); String yswjPath = ""; yswjPath = filePath + wjDh + File.separator + wjDh + ".pdf"; File file = new File(yswjPath); if (file.exists() && file.isFile()) { long fileSize = file.length(); double fileSizeMB = fileSize / (1024.0 * 1024.0); String fileSizeStr = String.format("%.2f", fileSizeMB); catYswjxx.setWjdx(fileSizeStr); catYswjxx.setWjgs(".pdf"); catYswjxx.setWjlj(yswjPath); catYswjxx.setWjm(wjDh); ysSuccess++; } else { ysFailed++; } catYswjxxService.saveOrUpdate(catYswjxx); } } resultMap.put("ysTotal", ysTotal); resultMap.put("ysSuccess", ysSuccess); resultMap.put("ysFailed", ysFailed); AjaxResponse ajaxResponse = new AjaxResponse(true); if (resultMap != null) { StringBuilder sb = new StringBuilder(); sb.append("top.layer.open({"); sb.append(" title : '提示',"); sb.append(" type : 2,"); sb.append(" area : [ '700px', '180px' ],"); sb.append(" fixed : true, "); sb.append(" content : 'common/relationFileTips?ysTotal=" + resultMap.get("ysTotal") + "&ysSuccess=" + resultMap.get("ysSuccess") + "&ysFailed=" + resultMap.get("ysFailed") + "'"); sb.append("});"); Map result = new HashMap(); result.put("jsExpression", sb.toString()); ajaxResponse.setResult(result); } return ajaxResponse; } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * 档案验收页面 * * @return */ @RequestMapping(value = "/checkIndex") @RequiresUser public ModelAndView acceptanceIndex() { ModelAndView mv = new ModelAndView("gh/catAjjxx/checkIndex"); return mv; } /** * 添加验收问题 * * @return */ @RequestMapping({"/SaveQuestion"}) @ResponseBody @RequiresUser public Object SaveQuestion(@RequestBody Map postData) { try { Long id = Long.parseLong(postData.get("id").toString()); String selectSql = "SELECT * FROM BUS_TRANSFER_LOG WHERE ID =" + id; Map map = jdbcTemplate.queryForMap(selectSql); Object ajId = map.get("AJ_ID"); List ids= (List) postData.get("ids"); for (String questionId : ids) { CheckQuestion question= checkQuestionService.getById(questionId); if (question != null) { QueryWrapper queryWrapper=new QueryWrapper<>(); queryWrapper.eq("TRANSFER_ID",id).eq("CHECK_ID",question.getId()); List saveQuestionList=saveQuestionService.list(queryWrapper); if (saveQuestionList.size()==0){ SaveQuestion saveQuestion=new SaveQuestion(); saveQuestion.setQuestion(question.getQuestion()); saveQuestion.setRequirements(question.getRequirements()); saveQuestion.setTranslation(question.getTranslation()); saveQuestion.setTransferId(id); saveQuestion.setCheckId(question.getId()); saveQuestionService.saveOrUpdate(saveQuestion); } } } return new AjaxResponse(true); } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * 资料验收 * * @return */ @RequestMapping({"/check"}) @ResponseBody @RequiresUser public Object check(@RequestBody Map postData) { try { Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); User user = (User) session.getAttribute("user"); Long id = Long.parseLong(postData.get("id").toString()); int checkState = Integer.parseInt(postData.get("checkState").toString()); String selectSql = "SELECT * FROM BUS_TRANSFER_LOG WHERE ID =" + id; Map map = jdbcTemplate.queryForMap(selectSql); Object ajId = map.get("AJ_ID"); CatCheck catCheck = new CatCheck(); catCheck.setItemId(id); catCheck.setAjId(Long.parseLong(ajId.toString())); // catCheck.setQuestion(postData.get("question").toString()); catCheck.setIsPass(checkState); catCheck.setCreateTime(new Date()); catCheck.setCreateUserName(user.getUserName()); catCheck.setCreateUserId(user.getUserId()); // catCheck.setCheckQuestion(postData.get("checkQuestion") == null ? "" : postData.get("checkQuestion").toString()); catCheckService.saveOrUpdate(catCheck); String updateSql = "update BUS_TRANSFER_LOG set YSZT = '" + checkState + "' where ID = " + id; jdbcTemplate.execute(updateSql); if (checkState==1){ String updateSqlY = "update CAT_ITEM_YSWJXX set YSZT = '" + checkState + "' where YJ_ID = " + id; jdbcTemplate.execute(updateSqlY); }else if (checkState==3){ String updateSqlY = "update CAT_FILE_AJJXX set YSWSJ = '" + postData.get("checkData") + "' where ID = " + ajId; jdbcTemplate.execute(updateSqlY); } return new AjaxResponse(true); } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } public static void main(String[] args) { File file = new File("E:\\Desktop\\DD20240091\\DD20240091"); long folderSize = getFolderSize(file); long l = folderSize / 1024 / 1024; long folder = (folderSize / 1024 / 1024); System.out.println(folderSize / 1024 / 1024); } public static Long getFolderSize(File folder) { if (!folder.exists()) { return 0L; } if (folder.isFile()) { return folder.length(); } Long totalSize = 0L; File[] files = folder.listFiles(); if (files != null) { for (File file : files) { if (file.isFile()) { totalSize += file.length(); } else if (file.isDirectory()) { totalSize += getFolderSize(file); } } } return totalSize; } private void deleteDir(File dir) { if (dir.isDirectory()) { File[] files = dir.listFiles(); if (files != null) { for (File file : files) { deleteDir(file); } } } dir.delete(); } }