diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionNotify.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionNotify.java new file mode 100644 index 0000000000000000000000000000000000000000..0ce69713f9722aec79288b490c0e4413897df43f --- /dev/null +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionNotify.java @@ -0,0 +1,65 @@ +package com.x.cms.assemble.control.jaxrs.document; + +import com.google.gson.JsonElement; +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.WrapBoolean; +import com.x.base.core.project.logger.Logger; +import com.x.base.core.project.logger.LoggerFactory; +import com.x.cms.assemble.control.Business; +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.query.DocumentNotify; + +/** + * 文档发送消息通知 + * @author sword + */ +public class ActionNotify extends BaseAction { + + private static Logger logger = LoggerFactory.getLogger(ActionNotify.class); + + protected ActionResult execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement ) throws Exception { + logger.debug(effectivePerson.getDistinguishedName()); + ActionResult result = new ActionResult<>(); + Wi wi = this.convertToWrapIn( jsonElement, Wi.class ); + + Document document = documentQueryService.get(id); + if(document == null){ + throw new ExceptionEntityNotExist(id); + } + if(!Document.DOC_STATUS_PUBLISH.equals(document.getDocStatus())){ + throw new IllegalStateException("文档未发布"); + } + wi.setDocumentId(id); + + AppInfo appInfo = appInfoServiceAdv.get(document.getAppId()); + if(appInfo == null){ + if(document == null){ + throw new ExceptionEntityNotExist(document.getAppId(), AppInfo.class); + } + } + + Business business = new Business(null); + if(!effectivePerson.getDistinguishedName().equals(document.getCreatorPerson()) && !business.isAppInfoManager(effectivePerson, appInfo)){ + throw new ExceptionAccessDenied(effectivePerson); + } + + ThisApplication.queueSendDocumentNotify.send(wi); + result.setData(new Wo(true)); + return result; + } + + public static class Wi extends DocumentNotify { + + } + + public static class Wo extends WrapBoolean { + public Wo(Boolean value){ + super(value); + } + } +} diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishAndNotify.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishAndNotify.java index 9ec1130e938a83a8202d5bc1fc25ed910ee75e58..3672c50770f5ca5a196651ec40c7c82a465727b1 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishAndNotify.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishAndNotify.java @@ -16,7 +16,6 @@ import com.x.base.core.project.logger.Logger; import com.x.base.core.project.logger.LoggerFactory; import com.x.cms.assemble.control.ThisApplication; import com.x.cms.assemble.control.jaxrs.permission.element.PermissionInfo; -import com.x.cms.core.entity.CategoryInfo; import com.x.cms.core.entity.Document; import com.x.cms.core.entity.FileInfo; @@ -25,6 +24,9 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +/** + * @author sword + */ public class ActionPersistPublishAndNotify extends BaseAction { private static Logger logger = LoggerFactory.getLogger(ActionPersistPublishAndNotify.class); @@ -65,8 +67,8 @@ public class ActionPersistPublishAndNotify extends BaseAction { } if (check) { try { - modifyDocStatus( id, "published", effectivePerson.getDistinguishedName() ); - document.setDocStatus("published"); + modifyDocStatus( id, Document.DOC_STATUS_PUBLISH, effectivePerson.getDistinguishedName() ); + document.setDocStatus(Document.DOC_STATUS_PUBLISH); document.setPublishTime(new Date()); document = documentPersistService.refreshDocInfoData( document ); @@ -177,43 +179,14 @@ public class ActionPersistPublishAndNotify extends BaseAction { //将读者以及作者信息持久化到数据库中 if( !wi.getSkipPermission() ) { try { - document = documentPersistService.refreshDocumentPermission( id, wi.getReaderList(), wi.getAuthorList() ); + documentPersistService.refreshDocumentPermission( id, wi.getReaderList(), wi.getAuthorList() ); } catch (Exception e) { - check = false; Exception exception = new ExceptionDocumentInfoProcess(e, "系统在核对文档访问管理权限信息时发生异常!"); result.error(exception); logger.error(e, effectivePerson, request, null); } } - //判断是否需要发送通知消息 - if (check) { - try { - CategoryInfo categoryInfo = categoryInfoServiceAdv.getWithFlag( document.getCategoryId() ); - if( categoryInfo != null ){ -// Boolean notify = false; -// if( categoryInfo.getSendNotify() == null ) { -// if( StringUtils.equals("信息", categoryInfo.getDocumentType()) ) { -// notify = true; -// } -// }else { -// if( categoryInfo.getSendNotify() ) { -// notify = true; -// } -// } - if( categoryInfo.getSendNotify() ){ - logger.info("try to add notify object to queue for document:" + document.getTitle() ); - ThisApplication.queueSendDocumentNotify.send( document.getId() ); - } - } - } catch (Exception e) { - check = false; - Exception exception = new ExceptionDocumentInfoProcess( e, "根据ID查询分类信息对象时发生异常。Flag:" + document.getCategoryId() ); - result.error( exception ); - logger.error( e, effectivePerson, request, null); - } - } - CacheManager.notify( Document.class ); return result; diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishContent.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishContent.java index 71a47a686925d9cfc32a3b45841a19c629c1f75c..f88021968a45bab34648e883d9356ea2d1661b2d 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishContent.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishContent.java @@ -12,7 +12,6 @@ import com.x.base.core.project.config.StorageMapping; import com.x.base.core.project.exception.ExceptionWhen; import com.x.processplatform.core.entity.content.Attachment; import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import com.google.gson.JsonElement; @@ -22,7 +21,6 @@ import com.x.base.core.project.annotation.AuditLog; 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.gson.XGsonBuilder; import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.EffectivePerson; import com.x.base.core.project.jaxrs.WoId; @@ -417,40 +415,14 @@ public class ActionPersistPublishContent extends BaseAction { if ( check && !wi.getSkipPermission() ) { //将读者以及作者信息持久化到数据库中 try { - document = documentPersistService.refreshDocumentPermission( document.getId(), wi.getReaderList(), wi.getAuthorList() ); + documentPersistService.refreshDocumentPermission( document.getId(), wi.getReaderList(), wi.getAuthorList() ); } catch (Exception e) { - check = false; Exception exception = new ExceptionDocumentInfoProcess(e, "系统在核对文档访问管理权限信息时发生异常!"); result.error(exception); logger.error(e, effectivePerson, request, null); } } - //判断是否需要发送通知消息 - if (check) { - try { - Boolean notify = false; - if( categoryInfo.getSendNotify() == null ) { - if( StringUtils.equals("信息", categoryInfo.getDocumentType()) ) { - notify = true; - } - }else { - if( categoryInfo.getSendNotify() ) { - notify = true; - } - } - if( notify && !BooleanUtils.isFalse(wi.getNotice())){ - logger.debug("try to add notify object to queue for document:" + document.getTitle() ); - ThisApplication.queueSendDocumentNotify.send( document.getId() ); - } - } catch (Exception e) { - check = false; - Exception exception = new ExceptionDocumentInfoProcess( e, "根据ID查询分类信息对象时发生异常。Flag:" + document.getCategoryId() ); - result.error( exception ); - logger.error( e, effectivePerson, request, null); - } - } - CacheManager.notify(FileInfo.class); CacheManager.notify(Document.class); return result; diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/DocumentAction.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/DocumentAction.java index 8727093b09187495863faa88dc3f1dc425b84025..8803a97f91a6707a9256b5acfc0e07fa5e5d808f 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/DocumentAction.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/DocumentAction.java @@ -1050,4 +1050,23 @@ public class DocumentAction extends StandardJaxrsAction { } asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); } + + @JaxrsMethodDescribe(value = "已发布文档消息通知。", action = ActionNotify.class) + @POST + @Path("{id}/notify") + @Produces(HttpMediaType.APPLICATION_JSON_UTF_8) + @Consumes(MediaType.APPLICATION_JSON) + public void publishNotify(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, + @JaxrsParameterDescribe("文档ID") @PathParam("id") String id, JsonElement jsonElement) { + EffectivePerson effectivePerson = this.effectivePerson(request); + ActionResult result = new ActionResult<>(); + try { + result = new ActionNotify().execute(effectivePerson, id, jsonElement); + } catch (Exception e) { + result.error(e); + logger.error(e, effectivePerson, request, jsonElement); + } + + asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); + } } diff --git a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/queue/QueueSendDocumentNotify.java b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/queue/QueueSendDocumentNotify.java index a18608ad5350d3cab2598f2bb5e04252587d7349..211dd796f0a4631b086fe4ce18abe228fa55a08e 100644 --- a/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/queue/QueueSendDocumentNotify.java +++ b/o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/queue/QueueSendDocumentNotify.java @@ -5,10 +5,8 @@ import com.x.base.core.entity.JpaObject; 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.config.Config; import com.x.base.core.project.logger.Logger; import com.x.base.core.project.logger.LoggerFactory; -import com.x.base.core.project.message.MessageConnector; import com.x.base.core.project.queue.AbstractQueue; import com.x.base.core.project.tools.ListTools; import com.x.cms.assemble.control.MessageFactory; @@ -17,6 +15,7 @@ import com.x.cms.assemble.control.service.UserManagerService; import com.x.cms.core.entity.AppInfo; import com.x.cms.core.entity.CategoryInfo; import com.x.cms.core.entity.Document; +import com.x.cms.core.entity.query.DocumentNotify; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; @@ -29,51 +28,62 @@ import java.util.stream.Collectors; * Document正式发布后,向通知对象或者所有的阅读者推送消息通知 * @author sword */ -public class QueueSendDocumentNotify extends AbstractQueue { +public class QueueSendDocumentNotify extends AbstractQueue { private static Logger logger = LoggerFactory.getLogger( QueueSendDocumentNotify.class ); private UserManagerService userManagerService = new UserManagerService(); @Override - public void execute(String documentId ) throws Exception { - logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>start QueueSendDocumentNotify:" + documentId ); - if( StringUtils.isEmpty(documentId) ) { - logger.debug("can not send publish notify , document is NULL!" ); + public void execute(DocumentNotify documentNotify ) throws Exception { + logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>start QueueSendDocumentNotify:{}", documentNotify); + if( StringUtils.isEmpty(documentNotify.getDocumentId()) ) { return; } final List persons = new ArrayList<>(); Document document = null; + AppInfo appInfo = null; + CategoryInfo category = null; try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { - document = emc.find(documentId, Document.class); - if(document !=null && StringUtils.equals( "信息" , document.getDocumentType()) && Config.messages().get(MessageConnector.TYPE_CMS_PUBLISH)!=null) { - logger.debug("send publish notify for new document:" + document.getTitle() ); - AppInfo appInfo = emc.find(document.getAppId(), AppInfo.class); - CategoryInfo category = emc.find(document.getCategoryId(), CategoryInfo.class); - if (appInfo != null && category != null) { - ReviewService reviewService = new ReviewService(); - persons.addAll(reviewService.listPermissionPersons(appInfo, category, document)); - if (ListTools.isNotEmpty(persons)) { - //有可能是*, 一般是所有的人员标识列表 - if (persons.contains("*") && !BooleanUtils.isFalse(category.getBlankToAllNotify())) { - String topUnitName = document.getCreatorTopUnitName(); - logger.debug(">>>>>document.getCreatorTopUnitName()=" + topUnitName); - if (StringUtils.equalsAnyIgnoreCase("cipher", topUnitName) || StringUtils.equalsAnyIgnoreCase("xadmin", topUnitName)) { - //取发起人所有顶层组织 - if (!StringUtils.equalsAnyIgnoreCase("cipher", document.getCreatorIdentity()) && - !StringUtils.equalsAnyIgnoreCase("xadmin", document.getCreatorIdentity())) { - topUnitName = userManagerService.getTopUnitNameByIdentity(document.getCreatorIdentity()); - } else if (!StringUtils.equalsAnyIgnoreCase("cipher", document.getCreatorPerson()) && - !StringUtils.equalsAnyIgnoreCase("xadmin", document.getCreatorPerson())) { - topUnitName = userManagerService.getTopUnitNameWithPerson(document.getCreatorPerson()); - } - } - if (StringUtils.isNotEmpty(topUnitName)) { - //取顶层组织的所有人 - persons.addAll(listPersonWithUnit(topUnitName)); - } - } + document = emc.find(documentNotify.getDocumentId(), Document.class); + if(document!=null){ + appInfo = emc.find(document.getAppId(), AppInfo.class); + category = emc.find(document.getCategoryId(), CategoryInfo.class); + if(appInfo==null || category==null){ + return; + } + }else{ + return; + } + } + if(BooleanUtils.isFalse(category.getSendNotify())){ + return; + } + if(ListTools.isNotEmpty(documentNotify.getNotifyPersonList()) + && !BooleanUtils.isTrue(documentNotify.getNotifyByDocumentReadPerson())){ + documentNotify.getNotifyPersonList().stream().forEach(name -> { + persons.addAll(userManagerService.listPersonWithName(name)); + }); + }else{ + ReviewService reviewService = new ReviewService(); + persons.addAll(reviewService.listPermissionPersons(appInfo, category, document)); + if(persons.contains("*")){ + String topUnitName = document.getCreatorTopUnitName(); + if (StringUtils.equalsAnyIgnoreCase("cipher", topUnitName) || + StringUtils.equalsAnyIgnoreCase("xadmin", topUnitName)) { + //取发起人所有顶层组织 + if (!StringUtils.equalsAnyIgnoreCase("cipher", document.getCreatorIdentity()) && + !StringUtils.equalsAnyIgnoreCase("xadmin", document.getCreatorIdentity())) { + topUnitName = userManagerService.getTopUnitNameByIdentity(document.getCreatorIdentity()); + } else if (!StringUtils.equalsAnyIgnoreCase("cipher", document.getCreatorPerson()) && + !StringUtils.equalsAnyIgnoreCase("xadmin", document.getCreatorPerson())) { + topUnitName = userManagerService.getTopUnitNameWithPerson(document.getCreatorPerson()); } } + if (StringUtils.isNotEmpty(topUnitName)) { + //取顶层组织的所有人 + persons.clear(); + persons.addAll(listPersonWithUnit(topUnitName)); + } } } if( ListTools.isNotEmpty( persons )) { @@ -87,13 +97,15 @@ public class QueueSendDocumentNotify extends AbstractQueue { } } personList.clear(); - logger.debug(documentId +" cms send total count:" + persons.size() ); + logger.debug(documentNotify.getDocumentId() +" cms send total count:" + persons.size() ); } - if(document!=null && StringUtils.isNotBlank(document.getCreatorPerson())){ + boolean flag = document!=null && StringUtils.isNotBlank(document.getCreatorPerson()) && + !BooleanUtils.isFalse(documentNotify.getNotifyCreatePerson()); + if(flag){ MessageWo wo = MessageWo.copier.copy(document); MessageFactory.cms_publish_creator(wo); } - logger.debug(documentId + " QueueSendDocumentNotify cms send publish notify for new document completed! " ); + logger.debug(documentNotify.getDocumentId() + " QueueSendDocumentNotify cms send publish notify for new document completed! " ); } /** @@ -102,7 +114,6 @@ public class QueueSendDocumentNotify extends AbstractQueue { * @return */ private List listPersonWithUnit(String unitName) { - UserManagerService userManagerService = new UserManagerService(); List persons = null; try { persons = userManagerService.listPersonWithUnit(unitName); diff --git a/o2server/x_cms_core_entity/src/main/java/com/x/cms/core/entity/Document.java b/o2server/x_cms_core_entity/src/main/java/com/x/cms/core/entity/Document.java index 6fbc3ce668a950c05f9b812b9003ca55a75381a1..c35aba8002b50662413a42f8e1d2a6a6052671ea 100644 --- a/o2server/x_cms_core_entity/src/main/java/com/x/cms/core/entity/Document.java +++ b/o2server/x_cms_core_entity/src/main/java/com/x/cms/core/entity/Document.java @@ -48,6 +48,7 @@ public class Document extends SliceJpaObject { private static final long serialVersionUID = 7668822947307502058L; private static final String TABLE = PersistenceProperties.Document.table; public static final int STRING_VALUE_MAX_LENGTH = JpaObject.length_255B; + public static final String DOC_STATUS_PUBLISH = "published"; /* 以上为 JpaObject 默认字段 */ @Override diff --git a/o2server/x_cms_core_entity/src/main/java/com/x/cms/core/entity/query/DocumentNotify.java b/o2server/x_cms_core_entity/src/main/java/com/x/cms/core/entity/query/DocumentNotify.java new file mode 100644 index 0000000000000000000000000000000000000000..6b4a6894516b13cc2fe0cbd3f93406a9c72d7ec4 --- /dev/null +++ b/o2server/x_cms_core_entity/src/main/java/com/x/cms/core/entity/query/DocumentNotify.java @@ -0,0 +1,58 @@ +package com.x.cms.core.entity.query; + +import com.x.base.core.project.annotation.FieldDescribe; +import com.x.base.core.project.gson.GsonPropertyObject; + +import java.util.List; + +/** + * 消息通知对象 + * + * @author sword + * @date 2022/03/10 16:45 + **/ +public class DocumentNotify extends GsonPropertyObject { + @FieldDescribe("文档ID") + private String documentId; + + @FieldDescribe("消息通知对象:人员、组织或者群组") + private List notifyPersonList; + + @FieldDescribe("是否根据文档的可见范围发送:true(忽略notifyPersonList的值)|false(默认)") + private Boolean notifyByDocumentReadPerson; + + @FieldDescribe("是否通知文档创建人:true(默认)|false") + private Boolean notifyCreatePerson; + + public String getDocumentId() { + return documentId; + } + + public void setDocumentId(String documentId) { + this.documentId = documentId; + } + + public List getNotifyPersonList() { + return notifyPersonList; + } + + public void setNotifyPersonList(List notifyPersonList) { + this.notifyPersonList = notifyPersonList; + } + + public Boolean getNotifyByDocumentReadPerson() { + return notifyByDocumentReadPerson; + } + + public void setNotifyByDocumentReadPerson(Boolean notifyByDocumentReadPerson) { + this.notifyByDocumentReadPerson = notifyByDocumentReadPerson; + } + + public Boolean getNotifyCreatePerson() { + return notifyCreatePerson; + } + + public void setNotifyCreatePerson(Boolean notifyCreatePerson) { + this.notifyCreatePerson = notifyCreatePerson; + } +}