提交 25dc52ac 编写于 作者: O o2null

Merge branch 'fix/teamworkmove' into 'develop'

移动teamwork

See merge request o2oa/o2oa!1017
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
......@@ -20,7 +19,6 @@
<module>x_bbs_core_entity</module>
<module>x_calendar_core_entity</module>
<module>x_cms_core_entity</module>
<module>x_cms_core_express</module>
<module>x_component_core_entity</module>
<module>x_file_core_entity</module>
<module>x_general_core_entity</module>
......@@ -33,13 +31,13 @@
<module>x_organization_core_entity</module>
<module>x_portal_core_entity</module>
<module>x_processplatform_core_entity</module>
<module>x_teamwork_core_entity</module>
<module>x_program_center_core_entity</module>
<module>x_organization_core_express</module>
<module>x_query_core_express</module>
<module>x_processplatform_core_express</module>
<module>x_bbs_assemble_control</module>
<module>x_calendar_assemble_control</module>
<module>x_cms_core_express</module>
<module>x_cms_assemble_control</module>
<module>x_attendance_assemble_control</module>
<module>x_component_assemble_control</module>
......@@ -64,7 +62,6 @@
<module>x_query_assemble_designer</module>
<module>x_query_assemble_surface</module>
<module>x_query_service_processing</module>
<module>x_teamwork_assemble_control</module>
<module>x_program_center</module>
<module>x_console</module>
</modules>
......
package com.x.teamwork.assemble.control;
import com.x.base.core.container.EntityManagerContainer;
public abstract class AbstractFactory {
private Business business;
public AbstractFactory( Business business ) throws Exception {
try {
if ( null == business ) {
throw new Exception( "business can not be null. " );
}
this.business = business;
} catch ( Exception e ) {
throw new Exception( "can not instantiating factory." );
}
}
public EntityManagerContainer entityManagerContainer() throws Exception {
return this.business.entityManagerContainer();
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import com.x.base.core.project.Context;
@WebListener
public class ApplicationServletContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
ThisApplication.context = Context.concrete(servletContextEvent);
ThisApplication.init();
ThisApplication.context().regist();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
try {
ThisApplication.destroy();
ThisApplication.context.destrory(servletContextEvent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control;
import com.x.base.core.project.Context;
import com.x.base.core.project.message.MessageConnector;
import com.x.teamwork.assemble.control.queue.QueueBatchOperation;
import com.x.teamwork.assemble.control.service.SystemConfigPersistService;
import com.x.teamwork.assemble.control.timertask.Timertask_BatchOperationTask;
import com.x.teamwork.assemble.control.timertask.Timertask_CheckAllTaskOverTime;
import com.x.teamwork.assemble.control.timertask.Timertask_RefreshAllTaskReview;
public class ThisApplication {
protected static Context context;
public static QueueBatchOperation queueBatchOperation;
public static Context context() {
return context;
}
public static void init() {
try {
//执行消息操作
queueBatchOperation = new QueueBatchOperation();
MessageConnector.start(context());
context().startQueue( queueBatchOperation );
new SystemConfigPersistService().initSystemConfig();
//每隔5分钟检查是否有未完成的批处理工作需要完成以及是否有未review的task需要核对权限信息
context.schedule( Timertask_BatchOperationTask.class, "0 */2 * * * ?" );
//每天凌晨把所有项目的所有工作任务的权限和review信息核对一次
context.schedule( Timertask_RefreshAllTaskReview.class, "0 0 2 * * ?" );
//每30分钟核对一次所有的工作任务,判断工作任务是否已经超时
//context.schedule( Timertask_CheckAllTaskOverTime.class, "0 0/30 * * * ?" );
context.schedule( Timertask_CheckAllTaskOverTime.class, "0 */9 * * * ?" );
} catch (Exception e) {
e.printStackTrace();
}
}
public static void destroy() {
try {
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.x.teamwork.assemble.control.factory;
import java.util.ArrayList;
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;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.base.core.project.tools.ListTools;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.Attachment;
import com.x.teamwork.core.entity.Attachment_;
public class AttachmentFactory extends AbstractFactory {
public AttachmentFactory(Business business) throws Exception {
super(business);
}
public Attachment get( String id ) throws Exception {
return this.entityManagerContainer().find(id, Attachment.class, ExceptionWhen.none);
}
public List<String> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(Attachment.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Attachment> root = cq.from( Attachment.class);
cq.select(root.get(Attachment_.id));
return em.createQuery(cq).getResultList();
}
public List<Attachment> list(List<String> ids) throws Exception {
if( ListTools.isEmpty( ids ) ){
return new ArrayList<Attachment>();
}
EntityManager em = this.entityManagerContainer().get(Attachment.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Attachment> cq = cb.createQuery(Attachment.class);
Root<Attachment> root = cq.from(Attachment.class);
Predicate p = root.get(Attachment_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
public List<Attachment> listAttachmentWithProject(String project) throws Exception {
if( StringUtils.isEmpty( project ) ){
return new ArrayList<Attachment>();
}
EntityManager em = this.entityManagerContainer().get(Attachment.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Attachment> cq = cb.createQuery(Attachment.class);
Root<Attachment> root = cq.from(Attachment.class);
Predicate p = cb.equal( root.get(Attachment_.projectId), project );
p = cb.and( p, cb.equal( root.get(Attachment_.bundleObjType ), "PROJECT"));
return em.createQuery(cq.where(p)).getResultList();
}
public List<Attachment> listAttachmentWithTask(String taskId ) throws Exception {
if( StringUtils.isEmpty( taskId ) ){
return new ArrayList<Attachment>();
}
EntityManager em = this.entityManagerContainer().get(Attachment.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Attachment> cq = cb.createQuery(Attachment.class);
Root<Attachment> root = cq.from(Attachment.class);
Predicate p = cb.equal( root.get(Attachment_.taskId ), taskId );
p = cb.and( p, cb.equal( root.get(Attachment_.bundleObjType ), "TASK"));
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.teamwork.assemble.control.factory;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.BatchOperation;
import com.x.teamwork.core.entity.BatchOperation_;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;
/**
* 批处理操作信息记录,比如需要级联删除大量的工作重新计算权限等
*/
public class BatchOperationFactory extends AbstractFactory {
public BatchOperationFactory(Business business) throws Exception {
super(business);
}
public List<BatchOperation> list( List<String> ids ) throws Exception {
EntityManager em = this.entityManagerContainer().get( BatchOperation.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BatchOperation> cq = cb.createQuery( BatchOperation.class );
Root<BatchOperation> root = cq.from( BatchOperation.class );
Predicate p = root.get( BatchOperation_.id).in( ids );
cq.orderBy( cb.asc( root.get( BatchOperation.createTime_FIELDNAME ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<BatchOperation> list(Integer maxCount) throws Exception {
EntityManager em = this.entityManagerContainer().get( BatchOperation.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BatchOperation> cq = cb.createQuery( BatchOperation.class );
Root<BatchOperation> root = cq.from( BatchOperation.class );
cq.orderBy( cb.asc( root.get( BatchOperation.createTime_FIELDNAME ) ) );
return em.createQuery(cq).setMaxResults(maxCount).getResultList();
}
public List<BatchOperation> listNotRun(Integer maxCount) throws Exception {
EntityManager em = this.entityManagerContainer().get( BatchOperation.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BatchOperation> cq = cb.createQuery( BatchOperation.class );
Root<BatchOperation> root = cq.from( BatchOperation.class );
Predicate p = cb.isFalse( root.get( BatchOperation_.isRunning ) );
cq.orderBy( cb.asc( root.get( BatchOperation.createTime_FIELDNAME ) ) );
return em.createQuery(cq.where(p)).setMaxResults(maxCount).getResultList();
}
}
\ No newline at end of file
package com.x.teamwork.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.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.Chat;
import com.x.teamwork.core.entity.ChatContent;
import com.x.teamwork.core.entity.Chat_;
import com.x.teamwork.core.entity.tools.CriteriaBuilderTools;
import com.x.teamwork.core.entity.tools.filter.QueryFilter;
public class ChatFactory extends AbstractFactory {
public ChatFactory( Business business ) throws Exception {
super(business);
}
/**
* 获取指定Id的Chat实体信息对象
* @param id
* @return
* @throws Exception
*/
public Chat get( String id ) throws Exception {
return this.entityManagerContainer().find( id, Chat.class, ExceptionWhen.none );
}
/**
* 根据ChatId获取LOB内容
* @param id
* @return
* @throws Exception
*/
public ChatContent getContent(String id) throws Exception {
return this.entityManagerContainer().find( id, ChatContent.class, ExceptionWhen.none );
}
/**
* 根据ChatId获取LOB内容
* @param id
* @return
* @throws Exception
*/
public String getContentString(String id) throws Exception {
ChatContent content = this.entityManagerContainer().find( id, ChatContent.class, ExceptionWhen.none );
if( content != null ) {
return content.getContent();
}
return null;
}
/**
* 根据条件查询符合条件的Chat数量
* @param personName
* @param unitNames
* @param groupNames
* @param queryFilter
* @return
* @throws Exception
*/
public Long countWithFilter( QueryFilter queryFilter) throws Exception {
EntityManager em = this.entityManagerContainer().get( Chat.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Chat> root = cq.from(Chat.class);
Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter( Chat_.class, cb, null, root, queryFilter );
cq.select(cb.count(root)).where(p);
return em.createQuery(cq).getSingleResult();
}
/**
* 根据条件查询符合条件的项目信息ID(查询前N条内存分页支持)
* @param personName
* @param unitNames
* @param groupNames
* @param queryFilter
* @return
* @throws Exception
*/
public List<Chat> listWithFilter( Integer maxCount, String orderField, String orderType, QueryFilter queryFilter ) throws Exception {
EntityManager em = this.entityManagerContainer().get( Chat.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Chat> cq = cb.createQuery(Chat.class);
Root<Chat> root = cq.from(Chat.class);
Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter( Chat_.class, cb, null, root, queryFilter );
Order orderWithField = CriteriaBuilderTools.getOrder(cb, root, Chat_.class, orderField, orderType);
if( orderWithField != null ){
cq.orderBy( orderWithField );
}
return em.createQuery(cq.where(p)).setMaxResults( maxCount).getResultList();
}
/**
* 根据条件查询符合条件的项目信息ID(根据sequnce分页支持)
* @param maxCount
* @param sequenceFieldValue
* @param orderField
* @param orderType
* @param queryFilter
* @return
* @throws Exception
*/
public List<Chat> listWithFilter( Integer maxCount, Object sequenceFieldValue, String orderField, String orderType, QueryFilter queryFilter ) throws Exception {
EntityManager em = this.entityManagerContainer().get( Chat.class );
return CriteriaBuilderTools.listNextWithCondition( em, Chat.class, Chat_.class, maxCount, queryFilter, sequenceFieldValue, orderField, orderType );
}
}
package com.x.teamwork.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.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.Dynamic;
import com.x.teamwork.core.entity.DynamicDetail;
import com.x.teamwork.core.entity.Dynamic_;
import com.x.teamwork.core.entity.tools.CriteriaBuilderTools;
import com.x.teamwork.core.entity.tools.filter.QueryFilter;
public class DynamicFactory extends AbstractFactory {
public DynamicFactory( Business business ) throws Exception {
super(business);
}
/**
* 获取指定Id的Dynamic实体信息对象
* @param id
* @return
* @throws Exception
*/
public Dynamic get( String id ) throws Exception {
return this.entityManagerContainer().find( id, Dynamic.class, ExceptionWhen.none );
}
public DynamicDetail getDetail(String flag) throws Exception {
return this.entityManagerContainer().find( flag, DynamicDetail.class, ExceptionWhen.none );
}
/**
* 根据过滤条件查询符合要求的项目信息数量
* @param queryFilter
* @return
* @throws Exception
*/
public Long countWithFilter( QueryFilter queryFilter) throws Exception {
EntityManager em = this.entityManagerContainer().get( Dynamic.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Dynamic> root = cq.from(Dynamic.class);
Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter( Dynamic_.class, cb, null, root, queryFilter );
cq.select(cb.count(root));
return em.createQuery(cq.where(p)).getSingleResult();
}
/**
* 根据条件查询符合条件的项目信息ID(查询前N条内存分页支持)
* @param maxCount
* @param orderField
* @param orderType
* @param queryFilter
* @return
* @throws Exception
*/
public List<Dynamic> listWithFilter( Integer maxCount, String orderField, String orderType, QueryFilter queryFilter ) throws Exception {
EntityManager em = this.entityManagerContainer().get( Dynamic.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Dynamic> cq = cb.createQuery(Dynamic.class);
Root<Dynamic> root = cq.from(Dynamic.class);
Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter( Dynamic_.class, cb, null, root, queryFilter );
Order orderWithField = CriteriaBuilderTools.getOrder(cb, root, Dynamic_.class, orderField, orderType);
if( orderWithField != null ){
cq.orderBy( orderWithField );
}
return em.createQuery(cq.where(p)).setMaxResults( maxCount).getResultList();
}
/**
* 根据条件查询符合条件的项目信息ID(根据sequnce分页支持)
* @param maxCount
* @param sequenceFieldValue
* @param orderField
* @param orderType
* @param queryFilter
* @return
* @throws Exception
*/
public List<Dynamic> listWithFilter( Integer maxCount, Object sequenceFieldValue, String orderField, String orderType, QueryFilter queryFilter ) throws Exception {
EntityManager em = this.entityManagerContainer().get( Dynamic.class );
return CriteriaBuilderTools.listNextWithCondition( em, Dynamic.class, Dynamic_.class, maxCount, queryFilter, sequenceFieldValue, orderField, orderType );
}
}
package com.x.teamwork.assemble.control.factory;
import java.util.ArrayList;
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;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.ProjectGroup;
import com.x.teamwork.core.entity.ProjectGroup_;
public class ProjectGroupFactory extends AbstractFactory {
public ProjectGroupFactory( Business business ) throws Exception {
super(business);
}
/**
* 获取指定Id的ProjectGroup实体信息对象
* @param id
* @return
* @throws Exception
*/
public ProjectGroup get( String id ) throws Exception {
return this.entityManagerContainer().find( id, ProjectGroup.class, ExceptionWhen.none );
}
/**
* 列示指定Id的ProjectGroup实体信息列表
* @param ids
* @return
* @throws Exception
*/
public List<ProjectGroup> list( List<String> ids ) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<ProjectGroup>();
}
EntityManager em = this.entityManagerContainer().get(ProjectGroup.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ProjectGroup> cq = cb.createQuery(ProjectGroup.class);
Root<ProjectGroup> root = cq.from(ProjectGroup.class);
Predicate p = root.get(ProjectGroup_.id).in(ids);
cq.orderBy( cb.desc( root.get( ProjectGroup_.updateTime ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据用户列示ProjectGroup实体信息列表
* @param person
* @return
* @throws Exception
*/
public List<String> listByPerson( String person ) throws Exception {
if( StringUtils.isEmpty( person ) ){
throw new Exception("person can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(ProjectGroup.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<ProjectGroup> root = cq.from(ProjectGroup.class);
Predicate p = cb.equal( root.get(ProjectGroup_.owner), person );
cq.select( root.get(ProjectGroup_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据用户列示ProjectGroup实体信息列表
* @param person
* @return
* @throws Exception
*/
public List<ProjectGroup> listGroupByPerson( String person ) throws Exception {
if( StringUtils.isEmpty( person ) ){
throw new Exception("person can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(ProjectGroup.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ProjectGroup> cq = cb.createQuery(ProjectGroup.class);
Root<ProjectGroup> root = cq.from(ProjectGroup.class);
Predicate p = cb.equal( root.get(ProjectGroup_.owner), person );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.teamwork.assemble.control.factory;
import java.util.ArrayList;
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;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.ProjectGroupRele;
import com.x.teamwork.core.entity.ProjectGroupRele_;
public class ProjectGroupReleFactory extends AbstractFactory {
public ProjectGroupReleFactory( Business business ) throws Exception {
super(business);
}
/**
* 获取指定Id的ProjectGroupRele实体信息对象
* @param id
* @return
* @throws Exception
*/
public ProjectGroupRele get( String id ) throws Exception {
return this.entityManagerContainer().find( id, ProjectGroupRele.class, ExceptionWhen.none );
}
/**
* 列示指定Id的ProjectGroupRele实体信息列表
* @param ids
* @return
* @throws Exception
*/
public List<ProjectGroupRele> list( List<String> ids ) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<ProjectGroupRele>();
}
EntityManager em = this.entityManagerContainer().get(ProjectGroupRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ProjectGroupRele> cq = cb.createQuery(ProjectGroupRele.class);
Root<ProjectGroupRele> root = cq.from(ProjectGroupRele.class);
Predicate p = root.get(ProjectGroupRele_.id).in(ids);
cq.orderBy( cb.desc( root.get( ProjectGroupRele_.updateTime ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据项目组ID列示项目ID信息列表
* @param group
* @return
* @throws Exception
*/
public List<String> listProjectIdByGroup( String group ) throws Exception {
if( StringUtils.isEmpty( group ) ){
throw new Exception("group can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(ProjectGroupRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<ProjectGroupRele> root = cq.from(ProjectGroupRele.class);
Predicate p = cb.equal( root.get(ProjectGroupRele_.groupId), group );
cq.select( root.get(ProjectGroupRele_.projectId) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据项目组ID列示关联信息ID列表
* @param group
* @return
* @throws Exception
*/
public List<String> listByGroup( String group ) throws Exception {
if( StringUtils.isEmpty( group ) ){
throw new Exception("group can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(ProjectGroupRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<ProjectGroupRele> root = cq.from(ProjectGroupRele.class);
Predicate p = cb.equal( root.get(ProjectGroupRele_.groupId), group );
cq.select( root.get(ProjectGroupRele_.id) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据项目组ID以及项目ID获取一个关联信息
* @param group
* @param project
* @return
* @throws Exception
*/
public List<ProjectGroupRele> listWithGroupAndProject( String group, String project ) throws Exception {
if( StringUtils.isEmpty( group ) ){
throw new Exception("group can not be empty!");
}
if( StringUtils.isEmpty( project ) ){
throw new Exception("project can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(ProjectGroupRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ProjectGroupRele> cq = cb.createQuery(ProjectGroupRele.class);
Root<ProjectGroupRele> root = cq.from(ProjectGroupRele.class);
Predicate p = cb.equal( root.get(ProjectGroupRele_.groupId), group );
p = cb.and( p, cb.equal( root.get(ProjectGroupRele_.projectId), project ));
return em.createQuery(cq.where(p)).getResultList();
}
public List<ProjectGroupRele> listReleWithProject(String projectId) throws Exception {
if( StringUtils.isEmpty( projectId ) ){
throw new Exception("projectId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(ProjectGroupRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ProjectGroupRele> cq = cb.createQuery(ProjectGroupRele.class);
Root<ProjectGroupRele> root = cq.from(ProjectGroupRele.class);
Predicate p = cb.equal( root.get(ProjectGroupRele_.projectId), projectId );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.teamwork.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.tools.ListTools;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.Project;
import com.x.teamwork.core.entity.Project_;
import com.x.teamwork.core.entity.Review;
import com.x.teamwork.core.entity.Review_;
import com.x.teamwork.core.entity.tools.CriteriaBuilderTools;
import com.x.teamwork.core.entity.tools.filter.QueryFilter;
/**
* 工作任务权限控制信息服务类
*/
public class ReviewFactory extends AbstractFactory {
public ReviewFactory( Business business) throws Exception {
super(business);
}
public List<String> listReviewByTask( String taskId, Integer maxCount ) throws Exception {
if( maxCount == null ) {
maxCount = 1000;
}
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<Review> root = cq.from( Review.class );
Predicate p = cb.equal(root.get( Review_.taskId ), taskId );
cq.select( root.get( Review_.id) ).where(p);
return em.createQuery( cq ).setMaxResults(maxCount).getResultList();
}
public List<String> listTaskIdsWithPersonAndProject(String person, String project ) throws Exception {
if( StringUtils.isEmpty( person ) ) {
throw new Exception("person can not be empty!");
}
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<Review> root = cq.from( Review.class );
Predicate p = cb.equal( root.get( Review_.permissionObj ), person );
p = cb.and( p, cb.equal( root.get( Review_.project ), project ));
if(!this.getProject(project)){
p = cb.and( p, cb.equal( root.get( Review_.deleted ), false ));
}
cq.select(root.get( Review_.taskId)).where(p);
return em.createQuery( cq ).getResultList();
}
public List<String> listTaskIdsWithPersonAndProject( String project, String person, Integer maxCount ) throws Exception {
if( maxCount == null ) {
maxCount = 1000;
}
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<Review> root = cq.from( Review.class );
Predicate p = cb.equal(root.get( Review_.project ), project );
p = cb.and( p, cb.equal(root.get( Review_.permissionObj ), person ));
if(!this.getProject(project)){
p = cb.and( p, cb.equal( root.get( Review_.deleted ), false ));
}
cq.select( root.get( Review_.taskId) ).where(p);
return em.createQuery( cq ).setMaxResults(maxCount).getResultList();
}
public List<String> listPermissionByTask( String taskId, Integer maxCount ) throws Exception {
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<Review> root = cq.from( Review.class );
Predicate p = cb.equal(root.get( Review_.taskId ), taskId );
cq.select(root.get( Review_.permissionObj )).where(p);
return em.createQuery( cq ).setMaxResults(maxCount).getResultList();
}
public List<String> listIdsByTaskAndPerson(String taskId, String person) throws Exception {
if( StringUtils.isEmpty( taskId ) ) {
throw new Exception("task id can not be empty!");
}
if( StringUtils.isEmpty( person ) ) {
throw new Exception("person can not be empty!");
}
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<Review> root = cq.from( Review.class );
Predicate p = cb.equal(root.get( Review_.taskId ), taskId );
p = cb.and( p, cb.equal( root.get( Review_.permissionObj ), person));
cq.select(root.get( Review_.id)).where(p);
return em.createQuery( cq ).getResultList();
}
public List<Review> listByTaskAndPerson(String taskId, String person) throws Exception {
if( StringUtils.isEmpty( taskId ) ) {
throw new Exception("task id can not be empty!");
}
if( StringUtils.isEmpty( person ) ) {
throw new Exception("person can not be empty!");
}
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Review> cq = cb.createQuery( Review.class );
Root<Review> root = cq.from( Review.class );
Predicate p = cb.equal(root.get( Review_.taskId ), taskId );
p = cb.and( p, cb.equal( root.get( Review_.permissionObj ), person));
return em.createQuery( cq.where(p) ).getResultList();
}
public Long countByTask(String taskId) throws Exception {
if( StringUtils.isEmpty( taskId ) ) {
throw new Exception("task id can not be empty!");
}
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Review> root = cq.from(Review.class);
Predicate p = cb.equal( root.get(Review_.taskId), taskId );
cq.select(cb.count(root)).where(p);
return em.createQuery(cq).getSingleResult();
}
public Long countWithFilter(String personName, QueryFilter queryFilter) throws Exception {
if( StringUtils.isEmpty( personName ) ) {
return 0L;
}
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Review> root = cq.from(Review.class);
Predicate p_permission = cb.equal( root.get(Review_.permissionObj), personName );
Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter( Review_.class, cb, p_permission, root, queryFilter );
cq.select(cb.count(root)).where(p);
return em.createQuery(cq).getSingleResult();
}
public List<Review> listWithFilter( Integer maxCount, String orderField, String orderType, String personName, QueryFilter queryFilter) throws Exception {
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Review> cq = cb.createQuery(Review.class);
Root<Review> root = cq.from(Review.class);
Predicate p_permission = null;
if( StringUtils.isNotEmpty( personName )) {
p_permission = CriteriaBuilderTools.predicate_or( cb, p_permission, cb.equal( root.get( Review_.permissionObj ), personName ));
}
Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter( Review_.class, cb, p_permission, root, queryFilter );
//排序,添加排序列,默认使用sequence
List<Order> orders = new ArrayList<>();
Order orderWithField = CriteriaBuilderTools.getOrder( cb, root, Review_.class, orderField, orderType );
if( orderWithField != null ){
orders.add( orderWithField );
}
if( !Review.taskSequence_FIELDNAME.equalsIgnoreCase( orderField )) {
//如果是其他的列,很可能排序值不唯一,所以使用多一列排序列来确定每次查询的顺序
orderWithField = CriteriaBuilderTools.getOrder( cb, root, Review_.class, Review.id_FIELDNAME, orderType );
if( orderWithField != null ){
orders.add( orderWithField );
}
}
if( ListTools.isNotEmpty( orders )){
cq.orderBy( orders );
}
return em.createQuery(cq.where(p)).setMaxResults( maxCount).getResultList();
}
public List<String> checkTaskIdsWithPermission(List<String> taskIds, String personName) throws Exception {
if( ListTools.isEmpty( taskIds ) ) {
throw new Exception("taskIds can not be empty!");
}
if( StringUtils.isEmpty( personName ) ) {
throw new Exception("personName can not be empty!");
}
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<Review> root = cq.from( Review.class );
Predicate p = cb.equal( root.get( Review_.permissionObj ), personName );
p = cb.and( p, root.get( Review_.taskId ).in( taskIds ));
p = cb.and( p, cb.equal( root.get( Review_.deleted ), false ));
cq.select(root.get( Review_.taskId)).where(p);
return em.createQuery( cq ).getResultList();
}
public List<Review> listTaskWithPersonAndParentId(String person, String taskId) throws Exception {
if( StringUtils.isEmpty( person ) ) {
throw new Exception("person can not be empty!");
}
if( StringUtils.isEmpty( taskId ) ) {
throw new Exception("taskId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get( Review.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Review> cq = cb.createQuery( Review.class );
Root<Review> root = cq.from( Review.class );
Predicate p = cb.equal( root.get( Review_.permissionObj ), person );
p = cb.and( p, cb.equal( root.get( Review_.parent ), taskId ));
p = cb.and( p, cb.equal( root.get( Review_.deleted ), false ));
return em.createQuery( cq.where(p) ).getResultList();
}
public Boolean getProject(String project) throws Exception {
if( StringUtils.isEmpty( project ) ) {
throw new Exception("project id can not be empty!");
}
EntityManager em = this.entityManagerContainer().get( Project.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Boolean> cq = cb.createQuery(Boolean.class);
Root<Project> root = cq.from(Project.class);
Predicate p = cb.equal( root.get(Project_.id), project );
cq.select(root.get( Project_.deleted)).where(p);
return em.createQuery(cq).getSingleResult();
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.factory;
import java.util.ArrayList;
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;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.SystemConfig;
import com.x.teamwork.core.entity.SystemConfig_;
public class SystemConfigFactory extends AbstractFactory {
public SystemConfigFactory( Business business) throws Exception {
super(business);
}
public SystemConfig get( String id ) throws Exception {
return this.entityManagerContainer().find(id, SystemConfig.class, ExceptionWhen.none);
}
public List<SystemConfig> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(SystemConfig.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SystemConfig> cq = cb.createQuery(SystemConfig.class);
@SuppressWarnings("unused")
Root<SystemConfig> root = cq.from( SystemConfig.class);
return em.createQuery(cq).getResultList();
}
public List<SystemConfig> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<SystemConfig>();
}
EntityManager em = this.entityManagerContainer().get(SystemConfig.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SystemConfig> cq = cb.createQuery(SystemConfig.class);
Root<SystemConfig> root = cq.from(SystemConfig.class);
Predicate p = root.get( SystemConfig_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listIdsByCode(String code) throws Exception {
if( code == null || code.isEmpty() ){
return null;
}
EntityManager em = this.entityManagerContainer().get(SystemConfig.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<SystemConfig> root = cq.from(SystemConfig.class);
Predicate p = cb.equal(root.get(SystemConfig_.configCode), code);
cq.select(root.get(SystemConfig_.id));
return em.createQuery(cq.where(p)).getResultList();
}
public SystemConfig getWithConfigCode( String configCode ) throws Exception {
if( configCode == null || configCode.isEmpty() ){
return null;
}
SystemConfig attendanceSetting = null;
List<SystemConfig> settingList = null;
EntityManager em = this.entityManagerContainer().get(SystemConfig.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SystemConfig> cq = cb.createQuery(SystemConfig.class);
Root<SystemConfig> root = cq.from(SystemConfig.class);
Predicate p = cb.equal(root.get( SystemConfig_.configCode ), configCode );
settingList = em.createQuery(cq.where(p)).getResultList();
if( settingList != null && settingList.size() > 0 ){
attendanceSetting = settingList.get(0);
}
return attendanceSetting;
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.factory;
import java.util.ArrayList;
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;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.Task;
import com.x.teamwork.core.entity.TaskDetail;
import com.x.teamwork.core.entity.Task_;
public class TaskFactory extends AbstractFactory {
public TaskFactory( Business business ) throws Exception {
super(business);
}
/**
* 获取指定Id的Task实体信息对象
* @param id
* @return
* @throws Exception
*/
public Task get( String id ) throws Exception {
return this.entityManagerContainer().find( id, Task.class, ExceptionWhen.none );
}
/**
* 获取指定Id的TaskDetail实体信息对象
* @param id
* @return
* @throws Exception
*/
public TaskDetail getDetail( String id ) throws Exception {
return this.entityManagerContainer().find( id, TaskDetail.class, ExceptionWhen.none );
}
/**
* 列示指定Id的Task实体信息列表
* @param ids
* @return
* @throws Exception
*/
public List<Task> list( List<String> ids ) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<Task>();
}
EntityManager em = this.entityManagerContainer().get(Task.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Task> cq = cb.createQuery(Task.class);
Root<Task> root = cq.from(Task.class);
Predicate p = root.get(Task_.id).in(ids);
cq.orderBy( cb.asc( root.get( Task_.createTime ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据类别列示Task实体ID信息列表
* @param application
* @return
* @throws Exception
*/
public List<String> listByProject( String projectId ) throws Exception {
if( StringUtils.isEmpty( projectId ) ){
throw new Exception("projectId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(Task.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Task> root = cq.from(Task.class);
Predicate p = cb.equal( root.get(Task_.project), projectId );
cq.select( root.get(Task_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 查询未review的工作任务信息
* @param maxCount
* @return
* @throws Exception
*/
public List<Task> listUnReviewTask(int maxCount) throws Exception {
if( maxCount == 0 ){
maxCount = 100;
}
EntityManager em = this.entityManagerContainer().get(Task.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Task> cq = cb.createQuery(Task.class);
Root<Task> root = cq.from(Task.class);
Predicate p = cb.or( cb.isNull(root.get(Task_.reviewed )), cb.isFalse( root.get(Task_.reviewed )));
cq.orderBy( cb.asc( root.get( Task_.updateTime ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据类别列示Task实体信息列表
* @param application
* @return
* @throws Exception
*/
public List<String> listByParent( String pid) throws Exception {
if( StringUtils.isEmpty( pid ) ){
throw new Exception("projectId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(Task.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Task> root = cq.from(Task.class);
Predicate p = cb.equal( root.get(Task_.parent), pid );
cq.select( root.get(Task_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据条件查询符合条件的项目信息数量
* @param projectId
* @return
* @throws Exception
*/
public Long countWithProject( String projectId ) throws Exception {
EntityManager em = this.entityManagerContainer().get( Task.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Task> root = cq.from(Task.class);
Predicate p = cb.equal( root.get( Task_.project), projectId );
cq.select(cb.count(root)).where(p);
return em.createQuery(cq).getSingleResult();
}
public List<Task> allUnCompletedSubTasks(String taskId) throws Exception {
if( StringUtils.isEmpty( taskId ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get(Task.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Task> cq = cb.createQuery(Task.class);
Root<Task> root = cq.from(Task.class);
Predicate p = cb.equal( root.get( Task_.parent ), taskId );
p = cb.and( p, cb.isFalse( root.get(Task_.completed )));
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listAllTaskIdsWithProject(String project) throws Exception {
if( StringUtils.isEmpty( project ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get(Task.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Task> root = cq.from(Task.class);
Predicate p = cb.equal( root.get( Task_.project ), project );
cq.select( root.get(Task_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.teamwork.assemble.control.factory;
import java.util.ArrayList;
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;
import org.apache.commons.lang3.StringUtils;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.TaskGroup;
import com.x.teamwork.core.entity.TaskGroup_;
public class TaskGroupFactory extends AbstractFactory {
public TaskGroupFactory( Business business ) throws Exception {
super(business);
}
/**
* 获取指定Id的TaskGroup实体信息对象
* @param id
* @return
* @throws Exception
*/
public TaskGroup get( String id ) throws Exception {
return this.entityManagerContainer().find( id, TaskGroup.class );
}
/**
* 列示指定Id的TaskGroup实体信息列表
* @param ids
* @return
* @throws Exception
*/
public List<TaskGroup> list( List<String> ids ) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<TaskGroup>();
}
EntityManager em = this.entityManagerContainer().get(TaskGroup.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskGroup> cq = cb.createQuery(TaskGroup.class);
Root<TaskGroup> root = cq.from(TaskGroup.class);
Predicate p = root.get(TaskGroup_.id).in(ids);
cq.orderBy( cb.desc( root.get( TaskGroup_.updateTime ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据用户列示TaskGroup实体信息列表
* @param person
* @return
* @throws Exception
*/
public List<String> listByPerson( String person ) throws Exception {
if( StringUtils.isEmpty( person ) ){
throw new Exception("person can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskGroup.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskGroup> root = cq.from(TaskGroup.class);
Predicate p = cb.equal( root.get(TaskGroup_.owner), person );
cq.select( root.get(TaskGroup_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据用户列示TaskGroup实体信息列表
* @param person
* @return
* @throws Exception
*/
public List<TaskGroup> listGroupByPerson( String person ) throws Exception {
if( StringUtils.isEmpty( person ) ){
throw new Exception("person can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskGroup.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskGroup> cq = cb.createQuery(TaskGroup.class);
Root<TaskGroup> root = cq.from(TaskGroup.class);
Predicate p = cb.equal( root.get(TaskGroup_.owner), person );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据用户和项目列示TaskGroup实体信息ID列表
* @param person
* @param project
* @return
* @throws Exception
*/
public List<String> listByPersonAndProject( String person, String project ) throws Exception {
if( StringUtils.isEmpty( person ) ){
throw new Exception("person can not be empty!");
}
if( StringUtils.isEmpty( project ) ){
throw new Exception("project can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskGroup.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskGroup> root = cq.from(TaskGroup.class);
Predicate p = cb.equal( root.get(TaskGroup_.owner), person );
p = cb.and( p, cb.equal( root.get(TaskGroup_.project), project ) );
cq.select( root.get(TaskGroup_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据用户和项目列示TaskGroup实体信息列表
* @param person
* @param project
* @return
* @throws Exception
*/
public List<TaskGroup> listGroupByPersonAndProject( String person, String project ) throws Exception {
if( StringUtils.isEmpty( person ) ){
throw new Exception("person can not be empty!");
}
if( StringUtils.isEmpty( project ) ){
throw new Exception("project can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskGroup.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskGroup> cq = cb.createQuery(TaskGroup.class);
Root<TaskGroup> root = cq.from(TaskGroup.class);
Predicate p = cb.equal( root.get(TaskGroup_.owner), person );
p = cb.and( p, cb.equal( root.get(TaskGroup_.project), project ) );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.teamwork.assemble.control.factory;
import java.util.ArrayList;
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;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.TaskGroupRele;
import com.x.teamwork.core.entity.TaskGroupRele_;
public class TaskGroupReleFactory extends AbstractFactory {
public TaskGroupReleFactory( Business business ) throws Exception {
super(business);
}
/**
* 获取指定Id的TaskGroupRele实体信息对象
* @param id
* @return
* @throws Exception
*/
public TaskGroupRele get( String id ) throws Exception {
return this.entityManagerContainer().find( id, TaskGroupRele.class, ExceptionWhen.none );
}
/**
* 列示指定Id的TaskGroupRele实体信息列表
* @param ids
* @return
* @throws Exception
*/
public List<TaskGroupRele> list( List<String> ids ) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<TaskGroupRele>();
}
EntityManager em = this.entityManagerContainer().get(TaskGroupRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskGroupRele> cq = cb.createQuery(TaskGroupRele.class);
Root<TaskGroupRele> root = cq.from(TaskGroupRele.class);
Predicate p = root.get(TaskGroupRele_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据项目组ID列示项目ID信息列表
* @param group
* @return
* @throws Exception
*/
public List<String> listTaskIdByGroup( String group ) throws Exception {
if( StringUtils.isEmpty( group ) ){
throw new Exception("group can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskGroupRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskGroupRele> root = cq.from(TaskGroupRele.class);
Predicate p = cb.equal( root.get(TaskGroupRele_.taskGroupId), group );
cq.select( root.get(TaskGroupRele_.taskId ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据项目组ID列示关联信息ID列表
* @param group
* @return
* @throws Exception
*/
public List<String> listByGroup( String group ) throws Exception {
if( StringUtils.isEmpty( group ) ){
throw new Exception("group can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskGroupRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskGroupRele> root = cq.from(TaskGroupRele.class);
Predicate p = cb.equal( root.get(TaskGroupRele_.taskGroupId), group );
cq.select( root.get(TaskGroupRele_.id) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据项目组ID以及项目ID获取一个关联信息
* @param group
* @param project
* @return
* @throws Exception
*/
public List<TaskGroupRele> listWithGroupAndTask( String group, String taskId ) throws Exception {
if( StringUtils.isEmpty( group ) ){
throw new Exception("group can not be empty!");
}
if( StringUtils.isEmpty( taskId ) ){
throw new Exception("taskId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskGroupRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskGroupRele> cq = cb.createQuery(TaskGroupRele.class);
Root<TaskGroupRele> root = cq.from(TaskGroupRele.class);
Predicate p = cb.equal( root.get(TaskGroupRele_.taskGroupId), group );
p = cb.and( p, cb.equal( root.get(TaskGroupRele_.taskId), taskId ));
return em.createQuery(cq.where(p)).getResultList();
}
public List<TaskGroupRele> listTaskReleWithProject(String projectId ) throws Exception {
if( StringUtils.isEmpty( projectId ) ){
throw new Exception("projectId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskGroupRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskGroupRele> cq = cb.createQuery(TaskGroupRele.class);
Root<TaskGroupRele> root = cq.from(TaskGroupRele.class);
Predicate p = cb.equal( root.get(TaskGroupRele_.project), projectId );
return em.createQuery(cq.where(p)).getResultList();
}
public List<TaskGroupRele> listTaskReleWithTask(String taskId ) throws Exception {
if( StringUtils.isEmpty( taskId ) ){
throw new Exception("taskId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskGroupRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskGroupRele> cq = cb.createQuery(TaskGroupRele.class);
Root<TaskGroupRele> root = cq.from(TaskGroupRele.class);
Predicate p = cb.equal( root.get(TaskGroupRele_.taskId), taskId );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.teamwork.assemble.control.factory;
import java.util.ArrayList;
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;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.base.core.project.tools.ListTools;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.TaskList;
import com.x.teamwork.core.entity.TaskListRele;
import com.x.teamwork.core.entity.TaskListRele_;
import com.x.teamwork.core.entity.TaskList_;
public class TaskListFactory extends AbstractFactory {
public TaskListFactory( Business business ) throws Exception {
super(business);
}
/**
* 获取指定Id的TaskList实体信息对象
* @param id
* @return
* @throws Exception
*/
public TaskList get( String id ) throws Exception {
return this.entityManagerContainer().find( id, TaskList.class, ExceptionWhen.none );
}
/**
* 列示指定Id的TaskList实体信息列表
* @param ids
* @return
* @throws Exception
*/
public List<TaskList> list( List<String> ids ) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<TaskList>();
}
EntityManager em = this.entityManagerContainer().get(TaskList.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskList> cq = cb.createQuery(TaskList.class);
Root<TaskList> root = cq.from(TaskList.class);
Predicate p = root.get(TaskList_.id).in(ids);
cq.orderBy( cb.desc( root.get( TaskList_.updateTime ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 列示指定Id的TaskList实体信息列表
* @param ids
* @return
* @throws Exception
*/
public List<TaskListRele> listRele( List<String> ids ) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<TaskListRele>();
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskListRele> cq = cb.createQuery(TaskListRele.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = root.get(TaskListRele_.id).in(ids);
cq.orderBy( cb.desc( root.get( TaskListRele_.updateTime ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据用户和项目ID查询工作任务列表(泳道)
* @param person
* @param projectId
* @return
* @throws Exception
*/
public List<TaskList> listWithPersonAndProject( String person, String projectId ) throws Exception {
if( StringUtils.isEmpty( person ) ){
throw new Exception("person can not be empty!");
}
if( StringUtils.isEmpty( projectId ) ){
throw new Exception("projectId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskList.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskList> cq = cb.createQuery(TaskList.class);
Root<TaskList> root = cq.from(TaskList.class);
Predicate p = cb.equal( root.get(TaskList_.owner ), person );
p = cb.and( p, cb.equal( root.get(TaskList_.project), projectId ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据列表ID获取所有的工作任务关联ID列表
* @param listId
* @return
* @throws Exception
*/
public List<String> listReleIdsWithListId(String listId ) throws Exception {
if( StringUtils.isEmpty( listId ) ){
throw new Exception("listId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskListId), listId );
cq.select( root.get(TaskListRele_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据列表ID获取所有的工作任务关联信息列表
* @param listId
* @return
* @throws Exception
*/
public List<TaskListRele> listReleWithListId( String listId ) throws Exception {
if( StringUtils.isEmpty( listId ) ){
throw new Exception("listId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskListRele> cq = cb.createQuery(TaskListRele.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskListId), listId );
cq.orderBy( cb.asc( root.get( TaskListRele_.order ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据任务ID和列表ID查询工作列表关联对象
* @param taskId
* @param listId
* @return
* @throws Exception
*/
public List<TaskListRele> listReleWithTaskAndList(String taskId, String listId) throws Exception {
if( StringUtils.isEmpty( taskId ) ){
throw new Exception("taskId can not be empty!");
}
if( StringUtils.isEmpty( listId ) ){
throw new Exception("listId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskListRele> cq = cb.createQuery(TaskListRele.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskId), taskId );
p = cb.and( p, cb.equal( root.get(TaskListRele_.taskListId), listId ));
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据任务ID查询工作列表关联对象
* @param taskId
* @return
* @throws Exception
*/
public List<TaskListRele> listReleWithTask(String taskId ) throws Exception {
if( StringUtils.isEmpty( taskId ) ){
throw new Exception("taskId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskListRele> cq = cb.createQuery(TaskListRele.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskId), taskId );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据任务ID查询工作列表关联对象
* @param taskId
* @return
* @throws Exception
*/
public List<String> listGroupIdsWithTask( String taskId ) throws Exception {
if( StringUtils.isEmpty( taskId ) ){
throw new Exception("taskId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskId), taskId );
cq.distinct(true).select( root.get(TaskListRele_.taskGroupId ) );
return em.createQuery(cq.where(p)).getResultList();
}
public Integer maxListOrder(String groupId ) throws Exception {
if( StringUtils.isEmpty( groupId ) ){
throw new Exception("groupId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskList.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Integer> cq = cb.createQuery(Integer.class);
Root<TaskList> root = cq.from(TaskList.class);
Predicate p = cb.equal( root.get(TaskList_.taskGroup ), groupId );
cq.select( cb.max( root.get( TaskList_.order )));
Integer max = em.createQuery(cq.where(p)).getSingleResult();
return max == null ? 0 : max;
}
public Integer maxTaskOrder(String listId) throws Exception {
if( StringUtils.isEmpty( listId ) ){
throw new Exception("listId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Integer> cq = cb.createQuery(Integer.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskListId), listId );
cq.select( cb.max( root.get( TaskListRele_.order )));
Integer max = em.createQuery(cq.where(p)).getSingleResult();
return max == null ? 0 : max;
}
public List<TaskList> listWithTaskGroup(String taskGroupId) throws Exception {
if( StringUtils.isEmpty( taskGroupId ) ){
throw new Exception("taskGroupId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskList.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskList> cq = cb.createQuery(TaskList.class);
Root<TaskList> root = cq.from(TaskList.class);
Predicate p = cb.equal( root.get(TaskList_.taskGroup ), taskGroupId );
cq.orderBy( cb.asc( root.get( TaskList_.order ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listTaskListIdsWithTaskGroup(String taskGroupId) throws Exception {
if( StringUtils.isEmpty( taskGroupId ) ){
throw new Exception("taskGroupId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskGroupId ), taskGroupId );
cq.select( root.get(TaskListRele_.taskListId ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listTaskIdsWithTaskGroupId(String taskGroupId) throws Exception {
if( StringUtils.isEmpty( taskGroupId ) ){
throw new Exception("taskGroupId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get( TaskListRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskGroupId ), taskGroupId );
cq.distinct(true).select( root.get(TaskListRele_.taskId ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listTaskIdsWithTaskGroupId( List<String> taskLists ) throws Exception {
if( ListTools.isEmpty( taskLists ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get( TaskListRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = root.get(TaskListRele_.taskListId ).in( taskLists );
cq.distinct(true).select( root.get(TaskListRele_.taskId ) );
return em.createQuery(cq.where(p)).getResultList();
}
public Long countTaskWithTaskListId(String taskListId) throws Exception {
EntityManager em = this.entityManagerContainer().get( TaskListRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskListId ), taskListId );
cq.select(cb.count(root)).where(p);
return em.createQuery(cq).getSingleResult();
}
public List<String> listTaskIdWithTaskListId(String taskListId) throws Exception {
if( StringUtils.isEmpty( taskListId ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get( TaskListRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskListId ), taskListId );
cq.select( root.get(TaskListRele_.taskId ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listTaskIdWithTaskListIds( List<String> taskListIds ) throws Exception {
if(ListTools.isEmpty( taskListIds ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get( TaskListRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = root.get(TaskListRele_.taskListId ).in( taskListIds );
cq.select( root.get(TaskListRele_.taskId ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listTaskIdWithTaskListId( List<String> taskListId) throws Exception {
if( ListTools.isEmpty( taskListId ) ){
throw new Exception("taskListId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get( TaskListRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = root.get(TaskListRele_.taskListId ).in( taskListId );
cq.select( root.get(TaskListRele_.taskId ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<TaskListRele> listReleWithTaskAndGroup( String taskId, String taskGroupId) throws Exception {
if( StringUtils.isEmpty( taskGroupId ) ){
throw new Exception("taskGroupId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskListRele> cq = cb.createQuery(TaskListRele.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskId ), taskId );
p = cb.and( p, cb.equal( root.get(TaskListRele_.taskGroupId ) , taskGroupId));
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listTaskListIdWithTaskAndGroup( String taskId, String taskGroupId ) throws Exception {
if( StringUtils.isEmpty( taskGroupId ) ){
throw new Exception("taskGroupId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskId ), taskId );
p = cb.and( p, cb.equal( root.get(TaskListRele_.taskGroupId ) , taskGroupId));
cq.select( root.get(TaskListRele_.taskListId) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<TaskListRele> listTaskListWithTask(String taskId, String taskGroupId ) throws Exception {
if( StringUtils.isEmpty( taskId ) ){
return null;
}
if( StringUtils.isEmpty( taskGroupId ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskListRele> cq = cb.createQuery(TaskListRele.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskId ), taskId );
p = cb.and( p, cb.equal( root.get(TaskListRele_.taskGroupId ), taskGroupId ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listTaskListIdWithTask(String taskId, String taskGroupId ) throws Exception {
if( StringUtils.isEmpty( taskId ) ){
return null;
}
if( StringUtils.isEmpty( taskGroupId ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskId ), taskId );
p = cb.and( p, cb.equal( root.get(TaskListRele_.taskGroupId ), taskGroupId ) );
cq.select( root.get(TaskListRele_.taskListId) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listTaskListIdsWithGroup(String taskGroupId, String person) throws Exception {
if( StringUtils.isEmpty( taskGroupId ) ){
return null;
}
if( StringUtils.isEmpty( person ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get(TaskList.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskList> root = cq.from(TaskList.class);
Predicate p = cb.equal( root.get( TaskList_.owner ), person );
p = cb.and( p, cb.equal( root.get( TaskList_.taskGroup ), taskGroupId ) );
cq.select( root.get(TaskList_.id) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<TaskListRele> listReleWithTaskAndListId(List<String> taskIds, String taskListId) throws Exception {
if( ListTools.isEmpty( taskIds ) ){
return null;
}
if( StringUtils.isEmpty( taskListId ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get(TaskListRele.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskListRele> cq = cb.createQuery(TaskListRele.class);
Root<TaskListRele> root = cq.from(TaskListRele.class);
Predicate p = cb.equal( root.get(TaskListRele_.taskListId ), taskListId );
p = cb.and( p, root.get(TaskListRele_.taskId ).in( taskIds ) );
cq.orderBy( cb.asc( root.get( TaskListRele_.order ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.teamwork.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;
import org.apache.commons.lang3.StringUtils;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.TaskTag;
import com.x.teamwork.core.entity.TaskTagRele;
import com.x.teamwork.core.entity.TaskTagRele_;
import com.x.teamwork.core.entity.TaskTag_;
import com.x.teamwork.core.entity.tools.CriteriaBuilderTools;
public class TaskTagFactory extends AbstractFactory {
public TaskTagFactory( Business business ) throws Exception {
super(business);
}
public List<String> listTagIdsWithTask(String taskId, String person) throws Exception {
EntityManager em = this.entityManagerContainer().get( TaskTagRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskTagRele> root = cq.from(TaskTagRele.class);
Predicate p = cb.equal( root.get( TaskTagRele_.taskId ), taskId );
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal( root.get( TaskTagRele_.owner ), person ) );
cq.select( root.get(TaskTagRele_.tagId) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据标签名称,项目ID,人员标识查询该标签在用户的项目标签中的标签ID,理论上只有一条记录
* @param tagName
* @param project
* @param distinguishedName
* @return
* @throws Exception
*/
public List<String> listTagIdsWithTagNameAndProjectAndPerson(String tagName, String project, String personName) throws Exception {
EntityManager em = this.entityManagerContainer().get( TaskTagRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskTag> root = cq.from(TaskTag.class);
Predicate p = cb.equal( root.get( TaskTag_.tag ), tagName );
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal( root.get( TaskTag_.owner ), personName ) );
if( StringUtils.isNotEmpty( project )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal( root.get( TaskTag_.project ), project ) );
}
cq.select( root.get(TaskTag_.id) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据标签ID、任务ID和人员名称查询标签与任务的关联信息
* @param tagId
* @param taskId
* @param personName
* @return
* @throws Exception
*/
public List<String> listTagReleIdsWithTagIdAndTaskAndPerson(String tagId, String taskId, String personName) throws Exception {
EntityManager em = this.entityManagerContainer().get( TaskTagRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskTagRele> root = cq.from(TaskTagRele.class);
Predicate p = cb.equal( root.get( TaskTagRele_.taskId ), taskId );
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal( root.get( TaskTagRele_.tagId ), tagId ) );
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal( root.get( TaskTagRele_.owner ), personName ) );
cq.select( root.get(TaskTagRele_.id) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<TaskTag> listWithProjectAndPerson( String project, String person ) throws Exception {
EntityManager em = this.entityManagerContainer().get( TaskTag.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskTag> cq = cb.createQuery(TaskTag.class);
Root<TaskTag> root = cq.from(TaskTag.class);
Predicate p = cb.equal( root.get( TaskTag_.project ), project );
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal( root.get( TaskTag_.owner ), person ) );
cq.orderBy( cb.asc( root.get( TaskTag_.createTime ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<TaskTagRele> listReleWithProjectAndPerson( String projectId, String person ) throws Exception {
EntityManager em = this.entityManagerContainer().get( TaskTagRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskTagRele> cq = cb.createQuery(TaskTagRele.class);
Root<TaskTagRele> root = cq.from(TaskTagRele.class);
Predicate p = cb.equal( root.get( TaskTagRele_.project ), projectId );
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal( root.get( TaskTagRele_.owner ), person ) );
cq.orderBy( cb.asc( root.get( TaskTagRele_.createTime ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<TaskTagRele> listReleWithTaskAndPerson( String taskId, String person ) throws Exception {
EntityManager em = this.entityManagerContainer().get( TaskTagRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskTagRele> cq = cb.createQuery(TaskTagRele.class);
Root<TaskTagRele> root = cq.from(TaskTagRele.class);
Predicate p = cb.equal( root.get( TaskTagRele_.taskId ), taskId );
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal( root.get( TaskTagRele_.owner ), person ) );
cq.orderBy( cb.asc( root.get( TaskTagRele_.createTime ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listTaskIdsWithReleTagIds(List<String> tagIds) throws Exception {
EntityManager em = this.entityManagerContainer().get( TaskTagRele.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<TaskTagRele> root = cq.from(TaskTagRele.class);
Predicate p = root.get( TaskTagRele_.tagId ).in( tagIds );
cq.select( root.get(TaskTagRele_.taskId) );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.teamwork.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Order;
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.base.core.project.tools.ListTools;
import com.x.teamwork.assemble.control.AbstractFactory;
import com.x.teamwork.assemble.control.Business;
import com.x.teamwork.core.entity.TaskView;
import com.x.teamwork.core.entity.TaskView_;
import com.x.teamwork.core.entity.tools.CriteriaBuilderTools;
import com.x.teamwork.core.entity.tools.filter.QueryFilter;
public class TaskViewFactory extends AbstractFactory {
public TaskViewFactory( Business business ) throws Exception {
super(business);
}
/**
* 获取指定Id的TaskView实体信息对象
* @param id
* @return
* @throws Exception
*/
public TaskView get( String id ) throws Exception {
return this.entityManagerContainer().find( id, TaskView.class, ExceptionWhen.none );
}
/**
* 列示指定Id的TaskView实体信息列表
* @param ids
* @return
* @throws Exception
*/
public List<TaskView> list( List<String> ids ) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<TaskView>();
}
EntityManager em = this.entityManagerContainer().get(TaskView.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskView> cq = cb.createQuery(TaskView.class);
Root<TaskView> root = cq.from(TaskView.class);
Predicate p = root.get(TaskView_.id).in(ids);
cq.orderBy( cb.desc( root.get( TaskView_.updateTime ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据用户和项目ID查询工作任务列表
* @param person
* @param projectId
* @return
* @throws Exception
*/
public List<TaskView> listWithPersonAndProject( String person, String projectId ) throws Exception {
if( StringUtils.isEmpty( person ) ){
throw new Exception("person can not be empty!");
}
if( StringUtils.isEmpty( projectId ) ){
throw new Exception("projectId can not be empty!");
}
EntityManager em = this.entityManagerContainer().get(TaskView.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskView> cq = cb.createQuery(TaskView.class);
Root<TaskView> root = cq.from(TaskView.class);
Predicate p = cb.equal( root.get(TaskView_.owner ), person );
p = cb.and( p, cb.equal( root.get(TaskView_.project), projectId ) );
return em.createQuery(cq.where(p)).getResultList();
}
public Long countWithFilter( QueryFilter queryFilter) throws Exception {
if( queryFilter == null ) {
return 0L;
}
EntityManager em = this.entityManagerContainer().get( TaskView.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<TaskView> root = cq.from(TaskView.class);
Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter( TaskView_.class, cb, null, root, queryFilter );
cq.select(cb.count(root)).where(p);
return em.createQuery(cq).getSingleResult();
}
public List<TaskView> listWithFilter( Integer maxCount, String orderField, String orderType, QueryFilter queryFilter) throws Exception {
EntityManager em = this.entityManagerContainer().get( TaskView.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskView> cq = cb.createQuery(TaskView.class);
Root<TaskView> root = cq.from(TaskView.class);
Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter( TaskView_.class, cb, null, root, queryFilter );
//排序,添加排序列,默认使用sequence
List<Order> orders = new ArrayList<>();
Order orderWithField = CriteriaBuilderTools.getOrder( cb, root, TaskView_.class, orderField, orderType );
if( orderWithField != null ){
orders.add( orderWithField );
}
if( !TaskView.sequence_FIELDNAME.equalsIgnoreCase( orderField )) {
//如果是其他的列,很可能排序值不唯一,所以使用多一列排序列来确定每次查询的顺序
orderWithField = CriteriaBuilderTools.getOrder( cb, root, TaskView_.class, TaskView.id_FIELDNAME, orderType );
if( orderWithField != null ){
orders.add( orderWithField );
}
}
if( ListTools.isNotEmpty( orders )){
cq.orderBy( orders );
}
return em.createQuery(cq.where(p)).setMaxResults( maxCount).getResultList();
}
}
package com.x.teamwork.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.CipherManagerJaxrsFilter;
@WebFilter(urlPatterns = {
"/jaxrs/cipher/*",
"/jaxrs/manager/*"
}, asyncSupported = true)
public class JaxrsCipherManagerFilter extends CipherManagerJaxrsFilter {
}
\ No newline at end of file
package com.x.teamwork.assemble.control.jaxrs.attachment;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckRemoveType;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.teamwork.assemble.control.ThisApplication;
import com.x.teamwork.core.entity.Attachment;
import com.x.teamwork.core.entity.Dynamic;
public class ActionDelete extends BaseAction {
private static Logger logger = LoggerFactory.getLogger( ActionDelete.class );
protected ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id ) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Attachment attachment = null;
StorageMapping mapping = null;
Dynamic dynamic = null;
Wo wo = new Wo();
Boolean check = true;
if( StringUtils.isEmpty( id ) ){
check = false;
Exception exception = new ExceptionAttachmentIdEmpty();
result.error( exception );
}
if( Boolean.TRUE.equals( check ) ){
try{
attachment = attachmentQueryService.get( id );
if (null == attachment) {
check = false;
Exception exception = new ExceptionAttachmentNotExists( id );
result.error( exception );
}
}catch(Exception e){
check = false;
Exception exception = new ExceptionAttachmentQueryById( e, id );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
if( Boolean.TRUE.equals( check ) ){
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
mapping = ThisApplication.context().storageMappings().get(Attachment.class, attachment.getStorage());
attachment = emc.find( id, Attachment.class );
emc.beginTransaction( Attachment.class );
emc.remove( attachment, CheckRemoveType.all );
attachment.deleteContent( mapping );
emc.commit();
}catch(Exception e){
check = false;
Exception exception = new ExceptionAttachmentDelete( e, attachment.getId() );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
if( Boolean.TRUE.equals( check ) ){
try {
dynamic = dynamicPersistService.deleteAttachment( attachment, effectivePerson );
if( dynamic != null ) {
List<WoDynamic> dynamics = new ArrayList<>();
dynamics.add( WoDynamic.copier.copy( dynamic ) );
wo.setDynamics(dynamics);
}
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
}
}
wo.setId( id );
result.setData( wo );
return result;
}
public static class Wo extends WoId {
@FieldDescribe("操作引起的动态内容")
List<WoDynamic> dynamics = new ArrayList<>();
public List<WoDynamic> getDynamics() {
return dynamics;
}
public void setDynamics(List<WoDynamic> dynamics) {
this.dynamics = dynamics;
}
}
public static class WoDynamic extends Dynamic{
private static final long serialVersionUID = -5076990764713538973L;
public static WrapCopier<Dynamic, WoDynamic> copier = WrapCopierFactory.wo( Dynamic.class, WoDynamic.class, null, JpaObject.FieldsInvisible);
private Long rank = 0L;
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.jaxrs.attachment;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoFile;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.teamwork.assemble.control.ThisApplication;
import com.x.teamwork.core.entity.Attachment;
import com.x.teamwork.core.entity.Dynamic;
public class ActionDownload extends BaseAction {
private static Logger logger = LoggerFactory.getLogger( ActionDownload.class );
protected ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id ) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Attachment attachment = null;
Boolean check = true;
Wo wo = null;
try {
attachment = attachmentQueryService.get( id );
if( attachment == null ){
check = false;
Exception exception = new ExceptionAttachmentNotExists( id );
result.error( exception );
}
} catch ( Exception e ) {
check = false;
Exception exception = new ExceptionAttachmentQueryById( e, id );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
if( Boolean.TRUE.equals( check ) ){
StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class, attachment.getStorage());
wo = new Wo(attachment.readContent(mapping),
this.contentType(false, attachment.getName()),
this.contentDisposition(false, attachment.getName()));
}
if( Boolean.TRUE.equals( check ) ){
try {
Dynamic dynamic = dynamicPersistService.downloadAttachmentDynamic(attachment, effectivePerson);
if( dynamic != null ) {
List<WoDynamic> dynamics = new ArrayList<>();
dynamics.add( WoDynamic.copier.copy( dynamic ) );
if( wo != null ) {
wo.setDynamics(dynamics);
}
}
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
}
}
result.setData(wo);
return result;
}
public static class Wo extends WoFile {
@FieldDescribe("操作引起的动态内容")
List<WoDynamic> dynamics = new ArrayList<>();
public List<WoDynamic> getDynamics() {
return dynamics;
}
public void setDynamics(List<WoDynamic> dynamics) {
this.dynamics = dynamics;
}
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
public static class WoDynamic extends Dynamic{
private static final long serialVersionUID = -5076990764713538973L;
public static WrapCopier<Dynamic, WoDynamic> copier = WrapCopierFactory.wo( Dynamic.class, WoDynamic.class, null, JpaObject.FieldsInvisible);
private Long rank = 0L;
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoFile;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.teamwork.assemble.control.ThisApplication;
import com.x.teamwork.core.entity.Attachment;
import com.x.teamwork.core.entity.Dynamic;
public class ActionDownloadStream extends BaseAction {
private static Logger logger = LoggerFactory.getLogger( ActionDownloadStream.class );
protected ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id, Boolean stream ) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Attachment attachment = null;
Boolean check = true;
Wo wo = null;
try {
attachment = attachmentQueryService.get( id );
if( attachment == null ){
check = false;
Exception exception = new ExceptionAttachmentNotExists( id );
result.error( exception );
}
} catch ( Exception e ) {
check = false;
Exception exception = new ExceptionAttachmentQueryById( e, id );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
if( Boolean.TRUE.equals( check ) ){
StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class, attachment.getStorage());
wo = new Wo(attachment.readContent(mapping),
this.contentType(stream, attachment.getName()),
this.contentDisposition(stream, attachment.getName()));
}
if( Boolean.TRUE.equals( check ) ){
try {
Dynamic dynamic = dynamicPersistService.downloadAttachmentDynamic(attachment, effectivePerson);
if( dynamic != null ) {
List<WoDynamic> dynamics = new ArrayList<>();
dynamics.add( WoDynamic.copier.copy( dynamic ) );
if( wo != null ) {
wo.setDynamics(dynamics);
}
}
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
}
}
result.setData(wo);
return result;
}
public static class Wo extends WoFile {
@FieldDescribe("操作引起的动态内容")
List<WoDynamic> dynamics = new ArrayList<>();
public List<WoDynamic> getDynamics() {
return dynamics;
}
public void setDynamics(List<WoDynamic> dynamics) {
this.dynamics = dynamics;
}
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
public static class WoDynamic extends Dynamic{
private static final long serialVersionUID = -5076990764713538973L;
public static WrapCopier<Dynamic, WoDynamic> copier = WrapCopierFactory.wo( Dynamic.class, WoDynamic.class, null, JpaObject.FieldsInvisible);
private Long rank = 0L;
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.teamwork.core.entity.Attachment;
public class ActionGet extends BaseAction {
private static Logger logger = LoggerFactory.getLogger( ActionGet.class );
protected ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id ) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wrap = null;
Attachment attachment = null;
if( StringUtils.isEmpty( id )){
Exception exception = new ExceptionAttachmentIdEmpty();
result.error( exception );
}else{
try {
attachment = attachmentQueryService.get( id );
if( attachment != null ){
wrap = Wo.copier.copy( attachment );
result.setData(wrap);
}else{
Exception exception = new ExceptionAttachmentNotExists( id );
result.error( exception );
}
} catch ( Exception e ) {
Exception exception = new ExceptionAttachmentQueryById( e, id );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
return result;
}
public static class Wo extends Attachment{
private static final long serialVersionUID = -5076990764713538973L;
public static WrapCopier<Attachment, Wo> copier = WrapCopierFactory.wo( Attachment.class, Wo.class, null, JpaObject.FieldsInvisible);
private Long rank = 0L;
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.jaxrs.attachment;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.teamwork.core.entity.Attachment;
import com.x.teamwork.core.entity.Project;
public class ActionListWithProject extends BaseAction {
private static Logger logger = LoggerFactory.getLogger( ActionListWithProject.class );
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id ) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<List<Wo>>();
List<Wo> wrapOutAttachmentList = null;
List<Attachment> attachments = null;
Project project = null;
if( StringUtils.isEmpty( id )){
Exception exception = new ExceptionProjectIdEmpty();
result.error( exception );
}else{
try {
project = projectQueryService.get( id );
if( project != null ){
attachments = attachmentQueryService.listAttachmentWithProject(id );
if( ListTools.isNotEmpty( attachments)) {
wrapOutAttachmentList = Wo.copier.copy( attachments );
}
}
} catch (Exception e) {
Exception exception = new ExceptionQueryProjectById( e, id );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
if( wrapOutAttachmentList == null ){
wrapOutAttachmentList = new ArrayList<Wo>();
}
result.setData( wrapOutAttachmentList );
}
return result;
}
public static class Wo extends Attachment{
private static final long serialVersionUID = -5076990764713538973L;
public static WrapCopier<Attachment, Wo> copier = WrapCopierFactory.wo( Attachment.class, Wo.class, null,JpaObject.FieldsInvisible);
private Long rank = 0L;
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.jaxrs.attachment;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.teamwork.core.entity.Attachment;
import com.x.teamwork.core.entity.Task;
public class ActionListWithTask extends BaseAction {
private static Logger logger = LoggerFactory.getLogger( ActionListWithTask.class );
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, String taskId ) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<List<Wo>>();
List<Wo> wrapOutAttachmentList = null;
List<Attachment> attachments = null;
Task task = null;
if( StringUtils.isEmpty( taskId )){
Exception exception = new ExceptionProjectIdEmpty();
result.error( exception );
}else{
try {
task = taskQueryService.get( taskId );
if( task != null ){
attachments = attachmentQueryService.listAttachmentWithTask(taskId);
if( ListTools.isNotEmpty( attachments)) {
wrapOutAttachmentList = Wo.copier.copy( attachments );
}
}
} catch (Exception e) {
Exception exception = new ExceptionQueryProjectById( e, taskId );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
if( wrapOutAttachmentList == null ){
wrapOutAttachmentList = new ArrayList<Wo>();
}
result.setData( wrapOutAttachmentList );
}
return result;
}
public static class Wo extends Attachment{
private static final long serialVersionUID = -5076990764713538973L;
public static WrapCopier<Attachment, Wo> copier = WrapCopierFactory.wo( Attachment.class, Wo.class, null,JpaObject.FieldsInvisible);
private Long rank = 0L;
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.jaxrs.attachment;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.teamwork.assemble.control.ThisApplication;
import com.x.teamwork.core.entity.Attachment;
import com.x.teamwork.core.entity.Dynamic;
import com.x.teamwork.core.entity.Project;
public class ActionProjectAttachmentUpload extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionProjectAttachmentUpload.class);
protected ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson,
String projectId, String site, byte[] bytes, FormDataContentDisposition disposition) {
ActionResult<Wo> result = new ActionResult<>();
Attachment attachment = null;
Project project = null;
StorageMapping mapping = null;
String fileName = null;
Boolean check = true;
Wo wo = new Wo();
if( Boolean.TRUE.equals( check ) ){
if( StringUtils.isEmpty( projectId ) ){
check = false;
Exception exception = new ExceptionProjectIdEmpty( );
result.error( exception );
}
}
if( Boolean.TRUE.equals( check ) ){//判断工作信息是否已经存在
try {
project = projectQueryService.get( projectId );
if (null == project) {
check = false;
Exception exception = new ExceptionProjectNotExists( projectId );
result.error( exception );
}
} catch (Exception e) {
check = false;
result.error( e );
logger.error( e, effectivePerson, request, null );
}
}
if( Boolean.TRUE.equals( check ) ){
try {
fileName = FilenameUtils.getName(new String(disposition.getFileName().getBytes(DefaultCharset.name_iso_8859_1), DefaultCharset.name));
/** 禁止不带扩展名的文件上传 */
if (StringUtils.isEmpty(fileName)) {
check = false;
Exception exception = new ExceptionEmptyExtension( fileName );
result.error( exception );
}
} catch (Exception e) {
check = false;
result.error( e );
}
}
if( Boolean.TRUE.equals( check ) ){
try {
mapping = ThisApplication.context().storageMappings().random( Attachment.class );
} catch (Exception e) {
check = false;
result.error( e );
logger.warn( "系统在获取存储的时候发生异常!" );
logger.error( e, effectivePerson, request, null );
}
}
if( Boolean.TRUE.equals( check ) ){
try {
attachment = this.concreteAttachment( mapping, project, fileName, effectivePerson, site );
attachment.saveContent(mapping, bytes, fileName);
attachment = attachmentPersistService.saveAttachment( project, attachment );
wo.setId( attachment.getId() );
} catch (Exception e) {
check = false;
result.error( e );
logger.warn( "系统在保存附件和更新附件数据时候发生异常!" );
logger.error( e, effectivePerson, request, null );
}
}
if( Boolean.TRUE.equals( check ) ){
try {
Dynamic dynamic = dynamicPersistService.uploadAttachmentDynamic(attachment, effectivePerson);
if( dynamic != null ) {
List<WoDynamic> dynamics = new ArrayList<>();
dynamics.add( WoDynamic.copier.copy( dynamic ) );
wo.setDynamics(dynamics);
}
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
}
}
result.setData(wo);
return result;
}
private Attachment concreteAttachment(StorageMapping mapping, Project project, String name, EffectivePerson effectivePerson, String site) throws Exception {
Attachment attachment = new Attachment();
String fileName = UUID.randomUUID().toString();
String extension = FilenameUtils.getExtension( name );
if ( StringUtils.isNotEmpty(extension)) {
fileName = fileName + "." + extension;
}else{
throw new Exception("file extension is empty.");
}
if( name.indexOf( "\\" ) >0 ){
name = StringUtils.substringAfterLast( name, "\\");
}
if( name.indexOf( "/" ) >0 ){
name = StringUtils.substringAfterLast( name, "/");
}
attachment.setCreateTime( new Date() );
attachment.setLastUpdateTime( new Date() );
attachment.setExtension( extension );
attachment.setName( name );
attachment.setFileName( fileName );
attachment.setStorage( mapping.getName() );
attachment.setProjectId( project.getId() );
attachment.setBundleObjType("PROJECT") ;
attachment.setCreatorUid( effectivePerson.getDistinguishedName() );
attachment.setSite( site );
attachment.setFileHost( "" );
attachment.setFilePath( "" );
return attachment;
}
public static class Wo extends WoId {
@FieldDescribe("操作引起的动态内容")
List<WoDynamic> dynamics = new ArrayList<>();
public List<WoDynamic> getDynamics() {
return dynamics;
}
public void setDynamics(List<WoDynamic> dynamics) {
this.dynamics = dynamics;
}
}
public static class WoDynamic extends Dynamic{
private static final long serialVersionUID = -5076990764713538973L;
public static WrapCopier<Dynamic, WoDynamic> copier = WrapCopierFactory.wo( Dynamic.class, WoDynamic.class, null, JpaObject.FieldsInvisible);
private Long rank = 0L;
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.teamwork.assemble.control.ThisApplication;
import com.x.teamwork.core.entity.Attachment;
import com.x.teamwork.core.entity.Dynamic;
import com.x.teamwork.core.entity.Task;
public class ActionTaskAttachmentUpload extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionTaskAttachmentUpload.class);
protected ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson,
String taskId, String site, byte[] bytes, FormDataContentDisposition disposition) {
ActionResult<Wo> result = new ActionResult<>();
Attachment attachment = null;
Task task = null;
StorageMapping mapping = null;
String fileName = null;
Boolean check = true;
Wo wo = new Wo();
if( Boolean.TRUE.equals( check ) ){
if( StringUtils.isEmpty( taskId ) ){
check = false;
Exception exception = new ExceptionTaskIdEmpty( );
result.error( exception );
}
}
if( Boolean.TRUE.equals( check ) ){//判断工作信息是否已经存在
try {
task = taskQueryService.get( taskId );
if (null == task) {
check = false;
Exception exception = new ExceptionTaskNotExists( taskId );
result.error( exception );
}
} catch (Exception e) {
check = false;
result.error( e );
logger.error( e, effectivePerson, request, null );
}
}
if( Boolean.TRUE.equals( check ) ){
try {
fileName = FilenameUtils.getName(new String(disposition.getFileName().getBytes(DefaultCharset.name_iso_8859_1), DefaultCharset.name));
/** 禁止不带扩展名的文件上传 */
if (StringUtils.isEmpty(fileName)) {
check = false;
Exception exception = new ExceptionEmptyExtension( fileName );
result.error( exception );
}
} catch (Exception e) {
check = false;
result.error( e );
}
}
if( Boolean.TRUE.equals( check ) ){
try {
mapping = ThisApplication.context().storageMappings().random( Attachment.class );
} catch (Exception e) {
check = false;
result.error( e );
logger.warn( "系统在获取存储的时候发生异常!" );
logger.error( e, effectivePerson, request, null );
}
}
if( Boolean.TRUE.equals( check ) ){
try {
attachment = this.concreteAttachment( mapping, task, fileName, effectivePerson, site );
attachment.saveContent(mapping, bytes, fileName);
attachment = attachmentPersistService.saveAttachment( task, attachment );
wo.setId( attachment.getId() );
} catch (Exception e) {
check = false;
result.error( e );
logger.warn( "系统在保存附件和更新附件数据时候发生异常!" );
logger.error( e, effectivePerson, request, null );
}
}
if( Boolean.TRUE.equals( check ) ){
try {
Dynamic dynamic = dynamicPersistService.uploadAttachmentDynamic(attachment, effectivePerson);
if( dynamic != null ) {
List<WoDynamic> dynamics = new ArrayList<>();
dynamics.add( WoDynamic.copier.copy( dynamic ) );
wo.setDynamics(dynamics);
}
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
}
}
result.setData(wo);
return result;
}
private Attachment concreteAttachment(StorageMapping mapping, Task task, String name, EffectivePerson effectivePerson, String site) throws Exception {
Attachment attachment = new Attachment();
String fileName = UUID.randomUUID().toString();
String extension = FilenameUtils.getExtension( name );
if ( StringUtils.isNotEmpty(extension)) {
fileName = fileName + "." + extension;
}else{
throw new Exception("file extension is empty.");
}
if( name.indexOf( "\\" ) >0 ){
name = StringUtils.substringAfterLast( name, "\\");
}
if( name.indexOf( "/" ) >0 ){
name = StringUtils.substringAfterLast( name, "/");
}
attachment.setCreateTime( new Date() );
attachment.setLastUpdateTime( new Date() );
attachment.setExtension( extension );
attachment.setName( name );
attachment.setFileName( fileName );
attachment.setStorage( mapping.getName() );
attachment.setProjectId( task.getProject() );
attachment.setTaskId( task.getId() );
attachment.setBundleObjType("TASK") ;
attachment.setCreatorUid( effectivePerson.getDistinguishedName() );
attachment.setSite( site );
attachment.setFileHost( "" );
attachment.setFilePath( "" );
return attachment;
}
public static class Wo extends WoId {
@FieldDescribe("操作引起的动态内容")
List<WoDynamic> dynamics = new ArrayList<>();
public List<WoDynamic> getDynamics() {
return dynamics;
}
public void setDynamics(List<WoDynamic> dynamics) {
this.dynamics = dynamics;
}
}
public static class WoDynamic extends Dynamic{
private static final long serialVersionUID = -5076990764713538973L;
public static WrapCopier<Dynamic, WoDynamic> copier = WrapCopierFactory.wo( Dynamic.class, WoDynamic.class, null, JpaObject.FieldsInvisible);
private Long rank = 0L;
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
@Path( "attachment" )
@JaxrsDescribe("工作任务附件信息管理服务")
public class AttachmentAction extends StandardJaxrsAction{
private static Logger logger = LoggerFactory.getLogger( AttachmentAction.class );
@JaxrsMethodDescribe(value = "根据项目ID获取工作附件信息列表", action = ActionListWithProject.class)
@GET
@Path( "list/project/{id}" )
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listByProjectId( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("项目ID") @PathParam( "id" ) String id) {
EffectivePerson effectivePerson = this.effectivePerson( request );
ActionResult<List<ActionListWithProject.Wo>> result = new ActionResult<>();
try {
result = new ActionListWithProject().execute( request, effectivePerson, id );
} catch (Exception e) {
result = new ActionResult<>();
logger.warn( "系统根据项目ID获取项目所有附件信息过程发生异常。" );
logger.error( e, effectivePerson, request, null);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "根据工作ID获取工作附件信息列表", action = ActionListWithTask.class)
@GET
@Path( "list/task/{id}" )
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listByTaskId( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("工作ID") @PathParam( "id" ) String id) {
EffectivePerson effectivePerson = this.effectivePerson( request );
ActionResult<List<ActionListWithTask.Wo>> result = new ActionResult<>();
try {
result = new ActionListWithTask().execute( request, effectivePerson, id );
} catch (Exception e) {
result = new ActionResult<>();
logger.warn( "系统根据工作ID获取工作所有附件信息过程发生异常。" );
logger.error( e, effectivePerson, request, null);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "根据ID删除附件信息对象", action = ActionDelete.class)
@DELETE
@Path( "{id}" )
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void delete( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("附件ID") @PathParam( "id" ) String id) {
EffectivePerson effectivePerson = this.effectivePerson( request );
ActionResult<ActionDelete.Wo> result = new ActionResult<>();
try {
result = new ActionDelete().execute( request, effectivePerson, id );
} catch (Exception e) {
result = new ActionResult<>();
logger.warn( "系统根据ID删除附件信息对象过程发生异常。" );
logger.error( e, effectivePerson, request, null);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "根据ID获取附件信息对象", action = ActionGet.class)
@GET
@Path( "{id}" )
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void get( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("附件信息ID") @PathParam( "id" ) String id) {
EffectivePerson effectivePerson = this.effectivePerson( request );
ActionResult<ActionGet.Wo> result = new ActionResult<>();
try {
result = new ActionGet().execute( request, effectivePerson, id );
} catch (Exception e) {
result = new ActionResult<>();
logger.warn( "系统根据ID获取附件信息对象过程发生异常。" );
logger.error( e, effectivePerson, request, null);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "根据ID下载指定附件", action = ActionDownload.class)
@GET
@Path("download/{id}")
@Consumes(MediaType.APPLICATION_JSON)
public void downLoad(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request,
@JaxrsParameterDescribe("附件信息ID") @PathParam("id") String id) {
ActionResult<ActionDownload.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionDownload().execute(request, effectivePerson, id);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "下载指定附件,设定是否使用stream输出", action = ActionDownloadStream.class)
@GET
@Path("download/{id}/stream/{stream}")
@Consumes(MediaType.APPLICATION_JSON)
public void downloadStream(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request,
@JaxrsParameterDescribe("附件信息ID") @PathParam("id") String id,
@JaxrsParameterDescribe("用.APPLICATION_OCTET_STREAM头输出") @PathParam("stream") Boolean stream) {
ActionResult<ActionDownloadStream.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionDownloadStream().execute(request, effectivePerson, id, stream);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "上传项目信息附件.", action = ActionProjectAttachmentUpload.class)
@POST
@Path("upload/project/{id}/site/{site}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void projectAttachmentUpload(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request,
@JaxrsParameterDescribe("项目信息ID") @PathParam("id") String id,
@JaxrsParameterDescribe("位置") @PathParam("site") String site,
@FormDataParam(FILE_FIELD) final byte[] bytes,
@FormDataParam(FILE_FIELD) final FormDataContentDisposition disposition) {
ActionResult<ActionProjectAttachmentUpload.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionProjectAttachmentUpload().execute(request, effectivePerson, id, site, bytes, disposition);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "为工作信息上传附件.", action = ActionTaskAttachmentUpload.class)
@POST
@Path("upload/task/{id}/site/{site}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void taskAttachmentUpload(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request,
@JaxrsParameterDescribe("工作任务ID") @PathParam("id") String id,
@JaxrsParameterDescribe("位置") @PathParam("site") String site,
@FormDataParam(FILE_FIELD) final byte[] bytes,
@FormDataParam(FILE_FIELD) final FormDataContentDisposition disposition) {
ActionResult<ActionTaskAttachmentUpload.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionTaskAttachmentUpload().execute(request, effectivePerson, id, site, bytes, disposition);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class AttachmentNotExistsException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public AttachmentNotExistsException( String id ) {
super("指定ID的附件信息记录不存在。ID:" + id );
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class AttachmentQueryByIdException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public AttachmentQueryByIdException( Throwable e, String id ) {
super("查询指定ID的附件信息时发生异常。ID:" + id, e );
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.teamwork.assemble.control.service.AttachmentPersistService;
import com.x.teamwork.assemble.control.service.AttachmentQueryService;
import com.x.teamwork.assemble.control.service.DynamicPersistService;
import com.x.teamwork.assemble.control.service.ProjectQueryService;
import com.x.teamwork.assemble.control.service.TaskPersistService;
import com.x.teamwork.assemble.control.service.TaskQueryService;
public class BaseAction extends StandardJaxrsAction {
protected AttachmentPersistService attachmentPersistService = new AttachmentPersistService();
protected AttachmentQueryService attachmentQueryService = new AttachmentQueryService();
protected TaskQueryService taskQueryService = new TaskQueryService();
protected ProjectQueryService projectQueryService = new ProjectQueryService();
protected DynamicPersistService dynamicPersistService = new DynamicPersistService();
protected TaskPersistService taskPersistService = new TaskPersistService();
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class ExceptionAttachmentDelete extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public ExceptionAttachmentDelete( Throwable e, String id ) {
super("系统根据id删除附件信息时发生异常。ID:" + id, e );
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class ExceptionAttachmentIdEmpty extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public ExceptionAttachmentIdEmpty() {
super("id为空,无法继续进行查询操作。");
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class ExceptionAttachmentNotExists extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public ExceptionAttachmentNotExists( String id ) {
super("指定id的附件信息不存在,无法继续进行操作。ID:" + id );
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class ExceptionAttachmentQueryById extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public ExceptionAttachmentQueryById( Throwable e, String id ) {
super("系统根据id查询附件信息时发生异常。ID:" + id, e );
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class ExceptionEmptyExtension extends PromptException {
private static final long serialVersionUID = 4132300948670472899L;
public ExceptionEmptyExtension(String name) {
super("不能上传文件扩展名为空的文件: {}.", name);
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class ExceptionProjectIdEmpty extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public ExceptionProjectIdEmpty() {
super("项目id为空,无法继续进行查询操作。");
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class ExceptionProjectNotExists extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public ExceptionProjectNotExists( String id ) {
super("指定id的项目信息不存在,无法继续进行操作。ID:" + id );
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class ExceptionQueryProjectById extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public ExceptionQueryProjectById( Throwable e, String id ) {
super("系统根据id查询项目信息时发生异常。ID:" + id, e );
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class ExceptionTaskIdEmpty extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public ExceptionTaskIdEmpty() {
super("工作任务id为空,无法继续进行查询操作。");
}
}
package com.x.teamwork.assemble.control.jaxrs.attachment;
import com.x.base.core.project.exception.PromptException;
public class ExceptionTaskNotExists extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public ExceptionTaskNotExists( String id ) {
super("指定ID的工作任务信息记录不存在。ID:" + id );
}
}
package com.x.teamwork.assemble.control.jaxrs.chat;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.teamwork.core.entity.Chat;
import com.x.teamwork.core.entity.Dynamic;
public class ActionDelete extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionDelete.class);
protected ActionResult<Wo> execute(HttpServletRequest request, EffectivePerson effectivePerson, String id) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Chat chat = null;
Boolean check = true;
Wo wo = new Wo();
if ( StringUtils.isEmpty( id ) ) {
check = false;
Exception exception = new ChatFlagForQueryEmptyException();
result.error( exception );
}
if( Boolean.TRUE.equals( check ) ){
try {
chat = chatQueryService.get( id );
if ( chat == null) {
check = false;
Exception exception = new ChatNotExistsException( id );
result.error( exception );
}
} catch (Exception e) {
check = false;
Exception exception = new ChatQueryException(e, "根据指定flag查询工作交流信息对象时发生异常。ID:" + id);
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
}
if( Boolean.TRUE.equals( check ) ){
try {
chatPersistService.delete( id, effectivePerson );
// 更新缓存
ApplicationCache.notify( Chat.class );
wo.setId( chat.getId() );
} catch (Exception e) {
check = false;
Exception exception = new ChatQueryException(e, "根据指定flag删除工作交流信息对象时发生异常。ID:" + id);
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
}
if( Boolean.TRUE.equals( check ) ){
try {
Dynamic dynamic = dynamicPersistService.chatDeleteDynamic( chat, effectivePerson);
if( dynamic != null ) {
List<WoDynamic> dynamics = new ArrayList<>();
dynamics.add( WoDynamic.copier.copy( dynamic ) );
if( wo != null ) {
wo.setDynamics(dynamics);
}
}
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
}
}
result.setData( wo );
return result;
}
public static class Wo extends WoId {
@FieldDescribe("操作引起的动态内容")
List<WoDynamic> dynamics = new ArrayList<>();
public List<WoDynamic> getDynamics() {
return dynamics;
}
public void setDynamics(List<WoDynamic> dynamics) {
this.dynamics = dynamics;
}
}
public static class WoDynamic extends Dynamic{
private static final long serialVersionUID = -5076990764713538973L;
public static WrapCopier<Dynamic, WoDynamic> copier = WrapCopierFactory.wo( Dynamic.class, WoDynamic.class, null, JpaObject.FieldsInvisible);
private Long rank = 0L;
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.jaxrs.chat;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.teamwork.core.entity.Chat;
public class ActionGet extends BaseAction {
private Logger logger = LoggerFactory.getLogger( ActionGet.class );
protected ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id ) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wrap = null;
Chat chat = null;
Boolean check = true;
if( Boolean.TRUE.equals( check ) ){
if( id == null || id.isEmpty() ){
check = false;
Exception exception = new ChatIDEmptyException();
result.error( exception );
}
}
if( Boolean.TRUE.equals( check ) ){
try {
chat = chatQueryService.get( id );
if( chat == null ) {
check = false;
Exception exception = new ChatNotExistsException(id);
result.error( exception );
}
} catch (Exception e) {
check = false;
Exception exception = new ChatQueryException( e, "系统根据ID查询指定工作评论信息时发生异常.ID:" + id );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
if( Boolean.TRUE.equals( check ) ){
try {
wrap = Wo.copier.copy( chat );
result.setData( wrap );
} catch (Exception e) {
check = false;
Exception exception = new ChatQueryException( e, "将查询结果转换为可以输出的信息时发生异常." );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
return result;
}
public static class Wo extends Chat {
private static final long serialVersionUID = -5076990764713538973L;
public static List<String> Excludes = new ArrayList<String>();
public static WrapCopier<Chat, Wo> copier = WrapCopierFactory.wo( Chat.class, Wo.class, null,Wo.Excludes);
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.jaxrs.chat;
import javax.servlet.http.HttpServletRequest;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoText;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
public class ActionGetContent extends BaseAction {
private Logger logger = LoggerFactory.getLogger( ActionGetContent.class );
protected ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id ) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wrap = null;
String chatContent = null;
Boolean check = true;
if( Boolean.TRUE.equals( check ) ){
if( id == null || id.isEmpty() ){
check = false;
Exception exception = new ChatIDEmptyException();
result.error( exception );
}
}
if( Boolean.TRUE.equals( check ) ){
try {
chatContent = chatQueryService.getContent( id );
} catch (Exception e) {
check = false;
Exception exception = new ChatQueryException( e, "系统根据ID查询指定工作评论信息内容时发生异常.ID:" + id );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
if( Boolean.TRUE.equals( check ) ){
try {
wrap = new Wo();
wrap.setText( chatContent );
result.setData( wrap );
} catch (Exception e) {
check = false;
Exception exception = new ChatQueryException( e, "将查询结果转换为可以输出的信息时发生异常." );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
return result;
}
public static class Wo extends WoText {
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.jaxrs.chat;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonElement;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.teamwork.core.entity.Chat;
import com.x.teamwork.core.entity.tools.filter.QueryFilter;
public class ActionListNextWithFilter extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionListNextWithFilter.class);
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, String flag, Integer count, JsonElement jsonElement ) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
Wi wrapIn = null;
Boolean check = true;
QueryFilter queryFilter = null;
if ( StringUtils.isEmpty( flag ) || "(0)".equals(flag)) {
flag = null;
}
try {
wrapIn = this.convertToWrapIn(jsonElement, Wi.class);
} catch (Exception e) {
check = false;
Exception exception = new ChatQueryException(e, "系统在将JSON信息转换为对象时发生异常。JSON:" + jsonElement.toString());
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
if( Boolean.TRUE.equals( check ) ){
queryFilter = wrapIn.getQueryFilter();
}
if( Boolean.TRUE.equals( check ) ){
try {
Long total = chatQueryService.countWithFilter( queryFilter );
List<Chat> chatList = chatQueryService.listWithFilterNext( count, flag, wrapIn.getOrderField(), wrapIn.getOrderType(), queryFilter );
if( ListTools.isNotEmpty( chatList )) {
wos = Wo.copier.copy(chatList);
}
result.setCount( total );
result.setData( wos );
} catch (Exception e) {
check = false;
logger.warn("系统查询项目信息列表时发生异常!");
result.error(e);
logger.error(e, effectivePerson, request, null);
}
}
return result;
}
public static class Wi extends WrapInQueryChat{
}
public static class Wo extends Chat {
private Long rank;
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
private static final long serialVersionUID = -5076990764713538973L;
public static List<String> Excludes = new ArrayList<String>();
static WrapCopier<Chat, Wo> copier = WrapCopierFactory.wo( Chat.class, Wo.class, null, ListTools.toList(JpaObject.FieldsInvisible));
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.jaxrs.chat;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.teamwork.assemble.control.service.ChatPersistService;
import com.x.teamwork.assemble.control.service.ChatQueryService;
import com.x.teamwork.assemble.control.service.DynamicPersistService;
import com.x.teamwork.assemble.control.service.SystemConfigQueryService;
import com.x.teamwork.assemble.control.service.TaskQueryService;
import com.x.teamwork.core.entity.Chat;
import net.sf.ehcache.Ehcache;
public class BaseAction extends StandardJaxrsAction {
protected Ehcache chatCache = ApplicationCache.instance().getCache( Chat.class );
protected ChatQueryService chatQueryService = new ChatQueryService();
protected ChatPersistService chatPersistService = new ChatPersistService();
protected TaskQueryService taskQueryService = new TaskQueryService();
protected DynamicPersistService dynamicPersistService = new DynamicPersistService();
protected SystemConfigQueryService systemConfigQueryService = new SystemConfigQueryService();
}
package com.x.teamwork.assemble.control.jaxrs.chat;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
@Path("chat")
@JaxrsDescribe("工作评论流信息管理")
public class ChatAction extends StandardJaxrsAction {
private Logger logger = LoggerFactory.getLogger(ChatAction.class);
@JaxrsMethodDescribe( value = "根据ID获取评论信息", action = ActionGet.class )
@GET
@Path("{id}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void get( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, @JaxrsParameterDescribe("评论信息ID") @PathParam("id") String id) {
ActionResult<ActionGet.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
Boolean check = true;
if(check){
try {
result = new ActionGet().execute( request, effectivePerson, id );
} catch (Exception e) {
result = new ActionResult<>();
Exception exception = new ChatQueryException( e, "根据ID获取评论信息时发生异常!" );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe( value = "根据ID获取评论信息文字内容", action = ActionGetContent.class )
@GET
@Path("{id}/content")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void getContent( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, @JaxrsParameterDescribe("评论信息ID") @PathParam("id") String id) {
ActionResult<ActionGetContent.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
Boolean check = true;
if(check){
try {
result = new ActionGetContent().execute( request, effectivePerson, id );
} catch (Exception e) {
result = new ActionResult<>();
Exception exception = new ChatQueryException( e, "根据ID获取工作评论信息内容时发生异常!" );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "列示评论信息,下一页.", action = ActionListNextWithFilter.class)
@PUT
@Path("list/{id}/next/{count}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listNextWithFilter(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("最后一条信息数据的ID") @PathParam( "id" ) String id,
@JaxrsParameterDescribe("每页显示的条目数量") @PathParam( "count" ) Integer count,
@JaxrsParameterDescribe("查询过滤条件") JsonElement jsonElement ) {
ActionResult<List<ActionListNextWithFilter.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionListNextWithFilter().execute(request, effectivePerson, id, count, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "创建一个工作交流信息.", action = ActionCreate.class)
@POST
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void create(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request,
@JaxrsParameterDescribe("工作交流信息") JsonElement jsonElement ) {
ActionResult<ActionCreate.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionCreate().execute(request, effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "根据标识删除工作交流信息.", action = ActionDelete.class)
@DELETE
@Path("{id}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void delete(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("id") String id ) {
ActionResult<ActionDelete.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionDelete().execute(request, effectivePerson, id);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.jaxrs.chat;
import com.x.base.core.project.exception.PromptException;
class ChatContentEmptyException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
ChatContentEmptyException() {
super("工作交流内容为空。" );
}
}
package com.x.teamwork.assemble.control.jaxrs.chat;
import com.x.base.core.project.exception.PromptException;
class ChatFlagForQueryEmptyException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
ChatFlagForQueryEmptyException() {
super("查询的工作交流信息ID为空,无法继续查询数据。" );
}
}
package com.x.teamwork.assemble.control.jaxrs.chat;
import com.x.base.core.project.exception.PromptException;
class ChatIDEmptyException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
ChatIDEmptyException() {
super("工作评论信息ID为空。" );
}
}
package com.x.teamwork.assemble.control.jaxrs.chat;
import com.x.base.core.project.exception.PromptException;
class ChatNotExistsException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
ChatNotExistsException( String id ) {
super("指定ID的工作交流信息不存在。ID:" + id );
}
}
package com.x.teamwork.assemble.control.jaxrs.chat;
import com.x.base.core.project.exception.PromptException;
class ChatPersistException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
ChatPersistException( Throwable e ) {
super("系统在保存工作交流信息时发生异常。" , e );
}
ChatPersistException( Throwable e, String message ) {
super("系统在保存工作交流信息时发生异常。Message:" + message, e );
}
ChatPersistException( String message ) {
super("系统在保存工作交流信息时发生异常。Message:" + message );
}
}
package com.x.teamwork.assemble.control.jaxrs.chat;
import com.x.base.core.project.exception.PromptException;
class ChatQueryException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
ChatQueryException( Throwable e ) {
super("系统在查询工作交流信息时发生异常。" , e );
}
ChatQueryException( Throwable e, String message ) {
super("系统在查询工作交流信息时发生异常。Message:" + message, e );
}
ChatQueryException( String message ) {
super("系统在查询工作交流信息时发生异常。Message:" + message );
}
}
package com.x.teamwork.assemble.control.jaxrs.chat;
import com.x.base.core.project.exception.PromptException;
class TaskIDEmptyException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
TaskIDEmptyException() {
super("工作任务信息ID为空。" );
}
}
package com.x.teamwork.assemble.control.jaxrs.chat;
import com.x.base.core.project.exception.PromptException;
class TaskNotExistsException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
TaskNotExistsException( String id ) {
super("指定ID的工作任务信息不存在。ID:" + id );
}
}
package com.x.teamwork.assemble.control.jaxrs.config;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.teamwork.core.entity.SystemConfig;
public class ActionGet extends BaseAction {
private Logger logger = LoggerFactory.getLogger( ActionGet.class );
protected ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id ) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wrap = null;
SystemConfig systemConfig = null;
Boolean check = true;
if( Boolean.TRUE.equals( check ) ){
if( id == null || id.isEmpty() ){
check = false;
Exception exception = new ExceptionConfigIdEmpty();
result.error( exception );
}
}
if( Boolean.TRUE.equals( check ) ){
try {
systemConfig = systemConfigQueryService.get( id );
} catch (Exception e) {
check = false;
Exception exception = new ExceptionConfigInfoProcess( e, "系统根据ID查询指定考勤系统配置信息时发生异常.ID:" + id );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
if( Boolean.TRUE.equals( check ) ){
if( systemConfig == null ) {
try {
systemConfig = systemConfigQueryService.getByCode( id );
} catch (Exception e) {
check = false;
Exception exception = new ExceptionConfigInfoProcess( e, "系统根据ID查询指定考勤系统配置信息时发生异常.CODE:" + id );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
}
if( Boolean.TRUE.equals( check ) ){
try {
wrap = Wo.copier.copy( systemConfig );
result.setData( wrap );
} catch (Exception e) {
check = false;
Exception exception = new ExceptionConfigInfoProcess( e, "将所有查询到的考勤配置信息对象转换为可以输出的信息时发生异常." );
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
}
return result;
}
public static class Wo extends SystemConfig {
private static final long serialVersionUID = -5076990764713538973L;
public static List<String> Excludes = new ArrayList<String>();
public static WrapCopier<SystemConfig, Wo> copier = WrapCopierFactory.wo( SystemConfig.class, Wo.class, null,Wo.Excludes);
}
}
\ No newline at end of file
package com.x.teamwork.assemble.control.jaxrs.config;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.teamwork.assemble.control.service.SystemConfigPersistService;
import com.x.teamwork.assemble.control.service.SystemConfigQueryService;
import com.x.teamwork.assemble.control.service.UserManagerService;
import com.x.teamwork.core.entity.Project;
import net.sf.ehcache.Ehcache;
public class BaseAction extends StandardJaxrsAction{
protected Ehcache configCache = ApplicationCache.instance().getCache( Project.class );
protected SystemConfigQueryService systemConfigQueryService = new SystemConfigQueryService();
protected SystemConfigPersistService systemConfigPersistService = new SystemConfigPersistService();
protected UserManagerService userManagerService = new UserManagerService();
}
package com.x.teamwork.assemble.control.jaxrs.config;
import com.x.base.core.project.exception.PromptException;
class ExceptionConfigCodeEmpty extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
public ExceptionConfigCodeEmpty() {
super("查询操作传入的设置编码Code为空,无法进行查询或者保存操作.");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册