ActionListPageInGroupWithFilter.java 6.2 KB
Newer Older
R
roo00 已提交
1
package com.x.teamwork.assemble.control.jaxrs.project;
R
fix  
roo00 已提交
2 3 4 5 6 7 8

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.google.gson.JsonElement;
L
luojing 已提交
9 10
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
R
fix  
roo00 已提交
11 12 13 14 15 16 17 18 19
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;
L
luojing 已提交
20
import com.x.teamwork.assemble.control.Business;
R
fix  
roo00 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
import com.x.teamwork.core.entity.Project;
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 ActionListPageInGroupWithFilter extends BaseAction {

	private static Logger logger = LoggerFactory.getLogger(ActionListPageInGroupWithFilter.class);

	protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, Integer pageNum, Integer count, String groupId, JsonElement jsonElement ) throws Exception {
		ActionResult<List<Wo>> result = new ActionResult<>();
		List<Wo> wos = new ArrayList<>();
		ResultObject resultObject = null;
		Wi wrapIn = null;
		Boolean check = true;
L
luojing 已提交
37 38
		//String cacheKey = null;
		//Element element = null;
R
fix  
roo00 已提交
39 40 41 42 43 44 45 46 47 48 49 50
		QueryFilter  queryFilter = null;
		List<String> queryProjectIds = new ArrayList<>();

		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);
		}
		
51
		if( Boolean.TRUE.equals( check ) ){
R
fix  
roo00 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
			if( wrapIn == null ) {
				wrapIn = new Wi();
			}
			queryFilter = wrapIn.getQueryFilter();
			List<String> projectIds = projectGroupQueryService.listProjectIdByGroup( groupId );
			if( ListTools.isEmpty( projectIds )) {
				queryProjectIds.add("0000-0000-0000");
			}else {
				for( String projectId : projectIds ) {
					queryProjectIds.add( projectId );
				}
			}
			queryFilter.addInTerm( new InTerm("id", new ArrayList<Object>(queryProjectIds) ));
		}
		
L
luojing 已提交
67
		/*if( Boolean.TRUE.equals( check ) ){
R
fix  
roo00 已提交
68 69 70 71
			
			cacheKey = ApplicationCache.concreteCacheKey( "ActionListPageWithFilter", effectivePerson.getDistinguishedName(), 
					pageNum, count, wrapIn.getOrderField(), wrapIn.getOrderType(), queryFilter.getContentSHA1() );
			element = projectCache.get( cacheKey );
L
luojing 已提交
72
		}*/
R
fix  
roo00 已提交
73
		
74
		if( Boolean.TRUE.equals( check ) ){
L
luojing 已提交
75
			/*if ((null != element) && (null != element.getObjectValue())) {
R
fix  
roo00 已提交
76 77 78
				resultObject = (ResultObject) element.getObjectValue();
				result.setCount( resultObject.getTotal() );
				result.setData( resultObject.getWos() );
L
luojing 已提交
79
			} else {*/				
R
roo00 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
				try {
					//获取用户能查看的所有的项目信息ID列表,最多查询2000条数据
					List<String>  projectIds = projectQueryService.listAllViewableProjectIds( effectivePerson, 2000, queryFilter );
					if( ListTools.isNotEmpty( projectIds )) {
						//直接根据可见项目ID列表进行分页查询
						Long total = Long.parseLong( projectIds.size() + "" );
						List<Project> projectList = projectQueryService.listWithProjectIdsFilter( count, pageNum, 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 );
								}
L
luojing 已提交
95 96 97 98 99
								
								Business business = null;
								try (EntityManagerContainer bc = EntityManagerContainerFactory.instance().create()) {
									business = new Business(bc);
								}
R
roo00 已提交
100
								control = new WrapOutControl();
L
luojing 已提交
101
								if( business.isManager(effectivePerson) 
R
roo00 已提交
102 103
										|| effectivePerson.getDistinguishedName().equalsIgnoreCase( project.getCreatorPerson() )
										|| project.getManageablePersonList().contains( effectivePerson.getDistinguishedName() )) {
L
luojing 已提交
104 105 106 107 108 109 110 111 112 113 114 115
									control.setDelete( true );
									control.setEdit( true );
									control.setSortable( true );
								}else{
									control.setDelete( false );
									control.setEdit( false );
									control.setSortable( false );
								}
								if(effectivePerson.getDistinguishedName().equalsIgnoreCase( project.getCreatorPerson())){
									control.setFounder( true );
								}else{
									control.setFounder( false );
R
roo00 已提交
116 117 118
								}
								wo.setControl(control);
								wos.add( wo );
R
fix  
roo00 已提交
119 120 121
							}
						}

R
roo00 已提交
122
						resultObject = new ResultObject( total, wos );
L
luojing 已提交
123
						//projectCache.put(new Element( cacheKey, resultObject ));
R
roo00 已提交
124 125 126
						result.setCount( resultObject.getTotal() );
						result.setData( resultObject.getWos() );
					}
R
fix  
roo00 已提交
127 128 129 130 131 132
				} catch (Exception e) {
					check = false;
					logger.warn("系统查询项目信息列表时发生异常!");
					result.error(e);
					logger.error(e, effectivePerson, request, null);
				}
L
luojing 已提交
133
			//}		
R
fix  
roo00 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
		}
		return result;
	}

	public static class Wi extends WrapInQueryProject{		
	}
	
	public static class Wo extends WrapOutProject {

		private static final long serialVersionUID = -5076990764713538973L;

		public static List<String> Excludes = new ArrayList<String>();

		static WrapCopier<Project, Wo> copier = WrapCopierFactory.wo( Project.class, Wo.class, null, ListTools.toList(JpaObject.FieldsInvisible));

	}
	
	public static class ResultObject {

		private Long total;
		
		private List<Wo> wos;

		public ResultObject() {}
		
		public ResultObject(Long count, List<Wo> data) {
			this.total = count;
			this.wos = data;
		}

		public Long getTotal() {
			return total;
		}

		public void setTotal(Long total) {
			this.total = total;
		}

		public List<Wo> getWos() {
			return wos;
		}

		public void setWos(List<Wo> wos) {
			this.wos = wos;
		}
	}
}