Explorar o código

Merge branch 'fix/cms_import_document_refresh_review' into 'wrdp'

[内容管理]缓存刷新改为同步模式,增加评论categoryId字段

See merge request o2oa/o2oa!2226
o2null %!s(int64=5) %!d(string=hai) anos
pai
achega
59ef222728

+ 3 - 0
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/comment/WrapInQueryDocumentCommentInfo.java

@@ -156,6 +156,9 @@ public class WrapInQueryDocumentCommentInfo {
 		if( StringUtils.isNotEmpty( this.getAppId() )) {
 			queryFilter.addEqualsTerm( new EqualsTerm( "appId", this.getAppId() ) );
 		}
+		if( StringUtils.isNotEmpty( this.getCategoryId() )) {
+			queryFilter.addEqualsTerm( new EqualsTerm( "categoryId", this.getCategoryId() ) );
+		}
 		if( StringUtils.isNotEmpty( this.getDocumentId() )) {
 			queryFilter.addEqualsTerm( new EqualsTerm( "documentId", this.getDocumentId() ) );
 		}

+ 40 - 39
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/queue/QueueDataRowImport.java

@@ -2,6 +2,8 @@ package com.x.cms.assemble.control.queue;
 
 import java.util.List;
 
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
 import org.apache.commons.lang3.StringUtils;
 
 import com.x.base.core.container.EntityManagerContainer;
@@ -20,8 +22,8 @@ import com.x.cms.core.entity.content.Data;
 
 public class QueueDataRowImport extends AbstractQueue<ImportDataRow> {
 
-	private CmsBatchOperationProcessService cmsBatchOperationProcessService = new CmsBatchOperationProcessService();
-	
+	private static Logger logger = LoggerFactory.getLogger( QueueDataRowImport.class );
+
 	public void execute( ImportDataRow dataRow ) throws Exception {
 		int curRow = dataRow.getCurRow();
 		List<String> colmlist = dataRow.getColmlist(); 
@@ -35,34 +37,34 @@ public class QueueDataRowImport extends AbstractQueue<ImportDataRow> {
 //		System.out.println(">>>>>>>>>>>>>>>>>>>QueueDataRowImport.execute正在处理第" + curRow + "行数据:" + printData( colmlist ) );
 		if( ListTools.isNotEmpty( colmlist ) ){
 			Data data = null;
-			Document document = null;
+
 			List<String> propertyNames = excelReadRuntime.propertyNames;
 			if( ListTools.isNotEmpty( propertyNames )) {
-				document = composeDocumentFormTemplate( excelReadRuntime.template );
-				if( StringUtils.isEmpty( document.getId()  )) {
-					document.setId( Document.createId() );
-				}
-				document.setImportBatchName( batchName );
-				document.setDocStatus("checking"); //待校验
-				document.setSummary( null );
-				document.addToReadPersonList( "所有人" );
-				document.addToAuthorPersonList( excelReadRuntime.operatorName );
-						
-				if( StringUtils.isNotEmpty( colmlist.get( titleColIndex )+"" )) {
-					if( StringUtils.isNotEmpty( titleFlag )) {
-						document.setTitle( titleFlag + colmlist.get( titleColIndex )+""  );
-					}else {
-						document.setTitle( colmlist.get( titleColIndex )+""  );
-					}					
-				}else {
-					if( StringUtils.isNotEmpty( titleFlag )) {
-						document.setTitle( titleFlag + "无标题"  );
-					}else {
-						document.setTitle( "无标题"  );
-					}					
-				}
-				boolean flag = false;
+				String docId = null;
 				try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
+					Document document = composeDocumentFormTemplate( excelReadRuntime.template );
+					if( StringUtils.isEmpty( document.getId()  )) {
+						document.setId( Document.createId() );
+					}
+					document.setImportBatchName( batchName );
+					document.setDocStatus("checking"); //待校验
+					document.setSummary( null );
+					document.addToReadPersonList( "所有人" );
+					document.addToAuthorPersonList( excelReadRuntime.operatorName );
+
+					if( StringUtils.isNotEmpty( colmlist.get( titleColIndex )+"" )) {
+						if( StringUtils.isNotEmpty( titleFlag )) {
+							document.setTitle( titleFlag + colmlist.get( titleColIndex )+""  );
+						}else {
+							document.setTitle( colmlist.get( titleColIndex )+""  );
+						}
+					}else {
+						if( StringUtils.isNotEmpty( titleFlag )) {
+							document.setTitle( titleFlag + "无标题"  );
+						}else {
+							document.setTitle( "无标题"  );
+						}
+					}
 					emc.beginTransaction( Document.class );
 					document.setDocStatus( excelReadRuntime.template.getDocStatus() ); //已发布
 					emc.persist( document, CheckPersistType.all );
@@ -98,31 +100,30 @@ public class QueueDataRowImport extends AbstractQueue<ImportDataRow> {
 //					if( StringUtils.isEmpty( document.getTitle() )) {
 //						document.setTitle( "无标题" );
 //					}
-							
-					emc.check( document, CheckPersistType.all );
-							
+
 					data.setDocument( document );
 					documentDataHelper.update( data );
 					emc.commit();
-					flag = true;
+					docId = document.getId();
 					dataImportStatus.addDocumentId( document.getId() );
 					dataImportStatus.increaseSuccessTotal(1);
-					System.out.println( "第" + curRow + "行数据导入成功,已经成功提交到数据库!导入成功共"+ excelReadRuntime.wo.getSuccess_count() +"条");
+					logger.print( "第" + curRow + "行数据导入成功,已经成功提交到数据库!导入成功共"+ excelReadRuntime.wo.getSuccess_count() +"条.");
 				} catch ( Exception e ) {
-					System.out.println( "第" + curRow + "行数据导入成功,保存失败!导入失败共"+ excelReadRuntime.wo.getError_count() +"条");
+					logger.print( "第" + curRow + "行数据导入成功,保存失败!导入失败共"+ excelReadRuntime.wo.getError_count() +"条.");
 					dataImportStatus.appendErorrData( colmlist );
 					dataImportStatus.increaseErrorTotal(1);
 					e.printStackTrace();
-				}
-
-				if(flag) {
-					cmsBatchOperationProcessService.refreshDocumentReview(document.getId());
+				} finally {
+                    if(docId!=null) {
+                        new CmsBatchOperationProcessService().refreshDocumentReview(docId);
 					/*new CmsBatchOperationPersistService().addOperation(
 							CmsBatchOperationProcessService.OPT_OBJ_DOCUMENT,
 							CmsBatchOperationProcessService.OPT_TYPE_PERMISSION, document.getId(), document.getId(), "导入新文档:ID=" + document.getId());*/
-				}
+                    }
+                }
+
 			}else {
-				System.out.println("数据导入不成功,propertyNames为空,无法识别数据列对应的属性!");
+				logger.print("数据导入不成功,propertyNames为空,无法识别数据列对应的属性!");
 			}
 		}
 		

+ 7 - 6
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/CmsBatchOperationProcessService.java

@@ -231,16 +231,16 @@ public class CmsBatchOperationProcessService {
 			cmsBatchOperation = emc.find( id, CmsBatchOperation.class );
 			
 			reviewService.refreshDocumentReview( emc, docId );
-			
-			Document document = emc.find( docId, Document.class );
+
+			/*Document document = emc.find( docId, Document.class );
 			if( document != null ) {
 				emc.beginTransaction( Document.class );
 				document.setReviewed( true );
-				
+
 				if( StringUtils.isEmpty( document.getAppAlias()  )) {
 					document.setAppAlias( document.getAppName() );
 				}
-				
+
 				document.setSequenceAppAlias( document.getAppAlias() + document.getId() );
 				document.setSequenceCategoryAlias( document.getCategoryAlias() + document.getId() );
 				if( StringUtils.isNotEmpty( document.getTitle() ) && document.getTitle().length() > 30 ) {
@@ -258,10 +258,10 @@ public class CmsBatchOperationProcessService {
 				}else {
 					document.setSequenceCreatorUnitName( document.getCreatorUnitName() + document.getId() );
 				}
-				
+
 				emc.check( document, CheckPersistType.all );
 				emc.commit();
-			}
+			}*/
 			
 			if( cmsBatchOperation != null ) {
 				emc.beginTransaction( CmsBatchOperation.class );
@@ -283,6 +283,7 @@ public class CmsBatchOperationProcessService {
 	 * @throws Exception
 	 */
 	public void refreshDocumentReview(String docId ) throws Exception {
+		logger.debug( "refreshDocumentReview {}", docId);
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			reviewService.refreshDocumentReview( emc, docId );
 

+ 9 - 11
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/PermissionOperateService.java

@@ -2,13 +2,8 @@ package com.x.cms.assemble.control.service;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.locks.ReentrantLock;
 
-import com.google.gson.JsonElement;
-import com.x.base.core.entity.dataitem.DataItemConverter;
-import com.x.base.core.project.gson.XGsonBuilder;
-import com.x.cms.assemble.control.DocumentDataHelper;
-import com.x.cms.core.entity.content.Data;
-import com.x.query.core.entity.Item;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.openjpa.lib.util.StringUtil;
 
@@ -26,6 +21,8 @@ import com.x.cms.core.entity.Document;
 public class PermissionOperateService {
 	
 	private static Logger logger = LoggerFactory.getLogger(PermissionOperateService.class);
+
+	private static ReentrantLock lock = new ReentrantLock();
 	/**
 	 * 根据文档ID,为文档设置用户访问和管理权限
 	 * @param docId
@@ -35,11 +32,12 @@ public class PermissionOperateService {
 	 */
 	public Document refreshDocumentPermission( String docId, List<PermissionInfo> readerList, List<PermissionInfo> authorList ) throws Exception {
 		List<PermissionInfo> permissionList = composeDocmentAllPermissions(readerList, authorList);
+		lock.lock();
 		try {
 			//将读者以及作者信息持久化到数据库中
 			return refreshDocumentPermission( docId, permissionList );
-		} catch (Exception e) {
-			throw e;
+		} finally {
+			lock.unlock();
 		}
 	}
 	
@@ -145,11 +143,10 @@ public class PermissionOperateService {
 		if( StringUtils.isEmpty(docId) ){
 			throw new Exception( "docId is empty!" );
 		}
+		logger.info("dear refreshDocumentPermission doc:{}",docId);
 		Document document = null;
 		try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
-			emc.beginTransaction( Document.class );
 			document = emc.find( docId, Document.class );
-			
 			if( document != null ) {
 				//清空文档权限信息
 				document.setManagerList( null );
@@ -205,11 +202,12 @@ public class PermissionOperateService {
 					document.addToReadPersonList( document.getCreatorPerson() );
 					document.addToManagerList( document.getCreatorPerson() );
 				}
-		
+				emc.beginTransaction( Document.class );
 				emc.check( document , CheckPersistType.all );
 				emc.commit();
 			}		
 		} catch ( Exception e ) {
+			logger.warn("refreshDocumentPermission doc error:{}",document);
 			throw e;
 		}