ProjectService.java 10.0 KB
Newer Older
R
roo00 已提交
1
package com.x.teamwork.assemble.control.service;
R
fix  
roo00 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.entity.annotation.CheckRemoveType;
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.ProjectDetail;
15
import com.x.teamwork.core.entity.CustomExtFieldRele;
L
luojing 已提交
16
import com.x.teamwork.core.entity.Review;
R
fix  
roo00 已提交
17
import com.x.teamwork.core.entity.Task;
L
luojing 已提交
18 19 20
import com.x.teamwork.core.entity.TaskDetail;
import com.x.teamwork.core.entity.TaskGroupRele;
import com.x.teamwork.core.entity.TaskListRele;
R
fix  
roo00 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
import com.x.teamwork.core.entity.tools.filter.QueryFilter;

class ProjectService {

	/**
	 * 根据项目的标识查询项目的信息
	 * @param emc
	 * @param flag  主要是ID
	 * @return
	 * @throws Exception 
	 */
	protected Project get(EntityManagerContainer emc, String flag) throws Exception {
		Business business = new Business( emc );
		return business.projectFactory().get( flag );
	}
	
	protected ProjectDetail getDetail(EntityManagerContainer emc, String id) throws Exception {
		Business business = new Business( emc );
		return business.projectFactory().getDetail( id );
	}
	
R
roo00 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
//	/**
//	 * 根据过滤条件查询符合要求的项目信息数量
//	 * @param emc
//	 * @param personName
//	 * @param identityNames
//	 * @param unitNames
//	 * @param groupNames
//	 * @param group 项目分组
//	 * @param title
//	 * @return
//	 * @throws Exception
//	 */
//	protected Long countWithFilter( EntityManagerContainer emc, String personName, List<String> identityNames, List<String> unitNames, List<String> groupNames, QueryFilter queryFilter ) throws Exception {
//		Business business = new Business( emc );	
//		return business.projectFactory().countWithFilter( personName, identityNames, unitNames, groupNames, queryFilter );
//	}
R
fix  
roo00 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
	
	/**
	 * 根据过滤条件查询符合要求的项目信息列表
	 * @param emc
	 * @param maxCount
	 * @param orderField
	 * @param orderType
	 * @param personName
	 * @param identityNames
	 * @param unitNames
	 * @param groupNames
	 * @param group  项目分组
	 * @param title
	 * @return
	 * @throws Exception
	 */
	protected List<Project> listWithFilter( EntityManagerContainer emc, Integer maxCount, String orderField, String orderType, String personName, List<String> identityNames, List<String> unitNames, List<String> groupNames, QueryFilter queryFilter ) throws Exception {
		Business business = new Business( emc );
		return business.projectFactory().listWithFilter(maxCount, orderField, orderType, personName, identityNames, unitNames, groupNames, queryFilter);
	}
	
79 80 81 82 83 84 85 86 87 88 89 90 91
	/**
	 * 根据过滤条件查询符合要求的项目信息列表
	 * @param emc
	 * @param projectId
	 * @param deleted
	 * @return
	 * @throws Exception
	 */
	protected List<Task> listAllTasks( EntityManagerContainer emc,  String projectId, Boolean deleted) throws Exception {
		Business business = new Business( emc );
		return business.projectFactory().listAllTasks(projectId, deleted);
	}
	
R
fix  
roo00 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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
	/**
	 * 根据条件查询符合条件的项目信息ID,根据上一条的sequnce查询指定数量的信息
	 * @param emc
	 * @param maxCount
	 * @param sequnce
	 * @param orderField
	 * @param orderType
	 * @param personName
	 * @param identityNames
	 * @param unitNames
	 * @param groupNames
	 * @param group   项目分组
	 * @param title
	 * @return
	 * @throws Exception
	 */
	protected List<Project> listWithFilter( EntityManagerContainer emc, Integer maxCount, String sequnce, String orderField, String orderType, String personName, List<String> identityNames, List<String> unitNames, List<String> groupNames, QueryFilter queryFilter ) throws Exception {
		Business business = new Business( emc );
		return business.projectFactory().listWithFilter(maxCount, sequnce, orderField, orderType, personName, identityNames, unitNames, groupNames, queryFilter);
	}

