Jelajahi Sumber

Merge branch 'wrdp' into 'develop'

Wrdp

See merge request o2oa/o2oa!2869
胡起 5 tahun lalu
induk
melakukan
509dcec39e

+ 90 - 0
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistViewRecord.java

@@ -0,0 +1,90 @@
+package com.x.cms.assemble.control.jaxrs.document;
+
+import com.google.gson.JsonElement;
+import com.x.base.core.project.annotation.FieldDescribe;
+import com.x.base.core.project.annotation.FieldTypeDescribe;
+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.jaxrs.WrapBoolean;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.base.core.project.organization.Person;
+import com.x.base.core.project.tools.DateTools;
+import com.x.base.core.project.tools.ListTools;
+import com.x.cms.core.entity.Document;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+
+public class ActionPersistViewRecord extends BaseAction {
+
+	private static  Logger logger = LoggerFactory.getLogger(ActionPersistViewRecord.class);
+
+	protected ActionResult<Wo> execute(HttpServletRequest request, String id, JsonElement jsonElement, EffectivePerson effectivePerson) throws Exception {
+		ActionResult<Wo> result = new ActionResult<>();
+
+		Document document  = documentQueryService.get(id);
+		if (null == document) {
+			throw new ExceptionDocumentNotExists(id);
+		}
+
+		Wi wi = this.convertToWrapIn(jsonElement, Wi.class );
+		if(ListTools.isNotEmpty(wi.getRecordList())){
+			for (ViewRecordWi viewRecordWi : wi.getRecordList()){
+				Person person = this.userManagerService.getPerson(viewRecordWi.getPerson());
+				if (person != null) {
+					documentViewRecordServiceAdv.addViewRecord(id, person.getDistinguishedName(), DateTools.parse(viewRecordWi.getViewTime()));
+				}
+			}
+		}
+		Wo wo = new Wo();
+		wo.setValue(true);
+
+		return result;
+	}
+
+	public static class Wo extends WrapBoolean {
+
+	}
+
+	public static class Wi extends GsonPropertyObject {
+		@FieldDescribe("阅读记录列表")
+		@FieldTypeDescribe(fieldType = "class", fieldTypeName = "Module", fieldValue = "{\"person\": \"阅读人员\", \"viewTime\": \"阅读时间(格式:2020-08-08)\"}")
+		private List<ViewRecordWi> recordList;
+
+		public List<ViewRecordWi> getRecordList() {
+			return recordList;
+		}
+
+		public void setRecordList(List<ViewRecordWi> recordList) {
+			this.recordList = recordList;
+		}
+	}
+
+	public static class ViewRecordWi extends GsonPropertyObject {
+
+		@FieldDescribe("阅读人员")
+		private String person;
+		@FieldDescribe("阅读时间(格式:2020-08-08)")
+		private String viewTime;
+
+		public String getPerson() {
+			return person;
+		}
+
+		public void setPerson(String person) {
+			this.person = person;
+		}
+
+		public String getViewTime() {
+			return viewTime;
+		}
+
+		public void setViewTime(String viewTime) {
+			this.viewTime = viewTime;
+		}
+	}
+
+
+}

+ 23 - 3
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/DocumentCipherAction.java

@@ -24,9 +24,9 @@ import java.util.List;
 @Path("document/cipher")
 @JaxrsDescribe("信息发布信息文档管理(Cipher)")
 public class DocumentCipherAction extends StandardJaxrsAction{
-	
+
 	private static  Logger logger = LoggerFactory.getLogger( DocumentCipherAction.class );
-	
+
 	@JaxrsMethodDescribe(value = "直接发布文档信息.", action = ActionPersistPublishByWorkFlow.class)
 	@PUT
 	@Path("publish/content")
@@ -96,4 +96,24 @@ public class DocumentCipherAction extends StandardJaxrsAction{
 		}
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
-}
+
+	@JaxrsMethodDescribe(value = "添加文档的阅读记录.", action = ActionPersistViewRecord.class)
+	@POST
+	@Path("{id}/persist/view/record")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void persist_documentViewRecord( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+											@JaxrsParameterDescribe("文档ID") @PathParam("id") String id, JsonElement jsonElement ) {
+		EffectivePerson effectivePerson = this.effectivePerson( request );
+		ActionResult<ActionPersistViewRecord.Wo> result = new ActionResult<>();
+
+		try {
+			result = new ActionPersistViewRecord().execute( request, id, jsonElement, effectivePerson );
+		} catch (Exception e) {
+			result.error( e );
+			logger.error( e, effectivePerson, request, null);
+		}
+
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+}

