ActionSave.java 7.5 KB
Newer Older
R
roo00 已提交
1
package com.x.teamwork.assemble.control.jaxrs.project;
R
fix  
roo00 已提交
2

R
roo00 已提交
3
import java.util.ArrayList;
R
fix  
roo00 已提交
4 5 6 7 8
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.google.gson.JsonElement;
R
roo00 已提交
9
import com.x.base.core.entity.JpaObject;
R
fix  
roo00 已提交
10 11 12 13 14 15 16 17 18 19
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.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
R
roo00 已提交
20 21
import com.x.teamwork.assemble.control.service.BatchOperationPersistService;
import com.x.teamwork.assemble.control.service.BatchOperationProcessService;
R
roo00 已提交
22
import com.x.teamwork.core.entity.Dynamic;
R
fix  
roo00 已提交
23 24 25
import com.x.teamwork.core.entity.Project;
import com.x.teamwork.core.entity.ProjectDetail;
import com.x.teamwork.core.entity.ProjectGroup;
R
roo00 已提交
26
import com.x.teamwork.core.entity.Task;
R
fix  
roo00 已提交
27 28 29 30 31 32 33 34

public class ActionSave extends BaseAction {

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

	protected ActionResult<Wo> execute(HttpServletRequest request, EffectivePerson effectivePerson, JsonElement jsonElement ) throws Exception {
		ActionResult<Wo> result = new ActionResult<>();
		Project project = null;
R
roo00 已提交
35
		Project old_project = null;
R
fix  
roo00 已提交
36
		Wi wi = null;
R
roo00 已提交
37
		Wo wo = new Wo();
R
fix  
roo00 已提交
38 39 40 41 42 43 44 45 46 47 48
		Boolean check = true;

		try {
			wi = this.convertToWrapIn( jsonElement, Wi.class );
		} catch (Exception e) {
			check = false;
			Exception exception = new ProjectPersistException(e, "系统在将JSON信息转换为对象时发生异常。JSON:" + jsonElement.toString());
			result.error(exception);
			logger.error(e, effectivePerson, request, null);
		}
		
49
		if( Boolean.TRUE.equals( check ) ){
R
fix  
roo00 已提交
50 51 52 53 54 55 56
			if ( !projectPersistService.checkPermissionForPersist( effectivePerson, systemConfigQueryService.getValueByCode("PROJECT_CREATOR")) ) {
				check = false;
				Exception exception = new ProjectPersistException("project save permission denied!" );
				result.error(exception);
			}
		}
		
57
		if( Boolean.TRUE.equals( check ) ){
R
roo00 已提交
58
			old_project = projectQueryService.get( wi.getId() );
R
fix  
roo00 已提交
59 60
		}
		
61
		if( Boolean.TRUE.equals( check ) ){
R
fix  
roo00 已提交
62 63 64 65 66 67 68 69
			ProjectDetail projectDetail = new ProjectDetail();
			projectDetail.setDescription( wi.getDescription() );
			
			try {	
				if( ListTools.isNotEmpty( wi.getGroups() )) {
					wi.setGroupCount( wi.getGroups().size() );
				}
				
R
roo00 已提交
70
				project = projectPersistService.save( Wi.copier.copy(wi), projectDetail, effectivePerson );
R
fix  
roo00 已提交
71 72 73 74 75 76 77
				
				//将项目添加到指定的项目组
				projectGroupPersistService.releProjectToGroup(  project.getId(), wi.getGroups() );
				
				// 更新缓存
				ApplicationCache.notify( Project.class );
				ApplicationCache.notify( ProjectGroup.class );
R
roo00 已提交
78 79

				ApplicationCache.notify( Task.class, ApplicationCache.concreteCacheKey( "ActionStatisticMyTasks", project.getId(), effectivePerson.getDistinguishedName() )  );
R
roo00 已提交
80
				ApplicationCache.notify( Task.class, ApplicationCache.concreteCacheKey( "ActionStatisticMyTaskViews", project.getId(),  effectivePerson.getDistinguishedName() )  );				
R
roo00 已提交
81
				
R
fix  
roo00 已提交
82
				wo.setId( project.getId() );
R
roo00 已提交
83
				
R
fix  
roo00 已提交
84 85 86 87 88 89 90 91
			} catch (Exception e) {
				check = false;
				Exception exception = new ProjectPersistException(e, "项目信息保存时发生异常。");
				result.error(exception);
				logger.error(e, effectivePerson, request, null);
			}
		}
		
92
		if( Boolean.TRUE.equals( check ) ){
R
fix  
roo00 已提交
93
			try {					
R
roo00 已提交
94 95 96 97 98 99 100 101
				new BatchOperationPersistService().addOperation( 
						BatchOperationProcessService.OPT_OBJ_PROJECT, 
						BatchOperationProcessService.OPT_TYPE_PERMISSION,  project.getId(),  project.getId(), "刷新文档权限:ID=" +   project.getId() );
			} catch (Exception e) {
				logger.error(e, effectivePerson, request, null);
			}	
		}
		
102
		if( Boolean.TRUE.equals( check ) ){
R
roo00 已提交
103
			try {					
R
roo00 已提交
104 105 106 107 108 109 110
				List<Dynamic> dynamics = dynamicPersistService.projectSaveDynamic(old_project, project, effectivePerson,  jsonElement.toString() );
				if( dynamics == null ) {
					dynamics = new ArrayList<>();
				}
				if( wo != null ) {
					wo.setDynamics(WoDynamic.copier.copy(dynamics));
				}
R
fix  
roo00 已提交
111 112 113 114
			} catch (Exception e) {
				logger.error(e, effectivePerson, request, null);
			}
		}
R
roo00 已提交
115
		result.setData( wo );
R
fix  
roo00 已提交
116 117 118
		return result;
	}	

R
roo00 已提交
119
	public static class Wi {
R
fix  
roo00 已提交
120
		
R
roo00 已提交
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
		@FieldDescribe("数据库主键,自动生成,非必填.")
		private String id;
		
