package com.x.teamwork.assemble.control.jaxrs.project; 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.container.EntityManagerContainer; import com.x.base.core.container.factory.EntityManagerContainerFactory; 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.cache.ApplicationCache; 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.assemble.control.Business; import com.x.teamwork.core.entity.Project; import com.x.teamwork.core.entity.ProjectConfig; import com.x.teamwork.core.entity.tools.filter.QueryFilter; import com.x.teamwork.core.entity.tools.filter.term.InTerm; import net.sf.ehcache.Element; public class ActionListNextWithFilter extends BaseAction { private static Logger logger = LoggerFactory.getLogger(ActionListNextWithFilter.class); protected ActionResult> execute( HttpServletRequest request, EffectivePerson effectivePerson, String flag, Integer count, JsonElement jsonElement ) throws Exception { ActionResult> result = new ActionResult<>(); ResultObject resultObject = null; List wos = new ArrayList<>(); Wi wrapIn = null; Boolean check = true; String cacheKey = null; Element element = null; QueryFilter queryFilter = null; List queryProjectIds = new ArrayList<>(); if ( StringUtils.isEmpty( flag ) || "(0)".equals(flag)) { flag = null; } try { wrapIn = this.convertToWrapIn(jsonElement, Wi.class); } catch (Exception e) { check = false; Exception exception = new ProjectQueryException(e, "系统在将JSON信息转换为对象时发生异常。JSON:" + jsonElement.toString()); result.error(exception); logger.error(e, effectivePerson, request, null); } if( Boolean.TRUE.equals( check ) ){ if( wrapIn == null ) { wrapIn = new Wi(); } queryFilter = wrapIn.getQueryFilter(); if( StringUtils.isNotEmpty( wrapIn.getGroup() )) { //如果项目分组不为空,那么需要先根据项目分组来查询这个分组下的所有项目ID集合 List projectIds = projectGroupQueryService.listProjectIdByGroup( wrapIn.getGroup() ); if( ListTools.isEmpty( projectIds )) { queryProjectIds.add("0000-0000-0000"); }else { for( String projectId : projectIds ) { queryProjectIds.add( projectId ); } } queryFilter.addInTerm( new InTerm("id", new ArrayList(queryProjectIds) )); } } if( Boolean.TRUE.equals( check ) ){ /*采用缓存 * cacheKey = ApplicationCache.concreteCacheKey( "ActionListNextWithFilter", effectivePerson.getDistinguishedName(), flag, count, wrapIn.getOrderField(), wrapIn.getOrderType(), queryFilter.getContentSHA1() ); element = projectCache.get( cacheKey ); if ((null != element) && (null != element.getObjectValue())) { resultObject = (ResultObject) element.getObjectValue(); result.setCount( resultObject.getTotal() ); result.setData( resultObject.getWos() ); } else {*/ try { //获取用户能查看的所有的项目信息ID列表,最多查询2000条数据 List projectIds = projectQueryService.listAllViewableProjectIds( effectivePerson, 2000, queryFilter ); if( ListTools.isNotEmpty( projectIds )) { //直接根据可见项目ID列表进行分页查询 Long total = Long.parseLong( projectIds.size() + "" ); List projectList = projectQueryService.listWithProjectIdFilter( count, flag, wrapIn.getOrderField(), wrapIn.getOrderType(), projectIds ); if( ListTools.isNotEmpty( projectList )) { WrapOutControl control = null; for( Project project : projectList ) { Wo wo = Wo.copier.copy(project); wo.setDescription( projectQueryService.getDescription( project.getId())); if( wo.getStarPersonList().contains( effectivePerson.getDistinguishedName() )) { wo.setStar( true ); } Business business = null; try (EntityManagerContainer bc = EntityManagerContainerFactory.instance().create()) { business = new Business(bc); } //查询项目配置信息 List projectConfigs = null; projectConfigs = projectConfigQueryService.getProjectConfigByProject( project.getId() ); control = new WrapOutControl(); if(ListTools.isNotEmpty(projectConfigs)){ ProjectConfig projectConfig = projectConfigs.get(0); control.setTaskCreate(projectConfig.getTaskCreate()); control.setTaskCopy(projectConfig.getTaskCopy()); control.setTaskRemove(projectConfig.getTaskRemove()); control.setLaneCreate(projectConfig.getLaneCreate()); control.setLaneEdit(projectConfig.getLaneEdit()); control.setLaneRemove(projectConfig.getLaneRemove()); control.setAttachmentUpload(projectConfig.getAttachmentUpload()); control.setComment(projectConfig.getComment()); }else{ control.setTaskCreate(true); } if( business.isManager(effectivePerson) || effectivePerson.getDistinguishedName().equalsIgnoreCase( project.getCreatorPerson() ) || project.getManageablePersonList().contains( effectivePerson.getDistinguishedName() )) { control.setDelete( true ); control.setEdit( true ); control.setSortable( true ); control.setTaskCreate(true); }else{ control.setDelete( false ); control.setEdit( false ); control.setSortable( false ); } if(effectivePerson.getDistinguishedName().equalsIgnoreCase( project.getCreatorPerson())){ control.setFounder( true ); }else{ control.setFounder( false ); } if(project.getDeleted() || project.getCompleted()){ control.setTaskCreate(false); } wo.setControl(control); wos.add( wo ); } } resultObject = new ResultObject( total, wos ); //projectCache.put(new Element( cacheKey, resultObject )); result.setCount( resultObject.getTotal() ); result.setData( resultObject.getWos() ); } } catch (Exception e) { check = false; logger.warn("系统查询项目信息列表时发生异常!"); result.error(e); logger.error(e, effectivePerson, request, null); } //} } return result; } public static class Wi extends WrapInQueryProject{ } public static class Wo extends WrapOutProject { private static final long serialVersionUID = -5076990764713538973L; public static List Excludes = new ArrayList(); static WrapCopier copier = WrapCopierFactory.wo( Project.class, Wo.class, null, ListTools.toList(JpaObject.FieldsInvisible)); } public static class ResultObject { private Long total; private List wos; public ResultObject() {} public ResultObject(Long count, List data) { this.total = count; this.wos = data; } public Long getTotal() { return total; } public void setTotal(Long total) { this.total = total; } public List getWos() { return wos; } public void setWos(List wos) { this.wos = wos; } } }