|
@@ -3,6 +3,7 @@ package org.springblade.manager.formula.impl;
|
|
|
import com.mixsmart.utils.FormulaUtils;
|
|
|
import com.mixsmart.utils.StringUtils;
|
|
|
import lombok.Data;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.StringPool;
|
|
|
import org.springblade.manager.dto.ElementData;
|
|
|
import org.springblade.manager.dto.FormData;
|
|
@@ -25,7 +26,9 @@ public class SubTable {
|
|
|
public static final Integer[] STEP = new Integer[]{15, 15, 1};
|
|
|
public static final List<String> KEYS = Arrays.asList(ITEM, DESIGN, DATA);
|
|
|
public static final Integer ROW_SIZE = 15;
|
|
|
- private LinkedHashMap<String, List<Object>> group = new LinkedHashMap<>();
|
|
|
+ private LinkedHashMap<String, Item> group = new LinkedHashMap<>();
|
|
|
+ private LinkedHashMap<String, Item> original = new LinkedHashMap<>();
|
|
|
+ private List<FormData> mainList;
|
|
|
private FormData itemName;
|
|
|
private FormData design;
|
|
|
private FormData data;
|
|
@@ -34,7 +37,7 @@ public class SubTable {
|
|
|
public SubTable() {
|
|
|
}
|
|
|
|
|
|
- public SubTable(List<FormData> source) {
|
|
|
+ public SubTable(List<FormData> source,List<FormData> mainList) {
|
|
|
if (source != null && source.size() > 0) {
|
|
|
source.stream().filter(e -> KEYS.contains(e.getEName().trim())).forEach(fd -> {
|
|
|
/*这是把所有数据重置为空,如果要实现手填就必须分析出项目,按项目名称覆盖LinkedHashMap<String, List<Object>> group*/
|
|
@@ -54,8 +57,7 @@ public class SubTable {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- /*初始化group,保留原先内容,只做同KEY覆盖*/
|
|
|
- initGroup();
|
|
|
+ this.mainList=mainList;
|
|
|
}
|
|
|
|
|
|
/*获取每页的行数*/
|
|
@@ -67,51 +69,75 @@ public class SubTable {
|
|
|
return itemName != null && data != null;
|
|
|
}
|
|
|
|
|
|
- public void put(String key, List<ElementData> data) {
|
|
|
+/* public void put(String key, List<ElementData> data) {
|
|
|
if (data != null && data.size() > 0) {
|
|
|
group.put(key, data.stream().map(ElementData::getValue).filter(StringUtils::isNotEmpty).collect(Collectors.toList()));
|
|
|
}
|
|
|
+ }*/
|
|
|
+
|
|
|
+ public void put(List<FormData> inspectionList,Map<String, FormData> formDataMap) {
|
|
|
+ /*检验单、评定表不能超过一页,多余的需要删除并把检测项数据写人附表*/
|
|
|
+ /*检验单或者评定表存的超页数据汇总到附表对象*/
|
|
|
+ for(FormData fd:inspectionList){
|
|
|
+ List<ElementData> overList = fd.getValues().stream().skip(fd.getCoordsList().size()).collect(Collectors.toList());
|
|
|
+ fd.setValues(fd.getValues().stream().limit(fd.getCoordsList().size()).collect(Collectors.toList()));
|
|
|
+ fd.setAddPages(0);
|
|
|
+ Item item = new Item(FormulaUtils.parseItemName(fd.getEName()).trim());
|
|
|
+ /*同项目*/
|
|
|
+ Optional<FormData> designFdOp = formDataMap.values().stream().filter(o -> o.getTableName().equals(fd.getTableName()) && !o.equals(fd) && fd.getMaxRow().equals(o.getMaxRow()) && o.getEName().contains("设计")).findAny();
|
|
|
+ designFdOp.ifPresent(formData -> item.setDesign(formData.getValues().stream().map(ElementData::stringValue).filter(StringUtils::isNotEmpty).collect(Collectors.toList())));
|
|
|
+ item.setData(FormulaUtils.setScale(null, overList).stream().map(ElementData::getValue).filter(StringUtils::isNotEmpty).collect(Collectors.toList()));
|
|
|
+ group.put(item.getName(),item);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public void flush() {
|
|
|
+ if(!checked()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ /*初始化group,保留原先内容,只做同KEY覆盖*/
|
|
|
+ initGroup();
|
|
|
/*行号,起始为0,当前行号整除列大小余0就是每页首行*/
|
|
|
AtomicInteger index=new AtomicInteger(0);
|
|
|
- if (group.size() > 0) {
|
|
|
+ List<Item> itemList =getPutOutList();
|
|
|
+ if (itemList.size() > 0) {
|
|
|
List<String> itemNameList = new ArrayList<>();
|
|
|
List<Object> designList = new ArrayList<>();
|
|
|
List<Object> dataList = new ArrayList<>();
|
|
|
int columnSize = getColumnSize();
|
|
|
- for (Map.Entry<String, List<Object>> entry : group.entrySet()) {
|
|
|
- String key = entry.getKey();
|
|
|
- String[] nameAndDesign = key.split("@");
|
|
|
- List<Object> values = entry.getValue();
|
|
|
+
|
|
|
+ for (Item item :itemList) {
|
|
|
+ String name = item.getName();
|
|
|
+ List<Object> values = item.getData();
|
|
|
/*写人的行数*/
|
|
|
int count = (int) Math.ceil((double) values.size() / (double) ROW_SIZE);
|
|
|
if(count>1) {
|
|
|
/*每一页的首行都要显示*/
|
|
|
int head= index.get();
|
|
|
- List<String> tmp= IntStream.range(head,head+count).boxed().map(i->{
|
|
|
- String res=StringPool.EMPTY;
|
|
|
+ List<String> tmp= IntStream.range(head,head+count).boxed().map(i->{
|
|
|
+ String res=StringPool.EMPTY;
|
|
|
if(i==head||(i%columnSize==0)){
|
|
|
- res= nameAndDesign[0];
|
|
|
+ res= name;
|
|
|
}
|
|
|
- index.getAndIncrement();
|
|
|
- return res;
|
|
|
+ index.getAndIncrement();
|
|
|
+ return res;
|
|
|
}).collect(Collectors.toList());
|
|
|
itemNameList.addAll(tmp);
|
|
|
}else{
|
|
|
/*行号+1*/
|
|
|
index.getAndIncrement();
|
|
|
- itemNameList.add(nameAndDesign[0]);
|
|
|
+ itemNameList.add(name);
|
|
|
}
|
|
|
if (design != null) {
|
|
|
- if (nameAndDesign.length >= 2) {
|
|
|
- designList.add( nameAndDesign[1]);
|
|
|
+ if (Func.isNotEmpty(item.getDesign())) {
|
|
|
+ String ds=item.getDesignStr();
|
|
|
+ designList.add(ds);
|
|
|
if(count>1){
|
|
|
- designList.addAll(Collections.nCopies(count-1, nameAndDesign[1]));
|
|
|
+ designList.addAll(Collections.nCopies(count-1, ds));
|
|
|
}
|
|
|
} else {
|
|
|
- designList.addAll(Collections.nCopies(count, ""));
|
|
|
+ designList.addAll(Collections.nCopies(count, StringPool.EMPTY));
|
|
|
}
|
|
|
}
|
|
|
dataList.addAll(values);
|
|
@@ -125,34 +151,71 @@ public class SubTable {
|
|
|
FormulaUtils.write(design, designList, true);
|
|
|
design.setUpdate(1);
|
|
|
}
|
|
|
-
|
|
|
FormulaUtils.write(data, dataList, true);
|
|
|
itemName.setUpdate(1);
|
|
|
data.setUpdate(1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /*获取最终输出的项目信息*/
|
|
|
+ public List<Item> getPutOutList(){
|
|
|
+ List<Item> itemList = new ArrayList<>(group.values());
|
|
|
+ if(this.mainList!=null){
|
|
|
+ List<String> itemNameIndex = this.mainList.stream().map(e->FormulaUtils.parseItemName(e.getEName()).trim()).collect(Collectors.toList());
|
|
|
+ AtomicInteger other= new AtomicInteger(itemList.size());
|
|
|
+ itemList.sort(Comparator.comparingInt(item-> itemNameIndex.contains(item.getName()) ?itemNameIndex.indexOf(item.getName()): other.getAndIncrement()));
|
|
|
+ }
|
|
|
+ return itemList;
|
|
|
+ }
|
|
|
/*用原有数据初始化*/
|
|
|
private void initGroup(){
|
|
|
- if(checked()) {
|
|
|
- List<String> itemName = this.itemName.getValues().stream().map(ElementData::stringValue).collect(Collectors.toList());
|
|
|
- List<String> designs = this.design.getValues().stream().map(ElementData::stringValue).collect(Collectors.toList());
|
|
|
- List<Object> data = this.data.getRawValue();
|
|
|
- String name = itemName.get(0);
|
|
|
- if(StringUtils.isNotEmpty(name)) {
|
|
|
- int head = 0;
|
|
|
- for (int i = 1; i < itemName.size(); i++) {
|
|
|
- String x = itemName.get(i);
|
|
|
- /*如果非空且与当前的不一样则视为新项目*/
|
|
|
- if (StringUtils.isNotEmpty(x) && !x.equals(name) || (i == itemName.size() - 1)) {
|
|
|
- String des = designs.subList(head, i).stream().filter(StringUtils::isNotEmpty).distinct().collect(Collectors.joining("/"));
|
|
|
- group.put(name + StringPool.AT + des, data.subList(head*15, i*ROW_SIZE));
|
|
|
- head = i;
|
|
|
- name = x;
|
|
|
- }
|
|
|
+ List<String> itemName = this.itemName.getValues().stream().map(ElementData::stringValue).collect(Collectors.toList());
|
|
|
+ List<String> designs = this.design.getValues().stream().map(ElementData::stringValue).collect(Collectors.toList());
|
|
|
+ List<Object> data = this.data.getRawValue();
|
|
|
+ String name = itemName.get(0);
|
|
|
+ if(StringUtils.isNotEmpty(name)) {
|
|
|
+ int head = 0;
|
|
|
+ for (int i = 1; i < itemName.size(); i++) {
|
|
|
+ String x = itemName.get(i);
|
|
|
+ /*如果非空且与当前的不一样则视为新项目*/
|
|
|
+ if (StringUtils.isNotEmpty(x) && !x.equals(name) || (i == itemName.size() - 1)) {
|
|
|
+ /* String des =designs.subList(head, i).stream().filter(StringUtils::isNotEmpty).distinct().collect(Collectors.joining("/"));*/
|
|
|
+ Item item = new Item(name);
|
|
|
+ item.setDesign(designs.subList(head, i).stream().filter(StringUtils::isNotEmpty).distinct().collect(Collectors.toList()));
|
|
|
+ /* original.put(name + StringPool.AT + des, new ArrayList<>(data.subList(head*15, i*ROW_SIZE)));*/
|
|
|
+ item.setData(new ArrayList<>(data.subList(head*15, i*ROW_SIZE)));
|
|
|
+ original.put(name,item);
|
|
|
+ head = i;
|
|
|
+ name = x;
|
|
|
}
|
|
|
}
|
|
|
+ merge();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*合并数据*/
|
|
|
+ private void merge(){
|
|
|
+ if(original.size()>0){
|
|
|
+ original.forEach((k,v)->{
|
|
|
+ group.computeIfAbsent(k,key->original.get(key));
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Data
|
|
|
+ public static class Item{
|
|
|
+ /*项目的顺序要根据检验单上的自上到下的顺序,相同项目名需要合并,如果存在不同设计值则连续显示;空白行要去除*/
|
|
|
+ private String name;
|
|
|
+ private List<String>design;
|
|
|
+ private List<Object> data;
|
|
|
+ public Item(String name) {
|
|
|
+ this.name = name;
|
|
|
+ }
|
|
|
+ public String getDesignStr(){
|
|
|
+ return String.join("/", design);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|