	/**
	 * 向数据库持久化项目信息
	 * @param emc
	 * @param projectDetail 
	 * @param project
	 * @return
	 * @throws Exception 
	 */
	protected Project save( EntityManagerContainer emc, Project object, ProjectDetail detail ) throws Exception {
		Project project = null;
		ProjectDetail projectDetail = null;
		if( StringUtils.isEmpty( object.getId() )  ){
			object.setId( Project.createId() );
		}
		
		project = emc.find( object.getId(), Project.class );
		projectDetail = emc.find( object.getId(), ProjectDetail.class );
		
		emc.beginTransaction( Project.class );
		emc.beginTransaction( ProjectDetail.class );
		
		if( project == null ){ // 保存一个新的对象
			project = new Project();
			object.copyTo( project );
			if( StringUtils.isNotEmpty( object.getId() ) ){
				project.setId( object.getId() );
			}
			emc.persist( project, CheckPersistType.all);
		}else{ //对象已经存在,更新对象信息
			if( StringUtils.isNotEmpty( project.getCreatorPerson() )) {
				object.setCreatorPerson( project.getCreatorPerson() );
			}
			object.copyTo( project, JpaObject.FieldsUnmodify  );
			emc.check( project, CheckPersistType.all );	
		}
		
		if( projectDetail == null ){ // 保存一个新的对象
			projectDetail = new ProjectDetail();
			detail.copyTo( projectDetail );
			projectDetail.setId( object.getId() );
			emc.persist( projectDetail, CheckPersistType.all);
		}else{ //对象已经存在,更新对象信息
			detail.copyTo( projectDetail, JpaObject.FieldsUnmodify  );
			projectDetail.setId( object.getId() );
			emc.check( projectDetail, CheckPersistType.all );	
		}
		emc.commit();
		return project;
	}

