@ -2,9 +2,13 @@ package cn.estsh.i3plus.ext.mes.apiservice.daoimpl;
import cn.estsh.i3plus.ext.mes.apiservice.dao.IMesShippingOrderManagementDetailDao ;
import cn.estsh.i3plus.ext.mes.pojo.model.MesShippingOrderManagementDetailModel ;
import cn.estsh.i3plus.pojo.base.bean.ListPager ;
import cn.estsh.i3plus.pojo.base.common.Pager ;
import cn.estsh.i3plus.pojo.base.common.PagerHelper ;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil ;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesShippingOrderManagement ;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesShippingOrderManagementDetail ;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
@ -15,6 +19,7 @@ import javax.persistence.EntityManager;
import javax.persistence.Query ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.Objects ;
/ * *
* @Description : SAP 生 产 计 划
@ -98,4 +103,88 @@ public class MesShippingOrderManagementDetailDaoImpl implements IMesShippingOrde
return modelList ;
}
@Override
public ListPager < MesShippingOrderManagementDetailModel > queryMesShippingDetailsByPager ( MesShippingOrderManagementDetailModel mesShippingOrderManagementDetailModel , Pager pager ) {
StringBuilder dataHql = new StringBuilder ( ) ;
dataHql . append ( " select new " ) . append ( MesShippingOrderManagementDetailModel . class . getName ( ) ) . append ( "(m,d)" ) ;
//共用HQL
String commonHql = getCommonHql ( mesShippingOrderManagementDetailModel ) ;
//行数
Query countQuery = entityManager . createQuery ( "select count(1) " + commonHql ) ;
setParameter ( mesShippingOrderManagementDetailModel , countQuery ) ;
//数据
Query dataQuery = entityManager . createQuery ( dataHql . append ( commonHql ) . append ( getOrderBy ( mesShippingOrderManagementDetailModel ) ) . toString ( ) , MesShippingOrderManagementDetailModel . class ) ;
setParameter ( mesShippingOrderManagementDetailModel , dataQuery ) ;
if ( Objects . isNull ( pager ) ) return new ListPager < > ( dataQuery . getResultList ( ) , pager ) ;
int count = Integer . parseInt ( String . valueOf ( countQuery . getSingleResult ( ) ) ) ;
if ( count < = 0 ) return new ListPager < > ( new ArrayList < > ( ) , pager ) ;
pager = PagerHelper . getPager ( pager , count ) ;
dataQuery . setFirstResult ( pager . getStartRow ( ) ) . setMaxResults ( pager . getPageSize ( ) ) ;
return new ListPager < > ( dataQuery . getResultList ( ) , pager ) ;
}
private void setParameter ( MesShippingOrderManagementDetailModel mesShippingOrderManagementDetailModel , Query query ) {
query . setParameter ( "isValid" , CommonEnumUtil . TRUE_OR_FALSE . TRUE . getValue ( ) ) ;
query . setParameter ( "isDeleted" , CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) ) ;
query . setParameter ( "organizeCode" , mesShippingOrderManagementDetailModel . getOrganizeCode ( ) ) ;
query . setParameter ( "status" , MesExtEnumUtil . SHIPPING_ORDER_DETAIL_SHIPPING_STATUS . SHIPPINGED . getValue ( ) ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getShippingType ( ) ) )
query . setParameter ( "shippingType" , mesShippingOrderManagementDetailModel . getShippingType ( ) ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getStartScanTimeStart ( ) ) )
query . setParameter ( "startScanTimeStart" , mesShippingOrderManagementDetailModel . getStartScanTimeStart ( ) ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getStartScanTimeEnd ( ) ) )
query . setParameter ( "startScanTimeEnd" , mesShippingOrderManagementDetailModel . getStartScanTimeEnd ( ) ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getEndScanTimeStart ( ) ) )
query . setParameter ( "endScanTimeStart" , mesShippingOrderManagementDetailModel . getEndScanTimeStart ( ) ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getEndScanTimeEnd ( ) ) )
query . setParameter ( "endScanTimeEnd" , mesShippingOrderManagementDetailModel . getEndScanTimeEnd ( ) ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getPublishTimeStart ( ) ) )
query . setParameter ( "publishTimeStart" , mesShippingOrderManagementDetailModel . getPublishTimeStart ( ) ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getPublishTimeEnd ( ) ) )
query . setParameter ( "publishTimeEnd" , mesShippingOrderManagementDetailModel . getPublishTimeEnd ( ) ) ;
}
private String getOrderBy ( MesShippingOrderManagementDetailModel mesShippingOrderManagementDetailModel ) {
StringBuilder orderBy = new StringBuilder ( ) ;
if ( StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getOrderByParam ( ) ) | | StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getAscOrDesc ( ) ) ) {
mesShippingOrderManagementDetailModel . setOrderByParam ( "createDatetime" ) ;
mesShippingOrderManagementDetailModel . setAscOrDesc ( CommonEnumUtil . ASC_OR_DESC . DESC . getValue ( ) ) ;
}
return orderBy . append ( " order by d." ) . append ( mesShippingOrderManagementDetailModel . getOrderByParam ( ) ) . append ( " " ) . append ( CommonEnumUtil . ASC_OR_DESC . DESC . getValue ( ) = = mesShippingOrderManagementDetailModel . getAscOrDesc ( ) ? "desc" : "asc" ) . toString ( ) ;
}
private String getCommonHql ( MesShippingOrderManagementDetailModel mesShippingOrderManagementDetailModel ) {
StringBuilder commonHql = new StringBuilder ( ) ;
commonHql . append ( " from MesShippingOrderManagement m left join MesShippingOrderManagementDetail d on m.id = d.pid" ) ;
commonHql . append ( " where m.isDeleted=:isDeleted and m.isValid = :isValid and m.organizeCode = :organizeCode " ) ;
commonHql . append ( " and d.isDeleted=:isDeleted and d.isValid = :isValid and d.organizeCode = :organizeCode " ) ;
commonHql . append ( " and d.status = :status " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getShippingCode ( ) ) )
commonHql . append ( " and m.shippingCode like '%" ) . append ( mesShippingOrderManagementDetailModel . getShippingCode ( ) ) . append ( "%' " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getBarcode ( ) ) )
commonHql . append ( " and d.barcode like '%" ) . append ( mesShippingOrderManagementDetailModel . getBarcode ( ) ) . append ( "%' " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getPartNo ( ) ) )
commonHql . append ( " and d.partNo like '%" ) . append ( mesShippingOrderManagementDetailModel . getPartNo ( ) ) . append ( "%' " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getCustPartNo ( ) ) )
commonHql . append ( " and d.custPartNo like '%" ) . append ( mesShippingOrderManagementDetailModel . getCustPartNo ( ) ) . append ( "%' " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getShippingType ( ) ) )
commonHql . append ( " and m.shippingType = :shippingType " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getCustCode ( ) ) )
commonHql . append ( " and m.custCode like '%" ) . append ( mesShippingOrderManagementDetailModel . getCustCode ( ) ) . append ( "%' " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getStartScanTimeStart ( ) ) )
commonHql . append ( " and m.startScanTime >= :startScanTimeStart " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getStartScanTimeEnd ( ) ) )
commonHql . append ( " and m.startScanTime <= :startScanTimeEnd " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getEndScanTimeStart ( ) ) )
commonHql . append ( " and m.endScanTime >= :endScanTimeStart " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getEndScanTimeEnd ( ) ) )
commonHql . append ( " and m.endScanTime <= :endScanTimeEnd " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getPublishTimeStart ( ) ) )
commonHql . append ( " and m.publishTime >= :publishTimeStart " ) ;
if ( ! StringUtils . isEmpty ( mesShippingOrderManagementDetailModel . getPublishTimeEnd ( ) ) )
commonHql . append ( " and m.publishTime <= :publishTimeEnd " ) ;
return commonHql . toString ( ) ;
}
}