# Conflicts:
#	modules/i3plus-pojo-platform/src/main/java/cn/estsh/i3plus/pojo/platform/sqlpack/CoreHqlPack.java
yun-zuoyi
yunhao.wang 7 years ago
commit 406ada5ac1

@ -23,6 +23,11 @@
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies> </dependencies>

@ -141,7 +141,7 @@ public class CommonEnumUtil {
* *
*/ */
public enum SYS_LOCALE_RESOURCE_TYPE { public enum SYS_LOCALE_RESOURCE_TYPE {
COMMON(1, "通用"), COMMON(1, "通用"),EXCEPTION(2, "异常"),
MODULE(10, "模块"), METHOD(11, "功能"), BUTTON(12, "按钮"); MODULE(10, "模块"), METHOD(11, "功能"), BUTTON(12, "按钮");
private int value; private int value;
@ -285,7 +285,6 @@ public class CommonEnumUtil {
} }
} }
/** /**
* *
* 1 * 1
@ -388,7 +387,6 @@ public class CommonEnumUtil {
} }
} }
/** /**
* *
*/ */
@ -422,7 +420,6 @@ public class CommonEnumUtil {
} }
} }
/** /**
* *
*/ */
@ -455,4 +452,39 @@ public class CommonEnumUtil {
return tmp; return tmp;
} }
} }
/**
*
*/
public enum PARENT{
DEFAULT(-1L,"根节点");
private Long value = -1L;
private String description = null;
public Long getValue() {
return value;
}
public String getDescription() {
return description;
}
private PARENT(Long value, String description) {
this.value = value;
this.description = description;
}
public static String valueOf(int val) {
String tmp = null;
for (int i = 0; i < values().length; i++) {
if (values()[i].value == val) {
tmp = values()[i].description;
}
}
return tmp;
}
}
} }

@ -77,6 +77,12 @@ public interface BaseRepository <T, ID extends Serializable> extends JpaReposito
public void deleteByProperties(String[] propName, Object[] propValue); public void deleteByProperties(String[] propName, Object[] propValue);
/** /**
* in
* @param ids
*/
public void deleteByIdIn(Long[] ids);
/**
* *
* @param conditionName * @param conditionName
* @param conditionValue * @param conditionValue
@ -112,6 +118,24 @@ public interface BaseRepository <T, ID extends Serializable> extends JpaReposito
*/ */
public int updateByProperties(String[] conditionName, Object[] conditionValue, String[] propertyName, Object[] propertyValue); public int updateByProperties(String[] conditionName, Object[] conditionValue, String[] propertyName, Object[] propertyValue);
/**
* hqlWhere
* @param hqlWhere
* @param propertyName
* @param propertyValue
* @return
*/
public int updateByHqlWhere(String hqlWhere,String propertyName, Object propertyValue);
/**
*
* @param hqlWhere HQL where
* @param propertyName
* @param propertyValue
* @return
*/
public int updateByHqlWhere(String hqlWhere,String[] propertyName, Object[] propertyValue);
public T getById(long id); public T getById(long id);
public List<T> list(); public List<T> list();

