liding
2026-10-24 f8c024b1c1de318a4de485e048d1044cd6dcaa53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
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.ProcessMethodSearchNewFileSeqMapper;
import com.ruoyi.process.mapper.ProcessMethodSearchNewMapper;
import com.ruoyi.process.mapper.ProcessMethodSearchNewHistoryMapper;
import com.ruoyi.process.pojo.ProcessMethodSearchNew;
import com.ruoyi.process.pojo.ProcessMethodSearchNewArchived;
import com.ruoyi.process.pojo.ProcessMethodSearchNewBackups;
import com.ruoyi.process.pojo.ProcessMethodSearchNewHistory;
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 jakarta.annotation.Resource;
import jakarta.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.LocalDate;
import java.time.ZoneId;
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 {
 
    private static final ZoneId CHINA_ZONE = ZoneId.of("Asia/Shanghai");
    private static final DateTimeFormatter FILE_DATE = DateTimeFormatter.BASIC_ISO_DATE;
 
    @Resource
    private ProcessMethodSearchNewArchivedMapper processMethodSearchNewArchivedMapper;
    @Resource
    private ProcessMethodSearchNewBackupsService processMethodSearchNewBackupsService;
    @Resource
    private ProcessMethodSearchNewBackupsMapper processMethodSearchNewBackupsMapper;
    @Resource
    private ProcessMethodSearchNewHistoryMapper processMethodSearchNewHistoryMapper;
    @Resource
    private ProcessMethodSearchNewFileSeqMapper processMethodSearchNewFileSeqMapper;
 
    /**
     * 新增标准查新
     *
     * @param processMethodSearchNewList
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addMethodSearchNew(List<ProcessMethodSearchNew> processMethodSearchNewList) {
        if (processMethodSearchNewList == null || processMethodSearchNewList.isEmpty()) {
            throw new ErrorException("请填写标准查新记录");
        }
        Integer userId = SecurityUtils.getUserId().intValue();
        for (ProcessMethodSearchNew processMethodSearchNew : processMethodSearchNewList) {
            validateSearchRecord(processMethodSearchNew);
            processMethodSearchNew.setIsNewStandard(1);
            processMethodSearchNew.setIsAutoArchived(0);
            processMethodSearchNew.setStandardMethodId(null);
            processMethodSearchNew.setCurrentAutoStandardId(null);
            processMethodSearchNew.setAutoArchivedTime(null);
            processMethodSearchNew.setSearchNewUserId(userId);
            processMethodSearchNew.setRemark(toLegacyRemark(processMethodSearchNew.getSearchNewResult()));
            if (!Integer.valueOf(3).equals(processMethodSearchNew.getSearchNewSource())) {
                processMethodSearchNew.setSearchNewWebsite(null);
            }
            this.save(processMethodSearchNew);
            insertHistory(processMethodSearchNew, userId);
            handleSearchResult(processMethodSearchNew);
        }
        return true;
    }
 
    @Override
    public boolean updateMethodSearchNew(ProcessMethodSearchNew processMethodSearchNew) {
        ProcessMethodSearchNew old = getById(processMethodSearchNew.getMethodSearchNewId());
        if (old == null) {
            throw new ErrorException("标准查新记录不存在");
        }
        if (Integer.valueOf(1).equals(old.getIsAutoArchived())) {
            throw new ErrorException("已归档标准不能继续查新");
        }
        processMethodSearchNew.setMethodName(old.getMethodName());
        processMethodSearchNew.setStandardNo(old.getStandardNo());
        processMethodSearchNew.setFileNo(old.getFileNo());
        processMethodSearchNew.setStandardMethodId(old.getStandardMethodId());
        validateSearchRecord(processMethodSearchNew);
        Integer userId = SecurityUtils.getUserId().intValue();
        boolean updated = update(Wrappers.<ProcessMethodSearchNew>lambdaUpdate()
                .eq(ProcessMethodSearchNew::getMethodSearchNewId, old.getMethodSearchNewId())
                .set(ProcessMethodSearchNew::getNewMethodName, processMethodSearchNew.getNewMethodName())
                .set(ProcessMethodSearchNew::getNewStandardNo, processMethodSearchNew.getNewStandardNo())
                .set(ProcessMethodSearchNew::getSearchNewSource, processMethodSearchNew.getSearchNewSource())
                .set(ProcessMethodSearchNew::getSearchNewTime, processMethodSearchNew.getSearchNewTime())
                .set(ProcessMethodSearchNew::getNextSearchDatePersisted,
                        processMethodSearchNew.getNextSearchDatePersisted())
                .set(ProcessMethodSearchNew::getSearchNewResult, processMethodSearchNew.getSearchNewResult())
                .set(ProcessMethodSearchNew::getSearchNewUserId, userId)
                .set(ProcessMethodSearchNew::getSearchNewWebsite,
                        Integer.valueOf(3).equals(processMethodSearchNew.getSearchNewSource())
                                ? processMethodSearchNew.getSearchNewWebsite() : null)
                .set(ProcessMethodSearchNew::getRemark, toLegacyRemark(processMethodSearchNew.getSearchNewResult()))
                .set(ProcessMethodSearchNew::getIsNewStandard, 1));
        if (updated) {
            ProcessMethodSearchNew latest = getById(old.getMethodSearchNewId());
            insertHistory(latest, userId);
            handleSearchResult(latest);
        }
        return updated;
    }
 
    @Override
    public boolean delMethodSearchNew(Integer methodSearchNewId) {
        if (methodSearchNewId == null) {
            throw new ErrorException("缺少标准查新记录id");
        }
        ProcessMethodSearchNew old = getById(methodSearchNewId);
        if (old == null) {
            throw new ErrorException("标准查新记录不存在");
        }
        if (Integer.valueOf(1).equals(old.getIsAutoArchived())) {
            throw new ErrorException("已归档标准不能删除");
        }
        Long historyCount = processMethodSearchNewHistoryMapper.selectCount(
                Wrappers.<ProcessMethodSearchNewHistory>lambdaQuery()
                        .eq(ProcessMethodSearchNewHistory::getMethodSearchNewId, methodSearchNewId));
        if (historyCount != null && historyCount > 0) {
            throw new ErrorException("该标准已有查新记录,不允许删除");
        }
        return removeById(methodSearchNewId);
    }
 
    /**
     * 标准查新列表
     *
     * @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);
        IPage<ProcessMethodSearchNew> result = baseMapper.pageMethodSearchNew(
                page, QueryWrappers.queryWrappers(processMethodSearchNew), beginDate, endDate);
        LocalDate today = LocalDate.now(CHINA_ZONE);
        result.getRecords().forEach(item -> {
            LocalDate nextDate = item.getNextSearchDate();
            if (nextDate == null) {
                item.setSearchDueStatus("待首次查新");
            } else if (today.isAfter(nextDate)) {
                item.setSearchDueStatus("已逾期");
            } else if (today.isEqual(nextDate)) {
                item.setSearchDueStatus("今日到期");
            } else {
                item.setSearchDueStatus("未到期");
            }
        });
        return result;
    }
 
    @Override
    public List<ProcessMethodSearchNewHistory> listSearchNewHistory(Integer methodSearchNewId) {
        if (methodSearchNewId == null) {
            throw new ErrorException("缺少标准查新记录id");
        }
        if (getById(methodSearchNewId) == null) {
            throw new ErrorException("标准查新记录不存在");
        }
        return processMethodSearchNewHistoryMapper.selectByMainId(methodSearchNewId);
    }
 
    @Override
    public IPage<ProcessMethodSearchNewHistory> pageSearchNewHistory(Page<ProcessMethodSearchNewHistory> page,
                                                                      String standardNo) {
        return processMethodSearchNewHistoryMapper.pageAll(page,
                StringUtils.isBlank(standardNo) ? null : standardNo.trim());
    }
 
    private void validateSearchRecord(ProcessMethodSearchNew row) {
        if (row == null) {
            throw new ErrorException("请填写标准查新记录");
        }
        if (StringUtils.isBlank(row.getMethodName()) || StringUtils.isBlank(row.getStandardNo())
                || StringUtils.isBlank(row.getFileNo())) {
            throw new ErrorException("请填写标准名称、标准号和文件编号");
        }
        if (row.getSearchNewTime() == null) {
            throw new ErrorException("请选择查新日期");
        }
        row.setSearchNewTime(row.getSearchNewTime().toLocalDate().atStartOfDay());
        if (!"现行有效".equals(row.getSearchNewResult())
                && !"已修订/有新版本替代".equals(row.getSearchNewResult())
                && !"废止(无替代)".equals(row.getSearchNewResult())
                && !"即将实施".equals(row.getSearchNewResult())) {
            throw new ErrorException("请选择有效的查新结果");
        }
        Integer source = row.getSearchNewSource();
        if (source == null || source < 3 || source > 8) {
            throw new ErrorException("请选择有效的查新记录来源");
        }
        if ("已修订/有新版本替代".equals(row.getSearchNewResult())
                && (StringUtils.isBlank(row.getNewMethodName()) || StringUtils.isBlank(row.getNewStandardNo()))) {
            throw new ErrorException("查新结果为已修订/有新版本替代时,请填写新标准名称和新标准号");
        }
        if (!"已修订/有新版本替代".equals(row.getSearchNewResult())) {
            row.setNewMethodName(null);
            row.setNewStandardNo(null);
        }
        if (!Integer.valueOf(3).equals(source)) {
            row.setSearchNewWebsite(null);
        }
        if ("已修订/有新版本替代".equals(row.getSearchNewResult())
                || "废止(无替代)".equals(row.getSearchNewResult())) {
            row.setNextSearchDate(null);
        } else if (row.getNextSearchDate() == null) {
            row.setNextSearchDate(row.getSearchNewTime().toLocalDate().plusMonths(3));
        }
        row.setNextSearchDatePersisted(row.getNextSearchDate());
    }
 
    private Integer toLegacyRemark(String result) {
        if ("废止(无替代)".equals(result)) return 0;
        if ("已修订/有新版本替代".equals(result)) return 1;
        return null;
    }
 
    private void insertHistory(ProcessMethodSearchNew row, Integer userId) {
        ProcessMethodSearchNewHistory history = new ProcessMethodSearchNewHistory();
        history.setMethodSearchNewId(row.getMethodSearchNewId());
        history.setStandardMethodId(row.getStandardMethodId());
        history.setMethodName(row.getMethodName());
        history.setStandardNo(row.getStandardNo());
        history.setFileNo(row.getFileNo());
        history.setSearchNewDate(row.getSearchNewTime().toLocalDate());
        history.setNextSearchDate(row.getNextSearchDatePersisted());
        history.setSearchNewResult(row.getSearchNewResult());
        history.setSearchNewSource(row.getSearchNewSource());
        history.setSearchNewWebsite(row.getSearchNewWebsite());
        history.setNewMethodName(row.getNewMethodName());
        history.setNewStandardNo(row.getNewStandardNo());
        history.setSearchNewUserId(userId);
        history.setCreateTime(LocalDateTime.now(CHINA_ZONE));
        processMethodSearchNewHistoryMapper.insert(history);
    }
 
    /** 旧标准只保留在查新记录;有新版时创建新的主列表记录。 */
    private void handleSearchResult(ProcessMethodSearchNew oldStandard) {
        String result = oldStandard.getSearchNewResult();
        if (!"废止(无替代)".equals(result) && !"已修订/有新版本替代".equals(result)) {
            return;
        }
 
        LocalDateTime now = LocalDateTime.now(CHINA_ZONE);
        update(Wrappers.<ProcessMethodSearchNew>lambdaUpdate()
                .eq(ProcessMethodSearchNew::getMethodSearchNewId, oldStandard.getMethodSearchNewId())
                .set(ProcessMethodSearchNew::getIsNewStandard, 0)
                .set(ProcessMethodSearchNew::getIsAutoArchived, 1)
                .set(ProcessMethodSearchNew::getCurrentAutoStandardId, null)
                .set(ProcessMethodSearchNew::getAutoArchivedTime, now));
 
        if (!"已修订/有新版本替代".equals(result)) {
            return;
        }
        if (count(Wrappers.<ProcessMethodSearchNew>lambdaQuery()
                .eq(ProcessMethodSearchNew::getStandardNo, oldStandard.getNewStandardNo())
                .eq(ProcessMethodSearchNew::getIsAutoArchived, 0)) > 0) {
            return;
        }
 
        ProcessMethodSearchNew replacement = new ProcessMethodSearchNew();
        replacement.setMethodName(oldStandard.getNewMethodName());
        replacement.setStandardNo(oldStandard.getNewStandardNo());
        replacement.setFileNo(nextFileNo(now.toLocalDate()));
        replacement.setIsNewStandard(1);
        replacement.setStandardMethodId(oldStandard.getStandardMethodId());
        replacement.setCurrentAutoStandardId(oldStandard.getCurrentAutoStandardId());
        replacement.setIsAutoArchived(0);
        save(replacement);
    }
 
    private String nextFileNo(LocalDate date) {
        String prefix = date.format(FILE_DATE);
        processMethodSearchNewFileSeqMapper.insertIfAbsent(date);
        Integer stored = processMethodSearchNewFileSeqMapper.selectForUpdate(date);
        Integer existing = processMethodSearchNewFileSeqMapper.selectMaxExisting(prefix);
        int next = Math.max(stored == null ? 0 : stored, existing == null ? 0 : existing) + 1;
        processMethodSearchNewFileSeqMapper.updateValue(date, next);
        return prefix + String.format("%03d", next);
    }
 
    /**
     * 标准查新导出
     *
     * @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);
            searchNewBackupsDto.setSearchNewDateString(methodSearchNew.getSearchNewTime() == null
                    ? null : methodSearchNew.getSearchNewTime().format(timeFormatter));
            searchNewBackupsDto.setSearchNewResultString(methodSearchNew.getSearchNewResult());
            if (methodSearchNew.getSearchNewSource() != null) switch (methodSearchNew.getSearchNewSource()) {
                case 0:
                    searchNewBackupsDto.setOther("√");
                    searchNewBackupsDto.setOtherWebsite("标准网(历史来源)");
                    break;
                case 1:
                    searchNewBackupsDto.setOther("√");
                    searchNewBackupsDto.setOtherWebsite("委托情报所(历史来源)");
                    break;
                case 2:
                    searchNewBackupsDto.setOther("√");
                    searchNewBackupsDto.setOtherWebsite("标准书店(历史来源)");
                    break;
                case 4:
                    searchNewBackupsDto.setStandardizationAdministration("√");
                    break;
                case 5:
                    searchNewBackupsDto.setMarketRegulation("√");
                    break;
                case 6:
                    searchNewBackupsDto.setNationalStandardInfo("√");
                    break;
                case 7:
                    searchNewBackupsDto.setNationalStandardFullText("√");
                    break;
                case 8:
                    searchNewBackupsDto.setIndustryStandard("√");
                    break;
                case 3:
                    searchNewBackupsDto.setOther("√");
                    searchNewBackupsDto.setOtherWebsite(methodSearchNew.getSearchNewWebsite());
                    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();
            // 获取第一个sheet页
            WriteSheet writeSheet = EasyExcel.writerSheet(0, "标准查新导出").build();
            //excelWriter.fill() 这地方就是填充属性。
//            excelWriter.fill(methodSearchNews, fillConfig, writeSheet); // 这里fillConfig是配置文件
            excelWriter.fill(methodSearchNews, writeSheet);
 
            // 这里easy excel模板导出问题 会删除后面内容再进行进行填充
            // 所以list 后面还有数据 想办法手动写入
            // 手动创建一个list 存放数据 然后再进行填充
            // 这里List<Object>可以用对象代替 偷懒用list
            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);
            // 这里追加是write 别和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 {
            // 千万别忘记close关闭流
            if (excelWriter != null) {
                excelWriter.close();
 
            }
        }
    }
 
 
    /**
     * 导入标准查新
     *
     * @param file
     * @return
     */
    @Override
    public boolean importMethodSearchNew(MultipartFile file) {
 
        List<ProcessMethodSearchNewBackupsDto> searchNewDtoList = new ArrayList<>();
 
        try {
            // excel解析
            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.getSearchNewDateString())) {
                    String dateText = searchNewDto.getSearchNewDateString().trim();
                    searchNew.setSearchNewTime(LocalDate.parse(dateText.substring(0, Math.min(10, dateText.length()))).atStartOfDay());
                }
                searchNew.setSearchNewResult(searchNewDto.getSearchNewResultString());
                int sourceCount = 0;
                if (StringUtils.isNotBlank(searchNewDto.getStandardizationAdministration())) sourceCount++;
                if (StringUtils.isNotBlank(searchNewDto.getMarketRegulation())) sourceCount++;
                if (StringUtils.isNotBlank(searchNewDto.getNationalStandardInfo())) sourceCount++;
                if (StringUtils.isNotBlank(searchNewDto.getNationalStandardFullText())) sourceCount++;
                if (StringUtils.isNotBlank(searchNewDto.getIndustryStandard())) sourceCount++;
                if (StringUtils.isNotBlank(searchNewDto.getOther())) sourceCount++;
                if (sourceCount != 1) {
                    throw new ErrorException("标准号" + searchNew.getStandardNo() + "必须且只能选择一个查新来源");
                }
                // 查新记录
                if (StringUtils.isNotBlank(searchNewDto.getStandardizationAdministration())) {
                    searchNew.setSearchNewSource(4);
                } else if (StringUtils.isNotBlank(searchNewDto.getMarketRegulation())) {
                    searchNew.setSearchNewSource(5);
                } else if (StringUtils.isNotBlank(searchNewDto.getNationalStandardInfo())) {
                    searchNew.setSearchNewSource(6);
                } else if (StringUtils.isNotBlank(searchNewDto.getNationalStandardFullText())) {
                    searchNew.setSearchNewSource(7);
                } else if (StringUtils.isNotBlank(searchNewDto.getIndustryStandard())) {
                    searchNew.setSearchNewSource(8);
                } else if (StringUtils.isNotBlank(searchNewDto.getOther())) {
                    searchNew.setSearchNewSource(3);
                    searchNew.setSearchNewWebsite(searchNewDto.getOtherWebsite());
                }
                return searchNew;
            }).collect(Collectors.toList());
            addMethodSearchNew(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(Wrappers.<ProcessMethodSearchNew>lambdaQuery()
                .eq(ProcessMethodSearchNew::getIsAutoArchived, 0));
 
        // 新增复制
        List<ProcessMethodSearchNewBackups> methodSearchNewBackups = searchNewList.stream().map(processMethodSearchNew -> {
            ProcessMethodSearchNewBackups backups = new ProcessMethodSearchNewBackups();
            BeanUtils.copyProperties(processMethodSearchNew, backups);
            backups.setNextSearchDate(processMethodSearchNew.getNextSearchDatePersisted());
            backups.setIsNewStandard(0);
            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;
    }
}