From 5cd4262f233df612fc9776c2be24bdf399f917f3 Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Thu, 27 Aug 2020 16:26:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=A4=B1=E8=B4=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AF=BC=E5=87=BA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 + .../msdw/tms/api/QuestionsControllerApi.java | 7 + .../com/msdw/tms/common/utils/Constant.java | 5 +- .../tms/common/utils/poi/ExcelImportUtil.java | 2 +- .../controller/PersonalFileController.java | 3 +- .../tms/controller/ProjectController.java | 3 +- .../tms/controller/QuestionsController.java | 11 +- .../request/QuestionsImportRequest.java | 13 ++ .../msdw/tms/entity/response/CommonCode.java | 1 + .../entity/vo/QuestionsImportFailureVO.java | 76 ++++++++ .../msdw/tms/service/QuestionsService.java | 7 +- .../impl/ProjectRecordServiceImpl.java | 2 +- .../service/impl/QuestionsServiceImpl.java | 122 ++++++++++-- .../试题导入失败数据导出模板.xlsx | Bin 0 -> 10178 bytes .../excel-template/试题导出模板.xlsx | Bin 10889 -> 10311 bytes .../com/msdw/tms/TmsApplicationTests.java | 181 +++++++++++++++++- src/test/java/com/msdw/tms/UserTest.java | 26 +++ .../tms/service/QuestionsServiceTest.java | 5 +- 18 files changed, 443 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/msdw/tms/entity/vo/QuestionsImportFailureVO.java create mode 100644 src/main/resources/excel-template/试题导入失败数据导出模板.xlsx create mode 100644 src/test/java/com/msdw/tms/UserTest.java diff --git a/pom.xml b/pom.xml index b7ca58f..51f1328 100644 --- a/pom.xml +++ b/pom.xml @@ -139,9 +139,16 @@ hutool-all 5.3.8 + + + com.alibaba + fastjson + 1.2.72 + + evaluation org.springframework.boot diff --git a/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java b/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java index 1257152..7ebee11 100644 --- a/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java +++ b/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java @@ -95,4 +95,11 @@ public interface QuestionsControllerApi { @ApiOperation(value = "通过excel批量导出", notes = "通过excel批量导出") void exportQuestion(HttpServletResponse response) throws Exception; + + /** + * 通过excel批量导出 + */ + @ApiOperation(value = "导出导入失败的数据和失败原因", notes = "导出导入失败的数据和失败原因") + void exportFailureRecord(HttpServletResponse response, String token) throws Exception; + } diff --git a/src/main/java/com/msdw/tms/common/utils/Constant.java b/src/main/java/com/msdw/tms/common/utils/Constant.java index 5ee4add..bd399bf 100644 --- a/src/main/java/com/msdw/tms/common/utils/Constant.java +++ b/src/main/java/com/msdw/tms/common/utils/Constant.java @@ -93,8 +93,9 @@ public class Constant { /** * 测评规则表id */ - public static final int EVALUATION_RULES_ID = 1;/** - * 测评规则表id + public static final int EVALUATION_RULES_ID = 1; + /** + * excel后缀 */ public static final String EXCEL_SUFFIX = ".xlsx"; /** diff --git a/src/main/java/com/msdw/tms/common/utils/poi/ExcelImportUtil.java b/src/main/java/com/msdw/tms/common/utils/poi/ExcelImportUtil.java index 1ad8ec6..73b6c98 100644 --- a/src/main/java/com/msdw/tms/common/utils/poi/ExcelImportUtil.java +++ b/src/main/java/com/msdw/tms/common/utils/poi/ExcelImportUtil.java @@ -55,7 +55,7 @@ public class ExcelImportUtil { } Field field = entity.getClass().getDeclaredField("index"); field.setAccessible(true); - field.set(entity, rowNum); + field.set(entity, rowNum + 1); list.add(entity); } } catch (Exception e) { diff --git a/src/main/java/com/msdw/tms/controller/PersonalFileController.java b/src/main/java/com/msdw/tms/controller/PersonalFileController.java index 75980fc..e21d6d7 100644 --- a/src/main/java/com/msdw/tms/controller/PersonalFileController.java +++ b/src/main/java/com/msdw/tms/controller/PersonalFileController.java @@ -1,5 +1,6 @@ package com.msdw.tms.controller; +import com.msdw.tms.api.PersonalFileControllerApi; import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.PersonalFileEntity; import com.msdw.tms.entity.vo.PersonalFileVo; @@ -12,7 +13,7 @@ import java.util.List; @RestController @RequestMapping("tms/personalFile") -public class PersonalFileController { +public class PersonalFileController implements PersonalFileControllerApi { @Autowired private PersonalFileService personalFileService; diff --git a/src/main/java/com/msdw/tms/controller/ProjectController.java b/src/main/java/com/msdw/tms/controller/ProjectController.java index 09014af..a7847a7 100644 --- a/src/main/java/com/msdw/tms/controller/ProjectController.java +++ b/src/main/java/com/msdw/tms/controller/ProjectController.java @@ -1,5 +1,6 @@ package com.msdw.tms.controller; +import com.msdw.tms.api.ProjectControllerApi; import com.msdw.tms.common.utils.PageUtils; import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.ProjectEntity; @@ -21,7 +22,7 @@ import java.util.Map; */ @RestController @RequestMapping("fictitious/project") -public class ProjectController { +public class ProjectController implements ProjectControllerApi { @Autowired private ProjectService projectService; diff --git a/src/main/java/com/msdw/tms/controller/QuestionsController.java b/src/main/java/com/msdw/tms/controller/QuestionsController.java index cbb1eb7..73f515d 100644 --- a/src/main/java/com/msdw/tms/controller/QuestionsController.java +++ b/src/main/java/com/msdw/tms/controller/QuestionsController.java @@ -19,6 +19,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Arrays; import java.util.List; +import java.util.Map; /** @@ -116,9 +117,9 @@ public class QuestionsController implements QuestionsControllerApi { @PostMapping("/import") //@RequiresPermissions("qms:questions:import") public R importQuestion(@RequestParam(name = "file") MultipartFile file) throws IOException { - List list = questionsService.importQuestion(file); + Map map = questionsService.importQuestion(file); - return R.ok().put("data", list); + return R.ok().put("data", map); } /** @@ -163,4 +164,10 @@ public class QuestionsController implements QuestionsControllerApi { questionsService.exportQuestion(response); } + @Override + @GetMapping("/export_failure") + public void exportFailureRecord(HttpServletResponse response, String token) throws Exception { + questionsService.exportFailureRecord(response, token); + } + } diff --git a/src/main/java/com/msdw/tms/entity/request/QuestionsImportRequest.java b/src/main/java/com/msdw/tms/entity/request/QuestionsImportRequest.java index 7dcb5e1..d9435ff 100644 --- a/src/main/java/com/msdw/tms/entity/request/QuestionsImportRequest.java +++ b/src/main/java/com/msdw/tms/entity/request/QuestionsImportRequest.java @@ -2,6 +2,7 @@ package com.msdw.tms.entity.request; import com.msdw.tms.common.utils.poi.ExcelAttribute; import lombok.Data; +import lombok.ToString; /** * 试题的基本信息表 @@ -9,6 +10,7 @@ import lombok.Data; * @author gongsj */ @Data +@ToString public class QuestionsImportRequest { /** * 第几行 @@ -65,4 +67,15 @@ public class QuestionsImportRequest { */ @ExcelAttribute(sort = 9) private String answerAnalysis; + + public String toStringForCompare() { + return questionStem + + questionTypeName + + optionA + + optionB + + optionC + + optionD + + optionE + + optionF; + } } diff --git a/src/main/java/com/msdw/tms/entity/response/CommonCode.java b/src/main/java/com/msdw/tms/entity/response/CommonCode.java index 542b19e..6003682 100644 --- a/src/main/java/com/msdw/tms/entity/response/CommonCode.java +++ b/src/main/java/com/msdw/tms/entity/response/CommonCode.java @@ -15,6 +15,7 @@ public enum CommonCode implements ResultCode { EXCEL_INVALID(false, 10007, "excel表内容错误!"), EVALUATION_TIME_INVALID(false, 10008, "测评时间错误!"), EXCEL_FILE_INVALID(false, 10009, "上传excel文件错误!"), + REPEAT_INEXCEL(false, 10010, "试题在excel表中重复!"), FAIL(false, 11111, "操作失败!"), SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); //操作是否成功 diff --git a/src/main/java/com/msdw/tms/entity/vo/QuestionsImportFailureVO.java b/src/main/java/com/msdw/tms/entity/vo/QuestionsImportFailureVO.java new file mode 100644 index 0000000..30e15f5 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/vo/QuestionsImportFailureVO.java @@ -0,0 +1,76 @@ +package com.msdw.tms.entity.vo; + +import com.msdw.tms.common.utils.poi.ExcelAttribute; +import lombok.Data; +import lombok.ToString; + +/** + * 试题的基本信息表 + * + * @author gongsj + */ +@Data +@ToString +public class QuestionsImportFailureVO { + /** + * 第几行 + */ + private Integer index; + + /** + * 题干,问题描述 + */ + @ExcelAttribute(sort = 0) + private String questionStem; + /** + * 题型 + */ + @ExcelAttribute(sort = 1) + private String questionTypeName; + /** + * 选项A + */ + @ExcelAttribute(sort = 2) + private String optionA; + /** + * 选项B + */ + @ExcelAttribute(sort = 3) + private String optionB; + /** + * 选项C + */ + @ExcelAttribute(sort = 4) + private String optionC; + /** + * 选项D + */ + @ExcelAttribute(sort = 5) + private String optionD; + /** + * 选项E + */ + @ExcelAttribute(sort = 6) + private String optionE; + /** + * 选项F + */ + @ExcelAttribute(sort = 7) + private String optionF; + /** + * 正确答案 + */ + @ExcelAttribute(sort = 8) + private String answer; + /** + * 答案解析 + */ + @ExcelAttribute(sort = 9) + private String answerAnalysis; + + /** + * 失败原因 + */ + @ExcelAttribute(sort = 10) + private String failureMsg; +} diff --git a/src/main/java/com/msdw/tms/service/QuestionsService.java b/src/main/java/com/msdw/tms/service/QuestionsService.java index ee57a5e..f791ba5 100644 --- a/src/main/java/com/msdw/tms/service/QuestionsService.java +++ b/src/main/java/com/msdw/tms/service/QuestionsService.java @@ -9,13 +9,12 @@ import com.msdw.tms.entity.request.QuestionsQueryRequest; import com.msdw.tms.entity.request.QuestionsUpdateRequest; import com.msdw.tms.entity.vo.EvaluationVO; import com.msdw.tms.entity.vo.QuestionsDetailVO; -import com.msdw.tms.entity.vo.QuestionsVO; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; -import java.util.Set; +import java.util.Map; /** * 记录试题信息 @@ -38,7 +37,7 @@ public interface QuestionsService extends IService { boolean deleteByIds(List asList); - List importQuestion(MultipartFile file) throws IOException; + Map importQuestion(MultipartFile file) throws IOException; FilesResult uploadFiles(MultipartFile file) throws IOException; @@ -49,5 +48,7 @@ public interface QuestionsService extends IService { void exportQuestion(HttpServletResponse response) throws Exception; String getEvaluationRemainingTime(Integer userId); + + void exportFailureRecord(HttpServletResponse response, String token) throws Exception; } diff --git a/src/main/java/com/msdw/tms/service/impl/ProjectRecordServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/ProjectRecordServiceImpl.java index 558968b..8f262a1 100644 --- a/src/main/java/com/msdw/tms/service/impl/ProjectRecordServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/ProjectRecordServiceImpl.java @@ -72,7 +72,7 @@ public class ProjectRecordServiceImpl extends ServiceImpl importQuestion(MultipartFile file) throws IOException { + public Map importQuestion(MultipartFile file) throws IOException { + //准备map接收导入失败的数据信息 + Map failureRecord = new HashMap<>(); + //准备list收集失败数据 + List failureVOs = new ArrayList<>(); + // 参数合法性校验,只能上传.xlsx后缀的文件 if (StringUtils.isBlank(file.getOriginalFilename()) || !file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")).equals(Constant.EXCEL_SUFFIX)) { @@ -337,12 +346,28 @@ public class QuestionsServiceImpl extends ServiceImpl failureRecord = new ArrayList<>(); - - for (int i = 0; i < list.size(); i++) { - QuestionsImportRequest question = list.get(i); + //去掉重复数据,得到去重后的数据 + ArrayList distinctList = list.stream().collect(Collectors.collectingAndThen(// 去重收集 + Collectors.toCollection(() -> + new TreeSet<>(Comparator.comparing(QuestionsImportRequest::toStringForCompare))), + ArrayList::new + )); + + //与元数据做差,得到重复的数据 + List repeatFactor = removeRepeatFactor(distinctList, list); + + //记录到失败信息列表 + repeatFactor.forEach(question -> { + QuestionsImportFailureVO failureVO = new QuestionsImportFailureVO(); + BeanUtils.copyProperties(question, failureVO); + failureVO.setFailureMsg(CommonCode.REPEAT_INEXCEL.message()); + failureVOs.add(failureVO); + }); + + List questions = distinctList.stream().map(question -> { //校验题干和内容重复 QuestionsEntity questionsEntity = new QuestionsEntity(); + //属性对拷 BeanUtils.copyProperties(question, questionsEntity); String questionTypeName = question.getQuestionTypeName(); //根据题型名称得到题型号 @@ -357,8 +382,11 @@ public class QuestionsServiceImpl extends ServiceImpl 0) {//说明已存在 - failureRecord.add("第 " + question.getIndex() + " 行导入失败," + "题干:" + question.getQuestionStem() + ",失败信息:" + CommonCode.QUESTION_EXISTS.message()); - continue; + QuestionsImportFailureVO failureVO = new QuestionsImportFailureVO(); + BeanUtils.copyProperties(question, failureVO); + failureVO.setFailureMsg(CommonCode.QUESTION_EXISTS.message()); + failureVOs.add(failureVO); + return null; } - + //TODO 创建者和修改者。。。 questionsEntity.setCreateTime(new Date()); questionsEntity.setModifyTime(new Date()); + return questionsEntity; + }).filter(Objects::nonNull)// 过滤掉为null的对象 + .collect(Collectors.toList()); - this.save(questionsEntity); + String token = ""; + + // 有导入失败的数据,才会存入redis + if (failureVOs.size() > 0) { + //生成token + token = FAILURE_IMPORT_KEY + UUID.randomUUID().toString().replace("-", ""); + + ValueOperations ops = stringRedisTemplate.opsForValue(); + String failureVOJson = JSON.toJSONString(failureVOs); + + ops.set(token, failureVOJson, 30 * 60, TimeUnit.SECONDS); } + // 批量保存 + this.saveBatch(questions); + + failureRecord.put("token", token); + failureRecord.put("successNum", (list.size() - failureVOs.size()) + ""); + failureRecord.put("failureNum", failureVOs.size() + ""); + return failureRecord; } + private List removeRepeatFactor(List source, List dest) { + if (source != null && dest != null) { + if (source.size() != 0 && dest.size() != 0) { + Collection A = new ArrayList<>(source); + List B = new ArrayList<>(dest); + A.retainAll(B); + if (A.size() != 0) { + B.removeAll(A); + } + return B; + } + } + return dest; + } + /** * 上传模板文件,修改模板信息表数据 */ @Override @Transactional public FilesResult uploadFiles(MultipartFile file) throws IOException { - // 参数合法性校验,只能上传.xlsx后缀的文件 if (StringUtils.isBlank(file.getOriginalFilename()) || !file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")).equals(Constant.EXCEL_SUFFIX)) { @@ -493,12 +558,10 @@ public class QuestionsServiceImpl extends ServiceImpl ops = stringRedisTemplate.opsForValue(); + //获取数据 + String record = ops.get(token); + if (StringUtils.isEmpty(record)) { + return; + } + + List parse = (List) JSON.parse(record); + parse.sort(Comparator.comparing(QuestionsImportFailureVO::getIndex)); +// Collections.sort(parse, new Comparator() { +// @Override +// public int compare(QuestionsImportFailureVO o1, QuestionsImportFailureVO o2) { +// //升序 +// return o1.getIndex().compareTo(o2.getIndex()); +// } +// }); + + //2.加载模板流数据 + org.springframework.core.io.Resource resource = new ClassPathResource("excel-template/试题导入失败数据导出模板.xlsx"); + FileInputStream fis = new FileInputStream(resource.getFile()); + + //3、通过工具类下载文件 + new ExcelExportUtil(QuestionsImportRequest.class, Constant.ROW_INDEX, Constant.STYLE_INDEX). + export(response, fis, parse, "导入失败数据表.xlsx"); + } + private Set getRandomList(int len, List list) { Set set = new HashSet<>(); Random random = new Random(); diff --git a/src/main/resources/excel-template/试题导入失败数据导出模板.xlsx b/src/main/resources/excel-template/试题导入失败数据导出模板.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..9bea0c39e7c9895d969e457f0bd00317bb6a1744 GIT binary patch literal 10178 zcmeHtg;yNe_I2a#Zo%E1;7$nc7TlfSBzUkOL4$-25FilTC1`MWr*R1yym9$;GV{L7 zF!TKd?^Ul=vZ~HmUFV*C?yh~VssaowE&v{Y2mk;m0TTSdBTi5N04y8;fCE5;Hjr|5 za<_DHH`erVv2-(J^LBKg$cBYx$O1q^p8wzWUmSsA%|54g4$NkqT`}nv?YE!83kwlR z8%Pakwh>aj6Le{6H;EW-{phXKv?>tWXw@7>4CqdU2}|bb^d!aC9oVk*RA@|4@?%O| zk45gDWy%ES7Hh{;#YORE5uzO)!cWv7DAv!LvDr~QP|@P^RwHw7wVf#MNEStiNzpbl zeJ_N*n%xuWYuAHTVDum~6Yzec&Px1zNvEkvjf-2GrYzl!Op7h)B8CySLiKC)HM#t5 z|2S@zVTBEmpcJ{dZ86jrM=o+y?l2_G3QpV;3hO|4cIw53{(3Itj(KlilRY`YhL7u| zwI0T|LcwEk(OOw5QN800DMId|KwxU@ zYU$v{&h~TvKY0EZWAZPrUYww$(!qfmcKGZzy!T>iF%DBw!As&l((hK%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z=~T}g^lZ1y;`<2d#HDVaG!cv+2PI$P%gxh{~zJ!=;`Ev4j8#I?ue)U{OOY#;Pv<|p0n8!_Kk1$>`e%73qK&JGU!(T+5oTmfu50w^Fh z2leE4eb*_P5_9vnc<4fV$iK$nKl+$rd?Fo0Vw8*k>VS6Bj_5l~oj0XLB29o5F;B=^ z?u_8+W@Ij?%Em7$8Tt~D!T0qIj_e|LPNJf9mmY9sA<=0C&2l8H8m4HuhvO~x`;?8? zJSLPiq0knxu-cH6E+$4<86e$}2vL72PIij&_@ELsST>GHg}zD)b&Mw(oNqhYgq>{Q zK~M&X>_6+r>$p%@6-ew~K-5z#hf#n0$M{&~t3h@Aj&<{&E>m9*-z~ba%O~GdBDQ?f z)!M-wi^u|0f5{yO;fib(xdcJ))h9Q7;mO?w;Imc@L`hF7YQjHJ(t7g}*MqN6GKLg_Ofn8&F~}xf$K<5 zH}f{PNzv)>1h3yrGM_Rn)Z)VgT+WPxD|mWXWY4(@9C{*fXKbb@S&6vrqx?O3crGbA zf?j-jQ}h92j{je?P|)xU>jNYUF(Dij^RHQG>f-XhB!qqF9@#Tq)ZNS;Q)*53751Fb#lP3qoar6fS_>0`$ z9Y1V2x5<;+`3X3Y^?c6(o}=NC@_E9;ARvW@Fu%bcue19^)dD3<26KT5a}Zcn4CUhO zHaMfA$liREaYM&YM{P>($9ce3($R0s6q4`w1i!0N8|%5?H-FGgaDASPEGTWzev?mC z6x@X009r5Q7h_VZbgxh19 z{n*1}V)xraCF$cB{433S?C>#9`t7iq?3cqwEa_ia(_^Q9Cjh@)0stK30Kh-!z+>~j iSMI->*HZq){LebBssIPcK>z?1@}q;KaTv|dtN#OLvzuiA literal 0 HcmV?d00001 diff --git a/src/main/resources/excel-template/试题导出模板.xlsx b/src/main/resources/excel-template/试题导出模板.xlsx index cc6ed7d7d57aa329727f0b788025b459815a375e..46366b90c68ea24c44fd77ced73871d8006e07fc 100644 GIT binary patch delta 3823 zcmZ9PXH*ji630WYLg<|kq(&(Ugk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q6Qwr1SHivbd-Q(fZhn%7!+~>I_jfMTbI_$bz|(`JiYXp4tpr)< zKfWRie)(M1r!rEn3AGjytK~65DrB79bGX?SPLiZ?aHV0tyzt7OPkxChE`S>?-TMVE zX*cCk78p9A@O#5Sc9XNCW3fsnxzCnipg}0lZ73%N55nbsuoQPEZuY7SI(^Rx_N1HW zwQXh#htj;xN{n`po7(KWA?ug;&lRQ4u7yMR-yZ`qj}wY}NC*HR$%z<{L|`D}e-Erb z=7{bOyZ#$&$R}WBtT1E%7|i&;7V6(FNn|^imFa&u`rrCJ1M(MG4*Q%LIl;t list = new ArrayList<>(); + list.add("a"); + list.add("b"); + list.add("c"); + list.add("d"); + list.add("b"); + list.add("c"); + list.add("a"); + list.add("a"); + list.add("a"); + + System.out.println("\n例子1 - 计算'a'出现的次数"); + System.out.println("a : " + Collections.frequency(list, "a")); + + System.out.println("\n例子2 - 计算所有对象出现的次数"); + Set uniqueSet = new HashSet<>(list); + for (String temp : uniqueSet) { + System.out.println(temp + ": " + Collections.frequency(list, temp)); + } + + System.out.println("\n例子3 -用Map来计算对象出现的次数"); + Map map = new HashMap<>(); + + for (String temp : list) { + Integer count = map.get(temp); + map.put(temp, (count == null) ? 1 : count + 1); + } + printMap(map); + + System.out.println("\nMap排序-以key排序"); + Map treeMap = new TreeMap<>(map); + printMap(treeMap); + + } + + static void printMap(Map map) { + for (Map.Entry entry : map.entrySet()) { + System.out.println("Key-value : " + entry.getKey() + "- " + + entry.getValue()); + } + } + + + @Test + void t9() throws Exception { + + List list = new ArrayList<>(); + list.add(new UserTest(1, "张三", "男", "深圳", "123456")); + list.add(new UserTest(2, "李四", "男", "深圳", "123456")); + list.add(new UserTest(3, "张三", "男", "杭州", "123456")); + list.add(new UserTest(4, "张三", "男", "深圳", "123456")); + list.add(new UserTest(5, "王五", "男", "深圳", "123456")); + list.add(new UserTest(6, "张三", "男", "深圳", "123456")); + list.add(new UserTest(7, "赵六", "女", "深圳", "123456")); + list.add(new UserTest(8, "赵六", "女", "深圳", "123456")); + list.add(new UserTest(9, "赵六", "女", "深圳", "123456")); + list.add(new UserTest(10, "赵六", "女", "深圳", "123456")); + list.add(new UserTest(11, "赵六", "女", "深圳", "123456")); + list.add(new UserTest(12, "张三", "男", "菲律宾", "123456")); + list.add(new UserTest(13, "张三", "男", "深圳", "123456")); + list.add(new UserTest(14, "张三", "男", "马来西亚", "123456")); + + + List errorMsg = new ArrayList<>(); + + ArrayList collect = list.stream() + .collect(Collectors.collectingAndThen(// 去重收集 + Collectors.toCollection(() -> + new TreeSet<>(Comparator.comparing(UserTest::toString))), + ArrayList::new + )); + + for (UserTest userTest : collect) { + + System.out.println(userTest.getIndex() + "-----" + userTest.toString()); + } + + System.out.println("----------------------------"); + + List userTests = removeRepeatFactor3(collect, list); + + for (UserTest userTest : userTests) { + + System.out.println(userTest.getIndex() + "-----" + userTest.toString()); + } + + + } + + private List removeRepeatFactor(List list1, List list2) { + if (list1 != null && list2 != null) { + if (list1.size() != 0 && list2.size() != 0) { + Collection A = new ArrayList<>(list1); + List B = new ArrayList<>(list2); + A.retainAll(B); + if (A.size() != 0) { + B.removeAll(A); + } + return B; + } + } + return list2; + } + + private List removeRepeatFactor3(List list1, List list2) { + if (list1 != null && list2 != null) { + if (list1.size() != 0 && list2.size() != 0) { + Collection A = new ArrayList<>(list1); + List B = new ArrayList<>(list2); + A.retainAll(B); + if (A.size() != 0) { + B.removeAll(A); + } + return B; + } + } + return list2; + } + + public List removeRepeatFactor2(List list1, List list2) throws Exception { + if (list1 != null && list2 != null) { + if (list1.size() != 0 && list2.size() != 0) { + Collection A = new ArrayList<>(list1); + Collection B = new ArrayList<>(list2); + A.retainAll(B); + if (A.size() != 0) { + B.removeAll(A); + } + return (List) B; + } + } + return list2; + } + + + @Test + void t10() { + + QuestionsImportRequest questionsImportRequest = new QuestionsImportRequest(); + questionsImportRequest.setOptionA("aaa"); + questionsImportRequest.setOptionB("bbb"); + questionsImportRequest.setOptionC("ccc"); + questionsImportRequest.setOptionD("ddd"); + questionsImportRequest.setOptionE("eee"); + questionsImportRequest.setOptionF("fff"); + questionsImportRequest.setQuestionStem("stem"); + questionsImportRequest.setQuestionTypeName("type"); + + System.out.println(questionsImportRequest.toStringForCompare()); + + } + + @Test + void t11() { + + List list = new ArrayList<>(); + list.add(new UserTest(1, "张三", "男", "深圳", "123456")); + list.add(new UserTest(2, "李四", "男", "深圳", "123456")); + list.add(new UserTest(3, "张三", "男", "杭州", "123456")); + list.add(new UserTest(4, "张三", "男", "深圳", "123456")); + list.add(new UserTest(5, "王五", "男", "深圳", "123456")); + list.add(new UserTest(6, "张三", "男", "深圳", "123456")); + list.add(new UserTest(7, "赵六", "女", "深圳", "123456")); + list.add(new UserTest(8, "赵六", "女", "深圳", "123456")); + list.add(new UserTest(9, "赵六", "女", "深圳", "123456")); + list.add(new UserTest(10, "赵六", "女", "深圳", "123456")); + list.add(new UserTest(11, "赵六", "女", "深圳", "123456")); + list.add(new UserTest(12, "张三", "男", "菲律宾", "123456")); + list.add(new UserTest(13, "张三", "男", "深圳", "123456")); + list.add(new UserTest(14, "张三", "男", "马来西亚", "123456")); + + stringRedisTemplate.opsForList().leftPush("sss", list.toString()); + } + } diff --git a/src/test/java/com/msdw/tms/UserTest.java b/src/test/java/com/msdw/tms/UserTest.java new file mode 100644 index 0000000..84e2982 --- /dev/null +++ b/src/test/java/com/msdw/tms/UserTest.java @@ -0,0 +1,26 @@ +package com.msdw.tms; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class UserTest { + private int index; + private String name; + private String gender; + private String addr; + private String phone; + + @Override + public String toString() { + return "UserTest{" + + "name='" + name + '\'' + + ", gender='" + gender + '\'' + + ", addr='" + addr + '\'' + + ", phone='" + phone + '\'' + + '}'; + } +} diff --git a/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java b/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java index 062824a..31729c3 100644 --- a/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java +++ b/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.nio.file.Files; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * 记录试题信息 @@ -93,9 +94,9 @@ class QuestionsServiceTest { IOUtils.copy(new FileInputStream(file), fileItem.getOutputStream()); MultipartFile multipartFile = new CommonsMultipartFile(fileItem); - List strings = questionsService.importQuestion(multipartFile); + Map map = questionsService.importQuestion(multipartFile); - System.out.println(strings.toString()); + System.out.println(map.toString()); } @Test