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

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

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;

L
luojing 已提交
10 11
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
R
fix  
roo00 已提交
12
import com.x.base.core.entity.JpaObject;
L
luojing 已提交
13
import com.x.base.core.project.annotation.FieldDescribe;
R
fix  
roo00 已提交
14 15 16 17 18 19 20
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;
L
luojing 已提交
21
import com.x.teamwork.assemble.control.Business;
R
fix  
roo00 已提交
22
import com.x.teamwork.core.entity.Project;
L
luojing 已提交
23
import com.x.teamwork.core.entity.ProjectConfig;
R
fix  
roo00 已提交
24 25
import com.x.teamwork.core.entity.ProjectDetail;
import com.x.teamwork.core.entity.ProjectGroup;
L
luojing 已提交
26
import com.x.teamwork.core.entity.Task;
R
fix  
roo00 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39


public class ActionGet extends BaseAction {

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

	protected ActionResult<Wo> execute(HttpServletRequest request, EffectivePerson effectivePerson, String flag) throws Exception {
		ActionResult<Wo> result = new ActionResult<>();
		Wo wo = null;
		Project project = null;
		ProjectDetail projectDetail = null;
		List<String> groupIds = null;
		List<ProjectGroup> groups = null;
L
luojing 已提交
40
		List<Task>  taskList = null;
L
luojing 已提交
41
		List<ProjectConfig>  projectConfigs = null;
R
fix  
roo00 已提交
42 43
		WrapOutControl control = null;
		Boolean check = true;
L
luojing 已提交
44 45 46 47 48
		
		Integer taskTotal = 0;
		Integer progressTotal = 0;
		Integer completedTotal = 0;
		Integer overtimeTotal = 0;
R
fix  
roo00 已提交
49 50 51 52 53 54 55

		if ( StringUtils.isEmpty( flag ) ) {
			check = false;
			Exception exception = new ProjectFlagForQueryEmptyException();
			result.error( exception );
		}

L
luojing 已提交
56
		/*String cacheKey = ApplicationCache.concreteCacheKey( flag,effectivePerson );
R
fix  
roo00 已提交
57 58 59 60 61
		Element element = projectCache.get( cacheKey );

		if ((null != element) && (null != element.getObjectValue())) {
			wo = (Wo) element.getObjectValue();
			result.setData( wo );
L
luojing 已提交
62
		} else {*/
63
			if( Boolean.TRUE.equals( check ) ){
R
fix  
roo00 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
				try {
					project = projectQueryService.get(flag);
					if ( project == null) {
						check = false;
						Exception exception = new ProjectNotExistsException(flag);
						result.error( exception );
					}
				} catch (Exception e) {
					check = false;
					Exception exception = new ProjectQueryException(e, "根据指定flag查询应用项目信息对象时发生异常。flag:" + flag);
					result.error(exception);
					logger.error(e, effectivePerson, request, null);
				}
			}
			
L
luojing 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
			if( Boolean.TRUE.equals( check ) ){				
				taskList = projectQueryService.listAllTasks(flag , true);
				if( ListTools.isNotEmpty( taskList )) {
					for( Task task : taskList ) {
						taskTotal ++;
						if( "completed".equalsIgnoreCase(task.getWorkStatus()) ) {
							completedTotal++;
						}
						if( "processing".equalsIgnoreCase(task.getWorkStatus()) ) {
							progressTotal++;
						}
						if( task.getOvertime() ) {
							overtimeTotal++;
						}
					}
				}
				
			}
			
98
			if( Boolean.TRUE.equals( check ) ){
R
fix  
roo00 已提交
99 100 101 102 103 104 105
				try {
					wo = Wo.copier.copy( project );
					if( wo.getStarPersonList().contains( effectivePerson.getDistinguishedName() )) {
						wo.setStar( true );
					}					
					//查询项目详情
					projectDetail = projectQueryService.getDetail( project.getId() );
R
roo00 已提交
106 107 108
					if( projectDetail != null ) {
						wo.setDescription( projectDetail.getDescription() );
					}
R
fix  
roo00 已提交
109 110 111 112 113 114
					
					//查询项目组信息
					groupIds = projectGroupQueryService.listGroupIdByProject( project.getId() );
					groups = projectGroupQueryService.list( groupIds );
					wo.setGroups( groups );	
					
L
luojing 已提交
115 116 117
					//查询项目配置信息
					projectConfigs = projectConfigQueryService.getProjectConfigByProject( project.getId() );
					
L
luojing 已提交
118 119 120 121
					Business business = null;
					try (EntityManagerContainer bc = EntityManagerContainerFactory.instance().create()) {
						business = new Business(bc);
					}
L
luojing 已提交
122
					
R
fix  
roo00 已提交
123
					control = new WrapOutControl();
L
luojing 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137
					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);
					}
					
L
luojing 已提交
138 139 140 141 142 143
					if( business.isManager(effectivePerson)
							|| effectivePerson.getDistinguishedName().equalsIgnoreCase( project.getCreatorPerson() )
							|| project.getManageablePersonList().contains( effectivePerson.getDistinguishedName() )) {
						control.setDelete( true );
						control.setEdit( true );
						control.setSortable( true );
L
luojing 已提交
144
						control.setTaskCreate(true);
L
luojing 已提交
145
						
L
luojing 已提交
146 147 148 149
					}else{
						control.setDelete( false );
						control.setEdit( false );
						control.setSortable( false );
L
luojing 已提交
150 151
					}
					if(project.getDeleted() || project.getCompleted()){
L
luojing 已提交
152
						control.setTaskCreate(false);
L
luojing 已提交
153 154 155 156 157
					}
					if(effectivePerson.getDistinguishedName().equalsIgnoreCase( project.getCreatorPerson())){
						control.setFounder( true );
					}else{
						control.setFounder( false );
R
fix  
roo00 已提交
158 159
					}
					wo.setControl(control);
L
luojing 已提交
160 161 162 163 164
					
					wo.setProgressTotal(progressTotal);
					wo.setCompletedTotal(completedTotal);
					wo.setOvertimeTotal(overtimeTotal);
					wo.setTaskTotal(taskTotal);
R
fix  
roo00 已提交
165 166 167 168 169 170 171
					result.setData(wo);
				} catch (Exception e) {
					Exception exception = new ProjectQueryException(e, "将查询出来的应用项目信息对象转换为可输出的数据信息时发生异常。");
					result.error(exception);
					logger.error(e, effectivePerson, request, null);
				}
			}
