fei
7 小时以前 bcb1d905904fd43034f7c95077336e5cb849eff1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/ArchiveRecordsController.java
@@ -1,22 +1,33 @@
package com.ruoyi.web.controller.archive;
import java.util.List;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.poi.ExcelExp;
import com.ruoyi.common.utils.poi.ExcelUtilManySheetFour;
import com.ruoyi.domain.ArchiveRecords;
import com.ruoyi.domain.DocumentMaterials;
import com.ruoyi.domain.dto.searSigAnn;
import com.ruoyi.domain.vo.*;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.service.IArchiveRecordsService;
import com.ruoyi.service.IDocumentMaterialsService;
import com.ruoyi.service.impl.BarcodeService;
import com.ruoyi.service.impl.pdfGenerateService;
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
@@ -24,6 +35,7 @@
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
import static com.ruoyi.common.core.page.TableSupport.PAGE_NUM;
import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE;
@@ -36,18 +48,43 @@
 */
@RestController
@RequestMapping("/system/records")
public class ArchiveRecordsController extends BaseController
{
public class ArchiveRecordsController extends BaseController {
    @Autowired
    private IArchiveRecordsService archiveRecordsService;
    @Autowired
    private BarcodeService barcodeService;
    @Autowired
    private pdfGenerateService pdfGenerateService;
    @Autowired
    private IDocumentMaterialsService iDocumentMaterialsService;
    /**
     * 查询档案完成情况
     */
    @PreAuthorize("@ss.hasPermi('system:records:list')")
    @GetMapping("/analysisRes")
    public AjaxResult analysis() {
        System.out.println("009099");
        return new AjaxResult(200, "查询成功", archiveRecordsService.statisticAya());
    }
    @PreAuthorize("@ss.hasPermi('system:records:export')")
    @Log(title = "档案分析结果导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAllStatis")
    public void exportAllStatis(HttpServletResponse response) {
        List<AnalysisResult> list = archiveRecordsService.statisticAya();
        ExcelUtil<AnalysisResult> util = new ExcelUtil<AnalysisResult>(AnalysisResult.class);
        util.exportExcel(response, list, "案卷目录");
    }
    /**
     * 查询档案记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:records:list')")
    @GetMapping("/list")
    public AjaxResult list(ArchiveRecords archiveRecords)
    {
    public AjaxResult list(ArchiveRecords archiveRecords) {
        Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10);
@@ -56,14 +93,30 @@
    }
    /**
     * 拿到最大id
     */
    @PreAuthorize("@ss.hasPermi('system:records:list')")
    @GetMapping("/getMaxId")
    public AjaxResult getMaxId() {
        return success(archiveRecordsService.getMaxId() + 1);
    }
    /**
     * 导出档案记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:records:export')")
    @Log(title = "档案记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveRecords archiveRecords)
    {
        List<ArchiveRecords> list = archiveRecordsService.selectArchiveRecordsList(archiveRecords);
    public void export(HttpServletResponse response, ArchiveRecords archiveRecords, @RequestParam(value = "ids", required = false) Long[] ids) {
        List<ArchiveRecords> list;
        System.out.println(ids);
        // 如果提供了ids参数,则根据ids导出指定记录
        if (ids != null && ids.length > 0) {
            list = archiveRecordsService.selectArchiveRecordsByIds(ids);
        } else {
            // 否则根据查询条件导出
            list = archiveRecordsService.selectArchiveRecordsList(archiveRecords);
        }
        ExcelUtil<ArchiveRecords> util = new ExcelUtil<ArchiveRecords>(ArchiveRecords.class);
        util.exportExcel(response, list, "档案记录数据");
    }
@@ -73,11 +126,10 @@
     */
    @PreAuthorize("@ss.hasPermi('system:records:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        ArchiveRecords records = archiveRecordsService.selectArchiveRecordsById(id);
        if(records!=null)
        if (records != null)
            return new AjaxResult(200, "查询成功", records);
        else
            return new AjaxResult(201, "查询失败!");
@@ -89,9 +141,17 @@
    @PreAuthorize("@ss.hasPermi('system:records:add')")
    @Log(title = "档案记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveRecords archiveRecords)
    {
        return toAjax(archiveRecordsService.insertArchiveRecords(archiveRecords));
    public AjaxResult add(@RequestBody ArchiveRecords archiveRecords) {
        int res = archiveRecordsService.insertArchiveRecords(archiveRecords);
        System.out.println(res);
        if (res == 0) {
            System.out.println(res);
            return new AjaxResult(0, "档案号已经存在了!");
        } else
            return new AjaxResult(200, "添加成功了!");
    }
    /**
@@ -100,19 +160,227 @@
    @PreAuthorize("@ss.hasPermi('system:records:edit')")
    @Log(title = "档案记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveRecords archiveRecords)
    {
    public AjaxResult edit(@RequestBody ArchiveRecords archiveRecords) {
        return toAjax(archiveRecordsService.updateArchiveRecords(archiveRecords));
    }
    @PreAuthorize("@ss.hasPermi('system:records:edit')")
    @Log(title = "档案记录", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateSByIds")
    public AjaxResult updateStatusByIds(@RequestBody Long[] ids) {
        System.out.println(ids);
        System.out.println("090sdfsdf");
        return new AjaxResult(0, archiveRecordsService.updateStatusByIds(ids) + "");
    }
    /**
     *
     */
    @PreAuthorize("@ss.hasPermi('system:records:list')")
    @Log(title = "档案记录", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/getAllFilesCounts")
    public AjaxResult getAllFileCounts(@RequestBody Long[] ids) {
// 1. 初始化Map,用于存储recordId和对应的文件数
        Map<Long, Integer> recordFileCountMap = new HashMap<>();
// 2. 获取基础上传路径
        String filePath = RuoYiConfig.getUploadPath();
// 3. 遍历每个recordId,计算文件数并放入Map
        for (Long recordId : ids) {
            // 拼接当前recordId的目录路径
            File desc = new File(filePath + File.separator + recordId);
            int fileCount = 0;
            try {
                // 判断目录是否存在且是目录
                if (desc.exists() && desc.isDirectory()) {
                    // 过滤出仅文件(排除子目录)
                    File[] files = desc.listFiles(new FileFilter() {
                        @Override
                        public boolean accept(File file) {
                            return file.isFile(); // 只统计文件,不统计目录
                        }
                    });
                    // 避免空指针(空目录时listFiles返回null)
                    if (files != null) {
                        fileCount = files.length;
                    }
                } else {
                    // 目录不存在/不是目录,文件数为0
                    fileCount = 0;
                    // 可选:日志提示
                    // log.warn("目录不存在或非目录:{}", desc.getAbsolutePath());
                }
            } catch (SecurityException e) {
                // 权限不足等异常,文件数置0
                fileCount = 0;
                // 可选:日志记录异常
                // log.error("获取目录[{}]文件数失败:{}", recordId, e.getMessage(), e);
            }
            // 4. 将recordId和对应的文件数放入Map
            recordFileCountMap.put(recordId, fileCount);
        }
        return new AjaxResult(200,"拿到所有对应的数据", recordFileCountMap);
    }
    /**
     * 删除档案记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:remove')")
    @Log(title = "档案记录", businessType = BusinessType.DELETE)
   @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(archiveRecordsService.deleteArchiveRecordsByIds(ids));
    }
    @PreAuthorize("@ss.hasPermi('system:records:edit')")
    @Log(title = "档案记录导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("excelImport") MultipartFile file) throws Exception {
        return archiveRecordsService.importExcel(file);
    }
    @PreAuthorize("@ss.hasPermi('system:records:edit')")
    @Log(title = "修改状态", businessType = BusinessType.IMPORT)
    @GetMapping(value = "/updateStatusById/{status}/{id}/{operator}")
    public AjaxResult updateStatusById(@PathVariable("status") String status, @PathVariable("id") String id, @PathVariable("operator") String operator) {
        return new AjaxResult(200, archiveRecordsService.updateArchiveById(status, Long.parseLong(id), operator)+"");
    }
    @PostMapping("/model")
    public void getExportModel(HttpServletResponse response) {
        List<ArchiveRecordModelExp> list = Collections.singletonList(new ArchiveRecordModelExp());
        ExcelUtil<ArchiveRecordModelExp> util = new ExcelUtil<>(ArchiveRecordModelExp.class);
        util.exportExcel(response, list, "档案信息");
    }
    @PostMapping("/modelOther")
    public void getExportModelOther(HttpServletResponse response) {
        List<ArchiveRecordModelOther> list = Collections.singletonList(new ArchiveRecordModelOther());
        ExcelUtil<ArchiveRecordModelOther> util = new ExcelUtil<>(ArchiveRecordModelOther.class);
        util.exportExcel(response, list, "档案信息");
    }
    @PreAuthorize("@ss.hasPermi('system:records:list')")
    @Log(title = "是否允许提交", businessType = BusinessType.IMPORT)
    @GetMapping(value = "/whether/{recordId}")
    public AjaxResult whether(@PathVariable("recordId") Long recordId) {
        return AjaxResult.success(archiveRecordsService.whether(recordId));
    }
    @PostMapping("/recordFileList")
    //导出excle
    public void getSpecialArchiveInfo(HttpServletResponse response, @RequestBody searSigAnn searSigAnn) throws IOException {
        System.out.println("uuuuuuuuuuuuuuuuuuusssss88888888888888");
        //System.out.println(includeQrCode);
        //生成二维码
        String code = "2024050000029250";
        byte[] bt = barcodeService.generateBarcodeImageScarn(code);
        //  System.out.println(Arrays.toString(selectedSignatures));
        //签名选择
        String[] sig = {"业务科室移交人:", "审批科/法规科移交人:","审批科移交人:", "档案整理公司:"};
        List<String> arrLis = new ArrayList<>();
        if (searSigAnn.getSelectedSignatures() != null) {
            for (String si : searSigAnn.getSelectedSignatures()) {
                arrLis.add(sig[Integer.parseInt(si)]);
                System.out.println(sig[Integer.parseInt(si)]);
            }
        }
        //注选择
        String[] ann = {"本清单由档案形成部门完成",
                "文件类型必须录入,包括结论材料、过程材料、申请材料,其他材料",
                "公开属性必须录入,主动公开、依申请公开、免予公开",
                "保管期限:30年或永久",
                "页号按照正式录入页码为准"};
        List<String> arrAn = new ArrayList<>();
        // 1. 对索引进行排序(从小到大)
        int[] sortedIndices = convertToIntArray(searSigAnn.getSelectedAnnotations()).clone();
        Arrays.sort(sortedIndices);
     //   String[] result = new String[sortedIndices.length];
        for (int sortedIndex : sortedIndices) {
            arrAn.add(ann[sortedIndex]);
        }
        List<DocumentMaterialsFileList> arsi = new ArrayList<>();
//        DocumentMaterials documentMaterials = new DocumentMaterials();
//        documentMaterials.setRecordId(recordId);
                ArchiveRecords archiveRecords = archiveRecordsService.selectArchiveRecordsById(searSigAnn.getRecordId());
        List<DocumentMaterialsVo> lst = iDocumentMaterialsService.findArchMInfo(searSigAnn.getRecordId().toString(), archiveRecords.getPageCount());
       // List<DocumentMaterialsFileList> lst =
        //拿到卷内目录的excel
//        List<DocumentMaterialsVoSmall> lst = dsvs.stream().map(res1 -> new DocumentMaterialsVoSmall(res1.getNum(), res1.getDocumentNumber(),res1.getCreator(),
//                res1.getTitle(), res1.getDate(), res1.getPageNumberFormatted(), res1.getRemarks())).collect(Collectors.toList());
        //iDocumentMaterialsService.selectDocumentMaterialsFileList(searSigAnn.getRecordId());
        // 复制属性到SmallObject列表
        for (DocumentMaterialsVo bigObject : lst) {
            DocumentMaterialsFileList smallObject = new DocumentMaterialsFileList();
            BeanUtil.copyProperties(bigObject, smallObject); // 复制属性
            System.out.println(bigObject);
            if(bigObject.getFileStyle()!=null&&
                    ((bigObject.getFileStyle().equals("其它材料"))
                    ||bigObject.getFileStyle().equals("光盘")
                            ||bigObject.getFileStyle().equals("U盘")))
                smallObject.setFileStyle1("是");
            else
                smallObject.setFileStyle1("否");
            arsi.add(smallObject);
        }
       // System.out.println(arsi.toString());
        //  arsi.add(aIV);
        ExcelExp e3 = new ExcelExp("文件材料移交目录清单", arsi, DocumentMaterialsFileList.class);
        // ExcelExp e4 = new ExcelExp("案卷封面",  arsi, recordId1, imgr1,sedcode, ArchiveInfoVo.class);
        List<ExcelExp> mysheet1 = new ArrayList<ExcelExp>();
        mysheet1.add(e3);
        // mysheet1.add(e4);
        //ByteOutputStream bos2 = new ByteOutputStream();
        //  if(searSigAnn.getMenu().equals(""))
        ExcelUtilManySheetFour<List<ExcelExp>> util3 = new ExcelUtilManySheetFour<List<ExcelExp>>(mysheet1);
        //拿到caseTitle和inquiryNumber
        String inquiryNumber = "";
        String caseTitle = "";
        if (!arsi.isEmpty()) {
            inquiryNumber = arsi.get(0).getInquiryNumber();
            caseTitle = arsi.get(0).getCaseTitle();
        }
        util3.exportExcelManySheet(response, mysheet1, searSigAnn.getIncludeQrCode(), bt, arrLis, arrAn, inquiryNumber, caseTitle);
    }
    public static int[] convertToIntArray(String[] source) {
        int[] result = new int[source.length];
        for (int i = 0; i < source.length; i++) {
            try {
                result[i] = Integer.parseInt(source[i].trim());
            } catch (NumberFormatException e) {
                System.out.println("错误: 索引 " + i + " 的值 '" +
                        source[i] + "' 不是有效整数");
                result[i] = 0; // 或者使用默认值
            }
        }
        return result;
    }
}