一小波优化

This commit is contained in:
zhou-hao
2018-06-01 23:25:19 +08:00
parent 8281a119a1
commit 5c656a7fa6
25 changed files with 166 additions and 207 deletions

View File

@@ -21,6 +21,7 @@ package org.hswebframework.web.commons.entity.factory;
import lombok.SneakyThrows;
import org.hswebframework.web.NotFoundException;
import org.hswebframework.utils.ClassUtils;
import org.hswebframework.web.bean.BeanFactory;
import org.hswebframework.web.bean.FastBeanCopier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,7 +35,7 @@ import java.util.function.Supplier;
* @since 3.0
*/
@SuppressWarnings("unchecked")
public class MapperEntityFactory implements EntityFactory {
public class MapperEntityFactory implements EntityFactory ,BeanFactory {
private Map<Class, Mapper> realTypeMapper = new HashMap<>();
private Logger logger = LoggerFactory.getLogger(this.getClass());
private Map<String, PropertyCopier> copierCache = new HashMap<>();

View File

@@ -0,0 +1,6 @@
package org.hswebframework.web.bean;
public interface BeanFactory {
<T> T newInstance(Class<T> beanType);
}

View File

@@ -2,6 +2,7 @@ package org.hswebframework.web.bean;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.PropertyUtilsBean;
@@ -33,10 +34,18 @@ public final class FastBeanCopier {
private static final Map<Class, Class> wrapperClassMapping = new HashMap<>();
public static final DefaultConvert DEFAULT_CONVERT = new DefaultConvert();
public static final DefaultConverter DEFAULT_CONVERT = new DefaultConverter();
public static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
public static BeanFactory BEAN_FACTORY = new BeanFactory() {
@Override
@SneakyThrows
public <T> T newInstance(Class<T> beanType) {
return beanType == Map.class ? (T) new HashMap<>() : beanType.newInstance();
}
};
static {
wrapperClassMapping.put(byte.class, Byte.class);
wrapperClassMapping.put(short.class, Short.class);
@@ -265,7 +274,9 @@ public final class FastBeanCopier {
boolean hasGeneric = false;
if (field != null) {
String[] arr = Arrays.stream(ResolvableType.forField(field)
.getGenerics()).map(ResolvableType::getRawClass)
.getGenerics())
.map(ResolvableType::getRawClass)
.filter(Objects::nonNull)
.map(t -> t.getName().concat(".class"))
.toArray(String[]::new);
if (arr.length > 0) {
@@ -324,16 +335,16 @@ public final class FastBeanCopier {
} else {
if (Cloneable.class.isAssignableFrom(targetType)) {
try {
convertCode.append("(" + getTypeName() + ")").append(getterCode).append(".clone()");
convertCode.append("(").append(getTypeName()).append(")").append(getterCode).append(".clone()");
} catch (Exception e) {
convertCode.append(getterCode);
}
} else {
if ((Map.class.isAssignableFrom(targetType)
|| Collection.class.isAssignableFrom(type)) && hasGeneric) {
convertCode.append("(" + getTypeName() + ")").append(convert);
convertCode.append("(").append(getTypeName()).append(")").append(convert);
} else {
convertCode.append("(" + getTypeName() + ")").append(getterCode);
convertCode.append("(").append(getTypeName()).append(")").append(getterCode);
// convertCode.append(getterCode);
}
@@ -398,7 +409,12 @@ public final class FastBeanCopier {
}
static final class DefaultConvert implements Converter {
public static final class DefaultConverter implements Converter {
private BeanFactory beanFactory = BEAN_FACTORY;
public void setBeanFactory(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
public Collection newCollection(Class targetClass) {
@@ -504,9 +520,7 @@ public final class FastBeanCopier {
return converter.convert(targetClass, source);
}
T newTarget = targetClass == Map.class ? (T) new HashMap<>() : targetClass.newInstance();
copy(source, newTarget);
return newTarget;
return copy(source, beanFactory.newInstance(targetClass),this);
} catch (Exception e) {
log.warn("复制类型{}->{}失败", source, targetClass, e);
throw new UnsupportedOperationException(e.getMessage(), e);

View File

@@ -25,6 +25,7 @@ import com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.hswebframework.web.ThreadLocalUtils;
import org.hswebframework.web.bean.FastBeanCopier;
import org.hswebframework.web.commons.entity.factory.EntityFactory;
import org.hswebframework.web.commons.entity.factory.MapperEntityFactory;
import org.hswebframework.web.convert.CustomMessageConverter;
@@ -64,8 +65,6 @@ import java.lang.reflect.Type;
import java.util.List;
/**
* TODO 完成注释
*
* @author zhouhao
*/
@Configuration
@@ -175,7 +174,9 @@ public class HswebAutoConfiguration {
@Bean(name = "entityFactory")
@ConditionalOnMissingBean(EntityFactory.class)
public MapperEntityFactory mapperEntityFactory() {
return new MapperEntityFactory(entityProperties.createMappers());
MapperEntityFactory entityFactory = new MapperEntityFactory(entityProperties.createMappers());
FastBeanCopier.BEAN_FACTORY = entityFactory;
return entityFactory;
}
@Bean

View File

@@ -1,41 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<artifactId>hsweb-system-all</artifactId>
<dependencies>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-authorization-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-database-manager-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-dictionary-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-organizational-starter</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-calendar</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hsweb-system-calendar-api</artifactId>
</project>

View File

@@ -1,5 +0,0 @@
package org.hswebframework.web.calendar.api;
public interface Calendar {
}

View File

@@ -1,4 +0,0 @@
package org.hswebframework.web.calendar.api;
public interface CalendarEvent {
}

View File

@@ -1,6 +0,0 @@
package org.hswebframework.web.calendar.api;
public class CalendarService {
}

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-calendar</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hsweb-system-calendar-cluster</artifactId>
</project>

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-calendar</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hsweb-system-calendar-local</artifactId>
</project>

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hsweb-system-calendar</artifactId>
<packaging>pom</packaging>
<modules>
<module>hsweb-system-calendar-api</module>
<module>hsweb-system-calendar-local</module>
<module>hsweb-system-calendar-cluster</module>
</modules>
</project>

View File

@@ -1,6 +0,0 @@
## 在线命令行工具
可通过在线执行命令脚本,查看系统信息,维护等功能
## API
//todo

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hsweb-system-cli</artifactId>
</project>

View File

@@ -1,5 +0,0 @@
## 历史记录管理
用于记录各种数据历史记录
## API
//todo

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hsweb-system-history</artifactId>
</project>

View File

@@ -11,8 +11,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Function;
/**
* TODO 完成注释
*
* @author zhouhao
*/
public class PersonnelAuthorizationHolder {

View File

@@ -16,10 +16,10 @@ import java.util.function.Predicate;
public class TreeNode<V> implements Serializable {
private static final long serialVersionUID = 1_0;
/**
* 父节点,根节点为{@code null}
*/
private TreeNode<V> parent;
// /**
// * 父节点,根节点为{@code null}
// */
// private TreeNode<V> parent;
/**
* 节点值
@@ -32,14 +32,14 @@ public class TreeNode<V> implements Serializable {
private int level;
private Set<TreeNode<V>> children;
public TreeNode<V> getParent() {
return parent;
}
public void setParent(TreeNode<V> parent) {
this.parent = parent;
}
//
// public TreeNode<V> getParent() {
// return parent;
// }
//
// public void setParent(TreeNode<V> parent) {
// this.parent = parent;
// }
public V getValue() {
return value;
@@ -55,6 +55,7 @@ public class TreeNode<V> implements Serializable {
public void setChildren(Set<TreeNode<V>> children) {
this.children = children;
children.forEach(node -> node.setLevel(getLevel() + 1));
}
public int getLevel() {

View File

@@ -1,10 +1,17 @@
package org.hswebframework.web.organizational.authorization.simple;
import org.hswebframework.web.organizational.authorization.Personnel;
import org.hswebframework.web.organizational.authorization.PersonnelAuthorization;
import org.hswebframework.web.organizational.authorization.Position;
import org.hswebframework.web.organizational.authorization.TreeNode;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.hswebframework.web.Maps;
import org.hswebframework.web.bean.BeanFactory;
import org.hswebframework.web.bean.Converter;
import org.hswebframework.web.bean.FastBeanCopier;
import org.hswebframework.web.organizational.authorization.*;
import org.hswebframework.web.organizational.authorization.relation.Relation;
import org.hswebframework.web.organizational.authorization.relation.Relations;
import org.hswebframework.web.organizational.authorization.relation.SimpleRelation;
import org.hswebframework.web.organizational.authorization.relation.SimpleRelations;
import java.util.Collections;
import java.util.Set;
@@ -14,13 +21,13 @@ import java.util.Set;
*/
public class SimplePersonnelAuthorization implements PersonnelAuthorization {
private static final long serialVersionUID = 1_0;
private Personnel personnel;
private Personnel personnel;
private Set<TreeNode<String>> districtIds;
private Set<TreeNode<String>> orgIds;
private Set<TreeNode<String>> positionIds;
private Set<TreeNode<String>> departmentIds;
private Relations relations;
private Set<Position> positions;
private Relations relations;
private Set<Position> positions;
public void setPositions(Set<Position> positions) {
this.positions = positions;
@@ -96,4 +103,6 @@ public class SimplePersonnelAuthorization implements PersonnelAuthorization {
public void setDepartmentIds(Set<TreeNode<String>> departmentIds) {
this.departmentIds = departmentIds;
}
}

View File

@@ -0,0 +1,55 @@
package org.hswebframework.web.organizational.authorization.simple;
import com.alibaba.fastjson.JSON;
import org.hswebframework.web.bean.BeanFactory;
import org.hswebframework.web.bean.FastBeanCopier;
import org.hswebframework.web.organizational.authorization.*;
import org.hswebframework.web.organizational.authorization.relation.Relation;
import org.hswebframework.web.organizational.authorization.relation.Relations;
import org.hswebframework.web.organizational.authorization.relation.SimpleRelation;
import org.hswebframework.web.organizational.authorization.relation.SimpleRelations;
import java.util.Map;
public class SimplePersonnelAuthorizationBuilder {
static FastBeanCopier.DefaultConverter converter = new FastBeanCopier.DefaultConverter();
static {
converter.setBeanFactory(new BeanFactory() {
@Override
public <T> T newInstance(Class<T> targetClass) {
if (targetClass == Position.class) {
return (T) new SimplePosition();
}
if (targetClass == Personnel.class) {
return (T) new SimplePersonnel();
}
if (targetClass == Department.class) {
return (T) new SimpleDepartment();
}
if (targetClass == Organization.class) {
return (T) new SimpleOrganization();
}
if (targetClass == District.class) {
return (T) new SimpleDistrict();
}
if (targetClass == Relation.class) {
return (T) new SimpleRelation();
}
if (targetClass == Relations.class) {
return (T) new SimpleRelations();
}
return FastBeanCopier.BEAN_FACTORY.newInstance(targetClass);
}
});
}
public static SimplePersonnelAuthorization fromJson(String json) {
return fromMap(JSON.parseObject(json));
}
public static SimplePersonnelAuthorization fromMap(Map<String,Object> map) {
return FastBeanCopier.copy(map, new SimplePersonnelAuthorization(), converter);
}
}

View File

@@ -0,0 +1,38 @@
package org.hswebframework.web.organizational.authorization.simple;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.hswebframework.web.Maps;
import org.hswebframework.web.bean.FastBeanCopier;
import org.junit.Test;
import java.util.Arrays;
import java.util.HashMap;
import static org.hswebframework.web.organizational.authorization.simple.SimplePersonnelAuthorizationBuilder.fromJson;
public class SimplePersonnelAuthorizationBuilderTest {
@Test
public void test() {
JSONObject auth = new JSONObject();
auth.put("personnel", Maps.buildMap()
.put("id", "1234")
.put("name", "234")
.get());
auth.put("orgIds", JSON.parseArray("[{\"value\":\"123\",\"children\":[{\"value\":\"234\"}]}]"));
auth.put("positions", JSON.parseArray("[{\"id\":\"1234\"," +
"\"department\":{\"id\":\"1234\",\"org\":{\"id\":\"234\",\"district\":{\"id\":\"test\"}}}}]"));
SimplePersonnelAuthorization authorization = fromJson(auth.toJSONString());
Object json = JSON.toJSON(authorization);
System.out.println(JSON.toJSONString(json, SerializerFeature.PrettyFormat));
System.out.println(JSON.toJSONString(FastBeanCopier.copy(authorization,new JSONObject())).equals(json.toString()));
}
}

View File

@@ -454,7 +454,7 @@ public class SimplePersonService extends GenericEntityService<PersonEntity, Stri
TreeNode<String> parentNode = new TreeNode<>();
parentNode.setValue(parent.getId());
parentNode.setChildren(treeNodes);
treeNode.setParent(parentNode);
// treeNode.setParent(parentNode);
}
treeNode.setValue(node.getId());
if (node.getChildren() != null && !node.getChildren().isEmpty()) {

View File

@@ -1,6 +1,8 @@
package org.hswebframework.web.workflow.flowable.controller;
import io.swagger.annotations.Api;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.entity.workflow.ActDefEntity;
import org.hswebframework.web.service.workflow.ActDefService;
@@ -20,7 +22,9 @@ import static org.hswebframework.web.commons.entity.param.QueryParamEntity.singl
* @Date 2017/9/4.
*/
@RestController
@RequestMapping("workflow/utils/")
@RequestMapping("workflow/utils")
@Api(tags = "工作流-节点配置", description = "工作流节点配置")
@Authorize(permission = "workflow-utils", description = "节点配置")
public class FlowableUtilsController {
@Autowired

View File

@@ -11,11 +11,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by Administrator on 2016/3/19 0019.
*/
public class CustomGroupEntityManager extends GroupEntityManager {
private UserService userService;
@@ -45,7 +44,7 @@ public class CustomGroupEntityManager extends GroupEntityManager {
List<RoleEntity> sysRoles = userService.getUserRole(id);
return ActivitiUserUtil.toActivitiGroups(sysRoles);
} catch (EmptyResultDataAccessException e) {
return null;
return new ArrayList<>();
}
}

View File

@@ -19,17 +19,13 @@
<module>hsweb-system-datasource</module>
<module>hsweb-system-workflow</module>
<module>hsweb-system-schedule</module>
<module>hsweb-system-cli</module>
<module>hsweb-system-all</module>
<module>hsweb-system-organizational</module>
<module>hsweb-system-file</module>
<module>hsweb-system-template</module>
<module>hsweb-system-script</module>
<module>hsweb-system-history</module>
<module>hsweb-system-dictionary</module>
<module>hsweb-system-oauth2-server</module>
<module>hsweb-system-oauth2-client</module>
<module>hsweb-system-calendar</module>
<module>hsweb-system-dashboard</module>
<module>hsweb-system-dev-tools</module>
</modules>