FormFactory.java 4.7 KB
Newer Older
R
roo00 已提交
1 2 3 4 5 6 7 8 9 10
package com.x.cms.assemble.control.factory;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

R
fix  
roo00 已提交
11 12
import org.apache.commons.lang3.StringUtils;

R
roo00 已提交
13
import com.x.base.core.project.exception.ExceptionWhen;
R
roo00 已提交
14
import com.x.base.core.project.tools.ListTools;
R
roo00 已提交
15 16 17 18
import com.x.cms.assemble.control.AbstractFactory;
import com.x.cms.assemble.control.Business;
import com.x.cms.core.entity.element.Form;
import com.x.cms.core.entity.element.Form_;
R
roo00 已提交
19
import com.x.cms.core.entity.tools.CriteriaBuilderTools;
R
roo00 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

/**
 * 分类表单模板信息管理表基础功能服务类
 * 
 * @author O2LEE
 */
public class FormFactory extends AbstractFactory {

	public FormFactory( Business business ) throws Exception {
		super(business);
	}

	/**
	 * @param id
	 * @return Form
	 * @throws Exception
	 */
	//@MethodDescribe("获取指定Id的Form文件附件信息对象")
	public Form get( String id ) throws Exception {
		return this.entityManagerContainer().find( id, Form.class, ExceptionWhen.none );
	}
	
	/**
	 * @return List:String
	 * @throws Exception
	 */
	//@MethodDescribe("列示全部的Form文件附件信息ID列表")
	public List<String> listAll() throws Exception {
		EntityManager em = this.entityManagerContainer().get( Form.class );
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<String> cq = cb.createQuery(String.class);
		Root<Form> root = cq.from( Form.class );
		cq.select(root.get(Form_.id));
		return em.createQuery(cq).getResultList();
	}
	
	/**
	 * 
	 * @param ids 需要查询的ID列表
	 * @return List:Form
	 * @throws Exception
	 */
	//@MethodDescribe("列示指定Id的Form文件附件信息ID列表")
//	public List<Form> list(List<String> ids) throws Exception {
//		if(ListTools.isEmpty( ids )) {
//			return null;
//		}
//		EntityManager em = this.entityManagerContainer().get( Form.class );
//		CriteriaBuilder cb = em.getCriteriaBuilder();
//		CriteriaQuery<Form> cq = cb.createQuery( Form.class );
//		Root<Form> root = cq.from( Form.class );
//		Predicate p = root.get(Form_.id).in(ids);
//		return em.createQuery(cq.where(p)).getResultList();
//	}
	
	/**
	 * 列示指定应用的所有表单模板信息ID列表
	 * @param doucmentId 指定的文档ID
	 * @return
	 * @throws Exception 
	 */
	//@MethodDescribe("列示指定分类的所有表单模板信息ID列表")
	public List<String> listByAppId( String appId ) throws Exception {		
R
fix  
roo00 已提交
83
		if( StringUtils.isEmpty(appId) ){
R
roo00 已提交
84 85 86 87 88 89 90 91 92 93 94 95
			throw new Exception("内容管理listByAppId方法不接受appId为空的查询操作!");
		}
		EntityManager em = this.entityManagerContainer().get( Form.class );
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<String> cq = cb.createQuery(String.class);
		Root<Form> root = cq.from( Form.class );
		cq.select(root.get(Form_.id));
		Predicate p = cb.equal(root.get( Form_.appId ), appId);
		return em.createQuery(cq.where(p)).getResultList();
	}
	
	public List<Form> listFormByAppId( String appId ) throws Exception {		
R
fix  
roo00 已提交
96
		if( StringUtils.isEmpty(appId) ){
R
roo00 已提交
97 98 99 100 101 102 103 104 105
			throw new Exception("内容管理listByAppId方法不接受appId为空的查询操作!");
		}
		EntityManager em = this.entityManagerContainer().get( Form.class );
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<Form> cq = cb.createQuery(Form.class);
		Root<Form> root = cq.from( Form.class );
		Predicate p = cb.equal(root.get( Form_.appId ), appId);
		return em.createQuery(cq.where(p)).getResultList();
	}
R
roo00 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

	/**
	 * 根据栏目ID以及表单的标识 获取一个表单对象
	 * @param appId 栏目ID
	 * @param formFlag 表单标识
	 * @return
	 * @throws Exception
	 */
	public Form getWithAppInfo(String appId, String formFlag) throws Exception {
		if( StringUtils.isEmpty(appId) ){
			throw new Exception("appId can not empty!");
		}
		if( StringUtils.isEmpty(formFlag) ){
			throw new Exception("formFlag can not empty!");
		}
		EntityManager em = this.entityManagerContainer().get( Form.class );
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<Form> cq = cb.createQuery(Form.class);
		Root<Form> root = cq.from( Form.class );
		Predicate appPre = cb.equal( root.get( Form_.appId ), appId );
		Predicate p = CriteriaBuilderTools.predicate_or( cb, cb.equal( root.get( Form_.id ), formFlag ), cb.equal( root.get( Form_.name ), formFlag ) );
//		p = CriteriaBuilderTools.predicate_or( cb, cb.equal( root.get( Form_.alias ), formFlag ), p );				
		p = CriteriaBuilderTools.predicate_and( cb, appPre, p );
		List<Form> list = em.createQuery(cq.where(p)).getResultList();		
		return ListTools.isEmpty( list ) ? null : list.get( 0 );
	}
R
roo00 已提交
132
}