提交 bcf9b57b 编写于 作者: O o2null

Merge branch '内容管理文档点赞与评论点赞合并' into 'develop'

内容管理文档点赞与评论点赞合并

See merge request o2oa/o2oa!253

(cherry picked from commit 2af8c6e9)

c1ff3f3b 内容管理文档点赞与评论点赞合并
64bf563a 内容管理文档点赞与评论点赞合并2
上级 9b614520
......@@ -13,14 +13,15 @@ import com.x.cms.assemble.control.AbstractFactory;
import com.x.cms.assemble.control.Business;
import com.x.cms.core.entity.DocumentCommend;
import com.x.cms.core.entity.DocumentCommend_;
import org.apache.commons.lang3.StringUtils;
/**
* 文档点赞基础功能服务类
*
*
* @author O2LEE
*/
public class DocumentCommendFactory extends AbstractFactory {
public DocumentCommendFactory(Business business) throws Exception {
super(business);
}
......@@ -29,35 +30,66 @@ public class DocumentCommendFactory extends AbstractFactory {
return this.entityManagerContainer().find(id, DocumentCommend.class, ExceptionWhen.none);
}
public List<String> listWithPerson( String personName, Integer maxCount ) throws Exception {
if( maxCount == null || maxCount == 0 ) {
maxCount = 10;
public List<String> listWithPerson( String personName, Integer maxCount, String type) throws Exception {
if( maxCount == null) {
maxCount = 0;
}
EntityManager em = this.entityManagerContainer().get( DocumentCommend.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<DocumentCommend> root = cq.from( DocumentCommend.class );
Predicate p = cb.equal(root.get( DocumentCommend_.commendPerson), personName );
if(StringUtils.isNoneBlank(type)){
p = cb.and( p, cb.equal(root.get( DocumentCommend_.type), type ) );
}
cq.select( root.get( DocumentCommend_.id) ).where(p);
return em.createQuery( cq ).setMaxResults(maxCount).getResultList();
if(maxCount<1){
return em.createQuery(cq).getResultList();
}else {
return em.createQuery(cq).setMaxResults(maxCount).getResultList();
}
}
public List<String> listByDocument( String docId, Integer maxCount ) throws Exception {
if( maxCount == null || maxCount == 0 ) {
maxCount = 10;
public List<String> listByDocument( String docId, Integer maxCount, String type) throws Exception {
if( maxCount == null) {
maxCount = 0;
}
EntityManager em = this.entityManagerContainer().get( DocumentCommend.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<DocumentCommend> root = cq.from( DocumentCommend.class );
Predicate p = cb.equal(root.get( DocumentCommend_.documentId), docId );
if(StringUtils.isNoneBlank(type)){
p = cb.and( p, cb.equal(root.get( DocumentCommend_.type), type ) );
}
cq.select( root.get( DocumentCommend_.id) ).where(p);
return em.createQuery( cq ).setMaxResults(maxCount).getResultList();
if(maxCount<1){
return em.createQuery(cq).getResultList();
}else {
return em.createQuery(cq).setMaxResults(maxCount).getResultList();
}
}
public List<String> listByDocAndPerson( String docId, String personName, Integer maxCount ) throws Exception {
if( maxCount == null || maxCount == 0 ) {
maxCount = 10;
public List<String> listByComment( String commentId, Integer maxCount) throws Exception {
if( maxCount == null) {
maxCount = 0;
}
EntityManager em = this.entityManagerContainer().get( DocumentCommend.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<DocumentCommend> root = cq.from( DocumentCommend.class );
Predicate p = cb.equal(root.get( DocumentCommend_.commentId), commentId );
cq.select( root.get( DocumentCommend_.id) ).where(p);
if(maxCount<1){
return em.createQuery(cq).getResultList();
}else {
return em.createQuery(cq).setMaxResults(maxCount).getResultList();
}
}
public List<String> listByDocAndPerson( String docId, String personName, Integer maxCount, String type) throws Exception {
if( maxCount == null) {
maxCount = 0;
}
EntityManager em = this.entityManagerContainer().get( DocumentCommend.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
......@@ -65,7 +97,32 @@ public class DocumentCommendFactory extends AbstractFactory {
Root<DocumentCommend> root = cq.from( DocumentCommend.class );
Predicate p = cb.equal(root.get( DocumentCommend_.documentId), docId );
p = cb.and( p, cb.equal(root.get( DocumentCommend_.commendPerson), personName ) );
if(StringUtils.isNoneBlank(type)){
p = cb.and( p, cb.equal(root.get( DocumentCommend_.type), type ) );
}
cq.select( root.get( DocumentCommend_.id) ).where(p);
return em.createQuery( cq ).setMaxResults(maxCount).getResultList();
if(maxCount<1){
return em.createQuery(cq).getResultList();
}else {
return em.createQuery(cq).setMaxResults(maxCount).getResultList();
}
}
public List<String> listByCommentAndPerson( String commentId, String personName, Integer maxCount) throws Exception {
if( maxCount == null) {
maxCount = 0;
}
EntityManager em = this.entityManagerContainer().get( DocumentCommend.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<DocumentCommend> root = cq.from( DocumentCommend.class );
Predicate p = cb.equal(root.get( DocumentCommend_.commentId), commentId );
p = cb.and( p, cb.equal(root.get( DocumentCommend_.commendPerson), personName ) );
cq.select( root.get( DocumentCommend_.id) ).where(p);
if(maxCount<1){
return em.createQuery(cq).getResultList();
}else {
return em.createQuery(cq).setMaxResults(maxCount).getResultList();
}
}
}
\ No newline at end of file
}
......@@ -4,12 +4,19 @@ import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
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.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
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.core.entity.Document;
import com.x.cms.core.entity.DocumentCommend;
import com.x.cms.core.entity.DocumentCommend_;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.EntityManager;
......@@ -17,11 +24,19 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
class ActionListPaging extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionListPaging.class);
private static final String COMMEND_TYPE_ALL = "all";
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, Integer page, Integer size, JsonElement jsonElement) throws Exception {
logger.debug(effectivePerson.getDistinguishedName());
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<List<Wo>> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
EntityManager em = emc.get(DocumentCommend.class);
......@@ -30,12 +45,45 @@ class ActionListPaging extends BaseAction {
Root<DocumentCommend> root = cq.from(DocumentCommend.class);
Predicate p = cb.conjunction();
if (StringUtils.isNotBlank(wi.getDocumentId())){
p = cb.and(p, root.get(DocumentCommend_.documentId).in(wi.getDocumentId()));
p = cb.and(p, cb.equal(root.get(DocumentCommend_.documentId), wi.getDocumentId()));
}
if (StringUtils.isNotBlank(wi.getCommentId())){
p = cb.and(p, cb.equal(root.get(DocumentCommend_.commentId), wi.getCommentId()));
}
if (StringUtils.isNotBlank(wi.getCommendPerson())){
p = cb.and(p, root.get(DocumentCommend_.commendPerson).in(wi.getCommendPerson()));
String person = business.organization().person().get(wi.getCommendPerson());
if(StringUtils.isBlank(person)){
person = wi.getCommendPerson();
}
p = cb.and(p, cb.equal(root.get(DocumentCommend_.commendPerson), person));
}
if (StringUtils.isNotBlank(wi.getCreatorPerson())){
String person = business.organization().person().get(wi.getCreatorPerson());
if(StringUtils.isBlank(person)){
person = wi.getCreatorPerson();
}
p = cb.and(p, cb.equal(root.get(DocumentCommend_.creatorPerson), person));
}
if(StringUtils.isBlank(wi.getType())){
p = cb.and(p, cb.equal(root.get(DocumentCommend_.type), DocumentCommend.COMMEND_TYPE_DOCUMENT));
}else if(!wi.getType().equals(COMMEND_TYPE_ALL)){
p = cb.and(p, cb.equal(root.get(DocumentCommend_.type), wi.getType()));
}
List<Wo> wos = emc.fetchDescPaging(DocumentCommend.class, Wo.copier, p, page, size, DocumentCommend.sequence_FIELDNAME);
if(BooleanUtils.isTrue(wi.getReturnDocIndexPic())){
List<String> docIds = ListTools.extractField(wos, DocumentCommend.documentId_FIELDNAME, String.class, true, true);
List<Document> documentList = emc.fetch(docIds, Document.class, ListTools.toList(Document.id_FIELDNAME, Document.indexPics_FIELDNAME));
final Map<String, String> map = documentList.stream().filter(t -> StringUtils.isNoneBlank(t.getIndexPics()))
.collect(Collectors.toMap(Document::getId, Document::getIndexPics,(k1,k2)->k2));
final List empty = new ArrayList<>();
wos.stream().forEach(wo -> {
if(map.containsKey(wo.getDocumentId())){
wo.setIndexPicList(ListTools.toList(map.get(wo.getDocumentId()).split(",")));
}else{
wo.setIndexPicList(empty);
}
});
}
result.setData(wos);
result.setCount(emc.count(DocumentCommend.class, p));
return result;
......@@ -47,7 +95,18 @@ class ActionListPaging extends BaseAction {
private static final long serialVersionUID = 8042740393049682505L;
static WrapCopier<Wi, DocumentCommend> copier = WrapCopierFactory.wi(Wi.class, DocumentCommend.class, null,
JpaObject.FieldsUnmodify);
ListTools.toList(JpaObject.FieldsUnmodify, DocumentCommend.title_FIELDNAME, DocumentCommend.commentTitle_FIELDNAME));
@FieldDescribe("是否返回点赞对应文档的首页图片,默认为false.")
private Boolean returnDocIndexPic;
public Boolean getReturnDocIndexPic() {
return returnDocIndexPic;
}
public void setReturnDocIndexPic(Boolean returnDocIndexPic) {
this.returnDocIndexPic = returnDocIndexPic;
}
}
public static class Wo extends DocumentCommend {
......@@ -57,5 +116,15 @@ class ActionListPaging extends BaseAction {
static WrapCopier<DocumentCommend, Wo> copier = WrapCopierFactory.wo(DocumentCommend.class, Wo.class, null,
JpaObject.FieldsInvisible);
@FieldDescribe("点赞对应文档的首页图片列表.")
private List<String> indexPicList;
public List<String> getIndexPicList() {
return indexPicList;
}
public void setIndexPicList(List<String> indexPicList) {
this.indexPicList = indexPicList;
}
}
}
......@@ -20,6 +20,9 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List;
/**
* @author sword
*/
@Path("commend")
@JaxrsDescribe("点赞信息管理")
public class DocumentCommendAction extends StandardJaxrsAction {
......@@ -61,4 +64,4 @@ public class DocumentCommendAction extends StandardJaxrsAction {
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
}
......@@ -2,62 +2,54 @@ package com.x.cms.assemble.control.jaxrs.comment;
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.project.cache.CacheManager;
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.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.cms.core.entity.Document;
import com.x.cms.core.entity.DocumentCommentCommend;
import com.x.cms.core.entity.DocumentCommend;
import com.x.cms.core.entity.DocumentCommentInfo;
/**
* 评论点赞
* @author sword
*/
public class ActionPersistCommend extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionPersistCommend.class);
protected ActionResult<Wo> execute(HttpServletRequest request, String id, EffectivePerson effectivePerson ) throws Exception {
logger.debug(request.getRequestURI());
ActionResult<Wo> result = new ActionResult<>();
DocumentCommentInfo comment = null;
Boolean check = true;
if (check) {
try {
comment = documentCommentInfoQueryService.get( id );
if (null == comment) {
check = false;
Exception exception = new ExceptionDocumentNotExists(id);
result.error(exception);
throw exception;
}
} catch (Exception e) {
check = false;
Exception exception = new ExceptionCommentQuery(e, "文档评论信息获取操作时发生异常。Id:" + id + ", Name:" + effectivePerson.getDistinguishedName());
result.error(exception);
logger.error(e, effectivePerson, request, null);
DocumentCommentInfo comment;
Document document;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
comment = emc.fetch(id, DocumentCommentInfo.class);
if (comment == null) {
throw new ExceptionEntityNotExist(id, DocumentCommentInfo.class);
}
}
if (check) {
try {
DocumentCommentCommend commentCommend = commentCommendPersistService.create( effectivePerson.getDistinguishedName(), id );
Wo wo = new Wo();
wo.setId( commentCommend.getId() );
result.setData( wo );
} catch (Exception e) {
Exception exception = new ExceptionCommentPersist(e, "给文档评论点赞时时发生异常。Id:" + id);
result.error(exception);
logger.error(e, effectivePerson, request, null);
throw exception;
document = emc.fetch(comment.getDocumentId(), Document.class);
if (document == null) {
throw new ExceptionEntityNotExist(comment.getDocumentId(), Document.class);
}
}
DocumentCommend commentCommend = docCommendPersistService.create( effectivePerson.getDistinguishedName(), document, comment);
Wo wo = new Wo();
wo.setId(commentCommend.getId() );
result.setData( wo );
CacheManager.notify( Document.class );
return result;
}
public static class Wo extends WoId {
}
}
\ No newline at end of file
}
......@@ -10,36 +10,30 @@ import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.cms.core.entity.Document;
import com.x.cms.core.entity.DocumentCommend;
/**
* 取消评论点赞
* @author sword
*/
public class ActionPersistUnCommend extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionPersistUnCommend.class);
protected ActionResult<Wo> execute(HttpServletRequest request, String commentId, EffectivePerson effectivePerson ) throws Exception {
logger.debug(request.getRequestURI());
ActionResult<Wo> result = new ActionResult<>();
Boolean check = true;
if (check) {
try {
List<String> ids = commentCommendPersistService.deleteWithCommentId( commentId, effectivePerson.getDistinguishedName() );
Wo wo = new Wo();
wo.setIds( ids );
result.setData( wo );
} catch (Exception e) {
Exception exception = new ExceptionCommentPersist(e, "系统根据个人和文档评论ID删除点赞信息时发生异常。commentId:" + commentId );
result.error(exception);
logger.error(e, effectivePerson, request, null);
throw exception;
}
}
List<String> ids = docCommendPersistService.delete(commentId, effectivePerson.getDistinguishedName(), DocumentCommend.COMMEND_TYPE_COMMENT);
Wo wo = new Wo();
wo.setIds( ids );
result.setData( wo );
CacheManager.notify( Document.class );
return result;
}
public static class Wo {
private List<String> ids = null;
public List<String> getIds() {
......@@ -49,7 +43,7 @@ public class ActionPersistUnCommend extends BaseAction {
public void setIds(List<String> ids) {
this.ids = ids;
}
}
}
\ No newline at end of file
}
......@@ -2,10 +2,7 @@ package com.x.cms.assemble.control.jaxrs.comment;
import com.x.base.core.project.cache.Cache;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.cms.assemble.control.service.CommentCommendPersistService;
import com.x.cms.assemble.control.service.DocumentCommentInfoPersistService;
import com.x.cms.assemble.control.service.DocumentCommentInfoQueryService;
import com.x.cms.assemble.control.service.DocumentQueryService;
import com.x.cms.assemble.control.service.*;
import com.x.cms.core.entity.AppInfo;
import com.x.cms.core.entity.CategoryInfo;
import com.x.cms.core.entity.Document;
......@@ -17,12 +14,14 @@ import net.sf.ehcache.Ehcache;
public class BaseAction extends StandardJaxrsAction {
protected Cache.CacheCategory cacheCategory = new Cache.CacheCategory(DocumentCommentInfo.class, Document.class);
protected DocumentCommentInfoPersistService documentCommentInfoPersistService = new DocumentCommentInfoPersistService();
protected DocumentCommentInfoQueryService documentCommentInfoQueryService = new DocumentCommentInfoQueryService();
protected DocumentCommentInfoPersistService documentCommentInfoPersistService = new DocumentCommentInfoPersistService();
protected DocumentCommentInfoQueryService documentCommentInfoQueryService = new DocumentCommentInfoQueryService();
protected DocumentQueryService documentInfoServiceAdv = new DocumentQueryService();
protected CommentCommendPersistService commentCommendPersistService = new CommentCommendPersistService();
protected DocCommendPersistService docCommendPersistService = new DocCommendPersistService();
}
......@@ -12,6 +12,10 @@ import com.x.cms.core.entity.DocumentCommend;
import javax.servlet.http.HttpServletRequest;
/**
* 文档点赞
* @author sword
*/
public class ActionPersistCommend extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionPersistCommend.class);
......@@ -41,7 +45,7 @@ public class ActionPersistCommend extends BaseAction {
if (check) {
try {
DocumentCommend documentCommend = docCommendPersistService.create( effectivePerson.getDistinguishedName(), id, document.getTitle() );
DocumentCommend documentCommend = docCommendPersistService.create( effectivePerson.getDistinguishedName(), document, null);
Wo wo = new Wo();
wo.setId( documentCommend.getId() );
result.setData( wo );
......
......@@ -8,6 +8,7 @@ import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.cms.core.entity.Document;
import com.x.cms.core.entity.DocumentCommend;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
......@@ -22,11 +23,11 @@ public class ActionPersistUnCommend extends BaseAction {
Boolean check = true;
if (check) {
try {
List<String> ids = docCommendPersistService.delete( docId, effectivePerson.getDistinguishedName() );
try {
List<String> ids = docCommendPersistService.delete( docId, effectivePerson.getDistinguishedName(), DocumentCommend.COMMEND_TYPE_DOCUMENT);
Wo wo = new Wo();
wo.setIds( ids );
result.setData( wo );
result.setData( wo );
} catch (Exception e) {
Exception exception = new ExceptionDocumentInfoProcess(e, "系统根据个人和文档ID删除点赞信息时发生异常。docId:" + docId );
result.error(exception);
......@@ -36,12 +37,12 @@ public class ActionPersistUnCommend extends BaseAction {
}
CacheManager.notify( Document.class );
return result;
}
public static class Wo extends GsonPropertyObject {
private List<String> ids = null;
public List<String> getIds() {
......@@ -51,7 +52,7 @@ public class ActionPersistUnCommend extends BaseAction {
public void setIds(List<String> ids) {
this.ids = ids;
}
}
}
\ No newline at end of file
}
package com.x.cms.assemble.control.jaxrs.document;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
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.cache.Cache;
import com.x.base.core.project.cache.CacheManager;
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.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.cms.core.entity.Document;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* @author sword
*/
public class ActionQueryListDocument extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionQueryListDocument.class);
protected ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
logger.debug(effectivePerson.getDistinguishedName());
ActionResult<List<Wo>> result = new ActionResult<>();
Wi wi = this.convertToWrapIn( jsonElement, Wi.class );
List<Wo> wos = new ArrayList<>();
if(ListTools.isNotEmpty(wi.getDocIds())) {
Cache.CacheKey cacheKey = new Cache.CacheKey(this.getClass(), gson.toJson(wi.docIds));
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
wos = (List<Wo>)optional.get();
} else {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
List<Document> documentList = emc.fetch(wi.getDocIds(), Document.class);
for (Document document : documentList) {
Wo wo = Wo.copier.copy(document);
if (StringUtils.isNoneBlank(document.getIndexPics())) {
wo.setPictureList(ListTools.toList(document.getIndexPics().split(",")));
}
wos.add(wo);
}
if(wos.size() > 0) {
CacheManager.put(cacheCategory, cacheKey, wos);
}
}
}
}
result.setData(wos);
return result;
}
public static class Wo extends WrapOutDocumentList {
public static final WrapCopier<Document, Wo> copier = WrapCopierFactory.wo( Document.class, Wo.class, null,JpaObject.FieldsInvisible);
}
public static class Wi extends GsonPropertyObject {
@FieldDescribe( "文档id" )
private List<String> docIds = new ArrayList<>();
public List<String> getDocIds() {
return docIds;
}
public void setDocIds(List<String> docIds) {
this.docIds = docIds;
}
}
}
......@@ -23,6 +23,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* @author sword
*/
public class ActionQueryListDocumentData extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionQueryListDocumentData.class);
......@@ -46,11 +49,7 @@ public class ActionQueryListDocumentData extends BaseAction {
List<Wo> wos = new ArrayList<>();
Wo wo = null;
List<Document> docs = documentQueryService.list(ids);
//先不考虑阅读权限的问题
/*List<String> unitNames = userManagerService.listUnitNamesWithPerson(effectivePerson.getDistinguishedName());
List<String> groupNames = userManagerService.listGroupNamesByPerson(effectivePerson.getDistinguishedName());*/
for (Document document : docs){
//if(this.hasReadPermission(business, document, unitNames, groupNames, effectivePerson, null)) {
Cache.CacheKey cacheKey = new Cache.CacheKey(this.getClass(), document.getId());
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
......
......@@ -984,6 +984,26 @@ public class DocumentAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "列示文档.", action = ActionQueryListDocument.class)
@POST
@Path("list/document")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void query_listDocument(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request, JsonElement jsonElement) {
EffectivePerson effectivePerson = this.effectivePerson(request);
ActionResult<List<ActionQueryListDocument.Wo>> result = new ActionResult<>();
try {
result = new ActionQueryListDocument().execute(effectivePerson, jsonElement);
} catch (Exception e) {
result.error(e);
logger.error(e, effectivePerson, request, jsonElement);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "查看文档数据.", action = ActionQueryGetDocumentData.class)
@GET
@Path("{id}/document/data")
......
......@@ -2,6 +2,8 @@ package com.x.cms.assemble.control.service;
import java.util.List;
import com.x.cms.core.entity.Document;
import com.x.cms.core.entity.DocumentCommentInfo;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
......@@ -18,36 +20,31 @@ public class DocCommendPersistService {
private DocCommendService docCommendService = new DocCommendService();
public DocumentCommend create( DocumentCommend documentCommend ) throws Exception {
if( documentCommend == null ){
throw new Exception("wrapIn document commend is null!");
}
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
return docCommendService.create(emc, documentCommend );
} catch ( Exception e ) {
throw e;
}
}
public DocumentCommend create( String personName, String docId, String title ) throws Exception {
if( StringUtils.isEmpty( docId ) ){
throw new Exception("docId can not empty!");
}
public DocumentCommend create( String personName, Document document, DocumentCommentInfo commentInfo) throws Exception {
if( StringUtils.isEmpty( personName ) ){
throw new Exception("personName can not empty!");
}
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
DocumentCommend documentCommend = new DocumentCommend();
documentCommend.setCommendPerson( personName );
documentCommend.setDocumentId( docId );
documentCommend.setTitle(title);
documentCommend.setDocumentId( document.getId() );
documentCommend.setTitle(document.getTitle());
documentCommend.setCreatorPerson(document.getCreatorPerson());
if(commentInfo== null) {
documentCommend.setType(DocumentCommend.COMMEND_TYPE_DOCUMENT);
}else{
documentCommend.setCreatorPerson(commentInfo.getCreatorName());
documentCommend.setType(DocumentCommend.COMMEND_TYPE_COMMENT);
documentCommend.setCommentId(commentInfo.getId());
documentCommend.setCommentTitle(commentInfo.getTitle());
}
return docCommendService.create(emc, documentCommend );
} catch ( Exception e ) {
throw e;
}
}
public List<String> delete( String docId, String personName ) throws Exception {
public List<String> delete( String docId, String personName, String type) throws Exception {
if( StringUtils.isEmpty( docId ) ){
throw new Exception("docId is empty!");
}
......@@ -55,7 +52,12 @@ public class DocCommendPersistService {
throw new Exception("personName is empty!");
}
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
List<String> ids = docCommendService.listByDocAndPerson(emc, docId, personName, 99 );
List<String> ids;
if(DocumentCommend.COMMEND_TYPE_COMMENT.equals(type)){
ids = docCommendService.listByCommentAndPerson(emc, docId, personName, 0);
}else {
ids = docCommendService.listByDocAndPerson(emc, docId, personName, 0, type);
}
if( ListTools.isNotEmpty( ids ) ) {
return docCommendService.delete(emc, ids );
}else {
......
......@@ -9,14 +9,14 @@ import com.x.base.core.container.factory.EntityManagerContainerFactory;
/**
* 文档点赞信息查询管理的服务类
*
*
* @author O2LEE
*/
public class DocCommendQueryService {
private DocCommendService docCommendService = new DocCommendService();
public List<String> listByDocAndPerson( String docId, String personName, Integer maxCount ) throws Exception {
public List<String> listByDocAndPerson( String docId, String personName, Integer maxCount, String type) throws Exception {
if( StringUtils.isEmpty( docId ) ){
return null;
}
......@@ -24,29 +24,29 @@ public class DocCommendQueryService {
return null;
}
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
return docCommendService.listByDocAndPerson(emc, docId, personName, maxCount);
return docCommendService.listByDocAndPerson(emc, docId, personName, maxCount, type);
} catch ( Exception e ) {
throw e;
}
}
public List<String> listByDocument( String docId, Integer maxCount ) throws Exception {
public List<String> listByDocument( String docId, Integer maxCount, String type) throws Exception {
if( StringUtils.isEmpty( docId ) ){
return null;
}
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
return docCommendService.listByDocument( emc, docId, maxCount );
return docCommendService.listByDocument( emc, docId, maxCount, type);
} catch ( Exception e ) {
throw e;
}
}
public List<String> listWithPerson( String personName, Integer maxCount ) throws Exception {
public List<String> listWithPerson( String personName, Integer maxCount, String type) throws Exception {
if( StringUtils.isEmpty( personName ) ){
return null;
}
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
return docCommendService.listWithPerson(emc, personName, maxCount);
return docCommendService.listWithPerson(emc, personName, maxCount, type);
} catch ( Exception e ) {
throw e;
}
......
......@@ -2,6 +2,7 @@ package com.x.cms.assemble.control.service;
import java.util.List;
import com.x.cms.core.entity.DocumentCommentInfo;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
......@@ -14,7 +15,7 @@ import com.x.cms.core.entity.DocumentCommend;
class DocCommendService {
public List<String> listByDocAndPerson( EntityManagerContainer emc, String docId, String personName, Integer maxCount ) throws Exception {
public List<String> listByDocAndPerson( EntityManagerContainer emc, String docId, String personName, Integer maxCount, String type) throws Exception {
if( StringUtils.isEmpty( docId ) ){
return null;
}
......@@ -22,23 +23,42 @@ class DocCommendService {
return null;
}
Business business = new Business( emc );
return business.documentCommendFactory().listByDocAndPerson(docId, personName, maxCount );
return business.documentCommendFactory().listByDocAndPerson(docId, personName, maxCount, type);
}
public List<String> listByDocument( EntityManagerContainer emc, String docId, Integer maxCount ) throws Exception {
public List<String> listByDocument( EntityManagerContainer emc, String docId, Integer maxCount, String type) throws Exception {
if( StringUtils.isEmpty( docId ) ){
return null;
}
Business business = new Business( emc );
return business.documentCommendFactory().listByDocument(docId, maxCount);
return business.documentCommendFactory().listByDocument(docId, maxCount, type);
}
public List<String> listWithPerson( EntityManagerContainer emc, String personName, Integer maxCount ) throws Exception {
public List<String> listByCommentAndPerson( EntityManagerContainer emc, String commentId, String personName, Integer maxCount) throws Exception {
if( StringUtils.isEmpty( commentId ) ){
return null;
}
if( StringUtils.isEmpty( personName ) ){
return null;
}
Business business = new Business( emc );
return business.documentCommendFactory().listByCommentAndPerson(commentId, personName, maxCount);
}
public List<String> listByComment( EntityManagerContainer emc, String commentId, Integer maxCount) throws Exception {
if( StringUtils.isEmpty( commentId ) ){
return null;
}
Business business = new Business( emc );
return business.documentCommendFactory().listByComment(commentId, maxCount);
}
public List<String> listWithPerson( EntityManagerContainer emc, String personName, Integer maxCount, String type) throws Exception {
if( StringUtils.isEmpty( personName ) ){
return null;
}
Business business = new Business( emc );
return business.documentCommendFactory().listWithPerson(personName, maxCount);
return business.documentCommendFactory().listWithPerson(personName, maxCount, type);
}
public DocumentCommend create( EntityManagerContainer emc, DocumentCommend wrapIn ) throws Exception {
......@@ -48,19 +68,36 @@ class DocCommendService {
Business business = new Business( emc );
List<String> commendIds = null;
DocumentCommend documentCommend = null;
commendIds = business.documentCommendFactory().listByDocAndPerson( wrapIn.getDocumentId(), wrapIn.getCommendPerson(), 1 );
if(DocumentCommend.COMMEND_TYPE_COMMENT.equals(wrapIn.getType())){
commendIds = business.documentCommendFactory().listByCommentAndPerson(wrapIn.getCommentId(), wrapIn.getCommendPerson(), 1);
}else {
commendIds = business.documentCommendFactory().listByDocAndPerson(wrapIn.getDocumentId(), wrapIn.getCommendPerson(), 1, DocumentCommend.COMMEND_TYPE_DOCUMENT);
}
if( ListTools.isEmpty( commendIds ) ){
Document doc = emc.find( wrapIn.getDocumentId(), Document.class );
documentCommend = new DocumentCommend();
documentCommend.setId( DocumentCommend.createId() );
documentCommend.setCommendPerson( wrapIn.getCommendPerson() );
documentCommend.setDocumentId( wrapIn.getDocumentId() );
documentCommend.setTitle(wrapIn.getTitle());
documentCommend.setCreatorPerson(wrapIn.getCreatorPerson());
documentCommend.setType(wrapIn.getType());
documentCommend.setCommentId(wrapIn.getCommentId());
documentCommend.setCommentTitle(wrapIn.getCommentTitle());
emc.beginTransaction( DocumentCommend.class );
if( doc != null ) {
emc.beginTransaction( Document.class );
doc.addCommendCount(1);
emc.check( doc, CheckPersistType.all );
if(DocumentCommend.COMMEND_TYPE_COMMENT.equals(wrapIn.getType())){
DocumentCommentInfo doc = emc.find( wrapIn.getCommentId(), DocumentCommentInfo.class );
if( doc != null ) {
emc.beginTransaction( DocumentCommentInfo.class );
doc.addCommendCount(1);
emc.check( doc, CheckPersistType.all );
}
}else{
Document doc = emc.find( wrapIn.getDocumentId(), Document.class );
if( doc != null ) {
emc.beginTransaction( Document.class );
doc.addCommendCount(1);
emc.check( doc, CheckPersistType.all );
}
}
emc.persist( documentCommend, CheckPersistType.all );
emc.commit();
......@@ -76,12 +113,21 @@ class DocCommendService {
}
DocumentCommend documentCommend = emc.find( id, DocumentCommend.class );
if( documentCommend != null ){
Document doc = emc.find( documentCommend.getDocumentId(), Document.class );
emc.beginTransaction( DocumentCommend.class );
if( doc != null ) {
emc.beginTransaction( Document.class );
doc.subCommendCount(1);
emc.check( doc, CheckPersistType.all );
if(DocumentCommend.COMMEND_TYPE_COMMENT.equals(documentCommend.getType())){
DocumentCommentInfo doc = emc.find( documentCommend.getCommentId(), DocumentCommentInfo.class );
if( doc != null ) {
emc.beginTransaction( DocumentCommentInfo.class );
doc.subCommendCount(1);
emc.check( doc, CheckPersistType.all );
}
}else{
Document doc = emc.find( documentCommend.getDocumentId(), Document.class );
if( doc != null ) {
emc.beginTransaction( Document.class );
doc.subCommendCount(1);
emc.check( doc, CheckPersistType.all );
}
}
emc.remove( documentCommend, CheckRemoveType.all );
emc.commit();
......@@ -95,14 +141,22 @@ class DocCommendService {
}
List<DocumentCommend> documentCommends = emc.list( DocumentCommend.class, ids );
if( ListTools.isNotEmpty( documentCommends )){
Document doc = null;
emc.beginTransaction( DocumentCommend.class );
emc.beginTransaction( DocumentCommentInfo.class );
emc.beginTransaction( Document.class );
for( DocumentCommend documentCommend : documentCommends ) {
doc = emc.find( documentCommend.getDocumentId(), Document.class );
if( doc != null ) {
doc.subCommendCount(1);
emc.check( doc, CheckPersistType.all );
if(DocumentCommend.COMMEND_TYPE_COMMENT.equals(documentCommend.getType())){
DocumentCommentInfo doc = emc.find( documentCommend.getCommentId(), DocumentCommentInfo.class );
if( doc != null ) {
doc.subCommendCount(1);
emc.check( doc, CheckPersistType.all );
}
}else{
Document doc = emc.find( documentCommend.getDocumentId(), Document.class );
if( doc != null ) {
doc.subCommendCount(1);
emc.check( doc, CheckPersistType.all );
}
}
emc.remove( documentCommend, CheckRemoveType.all );
}
......
......@@ -8,13 +8,13 @@ import com.x.cms.core.express.tools.DateOperation;
import org.apache.commons.lang3.StringUtils;
/**
* 对评论信息的持久化服务
*
*
* @author O2LEE
*/
public class DocumentCommentInfoPersistService {
private DocumentCommentInfoService documentCommentInfoService = new DocumentCommentInfoService();
public void delete( String flag, EffectivePerson effectivePerson ) throws Exception {
if ( StringUtils.isEmpty( flag )) {
throw new Exception("flag is empty.");
......@@ -36,7 +36,7 @@ public class DocumentCommentInfoPersistService {
throw new Exception("documentCommentInfo delete permission denied.");
}else {
documentCommentInfoService.delete( emc, flag );
}
}
} catch (Exception e) {
throw e;
}
......@@ -54,13 +54,14 @@ public class DocumentCommentInfoPersistService {
throw new Exception("documentCommentInfo is null.");
}
if( StringUtils.isEmpty( documentCommentInfo.getTitle() )) {
documentCommentInfo.setTitle("无标题评论信息("+ DateOperation.getNowDateTime() +")");
}
if( documentCommentInfo.getTitle().length() > 70 ) {
documentCommentInfo.setTitle( documentCommentInfo.getTitle().substring(0, 70) + "..." );
if(content.length() > 70){
documentCommentInfo.setTitle(content.substring(0, 70) + "...");
}else{
documentCommentInfo.setTitle(content);
}
}
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
documentCommentInfo = documentCommentInfoService.save( emc, documentCommentInfo, content );
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
documentCommentInfo = documentCommentInfoService.save( emc, documentCommentInfo, content );
} catch (Exception e) {
throw e;
}
......
......@@ -8,6 +8,7 @@ import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import com.x.base.core.entity.AbstractPersistenceProperties;
import org.apache.openjpa.persistence.jdbc.Index;
import com.x.base.core.entity.JpaObject;
......@@ -17,7 +18,7 @@ import com.x.base.core.entity.annotation.ContainerEntity;
import com.x.base.core.project.annotation.FieldDescribe;
/**
* 文档点赞
* 文档、评论点赞
*
* @author O2LEE
*
......@@ -34,6 +35,9 @@ public class DocumentCommend extends SliceJpaObject {
private static final long serialVersionUID = 3856138316794473794L;
private static final String TABLE = PersistenceProperties.DocumentCommend.table;
public static final String COMMEND_TYPE_DOCUMENT = "document";
public static final String COMMEND_TYPE_COMMENT = "comment";
@Override
public String getId() {
return id;
......@@ -69,10 +73,29 @@ public class DocumentCommend extends SliceJpaObject {
public static final String title_FIELDNAME = "title";
@FieldDescribe("文档标题")
@Column(length = JpaObject.length_255B, name = ColumnNamePrefix + title_FIELDNAME)
@Index(name = TABLE + IndexNameMiddle + title_FIELDNAME)
@CheckPersist(allowEmpty = true)
private String title;
public static final String commentId_FIELDNAME = "commentId";
@FieldDescribe("文档评论ID")
@Column(length = JpaObject.length_id, name = ColumnNamePrefix + commentId_FIELDNAME)
@Index(name = TABLE + IndexNameMiddle + commentId_FIELDNAME)
@CheckPersist(allowEmpty = true)
private String commentId;
public static final String commentTitle_FIELDNAME = "commentTitle";
@FieldDescribe("文档评论标题")
@Column(length = JpaObject.length_255B, name = ColumnNamePrefix + commentTitle_FIELDNAME)
@CheckPersist(allowEmpty = true)
private String commentTitle;
public static final String creatorPerson_FIELDNAME = "creatorPerson";
@FieldDescribe("文档或评论创建人")
@Column(length = JpaObject.length_255B, name = ColumnNamePrefix + creatorPerson_FIELDNAME)
@Index(name = TABLE + IndexNameMiddle + creatorPerson_FIELDNAME)
@CheckPersist(allowEmpty = true)
private String creatorPerson;
public static final String commendPerson_FIELDNAME = "commendPerson";
@FieldDescribe("点赞者")
@Column(length = JpaObject.length_255B, name = ColumnNamePrefix + commendPerson_FIELDNAME)
......@@ -80,6 +103,12 @@ public class DocumentCommend extends SliceJpaObject {
@Index(name = TABLE + IndexNameMiddle + commendPerson_FIELDNAME)
private String commendPerson;
public static final String type_FIELDNAME = "type";
@FieldDescribe("点赞类型:document(文档点赞,默认值)、comment(评论点赞)")
@Column(length = JpaObject.length_id, name = ColumnNamePrefix + type_FIELDNAME, columnDefinition = "varchar(64) DEFAULT 'document'")
@CheckPersist(allowEmpty = true)
private String type = COMMEND_TYPE_DOCUMENT;
public String getDocumentId() {
return documentId;
}
......@@ -103,4 +132,36 @@ public class DocumentCommend extends SliceJpaObject {
public void setTitle(String title) {
this.title = title;
}
public String getCommentId() {
return commentId;
}
public void setCommentId(String commentId) {
this.commentId = commentId;
}
public String getCommentTitle() {
return commentTitle;
}
public void setCommentTitle(String commentTitle) {
this.commentTitle = commentTitle;
}
public String getCreatorPerson() {
return creatorPerson;
}
public void setCreatorPerson(String creatorPerson) {
this.creatorPerson = creatorPerson;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册