ActionViewOverTimeListNextWithFilter.java 12.4 KB
Newer Older
L
luojing 已提交
1 2 3 4 5 6 7 8 9 10
package com.x.teamwork.assemble.control.jaxrs.task;

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

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;

import com.google.gson.JsonElement;
L
luojing 已提交
11 12
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
L
luojing 已提交
13 14 15 16 17 18 19 20 21 22 23
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.gson.GsonPropertyObject;
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 已提交
24
import com.x.teamwork.assemble.control.Business;
L
luojing 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
import com.x.teamwork.core.entity.Task;
import com.x.teamwork.core.entity.TaskTag;
import com.x.teamwork.core.entity.tools.filter.QueryFilter;
import com.x.teamwork.core.entity.tools.filter.term.EqualsTerm;
import com.x.teamwork.core.entity.tools.filter.term.IsFalseTerm;
import com.x.teamwork.core.entity.tools.filter.term.LikeTerm;

import net.sf.ehcache.Element;

public class ActionViewOverTimeListNextWithFilter extends BaseAction {

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

	protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, String flag, Integer count, String projectId, JsonElement jsonElement ) throws Exception {
		ActionResult<List<Wo>> result = new ActionResult<>();		
		List<Wo> wos = new ArrayList<>();
		ResultObject resultObject = null;
		Wi wrapIn = null;
		Boolean check = true;
		String cacheKey = null;
		Element element = null;
		QueryFilter  queryFilter = null;
		List<TaskTag> tags = null; 
L
luojing 已提交
48
		WrapOutControl control = null;
L
luojing 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
		
		if ( StringUtils.isEmpty( projectId ) ) {
			check = false;
			Exception exception = new TaskProjectFlagForQueryEmptyException();
			result.error( exception );
		}
		if ( StringUtils.isEmpty( flag ) || "(0)".equals(flag)) {
			flag = null;
		}
		
		try {
			wrapIn = this.convertToWrapIn(jsonElement, Wi.class);
		} catch (Exception e) {
			check = false;
			Exception exception = new TaskQueryException(e, "系统在将JSON信息转换为对象时发生异常。JSON:" + jsonElement.toString());
			result.error(exception);
			logger.error(e, effectivePerson, request, null);
		}
		
		if( Boolean.TRUE.equals( check ) ){
			if( Boolean.TRUE.equals( check ) ){
				wrapIn.setProject(projectId);
				wrapIn.setOvertime("true");
L
luojing 已提交
72
				wrapIn.setDeleted("false");
L
luojing 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85
				queryFilter = wrapIn.getQueryFilter();
			}
		}
		
		if( Boolean.TRUE.equals( check ) ){
			cacheKey = ApplicationCache.concreteCacheKey( "ActionOverTimeListNext", effectivePerson.getDistinguishedName(), 
					flag, count, wrapIn.getOrderField(), wrapIn.getOrderType(), queryFilter.getContentSHA1() );
			element = taskCache.get( cacheKey );
			
			if ((null != element) && (null != element.getObjectValue())) {
				resultObject = (ResultObject) element.getObjectValue();
				result.setCount( resultObject.getTotal() );
				result.setData( resultObject.getWos() );
L
luojing 已提交
86 87 88 89 90
			} else {		
				Business business = null;
				try (EntityManagerContainer bc = EntityManagerContainerFactory.instance().create()) {
					business = new Business(bc);
				}
L
luojing 已提交
91 92 93 94 95 96 97 98 99 100 101 102
				try {
					
					Long total = taskQueryService.countWithFilter( effectivePerson, queryFilter );
					List<Task> taskList = taskQueryService.listWithFilter( effectivePerson, count, flag, wrapIn.getOrderField(), wrapIn.getOrderType(), queryFilter );
					
					if( ListTools.isNotEmpty( taskList )) {
						wos = Wo.copier.copy(taskList);
						for( Wo wo : wos ) {
							tags = taskTagQueryService.listWithTaskAndPerson(effectivePerson, wo );
							if( ListTools.isNotEmpty( tags )) {
								wo.setTags( WoTaskTag.copier.copy( tags ));
							}
L
luojing 已提交
103 104 105 106
							try {
								control = new WrapOutControl();
								if( business.isManager(effectivePerson) 
										|| effectivePerson.getDistinguishedName().equalsIgnoreCase( wo.getCreatorPerson() )
107
										|| (ListTools.isNotEmpty(wo.getManageablePersonList()) && wo.getManageablePersonList().contains( effectivePerson.getDistinguishedName() ))){
L
luojing 已提交
108 109 110 111 112 113 114 115
									control.setDelete( true );
									control.setSortable( true );
									control.setChangeExecutor(true);
								}else{
									control.setDelete( false );
									control.setSortable( false );
									control.setChangeExecutor(false);
								}
116
								control.setEdit( true );
L
luojing 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
								if(effectivePerson.getDistinguishedName().equalsIgnoreCase( wo.getExecutor())){
									control.setChangeExecutor( true );
								}
								if(effectivePerson.getDistinguishedName().equalsIgnoreCase( wo.getCreatorPerson())){
									control.setFounder( true );
								}else{
									control.setFounder( false );
								}
								wo.setControl(control);
							} catch (Exception e) {
								check = false;
								Exception exception = new TaskQueryException(e, "根据指定flag查询工作任务权限信息时发生异常。flag:" + wo.getId());
								result.error(exception);
								logger.error(e, effectivePerson, request, null);
							}
L
luojing 已提交
132 133 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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
						}
					}

					resultObject = new ResultObject( total, wos );
					taskCache.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  GsonPropertyObject{
		@FieldDescribe("用于排列的属性,非必填,默认为createTime.")
		private String orderField = "createTime";

		@FieldDescribe("排序方式:DESC | ASC,非必填,默认为DESC.")
		private String orderType = "DESC";
		
		@FieldDescribe("用于搜索的标题,单值,非必填.")
		private String title = null;
		
		private String project = null;
		
		@FieldDescribe("用于搜索的上级工作任务ID,单值,非必填.")
		private String parentId = null;
		
		@FieldDescribe("用于搜索的工作标签:自定义标签,单值,非必填.")
		private String tag = null;
		
		@FieldDescribe("工作等级:普通-normal | 紧急-urgent | 特急-extraurgent,单值,非必填")
		private String priority = null;		
		
		@FieldDescribe("用于搜索的工作状态:草稿- draft  | 执行中- processing | 已完成- completed | 已归档- archived,单值,非必填")
		private String workStatus = null;
		
		@FieldDescribe("是否已完成,true|false,非必填")
		private String completed = null;		

		private String overtime = null;		
		
		@FieldDescribe("是否已经删除,true|false,非必填")
		private String deleted = null;		
		
		@FieldDescribe("执行者或者负责人,单值,非必填")
		private String executor = null;		

		private Long rank = 0L;

		public String getOrderField() {
			return orderField;
		}

		public void setOrderField(String orderField) {
			this.orderField = orderField;
		}

		public String getOrderType() {
			return orderType;
		}

		public void setOrderType(String orderType) {
			this.orderType = orderType;
		}

		public String getTitle() {
			return title;
		}

		public void setTitle(String title) {
			this.title = title;
		}

		public Long getRank() {
			return rank;
		}

		public void setRank(Long rank) {
			this.rank = rank;
		}

		public String getProject() {
			return project;
		}

		public void setProject(String project) {
			this.project = project;
		}

		public String getParentId() {
			return parentId;
		}

		public void setParentId(String parentId) {
			this.parentId = parentId;
		}

		public String getTag() {
			return tag;
		}

		public void setTag(String tag) {
			this.tag = tag;
		}

		public String getPriority() {
			return priority;
		}

		public void setPriority(String priority) {
			this.priority = priority;
		}

		public String getWorkStatus() {
			return workStatus;
		}

		public void setWorkStatus(String workStatus) {
			this.workStatus = workStatus;
		}

		public String getCompleted() {
			return completed;
		}

		public void setCompleted(String completed) {
			this.completed = completed;
		}

		public String getOvertime() {
			return overtime;
		}

		public void setOvertime(String overtime) {
			this.overtime = overtime;
		}

		public String getDeleted() {
			return deleted;
		}

		public void setDeleted(String deleted) {
			this.deleted = deleted;
		}

		public String getExecutor() {
			return executor;
		}

		public void setExecutor(String executor) {
			this.executor = executor;
		}
		
		/**
		 * 根据传入的查询参数,组织一个完整的QueryFilter对象
		 * @return
		 */
		public QueryFilter getQueryFilter() {
			QueryFilter queryFilter = new QueryFilter();
			//组织查询条件对象
			if( StringUtils.isNotEmpty( this.getTitle() )) {
				queryFilter.addLikeTerm( new LikeTerm( "name", "%" + this.getTitle() + "%" ) );
			}
			if( StringUtils.isNotEmpty( this.getProject() )) {
				queryFilter.addEqualsTerm( new EqualsTerm( "project", this.getProject() ) );
			}
			if( StringUtils.isNotEmpty( this.getParentId() )) {
				queryFilter.addEqualsTerm( new EqualsTerm( "parent", this.getParentId() ) );
			}
			if( StringUtils.isNotEmpty( this.getPriority())) {
				queryFilter.addEqualsTerm( new EqualsTerm( "priority", this.getPriority() ) );
			}
			if( StringUtils.isNotEmpty( this.getWorkStatus() )) {
				queryFilter.addEqualsTerm( new EqualsTerm( "workStatus", this.getWorkStatus() ) );
			}else {
				//默认查询所有的未归档的工作任务
				queryFilter.addIsFalseTerm( new IsFalseTerm("archive"));
			}
			if( StringUtils.isNotEmpty( this.getExecutor())) {
				queryFilter.addEqualsTerm( new EqualsTerm( "executor", this.getExecutor() ) );
			}
			if( StringUtils.isNotEmpty( this.getCompleted() )) {
				if( "true".equalsIgnoreCase( this.getCompleted() )) {
					queryFilter.addEqualsTerm( new EqualsTerm( "completed", true ) );
				}else {
					queryFilter.addEqualsTerm( new EqualsTerm( "completed", false ) );
				}
			}
			if( StringUtils.isNotEmpty( this.getDeleted() )) {
				if( "true".equalsIgnoreCase( this.getDeleted() )) {
					queryFilter.addEqualsTerm( new EqualsTerm( "deleted", true ) );
				}else {
					queryFilter.addEqualsTerm( new EqualsTerm( "deleted", false ) );
				}
			}
			if( StringUtils.isNotEmpty( this.getOvertime() )) {
				if( "true".equalsIgnoreCase( this.getOvertime() )) {
					queryFilter.addEqualsTerm( new EqualsTerm( "overtime", true ) );
				}else {
					queryFilter.addEqualsTerm( new EqualsTerm( "overtime", false ) );
				}
			}
			return queryFilter;
		}
	}
	
	public static class Wo extends Task {

		@FieldDescribe("任务标签")
		private List<WoTaskTag> tags = null;
		
L
luojing 已提交
350 351 352
		@FieldDescribe("任务权限")
		private WrapOutControl control = null;	
		
L
luojing 已提交
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
		public List<WoTaskTag> getTags() {
			return tags;
		}

		public void setTags(List<WoTaskTag> tags) {
			this.tags = tags;
		}
		
		private Long rank;

		public Long getRank() {
			return rank;
		}

		public void setRank(Long rank) {
			this.rank = rank;
		}

L
luojing 已提交
371 372 373 374 375 376 377
		public WrapOutControl getControl() {
			return control;
		}

		public void setControl(WrapOutControl control) {
			this.control = control;
		}
L
luojing 已提交
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
		private static final long serialVersionUID = -5076990764713538973L;

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

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

	}
	
	public static class WoTaskTag extends TaskTag {
		
		private static final long serialVersionUID = -5076990764713538973L;

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

		static WrapCopier<TaskTag, WoTaskTag> copier = WrapCopierFactory.wo( TaskTag.class, WoTaskTag.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;
		}
	}
}