From 2cf4759c212c92a4a67b05236dd71e152dea5261 Mon Sep 17 00:00:00 2001 From: lbwgithub <你的邮箱1002117856@qq.com> Date: Thu, 10 Oct 2019 09:33:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../i3plus/pojo/base/jpa/dao/BaseRepository.java | 2 + .../pojo/base/jpa/daoimpl/BaseRepositoryImpl.java | 130 +++++++++++++-------- .../cn/estsh/i3plus/pojo/wms/bean/WmsStockSn.java | 11 ++ 3 files changed, 93 insertions(+), 50 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 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; + } } From 5c68a15d0c0ed49b5e8833e2a4290aec5b9becc6 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 10 Oct 2019 15:28:47 +0800 Subject: [PATCH 2/3] add mrp function to aps --- .../i3plus/pojo/aps/annotation/RippleAnnotation.java | 13 +++++++++++++ .../main/java/cn/estsh/i3plus/pojo/aps/bean/Material.java | 2 ++ .../cn/estsh/i3plus/pojo/aps/bean/ProductRouting.java | 2 +- .../src/main/java/cn/estsh/i3plus/pojo/aps/bean/Work.java | 8 ++++---- .../cn/estsh/i3plus/pojo/aps/common/BeanRelation.java | 15 +++++++++++++-- .../main/java/cn/estsh/i3plus/pojo/aps/holders/EWork.java | 4 ++-- .../src/main/resources/relations/BaseOrder.xml | 4 ++-- .../src/main/resources/relations/OperResource.xml | 2 +- .../src/main/resources/relations/Operation.xml | 2 ++ .../src/main/resources/relations/StandOperation.xml | 2 -- .../i3plus-pojo-aps/src/main/resources/relations/Work.xml | 4 ++-- 11 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/annotation/RippleAnnotation.java diff --git a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/annotation/RippleAnnotation.java b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/annotation/RippleAnnotation.java new file mode 100644 index 0000000..9b577f0 --- /dev/null +++ b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/annotation/RippleAnnotation.java @@ -0,0 +1,13 @@ +package cn.estsh.i3plus.pojo.aps.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface RippleAnnotation { + String[] dependence() default {}; + String method() default ""; +} diff --git a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/Material.java b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/Material.java index fc3af62..f3f1368 100644 --- a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/Material.java +++ b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/Material.java @@ -1,5 +1,6 @@ package cn.estsh.i3plus.pojo.aps.bean; +import cn.estsh.i3plus.pojo.aps.annotation.RippleAnnotation; import cn.estsh.i3plus.pojo.aps.common.BaseCode; import cn.estsh.i3plus.pojo.aps.common.BeanRelation; import cn.estsh.i3plus.pojo.aps.enums.MATERIAL_TYPE; @@ -66,6 +67,7 @@ public class Material extends BaseCode { @Column(name="LEVEL") @ApiParam(value ="低阶码") + @RippleAnnotation(dependence = {"OperOutputs.Operation.ProductRouting.Material"}, method = "calcLevel") private Integer level; @Column(name="IS_AUTO_FIX_PEGGING") diff --git a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/ProductRouting.java b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/ProductRouting.java index 7cf68ed..92c4fa2 100644 --- a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/ProductRouting.java +++ b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/ProductRouting.java @@ -24,7 +24,7 @@ import java.util.List; **/ @Data @Entity -@Table(name = "APS_PRODUCTROUTING") +@Table(name = "APS_PRODUCT_ROUTING") @Api("物料") public class ProductRouting extends BaseCode { @Column(name="VALID_START") diff --git a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/Work.java b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/Work.java index ee20430..e7c42df 100644 --- a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/Work.java +++ b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/bean/Work.java @@ -155,13 +155,13 @@ public class Work extends BaseCode { } @JsonBackReference - public List getWorkRelationInputs() { - return BeanRelation.list(this, EWork.WorkRelationInputs); + public List getPrevRelations() { + return BeanRelation.list(this, EWork.PrevRelations); } @JsonBackReference - public List getWorkRelationOutputs() { - return BeanRelation.list(this, EWork.WorkRelationOutputs); + public List getPostRelations() { + return BeanRelation.list(this, EWork.PostRelations); } @JsonBackReference diff --git a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/common/BeanRelation.java b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/common/BeanRelation.java index 85b62df..d5fb2b3 100644 --- a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/common/BeanRelation.java +++ b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/common/BeanRelation.java @@ -117,6 +117,17 @@ public class BeanRelation { return result; } + public static List listByClass(BaseBean bean, Class cls, Enum holder, Enum... args) { + List beans = new ArrayList<>(); + List nextBeans = list(bean, holder, args); + for (BaseBean nextBean : nextBeans) { + if (nextBean.getClass() == cls) { + beans.add((T)nextBean); + } + } + return beans; + } + private static void listImpl(List result, BaseBean bean, Predicate pred, Enum[] holders, int index) { if (index >= holders.length) { if (pred == null || pred.test((T)bean)) { @@ -191,7 +202,7 @@ public class BeanRelation { * @param holder */ private static void remove(BaseBean bean, Enum holder) { - if (holder == null) { + if (bean == null || holder == null) { return; } BeanInfo beanInfo = BeanInfo.getBeanInfo(bean.getClass()); @@ -215,7 +226,7 @@ public class BeanRelation { * @param relaBean */ private static void remove(BaseBean bean, Enum holder, BaseBean relaBean) { - if (bean == null) { + if (bean == null || holder == null) { return; } BeanInfo beanInfo = BeanInfo.getBeanInfo(bean.getClass()); diff --git a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/holders/EWork.java b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/holders/EWork.java index 59568c1..13dee44 100644 --- a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/holders/EWork.java +++ b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/holders/EWork.java @@ -6,8 +6,8 @@ public enum EWork { WorkResources, WorkInputs, WorkOutputs, - WorkRelationInputs, - WorkRelationOutputs, + PrevRelations, + PostRelations, Operation, PlanFeedbacks } diff --git a/modules/i3plus-pojo-aps/src/main/resources/relations/BaseOrder.xml b/modules/i3plus-pojo-aps/src/main/resources/relations/BaseOrder.xml index 3b1c1f3..e1e512a 100644 --- a/modules/i3plus-pojo-aps/src/main/resources/relations/BaseOrder.xml +++ b/modules/i3plus-pojo-aps/src/main/resources/relations/BaseOrder.xml @@ -4,8 +4,8 @@ - + - + \ No newline at end of file diff --git a/modules/i3plus-pojo-aps/src/main/resources/relations/OperResource.xml b/modules/i3plus-pojo-aps/src/main/resources/relations/OperResource.xml index 27afb26..ab4dd08 100644 --- a/modules/i3plus-pojo-aps/src/main/resources/relations/OperResource.xml +++ b/modules/i3plus-pojo-aps/src/main/resources/relations/OperResource.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/modules/i3plus-pojo-aps/src/main/resources/relations/Operation.xml b/modules/i3plus-pojo-aps/src/main/resources/relations/Operation.xml index 8b21555..1371655 100644 --- a/modules/i3plus-pojo-aps/src/main/resources/relations/Operation.xml +++ b/modules/i3plus-pojo-aps/src/main/resources/relations/Operation.xml @@ -1,5 +1,7 @@ + + diff --git a/modules/i3plus-pojo-aps/src/main/resources/relations/StandOperation.xml b/modules/i3plus-pojo-aps/src/main/resources/relations/StandOperation.xml index 5c82b55..ead1a31 100644 --- a/modules/i3plus-pojo-aps/src/main/resources/relations/StandOperation.xml +++ b/modules/i3plus-pojo-aps/src/main/resources/relations/StandOperation.xml @@ -1,5 +1,3 @@ - - \ No newline at end of file diff --git a/modules/i3plus-pojo-aps/src/main/resources/relations/Work.xml b/modules/i3plus-pojo-aps/src/main/resources/relations/Work.xml index 5bb1d26..3f8ab14 100644 --- a/modules/i3plus-pojo-aps/src/main/resources/relations/Work.xml +++ b/modules/i3plus-pojo-aps/src/main/resources/relations/Work.xml @@ -6,9 +6,9 @@ - + - + From 3e8bcbeb8450b4388610818de5151ea9eda0131c Mon Sep 17 00:00:00 2001 From: lbwgithub <你的邮箱1002117856@qq.com> Date: Thu, 10 Oct 2019 15:35:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../i3plus/pojo/base/jpa/dao/BaseRepository.java | 2 +- .../pojo/base/jpa/daoimpl/BaseRepositoryImpl.java | 35 ++++++++++++-------- .../estsh/i3plus/pojo/base/util/BeanMapUtils.java | 33 +++++++++++++++++++ .../i3plus/pojo/base/util/StringCastUtils.java | 38 ++++++++++++++++++++++ .../pojo/model/softswitch/BsSuitCaseModel.java | 1 - 5 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/util/BeanMapUtils.java create mode 100644 modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/util/StringCastUtils.java 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 72d4e0c..95d1c5a 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,7 +215,7 @@ public interface BaseRepository extends JpaReposito List findByProperty(String propertyName, Object value); - List findByWasProperty(String[] propertyNames, Object[] values); + List> findByWasProperty(String[] propertyNames, Object[] values); List findByProperty(String[] propertyNames, Object[] values); 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 92a320a..012951c 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 @@ -6,8 +6,12 @@ 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 cn.estsh.i3plus.pojo.base.util.BeanMapUtils; +import cn.estsh.i3plus.pojo.base.util.StringCastUtils; import org.apache.commons.lang3.StringUtils; import org.hibernate.NonUniqueResultException; +import org.hibernate.SQLQuery; +import org.hibernate.transform.Transformers; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.jpa.repository.support.SimpleJpaRepository; @@ -414,31 +418,34 @@ public class BaseRepositoryImpl extends SimpleJpaRep } @Override - public List findByWasProperty(String[] propertyNames, Object[] values) { + 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() + " "); - + queryString.append(" SELECT \n" + + " a.sn_status AS snStatus,\n" + + " a.wh_no AS whNo,\n" + + " a.locate_no AS locateNo,\n" + + " a.part_no AS partNo,\n" + + " a.part_name_rdd AS partNameRdd,\n" + + " a.lot_no AS lotNo,\n" + + " CAST(IFNULL(SUM(a.qty), 0) AS DOUBLE) AS qty \n" + + "FROM\n" + + " `wms_stock_sn` a "); 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()+"') "); + queryString.append("where 1=1 and a.sn_status 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]); + queryString.append(" and a." + StringCastUtils.upperCharToUnderLine(propertyNames[i]) + "= " + values[i]); } } - return queryObject.getResultList(); + queryString.append(" group by a.lot_no,a.date_code"); + return entityManager.createNativeQuery(queryString.toString()).unwrap(SQLQuery.class).setResultTransformer( + Transformers.ALIAS_TO_ENTITY_MAP).getResultList(); } @Override @@ -1559,4 +1566,6 @@ public class BaseRepositoryImpl extends SimpleJpaRep } return num; } + + } diff --git a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/util/BeanMapUtils.java b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/util/BeanMapUtils.java new file mode 100644 index 0000000..387ed78 --- /dev/null +++ b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/util/BeanMapUtils.java @@ -0,0 +1,33 @@ +package cn.estsh.i3plus.pojo.base.util; + +import org.springframework.cglib.beans.BeanMap; + +import java.util.HashMap; +import java.util.Map; + +public class BeanMapUtils { + /** + * 将对象属性转化为map结合 + */ + public static Map beanToMap(T bean) { + Map map = new HashMap<>(); + if (bean != null) { + BeanMap beanMap = BeanMap.create(bean); + for (Object key : beanMap.keySet()) { + map.put(key + "", beanMap.get(key)); + } + } + return map; + } + + /** + * 将map集合中的数据转化为指定对象的同名属性中 + */ + public static T mapToBean(Map map, Class clazz) throws Exception { + T bean = clazz.newInstance(); + BeanMap beanMap = BeanMap.create(bean); + beanMap.putAll(map); + return bean; + + } +} diff --git a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/util/StringCastUtils.java b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/util/StringCastUtils.java new file mode 100644 index 0000000..959c68d --- /dev/null +++ b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/util/StringCastUtils.java @@ -0,0 +1,38 @@ +package cn.estsh.i3plus.pojo.base.util; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 字符串转大写换成下滑线加小写 + */ +public class StringCastUtils { + + + + public static String upperCharToUnderLine(String param) { + Pattern p= Pattern.compile("[A-Z]"); + if(param==null ||param.equals("")){ + return ""; + } + StringBuilder builder=new StringBuilder(param); + Matcher mc=p.matcher(param); + int i=0; + while (mc.find()) { + System.out.println(builder.toString()); + System.out.println("mc.start():" + mc.start() + ", i: " + i); + System.out.println("mc.end():" + mc.start() + ", i: " + i); + builder.replace(mc.start()+i, mc.end()+i, "_"+mc.group().toLowerCase()); + i++; + } + if('_' == builder.charAt(0)){ + builder.deleteCharAt(0); + } + System.out.println(builder.toString()); + return builder.toString(); + } + + public static void main(String[] args) { + upperCharToUnderLine("snStatus"); + } +} diff --git a/modules/i3plus-pojo-model/src/main/java/cn/estsh/i3plus/pojo/model/softswitch/BsSuitCaseModel.java b/modules/i3plus-pojo-model/src/main/java/cn/estsh/i3plus/pojo/model/softswitch/BsSuitCaseModel.java index 7641cf5..0bb8f7c 100644 --- a/modules/i3plus-pojo-model/src/main/java/cn/estsh/i3plus/pojo/model/softswitch/BsSuitCaseModel.java +++ b/modules/i3plus-pojo-model/src/main/java/cn/estsh/i3plus/pojo/model/softswitch/BsSuitCaseModel.java @@ -5,7 +5,6 @@ import cn.estsh.i3plus.pojo.softswitch.bean.*; import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.annotations.ApiParam; import lombok.Data; -import org.springframework.beans.factory.annotation.Autowired; import java.io.Serializable;