@ -1,14 +1,15 @@
package cn.estsh.i3plus.pojo.base.jpa.daoimpl; package cn.estsh.i3plus.pojo.base.jpa.daoimpl;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.jpa.dao.BaseRepository; import cn.estsh.i3plus.pojo.base.jpa.dao.BaseRepository;
import cn.estsh.i3plus.pojo.base.tool.SnowflakeIdMaker; import cn.estsh.i3plus.pojo.base.tool.SnowflakeIdMaker;
import cn.estsh.i3plus.pojo.base.common.Pager; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.jpa.repository.support.SimpleJpaRepository; import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Query; import javax.persistence.Query;
import javax.persistence.TypedQuery;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.*;
@ -22,6 +23,8 @@ import java.util.*;
**/ **/
public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, Serializable> public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, Serializable>
implements BaseRepository<T, Serializable> { implements BaseRepository<T, Serializable> {
public static final Logger LOGGER = LoggerFactory.getLogger(BaseRepositoryImpl.class);
/** /**
* *
*/ */
@ -141,6 +144,19 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
} }
@Override @Override
public void deleteByIdIn(Long[] ids) {
if(ids != null && ids.length > 0){
String hql = "delete from " + persistentClass.getName() + " o where o.id in(:ids) ";
Query query = entityManager.createQuery(hql);
query.setParameter("ids", Arrays.asList(ids));
query.executeUpdate();
}else{
throw new IllegalArgumentException("Method deleteByPropertiesIn argument is illegal! ids:" + ids);
}
}
@Override
public int updateByProperties(String conditionName, Object conditionValue, String propertyName, Object propertyValue) { public int updateByProperties(String conditionName, Object conditionValue, String propertyName, Object propertyValue) {
return updateByProperties(new String[] { conditionName }, new Object[] { conditionValue }, new String[] { propertyName }, new Object[] { propertyValue }); return updateByProperties(new String[] { conditionName }, new Object[] { conditionValue }, new String[] { propertyName }, new Object[] { propertyValue });
} }
@ -161,17 +177,20 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
&& (propertyValue.length > 0) && (propertyName.length == propertyValue.length) && (propertyValue.length > 0) && (propertyName.length == propertyValue.length)
&& (conditionValue != null) && (conditionValue.length > 0)) { && (conditionValue != null) && (conditionValue.length > 0)) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("update " + persistentClass.getName() + " o set "); sb.append("update " + persistentClass.getName() + " o set ");
for (int i = 0; i < propertyName.length; i++) { for (int i = 0; i < propertyName.length; i++) {
sb.append(propertyName[i] + " = :p_" + propertyName[i] + ","); sb.append(propertyName[i] + " = :p_" + propertyName[i] + ",");
} }
sb.deleteCharAt(sb.length() - 1); sb.deleteCharAt(sb.length() - 1);
sb.append(" where 1=1 "); sb.append(" where 1=1 ");
appendQL(sb, conditionName, conditionValue); appendQL(sb, conditionName, conditionValue);
Query query = entityManager.createQuery(sb.toString()); Query query = entityManager.createQuery(sb.toString());
for (int i = 0; i < propertyName.length; i++) { for (int i = 0; i < propertyName.length; i++) {
query.setParameter("p_" + propertyName[i], propertyValue[i]); query.setParameter("p_" + propertyName[i], propertyValue[i]);
} }
setParameter(query, conditionName, conditionValue); setParameter(query, conditionName, conditionValue);
return query.executeUpdate(); return query.executeUpdate();
} else { } else {
@ -181,6 +200,36 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
} }
@Override @Override
public int updateByHqlWhere(String hqlWhere, String propertyName, Object propertyValue) {
return updateByHqlWhere(hqlWhere, new String[]{propertyName}, new Object[]{propertyValue});
}
@Override
public int updateByHqlWhere(String hqlWhere, String[] propertyName, Object[] propertyValue) {
if ((propertyName != null) && (propertyName.length > 0) && (propertyValue != null)
&& (propertyValue.length > 0) && (propertyName.length == propertyValue.length)) {
StringBuffer sb = new StringBuffer();
sb.append("update " + persistentClass.getName() + " o set ");
for (int i = 0; i < propertyName.length; i++) {
sb.append(propertyName[i] + " = :p_" + propertyName[i] + ",");
}
sb.deleteCharAt(sb.length() - 1);
sb.append(" where 1=1 ");
sb.append(hqlWhere);
Query query = entityManager.createQuery(sb.toString());
for (int i = 0; i < propertyName.length; i++) {
query.setParameter("p_" + propertyName[i], propertyValue[i]);
}
return query.executeUpdate();
} else {
throw new IllegalArgumentException("Method updateByProperties argument is illegal! propertyName:" + propertyName + ",propertyValue:" + propertyValue);
}
}
@Override
public T getById(long id) { public T getById(long id) {
return this.getOne(id); return this.getOne(id);
} }
@ -292,7 +341,6 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
return queryObject.getResultList(); return queryObject.getResultList();
} }
@Override @Override
public T getByProperty(String propertyName, Object value) { public T getByProperty(String propertyName, Object value) {
String queryString = "from " + persistentClass.getSimpleName() + " as model where model." + propertyName + "= :" + propertyName; String queryString = "from " + persistentClass.getSimpleName() + " as model where model." + propertyName + "= :" + propertyName;

@ -55,9 +55,6 @@ public class Department extends BaseBean {
} }
} }
@ApiParam(value ="子部门列表")
private transient List<Department> childList;
@Column(name="RED_ORGANIZATION_NAME") @Column(name="RED_ORGANIZATION_NAME")
@ApiParam(value ="所属组织名称" , access ="所属组织名称") @ApiParam(value ="所属组织名称" , access ="所属组织名称")
private String redOrganizeName; private String redOrganizeName;
@ -71,4 +68,7 @@ public class Department extends BaseBean {
@ApiParam(value ="排序" , example ="1" , access ="排序") @ApiParam(value ="排序" , example ="1" , access ="排序")
private Integer departmentSort; private Integer departmentSort;
@ApiParam(value ="子集列表")
private transient List<Department> childList;
} }

