From a1ccd25594611634199d5d723abae731e3877dbc Mon Sep 17 00:00:00 2001 From: alwaysfrin <39822157+alwaysfrin@users.noreply.github.com> Date: Wed, 15 May 2019 13:49:26 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BA=8B=E5=8A=A1=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=8F=8Ademo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../i3plus/pojo/platform/bean/TestTransUser.java | 46 ++++++++++++++++++++++ .../repository/TestTransUserRepository.java | 15 +++++++ 2 files changed, 61 insertions(+) create mode 100644 modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/bean/TestTransUser.java create mode 100644 modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/repository/TestTransUserRepository.java diff --git a/modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/bean/TestTransUser.java b/modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/bean/TestTransUser.java new file mode 100644 index 0000000..ad3f8ec --- /dev/null +++ b/modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/bean/TestTransUser.java @@ -0,0 +1,46 @@ +package cn.estsh.i3plus.pojo.platform.bean; + +import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn; +import cn.estsh.i3plus.pojo.base.bean.BaseBean; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; +import javax.persistence.Version; + +/** + * @Description : 测试类,用来测试事务 + * @Reference : + * @Author : alwaysfrin + * @CreateDate : 2019-05-14 12:51 + * @Modify: + **/ +@Data +@Entity +@DynamicInsert +@DynamicUpdate +@EqualsAndHashCode(callSuper = true) +@Table(name="TEST_TRANS_USER") +@Api(value="测试用户类",description = "测试事务信息") +public class TestTransUser extends BaseBean { + + @Column(name="NAME") + @ApiParam(value ="名称" , access ="名称") + private String name; + + @Column(name="SALARY") + @ApiParam(value ="金额" , access ="金额") + private Double salary; + + @Version + @ApiParam(value ="版本控制" , access ="乐观锁") + private int version; +} diff --git a/modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/repository/TestTransUserRepository.java b/modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/repository/TestTransUserRepository.java new file mode 100644 index 0000000..2221006 --- /dev/null +++ b/modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/repository/TestTransUserRepository.java @@ -0,0 +1,15 @@ +package cn.estsh.i3plus.pojo.platform.repository; + +import cn.estsh.i3plus.pojo.base.jpa.dao.BaseRepository; +import cn.estsh.i3plus.pojo.platform.bean.SysUserInfo; +import cn.estsh.i3plus.pojo.platform.bean.TestTransUser; + +/** + * @Description : 测试事务用户 + * @Reference : + * @Author : frin + * @Date : 2019-5-14 + * @Modify : + **/ +public interface TestTransUserRepository extends BaseRepository { +} From 630ad20587241a7650e9a49d88f0e631dd1d7f65 Mon Sep 17 00:00:00 2001 From: Silliter Date: Fri, 17 May 2019 17:53:52 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=BC=80=E5=8F=91=E5=AE=89=E7=81=AF?= =?UTF-8?q?=E5=91=BC=E5=8F=AB=E5=8D=87=E7=BA=A7=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/estsh/i3plus/pojo/base/enumutil/AndonEnumUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/enumutil/AndonEnumUtil.java b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/enumutil/AndonEnumUtil.java index 3ceadb1..ec7d5c4 100644 --- a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/enumutil/AndonEnumUtil.java +++ b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/enumutil/AndonEnumUtil.java @@ -83,7 +83,7 @@ public class AndonEnumUtil { public enum ALARM_FLAG{ CALL(1,"10","呼叫"), - SIGN(2,"20","签到"), + SIGN(2,"20","响应"), RESOLVE(3,"30","解决"), CANCEL(4,"40", "撤销"); From d00c22882386646ee1810092b6443f8de7070e95 Mon Sep 17 00:00:00 2001 From: alwaysfrin <39822157+alwaysfrin@users.noreply.github.com> Date: Sun, 19 May 2019 17:54:56 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BA=8B=E5=8A=A1=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=8F=8Ademo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/estsh/i3plus/pojo/platform/bean/TestTransUser.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/bean/TestTransUser.java b/modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/bean/TestTransUser.java index ad3f8ec..7f5be42 100644 --- a/modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/bean/TestTransUser.java +++ b/modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/bean/TestTransUser.java @@ -40,7 +40,7 @@ public class TestTransUser extends BaseBean { @ApiParam(value ="金额" , access ="金额") private Double salary; - @Version + /*@Version @ApiParam(value ="版本控制" , access ="乐观锁") - private int version; + private int version;*/ } From cc02090910e20f75a262ab24ef47258e75cb37d9 Mon Sep 17 00:00:00 2001 From: alwaysfrin <39822157+alwaysfrin@users.noreply.github.com> Date: Sun, 19 May 2019 17:57:45 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BA=8B=E5=8A=A1=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=8F=8Ademo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../i3plus/pojo/base/jpa/dao/BaseRepository.java | 45 +++++++++++ .../pojo/base/jpa/daoimpl/BaseRepositoryImpl.java | 90 +++++++++++++++++++--- 2 files changed, 124 insertions(+), 11 deletions(-) diff --git a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/jpa/dao/BaseRepository.java b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/jpa/dao/BaseRepository.java index 4c07060..c131da7 100644 --- a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/jpa/dao/BaseRepository.java +++ b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/jpa/dao/BaseRepository.java @@ -132,6 +132,51 @@ public interface BaseRepository extends JpaReposito int updateByProperties(String[] conditionName, Object[] conditionValue, String[] propertyName, Object[] propertyValue); /** + * 通过多单属性进行单个值更新(eg: price = price + :price) + * @param conditionName + * @param conditionValue + * @param propertyName + * @param propertyValue + */ + int updateByPropertiesWithVal(String conditionName, Object conditionValue, String propertyName, Object propertyValue); + + /** + * 通过单个属性进行多个值更新(eg: price = price + :price) + * @param conditionName + * @param conditionValue + * @param propertyName + * @param propertyValue + */ + int updateByPropertiesWithVal(String conditionName, Object conditionValue, String[] propertyName, Object[] propertyValue); + + /** + * 通过属性进行多个值更新(eg: price = price + :price) + * @param propertyName + * @param propertyValue + */ + int updateByPropertiesWithVal(String propertyName, Object propertyValue,DdlPackBean packBean); + int updateByPropertiesWithVal(String[] propertyName, Object[] propertyValue,DdlPackBean packBean); + + + /** + * 通过多个属性进行单个值更新(eg: price = price + :price) + * @param conditionName + * @param conditionValue + * @param propertyName + * @param propertyValue + */ + int updateByPropertiesWithVal(String[] conditionName, Object[] conditionValue, String propertyName, Object propertyValue); + + /** + * 通过多个属性进行多个值更新(eg: price = price + :price) + * @param conditionName 查询属性名称 + * @param conditionValue 查询属性值 + * @param propertyName 更新属性名称 + * @param propertyValue 更新属性值 + */ + int updateByPropertiesWithVal(String[] conditionName, Object[] conditionValue, String[] propertyName, Object[] propertyValue); + + /** * 根据 hqlWhere 批量修改制定字段 * @param hqlWhere * @param propertyName 修改的字段名称 diff --git a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/jpa/daoimpl/BaseRepositoryImpl.java b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/jpa/daoimpl/BaseRepositoryImpl.java index ae2aecf..04141fd 100644 --- a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/jpa/daoimpl/BaseRepositoryImpl.java +++ b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/jpa/daoimpl/BaseRepositoryImpl.java @@ -11,10 +11,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.jpa.repository.support.SimpleJpaRepository; -import javax.persistence.EntityManager; -import javax.persistence.Id; -import javax.persistence.NoResultException; -import javax.persistence.Query; +import javax.persistence.*; import java.io.Serializable; import java.lang.reflect.Field; import java.text.SimpleDateFormat; @@ -196,6 +193,42 @@ public class BaseRepositoryImpl extends SimpleJpaRep @Override public int updateByProperties(String[] conditionName, Object[] conditionValue, String[] propertyName, Object[] propertyValue) { + return updateByPropertiesMain(conditionName, conditionValue, propertyName, propertyValue,true); + } + + @Override + public int updateByPropertiesWithVal(String conditionName, Object conditionValue, String propertyName, Object propertyValue) { + return updateByPropertiesWithVal(new String[] { conditionName }, new Object[] { conditionValue }, new String[] { propertyName }, new Object[] { propertyValue }); + } + + @Override + public int updateByPropertiesWithVal(String conditionName, Object conditionValue, String[] propertyName, Object[] propertyValue) { + return updateByPropertiesWithVal(new String[] { conditionName }, new Object[] { conditionValue }, propertyName, propertyValue); + } + + @Override + public int updateByPropertiesWithVal(String[] conditionName, Object[] conditionValue, String propertyName, Object propertyValue) { + return updateByPropertiesWithVal(conditionName, conditionValue, new String[] { propertyName }, new Object[] { propertyValue }); + } + + @Override + public int updateByPropertiesWithVal(String[] conditionName, Object[] conditionValue, String[] propertyName, Object[] propertyValue) { + return updateByPropertiesMain(conditionName, conditionValue, propertyName, propertyValue,false); + } + + /** + * 更新参数汇总方法 + * @param conditionName 条件属性名 + * @param conditionValue 条件属性值 + * @param propertyName 更新属性名 + * @param propertyValue 更新属性值 + * @param valWithSimple 是否简单赋值 + * true为正常eg: price = :price + * false为自身添加eg: price = price + :price + * @return + */ + private int updateByPropertiesMain(String[] conditionName, Object[] conditionValue, + String[] propertyName, Object[] propertyValue,boolean valWithSimple) { if ((propertyName != null) && (propertyName.length > 0) && (propertyValue != null) && (propertyValue.length > 0) && (propertyName.length == propertyValue.length) && (conditionValue != null) && (conditionValue.length > 0)) { @@ -203,7 +236,11 @@ public class BaseRepositoryImpl extends SimpleJpaRep sb.append("update " + persistentClass.getName() + " model set "); for (int i = 0; i < propertyName.length; i++) { - sb.append(propertyName[i] + " = :p_" + propertyName[i] + ","); + if(valWithSimple) { + sb.append(propertyName[i] + " = :p_" + propertyName[i] + ","); + }else{ + sb.append(propertyName[i] + " = " + propertyName[i] + " + :p_" + propertyName[i] + ","); + } } sb.deleteCharAt(sb.length() - 1); @@ -229,13 +266,32 @@ public class BaseRepositoryImpl extends SimpleJpaRep @Override public int updateByProperties(String[] propertyName, Object[] propertyValue,DdlPackBean packBean) { + return updateByPropertiesDdlPack(propertyName, propertyValue,packBean,true); + } + + @Override + public int updateByPropertiesWithVal(String propertyName, Object propertyValue,DdlPackBean packBean) { + return updateByPropertiesWithVal(new String[] { propertyName }, new Object[] { propertyValue },packBean); + } + + @Override + public int updateByPropertiesWithVal(String[] propertyName, Object[] propertyValue,DdlPackBean packBean) { + return updateByPropertiesDdlPack(propertyName, propertyValue,packBean,false); + } + + private int updateByPropertiesDdlPack(String[] propertyName, Object[] propertyValue, + DdlPackBean packBean,boolean valWithSimple) { if ((propertyName != null) && (propertyName.length > 0) && (propertyValue != null) && (propertyValue.length > 0) && (propertyName.length == propertyValue.length)) { StringBuffer sb = new StringBuffer(); sb.append("update " + persistentClass.getName() + " model set "); for (int i = 0; i < propertyName.length; i++) { - sb.append(propertyName[i] + " = :p_" + propertyName[i] + ","); + if(valWithSimple) { + sb.append(propertyName[i] + " = :p_" + propertyName[i] + ","); + }else{ + sb.append(propertyName[i] + " = " + propertyName[i] + " + :p_" + propertyName[i] + ","); + } } sb.deleteCharAt(sb.length() - 1); sb.append(" where 1=1 " + packBean.getWhereAppend()); @@ -297,7 +353,9 @@ public class BaseRepositoryImpl extends SimpleJpaRep @Override public List list() { - return this.findAll(); + List l = this.findAll(); + this.flush(); + return l; } @Override @@ -1349,7 +1407,11 @@ public class BaseRepositoryImpl extends SimpleJpaRep if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) { StringBuffer sb = new StringBuffer("select sum(model." + sumPropertyName + ") from " + persistentClass.getName() + " model where 1=1 "); appendQL(sb, paramName, paramValue); - sb.append(" group by model." + groupByName); + + if(StringUtils.isNotBlank(groupByName)) { + sb.append(" group by model." + groupByName); + } + Query query = entityManager.createQuery(sb.toString()); setParameter(query,paramName,paramValue); @@ -1374,7 +1436,10 @@ public class BaseRepositoryImpl extends SimpleJpaRep if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) { StringBuffer sb = new StringBuffer("select avg(model."+sumPropertyName+") from " + persistentClass.getName() + " model where 1=1 "); appendQL(sb,paramName,paramValue); - sb.append(" group by model." + groupByName); + + if(StringUtils.isNotBlank(groupByName)) { + sb.append(" group by model." + groupByName); + } Query query = entityManager.createQuery(sb.toString()); setParameter(query,paramName,paramValue); @@ -1400,7 +1465,7 @@ public class BaseRepositoryImpl extends SimpleJpaRep if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) { StringBuffer sb = new StringBuffer("select max(model." + sumPropertyName + ") from " + persistentClass.getName() + " model where 1=1 "); appendQL(sb, paramName, paramValue); - if(!StringUtils.isEmpty(groupByName)){ + if(StringUtils.isNotBlank(groupByName)){ sb.append(" group by model." + groupByName); } @@ -1428,7 +1493,10 @@ public class BaseRepositoryImpl extends SimpleJpaRep if ((paramName != null) && (paramName.length > 0) && (paramValue != null) && (paramValue.length > 0)) { StringBuffer sb = new StringBuffer("select min(model." + sumPropertyName + ") from " + persistentClass.getName() + " model where 1=1 "); appendQL(sb, paramName, paramValue); - sb.append(" group by model." + groupByName); + + if(StringUtils.isNotBlank(groupByName)) { + sb.append(" group by model." + groupByName); + } Query query = entityManager.createQuery(sb.toString()); setParameter(query,paramName,paramValue);