feat: 迁移国内标准法规部分1
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.adc.da.utils.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作树的接口类
|
||||
*
|
||||
*/
|
||||
public interface ITree {
|
||||
/**
|
||||
* 获取构建数的list,因为根节点可能不止一个,所有返回List
|
||||
* 获取的结构与getRoot基本一致,但是后边增加了另外的数据,不建议调用
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<TreeNode> getTree();
|
||||
|
||||
/**
|
||||
* 获取根节点树结构,因为根节点可能不止一个,所有返回List
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<TreeNode> getRoot();
|
||||
|
||||
/**
|
||||
* 获取指定节点数据
|
||||
*
|
||||
* @param nodeId
|
||||
* @return
|
||||
*/
|
||||
TreeNode getTreeNode(String nodeId);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.adc.da.utils.tree;
|
||||
|
||||
/**
|
||||
* 需要实现树的实体类需要实现的接口,获取关键数据
|
||||
*
|
||||
*/
|
||||
public interface ITreeNode<T> {
|
||||
/**
|
||||
* TreeNode获取nodeId
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getNodeId();
|
||||
|
||||
/**
|
||||
* TreeNode获取nodeName
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getNodeName();
|
||||
|
||||
/**
|
||||
* TreeNode获取nodeParentId(父id)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getNodeParentId();
|
||||
|
||||
/**
|
||||
* TreeNode获取orderNum(排序字段用于排序)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Integer getOrderNum();
|
||||
|
||||
/**
|
||||
* TreeNode获取nodeLevel(当前属于第几层级)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Integer getNodeLevel();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.adc.da.utils.tree;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 构建树形建构
|
||||
*/
|
||||
public class Tree implements ITree {
|
||||
/**
|
||||
* 用于存放treeNode的Map
|
||||
*/
|
||||
private LinkedHashMap<String, TreeNode> treeNodesMap = new LinkedHashMap<>();
|
||||
/**
|
||||
* 用于存放treeNode的list
|
||||
*/
|
||||
private List<TreeNode> treeNodesList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
public Tree(List<ITreeNode> list) {
|
||||
initTreeNodeMap(list);
|
||||
initTreeNodeList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将List对象数据转为TreeNodeMap
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
private void initTreeNodeMap(List<ITreeNode> list) {
|
||||
TreeNode treeNode;
|
||||
for (ITreeNode item : list) {
|
||||
treeNode = new TreeNode(item);
|
||||
treeNode.setLastNodeNum(1);
|
||||
treeNodesMap.put(treeNode.getNodeId(), treeNode);
|
||||
}
|
||||
Iterator<TreeNode> iterator = treeNodesMap.values().iterator();
|
||||
TreeNode parentTreeNode;
|
||||
while (iterator.hasNext()) {
|
||||
treeNode = iterator.next();
|
||||
if (StringUtils.isEmpty(treeNode.getParentNodeId())) {
|
||||
continue;
|
||||
}
|
||||
parentTreeNode = treeNodesMap.get(treeNode.getParentNodeId());
|
||||
if (parentTreeNode != null) {
|
||||
treeNode.setParent(parentTreeNode);
|
||||
parentTreeNode.addChild(treeNode);
|
||||
// 按照orderNum排序
|
||||
Collections.sort(parentTreeNode.getChildren(), new OrdNamComparator());
|
||||
// 判断这个节点是否是最子节点
|
||||
if (treeNode.getChildren().size() == 0) {
|
||||
treeNode.setLastNode(true);
|
||||
}
|
||||
// 计算每一个节点的最子节点的数量
|
||||
List<TreeNode> children = parentTreeNode.getChildren();
|
||||
if (children.size() > 0) {
|
||||
int sum = 0;
|
||||
for (TreeNode treeNode2 : children) {
|
||||
sum += treeNode2.getLastNodeNum();
|
||||
}
|
||||
parentTreeNode.setLastNodeNum(sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据treeNodesMap转为treeNodesList
|
||||
*/
|
||||
private void initTreeNodeList() {
|
||||
if (treeNodesList.size() > 0) {
|
||||
return;
|
||||
}
|
||||
if (treeNodesMap.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Iterator<TreeNode> iterator = treeNodesMap.values().iterator();
|
||||
TreeNode treeNode;
|
||||
while (iterator.hasNext()) {
|
||||
treeNode = iterator.next();
|
||||
if (treeNode.getParent() == null) {
|
||||
this.treeNodesList.add(treeNode);
|
||||
this.treeNodesList.addAll(treeNode.getAllChildren());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TreeNode> getTree() {
|
||||
return this.treeNodesList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TreeNode> getRoot() {
|
||||
List<TreeNode> rootList = new ArrayList<>();
|
||||
if (this.treeNodesList.size() > 0) {
|
||||
for (TreeNode node : treeNodesList) {
|
||||
if (node.getParent() == null) {
|
||||
rootList.add(node);
|
||||
Collections.sort(rootList, new OrdNamComparator());
|
||||
}
|
||||
}
|
||||
}
|
||||
return rootList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeNode getTreeNode(String nodeId) {
|
||||
return this.treeNodesMap.get(nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义排序,按照orderNum排序
|
||||
*/
|
||||
class OrdNamComparator implements Comparator<TreeNode> {
|
||||
@Override
|
||||
public int compare(TreeNode t1, TreeNode t2) {
|
||||
if (t1.getOrderNum() > t2.getOrderNum()) {
|
||||
return 1;
|
||||
}
|
||||
if (t1.getOrderNum() < t2.getOrderNum()) {
|
||||
return -1;
|
||||
}
|
||||
return t1.getNodeName().compareTo(t2.getNodeName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package com.adc.da.utils.tree;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TreeNode {
|
||||
|
||||
/**
|
||||
* 树节点ID
|
||||
*/
|
||||
@JSONField(ordinal = 1)
|
||||
private String nodeId;
|
||||
/**
|
||||
* 树节点名称
|
||||
*/
|
||||
@JSONField(ordinal = 2)
|
||||
private String nodeName;
|
||||
/**
|
||||
* 父节点ID
|
||||
*/
|
||||
@JSONField(ordinal = 3)
|
||||
private String parentNodeId;
|
||||
/**
|
||||
* 节点在树中的排序号
|
||||
*/
|
||||
@JSONField(ordinal = 4)
|
||||
private int orderNum;
|
||||
/**
|
||||
* 节点所在的层级
|
||||
*/
|
||||
@JSONField(ordinal = 5)
|
||||
private int level;
|
||||
/**
|
||||
* 最子节点的数量
|
||||
*/
|
||||
@JSONField(ordinal = 6)
|
||||
private int lastNodeNum;
|
||||
|
||||
/**
|
||||
* 是否是最子节点
|
||||
*/
|
||||
@JSONField(ordinal = 7)
|
||||
private boolean lastNode;
|
||||
|
||||
/**
|
||||
* 当前节点的儿子节点
|
||||
*/
|
||||
@JSONField(ordinal = 8)
|
||||
private List<TreeNode> children = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 当前节点的完整路径
|
||||
*/
|
||||
@JSONField(ordinal = 9)
|
||||
private String completeName;
|
||||
|
||||
/**
|
||||
* 当前节点的父级节点
|
||||
* 转json的时候忽略此属性,因为此属性到前端无作用
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
private TreeNode parent;
|
||||
|
||||
/**
|
||||
* 当前节点的子孙节点
|
||||
* 转json的时候忽略此属性,因为此属性到前端无作用
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
private List<TreeNode> allChildren = new ArrayList<>();
|
||||
|
||||
public TreeNode(ITreeNode obj) {
|
||||
this.nodeId = obj.getNodeId();
|
||||
this.nodeName = obj.getNodeName();
|
||||
this.parentNodeId = obj.getNodeParentId();
|
||||
this.orderNum = obj.getOrderNum();
|
||||
this.level = obj.getNodeLevel();
|
||||
}
|
||||
|
||||
public TreeNode(TreeNode obj) {
|
||||
this.orderNum = obj.getOrderNum();
|
||||
this.level = obj.getLevel();
|
||||
this.lastNodeNum = obj.getLastNodeNum();
|
||||
}
|
||||
|
||||
public TreeNode() {
|
||||
}
|
||||
|
||||
public void addChild(TreeNode treeNode) {
|
||||
this.children.add(treeNode);
|
||||
}
|
||||
|
||||
public void removeChild(TreeNode treeNode) {
|
||||
this.children.remove(treeNode);
|
||||
}
|
||||
|
||||
public String getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
public void setNodeId(String nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
|
||||
public String getNodeName() {
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
public void setNodeName(String nodeName) {
|
||||
this.nodeName = nodeName;
|
||||
}
|
||||
|
||||
public String getParentNodeId() {
|
||||
return parentNodeId;
|
||||
}
|
||||
|
||||
public void setParentNodeId(String parentNodeId) {
|
||||
this.parentNodeId = parentNodeId;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public TreeNode getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(TreeNode parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public List<TreeNode> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<TreeNode> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public int getOrderNum() {
|
||||
return orderNum;
|
||||
}
|
||||
|
||||
public void setOrderNum(int orderNum) {
|
||||
this.orderNum = orderNum;
|
||||
}
|
||||
|
||||
public int getLastNodeNum() {
|
||||
return lastNodeNum;
|
||||
}
|
||||
|
||||
public void setLastNodeNum(int lastNodeNum) {
|
||||
this.lastNodeNum = lastNodeNum;
|
||||
}
|
||||
|
||||
public boolean isLastNode() {
|
||||
return lastNode;
|
||||
}
|
||||
|
||||
public void setLastNode(boolean lastNode) {
|
||||
this.lastNode = lastNode;
|
||||
}
|
||||
|
||||
public List<TreeNode> getAllChildren() {
|
||||
if (this.allChildren.isEmpty()) {
|
||||
for (TreeNode treeNode : this.children) {
|
||||
this.allChildren.add(treeNode);
|
||||
this.allChildren.addAll(treeNode.getAllChildren());
|
||||
}
|
||||
}
|
||||
return this.allChildren;
|
||||
}
|
||||
|
||||
public String getCompleteName() {
|
||||
return completeName;
|
||||
}
|
||||
|
||||
public void setCompleteName(String completeName) {
|
||||
this.completeName = completeName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.adc.da.utils.treetool;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* List 排序 Comparator
|
||||
* @author david
|
||||
*/
|
||||
public class OrdNamComparator implements Comparator<TreeNode> {
|
||||
|
||||
@Override
|
||||
public int compare(TreeNode t1, TreeNode t2) {
|
||||
if (t1.getOrderNum() > t2.getOrderNum()) {
|
||||
return 1;
|
||||
}
|
||||
if (t1.getOrderNum() < t2.getOrderNum()) {
|
||||
return -1;
|
||||
}
|
||||
return t1.getNodeName().compareTo(t2.getNodeName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package com.adc.da.utils.treetool;
|
||||
|
||||
import com.adc.da.utils.treetool.annotation.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
//import group.ipp.tree.util.annotation.TreeNodeLevel;
|
||||
//import group.ipp.tree.util.annotation.TreeNodeName;
|
||||
//import group.ipp.tree.util.annotation.TreeNodeOrder;
|
||||
//import group.ipp.tree.util.annotation.TreeNodeParentId;
|
||||
|
||||
/**
|
||||
* 构建树形建构
|
||||
*
|
||||
* @author David
|
||||
*/
|
||||
public class Tree<T> {
|
||||
/**
|
||||
* 用于存放treeNode的Map
|
||||
*/
|
||||
private LinkedHashMap<String, TreeNode> treeNodesMap = new LinkedHashMap<>();
|
||||
/**
|
||||
* 用于存放treeNode的list
|
||||
*/
|
||||
private List<TreeNode> treeNodesList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
public Tree(List<T> list) {
|
||||
initTreeNodeMap(list);
|
||||
initTreeNodeList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将List对象数据转为TreeNodeMap
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
private void initTreeNodeMap(List<T> list) {
|
||||
TreeNode treeNode;
|
||||
for (Object item : list) {
|
||||
treeNode = new TreeNode();
|
||||
treeNode.setNodeId(getFieldValue(item, "TreeNodeId"));
|
||||
treeNode.setNodeName(getFieldValue(item, "TreeNodeName"));
|
||||
treeNode.setParentNodeId(getFieldValue(item, "TreeNodeParentId"));
|
||||
if(StringUtils.isEmpty(getFieldValue(item, "TreeNodeLevel"))) {
|
||||
treeNode.setLevel(0);
|
||||
} else {
|
||||
treeNode.setLevel(Integer.parseInt(getFieldValue(item, "TreeNodeLevel")));
|
||||
}
|
||||
if(StringUtils.isEmpty(getFieldValue(item, "TreeNodeOrder"))) {
|
||||
treeNode.setOrderNum(0);
|
||||
} else {
|
||||
treeNode.setOrderNum(Integer.parseInt(getFieldValue(item, "TreeNodeOrder")));
|
||||
}
|
||||
treeNode.setLastNodeNum(1);
|
||||
treeNode.setData(item);
|
||||
treeNodesMap.put(treeNode.getNodeId(), treeNode);
|
||||
}
|
||||
Iterator<TreeNode> iterator = treeNodesMap.values().iterator();
|
||||
TreeNode parentTreeNode;
|
||||
while (iterator.hasNext()) {
|
||||
treeNode = iterator.next();
|
||||
if (StringUtils.isEmpty(treeNode.getParentNodeId())) {
|
||||
continue;
|
||||
}
|
||||
parentTreeNode = treeNodesMap.get(treeNode.getParentNodeId());
|
||||
if (parentTreeNode != null) {
|
||||
treeNode.setParent(parentTreeNode);
|
||||
parentTreeNode.addChild(treeNode);
|
||||
// 按照orderNum排序
|
||||
Collections.sort(parentTreeNode.getChildren(), new OrdNamComparator());
|
||||
// 判断这个节点是否是最子节点
|
||||
if (treeNode.getChildren().size() == 0) {
|
||||
treeNode.setLastNode(true);
|
||||
}
|
||||
// 计算每一个节点的最子节点的数量
|
||||
List<TreeNode> children = parentTreeNode.getChildren();
|
||||
if (children.size() > 0) {
|
||||
int sum = 0;
|
||||
for (TreeNode treeNode2 : children) {
|
||||
sum += treeNode2.getLastNodeNum();
|
||||
}
|
||||
parentTreeNode.setLastNodeNum(sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getFieldValue(Object obj, String type) {
|
||||
Class clz = obj.getClass();
|
||||
Field[] fields = clz.getDeclaredFields();
|
||||
String value = null;
|
||||
try {
|
||||
for(Field field : fields){
|
||||
field.setAccessible(true);
|
||||
switch (type){
|
||||
case "TreeNodeId":
|
||||
if(field.isAnnotationPresent(TreeNodeId.class)) {
|
||||
value = String.valueOf(field.get(obj));
|
||||
}
|
||||
break;
|
||||
case "TreeNodeParentId":
|
||||
if(field.isAnnotationPresent(TreeNodeParentId.class)) {
|
||||
value = String.valueOf(field.get(obj));
|
||||
}
|
||||
break;
|
||||
case "TreeNodeName":
|
||||
if(field.isAnnotationPresent(TreeNodeName.class)) {
|
||||
value = String.valueOf(field.get(obj));
|
||||
}
|
||||
break;
|
||||
case "TreeNodeOrder":
|
||||
if(field.isAnnotationPresent(TreeNodeOrder.class)) {
|
||||
value = String.valueOf(field.get(obj));
|
||||
}
|
||||
break;
|
||||
case "TreeNodeLevel":
|
||||
if(field.isAnnotationPresent(TreeNodeLevel.class)) {
|
||||
value = String.valueOf(field.get(obj));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据treeNodesMap转为treeNodesList
|
||||
*/
|
||||
private void initTreeNodeList() {
|
||||
if (treeNodesList.size() > 0) {
|
||||
return;
|
||||
}
|
||||
if (treeNodesMap.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Iterator<TreeNode> iterator = treeNodesMap.values().iterator();
|
||||
TreeNode treeNode;
|
||||
while (iterator.hasNext()) {
|
||||
treeNode = iterator.next();
|
||||
if (treeNode.getParent() == null) {
|
||||
this.treeNodesList.add(treeNode);
|
||||
this.treeNodesList.addAll(treeNode.getAllChildren());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<TreeNode> getTree() {
|
||||
return this.treeNodesList;
|
||||
}
|
||||
|
||||
public List<TreeNode> getRoot() {
|
||||
List<TreeNode> rootList = new ArrayList<>();
|
||||
if (this.treeNodesList.size() > 0) {
|
||||
for (TreeNode node : treeNodesList) {
|
||||
if (node.getParent() == null) {
|
||||
rootList.add(node);
|
||||
Collections.sort(rootList, new OrdNamComparator());
|
||||
}
|
||||
}
|
||||
}
|
||||
return rootList;
|
||||
}
|
||||
|
||||
public TreeNode getTreeNode(String nodeId) {
|
||||
return this.treeNodesMap.get(nodeId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
package com.adc.da.utils.treetool;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author David
|
||||
*/
|
||||
public class TreeNode {
|
||||
|
||||
/**
|
||||
* 树节点ID
|
||||
*/
|
||||
@JSONField(ordinal = 1)
|
||||
private String nodeId;
|
||||
/**
|
||||
* 树节点名称
|
||||
*/
|
||||
@JSONField(ordinal = 2)
|
||||
private String nodeName;
|
||||
/**
|
||||
* 父节点ID
|
||||
*/
|
||||
@JSONField(ordinal = 3)
|
||||
private String parentNodeId;
|
||||
/**
|
||||
* 节点在树中的排序号
|
||||
*/
|
||||
@JSONField(ordinal = 4)
|
||||
private int orderNum;
|
||||
/**
|
||||
* 节点所在的层级
|
||||
*/
|
||||
@JSONField(ordinal = 5)
|
||||
private int level;
|
||||
/**
|
||||
* 最子节点的数量
|
||||
*/
|
||||
@JSONField(ordinal = 6)
|
||||
private int lastNodeNum;
|
||||
|
||||
/**
|
||||
* 是否是最子节点
|
||||
*/
|
||||
@JSONField(ordinal = 7)
|
||||
private boolean lastNode;
|
||||
|
||||
private Object data;
|
||||
|
||||
/**
|
||||
* 当前节点的儿子节点
|
||||
*/
|
||||
@JSONField(ordinal = 8)
|
||||
private List<TreeNode> children = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 当前节点的完整路径
|
||||
*/
|
||||
@JSONField(ordinal = 9)
|
||||
private String completeName;
|
||||
|
||||
/**
|
||||
* 当前节点的父级节点
|
||||
* 转json的时候忽略此属性,因为此属性到前端无作用
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
private TreeNode parent;
|
||||
|
||||
/**
|
||||
* 当前节点的子孙节点
|
||||
* 转json的时候忽略此属性,因为此属性到前端无作用
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
private List<TreeNode> allChildren = new ArrayList<>();
|
||||
|
||||
private int standFlag;
|
||||
|
||||
public TreeNode(TreeNode obj) {
|
||||
this.orderNum = obj.getOrderNum();
|
||||
this.level = obj.getLevel();
|
||||
this.lastNodeNum = obj.getLastNodeNum();
|
||||
}
|
||||
|
||||
public TreeNode() {
|
||||
}
|
||||
|
||||
public void addChild(TreeNode treeNode) {
|
||||
this.children.add(treeNode);
|
||||
}
|
||||
|
||||
public void removeChild(TreeNode treeNode) {
|
||||
this.children.remove(treeNode);
|
||||
}
|
||||
|
||||
public String getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
public void setNodeId(String nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
|
||||
public String getNodeName() {
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
public void setNodeName(String nodeName) {
|
||||
this.nodeName = nodeName;
|
||||
}
|
||||
|
||||
public String getParentNodeId() {
|
||||
return parentNodeId;
|
||||
}
|
||||
|
||||
public void setParentNodeId(String parentNodeId) {
|
||||
this.parentNodeId = parentNodeId;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public TreeNode getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(TreeNode parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public List<TreeNode> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<TreeNode> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public int getOrderNum() {
|
||||
return orderNum;
|
||||
}
|
||||
|
||||
public void setOrderNum(int orderNum) {
|
||||
this.orderNum = orderNum;
|
||||
}
|
||||
|
||||
public int getLastNodeNum() {
|
||||
return lastNodeNum;
|
||||
}
|
||||
|
||||
public void setLastNodeNum(int lastNodeNum) {
|
||||
this.lastNodeNum = lastNodeNum;
|
||||
}
|
||||
|
||||
public boolean isLastNode() {
|
||||
return lastNode;
|
||||
}
|
||||
|
||||
public void setLastNode(boolean lastNode) {
|
||||
this.lastNode = lastNode;
|
||||
}
|
||||
|
||||
public List<TreeNode> getAllChildren() {
|
||||
if (this.allChildren.isEmpty()) {
|
||||
for (TreeNode treeNode : this.children) {
|
||||
this.allChildren.add(treeNode);
|
||||
this.allChildren.addAll(treeNode.getAllChildren());
|
||||
}
|
||||
}
|
||||
return this.allChildren;
|
||||
}
|
||||
|
||||
public String getCompleteName() {
|
||||
return completeName;
|
||||
}
|
||||
|
||||
public void setCompleteName(String completeName) {
|
||||
this.completeName = completeName;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int getStandFlag() {
|
||||
return standFlag;
|
||||
}
|
||||
|
||||
public void setStandFlag(int standFlag) {
|
||||
this.standFlag = standFlag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.adc.da.utils.treetool.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author david
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD})
|
||||
@Documented
|
||||
public @interface TreeNodeId {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.adc.da.utils.treetool.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author david
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD})
|
||||
@Documented
|
||||
public @interface TreeNodeLevel {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.adc.da.utils.treetool.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author david
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD})
|
||||
@Documented
|
||||
public @interface TreeNodeName {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.adc.da.utils.treetool.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author david
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD})
|
||||
@Documented
|
||||
public @interface TreeNodeOrder {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.adc.da.utils.treetool.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author david
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD})
|
||||
@Documented
|
||||
public @interface TreeNodeParentId {
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class AESUtil {
|
||||
private static final String KEY_ALGORITHM = "AES";
|
||||
private static final String DEFAULT_CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";//默认的加密算法
|
||||
|
||||
/**
|
||||
* AES 加密操作
|
||||
*
|
||||
* @param content 待加密内容
|
||||
* @param password 加密密码
|
||||
* @return 返回Base64转码后的加密数据
|
||||
*/
|
||||
public static String encrypt(String content, String password) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);// 创建密码器
|
||||
|
||||
byte[] byteContent = content.getBytes("utf-8");
|
||||
|
||||
cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(password));// 初始化为加密模式的密码器
|
||||
|
||||
byte[] result = cipher.doFinal(byteContent);// 加密
|
||||
|
||||
return Base64.encodeBase64String(result);//通过Base64转码返回
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* AES 解密操作
|
||||
*
|
||||
* @param content
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
public static String decrypt(String content, String password) {
|
||||
|
||||
try {
|
||||
//实例化
|
||||
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
|
||||
|
||||
//使用密钥初始化,设置为解密模式
|
||||
cipher.init(Cipher.DECRYPT_MODE, getSecretKey(password));
|
||||
|
||||
//执行操作
|
||||
byte[] result = cipher.doFinal(Base64.decodeBase64(content));
|
||||
|
||||
return new String(result, "utf-8");
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成加密秘钥
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static SecretKeySpec getSecretKey(final String password) {
|
||||
//返回生成指定算法密钥生成器的 KeyGenerator 对象
|
||||
KeyGenerator kg = null;
|
||||
|
||||
try {
|
||||
kg = KeyGenerator.getInstance(KEY_ALGORITHM);
|
||||
|
||||
//AES 要求密钥长度为 128
|
||||
kg.init(128, new SecureRandom(password.getBytes()));
|
||||
|
||||
//生成一个密钥
|
||||
SecretKey secretKey = kg.generateKey();
|
||||
|
||||
return new SecretKeySpec(secretKey.getEncoded(), KEY_ALGORITHM);// 转换为AES专用密钥
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = "hello,您好";
|
||||
|
||||
System.out.println("s:" + s);
|
||||
|
||||
String s1 = AESUtil.encrypt(s, "1234");
|
||||
System.out.println("s1:" + s1);
|
||||
|
||||
System.out.println("s2:"+AESUtil.decrypt(s1, "1234"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
public class CompLDUtils {
|
||||
|
||||
private static int min(int one, int two, int three) {
|
||||
int min = one;
|
||||
if (two < min) {
|
||||
min = two;
|
||||
}
|
||||
if (three < min) {
|
||||
min = three;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
public static int ld(String str1, String str2) {
|
||||
int d[][]; // 矩阵
|
||||
int n = str1.length();
|
||||
int m = str2.length();
|
||||
int i; // 遍历str1的
|
||||
int j; // 遍历str2的
|
||||
char ch1; // str1的
|
||||
char ch2; // str2的
|
||||
int temp; // 记录相同字符,在某个矩阵位置值的增量,不是0就是1
|
||||
if (n == 0) {
|
||||
return m;
|
||||
}
|
||||
if (m == 0) {
|
||||
return n;
|
||||
}
|
||||
d = new int[n + 1][m + 1];
|
||||
for (i = 0; i <= n; i++) { // 初始化第一列
|
||||
d[i][0] = i;
|
||||
}
|
||||
for (j = 0; j <= m; j++) { // 初始化第一行
|
||||
d[0][j] = j;
|
||||
}
|
||||
for (i = 1; i <= n; i++) { // 遍历str1
|
||||
ch1 = str1.charAt(i - 1);
|
||||
// 去匹配str2
|
||||
for (j = 1; j <= m; j++) {
|
||||
ch2 = str2.charAt(j - 1);
|
||||
if (ch1 == ch2) {
|
||||
temp = 0;
|
||||
} else {
|
||||
temp = 1;
|
||||
}
|
||||
// 左边+1,上边+1, 左上角+temp取最小
|
||||
d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1]+ temp);
|
||||
}
|
||||
}
|
||||
return d[n][m];
|
||||
}
|
||||
public static double sim(String str1, String str2) {
|
||||
try {
|
||||
double ld = (double)ld(str1, str2);
|
||||
return (1-ld/(double)Math.max(str1.length(), str2.length()));
|
||||
} catch (Exception e) {
|
||||
return 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String str1="6转向系\n" +
|
||||
"6.1汽车(三轮汽车除外)的方向盘应设置于左侧,其他机动车的方向盘不得设置于右侧;专项作业车、教练车按需要可设置左右两个方向盘。有驾驶室的正三轮摩托车如使用方向盘转向,则方向盘中心立柱距车辆纵向中心平面的水平距离应小于等于200 mm;其他摩托车不得使用方向盘转向。\n" +
|
||||
"6.2机动车的方向盘(或方向把)应转动灵活,操纵方便,无卡滞现象。机动车应设置转向限位装置。转向系统在任何操作位置上,不得与其他部件有干涉现象。\n" +
|
||||
"6.3机动车(摩托车、三轮汽车、手扶拖拉机运输机组除外)正常行驶时,转向轮转向后应有一定的回正能力(允许有残余角),以使机动车具有稳定的直线行驶能力。\n" +
|
||||
"6.4机动车方向盘的最大自由转动量应小于或等于:\n" +
|
||||
"a) 最大设计车速大于或等于100 km/h 的机动车:15°\n" +
|
||||
"b) 三轮汽车:35°;\n" +
|
||||
"c) 其他机动车:25° 。\n" +
|
||||
"6.5汽车(三轮汽车除外)应具有适度的不足转向特性。\n" +
|
||||
"6.6三轮汽车、摩托车的转向轮向左或向右转角应小于等于:\n" +
|
||||
"a)\t三轮汽车、三轮摩托车、正三轮轻便摩托车:45°;\n" +
|
||||
"6)\t\t两轮普通摩托车、两轮轻便摩托车:48°。\n" +
|
||||
"6.6机动车在平坦、硬实、干燥和清洁的道路上行驶不应跑偏,其方向盘(或方向把)不应有摆振、路感不灵或其他异常现象。\n" +
|
||||
"6.8机动车在平坦、硬实、干燥和清洁的水泥或沥青道路上行驶,以10 km/h的速度在5 s之内沿螺旋线从直线行驶过渡到外圆直径为25 m的车辆通道圆行驶,施加于方向盘外缘的最大切向力应小于等于245 N。\n" +
|
||||
"6.9专用校车应采用转向助力装置;其他机动车转向轴最大设计轴荷大于4 000 kg时,也应采用转向助力装置。装有转向助力装置的机动车,转向时其转向助力功能不得出现时有时无的现象,且转向助力装置失效时仍应具有用方向盘控制机动车的能力。装有电动转向助力装置的汽车,在产品使用说明书规定的正常使用状态下,应保证转向助力装置的电能供应。\n" +
|
||||
"6.10汽车和汽车列车(不计具有作业功能的专用装置的突出部分)、轮式拖拉机运输机组应能在同一个车辆通道圆内通过,车辆通道圆的外圆直径认为25.00 m,车辆通道圆的内圆直径D2为10.60 m。 汽车和汽车列车、轮式拖拉机运输机组由直线行驶过渡到上述圆周运动时,任何部分超出直线行驶时的 车辆外侧面垂直面的值(外摆值)应小于等于0.80 m(对铰接客车和铰接式无轨电车外摆值应小于等于 1.20 m),其试验方法见GB 1589。\n" +
|
||||
"6.11汽车(三轮汽车除外)的车轮定位应与该车型的技术要求一致。对前轴采用非独立悬架的汽车(前轴采用双转向轴时除外),其转向轮的横向侧滑量,用侧滑台检验时侧滑量值应在±5 m/km之间。\n" +
|
||||
"6.12转向节及臂,转向横、直拉杆及球销不得有裂纹和损伤,并且转向球销不应松旷。对机动车进行改装或修理时横、直拉杆不得拼焊。\n" +
|
||||
"6.13三轮汽车、摩托车的前减振器、上下联板和方向把不应有变形和裂损。\n";
|
||||
String str2="6转向系\n" +
|
||||
"6.1汽车(三轮汽车除外)的方向盘应设置于左侧,其他机动车的方向盘不应设置于右侧;专项作业车、教练车按需要可设置左右两个方向盘。装有两个后轮、有驾驶室的正三轮摩托车如使用方向盘转向,则方向盘中心立柱距车辆纵向中心平面的水平距离应小于或等于200 mm ;其他摩托车不应使用方向盘转向。\n" +
|
||||
"6.2机动车的方向盘(或方向把)应转动灵活,无卡滞现象。机动车应设置转向限位装置。转向系统在任何操作位置上,不应与其他部件有干涉现象。\n" +
|
||||
"6.3机动车(摩托车、三轮汽车、手扶拖拉机运输机组除外〉正常行驶时,转向轮转向后应有一定的回正能力(允许有残余角),以使机动车具有稳定的直线行驶能力0\n" +
|
||||
"6.4机动车方向盘的最大自由转动量应小于或等于:\n" +
|
||||
"a) 最大设计车速大于或等于100 km/h 的机动车:15°\n" +
|
||||
"b) 三轮汽车:35°;\n" +
|
||||
"c) 其他机动车:25° 。\n" +
|
||||
"6.5汽车(三轮汽车除外)应具有适度的不足转向特性。\n" +
|
||||
"6.6三轮汽车、摩托车的转向轮向左或向右转角应小于或等于:\n" +
|
||||
"a) 三轮汽车、三轮摩托车、正三轮轻便摩托车:45°;\n" +
|
||||
"b)两轮普通摩托车、两轮轻便摩托车:48°0\n" +
|
||||
"6.7机动车在平坦、硬实、干燥和清洁的道路上行驶不应跑偏,其方向盘(或方向把)不应有摆振等异常现象。\n" +
|
||||
"6.8机动车在平坦、硬实、干燥和清洁的水泥或沥青道路上行驶,以10 km/h 的速度在5 s 之内沿螺旋线从直线行驶过渡到外圆直径为25m 的车辆通道圆行驶,施加于方向盘外缘的最大切向力应小于或等于245 N。\n" +
|
||||
"6.9汽车(三轮汽车除外)的车轮定位应与该车型的技术要求一致。对前轴采用非独立悬架的汽车(前轴采用双转向轴时除外),其转向轮的横向侧滑量,用侧滑台检验时侧滑量值应小于或等于5 m/km。\n" +
|
||||
"6.10 专用校车应采用转向助力装置;其他机动车转向轴最大设计轴荷大于4 000 kg 时,也应采用转向助力装置。装有转向助力装置的机动车,转向时其转向助力功能不应出现时有时无的现象,且转向助力装置失效时仍应具有用方向盘控制机动车的能力。\n" +
|
||||
"6.11转向节及臂,转向横、直拉杆及球销应连接可靠,且不应有裂纹和损伤,并且转向球销不应松旷。对机动车进行改装或修理时横、直拉杆不应拼焊。\n" +
|
||||
"6.12三轮汽车、摩托车的前减振器、上下联板和方向把不应有变形和裂损。";
|
||||
String str3="\n" +
|
||||
"5车辆识别代号的标示位置\n" +
|
||||
"5.1每辆车辆都应具有唯一的车辆识别代号,并永久保持地标示在车辆上,同一车辆上标示的所有的 车辆识别代号的字码构成与排列顺序应相同。除第9章规定的情况外,不得对已标示的车辆识别代号 进行变更。\n" +
|
||||
"5.2车辆应在产品标牌上标示车辆识别代号(L1、L3类车辆可除外),产品标牌的型式、标示位置、标示要求应符合GB/T 18411的规定。\n" +
|
||||
"5.3车辆应至少有一个车辆识别代号直接打刻在车架(无车架的车辆为车身主要承载且不能拆卸的部件)能防止锈烛、磨损的部位上。其中:\n" +
|
||||
"a)\tM1类车辆的车辆识别代号应打刻在发动机舱内能防止替换的车辆结构件上,或打刻在车门 立柱上,如受结构限制没有打刻空间时也可打刻在右侧除行李舱外的车辆其他结构件上;\n" +
|
||||
"b)\t最大设计总质量大于或等于12000 kg的货车及所有牵引杆挂车,车辆识别代号应打刻在右前轮纵向中心线前端纵梁外侧,如受结构限制也可打刻在右前轮纵向中心线附近纵梁外侧;\n" +
|
||||
"c)\t半挂车和中置轴挂车的车辆识别代号应打刻在右前支腿前端纵梁外侧(无纵梁车辆除外);\n" +
|
||||
"d)\t其他汽车和无纵梁挂车的车辆识别代号应打刻在车辆右侧前部的车辆结构件上,如受结构限 制也可打刻在右侧其他车辆结构件上。\n" +
|
||||
"打刻车辆识别代号的部件不应采用打磨、挖补、垫片、凿改、重新涂漆(设计和制造上为保护打刻的 车辆识别代号而采取涂漆工艺的情形除外)等方式处理,从上(前)方观察时,打刻区域周边足够大面积 的表面不应有任何覆盖物,如有覆盖物,该覆盖物的表面应明确标示“车辆识别代号”或“VIN”字样,且覆盖物在不使用任何专用工具的情况下能直接取下(或揭开)及复原,以方便地观察到足够大的包括打刻区域的表面。\n" +
|
||||
"注1:打刻区域周边足够大面积的表面(足够大的包括打刻区域的表面)是指打刻车辆识别代号的部件的全部表面,但所暴露表面能满足查看打刻车辆识别代号的部件有无挖补、重新焊接、粘贴等痕迹的需要时,也应视为满足要求。\n" +
|
||||
"注2:对摩托车,打刻的车辆识别代号在不举升车辆的情形下可观察、拓印的,视为满足要求。\n" +
|
||||
"打刻的车辆识别代号从上(前)方应易于观察、拓印,对于汽车和挂车还应能拍照。\n" +
|
||||
"5.4具有电子控制单元的汽车,其至少有一个电子控制单元应不可篡改地存储车辆识别代号。\n" +
|
||||
"5.5 M1、N1类车辆应在靠近风窗立柱的位置标示车辆识别代号,该车辆识别代号在白天不需移动任何部件从车外即能清晰识读。\n" +
|
||||
"5.6除按照5.2、5.3、5.4、5.5规定标示车辆识别代号之外,类车辆还应在行李舱的易见部位标示车辆识别代号;且若车辆制造厂选取车辆识别代号作为车辆及部件识别标记的标识信息,还应按照GB 30509的规定,标示车辆识别代号。\n" +
|
||||
"5.7除按照5.2、5.3、5.4规定标示车辆识别代号之外,最大设计总质量大于或等于12000 kg的栏板式、仓栅式、自卸式、罐式货车及最大设计总质量大于或等于10000 kg的栏板式、仓栅式、自卸式、罐式挂车还应在其货箱或常压罐体(或设计和制造上固定在货箱或常压罐体上且用于与车架连接的结构件)上打刻至少两个车辆识别代号。打刻的车辆识别代号应位于货箱(常压罐体)左、右两侧或前端面且易于拍照;且若打刻在货箱(常压罐体)左、右两侧时,打刻的车辆识别代号距货箱(常压罐体)前端面的距离应小于或等于1 000 mm,若打刻在左、右两侧连接结构件时应尽量靠近货箱(常压罐体)前端面。\n" +
|
||||
"5.8车辆制造厂应至少在一种随车文件中标示车辆识别代号。";
|
||||
|
||||
String str4 = "\n" +
|
||||
"5.3车辆的驱动\n" +
|
||||
"5.3.1车辆不应靠自身动力驱动。\n" +
|
||||
"5.3.2在碰撞瞬间,车辆应不冉承受任何附加转向或驱动装置的作用。\n" +
|
||||
"5.3.3车辆到达壁障的路线在横向任一方向偏离理论轨迹均不应超过150 mm。\n" +
|
||||
"5.4 试验速度\n" +
|
||||
"在碰撞瞬间,车辆速度应为504 km/h。如果试验在更高的碰撞速度下进行并且车辆符合要求,也认为试验合格。\n" +
|
||||
"5.5对前排座椅假人的测量\n" +
|
||||
"5.5.1为确定性能指标必需的所有测量,均应采用符合附录D要求的测量系统。\n" +
|
||||
"5.5.2不同的参数应通过具备下列CFC(通道的频率等级)的独立数据通道来记录。\n" +
|
||||
"5.5.2.1对假人头部的测量\n" +
|
||||
"重心处的加速度(a)由加速度的二维分量计算得出。加速度分量测量时,CFC为1000。\n" +
|
||||
"5.5.2.2对假人颈部的测量\n" +
|
||||
"5.5.2.2.1在头颈连接处测量的轴向张力和前后剪切力,CFC为1000。\n" +
|
||||
"5.5.2.2.2在头颈连接处测量的对Y轴的弯矩,CFC为600。\n" +
|
||||
"5.5.2.3对假人胸部的测量\n" +
|
||||
"胸部变形测量时,CFC为180。\n" +
|
||||
"5.5.2.4对假人大腿的测量\n" +
|
||||
"轴向压缩力测量时,CFC为600。";
|
||||
|
||||
System.out.println("ld=" + ld(str1, str2));
|
||||
System.out.println("sim=" + sim(str1, str2));
|
||||
System.out.println("====================================================");
|
||||
System.out.println("ld=" + ld(str1, str3));
|
||||
System.out.println("sim=" + sim(str1, str3));
|
||||
|
||||
System.out.println("====================================================");
|
||||
System.out.println("ld=" + ld(str1, str4));
|
||||
System.out.println("sim=" + sim(str1, str4));
|
||||
|
||||
System.out.println("====================================================");
|
||||
System.out.println("ld=" + ld(str3, str4));
|
||||
System.out.println("sim=" + sim(str3, str4));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: super_liu
|
||||
* date: 2020/12/9 10:00
|
||||
*/
|
||||
public class CompareListUtil {
|
||||
/**
|
||||
* @param aList 本列表
|
||||
* @param bList 对照列表
|
||||
* @return 返回增加的元素组成的列表
|
||||
* @Description: 计算列表aList相对于bList的增加的情况,兼容任何类型元素的列表数据结构
|
||||
*/
|
||||
public static <E> List<E> getAddaListThanbList(List<E> aList, List<E> bList) {
|
||||
List<E> addList = new ArrayList<E>();
|
||||
for (int i = 0; i < aList.size(); i++) {
|
||||
if (!myListContains(bList, aList.get(i))) {
|
||||
addList.add(aList.get(i));
|
||||
}
|
||||
}
|
||||
return addList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param aList 本列表
|
||||
* @param bList 对照列表
|
||||
* @return 返回减少的元素组成的列表
|
||||
* @Description: 计算列表aList相对于bList的减少的情况,兼容任何类型元素的列表数据结构
|
||||
*/
|
||||
public static <E> List<E> getReduceaListThanbList(List<E> aList, List<E> bList) {
|
||||
List<E> reduceaList = new ArrayList<E>();
|
||||
for (int i = 0; i < bList.size(); i++) {
|
||||
if (!myListContains(aList, bList.get(i))) {
|
||||
reduceaList.add(bList.get(i));
|
||||
}
|
||||
}
|
||||
return reduceaList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param sourceList 源列表
|
||||
* @param element 待判断的包含元素
|
||||
* @return 包含返回 true,不包含返回 false
|
||||
* @Description: 判断元素element是否是sourceList列表中的一个子元素
|
||||
*/
|
||||
private static <E> boolean myListContains(List<E> sourceList, E element) {
|
||||
if (sourceList == null || element == null) {
|
||||
return false;
|
||||
}
|
||||
if (sourceList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (E tip : sourceList) {
|
||||
if (element.equals(tip)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list
|
||||
* @return list
|
||||
* @Description: 去除list重复数据
|
||||
*/
|
||||
public static <E> List<E> cleanDisRepet(List<E> list) {
|
||||
HashSet h = new HashSet(list);
|
||||
list.clear();
|
||||
list.addAll(h);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Description: 各种类型数据,拼接成逗号分隔字符串
|
||||
* @Author: super_liu
|
||||
* date: 2020/11/23 14:30
|
||||
*/
|
||||
public class ConcatStringUtil {
|
||||
|
||||
public static String concatSet (Set<String> setVal) {
|
||||
String resultStr = "";
|
||||
if (setVal != null && !setVal.isEmpty()) {
|
||||
for (String val : setVal) {
|
||||
if (StringUtils.isNotBlank(val) && !"null".equals(val)) {
|
||||
resultStr += val + ",";
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(resultStr)) {
|
||||
resultStr = resultStr.substring(0,resultStr.length()-1);
|
||||
}
|
||||
}
|
||||
return resultStr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* @Description: 判断是否为日期格式
|
||||
* @Author: super_liu
|
||||
* date: 2020/12/31 11:25
|
||||
*/
|
||||
public class DateUtil {
|
||||
|
||||
/***
|
||||
* @Description: 判断多个日期是否都符合日期格式
|
||||
* @Author: super_liu
|
||||
* @Date: 2020/12/31 11:31
|
||||
* @Param: [str]
|
||||
* @Return: boolean
|
||||
*/
|
||||
public static boolean isValidDate(String str) throws Exception{
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String[] strArr = str.split(",");
|
||||
for (String dateStr : strArr) {
|
||||
try {
|
||||
simpleDateFormat.setLenient(false);
|
||||
simpleDateFormat.parse(dateStr);
|
||||
} catch (Exception e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* utc 时间格式转换正常格式 2018-08-07T03:41:59Z
|
||||
* @param utcTime 时间
|
||||
* @return
|
||||
*/
|
||||
public static String formatStrUTCToDateStr(String utcTime) {
|
||||
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.SIMPLIFIED_CHINESE);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
TimeZone utcZone = TimeZone.getTimeZone("UTC");
|
||||
sf.setTimeZone(utcZone);
|
||||
Date date = null;
|
||||
String dateTime = "";
|
||||
try {
|
||||
date = sf.parse(utcTime);
|
||||
dateTime = sdf.format(date);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String utcTime = "2021-04-15T01:43:54.296Z";
|
||||
String time = formatStrUTCToDateStr("2021-04-15T01:43:54.296Z");
|
||||
System.out.println("utcTime 转换前:" + utcTime);
|
||||
System.out.println("utcTime 转换后 time :" + time);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,271 @@
|
||||
package com.adc.da.utils.util;/**
|
||||
* Created by Administrator on 2018/12/20 16:42
|
||||
*/
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author Administrator
|
||||
* @Description TODO
|
||||
* Date 2018/12/20 16:42
|
||||
* @Param
|
||||
* @return
|
||||
**/
|
||||
public class ExcelUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExcelUtil.class);
|
||||
|
||||
|
||||
private static String EDGE = "Edge";
|
||||
private static String CHROME = "Chrome";
|
||||
private static String FIREFOX = "Firefox";
|
||||
private static String USERAGENT = "USER-AGENT";
|
||||
private static String UTF8 = "UTF8";
|
||||
private static String ISO88591 = "ISO8859-1";
|
||||
|
||||
/**
|
||||
* @param filePath 需要读取的文件路径
|
||||
* @param column 指定需要获取的列数,例如第一列 1
|
||||
* @param startRow 指定从第几行开始读取数据
|
||||
* @param endRow 指定结束行
|
||||
* @return 返回读取列数据的set
|
||||
*/
|
||||
public static List<String> getColumnSet(String fileOrginName, MultipartFile file, int column, int startRow, int endRow) throws IOException {
|
||||
Workbook wb = readExcel(fileOrginName, file.getInputStream()); //文件
|
||||
Sheet sheet = wb.getSheetAt(0); //sheet
|
||||
int rownum = sheet.getPhysicalNumberOfRows(); //行数
|
||||
Row row = null;
|
||||
List<String> result = new ArrayList<>();
|
||||
String cellData = null;
|
||||
if (wb != null) {
|
||||
for (int i = startRow - 1; i <= endRow; i++) {
|
||||
System.out.println(i);
|
||||
row = sheet.getRow(i);
|
||||
if (row != null) {
|
||||
if (row.getCell(column - 1) != null) {//单元格为空,不进入
|
||||
row.getCell(column - 1).setCellType(CellType.STRING);//设置单元格类型
|
||||
cellData = row.getCell(column - 1).getStringCellValue();
|
||||
result.add(cellData);
|
||||
} else {
|
||||
result.add("");
|
||||
}
|
||||
} else {
|
||||
|
||||
break;
|
||||
}
|
||||
System.out.println(cellData);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param column 指定需要获取的列数,例如第一列 1
|
||||
* @param startRow 指定从第几行开始读取数据
|
||||
* @return 返回读取列数据的set
|
||||
*/
|
||||
public static List<String> getColumnSet(String fileOrginName, MultipartFile file, int column, int startRow) throws IOException {
|
||||
Workbook wb = readExcel(fileOrginName, file.getInputStream()); //文件
|
||||
Sheet sheet = wb.getSheetAt(0); //sheet
|
||||
int rownum = sheet.getPhysicalNumberOfRows(); //行数
|
||||
System.out.println("sumrows " + rownum);
|
||||
|
||||
return getColumnSet(fileOrginName, file, column, startRow, rownum - 1);
|
||||
}
|
||||
|
||||
|
||||
//读取excel
|
||||
public static Workbook readExcel(String fileOrginName, InputStream is) {
|
||||
Workbook wb = null;
|
||||
String extString = fileOrginName.substring(fileOrginName.lastIndexOf("."));
|
||||
try {
|
||||
if (".xls".equals(extString)) {
|
||||
return wb = new HSSFWorkbook(is);
|
||||
} else if (".xlsx".equals(extString)) {
|
||||
return wb = new XSSFWorkbook(is);
|
||||
} else {
|
||||
return wb = null;
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error("异常:", e);
|
||||
} catch (IOException e) {
|
||||
logger.error("异常:", e);
|
||||
}
|
||||
return wb;
|
||||
}
|
||||
|
||||
/*public static Object getCellFormatValue(Cell cell){
|
||||
Object cellValue = null;
|
||||
if(cell!=null){
|
||||
//判断cell类型
|
||||
switch(cell.getCellType()){
|
||||
case NUMERIC:{
|
||||
cell.setCellType(CellType.STRING); //将数值型cell设置为string型
|
||||
cellValue = cell.getStringCellValue();
|
||||
break;
|
||||
}
|
||||
case FORMULA:{
|
||||
//判断cell是否为日期格式
|
||||
if(DateUtil.isCellDateFormatted(cell)){
|
||||
//转换为日期格式YYYY-mm-dd
|
||||
cellValue = cell.getDateCellValue();
|
||||
}else{
|
||||
//数字
|
||||
cellValue = String.valueOf(cell.getNumericCellValue());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case STRING:{
|
||||
cellValue = cell.getRichStringCellValue().getString();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
cellValue = "";
|
||||
}
|
||||
}else{
|
||||
cellValue = "";
|
||||
}
|
||||
return cellValue;
|
||||
}*/
|
||||
|
||||
public static String validatePattern(String fileName) {
|
||||
if (StringUtils.isNotEmpty(fileName)) {
|
||||
Boolean isOk = false;
|
||||
if (fileName.lastIndexOf(".docx") != -1) {
|
||||
isOk = true;
|
||||
}
|
||||
if (fileName.lastIndexOf(".pdf") != -1) {
|
||||
isOk = true;
|
||||
}
|
||||
if (fileName.lastIndexOf(".doc") != -1) {
|
||||
isOk = true;
|
||||
}
|
||||
if (fileName.lastIndexOf(".PDF") != -1) {
|
||||
isOk = true;
|
||||
}
|
||||
if(fileName.lastIndexOf(".ppt") != -1){
|
||||
isOk = true;
|
||||
}
|
||||
if(fileName.lastIndexOf(".pptx") != -1){
|
||||
isOk = true;
|
||||
}
|
||||
if(fileName.lastIndexOf(".xls") != -1){
|
||||
isOk = true;
|
||||
}
|
||||
if(fileName.lastIndexOf(".xlsx") != -1){
|
||||
isOk = true;
|
||||
}
|
||||
if(fileName.lastIndexOf(".jpg") != -1){
|
||||
isOk = true;
|
||||
}
|
||||
if(fileName.lastIndexOf(".JPG") != -1){
|
||||
isOk = true;
|
||||
}
|
||||
if(fileName.lastIndexOf(".png") != -1){
|
||||
isOk = true;
|
||||
}
|
||||
if(fileName.lastIndexOf(".PNG") != -1){
|
||||
isOk = true;
|
||||
}
|
||||
if(fileName.lastIndexOf(".PPT") != -1){
|
||||
isOk = true;
|
||||
}
|
||||
if(fileName.lastIndexOf(".PPTX") != -1){
|
||||
isOk = true;
|
||||
}
|
||||
if (isOk) {
|
||||
//其格式满足条件,无需提示
|
||||
return null;
|
||||
} else {
|
||||
return "请上传PDF、pdf、doc、docx、ppt、pptx、xls、xlsx、jpg、JPG、png、PNG、PPT、PPTX文件;";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断对象中属性值是否全为空
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkObjAllFieldsIsNull(Object object) {
|
||||
if (null == object) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
for (Field f : object.getClass().getDeclaredFields()) {
|
||||
f.setAccessible(true);
|
||||
|
||||
if (f.get(object) != null && StringUtils.isNotBlank(f.get(object).toString())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static String isUserAgent(String fileName, HttpServletRequest request) throws UnsupportedEncodingException {
|
||||
String userAgent = request.getHeader(USERAGENT);
|
||||
if (userAgent.contains(EDGE)) {
|
||||
//其他浏览器
|
||||
fileName = URLEncoder.encode(fileName, UTF8);
|
||||
//google,火狐浏览器
|
||||
} else if (userAgent.contains(CHROME) || userAgent.contains(FIREFOX)) {
|
||||
fileName = new String((fileName).getBytes(UTF8), ISO88591);
|
||||
} else {
|
||||
//其他浏览器
|
||||
fileName = URLEncoder.encode(fileName, UTF8);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public static boolean checkHeader(Sheet sheet, String names) throws IOException {
|
||||
Row row = sheet.getRow(0);
|
||||
List<String> modelNamesList = new ArrayList<>();
|
||||
for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) {
|
||||
if (org.apache.commons.lang.StringUtils.isNotBlank(row.getCell(i).getStringCellValue())) {
|
||||
modelNamesList.add(row.getCell(i).getStringCellValue());
|
||||
}
|
||||
}
|
||||
if (org.apache.commons.lang.StringUtils.join(modelNamesList, ',').equals(names)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getCellString(Cell cell) {
|
||||
if (cell == null){
|
||||
return "";
|
||||
}
|
||||
if (String.valueOf(cell).endsWith(".0")) {
|
||||
return StringUtils.removeEnd(String.valueOf(cell.getNumericCellValue()), ".0");
|
||||
}
|
||||
if (String.valueOf(cell).contains(".")) {
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
return String.valueOf(cell.getNumericCellValue());
|
||||
}
|
||||
return cell.getStringCellValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import com.adc.da.common.ReadExcel;
|
||||
import com.adc.da.exception.AdcDaBaseException;
|
||||
import com.adc.da.util.UUIDUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: super_liu
|
||||
* date: 2021/3/4 13:32
|
||||
*/
|
||||
public class ExportTempUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExportTempUtil.class);
|
||||
|
||||
public static void exportZipTemp (String filePath, String exportName, String header, HttpServletResponse response, HttpServletRequest request) {
|
||||
OutputStream os = null;
|
||||
OutputStream excelOS = null;
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
try{
|
||||
//创建临时文件夹
|
||||
String fileNowPath = filePath + "/tempZip/" + UUIDUtils.randomUUID20() + "/" + exportName;
|
||||
File nowFile = new File(fileNowPath);
|
||||
if (nowFile.exists()){
|
||||
nowFile.delete();
|
||||
}
|
||||
nowFile.mkdirs();
|
||||
String fileName = "导入模板.xls";
|
||||
HSSFSheet sheetItems = workbook.createSheet("模板");
|
||||
sheetItems.setDefaultColumnWidth(16);
|
||||
HSSFCellStyle cellStyle =workbook.createCellStyle();
|
||||
cellStyle.setWrapText(true);
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
Row rowHeader = sheetItems.createRow(0);//开始创建标题行
|
||||
if (StringUtils.isNotBlank(header)) {
|
||||
String[] headerArr = header.split(",");
|
||||
for (int i=0;i < headerArr.length; i++) {
|
||||
rowHeader.createCell(i).setCellValue(headerArr[i]);
|
||||
}
|
||||
}
|
||||
String repFileName = fileName.replaceAll("/","_");
|
||||
excelOS = new FileOutputStream(fileNowPath + "/" + repFileName);
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment; filename=\""+ ReadExcel.encodeFileName(exportName+".zip", request) +"\"");
|
||||
response.setContentType("application/force-download");
|
||||
response.flushBuffer();
|
||||
os = response.getOutputStream();
|
||||
workbook.write(excelOS);
|
||||
excelOS.flush();
|
||||
excelOS.close();
|
||||
ZipUtil.zip(fileNowPath,fileNowPath+".zip");
|
||||
FileInputStream fis = new FileInputStream(fileNowPath+".zip");
|
||||
int len = 0;
|
||||
while ((len = fis.read()) != -1) {
|
||||
os.write(len);
|
||||
}
|
||||
os.flush();
|
||||
os.close(); // 后开先关
|
||||
fis.close(); // 先开后关
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
throw new AdcDaBaseException("下载文件失败,请重试");
|
||||
} finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
IOUtils.closeQuietly(excelOS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import com.adc.da.util.LoginUserUtil;
|
||||
import com.adc.da.util.UUIDUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.sql.Clob;
|
||||
import java.sql.SQLException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 处理各类型字段
|
||||
* @Author: super_liu
|
||||
* date: 2021/6/1 9:37
|
||||
*/
|
||||
public class FieldConvertUtil {
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
|
||||
public static String mustFields = "id,stand_id,valid_flag,creation_user,creation_time,modify_time"; // 自定义属性表中必须字段
|
||||
|
||||
public static String mustFieldsLaws = "id,laws_id,valid_flag,creation_user,creation_time,modify_time"; // 自定义属性表中必须字段
|
||||
|
||||
public static String exportBaseFieldNames = "适用区域,重要度,标准类别,标准编号,标准年份,中文名称,英文名称," +
|
||||
"标准状态,发布日期,文本说明"; // 导出基础表字段 //删除 实施日期 2021-05-28
|
||||
|
||||
public static String exportBaseFieldNamesForeign = "重要度,标准类别,标准编号,标准年份/系列,中文名称,英文名称," +
|
||||
"标准状态,发布日期,文本说明"; // 导出基础表字段
|
||||
|
||||
public static String exportAttrFieldNamesInland = "归口管理部门,发布机构,工作组信息,我司参与深度,适用车辆类型,要求类型," +
|
||||
"标签,发布稿(必读),增补件(必读),报批稿,送审稿,征求意见稿,草案,相关资料,新车型实施日期(文本),在产车实施日期(文本)," +
|
||||
"EOP实施日期(文本),责任部门,相关部门,SVPPS,FO,项目评估角色,法规维护人,代替标准编号," +
|
||||
"对应其他标准,文字描述,引用标准,被引用标准,覆盖关系";
|
||||
|
||||
public static String exportAttrFieldNamesForeign = "适用车辆类型,要求类型," +
|
||||
"标签,发布稿(必读),增补件(必读),报批稿,送审稿,征求意见稿,草案,相关资料,新车型实施日期(文本),在产车实施日期(文本)," +
|
||||
"EOP实施日期(文本),责任部门,相关部门,SVPPS,FO,项目评估角色,法规维护人,代替标准编号," +
|
||||
"对应其他标准,文字描述,等效标准,引用标准,被引用标准,覆盖关系";
|
||||
|
||||
public static String exportBaseFieldNamesLaws = "政策编号,中文名称,英文名称," +
|
||||
"政策状态,适用区域,重要度,代替政策编号,发布日期";
|
||||
|
||||
public static String exportAttrFieldNamesLaws = "适用车辆类型,要求类型," +
|
||||
"个性化标签,政策文本,过程稿件,新车型实施日期(文本),在产车实施日期(文本),EOP实施日期(文本),SVPPS," +
|
||||
"相关部门,责任部门,FO,维护工程师,归口管理部门,发布机构,我司是否参与,相关资料";
|
||||
|
||||
public static String exportBaseFieldNamesBuss = "企标编号,中文名称,英文名称,标准状态,发布日期,标准实施日期," +
|
||||
"代替企标编号,被代替企标编号";
|
||||
|
||||
public static String exportAttrFieldNamesBuss = "SVPPS,规范性引用文件,废止日期,复审日期,密级,授权,相关部门," +
|
||||
"需会签部门,起草部门,主要起草人,起草分标委,企标文本,过程文本";
|
||||
|
||||
public static String exportBaseFieldNamesBussRecords = "标准编号,标准名称,发布日期,实施日期,标准状态,项目名称," +
|
||||
"代替标准编号,公开状态,产品类型,能源类型,企标备案文件,发布版文件,其他备案文件";
|
||||
|
||||
public static String exportBaseFieldNamesSarSarAccess = "标准号,中文名称,英文名称,新车型实施日期(项目)," +
|
||||
"在产车实施日期(项目),EOP实施日期(项目),实施说明,认证交付物,认证对象,监管类型,适用车辆类型,责任部门,相关部门,FO,项目评估角色," +
|
||||
"文本说明,标签,要求类型,清单类型,入库模块";
|
||||
|
||||
/***
|
||||
* @Description: Clob类型 转String
|
||||
* @Author: super_liu
|
||||
* @Date: 2021/6/1 13:49
|
||||
* @Param: [clob]
|
||||
* @Return: java.lang.String
|
||||
*/
|
||||
public static String ClobToString(Clob clob) throws SQLException, IOException {
|
||||
String ret = "";
|
||||
Reader read= clob.getCharacterStream();
|
||||
BufferedReader br = new BufferedReader(read);
|
||||
String s = br.readLine();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (s != null) {
|
||||
sb.append(s);
|
||||
s = br.readLine();
|
||||
}
|
||||
ret = sb.toString();
|
||||
if(br != null){
|
||||
br.close();
|
||||
}
|
||||
if(read != null){
|
||||
read.close();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/***
|
||||
* @Description: 向数据库存储时,处理时间类型数据
|
||||
* @Author: super_liu
|
||||
* @Date: 2021/6/1 13:51
|
||||
* @Param: [time]
|
||||
* @Return: java.lang.String
|
||||
*/
|
||||
public static String changeTimeValue (String timeStr) {
|
||||
if (StringUtils.isNotBlank(timeStr)) {
|
||||
timeStr = "str_to_date('" + timeStr + "','%Y-%m-%d %H:%i:%s')";
|
||||
} else {
|
||||
timeStr = "null";
|
||||
}
|
||||
return timeStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库中的时间格式转换成字符串格式
|
||||
* @param time
|
||||
* @param strFormat
|
||||
* @return
|
||||
*/
|
||||
public static String dateToStr(java.sql.Timestamp time, String strFormat) {
|
||||
DateFormat df = new SimpleDateFormat(strFormat);
|
||||
String str = "";
|
||||
if (time != null) {
|
||||
str = df.format(time);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/***
|
||||
* @Description: 自定义属性表中必须字段值
|
||||
* @Author: super_liu
|
||||
* @Date: 2021/6/1 14:14
|
||||
* @Param: [id]
|
||||
* @Return: java.lang.String
|
||||
*/
|
||||
public static String mustValues (String id) {
|
||||
String mustValue = "'"+ UUIDUtils.randomUUID20() + "','" + id + "','0','"
|
||||
+ LoginUserUtil.getUserId() + "'";
|
||||
Date date = new Date();
|
||||
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String nowTime = sf.format(date);
|
||||
String timeValue = "," + changeTimeValue(nowTime);
|
||||
mustValue += timeValue + timeValue;
|
||||
return mustValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import com.adc.da.common.SarTypeEnum;
|
||||
import com.adc.da.common.StandAttrTypeEnum;
|
||||
import com.adc.da.slrs.sarStandAttrDetails.entity.SarStandAttrDetails;
|
||||
import com.adc.da.slrs.sarStandAttrDetails.page.SarStandAttrDetailsEOPage;
|
||||
import com.adc.da.slrs.sarStandAttrDetails.service.ISarStandAttrDetailsService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 启动项目时加载标准属性信息
|
||||
* @Author: super_liu
|
||||
* date: 2020/9/7 10:54
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class InitStandAttrUtil implements ApplicationRunner {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(InitStandAttrUtil.class);
|
||||
|
||||
@Autowired
|
||||
private ISarStandAttrDetailsService sarStandAttrDetailsEOService;
|
||||
|
||||
private final static List<String> standTypeList = new ArrayList<>();
|
||||
private final static List<String> lawsTypeList = new ArrayList<>();
|
||||
public final static List<String> standStateList = new ArrayList<>();
|
||||
static {
|
||||
standTypeList.add(SarTypeEnum.STAND.getValue());
|
||||
standTypeList.add(SarTypeEnum.INLAND_STAND.getValue());
|
||||
standTypeList.add(SarTypeEnum.FOREIGN_STAND.getValue());
|
||||
lawsTypeList.add(SarTypeEnum.LAWS.getValue());
|
||||
lawsTypeList.add(SarTypeEnum.INLAND_LAWS.getValue());
|
||||
lawsTypeList.add(SarTypeEnum.FOREIGN_LAWS.getValue());
|
||||
standStateList.add("DRAFT");
|
||||
standStateList.add("ADVICE");
|
||||
standStateList.add("RADYSUBMIT");
|
||||
standStateList.add("SUBMIT");
|
||||
standStateList.add("FJNVYX9Q7J");
|
||||
standStateList.add("ZTJJSS");
|
||||
standStateList.add("TOVOID");
|
||||
standStateList.add("ZTXXYX");
|
||||
standStateList.add("5E5Z3CELX6");
|
||||
standStateList.add("N5KLTFLNRC");
|
||||
}
|
||||
|
||||
// 标准属性字段信息
|
||||
public static String queryField = ""; //所有属性表需要查询的字段以逗号分隔
|
||||
public static String queryFieldNames = ""; //所有属性表需要查询的字段名以逗号分隔
|
||||
public static List<String> queryFieldList = new ArrayList<>(); //所有属性表需要查询的字段
|
||||
public static List<String> selectionFieldList = new ArrayList<>(); // 属性表下拉选项类型字段
|
||||
public static List<String> fileFieldList = new ArrayList<>(); // 属性表文件类型字段
|
||||
public static List<String> clobFieldList = new ArrayList<>(); // 属性表clob类型字段
|
||||
public static List<String> timeFieldList = new ArrayList<>(); // 属性表日期类型字段
|
||||
public static List<String> multiTimeFieldList = new ArrayList<>(); // 属性表多个日期类型字段
|
||||
public static List<String> numFieldList = new ArrayList<>(); // 属性表数字类型字段
|
||||
public static List<SarStandAttrDetails> standInlandAttrFieldList = new ArrayList<>(); // 全部国内标准字段属性
|
||||
public static List<SarStandAttrDetails> standForeignAttrFieldList = new ArrayList<>(); // 全部海外标准字段属性
|
||||
public static Map<String,String> selectFieldMap = new HashMap<>(); // 下拉属性字段及选项值
|
||||
|
||||
// 政策属性字段信息
|
||||
public static String queryFieldLaws = ""; //所有属性表需要查询的字段以逗号分隔
|
||||
public static String queryFieldNamesLaws = ""; //所有属性表需要查询的字段名以逗号分隔
|
||||
public static List<String> queryFieldListLaws = new ArrayList<>(); //所有属性表需要查询的字段
|
||||
public static List<String> selectionFieldListLaws = new ArrayList<>(); // 属性表下拉选项类型字段
|
||||
public static List<String> fileFieldListLaws = new ArrayList<>(); // 属性表文件类型字段
|
||||
public static List<String> clobFieldListLaws = new ArrayList<>(); // 属性表clob类型字段
|
||||
public static List<String> timeFieldListLaws = new ArrayList<>(); // 属性表日期类型字段
|
||||
public static List<String> multiTimeFieldListLaws = new ArrayList<>(); // 属性表多个日期类型字段
|
||||
public static List<String> numFieldListLaws = new ArrayList<>(); // 属性表数字类型字段
|
||||
public static List<SarStandAttrDetails> lawsInlandAttrFieldList = new ArrayList<>(); // 属性表数字类型字段
|
||||
public static List<SarStandAttrDetails> lawsForeignAttrFieldList = new ArrayList<>(); // 全部政策字段属性
|
||||
public static Map<String,String> selectFieldMapLaws = new HashMap<>(); // 下拉属性字段及选项值
|
||||
|
||||
// 企标属性字段信息
|
||||
public static String queryFieldBuss = ""; //所有属性表需要查询的字段以逗号分隔
|
||||
public static String queryFieldNamesBuss = ""; //所有属性表需要查询的字段名以逗号分隔
|
||||
public static List<String> queryFieldListBuss = new ArrayList<>(); //所有属性表需要查询的字段
|
||||
public static List<String> selectionFieldListBuss = new ArrayList<>(); // 属性表下拉选项类型字段
|
||||
public static List<String> fileFieldListBuss = new ArrayList<>(); // 属性表文件类型字段
|
||||
public static List<String> clobFieldListBuss = new ArrayList<>(); // 属性表clob类型字段
|
||||
public static List<String> timeFieldListBuss = new ArrayList<>(); // 属性表日期类型字段
|
||||
public static List<String> multiTimeFieldListBuss = new ArrayList<>(); // 属性表多个日期类型字段
|
||||
public static List<String> numFieldListBuss = new ArrayList<>(); // 属性表数字类型字段
|
||||
public static List<SarStandAttrDetails> bussAttrFieldList = new ArrayList<>(); // 全部企标字段属性
|
||||
public static Map<String,String> selectFieldMapBuss = new HashMap<>(); // 下拉属性字段及选项值
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
logger.info("项目启动时加载--查询标准属性类!");
|
||||
// 属性表需要查询的字段
|
||||
StringBuilder fieldInfoBuilder = new StringBuilder();
|
||||
StringBuilder fieldInfoBuilderLaws = new StringBuilder();
|
||||
StringBuilder fieldInfoBuilderBuss = new StringBuilder();
|
||||
StringBuilder fieldInfoNameBuilder = new StringBuilder();
|
||||
StringBuilder fieldInfoNameBuilderLaws = new StringBuilder();
|
||||
StringBuilder fieldInfoNameBuilderBuss = new StringBuilder();
|
||||
QueryWrapper qw = new QueryWrapper();
|
||||
List<SarStandAttrDetails> getDetailsList = sarStandAttrDetailsEOService.list(qw);
|
||||
if (getDetailsList != null && !getDetailsList.isEmpty()) {
|
||||
logger.info("项目启动时加载--查询标准属性类--查询到" + getDetailsList.size() + "条属性字段数据!");
|
||||
for (SarStandAttrDetails detailsEO : getDetailsList) {
|
||||
String sarType = detailsEO.getSarType();
|
||||
String attrType = detailsEO.getAttrType();
|
||||
if (standTypeList.contains(sarType)) {
|
||||
if (!SarTypeEnum.FOREIGN_STAND.getValue().equals(sarType)) {
|
||||
standInlandAttrFieldList.add(detailsEO);
|
||||
}
|
||||
if (!SarTypeEnum.INLAND_STAND.getValue().equals(sarType)) {
|
||||
standForeignAttrFieldList.add(detailsEO);
|
||||
}
|
||||
fieldInfoBuilder.append(detailsEO.getAttrField() + ",");
|
||||
fieldInfoNameBuilder.append(detailsEO.getAttrName() + ",");
|
||||
queryFieldList.add(detailsEO.getAttrField());
|
||||
if (StandAttrTypeEnum.SELECT_OPTION.getValue().equals(attrType) || StandAttrTypeEnum.SEL_OPTS.getValue().equals(attrType)) {
|
||||
selectionFieldList.add(detailsEO.getAttrField());
|
||||
selectFieldMap.put(detailsEO.getAttrField(),detailsEO.getSelVal());
|
||||
} else if (StandAttrTypeEnum.FILE.getValue().equals(attrType)) {
|
||||
fileFieldList.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.TEXTAREA.getValue().equals(attrType) && detailsEO.getAttrLen() >= 4000) {
|
||||
clobFieldList.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.DATE_PICKER.getValue().equals(attrType)) {
|
||||
timeFieldList.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.DATE_PIC_OPTS.getValue().equals(attrType)) {
|
||||
multiTimeFieldList.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.INPUT_NUM.getValue().equals(attrType)) {
|
||||
numFieldList.add(detailsEO.getAttrField());
|
||||
}
|
||||
} else if (lawsTypeList.contains(sarType)) {
|
||||
if (!SarTypeEnum.FOREIGN_LAWS.getValue().equals(sarType)) {
|
||||
lawsInlandAttrFieldList.add(detailsEO);
|
||||
}
|
||||
if (!SarTypeEnum.INLAND_LAWS.getValue().equals(sarType)) {
|
||||
lawsForeignAttrFieldList.add(detailsEO);
|
||||
}
|
||||
fieldInfoBuilderLaws.append(detailsEO.getAttrField() + ",");
|
||||
fieldInfoNameBuilderLaws.append(detailsEO.getAttrName() + ",");
|
||||
queryFieldListLaws.add(detailsEO.getAttrField());
|
||||
if (StandAttrTypeEnum.SELECT_OPTION.getValue().equals(attrType) || StandAttrTypeEnum.SEL_OPTS.getValue().equals(attrType)) {
|
||||
selectionFieldListLaws.add(detailsEO.getAttrField());
|
||||
selectFieldMapLaws.put(detailsEO.getAttrField(),detailsEO.getSelVal());
|
||||
} else if (StandAttrTypeEnum.FILE.getValue().equals(attrType)) {
|
||||
fileFieldListLaws.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.TEXTAREA.getValue().equals(attrType) && detailsEO.getAttrLen() >= 4000) {
|
||||
clobFieldListLaws.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.DATE_PICKER.getValue().equals(attrType)) {
|
||||
timeFieldListLaws.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.DATE_PIC_OPTS.getValue().equals(attrType)) {
|
||||
multiTimeFieldListLaws.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.INPUT_NUM.getValue().equals(attrType)) {
|
||||
numFieldListLaws.add(detailsEO.getAttrField());
|
||||
}
|
||||
} else if (SarTypeEnum.BUSS.getValue().equals(sarType)) {
|
||||
bussAttrFieldList.add(detailsEO);
|
||||
fieldInfoBuilderBuss.append(detailsEO.getAttrField() + ",");
|
||||
fieldInfoNameBuilderBuss.append(detailsEO.getAttrName() + ",");
|
||||
queryFieldListBuss.add(detailsEO.getAttrField());
|
||||
if (StandAttrTypeEnum.SELECT_OPTION.getValue().equals(attrType) || StandAttrTypeEnum.SEL_OPTS.getValue().equals(attrType)) {
|
||||
selectionFieldListBuss.add(detailsEO.getAttrField());
|
||||
selectFieldMapBuss.put(detailsEO.getAttrField(),detailsEO.getSelVal());
|
||||
} else if (StandAttrTypeEnum.FILE.getValue().equals(attrType)) {
|
||||
fileFieldListBuss.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.TEXTAREA.getValue().equals(attrType) && detailsEO.getAttrLen() >= 4000) {
|
||||
clobFieldListBuss.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.DATE_PICKER.getValue().equals(attrType)) {
|
||||
timeFieldListBuss.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.DATE_PIC_OPTS.getValue().equals(attrType)) {
|
||||
multiTimeFieldListBuss.add(detailsEO.getAttrField());
|
||||
} else if (StandAttrTypeEnum.INPUT_NUM.getValue().equals(attrType)) {
|
||||
numFieldListBuss.add(detailsEO.getAttrField());
|
||||
}
|
||||
}
|
||||
}
|
||||
queryField = fieldInfoBuilder.toString();
|
||||
queryFieldLaws = fieldInfoBuilderLaws.toString();
|
||||
queryFieldBuss = fieldInfoBuilderBuss.toString();
|
||||
if (StringUtils.isNotBlank(queryField)) {
|
||||
queryField = queryField.substring(0,queryField.length()-1);
|
||||
}
|
||||
if (StringUtils.isNotBlank(queryFieldLaws)) {
|
||||
queryFieldLaws = queryFieldLaws.substring(0,queryFieldLaws.length()-1);
|
||||
}
|
||||
if (StringUtils.isNotBlank(queryFieldBuss)) {
|
||||
queryFieldBuss = queryFieldBuss.substring(0,queryFieldBuss.length()-1);
|
||||
}
|
||||
logger.info("项目启动时加载--查询标准属性类--查询到属性字段为:" + queryField);
|
||||
logger.info("项目启动时加载--查询政策属性类--查询到属性字段为:" + queryFieldLaws);
|
||||
logger.info("项目启动时加载--查询企标属性类--查询到属性字段为:" + queryFieldBuss);
|
||||
queryFieldNames = fieldInfoNameBuilder.toString();
|
||||
queryFieldNamesLaws = fieldInfoNameBuilderLaws.toString();
|
||||
queryFieldNamesBuss = fieldInfoNameBuilderBuss.toString();
|
||||
if (StringUtils.isNotBlank(queryFieldNames)) {
|
||||
queryFieldNames = queryFieldNames.substring(0,queryFieldNames.length()-1);
|
||||
}
|
||||
if (StringUtils.isNotBlank(queryFieldNamesLaws)) {
|
||||
queryFieldNamesLaws = queryFieldNamesLaws.substring(0,queryFieldNamesLaws.length()-1);
|
||||
}
|
||||
if (StringUtils.isNotBlank(queryFieldNamesBuss)) {
|
||||
queryFieldNamesBuss = queryFieldNamesBuss.substring(0,queryFieldNamesBuss.length()-1);
|
||||
}
|
||||
logger.info("项目启动时加载--查询标准属性类--查询到属性字段名称为:" + queryFieldNames);
|
||||
logger.info("项目启动时加载--查询政策属性类--查询到属性字段名称为:" + queryFieldNamesLaws);
|
||||
logger.info("项目启动时加载--查询企标属性类--查询到属性字段名称为:" + queryFieldNamesBuss);
|
||||
} else {
|
||||
logger.error("项目启动时加载--查询标准属性类--未查询到属性字段数据!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.hutool.core.map.MapUtil.removeNullValue;
|
||||
|
||||
public class ObjectToMapUtil {
|
||||
|
||||
public static Map<String, Object> objectToMap(Object object){
|
||||
Map<String,Object> dataMap = new HashMap<>();
|
||||
Class<?> clazz = object.getClass();
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
dataMap.put(field.getName(),field.get(object));
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除map中空key或者value空值
|
||||
* @param map
|
||||
*/
|
||||
public static void removeNullEntry(Map map){
|
||||
removeNullValue(map);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,651 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: super_liu
|
||||
* date: 2020/5/11 10:39
|
||||
*/
|
||||
public class POIReadExcelToHtml {
|
||||
private static Map<String, Object> map[];
|
||||
|
||||
/**
|
||||
* 程序入口方法(将excel文件读取成字符串)
|
||||
* @param isWithStyle 是否需要表格样式 包含 字体 颜色 边框 对齐方式
|
||||
* @return <table>...</table> 字符串
|
||||
*/
|
||||
public static String readExcelToHtml(Workbook xWb, int sheetNum, boolean isWithStyle){
|
||||
String htmlExcel = null;
|
||||
htmlExcel = readWorkbook(xWb,sheetNum,isWithStyle);
|
||||
/*try {
|
||||
// Workbook wb = WorkbookFactory.create(is);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
return htmlExcel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据excel的版本分配不同的读取方法进行处理
|
||||
* @param wb
|
||||
* @param isWithStyle
|
||||
* @return
|
||||
*/
|
||||
private static String readWorkbook(Workbook wb, int sheetNum, boolean isWithStyle){
|
||||
String htmlExcel = "";
|
||||
if (wb instanceof XSSFWorkbook) {
|
||||
XSSFWorkbook xWb = (XSSFWorkbook) wb;
|
||||
htmlExcel = getExcelInfo(xWb,sheetNum, isWithStyle);
|
||||
}else if(wb instanceof HSSFWorkbook){
|
||||
HSSFWorkbook hWb = (HSSFWorkbook) wb;
|
||||
htmlExcel = getExcelInfo(hWb,sheetNum, isWithStyle);
|
||||
}
|
||||
return htmlExcel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取excel成string
|
||||
* @param wb
|
||||
* @param isWithStyle
|
||||
* @return
|
||||
*/
|
||||
public static String getExcelInfo(Workbook wb, int sheetNum, boolean isWithStyle){
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Sheet sheet = wb.getSheetAt(sheetNum);//获取第一个Sheet的内容
|
||||
// map等待存储excel图片
|
||||
// Map<String, PictureData> sheetIndexPicMap = getSheetPictrues(0, sheet, wb);
|
||||
//临时保存位置,正式环境根据部署环境存放其他位置
|
||||
// try {
|
||||
// if(sheetIndexPicMap != null)
|
||||
// printImg(sheetIndexPicMap);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
//读取excel拼装html
|
||||
int lastRowNum = sheet.getLastRowNum();
|
||||
map = getRowSpanColSpanMap(sheet);
|
||||
sb.append("<table style='border-collapse:collapse;width:100%;'>");
|
||||
Row row = null; //兼容
|
||||
Cell cell = null; //兼容
|
||||
|
||||
for (int rowNum = sheet.getFirstRowNum(); rowNum <= lastRowNum; rowNum ++) {
|
||||
if(rowNum > 1000) break;
|
||||
row = sheet.getRow(rowNum);
|
||||
|
||||
int lastColNum = POIReadExcelToHtml.getColsOfTable(sheet)[0];
|
||||
int rowHeight = POIReadExcelToHtml.getColsOfTable(sheet)[1];
|
||||
|
||||
if(null != row) {
|
||||
lastColNum = row.getLastCellNum();
|
||||
rowHeight = row.getHeight();
|
||||
}
|
||||
|
||||
if (null == row) {
|
||||
sb.append("<tr><td > </td></tr>");
|
||||
continue;
|
||||
}else if(row.getZeroHeight()){
|
||||
continue;
|
||||
}else if(0 == rowHeight){
|
||||
continue; //针对jxl的隐藏行(此类隐藏行只是把高度设置为0,单getZeroHeight无法识别)
|
||||
}
|
||||
sb.append("<tr>");
|
||||
|
||||
for (int colNum = 0; colNum < lastColNum; colNum ++) {
|
||||
if(sheet.isColumnHidden(colNum)) continue;
|
||||
String imageRowNum = "0_" + rowNum + "_" + colNum;
|
||||
String imageHtml = "";
|
||||
cell = row.getCell(colNum);
|
||||
/*if ((sheetIndexPicMap != null && !sheetIndexPicMap.containsKey(imageRowNum) || sheetIndexPicMap == null) && cell == null) { //特殊情况 空白的单元格会返回null+//判断该单元格是否包含图片,为空时也可能包含图片
|
||||
sb.append("<td> </td>");
|
||||
continue;
|
||||
}
|
||||
if(sheetIndexPicMap!=null && sheetIndexPicMap.containsKey(imageRowNum)){
|
||||
//待修改路径
|
||||
String imagePath = "D:\\pic" + imageRowNum + ".jpeg";
|
||||
|
||||
imageHtml = "<img src='" + imagePath + "' style='height:" + rowHeight / 20 + "px;'>";
|
||||
}*/
|
||||
String stringValue = getCellValue(cell);
|
||||
if (map[0].containsKey(rowNum + "," + colNum)) {
|
||||
String pointString = (String)map[0].get(rowNum + "," + colNum);
|
||||
int bottomeRow = Integer.valueOf(pointString.split(",")[0]);
|
||||
int bottomeCol = Integer.valueOf(pointString.split(",")[1]);
|
||||
int rowSpan = bottomeRow - rowNum + 1;
|
||||
int colSpan = bottomeCol - colNum + 1;
|
||||
if(map[2].containsKey(rowNum + "," + colNum)){
|
||||
rowSpan = rowSpan - (Integer)map[2].get(rowNum + "," + colNum);
|
||||
}
|
||||
sb.append("<td rowspan= '" + rowSpan + "' colspan= '"+ colSpan + "' ");
|
||||
if(map.length > 3 && map[3].containsKey(rowNum + "," + colNum)){
|
||||
//此类数据首行被隐藏,value为空,需使用其他方式获取值
|
||||
stringValue = getMergedRegionValue(sheet, rowNum, colNum);
|
||||
}
|
||||
} else if (map[1].containsKey(rowNum + "," + colNum)) {
|
||||
map[1].remove(rowNum + "," + colNum);
|
||||
continue;
|
||||
} else {
|
||||
sb.append("<td ");
|
||||
}
|
||||
|
||||
//判断是否需要样式
|
||||
if(isWithStyle){
|
||||
dealExcelStyle(wb, sheet, cell, sb);//处理单元格样式
|
||||
}
|
||||
|
||||
sb.append(">");
|
||||
// if(sheetIndexPicMap!=null && sheetIndexPicMap.containsKey(imageRowNum)) sb.append(imageHtml);
|
||||
if (stringValue == null || "".equals(stringValue.trim())) {
|
||||
sb.append(" ");
|
||||
} else {
|
||||
// 将ascii码为160的空格转换为html下的空格( )
|
||||
sb.append(stringValue.replace(String.valueOf((char) 160)," "));
|
||||
}
|
||||
sb.append("</td>");
|
||||
}
|
||||
sb.append("</tr>");
|
||||
continue;
|
||||
}
|
||||
sb.append("</table>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分析excel表格,记录合并单元格相关的参数,用于之后html页面元素的合并操作
|
||||
* @param sheet
|
||||
* @return
|
||||
*/
|
||||
private static Map<String, Object>[] getRowSpanColSpanMap(Sheet sheet) {
|
||||
Map<String, String> map0 = new HashMap<String, String>(); //保存合并单元格的对应起始和截止单元格
|
||||
Map<String, String> map1 = new HashMap<String, String>(); //保存被合并的那些单元格
|
||||
Map<String, Integer> map2 = new HashMap<String, Integer>(); //记录被隐藏的单元格个数
|
||||
Map<String, String> map3 = new HashMap<String, String>(); //记录合并了单元格,但是合并的首行被隐藏的情况
|
||||
int mergedNum = sheet.getNumMergedRegions();
|
||||
CellRangeAddress range = null;
|
||||
Row row = null;
|
||||
for (int i = 0; i < mergedNum; i++) {
|
||||
range = sheet.getMergedRegion(i);
|
||||
int topRow = range.getFirstRow();
|
||||
int topCol = range.getFirstColumn();
|
||||
int bottomRow = range.getLastRow();
|
||||
int bottomCol = range.getLastColumn();
|
||||
/**
|
||||
* 此类数据为合并了单元格的数据
|
||||
* 1.处理隐藏(只处理行隐藏,列隐藏poi已经处理)
|
||||
*/
|
||||
if(topRow != bottomRow){
|
||||
int zeroRoleNum = 0;
|
||||
int tempRow = topRow;
|
||||
for(int j = topRow; j <= bottomRow; j ++){
|
||||
row = sheet.getRow(j);
|
||||
if(row.getZeroHeight() || row.getHeight() == 0){
|
||||
if(j == tempRow){
|
||||
//首行就进行隐藏,将rowTop向后移
|
||||
tempRow ++;
|
||||
continue;//由于top下移,后面计算rowSpan时会扣除移走的列,所以不必增加zeroRoleNum;
|
||||
}
|
||||
zeroRoleNum ++;
|
||||
}
|
||||
}
|
||||
if(tempRow != topRow){
|
||||
map3.put(tempRow + "," + topCol,topRow + "," + topCol);
|
||||
topRow = tempRow;
|
||||
}
|
||||
if(zeroRoleNum!=0) map2.put(topRow + "," + topCol, zeroRoleNum);
|
||||
}
|
||||
map0.put(topRow + "," + topCol, bottomRow + "," + bottomCol);
|
||||
int tempRow = topRow;
|
||||
while (tempRow <= bottomRow) {
|
||||
int tempCol = topCol;
|
||||
while (tempCol <= bottomCol) {
|
||||
map1.put(tempRow + "," + tempCol, topRow + "," + topCol);
|
||||
tempCol++;
|
||||
}
|
||||
tempRow++;
|
||||
}
|
||||
map1.remove(topRow + "," + topCol);
|
||||
}
|
||||
Map[] map = { map0, map1 ,map2,map3};
|
||||
System.err.println(map0);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取合并单元格的值
|
||||
* @param sheet
|
||||
* @param row
|
||||
* @param column
|
||||
* @return
|
||||
*/
|
||||
public static String getMergedRegionValue(Sheet sheet, int row, int column){
|
||||
int sheetMergeCount = sheet.getNumMergedRegions();
|
||||
for(int i = 0 ; i < sheetMergeCount ; i++){
|
||||
CellRangeAddress ca = sheet.getMergedRegion(i);
|
||||
int firstColumn = ca.getFirstColumn();
|
||||
int lastColumn = ca.getLastColumn();
|
||||
int firstRow = ca.getFirstRow();
|
||||
int lastRow = ca.getLastRow();
|
||||
|
||||
if(row >= firstRow && row <= lastRow){
|
||||
|
||||
if(column >= firstColumn && column <= lastColumn){
|
||||
Row fRow = sheet.getRow(firstRow);
|
||||
Cell fCell = fRow.getCell(firstColumn);
|
||||
|
||||
return getCellValue(fCell) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null ;
|
||||
}
|
||||
/**
|
||||
* 获取表格单元格Cell内容
|
||||
* @param cell
|
||||
* @return
|
||||
*/
|
||||
private static String getCellValue(Cell cell) {
|
||||
String result = new String();
|
||||
switch (cell.getCellType()) {
|
||||
case NUMERIC:// 数字类型
|
||||
if (HSSFDateUtil.isCellDateFormatted(cell)) {// 处理日期格式、时间格式
|
||||
SimpleDateFormat sdf = null;
|
||||
if (cell.getCellStyle().getDataFormat() == HSSFDataFormat.getBuiltinFormat("h:mm")) {
|
||||
sdf = new SimpleDateFormat("HH:mm");
|
||||
} else {// 日期
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
}
|
||||
Date date = cell.getDateCellValue();
|
||||
result = sdf.format(date);
|
||||
} else if (cell.getCellStyle().getDataFormat() == 58) {
|
||||
// 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58)
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
double value = cell.getNumericCellValue();
|
||||
Date date = org.apache.poi.ss.usermodel.DateUtil
|
||||
.getJavaDate(value);
|
||||
result = sdf.format(date);
|
||||
} else {
|
||||
double value = cell.getNumericCellValue();
|
||||
CellStyle style = cell.getCellStyle();
|
||||
DecimalFormat format = new DecimalFormat();
|
||||
String temp = style.getDataFormatString();
|
||||
// 单元格设置成常规
|
||||
if (temp.equals("General")) {
|
||||
format.applyPattern("#");
|
||||
}
|
||||
result = format.format(value);
|
||||
}
|
||||
break;
|
||||
case STRING:// String类型
|
||||
result = cell.getRichStringCellValue().toString();
|
||||
break;
|
||||
case BLANK:
|
||||
result = "";
|
||||
break;
|
||||
default:
|
||||
result = "";
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理表格样式
|
||||
* @param wb
|
||||
* @param sheet
|
||||
* @param cell
|
||||
* @param sb
|
||||
*/
|
||||
private static void dealExcelStyle(Workbook wb, Sheet sheet, Cell cell, StringBuffer sb){
|
||||
CellStyle cellStyle = cell.getCellStyle();
|
||||
if (cellStyle != null) {
|
||||
|
||||
HorizontalAlignment alignment = cellStyle.getAlignment();
|
||||
sb.append("align='" + convertAlignToHtml(alignment) + "' ");//单元格内容的水平对齐方式
|
||||
VerticalAlignment verticalAlignment = cellStyle.getVerticalAlignment();
|
||||
sb.append("valign='"+ convertVerticalAlignToHtml(verticalAlignment)+ "' ");//单元格中内容的垂直排列方式
|
||||
|
||||
if (wb instanceof XSSFWorkbook) {
|
||||
|
||||
XSSFFont xf = ((XSSFCellStyle) cellStyle).getFont();
|
||||
//short boldWeight = Font.BOLDWEIGHT_BOLD;
|
||||
sb.append("style='");
|
||||
//sb.append("font-weight:" + boldWeight + ";"); // 字体加粗
|
||||
sb.append("font-size: " + xf.getFontHeight() / 2 + "%;"); // 字体大小
|
||||
|
||||
int topRow = cell.getRowIndex(),topColumn = cell.getColumnIndex();
|
||||
if(map[0].containsKey(topRow+","+topColumn)){//该单元格为合并单元格,宽度需要获取所有单元格宽度后合并
|
||||
String value = (String)map[0].get(topRow+","+topColumn);
|
||||
String[] ary = value.split(",");
|
||||
int bottomColumn = Integer.parseInt(ary[1]);
|
||||
if(topColumn!=bottomColumn){//合并列,需要计算相应宽度
|
||||
int columnWidth = 0;
|
||||
for(int i=topColumn;i<=bottomColumn;i++){
|
||||
columnWidth += sheet.getColumnWidth(i);
|
||||
}
|
||||
sb.append("width:" + columnWidth/256*xf.getFontHeight()/20 + "pt;");
|
||||
}else{
|
||||
int columnWidth = sheet.getColumnWidth(cell.getColumnIndex()) ;
|
||||
sb.append("width:" + columnWidth/256*xf.getFontHeight()/20 + "pt;");
|
||||
}
|
||||
}else{
|
||||
int columnWidth = sheet.getColumnWidth(cell.getColumnIndex()) ;
|
||||
sb.append("width:" + columnWidth/256*xf.getFontHeight()/20 + "pt;");
|
||||
}
|
||||
|
||||
XSSFColor xc = xf.getXSSFColor();
|
||||
if (xc != null && !"".equals(xc.toString())) {
|
||||
sb.append("color:#" + xc.getARGBHex().substring(2) + ";"); // 字体颜色
|
||||
}
|
||||
|
||||
XSSFColor bgColor = (XSSFColor) cellStyle.getFillForegroundColorColor();
|
||||
if (bgColor != null && !"".equals(bgColor.toString())) {
|
||||
sb.append("background-color:#" + bgColor.getARGBHex().substring(2) + ";"); // 背景颜色
|
||||
}
|
||||
sb.append("border:solid #000000 1px;");
|
||||
// sb.append(getBorderStyle(0,cellStyle.getBorderTop(), ((XSSFCellStyle) cellStyle).getTopBorderXSSFColor()));
|
||||
// sb.append(getBorderStyle(1,cellStyle.getBorderRight(), ((XSSFCellStyle) cellStyle).getRightBorderXSSFColor()));
|
||||
// sb.append(getBorderStyle(2,cellStyle.getBorderBottom(), ((XSSFCellStyle) cellStyle).getBottomBorderXSSFColor()));
|
||||
// sb.append(getBorderStyle(3,cellStyle.getBorderLeft(), ((XSSFCellStyle) cellStyle).getLeftBorderXSSFColor()));
|
||||
}else if(wb instanceof HSSFWorkbook){
|
||||
HSSFFont hf = ((HSSFCellStyle) cellStyle).getFont(wb);
|
||||
//short boldWeight = hf.getBoldweight();
|
||||
short fontColor = hf.getColor();
|
||||
sb.append("style='");
|
||||
|
||||
HSSFPalette palette = ((HSSFWorkbook) wb).getCustomPalette(); // 类HSSFPalette用于求的颜色的国际标准形式
|
||||
HSSFColor hc = palette.getColor(fontColor);
|
||||
//sb.append("font-weight:" + boldWeight + ";"); // 字体加粗
|
||||
sb.append("font-size: " + hf.getFontHeight() / 2 + "%;"); // 字体大小
|
||||
String fontColorStr = convertToStardColor(hc);
|
||||
if (fontColorStr != null && !"".equals(fontColorStr.trim())) {
|
||||
sb.append("color:" + fontColorStr + ";"); // 字体颜色
|
||||
}
|
||||
|
||||
int topRow = cell.getRowIndex(),topColumn = cell.getColumnIndex();
|
||||
if(map[0].containsKey(topRow + "," + topColumn)){//该单元格为合并单元格,宽度需要获取所有单元格宽度后合并
|
||||
String value = (String)map[0].get(topRow + "," + topColumn);
|
||||
String[] ary = value.split(",");
|
||||
int bottomColumn = Integer.parseInt(ary[1]);
|
||||
if(topColumn != bottomColumn){//合并列,需要计算相应宽度
|
||||
int columnWidth = 0;
|
||||
for(int i = topColumn; i <= bottomColumn; i++){
|
||||
columnWidth += sheet.getColumnWidth(i);
|
||||
}
|
||||
sb.append("width:" + columnWidth / 256 * hf.getFontHeight() / 20 + "pt;");
|
||||
}else{
|
||||
int columnWidth = sheet.getColumnWidth(cell.getColumnIndex()) ;
|
||||
sb.append("width:" + columnWidth / 256 * hf.getFontHeight() / 20 + "pt;");
|
||||
}
|
||||
}else{
|
||||
int columnWidth = sheet.getColumnWidth(cell.getColumnIndex()) ;
|
||||
sb.append("width:" + columnWidth / 256 * hf.getFontHeight() / 20 + "pt;");
|
||||
}
|
||||
|
||||
short bgColor = cellStyle.getFillForegroundColor();
|
||||
hc = palette.getColor(bgColor);
|
||||
String bgColorStr = convertToStardColor(hc);
|
||||
if (bgColorStr != null && !"".equals(bgColorStr.trim())) {
|
||||
sb.append("background-color:" + bgColorStr + ";"); // 背景颜色
|
||||
}
|
||||
sb.append("border:solid #000000 1px;");
|
||||
}
|
||||
sb.append("' ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单元格内容的水平对齐方式
|
||||
* @param alignment
|
||||
* @return
|
||||
*/
|
||||
private static String convertAlignToHtml(HorizontalAlignment alignment) {
|
||||
String align = "left";
|
||||
switch (alignment) {
|
||||
case LEFT:
|
||||
align = "left";
|
||||
break;
|
||||
case CENTER:
|
||||
align = "center";
|
||||
break;
|
||||
case RIGHT:
|
||||
align = "right";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return align;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单元格中内容的垂直排列方式
|
||||
* @param verticalAlignment
|
||||
* @return
|
||||
*/
|
||||
private static String convertVerticalAlignToHtml(VerticalAlignment verticalAlignment) {
|
||||
String valign = "middle";
|
||||
switch (verticalAlignment) {
|
||||
case BOTTOM:
|
||||
valign = "bottom";
|
||||
break;
|
||||
case CENTER:
|
||||
valign = "center";
|
||||
break;
|
||||
case TOP:
|
||||
valign = "top";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return valign;
|
||||
}
|
||||
|
||||
private static String convertToStardColor(HSSFColor hc) {
|
||||
StringBuffer sb = new StringBuffer("");
|
||||
if (hc != null) {
|
||||
if (IndexedColors.AUTOMATIC.index == hc.getIndex()) {
|
||||
return null;
|
||||
}
|
||||
sb.append("#");
|
||||
for (int i = 0; i < hc.getTriplet().length; i ++) {
|
||||
sb.append(fillWithZero(Integer.toHexString(hc.getTriplet()[i])));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String fillWithZero(String str) {
|
||||
if (str != null && str.length() < 2) {
|
||||
return "0" + str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
static String[] bordesr = {"border-top:", "border-right:", "border-bottom:", "border-left:"};
|
||||
static String[] borderStyles = {"solid ", "solid ", "solid ", "solid ", "solid ", "solid ", "solid ", "solid ", "solid ", "solid", "solid", "solid", "solid", "solid"};
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static String getBorderStyle(HSSFPalette palette , int b, short s, short t){
|
||||
if(s == 0) return bordesr[b] + borderStyles[s] + "#d0d7e5 1px;";
|
||||
String borderColorStr = convertToStardColor( palette.getColor(t));
|
||||
borderColorStr = borderColorStr == null || borderColorStr.length() < 1 ? "#000000" : borderColorStr;
|
||||
return bordesr[b] + borderStyles[s] + borderColorStr + " 1px;";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static String getBorderStyle(int b, short s, XSSFColor xc){
|
||||
if(s == 0)return bordesr[b] + borderStyles[s] + "#d0d7e5 1px;";
|
||||
if (xc != null && ! "".equals(xc)) {
|
||||
String borderColorStr = xc.getARGBHex();//t.getARGBHex();
|
||||
borderColorStr=borderColorStr == null || borderColorStr.length() < 1 ? "#000000" : borderColorStr.substring(2);
|
||||
return bordesr[b] + borderStyles[s]+borderColorStr+" 1px;";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void writeFile(String content, String path) {
|
||||
OutputStream os = null;
|
||||
BufferedWriter bw = null;
|
||||
try {
|
||||
File file = new File(path);
|
||||
os = new FileOutputStream(file);
|
||||
bw = new BufferedWriter(new OutputStreamWriter(os,"GBK"));
|
||||
bw.write(content);
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
fnfe.printStackTrace();
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (null != bw)
|
||||
bw.close();
|
||||
if (null != os)
|
||||
os.close();
|
||||
} catch (IOException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取Excel图片公共方法
|
||||
* @param sheetNum 当前sheet编号
|
||||
* @param sheet 当前sheet对象
|
||||
* @param workbook 工作簿对象
|
||||
* @return Map key:图片单元格索引(0_1_1)String,value:图片流PictureData
|
||||
*/
|
||||
public static Map<String, PictureData> getSheetPictrues(int sheetNum, Sheet sheet, Workbook workbook) {
|
||||
if(workbook instanceof HSSFWorkbook){
|
||||
return getSheetPictrues03(sheetNum, (HSSFSheet) sheet, (HSSFWorkbook) workbook);
|
||||
}else if(workbook instanceof XSSFWorkbook){
|
||||
return getSheetPictrues07(sheetNum, (XSSFSheet) sheet, (XSSFWorkbook) workbook);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Excel2003图片
|
||||
* @param sheetNum 当前sheet编号
|
||||
* @param sheet 当前sheet对象
|
||||
* @param workbook 工作簿对象
|
||||
* @return Map key:图片单元格索引(0_1_1)String,value:图片流PictureData
|
||||
* @throws IOException
|
||||
*/
|
||||
private static Map<String, PictureData> getSheetPictrues03(int sheetNum,
|
||||
HSSFSheet sheet, HSSFWorkbook workbook) {
|
||||
|
||||
Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
|
||||
List<HSSFPictureData> pictures = workbook.getAllPictures();
|
||||
if (pictures.size() != 0) {
|
||||
for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) {
|
||||
HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor();
|
||||
shape.getLineWidth();
|
||||
if (shape instanceof HSSFPicture) {
|
||||
HSSFPicture pic = (HSSFPicture) shape;
|
||||
int pictureIndex = pic.getPictureIndex() - 1;
|
||||
HSSFPictureData picData = pictures.get(pictureIndex);
|
||||
String picIndex = String.valueOf(sheetNum) + "_"
|
||||
+ String.valueOf(anchor.getRow1()) + "_"
|
||||
+ String.valueOf(anchor.getCol1());
|
||||
sheetIndexPicMap.put(picIndex, picData);
|
||||
}
|
||||
}
|
||||
return sheetIndexPicMap;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Excel2007图片
|
||||
* @param sheetNum 当前sheet编号
|
||||
* @param sheet 当前sheet对象
|
||||
* @param workbook 工作簿对象
|
||||
* @return Map key:图片单元格索引(0_1_1)String,value:图片流PictureData
|
||||
*/
|
||||
private static Map<String, PictureData> getSheetPictrues07(int sheetNum,
|
||||
XSSFSheet sheet, XSSFWorkbook workbook) {
|
||||
Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
|
||||
|
||||
for (POIXMLDocumentPart dr : sheet.getRelations()) {
|
||||
if (dr instanceof XSSFDrawing) {
|
||||
XSSFDrawing drawing = (XSSFDrawing) dr;
|
||||
List<XSSFShape> shapes = drawing.getShapes();
|
||||
for (XSSFShape shape : shapes) {
|
||||
XSSFPicture pic = (XSSFPicture) shape;
|
||||
XSSFClientAnchor anchor = pic.getPreferredSize();
|
||||
CTMarker ctMarker = anchor.getFrom();
|
||||
String picIndex = String.valueOf(sheetNum) + "_"
|
||||
+ ctMarker.getRow() + "_" + ctMarker.getCol();
|
||||
sheetIndexPicMap.put(picIndex, pic.getPictureData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sheetIndexPicMap;
|
||||
}
|
||||
|
||||
public static void printImg(List<Map<String, PictureData>> sheetList) throws IOException {
|
||||
for (Map<String, PictureData> map : sheetList) {
|
||||
printImg(map);
|
||||
}
|
||||
}
|
||||
|
||||
public static void printImg(Map<String, PictureData> map) throws IOException {
|
||||
Object key[] = map.keySet().toArray();
|
||||
for (int i = 0; i < map.size(); i++) {
|
||||
// 获取图片流
|
||||
PictureData pic = map.get(key[i]);
|
||||
// 获取图片索引
|
||||
String picName = key[i].toString();
|
||||
// 获取图片格式
|
||||
String ext = pic.suggestFileExtension();
|
||||
|
||||
byte[] data = pic.getData();
|
||||
|
||||
FileOutputStream out = new FileOutputStream("D:\\pic" + picName + "." + ext);
|
||||
out.write(data);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] getColsOfTable(Sheet sheet) {
|
||||
int[] data = {0, 0};
|
||||
for (int i = sheet.getFirstRowNum(); i < sheet.getLastRowNum(); i++) {
|
||||
if (null != sheet.getRow(i)) {
|
||||
data[0] = sheet.getRow(i).getLastCellNum();
|
||||
data[1] = sheet.getRow(i).getHeight();
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import com.adc.da.slrs.sarStandardsInfo.entity.SarAdvanceSearchVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 根据前台传值,生成对应sql
|
||||
* @Author: super_liu
|
||||
* date: 2020/12/11 9:27
|
||||
*/
|
||||
public class SarAdvanceSearchUtil {
|
||||
|
||||
// 拼接sql语句
|
||||
public static String createSql (List<SarAdvanceSearchVO> searchVOList) {
|
||||
String sqlInfo = "";
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
if (searchVOList != null && !searchVOList.isEmpty()) {
|
||||
for (SarAdvanceSearchVO searchVO : searchVOList) {
|
||||
String sql = "";
|
||||
if (StringUtils.isNotBlank(searchVO.getValue())) {
|
||||
if(searchVO.getValue().contains(",")){
|
||||
sql += searchVO.getConnect()+"(";
|
||||
List<String> list = Arrays.asList(searchVO.getValue().split(","));
|
||||
for(int i =0;i<list.size();i++){
|
||||
if(i==list.size()-1){
|
||||
sql += searchVO.getField() +" "+searchVO.getType() + " " + "concat(concat('%','"+ list.get(i) +"'),'%') ";
|
||||
}else{
|
||||
sql += searchVO.getField() +" "+searchVO.getType() + " " + "concat(concat('%','"+ list.get(i) +"'),'%') and ";
|
||||
}
|
||||
}
|
||||
sql += " )";
|
||||
}else{
|
||||
sql += searchVO.getConnect() + " " + searchVO.getField() + " ";
|
||||
if (!"like".equals(searchVO.getType())) {
|
||||
sql += searchVO.getType() + "'" + searchVO.getValue() + "'";
|
||||
} else {
|
||||
sql += searchVO.getType() + " " + "concat(concat('%','"+ searchVO.getValue() +"'),'%')";
|
||||
}
|
||||
}
|
||||
sqlBuilder.append(sql);
|
||||
} else if (StringUtils.isNotBlank(searchVO.getTimeSt()) || StringUtils.isNotBlank(searchVO.getTimeEd())) {
|
||||
sql += searchVO.getConnect() + " ";
|
||||
if (StringUtils.isNotBlank(searchVO.getTimeSt()) && StringUtils.isBlank(searchVO.getTimeEd())) {
|
||||
sql += "("+searchVO.getField();
|
||||
sql += (searchVO.getType().equals("!=")?" not ":"") + " between " + "'" + searchVO.getTimeSt() + "' and '2099-12-31'";
|
||||
sql += " or "+searchVO.getField();
|
||||
sql += (searchVO.getType().equals("!=")?" not ":"") + " between " + "'" + searchVO.getTimeSt() +" 00:00:00"+ "' and '2099-12-31 23:59:59'";
|
||||
sql += " or "+searchVO.getField();
|
||||
sql += " = 'TBD'";
|
||||
sql += ")";
|
||||
} else if (StringUtils.isBlank(searchVO.getTimeSt()) && StringUtils.isNotBlank(searchVO.getTimeEd())) {
|
||||
sql += "("+searchVO.getField();
|
||||
sql += (searchVO.getType().equals("!=")?" not ":"") +" between '1970-01-01' and " + "'" + searchVO.getTimeEd() + "'";
|
||||
sql += " or "+searchVO.getField();
|
||||
sql += (searchVO.getType().equals("!=")?" not ":"") +" between '1970-01-01 00:00:00' and " +
|
||||
"'" + searchVO.getTimeEd() + " 23:59:59'";
|
||||
sql += " or "+searchVO.getField();
|
||||
sql += " = 'TBD'";
|
||||
sql += ")";
|
||||
} else if (StringUtils.isNotBlank(searchVO.getTimeSt()) && StringUtils.isNotBlank(searchVO.getTimeEd())) {
|
||||
sql += "("+searchVO.getField();
|
||||
sql += (searchVO.getType().equals("!=")?" not ":"") + " between '" + searchVO.getTimeSt() + "' and '"
|
||||
+ searchVO.getTimeEd() + "'";
|
||||
sql += " or "+searchVO.getField();
|
||||
sql += (searchVO.getType().equals("!=")?" not ":"") + " between '" + searchVO.getTimeSt() +" 00:00:00"+ "' and '"
|
||||
+ searchVO.getTimeEd() + " 23:59:59'";
|
||||
sql += " or "+searchVO.getField();
|
||||
sql += " = 'TBD'";
|
||||
sql += ")";
|
||||
}
|
||||
sqlBuilder.append(sql);
|
||||
}
|
||||
}
|
||||
sqlInfo = sqlBuilder.toString();
|
||||
}
|
||||
return sqlInfo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import com.adc.da.common.SarTypeEnum;
|
||||
import com.adc.da.slrs.sarStandAttrDetails.entity.SarStandAttrDetails;
|
||||
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 标准导出工具
|
||||
* @Author: super_liu
|
||||
* date: 2020/9/16 14:09
|
||||
*/
|
||||
public class StandExportUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(StandExportUtil.class);
|
||||
|
||||
|
||||
public static Workbook exportDatas (List<SarStandardsInfo> datas, String standType) {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
try {
|
||||
standType += "_STAND";
|
||||
StringBuilder attrBud = new StringBuilder();
|
||||
List<SarStandAttrDetails> detailsEOList = new ArrayList<>();
|
||||
Map<String,String> attrInfoMap = new HashMap<>();
|
||||
if (SarTypeEnum.INLAND_STAND.getValue().equals(standType)) {
|
||||
detailsEOList = InitStandAttrUtil.standInlandAttrFieldList;
|
||||
} else {
|
||||
detailsEOList = InitStandAttrUtil.standForeignAttrFieldList;
|
||||
}
|
||||
for (SarStandAttrDetails detailsEO : detailsEOList) {
|
||||
if (!InitStandAttrUtil.fileFieldList.contains(detailsEO.getAttrField())) {
|
||||
attrBud.append(detailsEO.getAttrName() + ",");
|
||||
attrInfoMap.put(detailsEO.getAttrName(),detailsEO.getAttrField());
|
||||
}
|
||||
}
|
||||
String header = FieldConvertUtil.exportBaseFieldNames + "," + attrBud.toString();
|
||||
if (SarTypeEnum.FOREIGN_STAND.getValue().equals(standType)) {
|
||||
header = FieldConvertUtil.exportBaseFieldNamesForeign + "," + attrBud.toString();
|
||||
}
|
||||
//创建工作表对象
|
||||
Sheet sheet = workbook.createSheet();
|
||||
// 创建头部
|
||||
createHeader(workbook,sheet,header);
|
||||
// 创建数据
|
||||
createDatas(workbook,sheet,datas,header,attrInfoMap);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return workbook;
|
||||
}
|
||||
|
||||
public static void createHeader(Workbook workbook, Sheet sheet, String header){
|
||||
CellStyle cellStyle = workbook.createCellStyle();//初始化单元格格式对象
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
Row rowHeader = sheet.createRow(0);//开始创建标题行
|
||||
if (StringUtils.isNotBlank(header)) {
|
||||
String[] headerArr = header.split(",");
|
||||
for (int i=0;i < headerArr.length; i++) {
|
||||
rowHeader.createCell(i).setCellValue(headerArr[i]);
|
||||
// rowHeader.createCell(i).setCellStyle(cellStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void createDatas(Workbook workbook, Sheet sheet, List<SarStandardsInfo> datas,
|
||||
String header, Map<String,String> attrInfoMap) throws Exception{
|
||||
CellStyle cellStyle = workbook.createCellStyle();//初始化单元格格式对象
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
if (datas != null && !datas.isEmpty()) {
|
||||
for (int i=0;i < datas.size(); i++) {
|
||||
SarStandardsInfo sarStandardsInfoEO = datas.get(i);
|
||||
Row row = sheet.createRow(i+1);
|
||||
String[] headerArr = header.split(",");
|
||||
int sheetNum = 0;
|
||||
for (String headerName : headerArr) {
|
||||
String value = getValueByName(headerName,sarStandardsInfoEO,attrInfoMap);
|
||||
if (StringUtils.isBlank(value) || "null".equals(value)) {
|
||||
value = "";
|
||||
}
|
||||
row.createCell(sheetNum).setCellValue(value);
|
||||
sheetNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 根据表头返回相应值
|
||||
public static String getValueByName (String name,SarStandardsInfo sarStandardsInfoEO,Map<String,String> attrInfoMap) throws Exception{
|
||||
String value = "";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH");
|
||||
Map<String,Object> attrValueMap = sarStandardsInfoEO.getAttrInfoMap();
|
||||
switch (name) {
|
||||
case "适用区域":
|
||||
value = sarStandardsInfoEO.getCountryShow();
|
||||
break;
|
||||
case "标准类别":
|
||||
value = sarStandardsInfoEO.getStandSortShow();
|
||||
break;
|
||||
case "重要度":
|
||||
if (StringUtils.isNotBlank(sarStandardsInfoEO.getIsRelateAccess())) {
|
||||
if ("1".equals(sarStandardsInfoEO.getIsRelateAccess())) {
|
||||
sarStandardsInfoEO.setIsRelateAccess("A");
|
||||
} else {
|
||||
sarStandardsInfoEO.setIsRelateAccess("B");
|
||||
}
|
||||
}
|
||||
value = sarStandardsInfoEO.getIsRelateAccess();
|
||||
break;
|
||||
case "标准编号":
|
||||
value = sarStandardsInfoEO.getStandNumber();
|
||||
break;
|
||||
case "标准年份":
|
||||
value = sarStandardsInfoEO.getStandYear();
|
||||
break;
|
||||
case "中文名称":
|
||||
value = sarStandardsInfoEO.getStandName();
|
||||
break;
|
||||
case "英文名称":
|
||||
value = sarStandardsInfoEO.getStandEnName();
|
||||
break;
|
||||
case "标准状态":
|
||||
value = sarStandardsInfoEO.getStandStateShow();
|
||||
break;
|
||||
case "发布日期":
|
||||
if (sarStandardsInfoEO.getIssueTime() != null) {
|
||||
String issueTime = sarStandardsInfoEO.getIssueTime();
|
||||
if (issueTime.length() > 10) {
|
||||
issueTime = issueTime.substring(0,10);
|
||||
}
|
||||
value = issueTime;
|
||||
}
|
||||
break;
|
||||
case "文本说明":
|
||||
value = sarStandardsInfoEO.getSynopsis();
|
||||
break;
|
||||
default:
|
||||
String field = attrInfoMap.get(name);
|
||||
if (attrValueMap != null) {
|
||||
value = String.valueOf(attrValueMap.get(field));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: super_liu
|
||||
* @date: 2021年06月01日 13:37
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
//判断row是否为空 空返回true
|
||||
public static boolean isRowEmpty(Row row) {
|
||||
if (null == row) {
|
||||
return true;
|
||||
}
|
||||
int firstCellNum = row.getFirstCellNum(); //第一个列位置
|
||||
int lastCellNum = row.getLastCellNum(); //最后一列位置
|
||||
int nullCellNum = 0; //空列数量
|
||||
for (int c = firstCellNum; c < lastCellNum; c++) {
|
||||
Cell cell = row.getCell(c);
|
||||
if (null == cell || CellType.BLANK == cell.getCellType()) {
|
||||
nullCellNum ++;
|
||||
continue;
|
||||
}
|
||||
String value = "";
|
||||
switch (cell.getCellType()) {
|
||||
case NUMERIC: // 数字
|
||||
//如果为时间格式的内容
|
||||
value = String.valueOf(cell.getNumericCellValue());
|
||||
break;
|
||||
case STRING: // 字符串
|
||||
value = cell.getStringCellValue();
|
||||
break;
|
||||
case BOOLEAN: // Boolean
|
||||
value = cell.getBooleanCellValue() + "";
|
||||
break;
|
||||
case FORMULA: // 公式
|
||||
value = cell.getCellFormula() + "";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
nullCellNum ++;
|
||||
}
|
||||
}
|
||||
//所有列都为空
|
||||
if (nullCellNum == (lastCellNum - firstCellNum)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user