From 6fc2127b332772521c808626562c049e67325366 Mon Sep 17 00:00:00 2001 From: roo00 Date: Wed, 10 Apr 2019 16:09:14 +0800 Subject: [PATCH] bug fix --- .../control/factory/DocumentFactory.java | 14 +- .../ActionEraseDocumentWithAppInfo.java | 131 +++++++++++++++++ .../control/jaxrs/appinfo/AppInfoAction.java | 20 +++ .../control/jaxrs/appinfo/BaseAction.java | 2 + .../jaxrs/appinfo/ExceptionIdEmpty.java | 12 ++ .../ActionEraseDocumentWithCategory.java | 134 ++++++++++++++++++ .../categoryinfo/CategoryInfoAction.java | 20 +++ .../control/service/AppInfoService.java | 35 +++-- .../control/service/CategoryInfoService.java | 100 +++++++++---- .../control/service/DocumentInfoService.java | 37 +++-- .../service/DocumentInfoServiceAdv.java | 33 +++++ .../control/jaxrs/file/ActionUpload.java | 2 +- ...tionErrorInfoFilterListNextWithFilter.java | 20 +-- .../control/jaxrs/login/ActionLogin.java | 26 +++- .../ActionListNextWithFilterAdmin.java | 19 +-- .../okrtask/ActionListNextWithFilter.java | 20 +-- .../service/OkrUserManagerService.java | 7 + .../processing/ScriptHelperFactory.java | 38 ++--- 18 files changed, 569 insertions(+), 101 deletions(-) create mode 100644 o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/ActionEraseDocumentWithAppInfo.java create mode 100644 o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/ExceptionIdEmpty.java create mode 100644 o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/categoryinfo/ActionEraseDocumentWithCategory.java diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/factory/DocumentFactory.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/factory/DocumentFactory.java index 715a8e34b5..caf9db7bb0 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/factory/DocumentFactory.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/factory/DocumentFactory.java @@ -65,14 +65,14 @@ public class DocumentFactory extends AbstractFactory { } //@MethodDescribe("根据ID列示指定分类所有Document信息列表") - public List listByCategoryId( String categoryId ) throws Exception { + public List listByCategoryId( String categoryId, Integer maxCount ) throws Exception { EntityManager em = this.entityManagerContainer().get( Document.class ); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery( String.class ); Root root = cq.from( Document.class ); Predicate p = cb.equal(root.get( Document_.categoryId ), categoryId ); cq.select(root.get( Document_.id)).where(p); - return em.createQuery( cq ).setMaxResults(10000).getResultList(); + return em.createQuery( cq ).setMaxResults(maxCount).getResultList(); } //@MethodDescribe("根据ID列示指定分类所有Document信息数量") @@ -86,6 +86,16 @@ public class DocumentFactory extends AbstractFactory { return em.createQuery(cq).getSingleResult(); } + public Long countByAppId( String appId ) throws Exception { + EntityManager em = this.entityManagerContainer().get( Document.class ); + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(Long.class); + Root root = cq.from(Document.class); + Predicate p = cb.equal( root.get(Document_.appId), appId ); + cq.select(cb.count(root)).where(p); + return em.createQuery(cq).getSingleResult(); + } + public List listInReviewDocumentList( Integer maxCount ) throws Exception { EntityManager em = this.entityManagerContainer().get(Document.class); CriteriaBuilder cb = em.getCriteriaBuilder(); diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/ActionEraseDocumentWithAppInfo.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/ActionEraseDocumentWithAppInfo.java new file mode 100644 index 0000000000..78ad2bfe39 --- /dev/null +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/ActionEraseDocumentWithAppInfo.java @@ -0,0 +1,131 @@ +package com.x.cms.assemble.control.jaxrs.appinfo; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import com.x.base.core.container.EntityManagerContainer; +import com.x.base.core.container.factory.EntityManagerContainerFactory; +import com.x.base.core.entity.annotation.CheckRemoveType; +import com.x.base.core.project.cache.ApplicationCache; +import com.x.base.core.project.config.StorageMapping; +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; +import com.x.cms.assemble.control.Business; +import com.x.cms.assemble.control.DocumentDataHelper; +import com.x.cms.assemble.control.ThisApplication; +import com.x.cms.core.entity.AppInfo; +import com.x.cms.core.entity.Document; +import com.x.cms.core.entity.FileInfo; +import com.x.query.core.entity.Item; + +public class ActionEraseDocumentWithAppInfo extends BaseAction { + + private static Logger logger = LoggerFactory.getLogger(ActionEraseDocumentWithAppInfo.class); + + protected ActionResult execute(HttpServletRequest request, String id, EffectivePerson effectivePerson) throws Exception { + ActionResult result = new ActionResult<>(); + AppInfo appInfo = null; + Boolean check = true; + + if ( id == null || id.isEmpty() ) { + check = false; + Exception exception = new ExceptionIdEmpty(); + result.error(exception); + } + if( check ){ + try { + appInfo = appInfoServiceAdv.get( id ); + if( appInfo == null ){ + check = false; + Exception exception = new ExceptionAppInfoNotExists( id ); + result.error( exception ); + } + } catch (Exception e) { + check = false; + Exception exception = new ExceptionAppInfoProcess( e, "根据指定ID查询应用栏目信息对象时发生异常。ID:" + id ); + result.error( exception ); + logger.error( e, effectivePerson, request, null); + } + } + + if ( check ) { + //查询栏目下的文档数量 + Long count = documentServiceAdv.countByAppId( id ); + List idsForDelete = null; + List allFileInfoIds = null; + Document document = null; + Integer queryMaxCount = 5000; + Integer whileCount = 0; + Integer currentWhileCount = 0; + FileInfo fileInfo = null; + StorageMapping mapping = null; + DocumentDataHelper documentDataHelper = null; + + if ( count > 0 ) { + logger.info(">>>>一共需要删除"+count+"个文档。"); + result.setCount(count); + whileCount = (int) (count/queryMaxCount + 1); + try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { + Business business = new Business( emc ); + + //循环清除分类下所有的文档信息 + while( count > 0 && currentWhileCount<=whileCount ) { + logger.info(">>>>正在根据appId查询"+count+"个需要删除的文档ID列表。"); + idsForDelete = documentServiceAdv.listIdsByAppId( id, null, queryMaxCount ); + if( ListTools.isNotEmpty( idsForDelete )) { + emc.beginTransaction( Document.class ); + emc.beginTransaction( Item.class ); + emc.beginTransaction( FileInfo.class ); + + for( String docId : idsForDelete ) { + try { + document = emc.find( docId, Document.class ); + //删除与该文档有关的所有数据Item信息 + documentDataHelper = new DocumentDataHelper( emc, document ); + documentDataHelper.remove(); + + //删除文档的附件信息 + allFileInfoIds = business.getFileInfoFactory().listAllByDocument( docId ); + if( allFileInfoIds != null && !allFileInfoIds.isEmpty() ){ + for( String fileInfoId : allFileInfoIds ){ + fileInfo = emc.find( fileInfoId, FileInfo.class ); + if( fileInfo != null ){ + if( "ATTACHMENT".equals( fileInfo.getFileType() )){ + mapping = ThisApplication.context().storageMappings().get( FileInfo.class, fileInfo.getStorage() ); + fileInfo.deleteContent( mapping ); + } + } + emc.remove( fileInfo, CheckRemoveType.all ); + } + } + //删除文档信息 + emc.remove( document, CheckRemoveType.all ); + }catch( Exception e ) { + e.printStackTrace(); + } + } + emc.commit(); + ApplicationCache.notify( Document.class ); + } + count = documentServiceAdv.countByAppId( id ); + logger.info(">>>>已经删除"+queryMaxCount+"个文档,还剩下"+count+"个文档需要删除。"); + } + } + } + } + + Wo wo = new Wo(); + wo.setId(id); + result.setData(wo); + return result; + } + + public static class Wo extends WoId { + + } +} \ No newline at end of file diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/AppInfoAction.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/AppInfoAction.java index f58a12a75d..e1546271e7 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/AppInfoAction.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/AppInfoAction.java @@ -79,6 +79,26 @@ public class AppInfoAction extends StandardJaxrsAction { } return ResponseFactory.getDefaultActionResultResponse(result); } + + @JaxrsMethodDescribe(value = "根据栏目ID删除所有的信息文档.", action = ActionEraseDocumentWithAppInfo.class) + @DELETE + @Path("erase/app/{id}") + @Produces(HttpMediaType.APPLICATION_JSON_UTF_8) + @Consumes(MediaType.APPLICATION_JSON) + public Response eraseWithAppId(@Context HttpServletRequest request, + @JaxrsParameterDescribe("栏目ID") @PathParam("id") String id) { + EffectivePerson effectivePerson = this.effectivePerson(request); + ActionResult result = new ActionResult<>(); + try { + result = new ActionEraseDocumentWithAppInfo().execute(request, id, effectivePerson ); + } catch (Exception e) { + result = new ActionResult<>(); + Exception exception = new ExceptionAppInfoProcess(e, "根据栏目ID删除所有的信息文档发生未知异常,ID:" + id); + result.error(exception); + logger.error(e, effectivePerson, request, null); + } + return ResponseFactory.getDefaultActionResultResponse(result); + } @JaxrsMethodDescribe(value = "根据标识获取信息栏目信息对象.", action = ActionGet.class) @GET diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/BaseAction.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/BaseAction.java index 1718807bd2..2bbf02dfc0 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/BaseAction.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/BaseAction.java @@ -16,6 +16,7 @@ import com.x.base.core.project.tools.ListTools; import com.x.cms.assemble.control.service.AppDictServiceAdv; import com.x.cms.assemble.control.service.AppInfoServiceAdv; import com.x.cms.assemble.control.service.CategoryInfoServiceAdv; +import com.x.cms.assemble.control.service.DocumentInfoServiceAdv; import com.x.cms.assemble.control.service.FormServiceAdv; import com.x.cms.assemble.control.service.PermissionOperateService; import com.x.cms.assemble.control.service.PermissionQueryService; @@ -37,6 +38,7 @@ public class BaseAction extends StandardJaxrsAction { protected ScriptServiceAdv scriptServiceAdv = new ScriptServiceAdv(); protected AppDictServiceAdv appDictServiceAdv = new AppDictServiceAdv(); protected CategoryInfoServiceAdv categoryInfoServiceAdv = new CategoryInfoServiceAdv(); + protected DocumentInfoServiceAdv documentServiceAdv = new DocumentInfoServiceAdv(); protected UserManagerService userManagerService = new UserManagerService(); protected PermissionQueryService permissionQueryService = new PermissionQueryService(); protected PermissionOperateService permissionOperateService = new PermissionOperateService(); diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/ExceptionIdEmpty.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/ExceptionIdEmpty.java new file mode 100644 index 0000000000..d0e9848179 --- /dev/null +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/appinfo/ExceptionIdEmpty.java @@ -0,0 +1,12 @@ +package com.x.cms.assemble.control.jaxrs.appinfo; + +import com.x.base.core.project.exception.PromptException; + +class ExceptionIdEmpty extends PromptException { + + private static final long serialVersionUID = 1859164370743532895L; + + ExceptionIdEmpty() { + super("分类信息“ID”不能为空。" ); + } +} diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/categoryinfo/ActionEraseDocumentWithCategory.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/categoryinfo/ActionEraseDocumentWithCategory.java new file mode 100644 index 0000000000..62b094d205 --- /dev/null +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/categoryinfo/ActionEraseDocumentWithCategory.java @@ -0,0 +1,134 @@ +package com.x.cms.assemble.control.jaxrs.categoryinfo; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import com.x.base.core.container.EntityManagerContainer; +import com.x.base.core.container.factory.EntityManagerContainerFactory; +import com.x.base.core.entity.annotation.CheckRemoveType; +import com.x.base.core.project.cache.ApplicationCache; +import com.x.base.core.project.config.StorageMapping; +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; +import com.x.cms.assemble.control.Business; +import com.x.cms.assemble.control.DocumentDataHelper; +import com.x.cms.assemble.control.ThisApplication; +import com.x.cms.core.entity.CategoryInfo; +import com.x.cms.core.entity.Document; +import com.x.cms.core.entity.FileInfo; +import com.x.query.core.entity.Item; + +public class ActionEraseDocumentWithCategory extends BaseAction { + + private static Logger logger = LoggerFactory.getLogger(ActionEraseDocumentWithCategory.class); + + protected ActionResult execute(HttpServletRequest request, String id, EffectivePerson effectivePerson) throws Exception { + ActionResult result = new ActionResult<>(); + CategoryInfo categoryInfo = null; + Boolean check = true; + + if ( id == null || id.isEmpty() ) { + check = false; + Exception exception = new ExceptionIdEmpty(); + result.error(exception); + } + if ( check ) { + try { + categoryInfo = categoryInfoServiceAdv.get(id); + } catch ( Exception e ) { + check = false; + Exception exception = new ExceptionCategoryInfoProcess(e, "根据ID查询分类信息对象时发生异常。ID:" + id); + result.error(exception); + logger.error(e, effectivePerson, request, null); + } + } + if ( check ) { + if ( categoryInfo == null ) { + check = false; + Exception exception = new ExceptionCategoryInfoNotExists( id ); + result.error(exception); + } + } + if ( check ) { + //查询分类下的文档数量 + Long count = documentServiceAdv.countByCategoryId(id); + Document document = null; + List idsForDelete = null; + List allFileInfoIds = null; + Integer queryMaxCount = 5000; + Integer whileCount = 0; + Integer currentWhileCount = 0; + FileInfo fileInfo = null; + StorageMapping mapping = null; + DocumentDataHelper documentDataHelper = null; + + if ( count > 0 ) { + logger.info(">>>>一共需要删除"+count+"个文档。"); + result.setCount(count); + whileCount = (int) (count/queryMaxCount + 1); + try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { + Business business = new Business( emc ); + + //循环清除分类下所有的文档信息 + while( count > 0 && currentWhileCount<=whileCount ) { + logger.info(">>>>正在根据categoryId查询"+count+"个需要删除的文档ID列表。"); + idsForDelete = documentServiceAdv.listIdsByCategoryId( id, queryMaxCount ); + if( ListTools.isNotEmpty( idsForDelete )) { + + emc.beginTransaction( Document.class ); + emc.beginTransaction( Item.class ); + emc.beginTransaction( FileInfo.class ); + + for( String docId : idsForDelete ) { + try { + document = emc.find( docId, Document.class ); + + //删除与该文档有关的所有数据Item信息 + documentDataHelper = new DocumentDataHelper( emc, document ); + documentDataHelper.remove(); + + //删除文档的附件信息 + allFileInfoIds = business.getFileInfoFactory().listAllByDocument( docId ); + if( allFileInfoIds != null && !allFileInfoIds.isEmpty() ){ + for( String fileInfoId : allFileInfoIds ){ + fileInfo = emc.find( fileInfoId, FileInfo.class ); + if( fileInfo != null ){ + if( "ATTACHMENT".equals( fileInfo.getFileType() )){ + mapping = ThisApplication.context().storageMappings().get( FileInfo.class, fileInfo.getStorage() ); + fileInfo.deleteContent( mapping ); + } + } + emc.remove( fileInfo, CheckRemoveType.all ); + } + } + //删除文档信息 + emc.remove( document, CheckRemoveType.all ); + }catch( Exception e ) { + e.printStackTrace(); + } + } + emc.commit(); + ApplicationCache.notify( Document.class ); + } + count = documentServiceAdv.countByCategoryId( id ); + logger.info(">>>>已经删除"+queryMaxCount+"个文档,还剩下"+count+"个文档需要删除。"); + } + } + } + } + + Wo wo = new Wo(); + wo.setId(id); + result.setData(wo); + return result; + } + + public static class Wo extends WoId { + + } +} \ No newline at end of file diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/categoryinfo/CategoryInfoAction.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/categoryinfo/CategoryInfoAction.java index 751b2e88b4..353e7cda0f 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/categoryinfo/CategoryInfoAction.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/categoryinfo/CategoryInfoAction.java @@ -118,6 +118,26 @@ public class CategoryInfoAction extends StandardJaxrsAction{ return ResponseFactory.getDefaultActionResultResponse(result); } + @JaxrsMethodDescribe(value = "根据分类ID删除所有的信息文档.", action = ActionEraseDocumentWithCategory.class) + @DELETE + @Path("erase/category/{id}") + @Produces(HttpMediaType.APPLICATION_JSON_UTF_8) + @Consumes(MediaType.APPLICATION_JSON) + public Response eraseWithCategory(@Context HttpServletRequest request, + @JaxrsParameterDescribe("分类ID") @PathParam("id") String id) { + EffectivePerson effectivePerson = this.effectivePerson(request); + ActionResult result = new ActionResult<>(); + try { + result = new ActionEraseDocumentWithCategory().execute(request, id, effectivePerson ); + } catch (Exception e) { + result = new ActionResult<>(); + Exception exception = new ExceptionCategoryInfoProcess(e, "根据分类ID删除所有的信息文档发生未知异常,ID:" + id); + result.error(exception); + logger.error(e, effectivePerson, request, null); + } + return ResponseFactory.getDefaultActionResultResponse(result); + } + @JaxrsMethodDescribe(value = "获取用户有查看访问文章信息的所有分类列表.", action = ActionListWhatICanView_Article.class) @GET @Path("list/view/app/{appId}") diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/AppInfoService.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/AppInfoService.java index 81bb865034..3d1f473f5b 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/AppInfoService.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/AppInfoService.java @@ -167,6 +167,11 @@ public class AppInfoService { List document_ids = null; CategoryInfo categoryInfo = null; Document document = null; + Long docCount = 0L; + Integer totalWhileCount = 0; + Integer currenteWhileCount = 0; + Integer queryMaxCount = 1000; + Business business = new Business(emc); appInfo = emc.find( wrapIn.getId(), AppInfo.class ); emc.beginTransaction( AppInfo.class ); @@ -193,16 +198,28 @@ public class AppInfoService { emc.check( categoryInfo, CheckPersistType.all ); //对该目录下所有的文档的栏目名称和分类别名进行调整 - document_ids = business.getDocumentFactory().listByCategoryId( categoryId ); - if( document_ids != null && !document_ids.isEmpty() ){ - for( String docId : document_ids ){ - document = emc.find( docId, Document.class ); - document.setAppName( categoryInfo.getAppName() ); - document.setCategoryAlias( categoryInfo.getCategoryAlias() ); - if( document.getHasIndexPic() == null ){ - document.setHasIndexPic( false ); + docCount = business.getDocumentFactory().countByCategoryId( categoryInfo.getId() ); + if( docCount > 0 ) { + totalWhileCount = (int) (docCount/queryMaxCount) + 1; + if( totalWhileCount > 0 ) { + while( docCount > 0 && currenteWhileCount <= totalWhileCount ) { + document_ids = business.getDocumentFactory().listByCategoryId( categoryId, queryMaxCount ); + if( document_ids != null && !document_ids.isEmpty() ){ + for( String docId : document_ids ){ + try { + document = emc.find( docId, Document.class ); + document.setAppName( categoryInfo.getAppName() ); + document.setCategoryAlias( categoryInfo.getCategoryAlias() ); + if( document.getHasIndexPic() == null ){ + document.setHasIndexPic( false ); + } + emc.check( document, CheckPersistType.all ); + }catch( Exception e ) { + e.printStackTrace(); + } + } + } } - emc.check( document, CheckPersistType.all ); } } } diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/CategoryInfoService.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/CategoryInfoService.java index 125c4ce64b..85ba067fc9 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/CategoryInfoService.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/CategoryInfoService.java @@ -130,6 +130,10 @@ public class CategoryInfoService { String oldCategoryName = null; List document_ids = null; Business business = new Business(emc); + Long docCount = 0L; + Integer totalWhileCount = 0; + Integer currenteWhileCount = 0; + Integer queryMaxCount = 1000; if( temp_categoryInfo.getId() == null ){ temp_categoryInfo.setId( CategoryInfo.createId() ); @@ -183,16 +187,33 @@ public class CategoryInfoService { if( !oldCategoryName.equals( categoryInfo.getCategoryName() )){ emc.beginTransaction( Document.class ); //对该目录下所有的文档的栏目名称和分类别名进行调整 - document_ids = business.getDocumentFactory().listByCategoryId( categoryInfo.getId() ); - if( document_ids != null && !document_ids.isEmpty() ){ - for( String docId : document_ids ){ - document = emc.find( docId, Document.class ); - document.setAppName( categoryInfo.getAppName() ); - document.setCategoryAlias( categoryInfo.getCategoryAlias() ); - if( document.getHasIndexPic() == null ){ - document.setHasIndexPic( false ); + docCount = business.getDocumentFactory().countByCategoryId( categoryInfo.getId() ); + if( docCount > 0 ) { + totalWhileCount = (int) (docCount/queryMaxCount) + 1; + if( totalWhileCount > 0 ) { + while( docCount > 0 && currenteWhileCount <= totalWhileCount ) { + //查询1000个文档进行操作 + document_ids = business.getDocumentFactory().listByCategoryId( categoryInfo.getId(), queryMaxCount ); + if( document_ids != null && !document_ids.isEmpty() ){ + for( String docId : document_ids ){ + try { + document = emc.find( docId, Document.class ); + document.setAppName( categoryInfo.getAppName() ); + document.setCategoryAlias( categoryInfo.getCategoryAlias() ); + if( document.getHasIndexPic() == null ){ + document.setHasIndexPic( false ); + } + emc.check( document, CheckPersistType.all ); + }catch( Exception e ) { + e.printStackTrace(); + } + } + } + //当前循环次数+1 + currenteWhileCount ++; + //重新查询剩余的文档数量 + docCount = business.getDocumentFactory().countByCategoryId( categoryInfo.getId() ); } - emc.check( document, CheckPersistType.all ); } } } @@ -259,6 +280,10 @@ public class CategoryInfoService { AppInfo appInfo = null; ViewCategory viewCategory = null; List dataItems = null; + Long docCount = 0L; + Integer totalWhileCount = 0; + Integer currenteWhileCount = 0; + Integer queryMaxCount = 1000; Business business = new Business( emc ); emc.beginTransaction( AppInfo.class ); @@ -268,8 +293,7 @@ public class CategoryInfoService { emc.beginTransaction( Document.class ); emc.beginTransaction( Item.class ); - categoryInfo = emc.find( id, CategoryInfo.class ); - + categoryInfo = emc.find( id, CategoryInfo.class ); categoryExt = emc.find( id, CategoryExt.class ); ids = business.getViewCategoryFactory().listByCategoryId(id); @@ -291,26 +315,44 @@ public class CategoryInfoService { } //还有文档以及文档权限需要删除 - ids = business.getDocumentFactory().listByCategoryId( id ); - if( ids != null && !ids.isEmpty() ){ - for( String del_id : ids ){ - document = emc.find( del_id, Document.class ); - if( document != null ){ - //删除与该文档有关的所有数据信息 - dataItems = business.itemFactory().listWithDocmentWithPath(del_id); - if ((!dataItems.isEmpty())) { - emc.beginTransaction( Item.class ); - for ( Item o : dataItems ) { - emc.remove(o); + docCount = business.getDocumentFactory().countByCategoryId( id ); + if( docCount > 0 ) { + totalWhileCount = (int) (docCount/queryMaxCount) + 1; + if( totalWhileCount > 0 ) { + while( docCount > 0 && currenteWhileCount <= totalWhileCount ) { + //查询1000个文档进行操作 + ids = business.getDocumentFactory().listByCategoryId( id, queryMaxCount ); + if( ids != null && !ids.isEmpty() ){ + for( String del_id : ids ){ + document = emc.find( del_id, Document.class ); + if( document != null ){ + try { + //删除与该文档有关的所有数据信息 + dataItems = business.itemFactory().listWithDocmentWithPath( del_id ); + if ((!dataItems.isEmpty())) { + emc.beginTransaction( Item.class ); + for ( Item o : dataItems ) { + emc.remove(o); + } + } + }catch( Exception e ) { + e.printStackTrace(); + } + + //检查是否需要删除热点图片 + try { + ThisApplication.queueDocumentDelete.send( document.getId() ); + } catch ( Exception e1 ) { + e1.printStackTrace(); + } + emc.remove( document ); + } } } - //检查是否需要删除热点图片 - try { - ThisApplication.queueDocumentDelete.send( document.getId() ); - } catch ( Exception e1 ) { - e1.printStackTrace(); - } - emc.remove( document ); + //当前循环次数+1 + currenteWhileCount ++; + //重新查询剩余的文档数量 + docCount = business.getDocumentFactory().countByCategoryId( id ); } } } diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/DocumentInfoService.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/DocumentInfoService.java index eb4c7874fa..ce3c66009f 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/DocumentInfoService.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/DocumentInfoService.java @@ -17,13 +17,26 @@ import com.x.query.core.entity.Item; public class DocumentInfoService { -// public List list( EntityManagerContainer emc, List ids ) throws Exception { -// if( ids == null || ids.isEmpty() ){ -// return null; -// } -// Business business = new Business( emc ); -// return business.getDocumentFactory().list( ids ); -// } + @SuppressWarnings("unchecked") + public List listByCategoryId( EntityManagerContainer emc, String categoryId, Integer maxCount ) throws Exception { + if( categoryId == null || categoryId.isEmpty() ){ + return null; + } + Business business = new Business( emc ); + return business.getDocumentFactory().listByCategoryId( categoryId, maxCount ); + } + + @SuppressWarnings("unchecked") + public List listByAppId( EntityManagerContainer emc, String appId, String documentType, Integer maxCount ) throws Exception { + if( appId == null || appId.isEmpty() ){ + return null; + } + if( documentType == null || documentType.isEmpty() ){ + documentType = "全部"; + } + Business business = new Business( emc ); + return business.getDocumentFactory().listByAppId( appId, documentType, maxCount ); + } @SuppressWarnings("unchecked") public List listByCategoryId( EntityManagerContainer emc, String categoryId ) throws Exception { @@ -31,7 +44,7 @@ public class DocumentInfoService { return null; } Business business = new Business( emc ); - return business.getDocumentFactory().listByCategoryId( categoryId ); + return business.getDocumentFactory().listByCategoryId( categoryId, 10000 ); } public Document get(EntityManagerContainer emc, String id) throws Exception { @@ -49,6 +62,14 @@ public class DocumentInfoService { Business business = new Business( emc ); return business.getDocumentFactory().countByCategoryId(categoryId); } + + public Long countByAppId(EntityManagerContainer emc, String appId) throws Exception { + if( appId == null || appId.isEmpty() ){ + return null; + } + Business business = new Business( emc ); + return business.getDocumentFactory().countByAppId(appId); + } public Document save( EntityManagerContainer emc, Document wrapIn ) throws Exception { if( wrapIn == null ){ diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/DocumentInfoServiceAdv.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/DocumentInfoServiceAdv.java index d1aa9ae9d7..98692e7738 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/DocumentInfoServiceAdv.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/service/DocumentInfoServiceAdv.java @@ -58,6 +58,28 @@ public class DocumentInfoServiceAdv { throw e; } } + + public List listIdsByCategoryId( String categoryId, Integer maxCount ) throws Exception { + if( categoryId == null || categoryId.isEmpty() ){ + throw new Exception("categoryId is null!"); + } + try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) { + return documentInfoService.listByCategoryId( emc, categoryId, maxCount ); + } catch ( Exception e ) { + throw e; + } + } + + public List listIdsByAppId( String appId, String documentType, Integer maxCount ) throws Exception { + if( appId == null || appId.isEmpty() ){ + throw new Exception("categoryId is null!"); + } + try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) { + return documentInfoService.listByAppId( emc, appId, documentType, maxCount ); + } catch ( Exception e ) { + throw e; + } + } public Document get( String id ) throws Exception { if( id == null || id.isEmpty() ){ @@ -125,6 +147,17 @@ public class DocumentInfoServiceAdv { throw e; } } + + public Long countByAppId(String appId ) throws Exception { + if( appId == null || appId.isEmpty() ){ + throw new Exception("appId is null!"); + } + try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) { + return documentInfoService.countByAppId( emc, appId ); + } catch ( Exception e ) { + throw e; + } + } public List list(List ids) throws Exception { if( ListTools.isEmpty( ids ) ){ diff --git a/o2server/x_file_assemble_control/src/main/java/com/x/file/assemble/control/jaxrs/file/ActionUpload.java b/o2server/x_file_assemble_control/src/main/java/com/x/file/assemble/control/jaxrs/file/ActionUpload.java index 3d29e4c728..60800b3c8e 100644 --- a/o2server/x_file_assemble_control/src/main/java/com/x/file/assemble/control/jaxrs/file/ActionUpload.java +++ b/o2server/x_file_assemble_control/src/main/java/com/x/file/assemble/control/jaxrs/file/ActionUpload.java @@ -46,7 +46,7 @@ class ActionUpload extends BaseAction { String fileName = new String(disposition.getFileName().getBytes(DefaultCharset.charset_iso_8859_1), DefaultCharset.charset); fileName = FilenameUtils.getName(fileName); - + if (StringUtils.isEmpty(FilenameUtils.getExtension(fileName))) { throw new ExceptionEmptyExtension(fileName); } diff --git a/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/identity/ActionErrorInfoFilterListNextWithFilter.java b/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/identity/ActionErrorInfoFilterListNextWithFilter.java index 70d7cdb330..68cae0d45a 100644 --- a/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/identity/ActionErrorInfoFilterListNextWithFilter.java +++ b/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/identity/ActionErrorInfoFilterListNextWithFilter.java @@ -53,18 +53,20 @@ public class ActionErrorInfoFilterListNextWithFilter extends BaseAction { } } if (check) { - try { - if (!okrUserInfoService.getIsOkrManager(currentPerson.getDistinguishedName())) { + if( !"xadmin".equalsIgnoreCase( currentPerson.getName() )) { + try { + if (!okrUserInfoService.getIsOkrManager(currentPerson.getDistinguishedName())) { + check = false; + Exception exception = new ExceptionInsufficientPermissions(currentPerson.getDistinguishedName(), + ThisApplication.OKRMANAGER); + result.error(exception); + } + } catch (Exception e) { check = false; - Exception exception = new ExceptionInsufficientPermissions(currentPerson.getDistinguishedName(), - ThisApplication.OKRMANAGER); + Exception exception = new ExceptionOkrSystemAdminCheck(e, currentPerson.getDistinguishedName()); result.error(exception); + logger.error(e, currentPerson, request, null); } - } catch (Exception e) { - check = false; - Exception exception = new ExceptionOkrSystemAdminCheck(e, currentPerson.getDistinguishedName()); - result.error(exception); - logger.error(e, currentPerson, request, null); } } diff --git a/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/login/ActionLogin.java b/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/login/ActionLogin.java index 4c096ccaf4..65486eb2b8 100644 --- a/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/login/ActionLogin.java +++ b/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/login/ActionLogin.java @@ -57,18 +57,32 @@ public class ActionLogin extends BaseAction { okrUserCache = setUserLoginIdentity( request, effectivePerson, wrapIn.getLoginIdentity() ); result.setData(okrUserCache); } catch (Exception e) { - Exception exception = new ExceptionGetOkrUserCache(e, effectivePerson.getDistinguishedName(), - wrapIn.getLoginIdentity()); + Exception exception = new ExceptionGetOkrUserCache(e, effectivePerson.getDistinguishedName(), wrapIn.getLoginIdentity()); result.error(exception); logger.error(e, effectivePerson, request, null); } } else {// 用户自己没有传入的身份,查询用户是否有该身份的代理配置(秘书) try { ids = okrConfigSecretaryService.listIdsByLeaderIdentity(effectivePerson.getDistinguishedName(), wrapIn.getLoginIdentity()); - if (ListTools.isEmpty(ids)) {//用户没有指定身份的代理权限,无法登录系统 - check = false; - Exception exception = new ExceptionUserHasNoProxyIdentity( effectivePerson.getDistinguishedName(), wrapIn.getLoginIdentity()); - result.error(exception); + if (ListTools.isEmpty(ids)) {//用户没有指定身份的代理权限,无法登录系统 + //以用户自己的主要身份进行登录 + identity = okrUserManagerService.getIdentityWithPerson( effectivePerson.getDistinguishedName() ); + if( StringUtils.isNotEmpty( identity )) { + System.out.println( "用户使用身份:" + identity + " 登录系统......" ); + try { + okrUserCache = setUserLoginIdentity( request, effectivePerson, identity ); + result.setData(okrUserCache); + } catch (Exception e) { + check = false; + Exception exception = new ExceptionGetOkrUserCache(e, effectivePerson.getDistinguishedName(), wrapIn.getLoginIdentity()); + result.error(exception); + logger.error(e, effectivePerson, request, null); + } + }else { + check = false; + Exception exception = new ExceptionUserHasNoProxyIdentity( effectivePerson.getDistinguishedName(), wrapIn.getLoginIdentity()); + result.error(exception); + } } else {// 顺利查询到身份代理配置信息,向cache里新增用户相关信息 okrUserCache = setUserLoginIdentity(request, effectivePerson, wrapIn.getLoginIdentity()); result.setData(okrUserCache); diff --git a/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/okrcenterworkinfo/ActionListNextWithFilterAdmin.java b/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/okrcenterworkinfo/ActionListNextWithFilterAdmin.java index dcc3a8670e..2d4b1a760e 100644 --- a/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/okrcenterworkinfo/ActionListNextWithFilterAdmin.java +++ b/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/okrcenterworkinfo/ActionListNextWithFilterAdmin.java @@ -53,18 +53,19 @@ public class ActionListNextWithFilterAdmin extends BaseAction { } if (check) { - try { - if (!okrUserInfoService.getIsOkrManager(currentPerson.getDistinguishedName())) { + if( !"xadmin".equalsIgnoreCase( currentPerson.getName() )) { + try { + if (!okrUserInfoService.getIsOkrManager(currentPerson.getDistinguishedName())) { + check = false; + Exception exception = new ExceptionInsufficientPermissions(currentPerson.getDistinguishedName(), ThisApplication.OKRMANAGER); + result.error(exception); + } + } catch (Exception e) { check = false; - Exception exception = new ExceptionInsufficientPermissions(currentPerson.getDistinguishedName(), - ThisApplication.OKRMANAGER); + Exception exception = new ExceptionOkrSystemAdminCheck(e, currentPerson.getDistinguishedName()); result.error(exception); + logger.error(e, currentPerson, request, null); } - } catch (Exception e) { - check = false; - Exception exception = new ExceptionOkrSystemAdminCheck(e, currentPerson.getDistinguishedName()); - result.error(exception); - logger.error(e, currentPerson, request, null); } } diff --git a/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/okrtask/ActionListNextWithFilter.java b/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/okrtask/ActionListNextWithFilter.java index 002bde6d2f..2b071238bf 100644 --- a/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/okrtask/ActionListNextWithFilter.java +++ b/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/jaxrs/okrtask/ActionListNextWithFilter.java @@ -54,19 +54,21 @@ public class ActionListNextWithFilter extends BaseAction { logger.error(e, effectivePerson, request, null); } - try { - if (!okrUserInfoService.getIsOkrManager(effectivePerson.getDistinguishedName())) { + if( !"xadmin".equalsIgnoreCase( effectivePerson.getName() )) { + try { + if (!okrUserInfoService.getIsOkrManager(effectivePerson.getDistinguishedName())) { + check = false; + Exception exception = new ExceptionInsufficientPermissions(effectivePerson.getDistinguishedName(), ThisApplication.OKRMANAGER); + result.error(exception); + } + } catch (Exception e) { check = false; - Exception exception = new ExceptionInsufficientPermissions(effectivePerson.getDistinguishedName(), - ThisApplication.OKRMANAGER); + Exception exception = new ExceptionOkrSystemAdminCheck(e, effectivePerson.getDistinguishedName()); result.error(exception); + logger.error(e, effectivePerson, request, null); } - } catch (Exception e) { - check = false; - Exception exception = new ExceptionOkrSystemAdminCheck(e, effectivePerson.getDistinguishedName()); - result.error(exception); - logger.error(e, effectivePerson, request, null); } + if (check) { if (wrapIn.getFilterLikeContent() != null && !wrapIn.getFilterLikeContent().isEmpty()) { diff --git a/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/service/OkrUserManagerService.java b/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/service/OkrUserManagerService.java index daaa876071..503a13170f 100644 --- a/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/service/OkrUserManagerService.java +++ b/o2server/x_okr_assemble_control/src/main/java/com/x/okr/assemble/control/service/OkrUserManagerService.java @@ -6,6 +6,7 @@ import com.x.base.core.container.EntityManagerContainer; import com.x.base.core.container.factory.EntityManagerContainerFactory; import com.x.base.core.project.organization.Person; import com.x.base.core.project.organization.Unit; +import com.x.base.core.project.tools.ListTools; import com.x.okr.assemble.control.Business; /** @@ -173,6 +174,12 @@ public class OkrUserManagerService { try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { business = new Business(emc); identities = business.organization().identity().listWithPerson( personName ); + System.out.println(">>>>>>>>>>>loginIdentity:" + loginIdentity ); + if( ListTools.isNotEmpty( identities )) { + for( String identity : identities ) { + System.out.println(">>>>>>>>>>>identity:" + identity ); + } + } if( identities.contains( loginIdentity )){ return true; } diff --git a/o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/ScriptHelperFactory.java b/o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/ScriptHelperFactory.java index db794fb57a..1bd32f916d 100644 --- a/o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/ScriptHelperFactory.java +++ b/o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/ScriptHelperFactory.java @@ -63,25 +63,25 @@ public class ScriptHelperFactory { * @return * @throws Exception */ - public static ScriptHelper create(Business business, Work work, Data data, Activity activity, - BindingPair... bindingPairs) throws Exception { - WorkContext workContext = new WorkContext(business, work, activity); - Map map = new HashMap<>(); - map.put(ScriptingEngine.BINDINGNAME_WORKCONTEXT, workContext); - map.put(ScriptingEngine.BINDINGNAME_DATA, data); - map.put(ScriptingEngine.BINDINGNAME_ORGANIZATION, new Organization(ThisApplication.context())); - map.put(ScriptingEngine.BINDINGNAME_WEBSERVICESCLIENT, new WebservicesClient()); - map.put(ScriptingEngine.BINDINGNAME_DICTIONARY, - new ApplicationDictHelper(business.entityManagerContainer(), work.getApplication())); - map.put(ScriptingEngine.BINDINGNAME_APPLICATIONS, ThisApplication.context().applications()); - for (BindingPair o : bindingPairs) { - map.put(o.getName(), o.getValue()); - } - ScriptHelper sh = new ScriptHelper(business, map, initialScriptText); - return sh; - } +// public static ScriptHelper create(Business business, Work work, Data data, Activity activity, +// BindingPair... bindingPairs) throws Exception { +// WorkContext workContext = new WorkContext(business, work, activity); +// Map map = new HashMap<>(); +// map.put(ScriptingEngine.BINDINGNAME_WORKCONTEXT, workContext); +// map.put(ScriptingEngine.BINDINGNAME_DATA, data); +// map.put(ScriptingEngine.BINDINGNAME_ORGANIZATION, new Organization(ThisApplication.context())); +// map.put(ScriptingEngine.BINDINGNAME_WEBSERVICESCLIENT, new WebservicesClient()); +// map.put(ScriptingEngine.BINDINGNAME_DICTIONARY, +// new ApplicationDictHelper(business.entityManagerContainer(), work.getApplication())); +// map.put(ScriptingEngine.BINDINGNAME_APPLICATIONS, ThisApplication.context().applications()); +// for (BindingPair o : bindingPairs) { +// map.put(o.getName(), o.getValue()); +// } +// ScriptHelper sh = new ScriptHelper(business, map, initialScriptText); +// return sh; +// } - public static ScriptHelper create(Business business, Work work, Data data, Activity activity, Task task, + public static ScriptHelper createWithTask(Business business, Work work, Data data, Activity activity, Task task, BindingPair... bindingPairs) throws Exception { WorkContext workContext = new WorkContext(business, work, activity, task); Map map = new HashMap<>(); @@ -99,7 +99,7 @@ public class ScriptHelperFactory { return sh; } - public static ScriptHelper create(Business business, Work work, Data data, Activity activity, + public static ScriptHelper createWithTaskCompleted(Business business, Work work, Data data, Activity activity, TaskCompleted taskCompleted, BindingPair... bindingPairs) throws Exception { WorkContext workContext = new WorkContext(business, work, activity, taskCompleted); Map map = new HashMap<>(); -- GitLab