Merge branch 'dev' into test

yun-zuoyi
王杰 6 years ago
commit 18bc35f60d

@ -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 "";
}

@ -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")

@ -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")

@ -155,13 +155,13 @@ public class Work extends BaseCode {
}
@JsonBackReference
public List<WorkRelation> getWorkRelationInputs() {
return BeanRelation.list(this, EWork.WorkRelationInputs);
public List<WorkRelation> getPrevRelations() {
return BeanRelation.list(this, EWork.PrevRelations);
}
@JsonBackReference
public List<WorkRelation> getWorkRelationOutputs() {
return BeanRelation.list(this, EWork.WorkRelationOutputs);
public List<WorkRelation> getPostRelations() {
return BeanRelation.list(this, EWork.PostRelations);
}
@JsonBackReference

@ -117,6 +117,17 @@ public class BeanRelation {
return result;
}
public static <T extends BaseBean> List<T> listByClass(BaseBean bean, Class<T> cls, Enum<?> holder, Enum<?>... args) {
List<T> beans = new ArrayList<>();
List<BaseBean> nextBeans = list(bean, holder, args);
for (BaseBean nextBean : nextBeans) {
if (nextBean.getClass() == cls) {
beans.add((T)nextBean);
}
}
return beans;
}
private static <T extends BaseBean> void listImpl(List<T> result, BaseBean bean, Predicate<T> 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());

@ -6,8 +6,8 @@ public enum EWork {
WorkResources,
WorkInputs,
WorkOutputs,
WorkRelationInputs,
WorkRelationOutputs,
PrevRelations,
PostRelations,
Operation,
PlanFeedbacks
}

@ -4,8 +4,8 @@
</Relation>
<Relation field="Works" name="Work" reverse="Order" type="ONE_TO_MULTI" owner="true">
</Relation>
<Relation field="PrevRelations" name="WorkRelation" reverse="PrevOrder" type="ONE_TO_MULTI" owner="false">
<Relation field="PostRelations" name="WorkRelation" reverse="PrevOrder" type="ONE_TO_MULTI" owner="false">
</Relation>
<Relation field="PostRelations" name="WorkRelation" reverse="PostOrder" type="ONE_TO_MULTI" owner="false">
<Relation field="PrevRelations" name="WorkRelation" reverse="PostOrder" type="ONE_TO_MULTI" owner="false">
</Relation>
</Class>

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Class name="OperResource">
<Relation field="Resource" name="Resource" reverse="OperResources" type="MULTI_TO_ONE" owner="false">
<Relation field="Resource" name="Resource" type="MULTI_TO_ONE" owner="false">
</Relation>
</Class>

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Class name="Operation">
<Relation field="StandOperation" name="StandOperation" type="MULTI_TO_ONE" owner="false">
</Relation>
<Relation field="OperInputs" name="OperInput" reverse="Operation" type="ONE_TO_MULTI" owner="true">
</Relation>
<Relation field="OperOutputs" name="OperOutput" reverse="Operation" type="ONE_TO_MULTI" owner="true">

@ -1,5 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<Class name="StandOperation">
<Relation field="Operations" name="Operation" reverse="StandOperation" type="ONE_TO_MULTI" owner="false">
</Relation>
</Class>

@ -6,9 +6,9 @@
</Relation>
<Relation field="WORK_RESOURCES" name="WorkResource" reverse="Work" type="ONE_TO_MULTI" owner="true">
</Relation>
<Relation field="WorkRelationOutputs" name="WorkRelation" reverse="PrevWork" type="ONE_TO_MULTI" owner="false">
<Relation field="PostRelations" name="WorkRelation" reverse="PrevWork" type="ONE_TO_MULTI" owner="false">
</Relation>
<Relation field="WorkRelationInputs" name="WorkRelation" reverse="PostWork" type="ONE_TO_MULTI" owner="false">
<Relation field="PrevRelations" name="WorkRelation" reverse="PostWork" type="ONE_TO_MULTI" owner="false">
</Relation>
<Relation field="Operation" name="Operation" type="MULTI_TO_ONE" owner="false">
</Relation>

@ -215,6 +215,8 @@ public interface BaseRepository <T, ID extends Serializable> extends JpaReposito
List<T> findByProperty(String propertyName, Object value);
List<Map<String,Object>> findByWasProperty(String[] propertyNames, Object[] values);
List<T> findByProperty(String[] propertyNames, Object[] values);
List<T> findByProperty(String propertyName, Object value,String orderByStuff);

@ -3,10 +3,15 @@ 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 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;
@ -37,7 +42,7 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
private Class<T> persistentClass;
private SnowflakeIdMaker snowflakeIdMaker;
public BaseRepositoryImpl(Class<T> clz, EntityManager em,SnowflakeIdMaker snowflakeIdMaker) {
public BaseRepositoryImpl(Class<T> clz, EntityManager em, SnowflakeIdMaker snowflakeIdMaker) {
super(clz, em);
this.entityManager = em;
this.persistentClass = clz;
@ -83,7 +88,7 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
@Override
public T insert(T item) {
return insert(item,true);
return insert(item, true);
}
@Override
@ -94,7 +99,7 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
@Override
public <S extends T> S save(S entity) {
//复写save方法若id为0或空则新增不然则修改
return (S) innerSave(entity,true);
return (S) innerSave(entity, true);
}
@Override
@ -136,100 +141,101 @@ public class BaseRepositoryImpl<T, ID extends Serializable> 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
* trueeg price = :price
* falseeg price = price + :price
* @param propertyName
* @param propertyValue
* @param valWithSimple
* trueeg price = :price
* falseeg 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 +243,9 @@ public class BaseRepositoryImpl<T, ID extends Serializable> 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 +267,36 @@ public class BaseRepositoryImpl<T, ID extends Serializable> 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 +310,7 @@ public class BaseRepositoryImpl<T, ID extends Serializable> 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 +351,9 @@ public class BaseRepositoryImpl<T, ID extends Serializable> 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 +367,12 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
@Override
public List<T> 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<T>();
}
}
@ -379,16 +385,16 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
@Override
public List<T> 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 +418,37 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
}
@Override
public List<Map<String,Object>> 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 \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 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 a." + StringCastUtils.upperCharToUnderLine(propertyNames[i]) + "= " + values[i]);
}
}
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
public List<T> findByProperty(String[] propertyNames, Object[] values) {
if(propertyNames.length != values.length){
throw new IllegalArgumentException("参数名的数量和参数值不匹配!propertyNames:" + propertyNames.length + ",values:" + values.length);
@ -1529,4 +1566,6 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
}
return num;
}
}

@ -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 <T> Map<String, Object> beanToMap(T bean) {
Map<String, Object> 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> T mapToBean(Map<String, Object> map, Class<T> clazz) throws Exception {
T bean = clazz.newInstance();
BeanMap beanMap = BeanMap.create(bean);
beanMap.putAll(map);
return bean;
}
}

@ -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");
}
}

@ -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;

@ -298,4 +298,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;
}
}

Loading…
Cancel
Save