提交 fea014c1 编写于 作者: liyi_hz2008's avatar liyi_hz2008 提交者: liyi_hz2008

新增两个配置适应对回帖的排序和对回帖删除的方式控制

上级 31748319
......@@ -106,7 +106,7 @@ public class BBSReplyInfoFactory extends AbstractFactory {
* @return
* @throws Exception
*/
public List<BBSReplyInfo> listWithSubjectForPage(String subjectId, Boolean showSubReply, Integer maxCount) throws Exception {
public List<BBSReplyInfo> listWithSubjectForPage(String subjectId, Boolean showSubReply, Integer maxCount, String orderType ) throws Exception {
if( subjectId == null ){
throw new Exception( "subjectId can not null." );
}
......@@ -120,13 +120,14 @@ public class BBSReplyInfoFactory extends AbstractFactory {
p_showSubReply = cb.or( p_showSubReply, cb.equal( root.get( BBSReplyInfo_.parentId), ""));
p = cb.and( p, p_showSubReply);
}
cq.orderBy( cb.desc( root.get( BBSReplyInfo_.createTime ) ) );
if( StringUtils.equalsIgnoreCase(orderType, "DESC")){
cq.orderBy( cb.desc( root.get( BBSReplyInfo_.createTime ) ) );
}else{
cq.orderBy( cb.asc( root.get( BBSReplyInfo_.createTime ) ) );
}
if( maxCount == null ){
// System.out.println( ">>>>>SQL:" + em.createQuery(cq.where(p)).toString() );
return em.createQuery(cq.where(p)).getResultList();
return em.createQuery(cq.where(p)).setMaxResults( 2000 ).getResultList();
}else{
// System.out.println( ">>>>>SQL:" + em.createQuery(cq.where(p)).setMaxResults( maxCount ).toString() );
return em.createQuery(cq.where(p)).setMaxResults( maxCount ).getResultList();
}
}
......@@ -422,7 +423,7 @@ public class BBSReplyInfoFactory extends AbstractFactory {
* @param replyId
* @return
*/
public List<BBSReplyInfo> listReplyWithReplyId(String replyId) throws Exception {
public List<BBSReplyInfo> listReplyWithReplyId(String replyId, String orderType ) throws Exception {
if( StringUtils.isEmpty( replyId ) ){
throw new Exception( "replyId is empty!" );
}
......@@ -435,6 +436,31 @@ public class BBSReplyInfoFactory extends AbstractFactory {
cb.equal( root.get( BBSReplyInfo_.replyAuditStatus ), "无审核" ),
cb.equal( root.get( BBSReplyInfo_.replyAuditStatus ), "审核通过" )
));
if( StringUtils.equalsIgnoreCase( orderType, "DESC")){
cq.orderBy( cb.desc( root.get( BBSReplyInfo_.createTime ) ) );
}else{
cq.orderBy( cb.asc( root.get( BBSReplyInfo_.createTime ) ) );
}
return em.createQuery(cq.where(p)).getResultList();
}
/**
* 根据回复ID,查询二级回复列表,状态:无审核|审核通过
*
* @param replyId
* @return
*/
public List<String> listSubReplyIdsWithReplyId(String replyId) throws Exception {
if( StringUtils.isEmpty( replyId ) ){
return null;
}
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class );
Predicate p = cb.equal( root.get( BBSReplyInfo_.parentId ), replyId );
cq.select( root.get( BBSReplyInfo_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
}
......@@ -2,12 +2,14 @@ package com.x.bbs.assemble.control.jaxrs.replyinfo;
import javax.servlet.http.HttpServletRequest;
import com.alibaba.druid.util.StringUtils;
import com.x.base.core.project.cache.ApplicationCache;
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.bbs.assemble.control.jaxrs.replyinfo.exception.ExceptionReplyIdEmpty;
import com.x.bbs.assemble.control.jaxrs.replyinfo.exception.ExceptionReplyInfoProcess;
import com.x.bbs.assemble.control.jaxrs.replyinfo.exception.ExceptionReplyNotExists;
......@@ -15,6 +17,8 @@ import com.x.bbs.entity.BBSReplyInfo;
import com.x.bbs.entity.BBSSectionInfo;
import com.x.bbs.entity.BBSSubjectInfo;
import java.util.List;
public class ActionDelete extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionDelete.class);
......@@ -50,23 +54,38 @@ public class ActionDelete extends BaseAction {
result.error(exception);
}
}
try {
replyInfoService.delete(id);
if (check) {
try {
String config_BBS_REPLY_DELETETYPE = configSettingService.getValueWithConfigCode("BBS_REPLY_DELETETYPE");
if(StringUtils.equals( "Recursively", config_BBS_REPLY_DELETETYPE )){
//递归删除
List<String> subIds = replyInfoService.listAllSubReplyIds(id, null);
if (ListTools.isNotEmpty(subIds)) {
for (String replyId : subIds) {
logger.debug("删除下级回复信息,ID=" + replyId);
replyInfoService.delete(replyId);
}
}
}
replyInfoService.delete(id);
Wo wo = new Wo();
wo.setId(id);
result.setData(wo);
Wo wo = new Wo();
wo.setId( id );
result.setData( wo );
ApplicationCache.notify( BBSSubjectInfo.class );
ApplicationCache.notify( BBSReplyInfo.class );
ApplicationCache.notify( BBSSectionInfo.class );
operationRecordService.replyOperation(effectivePerson.getDistinguishedName(), replyInfo, "DELETE", hostIp, hostName);
} catch (Exception e) {
check = false;
Exception exception = new ExceptionReplyInfoProcess(e, "根据指定ID删除回复信息时发生异常.ID:" + id);
result.error(exception);
logger.error(e, effectivePerson, request, null);
ApplicationCache.notify(BBSSubjectInfo.class);
ApplicationCache.notify(BBSReplyInfo.class);
ApplicationCache.notify(BBSSectionInfo.class);
operationRecordService.replyOperation(effectivePerson.getDistinguishedName(), replyInfo, "DELETE", hostIp, hostName);
} catch (Exception e) {
check = false;
Exception exception = new ExceptionReplyInfoProcess(e, "根据指定ID删除回复信息时发生异常.ID:" + id);
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
}
return result;
}
......
......@@ -58,17 +58,17 @@ public class ActionGet extends BaseAction {
result.error( exception );
logger.error( e, effectivePerson, request, null);
}
if( wrap != null && StringUtils.isNotEmpty( wrap.getCreatorName() ) ) {
wrap.setCreatorNameShort( wrap.getCreatorName().split( "@" )[0]);
}
if( wrap != null && StringUtils.isNotEmpty( wrap.getAuditorName() ) ) {
wrap.setAuditorNameShort( wrap.getAuditorName().split( "@" )[0]);
}
}else{
Exception exception = new ExceptionReplyNotExists( id );
result.error( exception );
}
}
if( StringUtils.isNotEmpty( wrap.getCreatorName() ) ) {
wrap.setCreatorNameShort( wrap.getCreatorName().split( "@" )[0]);
}
if( StringUtils.isNotEmpty( wrap.getAuditorName() ) ) {
wrap.setAuditorNameShort( wrap.getAuditorName().split( "@" )[0]);
}
result.setData( wrap );
return result;
}
......
......@@ -69,10 +69,11 @@ public class ActionListWithReply extends BaseAction {
List<BBSReplyInfo> replyInfoList_out = new ArrayList<BBSReplyInfo>();
Long total = 0L;
Boolean check = true;
String config_BBS_REPLY_SORTTYPE = configSettingService.getValueWithConfigCode("BBS_REPLY_SORTTYPE");
if (check) {
try {
replyInfoList = replyInfoService.listRelysWithRelyId(replyId);
replyInfoList = replyInfoService.listRelysWithRelyId(replyId, config_BBS_REPLY_SORTTYPE );
} catch (Exception e) {
check = false;
Exception exception = new ExceptionReplyInfoProcess(e,"根据回复ID查询针对该回复所有的二级回复数量时发生异常。replyId:" + replyId );
......@@ -102,7 +103,7 @@ public class ActionListWithReply extends BaseAction {
wo.setAuditorNameShort(wo.getAuditorName().split("@")[0]);
}
}
SortTools.desc(wraps, "createTime" );
// SortTools.desc(wraps, "createTime" );
result.setCount( Long.parseLong(wraps.size()+"") );
}
}
......
......@@ -77,6 +77,7 @@ public class ActionListWithSubjectForPage extends BaseAction {
List<BBSReplyInfo> replyInfoList_out = new ArrayList<BBSReplyInfo>();
Long total = 0L;
Boolean check = true;
String config_BBS_REPLY_SORTTYPE = configSettingService.getValueWithConfigCode("BBS_REPLY_SORTTYPE");
if (check) {
if (page == null) {
......@@ -105,7 +106,7 @@ public class ActionListWithSubjectForPage extends BaseAction {
if (check) {
if (total > 0) {
try {
replyInfoList = replyInfoService.listWithSubjectForPage( wrapIn.getSubjectId(), wrapIn.getShowSubReply(), page * count );
replyInfoList = replyInfoService.listWithSubjectForPage( wrapIn.getSubjectId(), wrapIn.getShowSubReply(), page * count, config_BBS_REPLY_SORTTYPE );
} catch (Exception e) {
check = false;
Exception exception = new ExceptionReplyInfoProcess(e,"根据主题ID查询主题内所有的回复列表时发生异常。Subject:" + wrapIn.getSubjectId());
......@@ -123,12 +124,12 @@ public class ActionListWithSubjectForPage extends BaseAction {
}
int startIndex = (page - 1) * count;
int endIndex = page * count;
for (int i = 0; replyInfoList != null && i < replyInfoList.size(); i++) {
for ( int i = 0; replyInfoList != null && i < replyInfoList.size(); i++ ) {
if (i < replyInfoList.size() && i >= startIndex && i < endIndex) {
replyInfoList_out.add( replyInfoList.get(i) );
}
}
if (ListTools.isNotEmpty( replyInfoList_out )) {
if ( ListTools.isNotEmpty( replyInfoList_out )) {
try {
wraps = Wo.copier.copy(replyInfoList_out);
} catch (Exception e) {
......@@ -141,7 +142,6 @@ public class ActionListWithSubjectForPage extends BaseAction {
}
if (check) {
if (ListTools.isNotEmpty(wraps)) {
List<BBSReplyInfo> subReplies = null;
for (Wo wo : wraps) {
if (StringUtils.isNotEmpty(wo.getCreatorName())) {
......@@ -152,10 +152,9 @@ public class ActionListWithSubjectForPage extends BaseAction {
}
//查询一下该回复是否存在下级回复,以及下级回复的数量,除了第一条,其他的都去掉内容,避免大量的网络传输
subReplies = replyInfoService.listRelysWithRelyId( wo.getId() );
subReplies = replyInfoService.listRelysWithRelyId( wo.getId(), config_BBS_REPLY_SORTTYPE );
if( ListTools.isNotEmpty( subReplies )){
wrapSubReplies = Wo.copier.copy( subReplies );
SortTools.desc( wrapSubReplies, "createTime" );
for( int i=0; i<wrapSubReplies.size(); i++ ){
if( i > 0 ){
wrapSubReplies.get(i).setContent(null);
......@@ -166,7 +165,7 @@ public class ActionListWithSubjectForPage extends BaseAction {
}
}
result.setCount(total);
SortTools.desc( wraps, "createTime" );
}
}
result.setData(wraps);
......
......@@ -5,13 +5,7 @@ import java.util.List;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.tools.ListTools;
import com.x.bbs.assemble.control.service.BBSForumInfoServiceAdv;
import com.x.bbs.assemble.control.service.BBSOperationRecordService;
import com.x.bbs.assemble.control.service.BBSReplyInfoService;
import com.x.bbs.assemble.control.service.BBSSectionInfoServiceAdv;
import com.x.bbs.assemble.control.service.BBSSubjectInfoService;
import com.x.bbs.assemble.control.service.UserManagerService;
import com.x.bbs.assemble.control.service.UserPermissionService;
import com.x.bbs.assemble.control.service.*;
import com.x.bbs.entity.BBSSubjectInfo;
import net.sf.ehcache.Ehcache;
......@@ -24,6 +18,7 @@ public class BaseAction extends StandardJaxrsAction{
protected BBSSectionInfoServiceAdv sectionInfoServiceAdv = new BBSSectionInfoServiceAdv();
protected BBSForumInfoServiceAdv forumInfoServiceAdv = new BBSForumInfoServiceAdv();
protected BBSOperationRecordService operationRecordService = new BBSOperationRecordService();
protected BBSConfigSettingService configSettingService = new BBSConfigSettingService();
protected UserManagerService userManagerService = new UserManagerService();
protected Boolean checkUserPermission( String checkPermissionCode, List<String> permissionInfoList ) {
......
......@@ -281,5 +281,29 @@ public class BBSConfigSettingService{
logger.warn( "system init system config 'BBS_SUBJECT_TYPECATAGORY' got an exception." );
logger.error(e);
}
value = "Recursively";
type = "select";
selectContent = "Single|Recursively";
isMultiple = false;
description = "回复删除模式:可选值:Single|Recursively,单选。";
try {
checkAndInitSystemConfig("BBS_REPLY_DELETETYPE", "回复删除模式", value, description, type, selectContent, isMultiple, ++ordernumber );
} catch (Exception e) {
logger.warn( "system init system config 'BBS_REPLY_DELETETYPE' got an exception." );
logger.error(e);
}
value = "ASC";
type = "select";
selectContent = "ASC|DESC";
isMultiple = false;
description = "回贴排序模式:可选值:ASC|DESC, 按创建时间正序|倒序,单选。";
try {
checkAndInitSystemConfig("BBS_REPLY_SORTTYPE", "回贴排序模式", value, description, type, selectContent, isMultiple, ++ordernumber );
} catch (Exception e) {
logger.warn( "system init system config 'BBS_REPLY_SORTTYPE' got an exception." );
logger.error(e);
}
}
}
package com.x.bbs.assemble.control.service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -10,6 +11,7 @@ import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.entity.annotation.CheckRemoveType;
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.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSForumInfo;
import com.x.bbs.entity.BBSReplyInfo;
......@@ -129,7 +131,7 @@ public class BBSReplyInfoService {
BBSSectionInfo _mainSectoinInfo = null;
BBSForumInfo _forumInfo = null;
if( id == null || id.isEmpty() ){
throw new Exception( "id is null, system can not delete any object." );
return;
}
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
//先判断需要操作的应用信息是否存在,根据ID进行一次查询,如果不存在不允许继续操作
......@@ -185,14 +187,14 @@ public class BBSReplyInfoService {
}
}
public List<BBSReplyInfo> listWithSubjectForPage(String subjectId, Boolean showSubReply, int maxCount) throws Exception {
public List<BBSReplyInfo> listWithSubjectForPage(String subjectId, Boolean showSubReply, int maxCount, String orderType ) throws Exception {
if( subjectId == null ){
throw new Exception( "subjectId can not null." );
}
Business business = null;
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
business = new Business(emc);
return business.replyInfoFactory().listWithSubjectForPage( subjectId, showSubReply, maxCount );
return business.replyInfoFactory().listWithSubjectForPage( subjectId, showSubReply, maxCount, orderType );
}catch( Exception e ){
throw e;
}
......@@ -255,16 +257,39 @@ public class BBSReplyInfoService {
* @param replyId
* @return
*/
public List<BBSReplyInfo> listRelysWithRelyId(String replyId) throws Exception {
public List<BBSReplyInfo> listRelysWithRelyId(String replyId, String orderType ) throws Exception {
if(StringUtils.isEmpty( replyId ) ){
throw new Exception( "replyId can not null." );
}
Business business = null;
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
business = new Business(emc);
return business.replyInfoFactory().listReplyWithReplyId(replyId);
return business.replyInfoFactory().listReplyWithReplyId(replyId, orderType);
}catch( Exception e ){
throw e;
}
}
public List<String> listAllSubReplyIds(String replyId, List<String> allIds ) throws Exception {
if( allIds == null ){
allIds = new ArrayList<>();
}
if(StringUtils.isEmpty( replyId ) ){
return allIds;
}
Business business = null;
try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create() ) {
business = new Business(emc);
List<String> subIds = business.replyInfoFactory().listSubReplyIdsWithReplyId(replyId);
if(ListTools.isNotEmpty( subIds )){
for( String id : subIds ){
if( !allIds.contains( id )){
allIds.add( id );
listAllSubReplyIds( id, allIds );
}
}
}
}
return allIds;
}
}
\ No newline at end of file
......@@ -256,7 +256,7 @@ public class BBSSubjectInfoService {
//先判断需要操作的应用信息是否存在,根据ID进行一次查询,如果不存在不允许继续操作
subjectInfo = emc.find( subjectId, BBSSubjectInfo.class );
subjectContent = emc.find( subjectId, BBSSubjectContent.class );
replyInfoList = business.replyInfoFactory().listWithSubjectForPage( subjectId, true, null );
replyInfoList = business.replyInfoFactory().listWithSubjectForPage( subjectId, true, null, "ASC" );
voteOptionList = business.voteOptionFactory().listVoteOptionBySubject( subjectId );
voteOptionGroupList = business.voteOptionFactory().listVoteOptionGroupBySubject( subjectId );
voteRecordList = business.voteRecordFactory().listVoteRecordBySubject( subjectId );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册