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 1d0e951..72d4e0c 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 @@ -215,6 +215,8 @@ public interface BaseRepository extends JpaReposito List findByProperty(String propertyName, Object value); + List findByWasProperty(String[] propertyNames, Object[] values); + List findByProperty(String[] propertyNames, Object[] values); List findByProperty(String propertyName, Object value,String orderByStuff); 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 71184ef..92a320a 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 @@ -3,6 +3,7 @@ package cn.estsh.i3plus.pojo.base.jpa.daoimpl; import cn.estsh.i3plus.pojo.base.bean.DdlPackBean; import cn.estsh.i3plus.pojo.base.common.Pager; import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; +import cn.estsh.i3plus.pojo.base.enumutil.WmsEnumUtil; import cn.estsh.i3plus.pojo.base.jpa.dao.BaseRepository; import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker; import org.apache.commons.lang3.StringUtils; @@ -37,7 +38,7 @@ public class BaseRepositoryImpl extends SimpleJpaRep private Class persistentClass; private SnowflakeIdMaker snowflakeIdMaker; - public BaseRepositoryImpl(Class clz, EntityManager em,SnowflakeIdMaker snowflakeIdMaker) { + public BaseRepositoryImpl(Class clz, EntityManager em, SnowflakeIdMaker snowflakeIdMaker) { super(clz, em); this.entityManager = em; this.persistentClass = clz; @@ -83,7 +84,7 @@ public class BaseRepositoryImpl extends SimpleJpaRep @Override public T insert(T item) { - return insert(item,true); + return insert(item, true); } @Override @@ -94,7 +95,7 @@ public class BaseRepositoryImpl extends SimpleJpaRep @Override public S save(S entity) { //复写save方法,若id为0或空则新增,不然则修改 - return (S) innerSave(entity,true); + return (S) innerSave(entity, true); } @Override @@ -136,100 +137,101 @@ public class BaseRepositoryImpl extends SimpleJpaRep } @Override - public void deleteById(ID id){ + public void deleteById(ID id) { deleteByProperty("id", id); } @Override public int deleteByProperty(String propName, Object propValue) { - return deleteByProperties(new String[] { propName }, new Object[] { propValue }); + return deleteByProperties(new String[]{propName}, new Object[]{propValue}); } @Override public int deleteByProperties(String[] propName, Object[] propValue) { if ((propName != null) && (propName.length > 0) && (propValue != null) && (propValue.length > 0) && (propValue.length == propName.length)) { StringBuffer sb = new StringBuffer("delete from " + persistentClass.getName() + " model where 1=1 "); - appendQL(sb,propName,propValue); + appendQL(sb, propName, propValue); Query query = entityManager.createQuery(sb.toString()); - setParameter(query,propName,propValue); + setParameter(query, propName, propValue); return query.executeUpdate(); - }else{ + } else { throw new IllegalArgumentException("删除错误!propName:" + propName + ",propValue:" + propValue); } } @Override public int deleteByIds(ID[] ids) { - return deleteByPropertyIn("id", ids); + return deleteByPropertyIn("id", ids); } @Override public int deleteByPropertyIn(String propName, Object[] propValues) { if ((propName != null && propName.length() > 0) && (propValues != null && propValues.length > 0)) { - String hql = "delete from " + persistentClass.getName() + " model where model."+propName+" in(:"+propName+") "; + String hql = "delete from " + persistentClass.getName() + " model where model." + propName + " in(:" + propName + ") "; Query query = entityManager.createQuery(hql); query.setParameter(propName, Arrays.asList(propValues)); return query.executeUpdate(); - }else{ - throw new IllegalArgumentException("删除出错:"+propName+":" + propValues); + } else { + throw new IllegalArgumentException("删除出错:" + propName + ":" + propValues); } } @Override 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}); } @Override public int updateByProperties(String conditionName, Object conditionValue, String[] propertyName, Object[] propertyValue) { - return updateByProperties(new String[] { conditionName }, new Object[] { conditionValue }, propertyName, propertyValue); + return updateByProperties(new String[]{conditionName}, new Object[]{conditionValue}, propertyName, propertyValue); } @Override public int updateByProperties(String[] conditionName, Object[] conditionValue, String propertyName, Object propertyValue) { - return updateByProperties(conditionName, conditionValue, new String[] { propertyName }, new Object[] { propertyValue }); + return updateByProperties(conditionName, conditionValue, new String[]{propertyName}, new Object[]{propertyValue}); } @Override public int updateByProperties(String[] conditionName, Object[] conditionValue, String[] propertyName, Object[] propertyValue) { - return updateByPropertiesMain(conditionName, conditionValue, propertyName, propertyValue,true); + 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 }); + 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); + 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 }); + 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); + return updateByPropertiesMain(conditionName, conditionValue, propertyName, propertyValue, false); } /** * 更新参数汇总方法 - * @param conditionName 条件属性名 + * + * @param conditionName 条件属性名 * @param conditionValue 条件属性值 - * @param propertyName 更新属性名 - * @param propertyValue 更新属性值 - * @param valWithSimple 是否简单赋值 - * true为正常eg: price = :price - * false为自身添加eg: price = price + :price + * @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) { + 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)) { @@ -237,9 +239,9 @@ public class BaseRepositoryImpl extends SimpleJpaRep sb.append("update " + persistentClass.getName() + " model set "); for (int i = 0; i < propertyName.length; i++) { - if(valWithSimple) { + if (valWithSimple) { sb.append(propertyName[i] + " = :p_" + propertyName[i] + ","); - }else{ + } else { sb.append(propertyName[i] + " = " + propertyName[i] + " + :p_" + propertyName[i] + ","); } } @@ -261,36 +263,36 @@ public class BaseRepositoryImpl extends SimpleJpaRep } @Override - public int updateByProperties(String propertyName, Object propertyValue,DdlPackBean packBean) { - return updateByProperties(new String[] { propertyName }, new Object[] { propertyValue },packBean); + public int updateByProperties(String propertyName, Object propertyValue, DdlPackBean packBean) { + return updateByProperties(new String[]{propertyName}, new Object[]{propertyValue}, packBean); } @Override - public int updateByProperties(String[] propertyName, Object[] propertyValue,DdlPackBean packBean) { - return updateByPropertiesDdlPack(propertyName, propertyValue,packBean,true); + 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); + 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); + 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) { + 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++) { - if(valWithSimple) { + if (valWithSimple) { sb.append(propertyName[i] + " = :p_" + propertyName[i] + ","); - }else{ + } else { sb.append(propertyName[i] + " = " + propertyName[i] + " + :p_" + propertyName[i] + ","); } } @@ -304,7 +306,7 @@ public class BaseRepositoryImpl extends SimpleJpaRep } //查询条件 for (String key : packBean.getHqlPreparedMap().keySet()) { - query.setParameter("m_" + key,packBean.getHqlPreparedMap().get(key)); + query.setParameter("m_" + key, packBean.getHqlPreparedMap().get(key)); } return query.executeUpdate(); @@ -345,9 +347,9 @@ public class BaseRepositoryImpl extends SimpleJpaRep @Override public T getById(long id) { - try{ - return entityManager.find(persistentClass,id); - }catch (Exception e){ + try { + return entityManager.find(persistentClass, id); + } catch (Exception e) { return null; } } @@ -361,12 +363,12 @@ public class BaseRepositoryImpl extends SimpleJpaRep @Override public List listPager(Pager pager) { - if(pager.getTotalRows() > 0) { + if (pager.getTotalRows() > 0) { return entityManager.createQuery("from " + persistentClass.getName()) .setFirstResult(pager.getStartRow()) .setMaxResults(pager.getPageSize()) .getResultList(); - }else{ + } else { return new ArrayList(); } } @@ -379,16 +381,16 @@ public class BaseRepositoryImpl extends SimpleJpaRep @Override public List findByPage(DdlPackBean packBean, int offset, int pageSize) { Query query = null; - String ddl = "from " + persistentClass.getName() + " where 1=1 " +packBean.getPackedHql(); + String ddl = "from " + persistentClass.getName() + " where 1=1 " + packBean.getPackedHql(); - if(packBean.isHql()){ + if (packBean.isHql()) { query = entityManager.createQuery(ddl); - }else{ + } else { query = entityManager.createNativeQuery(ddl); } for (String key : packBean.getHqlPreparedMap().keySet()) { - query.setParameter("m_" + key,packBean.getHqlPreparedMap().get(key)); + query.setParameter("m_" + key, packBean.getHqlPreparedMap().get(key)); } return query.setFirstResult(offset) @@ -412,6 +414,34 @@ public class BaseRepositoryImpl extends SimpleJpaRep } @Override + public List findByWasProperty(String[] propertyNames, Object[] values) { + if (propertyNames.length != values.length) { + throw new IllegalArgumentException("参数名的数量和参数值不匹配!propertyNames:" + propertyNames.length + ",values:" + values.length); + } + StringBuffer queryString = new StringBuffer(); + queryString.append(" select new "+persistentClass.getSimpleName()+"(snStatus,whNo,locateNo,partNo,partNameRdd,lotNo,sum(qty)) from " + persistentClass.getSimpleName() + " "); + + int size = propertyNames.length; + if (size > 0) { + queryString.append("where 1=1 and snStatus in ('"+ WmsEnumUtil.STOCK_SN_STATUS.PRE_INSTOCK.getValue()+"','"+WmsEnumUtil.STOCK_SN_STATUS.INSTOCKED.getValue()+"','"+WmsEnumUtil.STOCK_SN_STATUS.PICKED.getValue()+"','"+WmsEnumUtil.STOCK_SN_STATUS.QUALITY_CONTROL.getValue()+"') "); + } + + for (int i = 0; i < size; i++) { + if (values[i] != null) { + queryString.append(" and " + propertyNames[i] + "= :" + propertyNames[i]); + } + } + queryString.append("/n group by lotNo,dateCode"); + Query queryObject = entityManager.createQuery(queryString.toString()); + for (int i = 0; i < size; i++) { + if (values[i] != null) { + queryObject.setParameter(propertyNames[i], values[i]); + } + } + return queryObject.getResultList(); + } + + @Override public List findByProperty(String[] propertyNames, Object[] values) { if(propertyNames.length != values.length){ throw new IllegalArgumentException("参数名的数量和参数值不匹配!propertyNames:" + propertyNames.length + ",values:" + values.length); diff --git a/modules/i3plus-pojo-wms/src/main/java/cn/estsh/i3plus/pojo/wms/bean/WmsStockSn.java b/modules/i3plus-pojo-wms/src/main/java/cn/estsh/i3plus/pojo/wms/bean/WmsStockSn.java index 8ccbb2b..096bb5e 100644 --- a/modules/i3plus-pojo-wms/src/main/java/cn/estsh/i3plus/pojo/wms/bean/WmsStockSn.java +++ b/modules/i3plus-pojo-wms/src/main/java/cn/estsh/i3plus/pojo/wms/bean/WmsStockSn.java @@ -286,4 +286,15 @@ public class WmsStockSn extends BaseBean { this.isDeleted = isDeleted; this.isValid = isValid; } + + + public WmsStockSn(Integer snStatus,String whNo,String locateNo,String partNo,String partNameRdd,String lotNo,Double qty){ + this.snStatus=snStatus; + this.whNo = whNo; + this.locateNo = locateNo; + this.partNo = partNo; + this.partNameRdd = partNameRdd; + this.lotNo = lotNo; + this.qty = qty; + } }