@ -13,6 +13,7 @@ import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.List;
/** /**
* @Description : * @Description :
@ -71,4 +72,6 @@ public class Organize extends BaseBean {
@ApiParam(value ="组织状态枚举1.正常2.禁用)" , example ="1") @ApiParam(value ="组织状态枚举1.正常2.禁用)" , example ="1")
private Integer organizeStatusId; private Integer organizeStatusId;
@ApiParam(value ="子集列表")
private transient List<Organize> childList;
} }

@ -38,10 +38,10 @@ public class Position extends BaseBean {
@ApiParam(value ="岗位代码" , access ="岗位代码") @ApiParam(value ="岗位代码" , access ="岗位代码")
private String positionCode; private String positionCode;
// 默认值 -1
@Column(name="PARENT_ID") @Column(name="PARENT_ID")
@ApiParam(value ="上级岗位" , example ="-1" , access ="上级岗位") @ApiParam(value ="上级岗位" , example ="-1" , access ="上级岗位")
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
// 默认值 -1
private Long parentId; private Long parentId;
public Long getParentId() { public Long getParentId() {

@ -13,6 +13,7 @@ import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.List;
/** /**
* @Description : * @Description :
@ -79,4 +80,7 @@ public class SysMenu extends BaseBean {
@ApiParam(value ="功能状态1.正常2.禁用)" , example ="1" , access ="功能状态1.正常2.禁用)",defaultValue="1") @ApiParam(value ="功能状态1.正常2.禁用)" , example ="1" , access ="功能状态1.正常2.禁用)",defaultValue="1")
private Integer menuStatus = 1; private Integer menuStatus = 1;
@ApiParam(value ="子集列表")
private transient List<SysMenu> childList;
} }

@ -57,7 +57,7 @@ public class CoreHqlPack {
* @param position * @param position
* @return * @return
*/ */
public static String packHqlPosition(Position position) { public static String packHqlDepartment(Position position) {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
// 岗位名称 // 岗位名称
@ -88,7 +88,7 @@ public class CoreHqlPack {
* @param department * @param department
* @return * @return
*/ */
public static String packHqlPosition(Department department) { public static String packHqlDepartment(Department department) {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
// 部门名称 // 部门名称
@ -104,6 +104,22 @@ public class CoreHqlPack {
} }
/** /**
*
* @param position
* @return
*/
public static String packHqlPosition(Position position){
StringBuffer result = new StringBuffer();
// 查询参数封装
HqlPack.getNumEqualPack(position.getParentId(),"parentId",result);
HqlPack.getStringLikerPack(position.getName(),"name",result);
HqlPack.getStringLikerPack(position.getPositionCode(),"positionCode",result);
return result.toString();
}
/**
* *
* @param sysConfig * @param sysConfig
* @return * @return

Loading…
Cancel
Save