|
@@ -0,0 +1,68 @@
|
|
|
+/*
|
|
|
+ * *************************************************
|
|
|
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
|
|
|
+ * Created by Deason on 2018-11-01 14:11:22.
|
|
|
+ * *************************************************
|
|
|
+ */
|
|
|
+
|
|
|
+package cn.com.qmth.examcloud.core.print.service.bean.printingtemplate;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.core.print.entity.PrintingTemplate;
|
|
|
+import cn.com.qmth.examcloud.core.print.enums.TemplateType;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: fengdesheng
|
|
|
+ * @since: 2018/11/01
|
|
|
+ */
|
|
|
+public class PrintingTemplateConvert {
|
|
|
+
|
|
|
+ public static PrintingTemplate of(PrintingTemplateInfo info) {
|
|
|
+ PrintingTemplate entity = new PrintingTemplate();
|
|
|
+ BeanUtils.copyProperties(info, entity);
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static PrintingTemplateInfo of(PrintingTemplate entity) {
|
|
|
+ PrintingTemplateInfo info = new PrintingTemplateInfo();
|
|
|
+ BeanUtils.copyProperties(entity, info);
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<PrintingTemplateInfo> ofList(List<PrintingTemplate> entities) {
|
|
|
+ if (entities == null) {
|
|
|
+ return Lists.newArrayList();
|
|
|
+ }
|
|
|
+ return entities.stream().map(entity -> of(entity)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 补全所有的模板类型信息(用于界面布局)
|
|
|
+ */
|
|
|
+ public static List<PrintingTemplateInfo> fillMoreTypes(List<PrintingTemplate> entities) {
|
|
|
+ Map<Integer, PrintingTemplateInfo> maps = new HashMap<>();
|
|
|
+ if (entities != null) {
|
|
|
+ for (PrintingTemplate entity : entities) {
|
|
|
+ maps.put(entity.getTemplateType(), of(entity));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PrintingTemplateInfo> allTypes = new ArrayList<>();
|
|
|
+ for (TemplateType type : TemplateType.values()) {
|
|
|
+ if (maps.containsKey(type.getIndex())) {
|
|
|
+ allTypes.add(maps.get(type.getIndex()));
|
|
|
+ } else {
|
|
|
+ allTypes.add(new PrintingTemplateInfo(type.getIndex()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return allTypes;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|