	/**
	 * 根据项目标识删除项目信息
	 * @param emc
	 * @param id
	 * @throws Exception 
	 */
L
luojing 已提交
169
	protected void delete(EntityManagerContainer emc, String id ) throws Exception {
R
fix  
roo00 已提交
170 171 172 173 174 175 176
		Business business = new Business( emc );
		Project project = emc.find( id, Project.class );
		if( project != null ) {
			//这里要先递归删除所有的任务信息
			emc.beginTransaction( Task.class );
			emc.beginTransaction( Project.class );
			if( project != null ) {
L
luojing 已提交
177 178 179 180
				//emc.remove( project , CheckRemoveType.all );
				//改为软删除
				project.setDeleted(true);
				emc.check( project , CheckPersistType.all );
181
			}			
R
fix  
roo00 已提交
182 183 184 185 186
			//还需要删除所有的Task
			List<String> ids = business.taskFactory().listByProject( id );
			List<Task> tasks = business.taskFactory().list(ids);
			if( ListTools.isNotEmpty(tasks)) {
				for( Task task : tasks ) {
187 188 189
					//this.remove( emc, task.getId() ); 
					task.setRelation(true);
					emc.check( task, CheckPersistType.all );	
R
fix  
roo00 已提交
190 191 192 193
				}
			}
			emc.commit();
		}
R
roo00 已提交
194
	}
L
luojing 已提交
195 196 197 198 199 200 201 202
	/**
	 * 根据工作任务标识删除工作任务信息(物理删除)
	 * @param emc
	 * @param flag 主要是ID
	 * @throws Exception 
	 */
	public void remove( EntityManagerContainer emc, String flag ) throws Exception {
		emc.beginTransaction( Task.class );
203
/*		emc.beginTransaction( Review.class );
L
luojing 已提交
204 205
		emc.beginTransaction( TaskDetail.class );
		emc.beginTransaction( TaskListRele.class );
206
		emc.beginTransaction( TaskGroupRele.class );*/
L
luojing 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
		removeTaskWithChildren( emc, flag);		
		emc.commit();
	}
	/**
	 * 根据工作任务标识删除工作任务信息( 物理删除 )
	 * @param emc
	 * @param id
	 * @throws Exception 
	 */
	private void removeTaskWithChildren( EntityManagerContainer emc, String id ) throws Exception {
		Business business = new Business( emc );
		
		//还需要递归删除所有的下级Task
		List<String> childrenIds = business.taskFactory().listByParent( id );
		if( ListTools.isNotEmpty( childrenIds )) {
			for( String _id : childrenIds ) {
				removeTaskWithChildren( emc, _id );
			}
		}
		
227
		/*//任务列表中的关联信息
L
luojing 已提交
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
		List<TaskListRele> listReles = business.taskListFactory().listReleWithTask(  id );
		if( ListTools.isNotEmpty( listReles )) {
			for( TaskListRele taskListRele : listReles ) {
				emc.remove( taskListRele , CheckRemoveType.all );
			}
		}
		
		//删除任务组关联信息
		List<TaskGroupRele> groupReles = business.taskGroupReleFactory().listTaskReleWithTask( id );
		if( ListTools.isNotEmpty( groupReles )) {
			for( TaskGroupRele taskGroupRele : groupReles ) {
				emc.remove( taskGroupRele , CheckRemoveType.all );
			}
		}
		TaskDetail taskDetail = emc.find( id, TaskDetail.class );
		List<Review> reviewList = null;
		List<List<String>> reviewIdBatchs = null;
		List<String> reviewIds = business.reviewFactory().listReviewByTask( id, 9999 );
		if( ListTools.isNotEmpty( reviewIds )) {
			reviewIdBatchs = ListTools.batch( reviewIds, 1000 );
		}
		if( ListTools.isNotEmpty( reviewIdBatchs )) {
			for( List<String> batch : reviewIdBatchs ) {
				reviewList = emc.list( Review.class, batch );
				if( ListTools.isNotEmpty( reviewList )) {
					for( Review review : reviewList ) {
						//emc.remove( review, CheckRemoveType.all );
						//改为软删除
						review.setDeleted(true);
						emc.check( review, CheckPersistType.all );
					}
				}
			}
		}
262 263 264 265
		if( taskDetail != null ) {
		emc.remove( taskDetail , CheckRemoveType.all );
		}*/
		Task task = emc.find( id, Task.class );
L
luojing 已提交
266 267 268
		if( task != null ) {
			//emc.remove( task , CheckRemoveType.all );
			//改为软删除
269 270
			//task.setDeleted(true); 
			task.setRelation(true);
L
luojing 已提交
271 272
			emc.check( task, CheckPersistType.all );	
		}
273
		
L
luojing 已提交
274
	}
R
roo00 已提交
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295

	/**
	 * 根据条件查询项目ID列表,最大查询2000条
	 * @param emc
	 * @param maxCount
	 * @param personName
	 * @param identityNames
	 * @param unitNames
	 * @param groupNames
	 * @param queryFilter
	 * @return
	 * @throws Exception
	 */
	public List<String> listAllViewableProjectIds(EntityManagerContainer emc, int maxCount, String personName, List<String> identityNames, List<String> unitNames, List<String> groupNames, QueryFilter queryFilter) throws Exception {
		Business business = new Business( emc );
		return business.projectFactory().listAllViewableProjectIds(maxCount, personName, identityNames, unitNames, groupNames, queryFilter);
	}

	public List<String> listAllProjectIds(EntityManagerContainer emc ) throws Exception {
		Business business = new Business( emc );
		return business.projectFactory().listAllProjectIds();
R
fix  
roo00 已提交
296 297
	}	
}