		@FieldDescribe("项目名称,必填")
		private String title;

		@FieldDescribe("排序号,非必填")
		private Integer order;

		@FieldDescribe("项目类型:普通项目 | 软件项目,非必填")
		private String type = "普通项目";

		@FieldDescribe("图标文件ID,非必填")
		private String icon = null;

		@FieldDescribe("执行者|负责人,非必填")
		private String executor;
		
L
luojing 已提交
139 140 141
		@FieldDescribe("模板id")
		private String templateId;
		
R
roo00 已提交
142 143
		@FieldDescribe("管理者,非必填")
		private List<String> manageablePersonList;
R
fix  
roo00 已提交
144 145 146
		
		public static WrapCopier<Wi, Project> copier = WrapCopierFactory.wi( Wi.class, Project.class, null, null );

R
roo00 已提交
147
		@FieldDescribe("说明信息(1M),非必填")
R
fix  
roo00 已提交
148 149
		private String description;
		
R
roo00 已提交
150
		@FieldDescribe("项目所属的项目组,可多值,非必填.")
R
fix  
roo00 已提交
151 152
		private List<String> groups = null;

R
roo00 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
		private Integer groupCount = 0;
		
		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public Integer getGroupCount() {
			return groupCount;
		}

		public void setGroupCount(Integer groupCount) {
			this.groupCount = groupCount;
		}

R
fix  
roo00 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
		public String getDescription() {
			return description;
		}

		public void setDescription(String description) {
			this.description = description;
		}

		public List<String> getGroups() {
			return groups;
		}

		public void setGroups(List<String> groups) {
			this.groups = groups;
		}
R
roo00 已提交
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

		public String getTitle() {
			return title;
		}

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

		public Integer getOrder() {
			return order;
		}

		public void setOrder(Integer order) {
			this.order = order;
		}

		public String getType() {
			return type;
		}

		public void setType(String type) {
			this.type = type;
		}

		public String getIcon() {
			return icon;
		}

		public void setIcon(String icon) {
			this.icon = icon;
		}

		public String getExecutor() {
			return executor;
		}

		public void setExecutor(String executor) {
			this.executor = executor;
		}
L
luojing 已提交
226 227 228 229 230 231 232 233
		
		public String getTemplateId() {
			return templateId;
		}

		public void setTemplateId(String templateId) {
			this.templateId = templateId;
		}
R
roo00 已提交
234 235 236 237 238 239 240 241

		public List<String> getManageablePersonList() {
			return manageablePersonList;
		}

		public void setManageablePersonList(List<String> manageablePersonList) {
			this.manageablePersonList = manageablePersonList;
		}
R
fix  
roo00 已提交
242 243
	}

R
roo00 已提交
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
public static class Wo extends WoId {
		
		@FieldDescribe("操作引起的动态内容")
		List<WoDynamic> dynamics = new ArrayList<>();

		public List<WoDynamic> getDynamics() {
			return dynamics;
		}

		public void setDynamics(List<WoDynamic> dynamics) {
			this.dynamics = dynamics;
		}
		
	}
	
	public static class WoDynamic extends Dynamic{

		private static final long serialVersionUID = -5076990764713538973L;

		public static WrapCopier<Dynamic, WoDynamic> copier = WrapCopierFactory.wo( Dynamic.class, WoDynamic.class, null, JpaObject.FieldsInvisible);
		
		private Long rank = 0L;

		public Long getRank() {
			return rank;
		}

		public void setRank(Long rank) {
			this.rank = rank;
		}		
R
fix  
roo00 已提交
274 275 276
	}
	
}