提交 1e513e44 编写于 作者: sq3536's avatar sq3536

bug

上级 34bf5b15
...@@ -69,22 +69,6 @@ ...@@ -69,22 +69,6 @@
</dependency> </dependency>
<!-- Swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<exclusions>
<exclusion>
<artifactId>mapstruct</artifactId>
<groupId>org.mapstruct</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<!-- drools --> <!-- drools -->
<dependency> <dependency>
<groupId>org.drools</groupId> <groupId>org.drools</groupId>
......
package cn.ibizlab.util.domain; package cn.ibizlab.util.domain;
import cn.ibizlab.util.helper.BeanCache;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data; import lombok.Data;
import cn.ibizlab.util.helper.DEFieldCacheMap;
import org.springframework.cglib.beans.BeanMap; import org.springframework.cglib.beans.BeanMap;
import org.springframework.data.annotation.Transient; import org.springframework.data.annotation.Transient;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -100,7 +100,7 @@ public class DTOBase implements Serializable { ...@@ -100,7 +100,7 @@ public class DTOBase implements Serializable {
} }
public Object get(String field) { public Object get(String field) {
String fieldRealName= DEFieldCacheMap.getFieldRealName(this.getClass(),field); String fieldRealName= BeanCache.getFieldRealName(this.getClass(),field);
if(!ObjectUtils.isEmpty(fieldRealName)) { if(!ObjectUtils.isEmpty(fieldRealName)) {
return getMap().get(fieldRealName); return getMap().get(fieldRealName);
} }
...@@ -113,13 +113,13 @@ public class DTOBase implements Serializable { ...@@ -113,13 +113,13 @@ public class DTOBase implements Serializable {
@JSONField(name = "_any", unwrapped = true, serialize = false, deserialize = true) @JSONField(name = "_any", unwrapped = true, serialize = false, deserialize = true)
public void set(String field, Object value) { public void set(String field, Object value) {
field=field.toLowerCase(); field=field.toLowerCase();
String fieldRealName=DEFieldCacheMap.getFieldRealName(this.getClass(),field); String fieldRealName=BeanCache.getFieldRealName(this.getClass(),field);
if(!ObjectUtils.isEmpty(fieldRealName)) { if(!ObjectUtils.isEmpty(fieldRealName)) {
if (value == null) { if (value == null) {
getMap().put(fieldRealName, null); getMap().put(fieldRealName, null);
} }
else { else {
getMap().put(fieldRealName, DEFieldCacheMap.fieldValueOf(this.getClass(), fieldRealName, value)); getMap().put(fieldRealName, BeanCache.fieldValueOf(this.getClass(), fieldRealName, value));
} }
} }
else { else {
......
package cn.ibizlab.util.domain; package cn.ibizlab.util.domain;
import cn.ibizlab.util.helper.DEFieldCacheMap; import cn.ibizlab.util.helper.BeanCache;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnyGetter;
...@@ -81,7 +81,7 @@ public class EntityBase implements Serializable { ...@@ -81,7 +81,7 @@ public class EntityBase implements Serializable {
} }
public Object get(String field) { public Object get(String field) {
String fieldRealName=DEFieldCacheMap.getFieldRealName(this.getClass(),field); String fieldRealName= BeanCache.getFieldRealName(this.getClass(),field);
if(!ObjectUtils.isEmpty(fieldRealName)) { if(!ObjectUtils.isEmpty(fieldRealName)) {
return getMap().get(fieldRealName); return getMap().get(fieldRealName);
} }
...@@ -100,13 +100,13 @@ public class EntityBase implements Serializable { ...@@ -100,13 +100,13 @@ public class EntityBase implements Serializable {
@JSONField(name = "_any", unwrapped = true, serialize = false, deserialize = true) @JSONField(name = "_any", unwrapped = true, serialize = false, deserialize = true)
public void set(String field, Object value) { public void set(String field, Object value) {
field=field.toLowerCase(); field=field.toLowerCase();
String fieldRealName=DEFieldCacheMap.getFieldRealName(this.getClass(),field); String fieldRealName=BeanCache.getFieldRealName(this.getClass(),field);
if(!ObjectUtils.isEmpty(fieldRealName)) { if(!ObjectUtils.isEmpty(fieldRealName)) {
if (value == null) { if (value == null) {
getMap().put(fieldRealName, null); getMap().put(fieldRealName, null);
} }
else { else {
getMap().put(fieldRealName, DEFieldCacheMap.fieldValueOf(this.getClass(), fieldRealName, value)); getMap().put(fieldRealName, BeanCache.fieldValueOf(this.getClass(), fieldRealName, value));
} }
} }
else { else {
...@@ -124,13 +124,12 @@ public class EntityBase implements Serializable { ...@@ -124,13 +124,12 @@ public class EntityBase implements Serializable {
public <T> T copyTo(T targetEntity, boolean bIncEmpty){ public <T> T copyTo(T targetEntity, boolean bIncEmpty){
if(targetEntity instanceof EntityBase){ if(targetEntity instanceof EntityBase){
EntityBase target= (EntityBase) targetEntity; EntityBase target= (EntityBase) targetEntity;
Hashtable<String, Field> sourceFields=DEFieldCacheMap.getFieldMap(this.getClass()); BeanCache.get(this.getClass()).getFields().forEach(item -> {
for(String field : sourceFields.keySet()){ Object value=this.get(item.getCodeName());
Object value=this.get(field); if( !ObjectUtils.isEmpty(value) || ObjectUtils.isEmpty(value) && getFocusNull().contains(item.getJsonName()) && bIncEmpty ){
if( !ObjectUtils.isEmpty(value) || ObjectUtils.isEmpty(value) && getFocusNull().contains(field) && bIncEmpty ){ target.set(item.getCodeName(),value);
target.set(field,value);
} }
} });
} }
return targetEntity; return targetEntity;
} }
......
package cn.ibizlab.util.domain; package cn.ibizlab.util.domain;
import cn.ibizlab.util.helper.BeanCache;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -9,7 +10,9 @@ public class EntityMP extends EntityBase { ...@@ -9,7 +10,9 @@ public class EntityMP extends EntityBase {
public UpdateWrapper getUpdateWrapper(boolean clean) { public UpdateWrapper getUpdateWrapper(boolean clean) {
UpdateWrapper wrapper=new UpdateWrapper(); UpdateWrapper wrapper=new UpdateWrapper();
for(String nullField:getFocusNull()) { for(String nullField:getFocusNull()) {
wrapper.set(nullField,null); String columnName=BeanCache.getFieldColumnName(this.getClass(),nullField);
if(!ObjectUtils.isEmpty(columnName))
wrapper.set(columnName,null);
} }
if(clean) { if(clean) {
getFocusNull().clear(); getFocusNull().clear();
......
package cn.ibizlab.util.domain; package cn.ibizlab.util.domain;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import org.springframework.data.annotation.Id;
import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -17,17 +31,55 @@ import java.util.Objects; ...@@ -17,17 +31,55 @@ import java.util.Objects;
@Data @Data
public class IBZDataAudit implements Serializable{ public class IBZDataAudit implements Serializable{
@TableId(value= "dataauditid",type=IdType.UUID)//指定主键生成策略 @Id
private String dataauditid; @TableId(type=IdType.ASSIGN_ID)//指定主键生成策略
private String dataauditname; private String dataAuditId;
private String oppersonid; private String dataAuditName;
private String oppersonname; private String opPersonId;
private String audittype; private String opPersonName;
private Timestamp optime; private String auditType;
private String ipaddress; private Timestamp opTime;
private String auditinfo; private String ipAddress;
private Object auditobjectdata;
private String auditobject; @TableField(typeHandler = cn.ibizlab.util.domain.IBZDataAudit.IBZDataAuditItemTypeHandler.class)
private int isdatachanged; private List<IBZDataAuditItem> auditInfo;
private Object auditObjectData;
private String auditObject;
private int isDataChanged;
@Slf4j
@MappedTypes({List.class})
@MappedJdbcTypes(JdbcType.VARCHAR)
public static class IBZDataAuditItemTypeHandler extends AbstractJsonTypeHandler<List>
{
private static ObjectMapper objectMapper = new ObjectMapper();
private JavaType type;
public IBZDataAuditItemTypeHandler(Class<List> type) {
this.type = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, IBZDataAuditItem.class);
}
@Override
protected List parse(String json) {
try {
return objectMapper.readValue(json, type);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
protected String toJson(List obj) {
try {
return objectMapper.writeValueAsString(obj);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
public static void setObjectMapper(ObjectMapper objectMapper) {
IBZDataAuditItemTypeHandler.objectMapper = objectMapper;
}
}
} }
\ No newline at end of file
package cn.ibizlab.util.domain;
import lombok.Data;
@Data
public class IBZDataAuditItem {
private String id;
private String label;
private String dict;
private Object value;
private Object before;
}
package cn.ibizlab.util.filter; package cn.ibizlab.util.filter;
import cn.ibizlab.util.helper.DEFieldCacheMap; import cn.ibizlab.util.helper.BeanCache;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
...@@ -57,10 +57,10 @@ public class QueryWrapperContext<T> extends SearchContextBase implements ISearch ...@@ -57,10 +57,10 @@ public class QueryWrapperContext<T> extends SearchContextBase implements ISearch
while (it_sort.hasNext()) { while (it_sort.hasNext()) {
Sort.Order sort_order = it_sort.next(); Sort.Order sort_order = it_sort.next();
if(sort_order.getDirection()== Sort.Direction.ASC){ if(sort_order.getDirection()== Sort.Direction.ASC){
asc_fieldList.add(DEFieldCacheMap.getFieldColumnName(type,sort_order.getProperty())); asc_fieldList.add(BeanCache.getFieldName(type,sort_order.getProperty()));
} }
else if(sort_order.getDirection()== Sort.Direction.DESC){ else if(sort_order.getDirection()== Sort.Direction.DESC){
desc_fieldList.add(DEFieldCacheMap.getFieldColumnName(type,sort_order.getProperty())); desc_fieldList.add(BeanCache.getFieldName(type,sort_order.getProperty()));
} }
} }
......
package cn.ibizlab.util.helper;
import cn.ibizlab.util.annotation.Audit;
import cn.ibizlab.util.annotation.DEField;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
/**
* 实体对象属性缓存类
*/
public class DEFieldCacheMap {
private static Hashtable<String, Hashtable<String,Field>> cacheMap = new Hashtable<>();
private static Hashtable<String, List<Field>> cacheList = new Hashtable<>();
private static Hashtable<String, Hashtable<String,String>> cacheKey = new Hashtable<>();
private static Hashtable<String, Hashtable<String,DEField>> cacheDEField = new Hashtable<>();
private static Hashtable<String, Hashtable<String,Audit>> cacheAuditField = new Hashtable<>();
private static Hashtable<String, String> cacheDEKeyField = new Hashtable<>();
private static Object objLock1=new Object();
/**
* 将实体对象中的属性存入缓存中
* @param
* @return
*/
public static <T> Hashtable<String,Field> getFieldMap(Class<T> clazz) {
String className=clazz.getName();
if(className.indexOf("_$")>0) {
className=className.substring(0, className.lastIndexOf("_$"));
}
if(cacheMap.containsKey(className)) {
return cacheMap.get(className);
}
synchronized (objLock1) {
if(cacheMap.containsKey(className)) {
return cacheMap.get(className);
}
Hashtable<String,Field> result = new Hashtable<String,Field>();
List<Field> list=new ArrayList<Field>();
Hashtable<String,String> keys=new Hashtable<String,String>();
Hashtable<String,DEField> defields=new Hashtable<>();
Hashtable<String, Audit> auditfields=new Hashtable<>();
Hashtable<String,String> dekeyfields=new Hashtable<>();
Field[] fields=clazz.getDeclaredFields();
for(Field field:fields){
result.put(field.getName(),field);
list.add(field);
keys.put(field.getName().toLowerCase(),field.getName());
DEField deField=field.getAnnotation(DEField.class);
Audit auditField=field.getAnnotation(Audit.class);
if(!ObjectUtils.isEmpty(deField)) {
defields.put(field.getName(),deField);
if(deField.isKeyField()) {
cacheDEKeyField.put(className,field.getName());
}
}
if(!ObjectUtils.isEmpty(auditField)) {
auditfields.put(field.getName(),auditField);
}
}
cacheMap.put(className, result);
cacheList.put(className,list);
cacheKey.put(className,keys);
cacheDEField.put(className,defields);
cacheAuditField.put(className,auditfields);
return result;
}
}
public static Hashtable<String,Field> getFieldMap(String className) {
if(className.indexOf("_$")>0) {
className=className.substring(0, className.lastIndexOf("_$"));
}
if(cacheMap.containsKey(className)) {
return cacheMap.get(className);
}
Class clazz = null;
try {
clazz = Class.forName(className);
return getFieldMap(clazz);
}
catch (Exception ex) {
cacheMap.put(className, new Hashtable<String,Field>());
return cacheMap.get(className);
}
}
/**
* 从缓存中查询实体对象属性集合
* @param
* @return
*/
public static <T> Hashtable<String,DEField> getDEFields(Class<T> clazz) {
String className=clazz.getName();
if(className.indexOf("_$")>0) {
className=className.substring(0, className.lastIndexOf("_$"));
}
if(cacheDEField.containsKey(className)) {
return cacheDEField.get(className);
}
else{
DEFieldCacheMap.getFieldMap(className);
return cacheDEField.get(className);
}
}
/**
* 从缓存中查询审计属性集合
* @param
* @return
*/
public static <T> Hashtable<String,Audit> getAuditFields(Class<T> clazz) {
String className=clazz.getName();
if(className.indexOf("_$")>0) {
className=className.substring(0, className.lastIndexOf("_$"));
}
if(cacheAuditField.containsKey(className)) {
return cacheAuditField.get(className);
}
else{
DEFieldCacheMap.getFieldMap(className);
return cacheAuditField.get(className);
}
}
/**
* 从缓存中查询实体对象主键
* @param
* @return
*/
public static <T> String getDEKeyField(Class<T> clazz) {
String className=clazz.getName();
if(className.indexOf("_$")>0) {
className=className.substring(0, className.lastIndexOf("_$"));
}
if(cacheDEKeyField.containsKey(className)) {
return cacheDEKeyField.get(className);
}
else{
DEFieldCacheMap.getFieldMap(className);
return cacheDEKeyField.get(className);
}
}
/**
* 从缓存中查询实体对象属性列表
* @param
* @return
*/
public static <T> List<Field> getFields(Class<T> clazz) {
String className=clazz.getName();
if(className.indexOf("_$")>0) {
className=className.substring(0, className.lastIndexOf("_$"));
}
if(cacheList.containsKey(className)) {
return cacheList.get(className);
}
else{
DEFieldCacheMap.getFieldMap(className);
return cacheList.get(className);
}
}
public static List<Field> getFields(String className) {
if(className.indexOf("_$")>0) {
className=className.substring(0, className.lastIndexOf("_$"));
}
if(cacheList.containsKey(className)) {
return cacheList.get(className);
}
else{
DEFieldCacheMap.getFieldMap(className);
return cacheList.get(className);
}
}
/**
* 从缓存中查询实体对象属性列表
* @param
* @return
*/
public static <T> Hashtable<String,String> getFieldKeys(Class<T> clazz) {
String className=clazz.getName();
if(className.indexOf("_$")>0) {
className=className.substring(0, className.lastIndexOf("_$"));
}
if(cacheKey.containsKey(className)) {
return cacheKey.get(className);
}
else{
DEFieldCacheMap.getFieldMap(className);
return cacheKey.get(className);
}
}
public static <T> String getFieldRealName(Class<T> clazz,String fieldname) {
fieldname=fieldname.toLowerCase();
Hashtable<String,String> keys=DEFieldCacheMap.getFieldKeys(clazz);
if(keys.containsKey(fieldname)) {
return keys.get(fieldname);
}
else if(keys.containsKey(fieldname.replace("_",""))) {
return keys.get(fieldname.replace("_",""));
}
else {
return "";
}
}
public static <T> Field getField(Class<T> clazz,String fieldname) {
String fieldRealName=DEFieldCacheMap.getFieldRealName(clazz,fieldname);
if(!ObjectUtils.isEmpty(fieldRealName)) {
return DEFieldCacheMap.getFieldMap(clazz).get(fieldRealName);
}
else {
return null;
}
}
public static <T> String getFieldColumnName(Class<T> clazz,String fieldname) {
Field field = DEFieldCacheMap.getField(clazz,fieldname);
if(field!=null) {
DEField deField=field.getAnnotation(DEField.class);
if(deField!=null&& !ObjectUtils.isEmpty(deField.name()))
return deField.name();
}
return fieldname;
}
public static <T> Object fieldValueOf(Class<T> clazz,String fieldname,Object fieldValue) {
if(fieldValue==null)
return null;
Object resultValue=fieldValue;
Field field = DEFieldCacheMap.getField(clazz,fieldname);
if(field!=null) {
Class<?> type=field.getType();
resultValue = DataObject.objectValueOf(type,fieldValue);
}
return resultValue;
}
}
\ No newline at end of file
package cn.ibizlab.util.service; package cn.ibizlab.util.service;
import cn.ibizlab.util.annotation.Audit; import cn.ibizlab.util.annotation.Audit;
import cn.ibizlab.util.annotation.DEField;
import cn.ibizlab.util.domain.EntityBase; import cn.ibizlab.util.domain.EntityBase;
import cn.ibizlab.util.domain.IBZDataAuditItem;
import cn.ibizlab.util.helper.BeanCache;
import cn.ibizlab.util.security.AuthenticationUser;
import lombok.SneakyThrows;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.util.ObjectUtils;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -11,9 +27,137 @@ import java.util.Map; ...@@ -11,9 +27,137 @@ import java.util.Map;
*/ */
public interface IBZDataAuditService { public interface IBZDataAuditService {
@Async("asyncExecutor") @Async("asyncExecutor")
void createAudit(HttpServletRequest request, EntityBase entity, Object idValue, Map<String, Audit> auditFields); void createAudit(HttpServletRequest request, EntityBase entity, Object idValue);
@Async("asyncExecutor") @Async("asyncExecutor")
void updateAudit(HttpServletRequest request, EntityBase beforeEntity, Object serviceObj, Object idValue, Map<String, Audit> auditFields); void updateAudit(HttpServletRequest request, EntityBase beforeEntity, EntityBase entity, Object idValue);
@Async("asyncExecutor") @Async("asyncExecutor")
void removeAudit(HttpServletRequest request, EntityBase entity, Object idValue, Map<String, Audit> auditFields); void removeAudit(HttpServletRequest request, EntityBase entity, Object idValue);
default List<IBZDataAuditItem> getAuditInfo(EntityBase entity) {
List<IBZDataAuditItem> auditFieldArray = new ArrayList<>();
BeanCache.get(entity.getClass()).getAudits().forEach(item->{
String fieldName = item.getCodeName();
DEField deField = item.getDeField();
Object value = dataTransfer(entity.get(fieldName),item.getFormat());
if(!ObjectUtils.isEmpty(value)) {
IBZDataAuditItem auditFieldObj = new IBZDataAuditItem();
auditFieldObj.setId(item.getJsonName());
auditFieldObj.setLabel(item.getLogicName());
auditFieldObj.setValue(value);
if(!ObjectUtils.isEmpty(deField)&&!ObjectUtils.isEmpty(deField.dict())) {
auditFieldObj.setDict(deField.dict());
}
auditFieldArray.add(auditFieldObj);
}
});
if(auditFieldArray.size()>0) {
return auditFieldArray;
}
return null;
}
default List<IBZDataAuditItem> getUpdateAuditInfo(EntityBase oldData, EntityBase newData){
List<IBZDataAuditItem> auditFieldArray = new ArrayList<>();
BeanCache.get(oldData.getClass()).getAudits().forEach(item->{
String fieldName = item.getCodeName();
DEField deField = item.getDeField();
Object oldValue = oldData.get(fieldName);//老属性值
Object newValue = newData.get(fieldName);//新属性值
if(!compare(oldValue, newValue)) {
IBZDataAuditItem auditFieldObj = new IBZDataAuditItem();
auditFieldObj.setId(item.getJsonName());
auditFieldObj.setLabel(item.getLogicName());
auditFieldObj.setValue(dataTransfer(newValue, deField.format()));
auditFieldObj.setBefore(dataTransfer(oldValue, deField.format()));
if(!ObjectUtils.isEmpty(deField)&&!ObjectUtils.isEmpty(deField.dict())) {
auditFieldObj.setDict(deField.dict());
}
auditFieldArray.add(auditFieldObj);
}
});
if(auditFieldArray.size()>0) {
return auditFieldArray;
}
return null;
}
default Object dataTransfer(Object value, String strFormat) {
if(value==null) {
return "";
}
Object transResult=value;
if( (!ObjectUtils.isEmpty(strFormat)) && value instanceof Timestamp) { //时间类型转换
Timestamp timestamp = (Timestamp)value;
SimpleDateFormat format = new SimpleDateFormat(strFormat);
transResult = format.format(timestamp);
}
return transResult;
}
/**
* 对象比较
* @param sourceObj 比较源对象
* @param targetObj 比较目标对象
* @return
*/
default boolean compare(Object sourceObj, Object targetObj) {
if(sourceObj == null && targetObj == null) {
return true;
}
if(sourceObj == null && targetObj != null) {
return false;
}
return sourceObj.equals(targetObj);
}
/**
* 获取Ip地址
* @param request
* @return
*/
default String getIpAddress(HttpServletRequest request, AuthenticationUser authenticationUser) {
//客户端有提交ip,以提交的ip为准
if(authenticationUser != null && !ObjectUtils.isEmpty(authenticationUser.getAddr())) {
return authenticationUser.getAddr();
}
if(request == null) {
return "";
}
String Xip = request.getHeader("X-Real-IP");
String XFor = request.getHeader("X-Forwarded-For");
if(!ObjectUtils.isEmpty(XFor) && !"unKnown".equalsIgnoreCase(XFor)) {
//多次反向代理后会有多个ip值,第一个ip才是真实ip
int index = XFor.indexOf(",");
if(index != -1){
return XFor.substring(0,index);
}else{
return XFor;
}
}
XFor = Xip;
if(!ObjectUtils.isEmpty(XFor) && !"unKnown".equalsIgnoreCase(XFor)) {
return XFor;
}
if (ObjectUtils.isEmpty(XFor) || "unknown".equalsIgnoreCase(XFor)) {
XFor = request.getHeader("Proxy-Client-IP");
}
if (ObjectUtils.isEmpty(XFor) || "unknown".equalsIgnoreCase(XFor)) {
XFor = request.getHeader("WL-Proxy-Client-IP");
}
if (ObjectUtils.isEmpty(XFor) || "unknown".equalsIgnoreCase(XFor)) {
XFor = request.getHeader("HTTP_CLIENT_IP");
}
if (ObjectUtils.isEmpty(XFor) || "unknown".equalsIgnoreCase(XFor)) {
XFor = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ObjectUtils.isEmpty(XFor) || "unknown".equalsIgnoreCase(XFor)) {
XFor = request.getRemoteAddr();
}
return XFor;
}
} }
\ No newline at end of file
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
<eureka-client.version>2.2.5.RELEASE</eureka-client.version> <eureka-client.version>2.2.5.RELEASE</eureka-client.version>
<!--Java Web Token--> <!--Java Web Token-->
<jsonwebtoken-jjwt.version>0.9.1</jsonwebtoken-jjwt.version> <jsonwebtoken-jjwt.version>0.9.1</jsonwebtoken-jjwt.version>
<commons-lang.version>3.12.0</commons-lang.version>
<!--反序列化工具--> <!--反序列化工具-->
<kryo.version>4.0.2</kryo.version> <kryo.version>4.0.2</kryo.version>
<!-- Error --> <!-- Error -->
...@@ -170,6 +171,12 @@ ...@@ -170,6 +171,12 @@
<version>${jsonwebtoken-jjwt.version}</version> <version>${jsonwebtoken-jjwt.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<!-- Swagger2 --> <!-- Swagger2 -->
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
......
...@@ -137,6 +137,26 @@ ...@@ -137,6 +137,26 @@
<artifactId>lombok-mapstruct-binding</artifactId> <artifactId>lombok-mapstruct-binding</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- Swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<exclusions>
<exclusion>
<artifactId>mapstruct</artifactId>
<groupId>org.mapstruct</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
</dependencies> </dependencies>
......
package cn.ibizlab.util.helper;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* 单复数转换类
* 2018年12月30日
*/
public class Inflector {
private static final Pattern UNDERSCORE_PATTERN_1 = Pattern.compile("([A-Z]+)([A-Z][a-z])");
private static final Pattern UNDERSCORE_PATTERN_2 = Pattern.compile("([a-z\\d])([A-Z])");
private static List<RuleAndReplacement> plurals = new ArrayList<RuleAndReplacement>();
private static List<RuleAndReplacement> singulars = new ArrayList<RuleAndReplacement>();
private static List<String> uncountables = new ArrayList<String>();
private static Inflector instance;
private Inflector() {
initialize();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
// 单数转复数
System.out.println(Inflector.getInstance().pluralize("water"));
System.out.println(Inflector.getInstance().pluralize("box"));
System.out.println(Inflector.getInstance().pluralize("tomato"));
// 复数转单数
System.out.println(Inflector.getInstance().singularize("apples"));
}
private void initialize() {
plural("$", "s");
plural("s$", "s");
plural("(ax|test)is$", "$1es");
plural("(octop|vir)us$", "$1i");
plural("(alias|status)$", "$1es");
plural("(bu)s$", "$1es");
plural("(buffal|tomat)o$", "$1oes");
plural("([ti])um$", "$1a");
plural("sis$", "ses");
plural("(?:([^f])fe|([lr])f)$", "$1$2ves");
plural("(hive)$", "$1s");
plural("([^aeiouy]|qu)y$", "$1ies");
plural("(x|ch|ss|sh)$", "$1es");
plural("(matr|vert|ind)ix|ex$", "$1ices");
plural("([m|l])ouse$", "$1ice");
plural("(ox)$", "$1es");
plural("(quiz)$", "$1zes");
singular("s$", "");
singular("(n)ews$", "$1ews");
singular("([ti])a$", "$1um");
singular("((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$", "$1$2sis");
singular("(^analy)ses$", "$1sis");
singular("([^f])ves$", "$1fe");
singular("(hive)s$", "$1");
singular("(tive)s$", "$1");
singular("([lr])ves$", "$1f");
singular("([^aeiouy]|qu)ies$", "$1y");
singular("(s)eries$", "$1eries");
singular("(m)ovies$", "$1ovie");
singular("(x|ch|ss|sh)es$", "$1");
singular("([m|l])ice$", "$1ouse");
singular("(bus)es$", "$1");
singular("(o)es$", "$1");
singular("(shoe)s$", "$1");
singular("(cris|ax|test)es$", "$1is");
singular("([octop|vir])i$", "$1us");
singular("(alias|status)es$", "$1");
singular("^(ox)es", "$1");
singular("(vert|ind)ices$", "$1ex");
singular("(matr)ices$", "$1ix");
singular("(quiz)zes$", "$1");
irregular("person", "people");
irregular("man", "men");
irregular("child", "children");
irregular("sex", "sexes");
irregular("move", "moves");
uncountable(new String[] { "equipment", "information", "rice", "money", "species", "series", "fish", "sheep" });
}
public static Inflector getInstance() {
if (instance == null) {
instance = new Inflector();
}
return instance;
}
public String underscore(String camelCasedWord) {
String underscoredWord = UNDERSCORE_PATTERN_1.matcher(camelCasedWord).replaceAll("$1_$2");
underscoredWord = UNDERSCORE_PATTERN_2.matcher(underscoredWord).replaceAll("$1_$2");
underscoredWord = underscoredWord.replace('-', '_').toLowerCase();
return underscoredWord;
}
public String pluralize(String word) {
if (uncountables.contains(word.toLowerCase())) {
return word;
}
return replaceWithFirstRule(word, plurals);
}
public String singularize(String word) {
if (uncountables.contains(word.toLowerCase())) {
return word;
}
return replaceWithFirstRule(word, singulars);
}
private String replaceWithFirstRule(String word, List<RuleAndReplacement> ruleAndReplacements) {
for (RuleAndReplacement rar : ruleAndReplacements) {
String rule = rar.getRule();
String replacement = rar.getReplacement();
// Return if we find a match.
Matcher matcher = Pattern.compile(rule, Pattern.CASE_INSENSITIVE).matcher(word);
if (matcher.find()) {
return matcher.replaceAll(replacement);
}
}
return word;
}
public String tableize(String className) {
return pluralize(underscore(className));
}
public String tableize(Class<?> klass) {
String className = klass.getName().replace(klass.getPackage().getName() + ".", "");
return tableize(className);
}
public static void plural(String rule, String replacement) {
plurals.add(0, new RuleAndReplacement(rule, replacement));
}
public static void singular(String rule, String replacement) {
singulars.add(0, new RuleAndReplacement(rule, replacement));
}
public static void irregular(String singular, String plural) {
plural(singular, plural);
singular(plural, singular);
}
public static void uncountable(String... words) {
for (String word : words) {
uncountables.add(word);
}
}
}
class RuleAndReplacement {
private String rule;
private String replacement;
public RuleAndReplacement(String rule, String replacement) {
this.rule = rule;
this.replacement = replacement;
}
public String getReplacement() {
return replacement;
}
public void setReplacement(String replacement) {
this.replacement = replacement;
}
public String getRule() {
return rule;
}
public void setRule(String rule) {
this.rule = rule;
}
}
\ No newline at end of file
...@@ -11,6 +11,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; ...@@ -11,6 +11,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.*; import java.util.*;
...@@ -316,11 +317,30 @@ public class AuthenticationUser implements UserDetails ...@@ -316,11 +317,30 @@ public class AuthenticationUser implements UserDetails
public void setPermissionList(JSONObject permissionList) { public void setPermissionList(JSONObject permissionList) {
this.permissionList = permissionList; this.permissionList = permissionList;
if(authorities==null && permissionList !=null){ if(authorities==null && permissionList !=null){
if(permissionList.getJSONArray("authorities")!=null){ if(permissionList.getJSONArray("authorities")!=null){
authorities=new ArrayList<>(); authorities=new ArrayList<>();
permissionList.getJSONArray("authorities"). permissionList.getJSONArray("authorities").
forEach(item->authorities.add(new SimpleGrantedAuthority(String.valueOf(item)))); forEach(item->{
if(item instanceof String)
authorities.add(new SimpleGrantedAuthority(String.valueOf(item)));
else if(item instanceof GrantedAuthority)
authorities.add((GrantedAuthority)item);
else
{
JSONObject json=(JSONObject)item;
if (json.getString("type").equals("OPPRIV")) {
authorities.add(JSONObject.parseObject(json.toString(), UAADEAuthority.class));
} else if (json.getString("type").equals("APPMENU")) {
authorities.add(JSONObject.parseObject(json.toString(), UAAMenuAuthority.class));
} else if (json.getString("type").equals("UNIRES")) {
authorities.add(JSONObject.parseObject(json.toString(), UAAUniResAuthority.class));
} else if (json.getString("type").equals("ROLE")) {
authorities.add(JSONObject.parseObject(json.toString(), UAARoleAuthority.class));
}
}
});
} }
} }
} }
} }
package cn.ibizlab.util.security;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Data
public class UAADEAuthority extends UAAGrantedAuthority {
private String entity;
private Integer enableorgdr;
private Integer enabledeptdr;
private Integer enabledeptbc;
private Long orgdr;
private Long deptdr;
private String deptbc;
private boolean dataset;
private String bscope;
private List<Map<String, String>> deAction = new ArrayList<>();
public UAADEAuthority(){
this.setType("OPPRIV");
}
@Override
public String getAuthority() {
return this.getName();
}
public void setAuthority(String name) {
}
}
package cn.ibizlab.util.security;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
@Data
public class UAAGrantedAuthority implements GrantedAuthority {
private String name;
private String type ;
private String systemid;
@Override
public String getAuthority() {
return null;
}
}
package cn.ibizlab.util.security;
import lombok.Data;
@Data
public class UAAMenuAuthority extends UAAGrantedAuthority {
private String menuTag;
public UAAMenuAuthority(){
this.setType("APPMENU");
}
@Override
public String getAuthority() {
return menuTag;
}
public void setAuthority(String menuTag) {
this.menuTag = menuTag;
}
}
package cn.ibizlab.util.security;
import lombok.Data;
@Data
public class UAARoleAuthority extends UAAGrantedAuthority {
private String roleTag;
public UAARoleAuthority(){
this.setType("ROLE");
}
@Override
public String getAuthority() {
return roleTag;
}
public void setAuthority(String roleTag) {
this.roleTag = roleTag;
}
}
package cn.ibizlab.util.security;
import lombok.Data;
@Data
public class UAAUniResAuthority extends UAAGrantedAuthority {
private String unionResTag;
public UAAUniResAuthority(){
this.setType("UNIRES");
}
@Override
public String getAuthority() {
return unionResTag;
}
public void setAuthority(String unionResTag) {
this.unionResTag = unionResTag;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册