+ 95 - 29
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/DocumentViewRecordServiceAdv.java

@@ -21,14 +21,14 @@ import java.util.List;
 /**
  * 对文档访问记录信息进行管理的服务类(高级)
  * 高级服务器可以利用Service完成事务控制
- * 
+ *
  * @author O2LEE
  */
 public class DocumentViewRecordServiceAdv {
-	
+
 	private UserManagerService userManagerService = new UserManagerService();
 	private DocumentViewRecordService documentViewRecordService = new DocumentViewRecordService();
-	
+
 	public List<DocumentViewRecord> list( List<String> ids ) throws Exception {
 		try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
 			return documentViewRecordService.list( emc, ids );
@@ -44,7 +44,7 @@ public class DocumentViewRecordServiceAdv {
 			throw e;
 		}
 	}
-	
+
 	public List<String> listByPerson( String personName, Integer maxCount ) throws Exception {
 		try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
 			List<String> ids =  documentViewRecordService.listByPerson( emc, personName, maxCount );
@@ -56,7 +56,7 @@ public class DocumentViewRecordServiceAdv {
 			throw e;
 		}
 	}
-	
+
 	public List<String> listDocIdsByPerson( String personName, Integer maxCount ) throws Exception {
 		try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
 			List<String> ids =  documentViewRecordService.listDocIdsByPerson( emc, personName, maxCount );
@@ -68,7 +68,7 @@ public class DocumentViewRecordServiceAdv {
 			throw e;
 		}
 	}
-	
+
 	public void deleteByDocument( String docId ) throws Exception {
 		try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
 			documentViewRecordService.deleteByDocument( emc, docId );
@@ -79,8 +79,8 @@ public class DocumentViewRecordServiceAdv {
 
 	/**
 	 * TODO:记录访问日志,一个用户一篇文档只保留一条记录,更新访问次数和最后访问时间
-	 * 
-	 * @param document
+	 *
+	 * @param docId
 	 * @param personName
 	 * @throws Exception
 	 */
@@ -93,14 +93,14 @@ public class DocumentViewRecordServiceAdv {
 		try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
 			business = new Business( emc );
 			emc.beginTransaction( DocumentViewRecord.class );
-			
+
 			ids = business.documentViewRecordFactory().listByDocAndPerson( docId, personName );
 			document = emc.find( docId, Document.class );
-			
+
 			if( document == null ) {
 				throw new Exception("document not exists!ID:" + docId );
 			}
-			
+
 			if( ListTools.isNotEmpty( ids )){
 				int i = 0;
 				for( String id : ids ){
@@ -112,7 +112,7 @@ public class DocumentViewRecordServiceAdv {
 							documentViewRecord.setViewCount( 1 );
 						}
 						documentViewRecord.setViewCount( documentViewRecord.getViewCount() + 1 );
-						emc.check( documentViewRecord, CheckPersistType.all ); 
+						emc.check( documentViewRecord, CheckPersistType.all );
 					}else{
 						//删除多余的日志数据
 						emc.remove( documentViewRecord, CheckRemoveType.all );
@@ -132,23 +132,89 @@ public class DocumentViewRecordServiceAdv {
 					documentViewRecord.setViewCount( 1 );
 					documentViewRecord.setViewerTopUnitName( userManagerService.getTopUnitNameWithPerson( personName ));
 					documentViewRecord.setViewerUnitName( userManagerService.getUnitNameWithPerson( personName ));
-					emc.persist( documentViewRecord, CheckPersistType.all ); 
+					emc.persist( documentViewRecord, CheckPersistType.all );
+				}
+			}
+			emc.commit();
+
+			emc.beginTransaction( Document.class );
+			viewCount = business.documentViewRecordFactory().sumWithDocmentId( docId );
+			document.setViewCount( viewCount );
+			emc.check( document, CheckPersistType.all );
+			emc.commit();
+
+		} catch ( Exception e ) {
+			throw e;
+		}
+		return viewCount;
+	}
+
+	public Long addViewRecord( String docId, String personName, Date viewTime) throws Exception {
+		DocumentViewRecord documentViewRecord = null;
+		Document document = null;
+		Business business = null;
+		Long viewCount = 0L;
+		List<String> ids = null;
+		try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
+			business = new Business( emc );
+			emc.beginTransaction( DocumentViewRecord.class );
+
+			ids = business.documentViewRecordFactory().listByDocAndPerson( docId, personName );
+			document = emc.find( docId, Document.class );
+
+			if( document == null ) {
+				throw new Exception("document not exists!ID:" + docId );
+			}
+
+			if( ListTools.isNotEmpty( ids )){
+				int i = 0;
+				for( String id : ids ){
+					i++;
+					documentViewRecord = emc.find( id, DocumentViewRecord.class );
+					if( i == 1 ){
+						documentViewRecord.setLastViewTime(viewTime);
+						if( documentViewRecord.getViewCount() == null || documentViewRecord.getViewCount() == 0 ){
+							documentViewRecord.setViewCount( 1 );
+						}
+						documentViewRecord.setViewCount( documentViewRecord.getViewCount() + 1 );
+						emc.check( documentViewRecord, CheckPersistType.all );
+					}else{
+						//删除多余的日志数据
+						emc.remove( documentViewRecord, CheckRemoveType.all );
+					}
+				}
+			}else{
+				if( document != null ){
+					documentViewRecord = new DocumentViewRecord();
+					documentViewRecord.setCreateTime(viewTime);
+					documentViewRecord.setAppId( document.getAppId() );
+					documentViewRecord.setCategoryId( document.getCategoryId() );
+					documentViewRecord.setDocumentId( document.getId() );
+					documentViewRecord.setViewerName( personName );
+					documentViewRecord.setAppName( document.getAppName() );
+					documentViewRecord.setCategoryName( document.getCategoryName() );
+					documentViewRecord.setTitle( document.getTitle() );
+					documentViewRecord.setLastViewTime(viewTime);
+					documentViewRecord.setViewCount( 1 );
+					documentViewRecord.setViewerTopUnitName( userManagerService.getTopUnitNameWithPerson( personName ));
+					documentViewRecord.setViewerUnitName( userManagerService.getUnitNameWithPerson( personName ));
+					emc.persist( documentViewRecord, CheckPersistType.all );
 				}
 			}
 			emc.commit();
-			
+
 			emc.beginTransaction( Document.class );
 			viewCount = business.documentViewRecordFactory().sumWithDocmentId( docId );
 			document.setViewCount( viewCount );
-			emc.check( document, CheckPersistType.all ); 
+			emc.check( document, CheckPersistType.all );
 			emc.commit();
-			
+
 		} catch ( Exception e ) {
 			throw e;
-		}		
+		}
 		return viewCount;
 	}
-	
+
 	public List<DocumentViewRecord> listNextWithDocIds( String id, String docId, Integer count, String order) throws Exception {
 		if( docId == null ){
 			throw new Exception("docId is null!");
@@ -162,7 +228,7 @@ public class DocumentViewRecordServiceAdv {
 			throw e;
 		}
 	}
-	
+
 	public Long countWithDocIds( String docId ) throws Exception {
 		if( docId == null ){
 			throw new Exception("docId is null!");
@@ -173,12 +239,12 @@ public class DocumentViewRecordServiceAdv {
 			throw e;
 		}
 	}
-	
+
 	/**
 	 * 对文档访问日志信息进行清理
 	 * @param stay_yeanumr_viewRecord 日志保留年份
 	 * @param stay_count_viewRecord 日志保留条目数
-	 * @throws Exception 
+	 * @throws Exception
 	 */
 	public void clean( Integer stay_yeanumr_viewRecord, Integer stay_count_viewRecord ) throws Exception {
 		//先按时间清理
@@ -188,8 +254,8 @@ public class DocumentViewRecordServiceAdv {
 
 	/**
 	 * 按最大保留条目数进行清理
-	 * @param stay_count_operationLog
-	 * @throws Exception 
+	 * @param stay_count_viewRecord
+	 * @throws Exception
 	 */
 	private void cleanWithMaxCount(Integer stay_count_viewRecord ) throws Exception {
 		Business business = null;
@@ -218,8 +284,8 @@ public class DocumentViewRecordServiceAdv {
 
 	/**
 	 * 按保留年份对日志进行清理
-	 * @param stay_yearnum_operationLog
-	 * @throws Exception 
+	 * @param stay_yeanumr_viewRecord
+	 * @throws Exception
 	 */
 	private void cleanWithStayYearNumber( Integer stay_yeanumr_viewRecord ) throws Exception {
 		if( stay_yeanumr_viewRecord == null ) {
@@ -230,12 +296,12 @@ public class DocumentViewRecordServiceAdv {
 		Date limitDate = DateOperation.getDateFromString( ( year-4 ) + "-01-01 00:00:00");
 		cleanWithDate( limitDate );
 	}
-	
-	
+
+
 	/**
 	 * 按保留年份对日志进行清理
 	 * @param overTime
-	 * @throws Exception 
+	 * @throws Exception
 	 */
 	private void cleanWithDate( Date overTime ) throws Exception {
 		if( overTime == null ) {
@@ -267,7 +333,7 @@ public class DocumentViewRecordServiceAdv {
 	 * @param ids
 	 * @param effectivePerson
 	 * @return
-	 * @throws Exception 
+	 * @throws Exception
 	 */
 	public List<String> listReadDocId( List<String> ids, EffectivePerson effectivePerson ) throws Exception {
 		if( ListTools.isEmpty(  ids ) ) {

+ 56 - 33
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageUpload.java → o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageBatchUpload.java

@@ -6,10 +6,9 @@ import com.x.base.core.entity.annotation.CheckPersistType;
 import com.x.base.core.project.config.Config;
 import com.x.base.core.project.config.StorageMapping;
 import com.x.base.core.project.exception.ExceptionAccessDenied;
-import com.x.base.core.project.exception.ExceptionEntityNotExist;
 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.jaxrs.WrapBoolean;
 import com.x.base.core.project.logger.Logger;
 import com.x.base.core.project.logger.LoggerFactory;
 import com.x.base.core.project.tools.ExtractTextTools;
@@ -18,38 +17,29 @@ import com.x.processplatform.assemble.surface.ThisApplication;
 import com.x.processplatform.assemble.surface.WorkControl;
 import com.x.processplatform.core.entity.content.Attachment;
 import com.x.processplatform.core.entity.content.Work;
-import com.x.processplatform.core.entity.element.Application;
-import com.x.processplatform.core.entity.element.Process;
+import com.x.processplatform.core.entity.content.WorkCompleted;
+import com.x.processplatform.core.entity.element.ActivityType;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.tika.Tika;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 
-class ActionManageUpload extends BaseAction {
+class ActionManageBatchUpload extends BaseAction {
 
-	private static Logger logger = LoggerFactory.getLogger(ActionManageUpload.class);
+	private static Logger logger = LoggerFactory.getLogger(ActionManageBatchUpload.class);
 
-	ActionResult<Wo> execute(EffectivePerson effectivePerson, String workId, String site, String fileName, byte[] bytes,
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String workIds, String site, String fileName, byte[] bytes,
 			FormDataContentDisposition disposition, String extraParam, String person) throws Exception {
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			ActionResult<Wo> result = new ActionResult<>();
 			Business business = new Business(emc);
-			/* 后面要重新保存 */
-			Work work = emc.find(workId, Work.class);
-			/* 判断work是否存在 */
-			if (null == work) {
-				throw new ExceptionEntityNotExist(workId, Work.class);
-			}
-			Process process = business.process().pick(work.getProcess());
-			Application application = business.application().pick(work.getApplication());
 			// 需要对这个应用的管理权限
-			if (!business.canManageApplicationOrProcess(effectivePerson, application, process)) {
+			if (!business.canManageApplication(effectivePerson, null)) {
 				throw new ExceptionAccessDenied(effectivePerson);
 			}
+
 			if (StringUtils.isEmpty(fileName)) {
 				fileName = this.fileName(disposition);
 			}
-			/* 调整可能的附件名称 */
-			fileName = this.adjustFileName(business, work.getJob(), fileName);
 
 			/* 天谷印章扩展 */
 			if (StringUtils.isNotEmpty(extraParam)) {
@@ -61,26 +51,41 @@ class ActionManageUpload extends BaseAction {
 					site = wiExtraParam.getSite();
 				}
 			}
+
 			person = business.organization().person().get(person);
 			if(StringUtils.isEmpty(person)){
 				person = effectivePerson.getDistinguishedName();
 			}
-			StorageMapping mapping = ThisApplication.context().storageMappings().random(Attachment.class);
-			Attachment attachment = this.concreteAttachment(work, person, site);
-			attachment.saveContent(mapping, bytes, fileName);
-			attachment.setType((new Tika()).detect(bytes, fileName));
-			logger.debug("filename:{}, file type:{}.", attachment.getName(), attachment.getType());
-			if (Config.query().getExtractImage() && ExtractTextTools.supportImage(attachment.getName())
-					&& ExtractTextTools.available(bytes)) {
-				attachment.setText(ExtractTextTools.image(bytes));
-				logger.debug("filename:{}, file type:{}, text:{}.", attachment.getName(), attachment.getType(),
-						attachment.getText());
+			if(StringUtils.isNotEmpty(workIds) && bytes!=null && bytes.length>0) {
+				String[] idArray = workIds.split(",");
+				for (String workId : idArray) {
+                    Attachment attachment = null;
+					Work work = emc.find(workId.trim(), Work.class);
+                    if(work!=null) {
+						attachment = this.concreteAttachment(work, person, site);
+                    }else{
+                        WorkCompleted workCompleted = emc.find(workId, WorkCompleted.class);
+                        if (null != workCompleted) {
+                            attachment = this.concreteAttachment(workCompleted, person, site);
+                        }
+                    }
+                    if(attachment!=null){
+                        StorageMapping mapping = ThisApplication.context().storageMappings().random(Attachment.class);
+                        attachment.saveContent(mapping, bytes, fileName);
+                        attachment.setType((new Tika()).detect(bytes, fileName));
+                        if (Config.query().getExtractImage() && ExtractTextTools.supportImage(attachment.getName())
+                                && ExtractTextTools.available(bytes)) {
+                            attachment.setText(ExtractTextTools.image(bytes));
+                        }
+                        emc.beginTransaction(Attachment.class);
+                        emc.persist(attachment, CheckPersistType.all);
+                        emc.commit();
+                    }
+				}
 			}
-			emc.beginTransaction(Attachment.class);
-			emc.persist(attachment, CheckPersistType.all);
-			emc.commit();
+
 			Wo wo = new Wo();
-			wo.setId(attachment.getId());
+			wo.setValue(true);
 			result.setData(wo);
 			return result;
 		}
@@ -104,7 +109,25 @@ class ActionManageUpload extends BaseAction {
 		return attachment;
 	}
 
-	public static class Wo extends WoId {
+    private Attachment concreteAttachment(WorkCompleted workCompleted, String person, String site) throws Exception {
+        Attachment attachment = new Attachment();
+        attachment.setCompleted(true);
+        attachment.setPerson(person);
+        attachment.setLastUpdatePerson(person);
+        attachment.setSite(site);
+        /** 用于判断目录的值 */
+        attachment.setWorkCreateTime(workCompleted.getStartTime());
+        attachment.setApplication(workCompleted.getApplication());
+        attachment.setProcess(workCompleted.getProcess());
+        attachment.setJob(workCompleted.getJob());
+        attachment.setActivity(workCompleted.getActivity());
+        attachment.setActivityName(workCompleted.getActivityName());
+        attachment.setActivityToken(workCompleted.getActivity());
+        attachment.setActivityType(ActivityType.end);
+        return attachment;
+    }
+
+	public static class Wo extends WrapBoolean {
 
 	}
 

+ 6 - 6
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/AttachmentAction.java

@@ -1061,23 +1061,23 @@ public class AttachmentAction extends StandardJaxrsAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 
-	@JaxrsMethodDescribe(value = "管理员上传附件.", action = ActionManageUpload.class)
+	@JaxrsMethodDescribe(value = "管理员批量上传附件.", action = ActionManageBatchUpload.class)
 	@POST
-	@Path("upload/work/{workId}/manage")
+	@Path("batch/upload/manage")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.MULTIPART_FORM_DATA)
-	public void manageUpload(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
-			@JaxrsParameterDescribe("工作标识") @PathParam("workId") String workId,
+	public void manageBatchUpload(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+			@JaxrsParameterDescribe("工作标识列表,多值逗号隔开") @FormDataParam("workIds") String workIds,
 			@JaxrsParameterDescribe("位置") @FormDataParam("site") String site,
 			@JaxrsParameterDescribe("附件名称") @FormDataParam(FILENAME_FIELD) String fileName,
 			@JaxrsParameterDescribe("上传到指定用户") @FormDataParam("person") String person,
 			@JaxrsParameterDescribe("天印扩展字段") @FormDataParam("extraParam") String extraParam,
 			@FormDataParam(FILE_FIELD) final byte[] bytes,
 			@FormDataParam(FILE_FIELD) final FormDataContentDisposition disposition) {
-		ActionResult<ActionManageUpload.Wo> result = new ActionResult<>();
+		ActionResult<ActionManageBatchUpload.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new ActionManageUpload().execute(effectivePerson, workId, site, fileName, bytes, disposition,
+			result = new ActionManageBatchUpload().execute(effectivePerson, workIds, site, fileName, bytes, disposition,
 					extraParam, person);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);