package com.x.okr.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.okr.assemble.control.AbstractFactory;
import com.x.okr.assemble.control.Business;
import com.x.okr.entity.OkrWorkChat;
import com.x.okr.entity.OkrWorkChat_;
/**
* 类 名:OkrWorkChatFactory
* 实体类:OkrWorkChat
* 作 者:Liyi
* 单 位:O2 Team
* 日 期:2016-05-20 17:17:27
**/
public class OkrWorkChatFactory extends AbstractFactory {
public OkrWorkChatFactory( Business business ) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的OkrWorkChat实体信息对象" )
public OkrWorkChat get( String id ) throws Exception {
return this.entityManagerContainer().find(id, OkrWorkChat.class, ExceptionWhen.none);
}
//@MethodDescribe( "列示全部的OkrWorkChat实体信息列表" )
public List listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(OkrWorkChat.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(String.class);
Root root = cq.from( OkrWorkChat.class);
cq.select(root.get(OkrWorkChat_.id));
return em.createQuery(cq).getResultList();
}
//@MethodDescribe( "列示指定Id的OkrWorkChat实体信息列表" )
public List list(List ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList();
}
EntityManager em = this.entityManagerContainer().get(OkrWorkChat.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(OkrWorkChat.class);
Root root = cq.from(OkrWorkChat.class);
Predicate p = root.get(OkrWorkChat_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据中心工作ID,列示所有的数据信息
* @param centerId 中心工作
* @return
* @throws Exception
*/
//@MethodDescribe( "根据中心工作ID,列示所有的信息" )
public List listByCenterWorkId(String centerId) throws Exception {
if( centerId == null || centerId.isEmpty() ){
throw new Exception( " centerId is null!" );
}
EntityManager em = this.entityManagerContainer().get( OkrWorkChat.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery< String > cq = cb.createQuery( String.class );
Root< OkrWorkChat > root = cq.from( OkrWorkChat.class );
Predicate p = cb.equal( root.get( OkrWorkChat_.centerId ), centerId );
cq.select( root.get( OkrWorkChat_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
/**
* 根据工作信息ID,列示所有的数据信息
* @param workId
* @return
* @throws Exception
*/
//@MethodDescribe( "根据工作信息ID,列示所有的数据信息" )
public List listByWorkId(String workId) throws Exception {
EntityManager em = this.entityManagerContainer().get( OkrWorkChat.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(String.class);
Root root = cq.from( OkrWorkChat.class);
Predicate p = cb.equal( root.get( OkrWorkChat_.workId ), workId );
cq.select(root.get( OkrWorkChat_.id) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 查询下一页的信息数据
* @param id
* @param count
* @param sequence
* @param wrapIn
* @return
* @throws Exception
*/
@SuppressWarnings( "unchecked" )
public List listNextWithFilter( String id, Integer count, Object sequence, String workId, String sequenceField, String order ) throws Exception {
//先获取上一页最后一条的sequence值,如果有值的话,以此sequence值作为依据取后续的count条数据
EntityManager em = this.entityManagerContainer().get( OkrWorkChat.class );
List