From 4f3a98f19143865cdc1de4791e8a95d96bd40c65 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期五, 01 八月 2025 13:27:59 +0800
Subject: [PATCH] yys 密码已重置

---
 cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessMethodSearchNewServiceImpl.java |  370 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 370 insertions(+), 0 deletions(-)

diff --git a/cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessMethodSearchNewServiceImpl.java b/cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessMethodSearchNewServiceImpl.java
new file mode 100644
index 0000000..4d8a602
--- /dev/null
+++ b/cnas-process/src/main/java/com/ruoyi/process/service/impl/ProcessMethodSearchNewServiceImpl.java
@@ -0,0 +1,370 @@
+package com.ruoyi.process.service.impl;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.alibaba.excel.util.FileUtils;
+import com.alibaba.excel.util.ListUtils;
+import com.alibaba.excel.write.metadata.WriteSheet;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.QueryWrappers;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.framework.exception.ErrorException;
+import com.ruoyi.inspect.util.UserUtils;
+import com.ruoyi.process.dto.ProcessMethodSearchNewArchivedDto;
+import com.ruoyi.process.dto.ProcessMethodSearchNewBackupsDto;
+import com.ruoyi.process.mapper.ProcessMethodSearchNewArchivedMapper;
+import com.ruoyi.process.mapper.ProcessMethodSearchNewBackupsMapper;
+import com.ruoyi.process.mapper.ProcessMethodSearchNewMapper;
+import com.ruoyi.process.pojo.ProcessMethodSearchNew;
+import com.ruoyi.process.pojo.ProcessMethodSearchNewArchived;
+import com.ruoyi.process.pojo.ProcessMethodSearchNewBackups;
+import com.ruoyi.process.service.ProcessMethodSearchNewBackupsService;
+import com.ruoyi.process.service.ProcessMethodSearchNewService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 鏍囧噯鏌ユ柊
+ *
+ * @author zhuo
+ * @since 2024-11-04
+ */
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class ProcessMethodSearchNewServiceImpl extends ServiceImpl<ProcessMethodSearchNewMapper, ProcessMethodSearchNew> implements ProcessMethodSearchNewService {
+
+    @Resource
+    private ProcessMethodSearchNewArchivedMapper processMethodSearchNewArchivedMapper;
+    @Resource
+    private ProcessMethodSearchNewBackupsService processMethodSearchNewBackupsService;
+    @Resource
+    private ProcessMethodSearchNewBackupsMapper processMethodSearchNewBackupsMapper;
+
+    /**
+     * 鏂板鏍囧噯鏌ユ柊
+     *
+     * @param processMethodSearchNewList
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean addMethodSearchNew(List<ProcessMethodSearchNew> processMethodSearchNewList) {
+        for (ProcessMethodSearchNew processMethodSearchNew : processMethodSearchNewList) {
+            processMethodSearchNew.setIsNewStandard(1);
+        }
+        // 鏂板
+        this.saveBatch(processMethodSearchNewList);
+        return true;
+    }
+
+    /**
+     * 鏍囧噯鏌ユ柊鍒楄〃
+     *
+     * @param processMethodSearchNew
+     * @return
+     */
+    @Override
+    public IPage<ProcessMethodSearchNew> pageMethodSearchNew(Page page, ProcessMethodSearchNewBackupsDto processMethodSearchNew) {
+        String beginDate = processMethodSearchNew.getBeginDate();
+        String endDate = processMethodSearchNew.getEndDate();
+        processMethodSearchNew.setBeginDate(null);
+        processMethodSearchNew.setEndDate(null);
+        return baseMapper.pageMethodSearchNew(page, QueryWrappers.queryWrappers(processMethodSearchNew), beginDate, endDate);
+    }
+
+    /**
+     * 鏍囧噯鏌ユ柊瀵煎嚭
+     *
+     * @param archivedId
+     * @param response
+     */
+    @Override
+    public void exportMethodSearchNew(Integer archivedId, HttpServletResponse response) {
+        // 鏌ヨ鏍囧噯鏌ユ柊瀛樻。淇℃伅
+        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        ProcessMethodSearchNewArchived methodSearchNewArchived = processMethodSearchNewArchivedMapper.selectById(archivedId);
+        Integer writeUserId = methodSearchNewArchived.getWriteUserId();
+        Integer ratifyUserId = methodSearchNewArchived.getRatifyUserId();
+        String writeDate = methodSearchNewArchived.getWriteTime() == null ?
+                null : methodSearchNewArchived.getWriteTime().format(timeFormatter);
+        String ratifyDate =methodSearchNewArchived.getRatifyTime() == null ?
+                null :  methodSearchNewArchived.getRatifyTime().format(timeFormatter);
+        // 鏌ヨ瀛樻。澶囦唤
+        List<ProcessMethodSearchNewBackups> methodSearchNewBackups = processMethodSearchNewBackupsMapper.selectList(Wrappers.<ProcessMethodSearchNewBackups>lambdaQuery()
+                .eq(ProcessMethodSearchNewBackups::getArchivedId, archivedId));
+
+        int index = 1;
+        // 鏍煎紡鍖栧弬鏁�
+        List<ProcessMethodSearchNewBackupsDto> methodSearchNews = new ArrayList<>();
+        for (ProcessMethodSearchNewBackups methodSearchNew : methodSearchNewBackups) {
+            ProcessMethodSearchNewBackupsDto searchNewBackupsDto = new ProcessMethodSearchNewBackupsDto();
+            BeanUtils.copyProperties(methodSearchNew, searchNewBackupsDto);
+            // 鏄惁鏄窡鏂版爣鍑�
+            if (methodSearchNew.getIsNewStandard().equals(1)) {
+                searchNewBackupsDto.setIsNewStandardString("鏄�");
+            } else {
+                searchNewBackupsDto.setIsNewStandardString("鍚�");
+            }
+
+            // 澶囨敞
+            if (methodSearchNew.getRemark() != null) {
+                if (methodSearchNew.getRemark().equals(1)) {
+                    searchNewBackupsDto.setRemarkString("鏇挎崲");
+                } else {
+                    searchNewBackupsDto.setRemarkString("浣滃簾");
+                }
+            }
+            switch (methodSearchNew.getSearchNewSource()) {
+                case 0:
+                    searchNewBackupsDto.setStandardNet("鈭�");
+                    break;
+                case 1:
+                    searchNewBackupsDto.setInformationOffices("鈭�");
+                    break;
+                case 2:
+                    searchNewBackupsDto.setStandardBookstore("鈭�");
+                    break;
+                case 3:
+                    searchNewBackupsDto.setOther("鈭�");
+                    break;
+            }
+            searchNewBackupsDto.setIndex(index);
+            methodSearchNews.add(searchNewBackupsDto);
+            index++;
+
+        }
+        // 鏌ヨ绛惧悕鍦板潃
+        String writeUserUrl = UserUtils.getUserSignatureUrl(writeUserId);
+        String ratifyUserUrl = UserUtils.getUserSignatureUrl(ratifyUserId);
+
+        //鍒涘缓ExcelWriter 鍙互鑷姩鍏虫祦浣嗚繕鏄墜鍔ㄥ叧涓�娆�
+        ExcelWriter excelWriter = null;
+
+        try {
+            // outputStream锛氳瀵煎嚭鐨勬枃浠剁殑杈撳嚭娴�
+            OutputStream outputStream = response.getOutputStream();
+            // 鑾峰彇妯$増鏂囦欢
+            ClassPathResource classPathResource = new ClassPathResource("/static/excel/check-records.xlsx");
+            // 浣跨敤妯$増鏂囦欢鐨勪袱绉嶆柟寮忥細
+            // 	1銆佹枃浠惰矾寰勶細.withTemplate(templateFileName)
+            // 	2銆佽緭鍏ユ祦锛�.withTemplate(inputStream)
+            // String templateFileName = classPathResource.getFile().getPath();
+            InputStream inputStream = classPathResource.getInputStream();
+            // 鍒涘缓ExcelWriter
+            excelWriter = EasyExcel.write(outputStream).withTemplate(inputStream).build();
+            // 鑾峰彇绗竴涓猻heet椤�
+            WriteSheet writeSheet = EasyExcel.writerSheet(0, "鏍囧噯鏌ユ柊瀵煎嚭").build();
+            //excelWriter.fill() 杩欏湴鏂瑰氨鏄~鍏呭睘鎬с��
+//            excelWriter.fill(methodSearchNews, fillConfig, writeSheet); // 杩欓噷fillConfig鏄厤缃枃浠�
+            excelWriter.fill(methodSearchNews, writeSheet);
+
+            // 杩欓噷easy excel妯℃澘瀵煎嚭闂 浼氬垹闄ゅ悗闈㈠唴瀹瑰啀杩涜杩涜濉厖
+            // 鎵�浠ist 鍚庨潰杩樻湁鏁版嵁 鎯冲姙娉曟墜鍔ㄥ啓鍏�
+            // 鎵嬪姩鍒涘缓涓�涓猯ist 瀛樻斁鏁版嵁 鐒跺悗鍐嶈繘琛屽~鍏�
+            // 杩欓噷List<Object>鍙互鐢ㄥ璞′唬鏇� 鍋锋噿鐢╨ist
+            List<List<Object>> totalListList = ListUtils.newArrayList();
+            List<Object> totalList = ListUtils.newArrayList();
+            totalListList.add(totalList);
+            // 绗竴鍒�
+            totalList.add("缂栧埗浜猴細");
+            // 绗簩鍒� 璁剧疆绛惧悕
+            if (StringUtils.isNotBlank(writeUserUrl)) {
+                totalList.add(FileUtils.readFileToByteArray(new File(writeUserUrl)));
+            }
+            // 绗笁鍒�
+            totalList.add("鏃ユ湡锛�");
+            // 绗簲鍒�
+            totalList.add(writeDate);
+            // 绗叚鍒�
+            totalList.add("瀹℃牳锛�");
+            // 绗竷鍒�
+            if (StringUtils.isNotBlank(ratifyUserUrl)) {
+                totalList.add(FileUtils.readFileToByteArray(new File(ratifyUserUrl)));
+            }
+            // 绗叓鍒�
+            totalList.add("鏃ユ湡锛�");
+            // 绗節鍒�
+            totalList.add(ratifyDate);
+            // 杩欓噷杩藉姞鏄痺rite 鍒拰fill 鎼為敊浜�
+            excelWriter.write(totalListList, writeSheet);
+
+            // 璁剧疆杈撳嚭娴佹牸寮忎互鍙婃枃浠跺悕锛�
+            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+            response.setCharacterEncoding("utf-8");
+            String fileName = URLEncoder.encode(
+                    "鍘熸潗鏂欐娴嬩俊鎭鍑�", "UTF-8");
+            response.setHeader("Content-disposition",
+                    "attachment;filename=" + fileName + ".xlsx");
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            // 鍗冧竾鍒繕璁癱lose鍏抽棴娴�
+            if (excelWriter != null) {
+                excelWriter.close();
+
+            }
+        }
+    }
+
+
+    /**
+     * 瀵煎叆鏍囧噯鏌ユ柊
+     *
+     * @param file
+     * @return
+     */
+    @Override
+    public boolean importMethodSearchNew(MultipartFile file) {
+
+        List<ProcessMethodSearchNewBackupsDto> searchNewDtoList = new ArrayList<>();
+
+        try {
+            // excel瑙f瀽
+            EasyExcel.read(file.getInputStream(), ProcessMethodSearchNewBackupsDto.class, new AnalysisEventListener<ProcessMethodSearchNewBackupsDto>() {
+                @Override
+                public void invoke(ProcessMethodSearchNewBackupsDto searchNewDto, AnalysisContext analysisContext) {
+                    searchNewDtoList.add(searchNewDto);
+                }
+
+                @Override
+                public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+
+                }
+            }).sheet().doRead();
+            // 鏍煎紡鍖栨煡鏂板璞�
+            List<ProcessMethodSearchNew> collect = searchNewDtoList.stream().map(searchNewDto -> {
+                ProcessMethodSearchNew searchNew = new ProcessMethodSearchNew();
+                BeanUtils.copyProperties(searchNewDto, searchNew);
+                // 鏄惁鏄洿鏂�
+                if (StringUtils.isNotBlank(searchNewDto.getIsNewStandardString())) {
+                    if (searchNewDto.getIsNewStandardString().equals("鏄�")) {
+                        searchNew.setIsNewStandard(1);
+                    } else {
+                        searchNew.setIsNewStandard(0);
+                    }
+                }
+                // 鏌ユ柊璁板綍
+                if (StringUtils.isNotBlank(searchNewDto.getStandardNet())) {
+                    searchNew.setSearchNewSource(0);
+                } else if (StringUtils.isNotBlank(searchNewDto.getInformationOffices())) {
+                    searchNew.setSearchNewSource(1);
+                } else if (StringUtils.isNotBlank(searchNewDto.getIsNewStandardString())) {
+                    searchNew.setSearchNewSource(2);
+                } else if (StringUtils.isNotBlank(searchNewDto.getOther())) {
+                    searchNew.setSearchNewSource(3);
+                }
+
+                // 澶囨敞
+                if (StringUtils.isNotBlank(searchNewDto.getRemarkString())) {
+                    if (searchNewDto.getRemarkString().equals("鏇挎崲")) {
+                        searchNew.setRemark(1);
+                    } else if (searchNewDto.getRemarkString().equals("浣滃簾")) {
+                        searchNew.setRemark(0);
+                    }
+                }
+
+                return searchNew;
+            }).collect(Collectors.toList());
+            this.saveBatch(collect);
+
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return true;
+    }
+
+    /**
+     * 鏂板鏍囧噯鏌ユ柊瀹℃壒娴佺▼
+     * @param archived
+     * @return
+     */
+    @Override
+    public boolean addSearchNewArchived(ProcessMethodSearchNewArchived archived) {
+        // 鏂板瀛樻。
+        Integer userId = SecurityUtils.getUserId().intValue();
+        archived.setWriteUserId(userId);
+        archived.setWriteTime(LocalDateTime.now());
+        processMethodSearchNewArchivedMapper.insert(archived);
+
+        // 鏌ヨ鎵�鏈夌殑鏍囧噯鏌ユ柊
+        List<ProcessMethodSearchNew> searchNewList = this.list();
+
+        // 鏂板澶嶅埗
+        List<ProcessMethodSearchNewBackups> methodSearchNewBackups = searchNewList.stream().map(processMethodSearchNew -> {
+            ProcessMethodSearchNewBackups backups = new ProcessMethodSearchNewBackups();
+            BeanUtils.copyProperties(processMethodSearchNew, backups);
+            backups.setArchivedId(archived.getArchivedId());
+            return backups;
+        }).collect(Collectors.toList());
+        processMethodSearchNewBackupsService.saveBatch(methodSearchNewBackups);
+
+        return true;
+    }
+
+    /**
+     * 鏌ヨ瀛樻。
+     * @param page
+     * @param archived
+     * @return
+     */
+    @Override
+    public IPage<ProcessMethodSearchNewArchivedDto> pageSearchNewArchived(Page page, ProcessMethodSearchNewArchivedDto archived) {
+        return processMethodSearchNewArchivedMapper.pageSearchNewArchived(page, QueryWrappers.queryWrappers(archived));
+    }
+
+    /**
+     * 鏌ヨ瀛樻。澶囦唤鍒楄〃
+     * @param page
+     * @param backups
+     * @return
+     */
+    @Override
+    public IPage<ProcessMethodSearchNewBackups> pageSearchNewBackups(Page page, ProcessMethodSearchNewBackups backups) {
+        if (backups.getArchivedId() == null) {
+            throw new ErrorException("缂哄皯瀛樻。id");
+        }
+        return processMethodSearchNewBackupsMapper.pageSearchNewBackups(page, QueryWrappers.queryWrappers(backups));
+    }
+
+    /**
+     * 瀛樻。鎵瑰噯
+     * @param archived
+     * @return
+     */
+    @Override
+    public boolean ratifySearchNewArchivedr(ProcessMethodSearchNewArchived archived) {
+        // 褰撳墠鐧诲綍鐢ㄦ埛
+        Integer userId = SecurityUtils.getUserId().intValue();
+        processMethodSearchNewArchivedMapper.update(null, Wrappers.<ProcessMethodSearchNewArchived>lambdaUpdate()
+                .eq(ProcessMethodSearchNewArchived::getArchivedId, archived.getArchivedId())
+                .set(ProcessMethodSearchNewArchived::getRatifyUserId, userId)
+                .set(ProcessMethodSearchNewArchived::getRatifyRemark, archived.getRatifyRemark())
+                .set(ProcessMethodSearchNewArchived::getRatifyStatus, archived.getRatifyStatus())
+                .set(ProcessMethodSearchNewArchived::getRatifyTime, LocalDateTime.now())
+        );
+        return true;
+    }
+}
+

--
Gitblit v1.9.3