L
luojing 已提交
172
		//}
R
fix  
roo00 已提交
173 174 175 176 177 178
		return result;
	}

	public static class Wo extends WrapOutProject {
		
		private static final long serialVersionUID = -5076990764713538973L;
L
luojing 已提交
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
		
		@FieldDescribe("所有任务数量")
		private Integer taskTotal = 0;
		
		@FieldDescribe("执行中任务数量")
		private Integer progressTotal = 0;
		
		@FieldDescribe("已完成任务数量")
		private Integer completedTotal = 0;
		
		@FieldDescribe("超时任务数量")
		private Integer overtimeTotal = 0;
		
		public Integer getTaskTotal() {
			return taskTotal;
		}

		public void setTaskTotal(Integer taskTotal) {
			this.taskTotal = taskTotal;
		}
		
		public Integer getProgressTotal() {
			return progressTotal;
		}

		public void setProgressTotal(Integer progressTotal) {
			this.progressTotal = progressTotal;
		}

		public Integer getCompletedTotal() {
			return completedTotal;
		}

		public void setCompletedTotal( Integer completedTotal ) {
			this.completedTotal = completedTotal;
		}

		public Integer getOvertimeTotal() {
			return overtimeTotal;
		}

		public void setOvertimeTotal( Integer overtimeTotal ) {
			this.overtimeTotal = overtimeTotal;
		}
		
R
fix  
roo00 已提交
224 225 226 227 228 229 230

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

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

	}
}