| | |
| | | package com.zbooksoft.gdmis.operate; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ruili.wcp.common.CustomConfigUtil; |
| | | import com.ruili.wcp.common.SpringContextUtil; |
| | | import com.ruili.wcp.configsettting.SystemConfig; |
| | | import com.ruili.wcp.data.entity.config.Module; |
| | | import com.ruili.wcp.data.entity.config.View; |
| | | import com.ruili.wcp.data.entity.management.User; |
| | |
| | | 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.BorrowDetail; |
| | | import com.zbooksoft.gdmis.data.entity.CatAjjxx; |
| | | import com.zbooksoft.gdmis.data.entity.CatYswjxx; |
| | | import com.zbooksoft.gdmis.data.entity.PhysicalDetail; |
| | | import com.zbooksoft.gdmis.service.*; |
| | | import org.apache.shiro.SecurityUtils; |
| | |
| | | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.sql.PreparedStatement; |
| | | import java.sql.SQLException; |
| | | import java.time.LocalDateTime; |
| | |
| | | ModuleService moduleService = (ModuleService) SpringContextUtil.getBean("moduleServiceImpl"); |
| | | JdbcTemplate jdbcTemplate = (JdbcTemplate) SpringContextUtil.getBean("jdbcTemplate"); |
| | | IFormData iform = (IFormData) SpringContextUtil.getBean("iFormData"); |
| | | CatYswjxxService catYswjxxService = (CatYswjxxService) SpringContextUtil.getBean("catYswjxxServiceImpl"); |
| | | CustomConfigUtil customConfigUtil = (CustomConfigUtil) SpringContextUtil.getBean("customConfigUtil"); |
| | | |
| | | |
| | | /** |
| | |
| | | return idList.size(); |
| | | } |
| | | }); |
| | | QueryWrapper<CatYswjxx> queryWrapper=new QueryWrapper<>(); |
| | | queryWrapper.in("aj_id",idList).eq("yszt",3); |
| | | // queryWrapper.in("aj_id",idList); |
| | | List<CatYswjxx> catYswjxxList=catYswjxxService.list(queryWrapper); |
| | | ArchivesCustomConfig archivesCustomConfig = customConfigUtil.getConfigObj(ArchivesCustomConfig.class); |
| | | for (CatYswjxx catYswjxx : catYswjxxList) { |
| | | String destDir = archivesCustomConfig.getOriginalPath() + "已入库" + File.separator + catYswjxx.getWjlj().substring(archivesCustomConfig.getOriginalPath().length()); |
| | | // 源文件路径 |
| | | File sourceFile = new File(catYswjxx.getWjlj()); |
| | | // 目标文件路径 |
| | | File destFile = new File(destDir); |
| | | |
| | | // 确保目标目录存在 |
| | | File destParentDir = destFile.getParentFile(); |
| | | if (destParentDir != null && !destParentDir.exists()) { |
| | | destParentDir.mkdirs(); |
| | | } |
| | | |
| | | // 判断源文件是文件还是文件夹 |
| | | if (sourceFile.isDirectory()) { |
| | | // 如果是文件夹,复制整个文件夹及其内容 |
| | | copyDirectory(sourceFile, destFile); |
| | | } else { |
| | | // 如果是文件,直接复制 |
| | | java.nio.file.Files.copy(sourceFile.toPath(), destFile.toPath(), |
| | | java.nio.file.StandardCopyOption.REPLACE_EXISTING); |
| | | } |
| | | |
| | | // 删除源文件或源文件夹 |
| | | deleteDirectory(sourceFile); |
| | | |
| | | catYswjxx.setWjlj(destDir); |
| | | catYswjxxService.saveOrUpdate(catYswjxx); |
| | | } |
| | | return new AjaxResponse(true); |
| | | } catch (Exception e) { |
| | | logger.error(e.getMessage(), e); |
| | | return new AjaxResponse(new ErrorInfo(e.getMessage()), false); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 复制目录及其子目录和文件 |
| | | * @param source 源目录 |
| | | * @param target 目标目录 |
| | | * @throws IOException |
| | | */ |
| | | private void copyDirectory(File source, File target) throws IOException { |
| | | if (source.isDirectory()) { |
| | | // 如果目标目录不存在,则创建 |
| | | if (!target.exists()) { |
| | | target.mkdirs(); |
| | | } |
| | | |
| | | // 获取源目录下的所有文件和子目录 |
| | | String[] files = source.list(); |
| | | if (files != null) { |
| | | for (String file : files) { |
| | | File srcFile = new File(source, file); |
| | | File destFile = new File(target, file); |
| | | // 递归复制 |
| | | copyDirectory(srcFile, destFile); |
| | | } |
| | | } |
| | | } else { |
| | | // 如果是文件,直接复制 |
| | | java.nio.file.Files.copy(source.toPath(), target.toPath(), |
| | | java.nio.file.StandardCopyOption.REPLACE_EXISTING); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除目录及其子目录和文件 |
| | | * @param directory 要删除的目录 |
| | | */ |
| | | private void deleteDirectory(File directory) { |
| | | if (directory.isDirectory()) { |
| | | File[] files = directory.listFiles(); |
| | | if (files != null) { |
| | | for (File file : files) { |
| | | deleteDirectory(file); |
| | | } |
| | | } |
| | | } |
| | | directory.delete(); |
| | | } |
| | | |
| | | /** |
| | |
| | | try { |
| | | int state = 0; |
| | | String columnName = "fbzt"; |
| | | updateState(viewId, idList, state, columnName); |
| | | // updateState(viewId, idList, state, columnName); |
| | | QueryWrapper<CatAjjxx> fileQueryWrapper = new QueryWrapper<>(); |
| | | fileQueryWrapper.in("id",idList); |
| | | List<CatAjjxx> catAjjxxList=catAjjxxService.list(fileQueryWrapper); |
| | | return new AjaxResponse(true); |
| | | } catch (Exception e) { |
| | | logger.error(e.getMessage(), e); |
| | |
| | | public void updateState(Long viewId, ArrayList<Long> idList, Integer state, String columnName) { |
| | | View view = viewService.getViewById(viewId); |
| | | String strSql = "update " + view.getMainTableName() + " set " + columnName + " = " + state; |
| | | jdbcTemplate.batchUpdate(strSql + " where " + view.getIdField() + "=?", new BatchPreparedStatementSetter() { |
| | | @Override |
| | | public void setValues(PreparedStatement ps, int i) throws SQLException { |
| | | ps.setLong(1, idList.get(i));// 下标从1开始 |
| | | } |
| | | // jdbcTemplate.batchUpdate(strSql + " where " + view.getIdField() + "=?", new BatchPreparedStatementSetter() { |
| | | // @Override |
| | | // public void setValues(PreparedStatement ps, int i) throws SQLException { |
| | | // ps.setLong(1, idList.get(i));// 下标从1开始 |
| | | // } |
| | | // |
| | | // @Override |
| | | // public int getBatchSize() { |
| | | // return idList.size(); |
| | | // } |
| | | // }); |
| | | |
| | | @Override |
| | | public int getBatchSize() { |
| | | return idList.size(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |