kimi
2020-11-27 75c32d6d697a550400d0b4eec95b8570d83b726f
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
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
package com.highdatas.srs.web;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.highdatas.srs.entity.*;
import com.highdatas.srs.pojo.CodeMsg;
import com.highdatas.srs.pojo.Result;
import com.highdatas.srs.service.IModuleService;
import com.highdatas.srs.service.ISchemeDetailService;
import com.highdatas.srs.service.ISchemeService;
import com.highdatas.srs.service.ITopicService;
import com.highdatas.srs.util.DbUtils;
import com.highdatas.srs.util.FileUtils;
import lombok.extern.java.Log;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author kimi
 * @description
 * @date 2020-01-17 12:05
 */
 
@RestController
@Log
@RequestMapping("file")
public class FileController {
    @Autowired
    ISchemeDetailService schemeDetailService;
    @Autowired
    ISchemeService schemeService;
    @Autowired
    ITopicService topicService;
    @Autowired
    IModuleService moduleService;
 
    @Value("${base.file.path}")
    String basePath;
    @Value("${base.topic.path}")
    String topicPath;
 
    @RequestMapping(value = "child", method = RequestMethod.GET)
    public Result children(@RequestParam String path) throws UnsupportedEncodingException {
        path = URLDecoder.decode(path, "UTF-8");
        ArrayList<JSONObject> childrenFiles = FileUtils.getChildrenFiles(path);
        return Result.success(childrenFiles);
    }
 
    @RequestMapping(value = "downloadPath", method = RequestMethod.GET)
    public Result downloadPath(@RequestParam String path, HttpServletResponse response) throws UnsupportedEncodingException {
        path = URLDecoder.decode(path, "UTF-8");
        File file = new File(path);
        if (file.exists()) { //判断文件父目录是否存在
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            // response.setContentType("application/force-download");
            response.setHeader("Content-Disposition", "attachment;fileName=" + java.net.URLEncoder.encode(file.getName(), "UTF-8"));
            byte[] buffer = new byte[1024];
            FileInputStream fis = null; //文件输入流
            BufferedInputStream bis = null;
 
            OutputStream os = null; //输出流
            try {
                os = response.getOutputStream();
                fis = new FileInputStream(file);
                bis = new BufferedInputStream(fis);
                int i = bis.read(buffer);
                while (i != -1) {
                    os.write(buffer);
                    i = bis.read(buffer);
                }
 
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            log.info("----------file download---" + file.getName());
            try {
                bis.close();
                fis.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return null;
    }
 
    @RequestMapping("timeline/{schemeId}")
    public void timeline(@PathVariable String schemeId, HttpServletResponse response) {
        Scheme scheme = schemeService.selectById(schemeId);
        if (scheme == null) {
            return;
        }
        String status = scheme.getStatus();
        if (!status.equalsIgnoreCase("working")) {
            return;
        }
 
        try {
            // 1.读取Excel模板
            String filePath = "D:/project/template.xlsx";
            File file = new File(filePath);
            InputStream in = new FileInputStream(file);
            XSSFWorkbook wb = new XSSFWorkbook(in);
            // 2.读取模板里面的所有Sheet
            XSSFSheet sheet = wb.getSheetAt(0);
//        Font dateFont = wb.createFont();
//        dateFont.setFontName("等线");
//        dateFont.setFontHeightInPoints((short) 9);
//        XSSFCellStyle dateCellStyle = wb.createCellStyle();
//        dateCellStyle.setRotation((short) (Math.abs(45)));
//        dateCellStyle.setWrapText(true);
//        dateCellStyle.setFont(dateFont);
            XSSFCellStyle inTimeCellStyle = wb.createCellStyle();
            inTimeCellStyle.setFillBackgroundColor(IndexedColors.LIGHT_ORANGE.getIndex());
            inTimeCellStyle.setFillPattern(FillPatternType.THICK_HORZ_BANDS);
 
            XSSFCellStyle finishTimeCellStyle = wb.createCellStyle();
            finishTimeCellStyle.setFillBackgroundColor(IndexedColors.ORANGE.getIndex());
            finishTimeCellStyle.setFillPattern(FillPatternType.THICK_FORWARD_DIAG);
 
 
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
 
            XSSFRow dateRow = sheet.getRow(1);
            XSSFRow firstRow = sheet.getRow(0);
            XSSFCell planCell = firstRow.getCell(12);
            XSSFCellStyle planStyle = planCell.getCellStyle();
            XSSFCell planEndCell = firstRow.getCell(17);
            XSSFCell exportCell = firstRow.getCell(23);
 
            XSSFCellStyle exportStyle = exportCell.getCellStyle();
            XSSFCellStyle cellEndStyle = planEndCell.getCellStyle();
            XSSFRow titleRow = sheet.getRow(3);
            XSSFRow datesRow = sheet.getRow(2);
            datesRow.setHeightInPoints(60);
            XSSFCell dateCell = datesRow.getCell(12);
            XSSFCellStyle dateCellCellStyle = dateCell.getCellStyle();
            XSSFRow subTitleRow = sheet.getRow(4);
            XSSFCell subTitleCell = subTitleRow.getCell(2);
            XSSFCellStyle subTitleCellStyle = subTitleCell.getCellStyle();
            XSSFCell subStartCell = subTitleRow.getCell(6);
            XSSFCellStyle subStartCellStyle = subStartCell.getCellStyle();
            XSSFCell subtimesCell = subTitleRow.getCell(7);
            XSSFCellStyle subtimesCellStyle = subtimesCell.getCellStyle();
            XSSFCell subendTimeCell = subTitleRow.getCell(9);
            XSSFCellStyle subendTimeCellCellStyle = subendTimeCell.getCellStyle();
            XSSFCell subendRemarkCell = subTitleRow.getCell(10);
            XSSFCellStyle remarkCellCellStyle = subendRemarkCell.getCellStyle();
 
            XSSFCell titleCell = titleRow.getCell(1);
            XSSFCellStyle titleStyle = titleCell.getCellStyle();
            XSSFCell nameCell = dateRow.getCell(1);
            nameCell.setCellValue(scheme.getName() + "(" + dateFormat.format(scheme.getStartTime()) + ")");
 
            List<Module> parent_id = moduleService.selectList(new EntityWrapper<Module>().isNull("parent_id").orderBy("order_no"));
            List<SchemeDetail> schemeDetailList = schemeDetailService.selectList(new EntityWrapper<SchemeDetail>().eq("parent_id", scheme.getId()));
            Date startTime = scheme.getStartTime();
            Date endTime = scheme.getEndTime();
 
 
            Calendar start = Calendar.getInstance();
            start.setTime(startTime);
            int index = 12;
            XSSFRow dateRows = sheet.getRow(2);
            while (startTime.before(endTime)) {
                startTime = start.getTime();
                XSSFCell inTimeCell = dateRows.createCell(index);
                inTimeCell.setCellValue(dateFormat.format(startTime));
                inTimeCell.setCellStyle(dateCellCellStyle);
 
                index++;
                start.add(Calendar.DAY_OF_YEAR, 1);
            }
            startTime = scheme.getStartTime();
            start.setTime(startTime);
 
            int startRow = 3;
            for (int i = 0; i < parent_id.size(); i++) {
                Module module = parent_id.get(i);
                XSSFRow row = sheet.createRow(startRow);
                XSSFCell cell = row.createCell(1);
                cell.setCellValue(MessageFormat.format("Step {0} {1}", i + 1, module.getTitle()));
                cell.setCellStyle(titleStyle);
                List<Module> subModuleList = moduleService.selectList(new EntityWrapper<Module>().eq("parent_id", module.getId()).orderBy("order_no"));
                for (Module subModule : subModuleList) {
                    List<SchemeDetail> collect = schemeDetailList.stream().filter(schemeDetail -> schemeDetail.getType().toString().equals(subModule.getId())).collect(Collectors.toList());
                    if (collect.isEmpty()) {
                        continue;
                    }
                    startRow++;
                    SchemeDetail detail = collect.get(0);
                    XSSFRow nextRow = sheet.createRow(startRow);
                    XSSFCell subtitleCell = nextRow.createCell(2);
                    subtitleCell.setCellValue(subModule.getTitle());
                    subtitleCell.setCellStyle(subTitleCellStyle);
                    XSSFCell startCell = nextRow.createCell(6);
                    startCell.setCellValue(dateFormat.format(detail.getStartTime()));
                    startCell.setCellStyle(subStartCellStyle);
                    XSSFCell timesCell = nextRow.createCell(7);
                    int dayDiffer = DbUtils.getDayDiffer(detail.getStartTime(), detail.getEndTime());
                    timesCell.setCellValue(dayDiffer);
                    timesCell.setCellStyle(titleRow.getRowStyle());
 
                    XSSFCell endCell = nextRow.createCell(9);
                    endCell.setCellValue(dateFormat.format(detail.getEndTime()));
                    endCell.setCellStyle(subtimesCellStyle);
 
                    XSSFCell remarkCell = nextRow.createCell(10);
                    remarkCell.setCellValue((detail.getRemark()));
                    remarkCell.setCellStyle(titleRow.getRowStyle());
 
                    if (detail.getFinish()) {
                        XSSFCell finishCell = nextRow.createCell(8);
                        finishCell.setCellValue(dateFormat.format(detail.getFinishTime()));
                        finishCell.setCellStyle(subendTimeCellCellStyle);
 
                        XSSFCell endScheduleCell = nextRow.createCell(11);
                        endScheduleCell.setCellValue(DbUtils.getDayDiffer(detail.getStartTime(), detail.getFinishTime()));
                        endScheduleCell.setCellStyle(titleRow.getRowStyle());
                    }
 
                    index = 12;
                    Boolean finish = detail.getFinish();
                    startTime = scheme.getStartTime();
                    start.setTime(scheme.getStartTime());
                    endTime = scheme.getEndTime();
                    while (startTime.before(endTime)) {
                        startTime = start.getTime();
                        Date subStart = detail.getStartTime();
                        Date subEnd = detail.getEndTime();
                        Date lastTime;
                        if (finish && (DbUtils.getDayDiffer(detail.getFinishTime(), detail.getEndTime()) > 0)){
                            lastTime = detail.getFinishTime();
                        }
                        else{
                            lastTime = detail.getEndTime();
                        }
 
                        if (DbUtils.getDayDiffer(startTime, subStart) <= 0 && DbUtils.getDayDiffer(startTime, subEnd) >= 0) {
                            XSSFCell inTimeCell = nextRow.createCell(index);
                            inTimeCell.setCellStyle(planStyle);
                        }else if(DbUtils.getDayDiffer(startTime, subEnd) <= 0 && DbUtils.getDayDiffer(startTime, lastTime) >= 0){
                            XSSFCell inTimeCell = nextRow.createCell(index);
                            inTimeCell.setCellStyle(exportStyle);
                        }
                        if (detail.getFinish() && DbUtils.getDayDiffer(startTime, detail.getFinishTime()) == 0) {
                            XSSFCell inTimeCell = nextRow.createCell(index);
                            inTimeCell.setCellStyle(cellEndStyle);
                        }
 
                        index++;
                        start.add(Calendar.DAY_OF_YEAR, 1);
                    }
 
                }
                startRow++;
            }
 
            response.setContentType("application/octet-stream;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.setHeader("content-type", "application/octet-stream;charset=UTF-8");
            //默认Excel名称
            response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode("mapping数据.xlsx", "UTF-8"));
 
 
            response.flushBuffer();
            wb.write(response.getOutputStream());
        } catch (Exception e) {
            e.printStackTrace();
        }
 
 
    }
 
    @RequestMapping("{detailId}/download/{fileName}")
    public Result downLoad(@PathVariable String detailId, @PathVariable String fileName, HttpServletResponse response) throws UnsupportedEncodingException {
        SchemeDetail detail = schemeDetailService.selectById(detailId);
        if (detail == null) {
            return Result.error(CodeMsg.SELECT_ERROR);
        }
 
        String parentId = detail.getParentId();
        Scheme scheme = schemeService.selectById(parentId);
        if (scheme == null) {
            return Result.error(CodeMsg.SELECT_ERROR);
        }
 
        String path = FileUtils.createFile(basePath, scheme.getName(), detail.getType().covert());
        File file = new File(path);
        if (file.exists()) { //判断文件父目录是否存在
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            // response.setContentType("application/force-download");
            response.setHeader("Content-Disposition", "attachment;fileName=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
            byte[] buffer = new byte[1024];
            FileInputStream fis = null; //文件输入流
            BufferedInputStream bis = null;
 
            OutputStream os = null; //输出流
            try {
                os = response.getOutputStream();
                fis = new FileInputStream(file);
                bis = new BufferedInputStream(fis);
                int i = bis.read(buffer);
                while (i != -1) {
                    os.write(buffer);
                    i = bis.read(buffer);
                }
 
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            log.info("----------file download---" + fileName);
            try {
                bis.close();
                fis.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return null;
    }
 
    @RequestMapping("/download/{topicId}")
    public Result downLoadTopic(@PathVariable String topicId, HttpServletResponse response) throws UnsupportedEncodingException {
        Topic topic = topicService.selectById(topicId);
        String path = topic.getAttachment();
        File file = new File(path);
        if (file.exists()) { //判断文件父目录是否存在
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            // response.setContentType("application/force-download");
            response.setHeader("Content-Disposition", "attachment;fileName=" + java.net.URLEncoder.encode(file.getName(), "UTF-8"));
            byte[] buffer = new byte[1024];
            FileInputStream fis = null; //文件输入流
            BufferedInputStream bis = null;
 
            OutputStream os = null; //输出流
            try {
                os = response.getOutputStream();
                fis = new FileInputStream(file);
                bis = new BufferedInputStream(fis);
                int i = bis.read(buffer);
                while (i != -1) {
                    os.write(buffer);
                    i = bis.read(buffer);
                }
 
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            log.info("----------file download---" + file.getName());
            try {
                bis.close();
                fis.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return null;
    }
 
    @RequestMapping("/downloadPath/{path}")
    public Result downLoadPath(@PathVariable String path, HttpServletResponse response) throws UnsupportedEncodingException {
        path = URLDecoder.decode(path, "UTF-8");
        File file = new File(path);
        if (file.exists()) { //判断文件父目录是否存在
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            // response.setContentType("application/force-download");
            response.setHeader("Content-Disposition", "attachment;fileName=" + java.net.URLEncoder.encode(file.getName(), "UTF-8"));
            byte[] buffer = new byte[1024];
            FileInputStream fis = null; //文件输入流
            BufferedInputStream bis = null;
 
            OutputStream os = null; //输出流
            try {
                os = response.getOutputStream();
                fis = new FileInputStream(file);
                bis = new BufferedInputStream(fis);
                int i = bis.read(buffer);
                while (i != -1) {
                    os.write(buffer);
                    i = bis.read(buffer);
                }
 
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            log.info("----------file download---" + file.getName());
            try {
                bis.close();
                fis.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return null;
    }
 
    /**
     * 实现文件上传
     */
    @RequestMapping("fileUpload/{detailId}")
    @ResponseBody
    public Result fileUpload(@PathVariable String detailId, @RequestParam("file") MultipartFile file, HttpServletRequest request) {
        String desp = request.getParameter("desp");
        SchemeDetail detail = schemeDetailService.selectById(detailId);
        if (detail == null) {
            return Result.error(CodeMsg.SELECT_ERROR);
        }
        if (!detail.getMustAttach()) {
            ProjectDeal projectDeal = new ProjectDeal();
            projectDeal.setCreateTime(new Date()).setSchemeId(detail.getParentId())
                    .setSchemeDetailId(detailId).setDesp(desp)
                    .setId(DbUtils.getUUID()).insert();
 
            detail.setFinish(true);
            detail.setUpdateTime(new Date());
            detail.setFinishTime(new Date());
            detail.updateById();
            return Result.success(CodeMsg.SUCCESS);
        }
        if (file.isEmpty()) {
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
 
        String parentId = detail.getParentId();
        Scheme scheme = schemeService.selectById(parentId);
        if (scheme == null) {
            return Result.error(CodeMsg.SELECT_ERROR);
        }
 
        String fileName = file.getOriginalFilename();
        int size = (int) file.getSize();
        log.info(fileName + "-->" + size);
 
        String path = FileUtils.createFile(basePath, scheme.getName(), detail.getType().covert());
        File dest = new File(path + "/" + fileName);
        if (!dest.getParentFile().exists()) { //判断文件父目录是否存在
            dest.getParentFile().mkdirs();
        }
        dest.deleteOnExit();
 
        try {
            dest.createNewFile();
            file.transferTo(dest); //保存文件
 
            ProjectDeal projectDeal = new ProjectDeal();
            projectDeal.setCreateTime(new Date()).setSchemeId(detail.getParentId())
                    .setAttachment(path + "/" + fileName)
                    .setSchemeDetailId(detailId).setDesp(desp)
                    .setId(DbUtils.getUUID()).insert();
 
            ProjectDeal projectDeal2 = new ProjectDeal();
            projectDeal2.setCreateTime(new Date()).setSchemeId(detail.getParentId())
                    .setSchemeDetailId(detailId).setDesp("处理任务:" + detail.getType().covert())
                    .setId(DbUtils.getUUID()).insert();
            detail.setFinish(true);
            detail.setAttachment(path + "/" + fileName);
            detail.setUpdateTime(new Date());
            detail.setFinishTime(new Date());
            detail.updateById();
            return Result.success(CodeMsg.SUCCESS);
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return Result.error(CodeMsg.OPERATR_ERROR);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return Result.error(CodeMsg.OPERATR_ERROR);
        }
    }
 
    /**
     * 实现文件上传
     */
    @RequestMapping("/schemeUpload/{id}")
    @ResponseBody
    public Result schemeFileUpload(@PathVariable String id, @RequestParam("file") MultipartFile file, HttpServletRequest request) {
        Scheme scheme = schemeService.selectById(id);
        if (scheme == null) {
            return Result.error(CodeMsg.SELECT_ERROR);
        }
 
        String fileName = file.getOriginalFilename();
        int size = (int) file.getSize();
        log.info(fileName + "-->" + size);
 
        String path = FileUtils.createFile(basePath, scheme.getName(), null);
        File dest = new File(path + "/" + fileName);
        if (!dest.getParentFile().exists()) { //判断文件父目录是否存在
            dest.getParentFile().mkdirs();
        }
        dest.deleteOnExit();
 
        try {
            dest.createNewFile();
            file.transferTo(dest); //保存文件
 
            scheme.setAttachment(path + "/" + fileName);
            scheme.updateById();
            return Result.success(CodeMsg.SUCCESS);
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return Result.error(CodeMsg.OPERATR_ERROR);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return Result.error(CodeMsg.OPERATR_ERROR);
        }
    }
 
    @RequestMapping("topicUpload")
    @ResponseBody
    public Result topicUpload(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
//        new TitleService().setPopulation(population);
        Map<String, String[]> parameterMap = request.getParameterMap();
        String population = request.getParameter("population");
        String exposure = request.getParameter("exposure");
        String comparator = request.getParameter("comparator");
        String outcomes = request.getParameter("outcomes");
        String outcomesOther = request.getParameter("outcomesOther");
        String titleType = request.getParameter("titleType");
 
        TitleService titleService =new TitleService().setPopulation(population)
                .setExposure(exposure).setComparator(comparator).setOutcomes(outcomes).setOutcomesOther(outcomesOther)
                .setTitleType(titleType);
        String id = titleService.getId();
 
        String title = titleService.createTitle();
        String userId = request.getParameter("userId");
        Topic topic;
        if (StringUtils.isEmpty(id)) {
            String uuid = DbUtils.getUUID();
            titleService.setId(uuid);
            titleService.setTitle(titleService.createTitle());
            titleService.insert();
            topic = new Topic().setTitleId(uuid).setId(uuid).setUserId(userId).setCreateTime(new Date());
        } else {
            titleService.setTitle(titleService.createTitle());
            titleService.updateById();
            topic = topicService.selectById(id);
        }
 
        String fileName = file.getOriginalFilename();
        int size = (int) file.getSize();
        log.info(fileName + "-->" + size);
        String path = topicPath + "/" + topic.getId() + fileName;
        File dest = new File(path);
        if (!dest.getParentFile().exists()) { //判断文件父目录是否存在
            dest.getParentFile().mkdirs();
        }
        dest.deleteOnExit();
 
        try {
            dest.createNewFile();
            file.transferTo(dest); //保存文件
            topic.setAttachment(path);
            topic.insertOrUpdate();
            return Result.success(CodeMsg.SUCCESS);
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return Result.error(CodeMsg.OPERATR_ERROR);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return Result.error(CodeMsg.OPERATR_ERROR);
        }
    }
 
 
    /**
     * 实现多文件上传
     */
    @RequestMapping(value = "multifileUpload", method = RequestMethod.POST)
    public @ResponseBody
    String multifileUpload(HttpServletRequest request) {
 
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("fileName");
 
        if (files.isEmpty()) {
            return "false";
        }
 
        String path = "F:/test";
 
        for (MultipartFile file : files) {
            String fileName = file.getOriginalFilename();
            int size = (int) file.getSize();
            log.info(fileName + "-->" + size);
 
            if (file.isEmpty()) {
                return "false";
            } else {
                File dest = new File(path + "/" + fileName);
                if (!dest.getParentFile().exists()) { //判断文件父目录是否存在
                    dest.getParentFile().mkdir();
                }
                try {
                    file.transferTo(dest);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    return "false";
                }
            }
        }
        return "true";
    }
 
}