diff --git a/diboot-core/src/main/java/com/diboot/core/config/Cons.java b/diboot-core/src/main/java/com/diboot/core/config/Cons.java index 77e64f9..43bc17f 100644 --- a/diboot-core/src/main/java/com/diboot/core/config/Cons.java +++ b/diboot-core/src/main/java/com/diboot/core/config/Cons.java @@ -65,7 +65,15 @@ public class Cons { /** * 创建时间字段 */ - createTime + createTime, + /** + * 更新时间 + */ + updateTime, + /** + * 创建人 + */ + createBy } } diff --git a/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java b/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java index 6344f71..de140da 100644 --- a/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java +++ b/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java @@ -50,7 +50,7 @@ public class BaseController { if(entityOrDto instanceof HttpServletRequest){ throw new Exception("参数错误:buildQueryWrapper()参数为Entity/DTO对象!"); } - return QueryBuilder.toQueryWrapper(entityOrDto, extractParams()); + return QueryBuilder.toQueryWrapper(entityOrDto, extractQueryParams()); } /*** @@ -62,7 +62,7 @@ public class BaseController { if(entityOrDto instanceof HttpServletRequest){ throw new Exception("参数错误:buildQueryWrapper()参数为Entity/DTO对象!"); } - return QueryBuilder.toLambdaQueryWrapper(entityOrDto, extractParams()); + return QueryBuilder.toLambdaQueryWrapper(entityOrDto, extractQueryParams()); } /*** @@ -124,7 +124,7 @@ public class BaseController { * 提取请求参数名集合 * @return */ - private Set extractParams(){ + protected Set extractQueryParams(){ Map paramValueMap = convertParams2Map(); if(V.notEmpty(paramValueMap)){ return paramValueMap.keySet(); @@ -136,7 +136,7 @@ public class BaseController { * 将请求参数值转换为Map * @return */ - public Map convertParams2Map(){ + protected Map convertParams2Map(){ Map result = new HashMap<>(8); if(request == null){ return result; @@ -196,7 +196,7 @@ public class BaseController { * @param param * @return */ - public Long getLong(String param){ + protected Long getLong(String param){ return S.toLong(request.getParameter(param)); } @@ -206,7 +206,7 @@ public class BaseController { * @param defaultValue * @return */ - public long getLong(String param, Long defaultValue){ + protected long getLong(String param, Long defaultValue){ return S.toLong(request.getParameter(param), defaultValue); } @@ -215,7 +215,7 @@ public class BaseController { * @param param * @return */ - public Integer getInteger(String param){ + protected Integer getInteger(String param){ return S.toInt(request.getParameter(param)); } @@ -225,7 +225,7 @@ public class BaseController { * @param defaultValue * @return */ - public int getInt(String param, Integer defaultValue){ + protected int getInt(String param, Integer defaultValue){ return S.toInt(request.getParameter(param), defaultValue); } @@ -234,7 +234,7 @@ public class BaseController { * @param param * @return */ - public boolean getBoolean(String param){ + protected boolean getBoolean(String param){ return S.toBoolean(request.getParameter(param)); } @@ -244,7 +244,7 @@ public class BaseController { * @param defaultBoolean * @return */ - public boolean getBoolean(String param, boolean defaultBoolean){ + protected boolean getBoolean(String param, boolean defaultBoolean){ return S.toBoolean(request.getParameter(param), defaultBoolean); } @@ -253,7 +253,7 @@ public class BaseController { * @param param * @return */ - public Double getDouble(String param){ + protected Double getDouble(String param){ if(V.notEmpty(request.getParameter(param))){ return Double.parseDouble(request.getParameter(param)); } @@ -266,7 +266,7 @@ public class BaseController { * @param defaultValue * @return */ - public Double getDouble(String param, Double defaultValue){ + protected Double getDouble(String param, Double defaultValue){ if(V.notEmpty(request.getParameter(param))){ return Double.parseDouble(request.getParameter(param)); } @@ -278,7 +278,7 @@ public class BaseController { * @param param * @return */ - public String getString(String param){ + protected String getString(String param){ if(V.notEmpty(request.getParameter(param))){ return request.getParameter(param); } @@ -291,7 +291,7 @@ public class BaseController { * @param defaultValue * @return */ - public String getString(String param, String defaultValue){ + protected String getString(String param, String defaultValue){ if(V.notEmpty(request.getParameter(param))){ return request.getParameter(param); } @@ -303,7 +303,7 @@ public class BaseController { * @param param * @return */ - public String[] getStringArray(String param){ + protected String[] getStringArray(String param){ if(request.getParameterValues(param) != null){ return request.getParameterValues(param); } @@ -315,7 +315,7 @@ public class BaseController { * @param param * @return */ - public List getStringList(String param){ + protected List getStringList(String param){ String[] strArray = getStringArray(param); if(V.isEmpty(strArray)){ return null; @@ -328,7 +328,7 @@ public class BaseController { * @param param * @return */ - public List getLongList(String param){ + protected List getLongList(String param){ String[] strArray = getStringArray(param); if(V.isEmpty(strArray)){ return null; diff --git a/diboot-core/src/main/java/com/diboot/core/service/impl/BaseServiceImpl.java b/diboot-core/src/main/java/com/diboot/core/service/impl/BaseServiceImpl.java index d8bd04e..c0c445a 100644 --- a/diboot-core/src/main/java/com/diboot/core/service/impl/BaseServiceImpl.java +++ b/diboot-core/src/main/java/com/diboot/core/service/impl/BaseServiceImpl.java @@ -78,9 +78,21 @@ public class BaseServiceImpl, T> extends ServiceImpl warning("createEntity", "参数entity为null"); return false; } + return save(entity); + } + + @Override + public boolean save(T entity) { + beforeCreateEntity(entity); return super.save(entity); } + /** + * 用于创建之前的自动填充等场景调用 + */ + protected void beforeCreateEntity(T entity){ + } + @Override @Transactional(rollbackFor = Exception.class) public boolean createEntityAndRelatedEntities(T entity, List relatedEntities, ISetter relatedEntitySetter) { @@ -130,7 +142,26 @@ public class BaseServiceImpl, T> extends ServiceImpl } else{ // 批量插入 - return super.saveBatch(entityList, BaseConfig.getBatchSize()); + return saveBatch(entityList, BaseConfig.getBatchSize()); + } + } + + @Override + public boolean saveBatch(Collection entityList, int batchSize){ + // 批量插入 + beforeCreateEntities(entityList); + return super.saveBatch(entityList, batchSize); + } + + /** + * 用于创建之前的自动填充等场景调用 + */ + protected void beforeCreateEntities(Collection entityList){ + if(V.isEmpty(entityList)){ + return; + } + for(T entity : entityList){ + beforeCreateEntity(entity); } } @@ -649,7 +680,7 @@ public class BaseServiceImpl, T> extends ServiceImpl * @param message */ private void warning(String method, String message){ - log.warn(this.getClass().getName() + ".{} 调用错误: {}, 请检查!", method, message); + log.warn(this.getClass().getSimpleName() + ".{} 调用错误: {}, 请检查!", method, message); } } \ No newline at end of file diff --git a/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java b/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java index c6e2fa3..89fe98f 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java +++ b/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java @@ -161,8 +161,14 @@ public class BeanUtils { * @return */ public static Object getProperty(Object obj, String field){ - BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(obj); - return wrapper.getPropertyValue(field); + try { + BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(obj); + return wrapper.getPropertyValue(field); + } + catch (Exception e) { + log.warn("获取对象属性值出错,返回null", e); + } + return null; } /***