From a2febc5c25494712d9a3493aa1871a3cb5861096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A0=BC=E7=BA=B3=E6=96=AF?= Date: Mon, 7 Mar 2022 16:56:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SysLoginServiceImpl.java | 3 +- .../java/com/daffodil/core/dao/JpaDao.java | 6 ++++ .../core/dao/impl/IntegerJpaDaoImpl.java | 18 ++++++++---- .../daffodil/core/dao/impl/JdbcDaoImpl.java | 2 +- .../daffodil/core/dao/impl/JpaDaoImpl.java | 18 ++++++++---- .../core/dao/impl/LongJpaDaoImpl.java | 21 +++++++++----- .../core/dao/impl/StringJpaDaoImpl.java | 21 +++++++++----- .../com/daffodil/core/enums/DataStatus.java | 29 ------------------- .../com/daffodil/core/enums/OnlineStatus.java | 23 --------------- 9 files changed, 62 insertions(+), 79 deletions(-) delete mode 100644 daffodil-cloud-core/src/main/java/com/daffodil/core/enums/DataStatus.java delete mode 100644 daffodil-cloud-core/src/main/java/com/daffodil/core/enums/OnlineStatus.java diff --git a/daffodil-cloud-auth/src/main/java/com/daffodil/auth/service/impl/SysLoginServiceImpl.java b/daffodil-cloud-auth/src/main/java/com/daffodil/auth/service/impl/SysLoginServiceImpl.java index a6d4aeed..07880e49 100644 --- a/daffodil-cloud-auth/src/main/java/com/daffodil/auth/service/impl/SysLoginServiceImpl.java +++ b/daffodil-cloud-auth/src/main/java/com/daffodil/auth/service/impl/SysLoginServiceImpl.java @@ -16,7 +16,6 @@ import com.daffodil.auth.service.ISysMenuService; import com.daffodil.auth.service.ISysLoginInfoService; import com.daffodil.auth.service.ISysUserService; import com.daffodil.core.constant.Constants; -import com.daffodil.core.enums.DataStatus; import com.daffodil.core.exception.BaseException; import com.daffodil.system.entity.SysLoginInfo; import com.daffodil.system.entity.SysUser; @@ -96,7 +95,7 @@ public class SysLoginServiceImpl implements ISysLoginService{ throw new BaseException("用户不存在或密码错误"); } - if (DataStatus.DELETED.getCode().equals(user.getStatus())) { + if (Constants.DELETED.equals(user.getStatus())) { this.recordLoginInfo(loginName, Constants.LOGIN_FAIL, "用户已被禁用,请联系管理员", request); throw new BaseException("用户已被禁用,请联系管理员"); } diff --git a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/JpaDao.java b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/JpaDao.java index bb532188..a9cd776b 100644 --- a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/JpaDao.java +++ b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/JpaDao.java @@ -32,6 +32,12 @@ public abstract interface JpaDao { * @throws BusinessException */ public abstract void delete(BaseEntity[] entitys) throws BusinessException; + /** + * 删除多个实体对象 + * @param entitys + * @throws BusinessException + */ + public abstract void delete(List entitys) throws BusinessException; /** * 根据hql语句删除实体对象 * @param hql diff --git a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/IntegerJpaDaoImpl.java b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/IntegerJpaDaoImpl.java index 368c9426..68eb0477 100644 --- a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/IntegerJpaDaoImpl.java +++ b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/IntegerJpaDaoImpl.java @@ -56,12 +56,20 @@ public class IntegerJpaDaoImpl implements JpaDao { public void delete(BaseEntity[] entitys) throws BusinessException { try { - BaseEntity[] arrayOfBaseEntity; - int j = (arrayOfBaseEntity = entitys).length; + int j = entitys.length; for (int i = 0; i < j; i++) { - BaseEntity entity = arrayOfBaseEntity[i]; - this.entityManager - .remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); + BaseEntity entity = entitys[i]; + this.entityManager.remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); + } + } catch (Exception e) { + throw new BusinessException("[JPA] 执行HQL语句错误 ...", e); + } + } + + public void delete(List entitys) throws BusinessException { + try { + for (Object entity : entitys) { + this.entityManager.remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); } } catch (Exception e) { throw new BusinessException("[JPA] 执行HQL语句错误 ...", e); diff --git a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/JdbcDaoImpl.java b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/JdbcDaoImpl.java index 50847d35..253fb0fd 100644 --- a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/JdbcDaoImpl.java +++ b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/JdbcDaoImpl.java @@ -27,7 +27,7 @@ import com.daffodil.core.exception.BusinessException; * @version 1.0 * @description */ -@Repository("JdbcDao") +@Repository("jdbcDao") public class JdbcDaoImpl implements JdbcDao { @Autowired diff --git a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/JpaDaoImpl.java b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/JpaDaoImpl.java index ca17d87c..f629432e 100644 --- a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/JpaDaoImpl.java +++ b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/JpaDaoImpl.java @@ -55,10 +55,9 @@ public class JpaDaoImpl implements JpaDao { public void delete(BaseEntity[] entitys) throws BusinessException { try { - BaseEntity[] arrayOfBaseEntity; - int j = (arrayOfBaseEntity = entitys).length; + int j = entitys.length; for (int i = 0; i < j; i++) { - BaseEntity entity = arrayOfBaseEntity[i]; + BaseEntity entity = entitys[i]; this.entityManager .remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); } @@ -66,6 +65,16 @@ public class JpaDaoImpl implements JpaDao { throw new BusinessException("[JPA] 执行HQL语句错误 ...", e); } } + + public void delete(List entitys) throws BusinessException { + try { + for (Object entity : entitys) { + this.entityManager.remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); + } + } catch (Exception e) { + throw new BusinessException("[JPA] 执行HQL语句错误 ...", e); + } + } public void delete(String hql) throws BusinessException { try { @@ -116,9 +125,8 @@ public class JpaDaoImpl implements JpaDao { Assert.notEmpty(ids, "[JPA] 参数ids不能为空"); try { for (int i = 0; i < ids.length; i++) { - Serializable id = ids[i]; BaseEntity entity = (BaseEntity) clazz.getDeclaredConstructor().newInstance(); - entity.setId(id); + entity.setId(ids[i]); this.entityManager.remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); } } catch (Exception e) { diff --git a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/LongJpaDaoImpl.java b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/LongJpaDaoImpl.java index 421bc455..60433667 100644 --- a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/LongJpaDaoImpl.java +++ b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/LongJpaDaoImpl.java @@ -54,12 +54,20 @@ public class LongJpaDaoImpl implements JpaDao { public void delete(BaseEntity[] entitys) throws BusinessException { try { - BaseEntity[] arrayOfBaseEntity; - int j = (arrayOfBaseEntity = entitys).length; + int j = entitys.length; for (int i = 0; i < j; i++) { - BaseEntity entity = arrayOfBaseEntity[i]; - this.entityManager - .remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); + BaseEntity entity = entitys[i]; + this.entityManager.remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); + } + } catch (Exception e) { + throw new BusinessException("[JPA] 执行HQL语句错误 ...", e); + } + } + + public void delete(List entitys) throws BusinessException { + try { + for (Object entity : entitys) { + this.entityManager.remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); } } catch (Exception e) { throw new BusinessException("[JPA] 执行HQL语句错误 ...", e); @@ -115,9 +123,8 @@ public class LongJpaDaoImpl implements JpaDao { Assert.notEmpty(ids, "[JPA] 参数ids不能为空"); try { for (int i = 0; i < ids.length; i++) { - Long id = ids[i]; BaseEntity entity = (BaseEntity) clazz.getDeclaredConstructor().newInstance(); - entity.setId(id); + entity.setId(ids[i]); this.entityManager.remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); } } catch (Exception e) { diff --git a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/StringJpaDaoImpl.java b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/StringJpaDaoImpl.java index d014a9bf..dddca5a6 100644 --- a/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/StringJpaDaoImpl.java +++ b/daffodil-cloud-core/src/main/java/com/daffodil/core/dao/impl/StringJpaDaoImpl.java @@ -55,12 +55,20 @@ public class StringJpaDaoImpl implements JpaDao { public void delete(BaseEntity[] entitys) throws BusinessException { try { - BaseEntity[] arrayOfBaseEntity; - int j = (arrayOfBaseEntity = entitys).length; + int j = entitys.length; for (int i = 0; i < j; i++) { - BaseEntity entity = arrayOfBaseEntity[i]; - this.entityManager - .remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); + BaseEntity entity = entitys[i]; + this.entityManager.remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); + } + } catch (Exception e) { + throw new BusinessException("[JPA] 执行HQL语句错误 ...", e); + } + } + + public void delete(List entitys) throws BusinessException { + try { + for (Object entity : entitys) { + this.entityManager.remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); } } catch (Exception e) { throw new BusinessException("[JPA] 执行HQL语句错误 ...", e); @@ -116,9 +124,8 @@ public class StringJpaDaoImpl implements JpaDao { Assert.notEmpty(ids, "[JPA] 参数ids不能为空"); try { for (int i = 0; i < ids.length; i++) { - String id = ids[i]; BaseEntity entity = (BaseEntity) clazz.getDeclaredConstructor().newInstance(); - entity.setId(id); + entity.setId(ids[i]); this.entityManager.remove(this.entityManager.contains(entity) ? entity : this.entityManager.merge(entity)); } } catch (Exception e) { diff --git a/daffodil-cloud-core/src/main/java/com/daffodil/core/enums/DataStatus.java b/daffodil-cloud-core/src/main/java/com/daffodil/core/enums/DataStatus.java deleted file mode 100644 index edb0987a..00000000 --- a/daffodil-cloud-core/src/main/java/com/daffodil/core/enums/DataStatus.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.daffodil.core.enums; - -/** - * 数据状态 - * - * @author yweijian - * @date 2019年8月18日 - * @version 1.0 - */ -public enum DataStatus { - - NORMAL("0", "正常"), DISABLE("1", "停用"), DELETED("2", "删除"); - - private final String code; - private final String info; - - DataStatus(String code, String info) { - this.code = code; - this.info = info; - } - - public String getCode() { - return code; - } - - public String getInfo() { - return info; - } -} diff --git a/daffodil-cloud-core/src/main/java/com/daffodil/core/enums/OnlineStatus.java b/daffodil-cloud-core/src/main/java/com/daffodil/core/enums/OnlineStatus.java deleted file mode 100644 index dc7470e1..00000000 --- a/daffodil-cloud-core/src/main/java/com/daffodil/core/enums/OnlineStatus.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.daffodil.core.enums; - -/** - * 用户会话状态枚举类 - * - * @author yweijian - * @date 2019年8月16日 - * @version 1.0 - */ -public enum OnlineStatus { - /** 用户状态 */ - ON_LINE("在线"), OFF_LINE("离线"); - - private final String info; - - private OnlineStatus(String info) { - this.info = info; - } - - public String getInfo() { - return info; - } -} -- Gitee