提交 a044a851 编写于 作者: O o2null

Revert "Merge branch 'fix/group_as_read' into 'master'"

This reverts merge request !123
上级 03a1005d

要显示的变更太多。

To preserve performance only 1000 of 1000+ files are displayed.
......@@ -25,7 +25,8 @@
/o2web/ftpconfig.js
**/.DS_Store
.DS_Store
**/.idea/
**/.idea
/.idea/
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
......@@ -150,4 +151,3 @@ typings/
#vscode
**/.factorypath
**/.vscode/
*.swp
\ No newline at end of file
......@@ -92,7 +92,7 @@ AIX : http://download.o2oa.net/download/o2server_20200316073520_aix.zip
银河麒麟(飞腾):http://download.o2oa.net/download/o2server_20200316073520_kylinos_phytium.zip
raspberrypi(树莓派):http://download.o2oa.net/download/o2server_20200316073520_raspberrypi.zip
raspberrypi(树莓派):http://download.o2oa.net/download/o2server_20200316073520_raspberrypi.zip
......
......@@ -128,7 +128,7 @@ function downloadFile(path, filename, headcb, progresscb, cb){
});
request.get(options).pipe(str).pipe(stream);
} else {
gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode);
gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+response.statusCode);
}
})
req.on('error', (e) => {
......
......@@ -166,7 +166,6 @@
"nodeAgentPort": 20010.0,
"nodeAgentEncrypt": true,
"quickStartWebApp": false,
"autoStart": true,
"###enable": "是否启用###",
"###isPrimaryCenter": "是否是center节点,仅允许存在一个center节点###",
"###center": "Center服务器配置###",
......
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
......@@ -227,10 +228,6 @@
<groupId>org.apache.pdfbox</groupId>
<artifactId>jbig2-imageio</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
</dependency>
<dependency>
<groupId>com.adobe.xmp</groupId>
<artifactId>xmpcore</artifactId>
......@@ -488,11 +485,6 @@
<artifactId>commons-text</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
......
2020-03-17 18:53:45
\ No newline at end of file
......@@ -83,70 +83,70 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
// Object object = jpa.get(field.getName());
Object object = FieldUtils.readField(field, jpa, true);
switch (fieldType) {
case stringValue:
this.persistChecker.stringValue.check(field, null == object ? null : Objects.toString(object), jpa,
checkPersist, checkPersistType);
break;
case stringValueList:
this.persistChecker.stringValueList.check(field, null == object ? null : (List<String>) object, jpa,
checkPersist, checkPersistType);
break;
case dateValue:
this.persistChecker.dateValue.check(field, (null == object ? null : (Date) object), jpa,
checkPersist, checkPersistType);
break;
case dateValueList:
this.persistChecker.dateValueList.check(field, (null == object ? null : (List<Date>) object), jpa,
checkPersist, checkPersistType);
break;
case booleanValue:
this.persistChecker.booleanValue.check(field, (null == object ? null : (Boolean) object), jpa,
checkPersist, checkPersistType);
break;
case booleanValueList:
this.persistChecker.booleanValueList.check(field, (null == object ? null : (List<Boolean>) object),
jpa, checkPersist, checkPersistType);
break;
case integerValue:
this.persistChecker.integerValue.check(field, (null == object ? null : (Integer) object), jpa,
checkPersist, checkPersistType);
break;
case integerValueList:
this.persistChecker.integerValueList.check(field, (null == object ? null : (List<Integer>) object),
jpa, checkPersist, checkPersistType);
break;
case doubleValue:
this.persistChecker.doubleValue.check(field, (null == object ? null : (Double) object), jpa,
checkPersist, checkPersistType);
break;
case doubleValueList:
this.persistChecker.doubleValueList.check(field, (null == object ? null : (List<Double>) object),
jpa, checkPersist, checkPersistType);
break;
case longValue:
this.persistChecker.longValue.check(field, (null == object ? null : (Long) object), jpa,
checkPersist, checkPersistType);
break;
case longValueList:
this.persistChecker.longValueList.check(field, (null == object ? null : (List<Long>) object), jpa,
checkPersist, checkPersistType);
break;
case floatValue:
this.persistChecker.floatValue.check(field, (null == object ? null : (Float) object), jpa,
checkPersist, checkPersistType);
break;
case floatValueList:
this.persistChecker.floatValueList.check(field, (null == object ? null : (List<Float>) object), jpa,
checkPersist, checkPersistType);
break;
case byteValueArray:
this.persistChecker.byteValueArray.check(field, (null == object ? null : (byte[]) object), jpa,
checkPersist, checkPersistType);
break;
case enumValue:
break;
default:
break;
case stringValue:
this.persistChecker.stringValue.check(field, null == object ? null : Objects.toString(object), jpa,
checkPersist, checkPersistType);
break;
case stringValueList:
this.persistChecker.stringValueList.check(field, null == object ? null : (List<String>) object, jpa,
checkPersist, checkPersistType);
break;
case dateValue:
this.persistChecker.dateValue.check(field, (null == object ? null : (Date) object), jpa, checkPersist,
checkPersistType);
break;
case dateValueList:
this.persistChecker.dateValueList.check(field, (null == object ? null : (List<Date>) object), jpa,
checkPersist, checkPersistType);
break;
case booleanValue:
this.persistChecker.booleanValue.check(field, (null == object ? null : (Boolean) object), jpa,
checkPersist, checkPersistType);
break;
case booleanValueList:
this.persistChecker.booleanValueList.check(field, (null == object ? null : (List<Boolean>) object), jpa,
checkPersist, checkPersistType);
break;
case integerValue:
this.persistChecker.integerValue.check(field, (null == object ? null : (Integer) object), jpa,
checkPersist, checkPersistType);
break;
case integerValueList:
this.persistChecker.integerValueList.check(field, (null == object ? null : (List<Integer>) object), jpa,
checkPersist, checkPersistType);
break;
case doubleValue:
this.persistChecker.doubleValue.check(field, (null == object ? null : (Double) object), jpa,
checkPersist, checkPersistType);
break;
case doubleValueList:
this.persistChecker.doubleValueList.check(field, (null == object ? null : (List<Double>) object), jpa,
checkPersist, checkPersistType);
break;
case longValue:
this.persistChecker.longValue.check(field, (null == object ? null : (Long) object), jpa, checkPersist,
checkPersistType);
break;
case longValueList:
this.persistChecker.longValueList.check(field, (null == object ? null : (List<Long>) object), jpa,
checkPersist, checkPersistType);
break;
case floatValue:
this.persistChecker.floatValue.check(field, (null == object ? null : (Float) object), jpa, checkPersist,
checkPersistType);
break;
case floatValueList:
this.persistChecker.floatValueList.check(field, (null == object ? null : (List<Float>) object), jpa,
checkPersist, checkPersistType);
break;
case byteValueArray:
this.persistChecker.byteValueArray.check(field, (null == object ? null : (byte[]) object), jpa,
checkPersist, checkPersistType);
break;
case enumValue:
break;
default:
break;
}
}
}
......@@ -161,16 +161,16 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
// Object object = jpa.get(field.getName());
Object object = FieldUtils.readField(field, jpa, true);
switch (fieldType) {
case stringValue:
this.removeChecker.stringValue.check(field, null == object ? null : Objects.toString(object), jpa,
checkRemove, checkRemoveType);
break;
case stringValueList:
this.removeChecker.stringValueList.check(field, null == object ? null : (List<String>) object, jpa,
checkRemove, checkRemoveType);
break;
default:
break;
case stringValue:
this.removeChecker.stringValue.check(field, null == object ? null : Objects.toString(object), jpa,
checkRemove, checkRemoveType);
break;
case stringValueList:
this.removeChecker.stringValueList.check(field, null == object ? null : (List<String>) object, jpa,
checkRemove, checkRemoveType);
break;
default:
break;
}
}
}
......@@ -208,19 +208,18 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
t = em.find(cls, id);
}
switch (exceptionWhen) {
case not_found:
if (null == t) {
throw new Exception("can not find entity id: " + id + ", class: " + cls.getCanonicalName() + ".");
}
break;
case found:
if (null != t) {
throw new Exception(
"entity already existed, id: " + id + ", class: " + cls.getCanonicalName() + ".");
}
break;
default:
break;
case not_found:
if (null == t) {
throw new Exception("can not find entity id: " + id + ", class: " + cls.getCanonicalName() + ".");
}
break;
case found:
if (null != t) {
throw new Exception("entity already existed, id: " + id + ", class: " + cls.getCanonicalName() + ".");
}
break;
default:
break;
}
return t;
}
......@@ -245,14 +244,14 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
Predicate p = cb.equal(root.get(field.getName()), flag);
List<T> list = em.createQuery(cq.select(root).where(p).distinct(true)).setMaxResults(2).getResultList();
switch (list.size()) {
case 0:
break;
case 1:
t = list.get(0);
break out;
case 2:
throw new Exception("flag get multiple entity flag:" + flag + ", class:" + cls.getName()
+ ", attribute:" + field.getName() + ".");
case 0:
break;
case 1:
t = list.get(0);
break out;
case 2:
throw new Exception("flag get multiple entity flag:" + flag + ", class:" + cls.getName()
+ ", attribute:" + field.getName() + ".");
}
}
return t;
......@@ -310,15 +309,15 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
cq.select(root).where(p);
List<T> list = em.createQuery(cq).setMaxResults(2).getResultList();
switch (list.size()) {
case 0:
break;
case 1:
t = list.get(0);
break out;
case 2:
throw new Exception("flag get multiple entity flag:" + flag + ", class:" + cls.getName()
+ ", attribute:" + field.getName() + ", restrict attrubte:" + singularAttribute
+ ", restrict value:" + restrictValue + ".");
case 0:
break;
case 1:
t = list.get(0);
break out;
case 2:
throw new Exception("flag get multiple entity flag:" + flag + ", class:" + cls.getName()
+ ", attribute:" + field.getName() + ", restrict attrubte:" + singularAttribute
+ ", restrict value:" + restrictValue + ".");
}
}
return t;
......@@ -541,25 +540,13 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
public <T extends JpaObject, W extends Object> List<T> listBetweenAndEqual(Class<T> cls, String attribute,
Object start, Object end, String equalAttribute, Object equalValue) throws Exception {
Comparable s = (Comparable) start;
Comparable e = (Comparable) end;
EntityManager em = this.get(cls);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery(cls);
Root<T> root = cq.from(cls);
Predicate p = cb.between(root.get(attribute), s, e);
p = cb.and(p, cb.equal(root.get(equalAttribute), equalValue));
cq.select(root).where(p);
List<T> os = em.createQuery(cq).getResultList();
List<T> list = new ArrayList<>(os);
return list;
// Query query = em.createQuery("select o from " + cls.getName() + " o where
// ((o." + attribute
// + " between ?1 and ?2) and (o." + equalAttribute + " = ?3))");
// query.setParameter(1, start);
// query.setParameter(2, end);
// query.setParameter(3, equalValue);
// return new ArrayList<T>(query.getResultList());
Query query = em.createQuery("select o from " + cls.getName() + " o where ((o." + attribute
+ " between ?1 and ?2) and (o." + equalAttribute + " = ?3))");
query.setParameter(1, start);
query.setParameter(2, end);
query.setParameter(3, equalValue);
return new ArrayList<T>(query.getResultList());
}
public <T extends JpaObject> List<T> listNotEqual(Class<T> cls, String attribute, Object value) throws Exception {
......@@ -1138,9 +1125,9 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
selections.add(root.get(str));
}
cq.multiselect(selections).where(predicate);
// if (StringUtils.isNotEmpty(orderAttribute)) {
// cq.orderBy(cb.desc(root.get(orderAttribute)));
// }
// if (StringUtils.isNotEmpty(orderAttribute)) {
// cq.orderBy(cb.desc(root.get(orderAttribute)));
// }
T t = null;
for (Tuple o : em.createQuery(cq).getResultList()) {
t = clz.newInstance();
......@@ -1836,4 +1823,5 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
return list;
}
}
\ No newline at end of file
package com.x.base.core.project.build;
import java.io.File;
import java.io.FileReader;
import java.util.Date;
import java.util.LinkedHashMap;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.tools.DateTools;
import com.x.base.core.project.tools.DefaultCharset;
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
public class CreateVersionFile {
public static void main(String... args) throws Exception {
File base = new File(args[0]);
File file = new File(base, "../version.o2");
File pom = new File(base, "../pom.xml");
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader(pom));
LinkedHashMap<String, String> map = new LinkedHashMap<>();
map.put("version", model.getVersion() + "");
map.put("date", DateTools.format(new Date()));
FileUtils.write(file, XGsonBuilder.toJson(map), DefaultCharset.charset_utf_8);
}
}
......@@ -9,6 +9,7 @@ import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
......
package com.x.bbs.assemble.control;
import com.x.base.core.container.EntityManagerContainer;
public abstract class AbstractFactory {
private Business business;
public AbstractFactory( Business business ) throws Exception {
try {
if ( null == business ) {
throw new Exception( "business can not be null. " );
}
this.business = business;
} catch ( Exception e ) {
throw new Exception( "can not instantiating factory." );
}
}
public EntityManagerContainer entityManagerContainer() throws Exception {
return this.business.entityManagerContainer();
}
}
\ No newline at end of file
package com.x.bbs.assemble.control;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import com.x.base.core.project.Context;
@WebListener
public class ApplicationServletContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
ThisApplication.context = Context.concrete(servletContextEvent);
ThisApplication.init();
ThisApplication.context().regist();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
try {
ThisApplication.destroy();
ThisApplication.context.destrory(servletContextEvent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.x.bbs.assemble.control;
import com.x.base.core.container.EntityManagerContainer;
import com.x.bbs.assemble.control.factory.BBSConfigSettingFactory;
import com.x.bbs.assemble.control.factory.BBSForumInfoFactory;
import com.x.bbs.assemble.control.factory.BBSOperationRecordFactory;
import com.x.bbs.assemble.control.factory.BBSPermissionInfoFactory;
import com.x.bbs.assemble.control.factory.BBSPermissionRoleFactory;
import com.x.bbs.assemble.control.factory.BBSReplyInfoFactory;
import com.x.bbs.assemble.control.factory.BBSRoleInfoFactory;
import com.x.bbs.assemble.control.factory.BBSSectionInfoFactory;
import com.x.bbs.assemble.control.factory.BBSSubjectAttachmentFactory;
import com.x.bbs.assemble.control.factory.BBSSubjectInfoFactory;
import com.x.bbs.assemble.control.factory.BBSSubjectVoteResultFactory;
import com.x.bbs.assemble.control.factory.BBSUserInfoFactory;
import com.x.bbs.assemble.control.factory.BBSUserRoleFactory;
import com.x.bbs.assemble.control.factory.BBSVoteOptionFactory;
import com.x.bbs.assemble.control.factory.BBSVoteRecordFactory;
import com.x.organization.core.express.Organization;
public class Business {
private EntityManagerContainer emc;
public Business(EntityManagerContainer emc) throws Exception {
this.emc = emc;
}
public EntityManagerContainer entityManagerContainer() {
return this.emc;
}
private Organization organization;
private BBSForumInfoFactory forumInfoFactory;
private BBSSectionInfoFactory sectionInfoFactory;
private BBSSubjectInfoFactory subjectInfoFactory;
private BBSVoteOptionFactory voteOptionFactory;
private BBSSubjectVoteResultFactory subjectVoteResultFactory;
private BBSVoteRecordFactory voteRecordFactory;
private BBSReplyInfoFactory replyInfoFactory;
private BBSSubjectAttachmentFactory subjectAttachmentFactory;
private BBSOperationRecordFactory operationRecordFactory;
private BBSUserInfoFactory userInfoFactory;
private BBSRoleInfoFactory roleInfoFactory;
private BBSPermissionInfoFactory permissionInfoFactory;
private BBSPermissionRoleFactory permissionRoleFactory;
private BBSUserRoleFactory userRoleFactory;
private BBSConfigSettingFactory configSettingFactory;
public Organization organization() throws Exception {
if (null == this.organization) {
this.organization = new Organization(ThisApplication.context());
}
return organization;
}
public BBSVoteRecordFactory voteRecordFactory() throws Exception {
if (null == this.voteRecordFactory) {
this.voteRecordFactory = new BBSVoteRecordFactory(this);
}
return voteRecordFactory;
}
public BBSSubjectVoteResultFactory subjectVoteResultFactory() throws Exception {
if (null == this.subjectVoteResultFactory) {
this.subjectVoteResultFactory = new BBSSubjectVoteResultFactory(this);
}
return subjectVoteResultFactory;
}
public BBSVoteOptionFactory voteOptionFactory() throws Exception {
if (null == this.voteOptionFactory) {
this.voteOptionFactory = new BBSVoteOptionFactory(this);
}
return voteOptionFactory;
}
public BBSConfigSettingFactory configSettingFactory() throws Exception {
if (null == this.configSettingFactory) {
this.configSettingFactory = new BBSConfigSettingFactory(this);
}
return configSettingFactory;
}
public BBSSubjectAttachmentFactory subjectAttachmentFactory() throws Exception {
if (null == this.subjectAttachmentFactory) {
this.subjectAttachmentFactory = new BBSSubjectAttachmentFactory(this);
}
return subjectAttachmentFactory;
}
public BBSUserInfoFactory userInfoFactory() throws Exception {
if (null == this.userInfoFactory) {
this.userInfoFactory = new BBSUserInfoFactory(this);
}
return userInfoFactory;
}
public BBSRoleInfoFactory roleInfoFactory() throws Exception {
if (null == this.roleInfoFactory) {
this.roleInfoFactory = new BBSRoleInfoFactory(this);
}
return roleInfoFactory;
}
public BBSPermissionInfoFactory permissionInfoFactory() throws Exception {
if (null == this.permissionInfoFactory) {
this.permissionInfoFactory = new BBSPermissionInfoFactory(this);
}
return permissionInfoFactory;
}
public BBSPermissionRoleFactory permissionRoleFactory() throws Exception {
if (null == this.permissionRoleFactory) {
this.permissionRoleFactory = new BBSPermissionRoleFactory(this);
}
return permissionRoleFactory;
}
public BBSUserRoleFactory userRoleFactory() throws Exception {
if (null == this.userRoleFactory) {
this.userRoleFactory = new BBSUserRoleFactory(this);
}
return userRoleFactory;
}
public BBSForumInfoFactory forumInfoFactory() throws Exception {
if (null == this.forumInfoFactory) {
this.forumInfoFactory = new BBSForumInfoFactory(this);
}
return forumInfoFactory;
}
public BBSSectionInfoFactory sectionInfoFactory() throws Exception {
if (null == this.sectionInfoFactory) {
this.sectionInfoFactory = new BBSSectionInfoFactory(this);
}
return sectionInfoFactory;
}
public BBSSubjectInfoFactory subjectInfoFactory() throws Exception {
if (null == this.subjectInfoFactory) {
this.subjectInfoFactory = new BBSSubjectInfoFactory(this);
}
return subjectInfoFactory;
}
public BBSReplyInfoFactory replyInfoFactory() throws Exception {
if (null == this.replyInfoFactory) {
this.replyInfoFactory = new BBSReplyInfoFactory(this);
}
return replyInfoFactory;
}
public BBSOperationRecordFactory operationRecordFactory() throws Exception {
if (null == this.operationRecordFactory) {
this.operationRecordFactory = new BBSOperationRecordFactory(this);
}
return operationRecordFactory;
}
}
package com.x.bbs.assemble.control;
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.tools.ListTools;
import com.x.bbs.assemble.control.queue.MessageWo;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
public class MessageFactory {
private static Logger logger = LoggerFactory.getLogger( MessageFactory.class );
/**
* 新的回复,通知相关管理员
* @param persons
* @param messageWo
* @throws Exception
*/
public static void notifyManager_forNewReply(List<String> persons, MessageWo messageWo ) throws Exception {
if(ListTools.isNotEmpty( persons )){
for( String person : persons ){
notifyManager_forNewReply( person, messageWo );
}
}
}
/**
* 新的回复,通知主题创建者
* @param persons
* @param messageWo
* @throws Exception
*/
public static void notifySubjectCreator_forNewReply(List<String> persons, MessageWo messageWo ) throws Exception {
if(ListTools.isNotEmpty( persons )){
for( String person : persons ){
notifySubjectCreator_forNewReply( person, messageWo );
}
}
}
/**
* 新的回复,通知相关管理员
* @param person
* @param messageWo
* @throws Exception
*/
public static void notifyManager_forNewReply( String person, MessageWo messageWo ) throws Exception {
if(StringUtils.isNotEmpty( person ) ){
String personName = StringUtils.isNotEmpty( messageWo.getCreatePerson() )?"":messageWo.getCreatePerson().split("@")[0];
String title = personName + "发表了新的回复:" + messageWo.getTitle();
logger.debug("bbs send notification:new reply for subject [" + messageWo.getTitle() + "], target:" + person );
MessageConnector.send( MessageConnector.TYPE_BBS_REPLYCREATE, title, person, messageWo );
}
}
/**
* 新的回复,通知主题创建者
* @param person
* @param messageWo
* @throws Exception
*/
public static void notifySubjectCreator_forNewReply( String person, MessageWo messageWo ) throws Exception {
if(StringUtils.isNotEmpty( person ) ){
String personName = StringUtils.isNotEmpty( messageWo.getCreatePerson() )?"":messageWo.getCreatePerson().split("@")[0];
String title = personName + "回复了您发表的主题:" + messageWo.getTitle();
logger.debug("bbs send notification:new reply for subject [" + messageWo.getTitle() + "], target:" + person );
MessageConnector.send( MessageConnector.TYPE_BBS_REPLYCREATE, title, person, messageWo );
}
}
/**
* 新的主题发表,通知相关管理员
* @param persons
* @param messageWo
* @throws Exception
*/
public static void notifyManager_forNewSubject(List<String> persons, MessageWo messageWo ) throws Exception {
if(ListTools.isNotEmpty( persons )){
for( String person : persons ){
notifyManager_forNewSubject( person, messageWo );
}
}
}
/**
* 新的主题发表,通知相关管理员
* @param person
* @param messageWo
* @throws Exception
*/
public static void notifyManager_forNewSubject( String person, MessageWo messageWo ) throws Exception {
if(StringUtils.isNotEmpty( person ) ){
String personName = StringUtils.isNotEmpty( messageWo.getCreatePerson() )?"":messageWo.getCreatePerson().split("@")[0];
String title = personName + "发表了新的主题:" + messageWo.getTitle();
logger.debug("bbs send notification:new reply for subject [" + messageWo.getTitle() + "], target:" + person );
MessageConnector.send( MessageConnector.TYPE_BBS_SUBJECTCREATE, title, person, messageWo );
}
}
}
package com.x.bbs.assemble.control;
import java.util.List;
import com.x.base.core.project.Context;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.message.MessageConnector;
import com.x.base.core.project.tools.ListTools;
import com.x.bbs.assemble.control.queue.QueueNewReplyNotify;
import com.x.bbs.assemble.control.queue.QueueNewSubjectNotify;
import com.x.bbs.assemble.control.schedule.SubjectReplyTotalStatisticTask;
import com.x.bbs.assemble.control.schedule.SubjectTotalStatisticTask;
import com.x.bbs.assemble.control.schedule.UserSubjectReplyPermissionStatisticTask;
import com.x.bbs.assemble.control.service.BBSConfigSettingService;
import com.x.bbs.assemble.control.service.BBSForumInfoServiceAdv;
import com.x.bbs.assemble.control.service.BBSPermissionInfoService;
import com.x.bbs.assemble.control.service.BBSRoleInfoService;
import com.x.bbs.assemble.control.service.BBSSectionInfoServiceAdv;
import com.x.bbs.assemble.control.service.UserManagerService;
import com.x.bbs.entity.BBSForumInfo;
import com.x.bbs.entity.BBSSectionInfo;
public class ThisApplication {
protected static Context context;
public static final String BBSMANAGER = "BBSManager@CMSManagerSystemRole@R";
public static QueueNewReplyNotify queueNewReplyNotify;
public static QueueNewSubjectNotify queueNewSubjectNotify;
public static Context context() {
return context;
}
public static void init() throws Exception {
try {
initAllSystemConfig();
queueNewReplyNotify = new QueueNewReplyNotify();
queueNewSubjectNotify = new QueueNewSubjectNotify();
MessageConnector.start(context());
context().startQueue( queueNewReplyNotify );
context().startQueue( queueNewSubjectNotify );
context.schedule( SubjectTotalStatisticTask.class, "0 10 * * * ?");
context.schedule( SubjectReplyTotalStatisticTask.class, "0 40 * * * ?");
context.schedule( UserSubjectReplyPermissionStatisticTask.class, "0 0/30 * * * ?");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void destroy() {
try {
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getRoleAndPermissionCacheKey( String personName ) {
return "RoleAndPermission.withPerson." + personName;
}
private static void initAllSystemConfig() {
BBSPermissionInfoService permissionInfoService = new BBSPermissionInfoService();
BBSRoleInfoService roleInfoService = new BBSRoleInfoService();
BBSForumInfoServiceAdv forumInfoServiceAdv = new BBSForumInfoServiceAdv();
BBSSectionInfoServiceAdv sectionInfoServiceAdv = new BBSSectionInfoServiceAdv();
BBSConfigSettingService configSettingService = new BBSConfigSettingService();
List<BBSForumInfo> forumInfoList = null;
List<BBSSectionInfo> sectionInfoList = null;
try {
configSettingService.initAllSystemConfig();
} catch (Exception e) {
LoggerFactory.getLogger(ThisApplication.class)
.warn("BBS system check all config setting got an exception.");
LoggerFactory.getLogger(ThisApplication.class).error(e);
}
try {
forumInfoList = forumInfoServiceAdv.listAll();
if (forumInfoList != null) {
for (BBSForumInfo forumInfo : forumInfoList) {
permissionInfoService.createForumPermission(forumInfo);
roleInfoService.createForumRole( null, forumInfo);
}
}
} catch (Exception e) {
LoggerFactory.getLogger(ThisApplication.class)
.warn("BBS system check all forum permission and role got an exception.");
LoggerFactory.getLogger(ThisApplication.class).error(e);
}
try {
sectionInfoList = sectionInfoServiceAdv.listAll();
if (sectionInfoList != null) {
for (BBSSectionInfo sectionInfo : sectionInfoList) {
permissionInfoService.createSectionPermission(sectionInfo);
roleInfoService.createSectionRole( "System", sectionInfo);
}
}
} catch (Exception e) {
LoggerFactory.getLogger(ThisApplication.class)
.warn("BBS system check all section permission and role got an exception.");
LoggerFactory.getLogger(ThisApplication.class).error(e);
}
}
/**
* 判断用户是否有BBS系统管理权限
* 1、系统管理员Manager或者xadmin
* 2、拥有BBSManager角色的人员
* @param effectivePerson
* @return
*/
public static Boolean isBBSManager( EffectivePerson effectivePerson ) {
UserManagerService userManagerService = new UserManagerService();
try {
if ( userManagerService.isHasPlatformRole( effectivePerson.getDistinguishedName(), ThisApplication.BBSMANAGER )
|| effectivePerson.isManager()) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 判断用户是否有权限对指定的论坛进行管理
* 1、系统管理员、BBS管理员
* 2、指定论坛设置的管理员
* @param effectivePerson
* @param forumInfo
* @return
*/
public static Boolean isForumManager( EffectivePerson effectivePerson, BBSForumInfo forumInfo ) {
if( isBBSManager( effectivePerson ) ) {
return true;
}
if ( forumInfo != null && ListTools.isNotEmpty( forumInfo.getForumManagerList() ) ) {
for (String name : forumInfo.getForumManagerList()) {
if ( effectivePerson.getDistinguishedName().equals( name ) ) {
return true;
}
}
}
return false;
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSConfigSetting;
import com.x.bbs.entity.BBSConfigSetting_;
/**
* 类 名:BBSConfigSettingFactory<br/>
* 实体类:BBSConfigSetting<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-05-20 17:17:26
**/
public class BBSConfigSettingFactory extends AbstractFactory {
public BBSConfigSettingFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSConfigSetting实体信息对象" )
public BBSConfigSetting get( String id ) throws Exception {
return this.entityManagerContainer().find(id, BBSConfigSetting.class, ExceptionWhen.none);
}
//@MethodDescribe( "列示全部的BBSConfigSetting实体信息列表" )
@SuppressWarnings("unused")
public List<BBSConfigSetting> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSConfigSetting.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSConfigSetting> cq = cb.createQuery(BBSConfigSetting.class);
Root<BBSConfigSetting> root = cq.from( BBSConfigSetting.class);
return em.createQuery(cq).getResultList();
}
//@MethodDescribe( "列示指定Id的BBSConfigSetting实体信息列表" )
public List<BBSConfigSetting> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSConfigSetting>();
}
EntityManager em = this.entityManagerContainer().get(BBSConfigSetting.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSConfigSetting> cq = cb.createQuery(BBSConfigSetting.class);
Root<BBSConfigSetting> root = cq.from(BBSConfigSetting.class);
Predicate p = root.get(BBSConfigSetting_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据指定的配置编码获取配置的值" )
public String getValueWithConfigCode(String configCode) throws Exception {
if( configCode == null || configCode.isEmpty() ){
throw new Exception( "config code is null, can not find any system setting!" );
}
EntityManager em = this.entityManagerContainer().get(BBSConfigSetting.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<BBSConfigSetting> root = cq.from(BBSConfigSetting.class);
Predicate p = cb.equal( root.get( BBSConfigSetting_.configCode ), configCode );
cq.select(root.get(BBSConfigSetting_.configValue));
List<String> valueList = em.createQuery(cq.where(p)).getResultList();
if( valueList != null && valueList.size() > 0 ){
return valueList.get(0);
}
return null;
}
public BBSConfigSetting getWithConfigCode(String configCode) throws Exception {
if( configCode == null || configCode.isEmpty() ){
throw new Exception( "config code is null, can not find any system setting!" );
}
EntityManager em = this.entityManagerContainer().get(BBSConfigSetting.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSConfigSetting> cq = cb.createQuery(BBSConfigSetting.class);
Root<BBSConfigSetting> root = cq.from(BBSConfigSetting.class);
Predicate p = cb.equal( root.get( BBSConfigSetting_.configCode ), configCode );
List<BBSConfigSetting> valueList = em.createQuery(cq.where(p)).getResultList();
if( valueList != null && valueList.size() > 0 ){
return valueList.get(0);
}
return null;
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSForumInfo;
import com.x.bbs.entity.BBSForumInfo_;
/**
* 类 名:BBSForumInfoFactory<br/>
* 实体类:BBSForumInfo<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-08-10 17:17:26
**/
public class BBSForumInfoFactory extends AbstractFactory {
public BBSForumInfoFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSForumInfo实体信息对象" )
public BBSForumInfo get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSForumInfo.class, ExceptionWhen.none );
}
//@MethodDescribe( "列示指定Id的BBSForumInfo实体信息列表" )
public List<BBSForumInfo> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSForumInfo>();
}
EntityManager em = this.entityManagerContainer().get(BBSForumInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSForumInfo> cq = cb.createQuery(BBSForumInfo.class);
Root<BBSForumInfo> root = cq.from(BBSForumInfo.class);
Predicate p = root.get(BBSForumInfo_.id).in(ids);
cq.orderBy( cb.asc( root.get( BBSForumInfo_.orderNumber ) ) );
return em.createQuery(cq.where(p)).setMaxResults( 1000 ).getResultList();
}
//@MethodDescribe( "列示全部的BBSForumInfo实体信息列表" )
public List<BBSForumInfo> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSForumInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSForumInfo> cq = cb.createQuery(BBSForumInfo.class);
Root<BBSForumInfo> root = cq.from(BBSForumInfo.class);
cq.orderBy( cb.asc( root.get( BBSForumInfo_.orderNumber ) ) );
return em.createQuery( cq ).setMaxResults( 1000 ).getResultList();
}
//@MethodDescribe( "根据用户权限列示全部的BBSForumInfo实体信息列表" )
public List<BBSForumInfo> listAllViewAbleForumWithMyPermission( List<String> viewAbleForumIds ) throws Exception {
EntityManager em = this.entityManagerContainer().get( BBSForumInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSForumInfo> cq = cb.createQuery(BBSForumInfo.class);
Root<BBSForumInfo> root = cq.from(BBSForumInfo.class);
Predicate p = cb.equal( root.get( BBSForumInfo_.forumVisible ), "所有人" );
if( viewAbleForumIds != null && !viewAbleForumIds.isEmpty() ){
p = cb.or( p, root.get( BBSForumInfo_.id ).in( viewAbleForumIds ) );
}
cq.orderBy( cb.asc( root.get( BBSForumInfo_.orderNumber ) ) );
return em.createQuery( cq.where(p) ).setMaxResults( 1000 ).getResultList();
}
// @MethodDescribe( "列示全部可见性为所有人的BBSForumInfo实体信息ID列表" )
public List<String> listAllPublicForumIds() throws Exception {
EntityManager em = this.entityManagerContainer().get( BBSForumInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<BBSForumInfo> root = cq.from(BBSForumInfo.class);
Predicate p = cb.equal( root.get(BBSForumInfo_.forumStatus ), "启用" );
p = cb.and( p, cb.equal( root.get(BBSForumInfo_.forumVisible ), "所有人" ) );
cq.select( root.get( BBSForumInfo_.id ) );
return em.createQuery( cq.where(p) ).setMaxResults( 1000 ).getResultList();
}
//@MethodDescribe( "列示已经启用的BBSForumInfo实体信息ID列表" )
public List<BBSForumInfo> listAllOpenForumInfo() throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSForumInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSForumInfo> cq = cb.createQuery(BBSForumInfo.class);
Root<BBSForumInfo> root = cq.from(BBSForumInfo.class);
Predicate p = cb.equal( root.get(BBSForumInfo_.forumStatus ), "启用" );
cq.orderBy( cb.asc( root.get( BBSForumInfo_.orderNumber ) ) );
return em.createQuery( cq.where(p) ).setMaxResults( 1000 ).getResultList();
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSOperationRecord;
import com.x.bbs.entity.BBSOperationRecord_;
/**
* 类 名:BBSOperationRecordFactory<br/>
* 实体类:BBSOperationRecord<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-05-20 17:17:26
**/
public class BBSOperationRecordFactory extends AbstractFactory {
public BBSOperationRecordFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSOperationRecord实体信息对象" )
public BBSOperationRecord get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSOperationRecord.class, ExceptionWhen.none );
}
//@MethodDescribe( "列示指定Id的BBSOperationRecord实体信息列表" )
public List<BBSOperationRecord> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSOperationRecord>();
}
EntityManager em = this.entityManagerContainer().get(BBSOperationRecord.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSOperationRecord> cq = cb.createQuery(BBSOperationRecord.class);
Root<BBSOperationRecord> root = cq.from(BBSOperationRecord.class);
Predicate p = root.get(BBSOperationRecord_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "获取所有有操作的用户姓名列表,去重复" )
public List<String> distinctAllOperationUserNames() throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSOperationRecord.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<BBSOperationRecord> root = cq.from(BBSOperationRecord.class);
Predicate p = cb.isNotNull( root.get(BBSOperationRecord_.id) );
cq.distinct(true).select( root.get(BBSOperationRecord_.operatorName) );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSPermissionInfo;
import com.x.bbs.entity.BBSPermissionInfo_;
/**
* 类 名:BBSPermissionInfoFactory<br/>
* 实体类:BBSPermissionInfo<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-08-10 17:17:26
**/
public class BBSPermissionInfoFactory extends AbstractFactory {
public BBSPermissionInfoFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSPermissionInfo实体信息对象" )
public BBSPermissionInfo get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSPermissionInfo.class, ExceptionWhen.none );
}
//@MethodDescribe( "列示指定Id的BBSPermissionInfo实体信息列表" )
public List<BBSPermissionInfo> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSPermissionInfo>();
}
EntityManager em = this.entityManagerContainer().get(BBSPermissionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSPermissionInfo> cq = cb.createQuery(BBSPermissionInfo.class);
Root<BBSPermissionInfo> root = cq.from(BBSPermissionInfo.class);
Predicate p = root.get(BBSPermissionInfo_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "列示全部的BBSPermissionInfo实体信息列表" )
public List<BBSPermissionInfo> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSPermissionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSPermissionInfo> cq = cb.createQuery(BBSPermissionInfo.class);
return em.createQuery( cq ).setMaxResults( 1000 ).getResultList();
}
//@MethodDescribe( "查询指定CODE的权限信息对象" )
public BBSPermissionInfo getPermissionByCode( String permissionCode ) throws Exception {
if( permissionCode == null || permissionCode.isEmpty() ){
throw new Exception("permissionCode is null!");
}
List<BBSPermissionInfo> permissionInfoList = null;
EntityManager em = this.entityManagerContainer().get(BBSPermissionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSPermissionInfo> cq = cb.createQuery(BBSPermissionInfo.class);
Root<BBSPermissionInfo> root = cq.from(BBSPermissionInfo.class);
Predicate p = cb.equal( root.get(BBSPermissionInfo_.permissionCode), permissionCode );
permissionInfoList = em.createQuery(cq.where(p)).getResultList();
if( permissionInfoList != null && permissionInfoList.size() > 0 ){
return permissionInfoList.get(0);
}else{
return null;
}
}
//@MethodDescribe( "根据论坛ID查询指定论坛所有相关的权限信息列表" )
public List<String> listPermissionByForumId(String forumId) throws Exception {
if( forumId == null || forumId.isEmpty() ){
throw new Exception("forumId is null!");
}
EntityManager em = this.entityManagerContainer().get( BBSPermissionInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSPermissionInfo> root = cq.from( BBSPermissionInfo.class );
Predicate p = cb.equal( root.get( BBSPermissionInfo_.forumId ), forumId );
p = cb.and( p, cb.equal( root.get( BBSPermissionInfo_.permissionType ), "论坛权限" ));
cq.select( root.get( BBSPermissionInfo_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
/**
* 根据版块ID查询指定版块所有相关的权限信息列表
* @param sectionId
* @param queryMainSection 是否查询主版块ID
* @return
* @throws Exception
*/
public List<String> listPermissionBySectionId( String sectionId, Boolean queryMainSection ) throws Exception {
if( sectionId == null || sectionId.isEmpty() ){
throw new Exception("sectionId is null!");
}
EntityManager em = this.entityManagerContainer().get( BBSPermissionInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSPermissionInfo> root = cq.from( BBSPermissionInfo.class );
Predicate p = cb.equal( root.get( BBSPermissionInfo_.sectionId ), sectionId );
if( queryMainSection ) {
p = cb.or( p, cb.equal( root.get( BBSPermissionInfo_.mainSectionId ), sectionId ) );
}
cq.select( root.get( BBSPermissionInfo_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
//@MethodDescribe( "根据权限编码列表获取权限信息列表" )
public List<BBSPermissionInfo> listByPermissionCodes( List<String> permissionCodes ) throws Exception {
if( permissionCodes == null || permissionCodes.size() == 0 ){
return new ArrayList<BBSPermissionInfo>();
}
EntityManager em = this.entityManagerContainer().get(BBSPermissionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSPermissionInfo> cq = cb.createQuery(BBSPermissionInfo.class);
Root<BBSPermissionInfo> root = cq.from(BBSPermissionInfo.class);
Predicate p = root.get(BBSPermissionInfo_.permissionCode).in( permissionCodes );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据主版块ID获取所有的权限信息列表" )
public List<BBSPermissionInfo> listPermissionByMainSectionId( String mainSectionId ) throws Exception {
if( mainSectionId == null || mainSectionId.isEmpty() ){
throw new Exception("mainSectionId is null!");
}
EntityManager em = this.entityManagerContainer().get(BBSPermissionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSPermissionInfo> cq = cb.createQuery(BBSPermissionInfo.class);
Root<BBSPermissionInfo> root = cq.from(BBSPermissionInfo.class);
Predicate p = cb.equal( root.get(BBSPermissionInfo_.mainSectionId ), mainSectionId );
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listPermissionIdsByMainSectionId( String mainSectionId ) throws Exception {
if( mainSectionId == null || mainSectionId.isEmpty() ){
throw new Exception("mainSectionId is null!");
}
EntityManager em = this.entityManagerContainer().get(BBSPermissionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<BBSPermissionInfo> root = cq.from(BBSPermissionInfo.class);
Predicate p = cb.equal( root.get(BBSPermissionInfo_.mainSectionId ), mainSectionId );
cq.select( root.get( BBSPermissionInfo_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSPermissionRole;
import com.x.bbs.entity.BBSPermissionRole_;
/**
* 类 名:BBSPermissionRoleFactory<br/>
* 实体类:BBSPermissionRole<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-08-10 17:17:26
**/
public class BBSPermissionRoleFactory extends AbstractFactory {
public BBSPermissionRoleFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSPermissionRole实体信息对象" )
public BBSPermissionRole get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSPermissionRole.class, ExceptionWhen.none );
}
//@MethodDescribe( "列示指定Id的BBSPermissionRole实体信息列表" )
public List<BBSPermissionRole> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSPermissionRole>();
}
EntityManager em = this.entityManagerContainer().get(BBSPermissionRole.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSPermissionRole> cq = cb.createQuery(BBSPermissionRole.class);
Root<BBSPermissionRole> root = cq.from(BBSPermissionRole.class);
Predicate p = root.get(BBSPermissionRole_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "列示全部的BBSPermissionRole实体信息列表" )
public List<BBSPermissionRole> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSPermissionRole.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSPermissionRole> cq = cb.createQuery(BBSPermissionRole.class);
return em.createQuery( cq ).setMaxResults( 1000 ).getResultList();
}
//@MethodDescribe( "根据角色编码列示该角色包含的所有BBSPermissionRole实体信息ID列表" )
public List<String> listPermissionByRoleCode(String roleCode) throws Exception {
if( roleCode == null || roleCode.isEmpty() ){
throw new Exception("roleCode is null!");
}
EntityManager em = this.entityManagerContainer().get( BBSPermissionRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSPermissionRole> root = cq.from( BBSPermissionRole.class );
Predicate p = cb.equal( root.get( BBSPermissionRole_.roleCode ), roleCode );
cq.select( root.get( BBSPermissionRole_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
//@MethodDescribe( "根据角色编码和权限编码判断角色和权限的绑定信息对象是否存在" )
public boolean exsistPermissionRole( String roleCode, String permissionCode ) throws Exception {
if( roleCode == null || roleCode.isEmpty() ){
throw new Exception("roleCode is null!");
}
if( permissionCode == null || permissionCode.isEmpty() ){
throw new Exception("permissionCode is null!");
}
List<BBSPermissionRole> roleInfoList = null;
EntityManager em = this.entityManagerContainer().get( BBSPermissionRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSPermissionRole> cq = cb.createQuery( BBSPermissionRole.class );
Root<BBSPermissionRole> root = cq.from( BBSPermissionRole.class );
Predicate p = cb.equal( root.get( BBSPermissionRole_.roleCode ), roleCode );
p = cb.and( p, cb.equal( root.get( BBSPermissionRole_.permissionCode ), permissionCode ));
roleInfoList = em.createQuery( cq.where(p) ).getResultList();
if( roleInfoList != null && roleInfoList.size() > 0 ){
return true;
}else{
return false;
}
}
//@MethodDescribe( "根据角色编码和权限编码查询角色和权限的绑定信息对象" )
public BBSPermissionRole getByRoleAndPermission(String roleCode, String permissionCode) throws Exception {
if( roleCode == null || roleCode.isEmpty() ){
throw new Exception("roleCode is null!");
}
if( permissionCode == null || permissionCode.isEmpty() ){
throw new Exception("permissionCode is null!");
}
List<BBSPermissionRole> roleInfoList = null;
EntityManager em = this.entityManagerContainer().get( BBSPermissionRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSPermissionRole> cq = cb.createQuery( BBSPermissionRole.class );
Root<BBSPermissionRole> root = cq.from( BBSPermissionRole.class );
Predicate p = cb.equal( root.get( BBSPermissionRole_.roleCode ), roleCode );
p = cb.and( p, cb.equal( root.get( BBSPermissionRole_.permissionCode ), permissionCode ));
roleInfoList = em.createQuery( cq.where(p) ).getResultList();
if( roleInfoList != null && roleInfoList.size() > 0 ){
return roleInfoList.get( 0 );
}else{
return null;
}
}
//@MethodDescribe( "根据角色ID列表列示权限ID信息列表" )
public List<String> listPermissionCodesByRoleCodes(List<String> roleCodes) throws Exception {
if( roleCodes == null || roleCodes.isEmpty() ){
throw new Exception("roleCodes is null!");
}
EntityManager em = this.entityManagerContainer().get( BBSPermissionRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSPermissionRole> root = cq.from( BBSPermissionRole.class );
Predicate p = root.get( BBSPermissionRole_.roleCode ).in( roleCodes );
cq.select( root.get( BBSPermissionRole_.permissionCode ) );
return em.createQuery( cq.where(p) ).getResultList();
}
//@MethodDescribe( "根据权限编码列示BBSPermissionRole实体信息列表" )
public List<BBSPermissionRole> listByPermissionCode(String permissionCode) throws Exception {
if( permissionCode == null || permissionCode.isEmpty() ){
throw new Exception("permissionCode is null!");
}
EntityManager em = this.entityManagerContainer().get( BBSPermissionRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSPermissionRole> cq = cb.createQuery( BBSPermissionRole.class );
Root<BBSPermissionRole> root = cq.from( BBSPermissionRole.class );
Predicate p = cb.equal( root.get( BBSPermissionRole_.permissionCode ), permissionCode );
return em.createQuery( cq.where(p) ).getResultList();
}
//@MethodDescribe( "根据指定的权限编码列表查询权限信息对象列表" )
public List<BBSPermissionRole> listPermissionByCodes( List<String> permissionCodes ) throws Exception {
if( permissionCodes == null || permissionCodes.isEmpty() ){
throw new Exception( "permissionCodes is null!" );
}
EntityManager em = this.entityManagerContainer().get( BBSPermissionRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSPermissionRole> cq = cb.createQuery( BBSPermissionRole.class );
Root<BBSPermissionRole> root = cq.from( BBSPermissionRole.class );
Predicate p = root.get( BBSPermissionRole_.permissionCode ).in( permissionCodes );
return em.createQuery( cq.where(p) ).getResultList();
}
public List<String> listByForumId(String forumId) throws Exception {
if( StringUtils.isEmpty( forumId) ){
throw new Exception( "forumId is empty!" );
}
EntityManager em = this.entityManagerContainer().get( BBSPermissionRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSPermissionRole> root = cq.from( BBSPermissionRole.class );
Predicate p = cb.equal( root.get( BBSPermissionRole_.forumId ), forumId );
cq.select( root.get( BBSPermissionRole_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
/**
* 根据版块信息ID查询所有的权限角色关联信息
* @param sectionId
* @param queryMainSectionId 是否查询主版块ID
* @return
* @throws Exception
*/
public List<String> listBySectionId( String sectionId, Boolean queryMainSectionId ) throws Exception {
if( StringUtils.isEmpty( sectionId) ){
throw new Exception( "sectionId is empty!" );
}
EntityManager em = this.entityManagerContainer().get( BBSPermissionRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSPermissionRole> root = cq.from( BBSPermissionRole.class );
Predicate p = cb.equal( root.get( BBSPermissionRole_.sectionId ), sectionId );
if( queryMainSectionId ) {
p = cb.or( p, cb.equal( root.get( BBSPermissionRole_.mainSectionId ), sectionId ) );
}
cq.select( root.get( BBSPermissionRole_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.base.core.project.tools.ListTools;
import com.x.bbs.assemble.common.date.DateOperation;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSReplyInfo;
import com.x.bbs.entity.BBSReplyInfo_;
/**
* 类 名:BBSReplyInfoFactory<br/>
* 实体类:BBSReplyInfo<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-05-20 17:17:26
**/
public class BBSReplyInfoFactory extends AbstractFactory {
public BBSReplyInfoFactory( Business business ) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSReplyInfo实体信息对象" )
public BBSReplyInfo get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSReplyInfo.class, ExceptionWhen.none );
}
//@MethodDescribe( "列示指定Id的BBSReplyInfo实体信息列表" )
public List<BBSReplyInfo> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSReplyInfo>();
}
EntityManager em = this.entityManagerContainer().get(BBSReplyInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSReplyInfo> cq = cb.createQuery(BBSReplyInfo.class);
Root<BBSReplyInfo> root = cq.from(BBSReplyInfo.class);
Predicate p = root.get(BBSReplyInfo_.id).in(ids);
return em.createQuery( cq.where(p) ).getResultList();
}
//@MethodDescribe( "根据主贴ID统计主贴的回复数量" )
public Long countBySubjectId( String subjectId ) throws Exception {
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class);
Predicate p = cb.equal( root.get( BBSReplyInfo_.subjectId ), subjectId );
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
//@MethodDescribe( "根据版块信息查询版块内主题数量,包括子版块内的主题数量" )
public Long countBySectionId( String sectionId ) throws Exception {
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class);
Predicate p = cb.equal( root.get( BBSReplyInfo_.mainSectionId ), sectionId );
p = cb.or( p, cb.equal( root.get( BBSReplyInfo_.sectionId ), sectionId ) );
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
//@MethodDescribe( "根据版块信息查询论坛内主题数量" )
public Long countByForumId(String forumId) throws Exception {
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class);
Predicate p = cb.equal( root.get( BBSReplyInfo_.forumId ), forumId );
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
//@MethodDescribe( "根据主题ID获取该主题所有的回复信息对象列表" )
public List<BBSReplyInfo> listWithSubjectForPage( String subjectId, Integer maxCount ) throws Exception {
if( subjectId == null ){
throw new Exception( "subjectId can not null." );
}
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSReplyInfo> cq = cb.createQuery( BBSReplyInfo.class );
Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class );
Predicate p = cb.equal( root.get( BBSReplyInfo_.subjectId ), subjectId );
cq.orderBy( cb.asc( root.get( BBSReplyInfo_.orderNumber ) ) );
if( maxCount == null ){
return em.createQuery(cq.where(p)).getResultList();
}else{
return em.createQuery(cq.where(p)).setMaxResults( maxCount ).getResultList();
}
}
//@MethodDescribe( "根据主题ID获取该主题最大的回复编号(楼层)" )
public Integer getMaxOrderNumber( String subjectId ) throws Exception {
if( subjectId == null ){
throw new Exception( "subjectId can not null." );
}
List<BBSReplyInfo> replyInfoList = null;
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSReplyInfo> cq = cb.createQuery( BBSReplyInfo.class );
Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class );
Predicate p = cb.equal( root.get( BBSReplyInfo_.subjectId ), subjectId );
cq.orderBy( cb.desc( root.get( BBSReplyInfo_.orderNumber ) ) );
replyInfoList = em.createQuery(cq.where(p)).setMaxResults( 1 ).getResultList();
if( ListTools.isNotEmpty( replyInfoList ) ){
return replyInfoList.get(0).getOrderNumber();
}else{
return 0;
}
}
//@MethodDescribe( "根据指定用户姓名、论坛ID,主版块ID, 版块ID查询符合条件的所有回复的数量" )
public Long countReplyForPage( String creatorName, String forumId, String mainSectionId, String sectionId, String subjectId ) throws Exception {
Boolean allFilterNull = true;
if( StringUtils.isNotEmpty( creatorName ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( forumId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( mainSectionId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( sectionId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( subjectId ) ){
allFilterNull = false;
}
if( allFilterNull ){
throw new Exception( "count filter can not all null." );
}
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class);
Predicate p = cb.isNotNull( root.get( BBSReplyInfo_.id ) );
if( StringUtils.isNotEmpty( creatorName ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.creatorName ), creatorName ) );
}
if( StringUtils.isNotEmpty( forumId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.forumId ), forumId ) );
}
if( StringUtils.isNotEmpty( mainSectionId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.mainSectionId ), mainSectionId ) );
}
if( StringUtils.isNotEmpty( sectionId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.sectionId ), sectionId ) );
}
if( StringUtils.isNotEmpty( subjectId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.subjectId ), subjectId ) );
}
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
//@MethodDescribe( "根据指定用户姓名、论坛ID,主版块ID, 版块ID查询符合条件的所有回复对象列表" )
public List<BBSReplyInfo> listReplyForPage( String creatorName, String forumId, String mainSectionId, String sectionId, String subjectId, Integer maxCount ) throws Exception {
Boolean allFilterNull = true;
if( StringUtils.isNotEmpty( creatorName ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( forumId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( mainSectionId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( sectionId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( subjectId ) ){
allFilterNull = false;
}
if( allFilterNull ){
throw new Exception( "list filter can not all null." );
}
if( maxCount == null ){
maxCount = 20;
}
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSReplyInfo> cq = cb.createQuery( BBSReplyInfo.class );
Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class );
Predicate p = cb.isNotNull( root.get( BBSReplyInfo_.id ) );
if( StringUtils.isNotEmpty( creatorName ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.creatorName ), creatorName ) );
}
if( StringUtils.isNotEmpty( forumId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.forumId ), forumId ) );
}
if( StringUtils.isNotEmpty( mainSectionId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.mainSectionId ), mainSectionId ) );
}
if( StringUtils.isNotEmpty( sectionId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.sectionId ), sectionId ) );
}
if( StringUtils.isNotEmpty( subjectId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.subjectId ), subjectId ) );
}
cq.orderBy( cb.asc( root.get( BBSReplyInfo_.orderNumber ) ) );
return em.createQuery(cq.where(p)).setMaxResults( maxCount ).getResultList();
}
//@MethodDescribe( "(今日)根据指定用户姓名、论坛ID,主版块ID, 版块ID查询符合条件的所有回复的数量" )
public Long countReplyForTodayByUserName( String creatorName, String forumId, String mainSectionId, String sectionId, String subjectId ) throws Exception {
Boolean allFilterNull = true;
if( StringUtils.isNotEmpty( creatorName ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( forumId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( mainSectionId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( sectionId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( subjectId ) ){
allFilterNull = false;
}
if( allFilterNull ){
throw new Exception( "list filter can not all null." );
}
DateOperation dateOperation = new DateOperation();
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class);
Predicate p = cb.greaterThanOrEqualTo( root.get( BBSReplyInfo_.createTime ), dateOperation.getTodayStartTime() );
if( StringUtils.isNotEmpty( creatorName ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.creatorName ), creatorName ) );
}
if( StringUtils.isNotEmpty( forumId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.forumId ), forumId ) );
}
if( StringUtils.isNotEmpty( mainSectionId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.mainSectionId ), mainSectionId ) );
}
if( StringUtils.isNotEmpty( sectionId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.sectionId ), sectionId ) );
}
if( StringUtils.isNotEmpty( subjectId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.subjectId ), subjectId ) );
}
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
//@MethodDescribe( "(今日)根据指定用户姓名、论坛ID,主版块ID, 版块ID查询符合条件的所有回复对象列表" )
public List<BBSReplyInfo> listReplyForTodayByUserName( String creatorName, String forumId, String mainSectionId, String sectionId, String subjectId, Integer maxCount ) throws Exception {
Boolean allFilterNull = true;
if( StringUtils.isNotEmpty( creatorName ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( forumId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( mainSectionId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( sectionId ) ){
allFilterNull = false;
}
if( StringUtils.isNotEmpty( subjectId ) ){
allFilterNull = false;
}
if( allFilterNull ){
throw new Exception( "list filter can not all null." );
}
if( maxCount == null ){
maxCount = 20;
}
DateOperation dateOperation = new DateOperation();
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSReplyInfo> cq = cb.createQuery( BBSReplyInfo.class );
Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class );
Predicate p = cb.greaterThanOrEqualTo( root.get( BBSReplyInfo_.createTime ), dateOperation.getTodayStartTime() );
if( StringUtils.isNotEmpty( creatorName ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.creatorName ), creatorName ) );
}
if( StringUtils.isNotEmpty( forumId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.forumId ), forumId ) );
}
if( StringUtils.isNotEmpty( mainSectionId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.mainSectionId ), mainSectionId ) );
}
if( StringUtils.isNotEmpty( sectionId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.sectionId ), sectionId ) );
}
if( StringUtils.isNotEmpty( subjectId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.subjectId ), subjectId ) );
}
cq.orderBy( cb.asc( root.get( BBSReplyInfo_.orderNumber ) ) );
return em.createQuery(cq.where(p)).setMaxResults( maxCount ).getResultList();
}
public Long countReplyForTodayBySectionId( String sectionId ) throws Exception {
DateOperation dateOperation = new DateOperation();
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSReplyInfo> root = cq.from(BBSReplyInfo.class);
Predicate p = cb.greaterThanOrEqualTo( root.get( BBSReplyInfo_.createTime ), dateOperation.getTodayStartTime() );
if( StringUtils.isNotEmpty( sectionId ) ){
Predicate or = cb.equal( root.get( BBSReplyInfo_.mainSectionId ), sectionId );
or = cb.or( or, cb.equal( root.get( BBSReplyInfo_.sectionId ), sectionId ) );
p = cb.and( p, or );
}
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
public Long countForTodayByForumId( String forumId ) throws Exception {
DateOperation dateOperation = new DateOperation();
EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSReplyInfo> root = cq.from(BBSReplyInfo.class);
Predicate p = cb.greaterThanOrEqualTo( root.get( BBSReplyInfo_.createTime ), dateOperation.getTodayStartTime() );
if( StringUtils.isNotEmpty( forumId ) ){
p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.forumId ), forumId ) );
}
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
/**
* 查询指定的版块内时间范围内发表的回帖数量
* @param sectionId
* @param todayStartTime
* @param todayEndTime
* @param queryMainSection 是否也查询主版块是sectionId的数据
* @return
* @throws Exception
*/
public Long countReplyByDate(String sectionId, Date todayStartTime, Date todayEndTime, boolean queryMainSection ) throws Exception {
if( StringUtils.isEmpty( sectionId ) ){
throw new Exception("sectionId is null");
}
if( todayStartTime == null ) {
todayStartTime = new DateOperation().getTodayStartTime();
}
if( todayEndTime == null ) {
todayEndTime = new DateOperation().getTodayEndTime();
}
EntityManager em = this.entityManagerContainer().get(BBSReplyInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class );
Predicate p = cb.equal( root.get( BBSReplyInfo_.sectionId ), sectionId );
if( queryMainSection ) {
p = cb.or( p, cb.equal( root.get( BBSReplyInfo_.mainSectionId ), sectionId ));
}
Predicate p_time = cb.between( root.get( BBSReplyInfo_.createTime ), todayStartTime, todayEndTime ) ;
p = cb.and( p, p_time );
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
public List<String> listIdsByMainAndSubSectionId( String sectionId ) throws Exception {
if( StringUtils.isEmpty( sectionId ) ){
throw new Exception( "sectionId is empty!" );
}
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_.mainSectionId ), sectionId );
p = cb.or( p, cb.equal( root.get( BBSReplyInfo_.sectionId ), sectionId ) );
cq.select( root.get( BBSReplyInfo_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSRoleInfo;
import com.x.bbs.entity.BBSRoleInfo_;
/**
* 类 名:BBSRoleInfoFactory<br/>
* 实体类:BBSRoleInfo<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-08-10 17:17:26
**/
public class BBSRoleInfoFactory extends AbstractFactory {
public BBSRoleInfoFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSRoleInfo实体信息对象" )
public BBSRoleInfo get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSRoleInfo.class, ExceptionWhen.none );
}
//@MethodDescribe( "列示指定Id的BBSRoleInfo实体信息列表" )
public List<BBSRoleInfo> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSRoleInfo>();
}
EntityManager em = this.entityManagerContainer().get(BBSRoleInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSRoleInfo> cq = cb.createQuery(BBSRoleInfo.class);
Root<BBSRoleInfo> root = cq.from(BBSRoleInfo.class);
Predicate p = root.get(BBSRoleInfo_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "列示全部的BBSRoleInfo实体信息列表" )
public List<BBSRoleInfo> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSRoleInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSRoleInfo> cq = cb.createQuery(BBSRoleInfo.class);
return em.createQuery( cq ).setMaxResults( 1000 ).getResultList();
}
//@MethodDescribe( "根据角色编码获取指定的BBSRoleInfo实体信息列表" )
public BBSRoleInfo getRoleByCode( String roleCode ) throws Exception {
if( roleCode == null || roleCode.isEmpty() ){
throw new Exception("roleCode is null!");
}
List<BBSRoleInfo> roleInfoList = null;
EntityManager em = this.entityManagerContainer().get( BBSRoleInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSRoleInfo> cq = cb.createQuery( BBSRoleInfo.class );
Root<BBSRoleInfo> root = cq.from( BBSRoleInfo.class );
Predicate p = cb.equal( root.get( BBSRoleInfo_.roleCode ), roleCode );
roleInfoList = em.createQuery( cq.where(p) ).getResultList();
if( roleInfoList != null && roleInfoList.size() > 0 ){
return roleInfoList.get(0);
}else{
return null;
}
}
//@MethodDescribe( "根据论坛ID获取指定论坛包含的所有BBSRoleInfo实体信息列表" )
public List<String> listRoleByForumId( String forumId ) throws Exception {
if( forumId == null || forumId.isEmpty() ){
throw new Exception("forumId is null!");
}
EntityManager em = this.entityManagerContainer().get( BBSRoleInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSRoleInfo> root = cq.from( BBSRoleInfo.class );
Predicate p = cb.equal( root.get( BBSRoleInfo_.forumId ), forumId );
cq.select( root.get( BBSRoleInfo_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
/**
* 根据版块ID获取指定版块包含的所有BBSRoleInfo实体信息列表
* @param sectionId
* @param queryMainSectionId 是否查询主版块ID
* @return
* @throws Exception
*/
public List<String> listRoleBySectionId( String sectionId, Boolean queryMainSectionId ) throws Exception {
if( sectionId == null || sectionId.isEmpty() ){
throw new Exception("sectionId is null!");
}
EntityManager em = this.entityManagerContainer().get( BBSRoleInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSRoleInfo> root = cq.from( BBSRoleInfo.class );
Predicate p = cb.equal( root.get( BBSRoleInfo_.sectionId ), sectionId );
if( queryMainSectionId ) {
p = cb.or( p, cb.equal( root.get( BBSRoleInfo_.mainSectionId ), sectionId ) );
}
cq.select( root.get( BBSRoleInfo_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
public List<String> listRoleByMainSectionId(String sectionId) throws Exception {
if( sectionId == null || sectionId.isEmpty() ){
throw new Exception("sectionId is null!");
}
EntityManager em = this.entityManagerContainer().get( BBSRoleInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSRoleInfo> root = cq.from( BBSRoleInfo.class );
Predicate p = cb.equal( root.get( BBSRoleInfo_.mainSectionId ), sectionId );
cq.select( root.get( BBSRoleInfo_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.base.core.project.tools.ListTools;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSSectionInfo;
import com.x.bbs.entity.BBSSectionInfo_;
/**
* 类 名:BBSSectionInfoFactory<br/>
* 实体类:BBSSectionInfo<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-05-20 17:17:26
**/
public class BBSSectionInfoFactory extends AbstractFactory {
public BBSSectionInfoFactory( Business business ) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSSectionInfo实体信息对象" )
public BBSSectionInfo get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSSectionInfo.class, ExceptionWhen.none );
}
//@MethodDescribe( "列示指定Id的BBSSectionInfo实体信息列表" )
public List<BBSSectionInfo> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSSectionInfo>();
}
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSSectionInfo> cq = cb.createQuery(BBSSectionInfo.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = root.get(BBSSectionInfo_.id).in(ids);
cq.orderBy( cb.asc( root.get( BBSSectionInfo_.orderNumber ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "列示全部的BBSSectionInfo实体信息列表" )
public List<BBSSectionInfo> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSSectionInfo> cq = cb.createQuery(BBSSectionInfo.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
cq.orderBy( cb.asc( root.get( BBSSectionInfo_.orderNumber ) ) );
return em.createQuery( cq ).getResultList();
}
//@MethodDescribe( "根据论坛ID查询所有的主版块信息列表" )
public List<BBSSectionInfo> listMainSectionByForumId( String forumId ) throws Exception {
if( forumId == null || forumId.isEmpty() ){
throw new Exception( "forumId is null!" );
}
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSSectionInfo> cq = cb.createQuery(BBSSectionInfo.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.forumId ), forumId );
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionLevel ), "主版块" ));
cq.orderBy( cb.asc( root.get( BBSSectionInfo_.orderNumber ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据主版块ID查询所有的子版块信息列表" )
public List<BBSSectionInfo> listSubSectionByMainSectionId( String sectionId ) throws Exception {
if( sectionId == null || sectionId.isEmpty() ){
throw new Exception( "sectionId is null!" );
}
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSSectionInfo> cq = cb.createQuery(BBSSectionInfo.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.mainSectionId ), sectionId );
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionLevel ), "子版块" ));
cq.orderBy( cb.asc( root.get( BBSSectionInfo_.orderNumber ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据主版块ID查询所有的子版块信息Id列表" )
public List<String> listSubSectionIdsByMainSectionId( String sectionId ) throws Exception {
if( sectionId == null || sectionId.isEmpty() ){
throw new Exception( "sectionId is null!" );
}
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.mainSectionId ), sectionId );
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionLevel ), "子版块" ));
cq.select( root.get( BBSSectionInfo_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据论坛ID表查该论坛所包含的主版块数量" )
public Long countMainSectionByForumId( String forumId ) throws Exception {
EntityManager em = this.entityManagerContainer().get( BBSSectionInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSSectionInfo> root = cq.from( BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.forumId ), forumId );
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionLevel ), "主版块" ));
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
//@MethodDescribe( "根据论坛ID表查该论坛所包含的主版块和子版块数量总和" )
public Long countAllSectionByForumId( String forumId ) throws Exception {
EntityManager em = this.entityManagerContainer().get( BBSSectionInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSSectionInfo> root = cq.from( BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.forumId ), forumId );
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
//@MethodDescribe( "根据版块ID查询该版块所包含的子版块数量" )
public Long countSubSectionByMainSectionId(String sectionId) throws Exception {
EntityManager em = this.entityManagerContainer().get( BBSSectionInfo.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSSectionInfo> root = cq.from( BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.mainSectionId ), sectionId );
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionStatus ), "启用" ));
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionLevel ), "子版块" ));
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
//@MethodDescribe( "根据论坛ID查询该论坛所包含的所有主版块以及子版块信息列表" )
public List<BBSSectionInfo> listAllSectionByForumId( String forumId ) throws Exception {
if( forumId == null || forumId.isEmpty() ){
throw new Exception( "forumId is null!" );
}
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSSectionInfo> cq = cb.createQuery(BBSSectionInfo.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.forumId ), forumId );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据论坛ID查询该论坛所包含的所有主版块以及子版块信息列表" )
public List<String> listAllSectionIdsByForumId( String forumId ) throws Exception {
if( forumId == null || forumId.isEmpty() ){
throw new Exception( "forumId is null!" );
}
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.forumId ), forumId );
cq.select( root.get( BBSSectionInfo_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据论坛ID以及用户可访问的版块ID查询用户可访问的所有的主版块信息列表" )
public List<BBSSectionInfo> viewMainSectionByForumId( String forumId, List<String> viewableSectionIds ) throws Exception {
if( forumId == null || forumId.isEmpty() ){
throw new Exception( "forumId is null!" );
}
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSSectionInfo> cq = cb.createQuery(BBSSectionInfo.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.forumId ), forumId );
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionLevel ), "主版块" ));
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionStatus ), "启用" ));
Predicate or = cb.equal( root.get( BBSSectionInfo_.sectionVisible ), "所有人" );
if( ListTools.isNotEmpty( viewableSectionIds ) ){
or = cb.or(p, root.get( BBSSectionInfo_.id ).in( viewableSectionIds ) );
}
p = cb.and( p, or );
cq.orderBy( cb.asc( root.get( BBSSectionInfo_.orderNumber ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据版块ID以及用户可访问的版块ID列表查询所有用户可访问的子版块信息列表" )
public List<BBSSectionInfo> viewSubSectionByMainSectionId( String sectionId, List<String> viewableSectionIds ) throws Exception {
if( sectionId == null || sectionId.isEmpty() ){
throw new Exception( "sectionId is null!" );
}
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSSectionInfo> cq = cb.createQuery(BBSSectionInfo.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.mainSectionId ), sectionId );
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionLevel ), "子版块" ));
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionStatus ), "启用" ));
Predicate or = cb.equal( root.get( BBSSectionInfo_.sectionVisible ), "所有人" );
if( ListTools.isNotEmpty( viewableSectionIds ) ){
or = cb.or(p, root.get( BBSSectionInfo_.id ).in( viewableSectionIds ) );
}
p = cb.and( p, or );
cq.orderBy( cb.asc( root.get( BBSSectionInfo_.orderNumber ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据论坛ID列表查询指定论坛范围内所有公开访问的主版块列表" )
public List<String> listVisibleToAllUserMainSectionIds( List<String> forumIds ) throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.sectionLevel ), "主版块" );
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionVisible ), "所有人" ));
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionStatus ), "启用" ));
if( ListTools.isNotEmpty( forumIds ) ){
p = cb.and(p, root.get( BBSSectionInfo_.forumId ).in( forumIds ));
}
cq.select( root.get( BBSSectionInfo_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据论坛ID列表,主版块ID列表查询指定论坛和主版块范围内所有公开访问的子版块列表" )
public List<String> listVisibleToAllUserSectionIds( List<String> forumIds, List<String> mainSectionIds ) throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.sectionLevel ), "子版块" );
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionVisible ), "所有人" ));
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionStatus ), "启用" ));
if( ListTools.isNotEmpty( forumIds ) ){
p = cb.and(p, root.get( BBSSectionInfo_.forumId ).in( forumIds ));
}
if( ListTools.isNotEmpty( mainSectionIds ) ){
p = cb.and(p, root.get( BBSSectionInfo_.mainSectionId ).in( mainSectionIds ) );
}
cq.select( root.get( BBSSectionInfo_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据论坛ID列表查询指定论坛范围内所有公开访问的主版块和子版块信息列表" )
public List<String> viewSectionByForumId( List<String> viewforumIds, Boolean publicStatus ) throws Exception {
if( viewforumIds == null || viewforumIds.isEmpty() ){
throw new Exception( "viewforumIds is null!" );
}
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = root.get( BBSSectionInfo_.forumId ).in( viewforumIds );
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionStatus ), "启用" ));
if( publicStatus != null && publicStatus ){
p = cb.and(p, cb.equal( root.get( BBSSectionInfo_.sectionVisible ), "所有人" ));
}
cq.select( root.get( BBSSectionInfo_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
public List<String> listByForumId( String forumId ) throws Exception {
if( forumId == null || forumId.isEmpty() ){
throw new Exception( "forumId is null!" );
}
EntityManager em = this.entityManagerContainer().get(BBSSectionInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<BBSSectionInfo> root = cq.from(BBSSectionInfo.class);
Predicate p = cb.equal( root.get( BBSSectionInfo_.forumId ), forumId);
cq.select( root.get( BBSSectionInfo_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSSubjectAttachment;
import com.x.bbs.entity.BBSSubjectAttachment_;
/**
* 类 名:BBSSubjectAttachmentFactory<br/>
* 实体类:BBSSubjectAttachment<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-08-10 17:17:26
**/
public class BBSSubjectAttachmentFactory extends AbstractFactory {
public BBSSubjectAttachmentFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSSubjectAttachment实体信息对象" )
public BBSSubjectAttachment get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSSubjectAttachment.class, ExceptionWhen.none );
}
//@MethodDescribe( "列示指定Id的BBSSubjectAttachment实体信息列表" )
public List<BBSSubjectAttachment> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSSubjectAttachment>();
}
EntityManager em = this.entityManagerContainer().get(BBSSubjectAttachment.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSSubjectAttachment> cq = cb.createQuery(BBSSubjectAttachment.class);
Root<BBSSubjectAttachment> root = cq.from(BBSSubjectAttachment.class);
Predicate p = root.get(BBSSubjectAttachment_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据主题ID列示BBSSubjectAttachment实体信息列表" )
public List<BBSSubjectAttachment> listBySubjectId( String subjectId ) throws Exception {
if( subjectId == null || subjectId.isEmpty() ){
throw new Exception("subject id is null!");
}
EntityManager em = this.entityManagerContainer().get(BBSSubjectAttachment.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSSubjectAttachment> cq = cb.createQuery(BBSSubjectAttachment.class);
Root<BBSSubjectAttachment> root = cq.from(BBSSubjectAttachment.class);
Predicate p = cb.equal( root.get(BBSSubjectAttachment_.subjectId ), subjectId );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "列示全部的BBSSubjectAttachment实体信息列表" )
public List<BBSSubjectAttachment> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSSubjectAttachment.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSSubjectAttachment> cq = cb.createQuery(BBSSubjectAttachment.class);
return em.createQuery( cq ).setMaxResults( 1000 ).getResultList();
}
/**
* 根据指定的版块ID查询所有的附件信息ID列表
* @param sectionId
* @param queryMainSectionId 是否查询主版块ID
* @return
* @throws Exception
*/
public List<String> listBySectionId(String sectionId, Boolean queryMainSectionId ) throws Exception {
if( StringUtils.isNotEmpty( sectionId )){
throw new Exception("sectionId id is empty!");
}
EntityManager em = this.entityManagerContainer().get(BBSSubjectAttachment.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<BBSSubjectAttachment> root = cq.from(BBSSubjectAttachment.class);
Predicate p = cb.equal( root.get(BBSSubjectAttachment_.sectionId ), sectionId );
if( queryMainSectionId ) {
p = cb.or( p, cb.equal( root.get(BBSSubjectAttachment_.mainSectionId ), sectionId ) );
}
cq.select( root.get( BBSSubjectAttachment_.id ) );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.bbs.assemble.control.factory;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSSubjectVoteResult;
/**
* 类 名:BBSSubjectVoteResultFactory<br/>
* 实体类:BBSSubjectVoteResult<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-05-20 17:17:26
**/
public class BBSSubjectVoteResultFactory extends AbstractFactory {
public BBSSubjectVoteResultFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSSubjectVoteResult实体信息对象" )
public BBSSubjectVoteResult get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSSubjectVoteResult.class );
}
//@MethodDescribe( "获取指定Id的BBSSubjectVoteResult实体信息对象" )
public String getStatisticResult( String id ) throws Exception {
if( id == null || id.isEmpty() ){
return null;
}
BBSSubjectVoteResult subjectVoteResult = this.entityManagerContainer().find( id, BBSSubjectVoteResult.class );
if( subjectVoteResult != null ){
return subjectVoteResult.getStatisticContent();
}
return null;
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSUserInfo;
import com.x.bbs.entity.BBSUserInfo_;
/**
* 类 名:BBSUserInfoFactory<br/>
* 实体类:BBSUserInfo<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-08-10 17:17:26
**/
public class BBSUserInfoFactory extends AbstractFactory {
public BBSUserInfoFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSUserInfo实体信息对象" )
public BBSUserInfo get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSUserInfo.class, ExceptionWhen.none );
}
//@MethodDescribe( "列示指定Id的BBSUserInfo实体信息列表" )
public List<BBSUserInfo> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSUserInfo>();
}
EntityManager em = this.entityManagerContainer().get(BBSUserInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSUserInfo> cq = cb.createQuery(BBSUserInfo.class);
Root<BBSUserInfo> root = cq.from(BBSUserInfo.class);
Predicate p = root.get(BBSUserInfo_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "列示指定姓名的BBSUserInfo实体信息列表" )
public List<BBSUserInfo> listByUserName( String userName ) throws Exception {
if( userName == null || userName.isEmpty() ){
throw new Exception( "userName is null!");
}
EntityManager em = this.entityManagerContainer().get(BBSUserInfo.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSUserInfo> cq = cb.createQuery(BBSUserInfo.class);
Root<BBSUserInfo> root = cq.from(BBSUserInfo.class);
Predicate p = cb.equal( root.get(BBSUserInfo_.userName), userName );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSUserRole;
import com.x.bbs.entity.BBSUserRole_;
/**
* 类 名:BBSUserRoleFactory<br/>
* 实体类:BBSUserRole<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-08-10 17:17:26
**/
public class BBSUserRoleFactory extends AbstractFactory {
public BBSUserRoleFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSUserRole实体信息对象" )
public BBSUserRole get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSUserRole.class, ExceptionWhen.none );
}
//@MethodDescribe( "列示指定Id的BBSUserRole实体信息列表" )
public List<BBSUserRole> list(List<String> ids) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSUserRole>();
}
EntityManager em = this.entityManagerContainer().get(BBSUserRole.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSUserRole> cq = cb.createQuery(BBSUserRole.class);
Root<BBSUserRole> root = cq.from(BBSUserRole.class);
Predicate p = root.get(BBSUserRole_.id).in(ids);
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "列示全部的BBSUserRole实体信息列表" )
public List<BBSUserRole> listAll() throws Exception {
EntityManager em = this.entityManagerContainer().get(BBSUserRole.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSUserRole> cq = cb.createQuery(BBSUserRole.class);
return em.createQuery( cq ).setMaxResults( 5000 ).getResultList();
}
//@MethodDescribe( "根据绑定对象唯一标识以及绑定对象类别查询所有绑定的角色ID列表" )
public List<String> listRoleIdsByObjectUniqueId( String uniqueId, String objectType ) throws Exception {
if( uniqueId == null || uniqueId.isEmpty() ){
throw new Exception("uniqueId is null!");
}
if( objectType == null || objectType.isEmpty() ){
throw new Exception("objectType is null!");
}
EntityManager em = this.entityManagerContainer().get( BBSUserRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSUserRole> root = cq.from( BBSUserRole.class );
Predicate p = cb.equal( root.get( BBSUserRole_.uniqueId ), uniqueId );
p = cb.and( p, cb.equal( root.get( BBSUserRole_.objectType ), objectType ));
cq.select( root.get( BBSUserRole_.roleId ) );
return em.createQuery( cq.where(p) ).getResultList();
}
//@MethodDescribe( "根据绑定对象唯一标识以及绑定对象类别查询所有绑定的角色编码列表" )
public List<String> listRoleCodeByObjectUniqueId( String uniqueId, String objectType ) throws Exception {
if( uniqueId == null || uniqueId.isEmpty() ){
throw new Exception("uniqueId is null!");
}
if( objectType == null || objectType.isEmpty() ){
throw new Exception("objectType is null!");
}
EntityManager em = this.entityManagerContainer().get( BBSUserRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSUserRole> root = cq.from( BBSUserRole.class );
Predicate p = cb.equal( root.get( BBSUserRole_.uniqueId ), uniqueId );
p = cb.and( p, cb.equal( root.get( BBSUserRole_.objectType ), objectType ));
cq.select( root.get( BBSUserRole_.roleCode ) );
return em.createQuery( cq.where(p) ).getResultList();
}
//@MethodDescribe( "根据角色编码查询所有的人员角色绑定信息对象ID列表" )
public List<String> listIdsByRoleCode( String roleCode ) throws Exception {
if( roleCode == null || roleCode.isEmpty() ){
throw new Exception("roleCode is null!");
}
EntityManager em = this.entityManagerContainer().get( BBSUserRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSUserRole> root = cq.from( BBSUserRole.class );
Predicate p = cb.equal( root.get( BBSUserRole_.roleCode ), roleCode );
cq.select( root.get( BBSUserRole_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
//@MethodDescribe( "根据指定的绑定对象唯一标识列表查询在该对象上绑定的所有角色ID列表" )
public List<String> listRoleIdsByObjectUnique(List<String> objectUniqueIds) throws Exception {
if( objectUniqueIds == null || objectUniqueIds.isEmpty() ){
return null;
}
EntityManager em = this.entityManagerContainer().get( BBSUserRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSUserRole> root = cq.from( BBSUserRole.class );
Predicate p = root.get( BBSUserRole_.uniqueId ).in( objectUniqueIds );
cq.select( root.get( BBSUserRole_.roleId ) );
return em.createQuery( cq.where(p) ).getResultList();
}
//@MethodDescribe( "根据指定的绑定对象唯一标识列表查询在该对象上绑定的所有角色编码列表" )
public List<String> listRoleCodesByObjectUnique( List<String> objectUniqueIds ) throws Exception {
if( objectUniqueIds == null || objectUniqueIds.isEmpty() ){
return null;
}
EntityManager em = this.entityManagerContainer().get( BBSUserRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSUserRole> root = cq.from( BBSUserRole.class );
Predicate p = root.get( BBSUserRole_.uniqueId ).in( objectUniqueIds );
cq.select( root.get( BBSUserRole_.roleCode ) );
return em.createQuery( cq.where(p) ).getResultList();
}
public List<String> listByForumId(String forumId) throws Exception {
if( StringUtils.isEmpty( forumId ) ){
throw new Exception("forumId is empty!!");
}
EntityManager em = this.entityManagerContainer().get( BBSUserRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSUserRole> root = cq.from( BBSUserRole.class );
Predicate p = cb.equal( root.get( BBSUserRole_.forumId ), forumId );
cq.select( root.get( BBSUserRole_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
/**
* 根据版块信息ID查询所有的用户角色关联信息
* @param sectionId
* @param queryMainSectionId
* @return
* @throws Exception
*/
public List<String> listBySectionId(String sectionId, Boolean queryMainSectionId) throws Exception {
if( StringUtils.isEmpty( sectionId ) ){
throw new Exception("sectionId is empty!!");
}
EntityManager em = this.entityManagerContainer().get( BBSUserRole.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class );
Root<BBSUserRole> root = cq.from( BBSUserRole.class );
Predicate p = cb.equal( root.get( BBSUserRole_.sectionId ), sectionId );
if( queryMainSectionId ) {
p = cb.or( p, cb.equal( root.get( BBSUserRole_.mainSectionId ), sectionId ) );
}
cq.select( root.get( BBSUserRole_.id ) );
return em.createQuery( cq.where(p) ).getResultList();
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSVoteOption;
import com.x.bbs.entity.BBSVoteOptionGroup;
import com.x.bbs.entity.BBSVoteOptionGroup_;
import com.x.bbs.entity.BBSVoteOption_;
/**
* 类 名:BBSVoteOptionFactory<br/>
* 实体类:BBSVoteOption<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-05-20 17:17:26
**/
public class BBSVoteOptionFactory extends AbstractFactory {
public BBSVoteOptionFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSVoteOption实体信息对象" )
public BBSVoteOption get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSVoteOption.class, ExceptionWhen.none );
}
//@MethodDescribe( "列示指定Id的BBSVoteOption实体信息列表" )
public List<BBSVoteOption> list( List<String> ids ) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSVoteOption>();
}
EntityManager em = this.entityManagerContainer().get(BBSVoteOption.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSVoteOption> cq = cb.createQuery(BBSVoteOption.class);
Root<BBSVoteOption> root = cq.from(BBSVoteOption.class);
Predicate p = root.get(BBSVoteOption_.id).in(ids);
cq.orderBy( cb.desc( root.get( BBSVoteOption_.orderNumber ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据主题信息ID查询所有投票选择项信息ID列表" )
public List<String> listVoteOptionIdsBySubject( String subjectId ) throws Exception {
if( subjectId == null || subjectId.isEmpty() ){
throw new Exception( "subjectId is null!" );
}
EntityManager em = this.entityManagerContainer().get( BBSVoteOption.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class);
Root<BBSVoteOption> root = cq.from( BBSVoteOption.class );
Predicate p = cb.equal( root.get( BBSVoteOption_.subjectId ), subjectId );
cq.select( root.get( BBSVoteOption_.id ) );
return em.createQuery( cq.where(p)).getResultList();
}
//@MethodDescribe( "根据主题信息ID查询所有投票选择项信息列表" )
public List<BBSVoteOption> listVoteOptionBySubject( String subjectId ) throws Exception {
if( subjectId == null || subjectId.isEmpty() ){
throw new Exception( "subjectId is null!" );
}
EntityManager em = this.entityManagerContainer().get( BBSVoteOption.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSVoteOption> cq = cb.createQuery( BBSVoteOption.class);
Root<BBSVoteOption> root = cq.from( BBSVoteOption.class );
Predicate p = cb.equal( root.get( BBSVoteOption_.subjectId ), subjectId );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据主题信息ID查询所有投票选择项分组信息列表" )
public List<BBSVoteOptionGroup> listVoteOptionGroupBySubject( String subjectId ) throws Exception {
if( subjectId == null || subjectId.isEmpty() ){
throw new Exception( "subjectId is null!" );
}
EntityManager em = this.entityManagerContainer().get( BBSVoteOptionGroup.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSVoteOptionGroup> cq = cb.createQuery( BBSVoteOptionGroup.class);
Root<BBSVoteOptionGroup> root = cq.from( BBSVoteOptionGroup.class );
Predicate p = cb.equal( root.get( BBSVoteOptionGroup_.subjectId ), subjectId );
return em.createQuery(cq.where(p)).getResultList();
}
public List<BBSVoteOption> listVoteOptionByGroupId(String groupId) throws Exception {
if( groupId == null || groupId.isEmpty() ){
throw new Exception( "groupId is null!" );
}
EntityManager em = this.entityManagerContainer().get( BBSVoteOption.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSVoteOption> cq = cb.createQuery( BBSVoteOption.class);
Root<BBSVoteOption> root = cq.from( BBSVoteOption.class );
Predicate p = cb.equal( root.get( BBSVoteOption_.optionGroupId ), groupId );
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.bbs.assemble.control.factory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.bbs.assemble.control.AbstractFactory;
import com.x.bbs.assemble.control.Business;
import com.x.bbs.entity.BBSVoteRecord;
import com.x.bbs.entity.BBSVoteRecord_;
/**
* 类 名:BBSVoteRecordFactory<br/>
* 实体类:BBSVoteRecord<br/>
* 作 者:Liyi<br/>
* 单 位:O2 Team<br/>
* 日 期:2016-05-20 17:17:26
**/
public class BBSVoteRecordFactory extends AbstractFactory {
public BBSVoteRecordFactory(Business business) throws Exception {
super(business);
}
//@MethodDescribe( "获取指定Id的BBSVoteRecord实体信息对象" )
public BBSVoteRecord get( String id ) throws Exception {
return this.entityManagerContainer().find( id, BBSVoteRecord.class, ExceptionWhen.none );
}
// @MethodDescribe( "列示指定Id的BBSVoteRecord实体信息列表" )
public List<BBSVoteRecord> list( List<String> ids ) throws Exception {
if( ids == null || ids.size() == 0 ){
return new ArrayList<BBSVoteRecord>();
}
EntityManager em = this.entityManagerContainer().get(BBSVoteRecord.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSVoteRecord> cq = cb.createQuery(BBSVoteRecord.class);
Root<BBSVoteRecord> root = cq.from(BBSVoteRecord.class);
Predicate p = root.get(BBSVoteRecord_.id).in(ids);
cq.orderBy( cb.desc( root.get( BBSVoteRecord_.sequence ) ) );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据主题信息ID查询所有投票记录信息ID列表" )
public List<String> listVoteRecordBySubjectIds( String subjectId ) throws Exception {
if( subjectId == null || subjectId.isEmpty() ){
throw new Exception( "subjectId is null!" );
}
EntityManager em = this.entityManagerContainer().get( BBSVoteRecord.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery( String.class);
Root<BBSVoteRecord> root = cq.from( BBSVoteRecord.class );
cq.select(root.get( BBSVoteRecord_.id));
Predicate p = cb.equal( root.get( BBSVoteRecord_.subjectId ), subjectId );
return em.createQuery(cq.where(p)).getResultList();
}
//@MethodDescribe( "根据主题信息ID查询所有投票记录信息ID列表" )
public List<BBSVoteRecord> listVoteRecordBySubject( String subjectId ) throws Exception {
if( subjectId == null || subjectId.isEmpty() ){
throw new Exception( "subjectId is null!" );
}
EntityManager em = this.entityManagerContainer().get( BBSVoteRecord.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSVoteRecord> cq = cb.createQuery( BBSVoteRecord.class);
Root<BBSVoteRecord> root = cq.from( BBSVoteRecord.class );
Predicate p = cb.equal( root.get( BBSVoteRecord_.subjectId ), subjectId );
return em.createQuery(cq.where(p)).getResultList();
}
public Long getVoteCountByUserAndSubject(String personName, String subjectId) throws Exception {
if( personName == null || personName.isEmpty() ){
throw new Exception( "personName is null!" );
}
if( subjectId == null || subjectId.isEmpty() ){
throw new Exception( "subjectId is null!" );
}
EntityManager em = this.entityManagerContainer().get( BBSVoteRecord.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery( Long.class);
Root<BBSVoteRecord> root = cq.from( BBSVoteRecord.class );
Predicate p = cb.equal( root.get( BBSVoteRecord_.votorName ), personName );
p = cb.and( p, cb.equal( root.get( BBSVoteRecord_.subjectId ), subjectId ) );
cq.select( cb.count( root ));
return em.createQuery(cq.where(p)).getSingleResult();
}
public Long getVoteCountByUserAndOption(String personName, String optionId) throws Exception {
if( personName == null || personName.isEmpty() ){
throw new Exception( "personName is null!" );
}
if( optionId == null || optionId.isEmpty() ){
throw new Exception( "subjectId is null!" );
}
EntityManager em = this.entityManagerContainer().get( BBSVoteRecord.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery( Long.class);
Root<BBSVoteRecord> root = cq.from( BBSVoteRecord.class );
Predicate p = cb.equal( root.get( BBSVoteRecord_.votorName ), personName );
p = cb.and( p, cb.equal( root.get( BBSVoteRecord_.optionId ), optionId ) );
cq.select( cb.count( root ));
return em.createQuery(cq.where(p)).getSingleResult();
}
public Long countVoteRecordForSubject( String subjectId, String voteOptionId ) throws Exception {
EntityManager em = this.entityManagerContainer().get( BBSVoteRecord.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<BBSVoteRecord> root = cq.from( BBSVoteRecord.class);
Predicate p = cb.equal( root.get( BBSVoteRecord_.subjectId ), subjectId );
if( StringUtils.isNotEmpty( voteOptionId ) ){
p = cb.and( p, cb.equal( root.get( BBSVoteRecord_.optionId ), voteOptionId ));
}
cq.select( cb.count( root ) );
return em.createQuery(cq.where(p)).getSingleResult();
}
public List<BBSVoteRecord> listVoteRecordForPage(String subjectId, String voteOptionId, Integer maxRecordCount) throws Exception {
if( maxRecordCount == null ){
throw new Exception( "maxRecordCount is null." );
}
EntityManager em = this.entityManagerContainer().get(BBSVoteRecord.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSVoteRecord> cq = cb.createQuery(BBSVoteRecord.class);
Root<BBSVoteRecord> root = cq.from(BBSVoteRecord.class);
Predicate p = cb.isNotNull( root.get( BBSVoteRecord_.id ) );
p = cb.and( p, cb.equal( root.get( BBSVoteRecord_.optionId ), voteOptionId ));
cq.orderBy( cb.desc( root.get( BBSVoteRecord_.createTime ) ) );
return em.createQuery(cq.where(p)).setMaxResults( maxRecordCount ).getResultList();
}
/**
* 根据人员和选项组查询人员选择过的所有选项列表
* @param personName
* @param optionGroupId
* @return
* @throws Exception
*/
public List<BBSVoteRecord> listVoteCountByUserAndGroup(String personName, String optionGroupId) throws Exception {
if( StringUtils.isEmpty( personName ) ){
throw new Exception( "personName is empty!" );
}
if( StringUtils.isEmpty( optionGroupId ) ){
throw new Exception( "optionGroupId is empty!" );
}
EntityManager em = this.entityManagerContainer().get( BBSVoteRecord.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<BBSVoteRecord> cq = cb.createQuery( BBSVoteRecord.class);
Root<BBSVoteRecord> root = cq.from( BBSVoteRecord.class );
Predicate p = cb.equal( root.get( BBSVoteRecord_.votorName ), personName );
p = cb.and( p, cb.equal( root.get( BBSVoteRecord_.optionGroupId ), optionGroupId ));
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.bbs.assemble.control.jaxrs;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import com.x.base.core.project.jaxrs.AbstractActionApplication;
import com.x.bbs.assemble.control.jaxrs.attachment.AttachmentAction;
import com.x.bbs.assemble.control.jaxrs.attachment.PictureAction;
import com.x.bbs.assemble.control.jaxrs.configsetting.BBSConfigSettingAction;
import com.x.bbs.assemble.control.jaxrs.configsetting.BBSConfigSettingAnonymousAction;
import com.x.bbs.assemble.control.jaxrs.foruminfo.ForumInfoAction;
import com.x.bbs.assemble.control.jaxrs.foruminfo.ForumInfoManagerUserAction;
import com.x.bbs.assemble.control.jaxrs.image.ImageBase64Action;
import com.x.bbs.assemble.control.jaxrs.login.LoginAction;
import com.x.bbs.assemble.control.jaxrs.login.LogoutAction;
import com.x.bbs.assemble.control.jaxrs.login.MobileIndexAction;
import com.x.bbs.assemble.control.jaxrs.permissioninfo.PermissionInfoAction;
import com.x.bbs.assemble.control.jaxrs.permissioninfo.PermissionInfoAdminAction;
import com.x.bbs.assemble.control.jaxrs.replyinfo.ReplyInfoAction;
import com.x.bbs.assemble.control.jaxrs.replyinfo.ReplyInfoManagerUserAction;
import com.x.bbs.assemble.control.jaxrs.roleinfo.RoleInfoAction;
import com.x.bbs.assemble.control.jaxrs.sectioninfo.SectionInfoAction;
import com.x.bbs.assemble.control.jaxrs.sectioninfo.SectionInfoManagerUserAction;
import com.x.bbs.assemble.control.jaxrs.subjectinfo.SubjectAttachmentAction;
import com.x.bbs.assemble.control.jaxrs.subjectinfo.SubjectInfoAction;
import com.x.bbs.assemble.control.jaxrs.subjectinfo.SubjectInfoManagerUserAction;
import com.x.bbs.assemble.control.jaxrs.userinfo.UserInfoAction;
import com.x.bbs.assemble.control.jaxrs.uuid.UUIDAction;
@ApplicationPath("jaxrs")
public class ActionApplication extends AbstractActionApplication {
public Set<Class<?>> getClasses() {
this.classes.add(UUIDAction.class);
this.classes.add(LoginAction.class);
this.classes.add(LogoutAction.class);
this.classes.add(ForumInfoAction.class);
this.classes.add(ForumInfoManagerUserAction.class);
this.classes.add(SectionInfoAction.class);
this.classes.add(SectionInfoManagerUserAction.class);
this.classes.add(SubjectInfoAction.class);
this.classes.add(ImageBase64Action.class);
this.classes.add(SubjectInfoManagerUserAction.class);
this.classes.add(SubjectAttachmentAction.class);
this.classes.add(ReplyInfoAction.class);
this.classes.add(ReplyInfoManagerUserAction.class);
this.classes.add(PermissionInfoAction.class);
this.classes.add(PermissionInfoAdminAction.class);
this.classes.add(RoleInfoAction.class);
this.classes.add(UserInfoAction.class);
this.classes.add(MobileIndexAction.class);
this.classes.add(BBSConfigSettingAction.class);
this.classes.add(BBSConfigSettingAnonymousAction.class);
this.classes.add(AttachmentAction.class);
this.classes.add(PictureAction.class);
return this.classes;
}
}
\ No newline at end of file
package com.x.bbs.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.AnonymousCipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = {
"/jaxrs/image/encode/*",
"/servlet/image/encode/*",
"/jaxrs/setting/*",
"/jaxrs/uuid/*"
}, asyncSupported = true)
public class BBSAnonyJaxrsFilter extends AnonymousCipherManagerUserJaxrsFilter {
}
package com.x.bbs.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.AnonymousCipherManagerUserJaxrsFilter;
/**
* web服务过滤器,匿名用户可以访问的服务
* @author liyi *
*/
@WebFilter( urlPatterns = {
"/jaxrs/permission/*",
"/jaxrs/subjectattach/*",
"/jaxrs/forum/*",
"/jaxrs/section/*",
"/jaxrs/subject/*",
"/jaxrs/reply/*",
"/jaxrs/userinfo/*",
"/jaxrs/login/*",
"/jaxrs/logout/*",
"/jaxrs/mobile/*",
"/jaxrs/picture/*",
"/jaxrs/attachment/*"
} , asyncSupported = true)
public class BBSJaxrsFilter extends AnonymousCipherManagerUserJaxrsFilter {}
\ No newline at end of file
package com.x.bbs.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.ManagerUserJaxrsFilter;
/**
* web服务过滤器,将指定的URL定义为需要用户认证的服务,如果用户未登录,则无法访问该服务
* @author liyi *
*/
@WebFilter( urlPatterns = {
"/jaxrs/user/*",
"/servlet/*"
} , asyncSupported = true)
public class BBSJaxrsManagerUserFilter extends ManagerUserJaxrsFilter {}
\ No newline at end of file
package com.x.bbs.assemble.control.jaxrs;
public class MethodExcuteResult {
private Boolean success = true;
private String message = "success";
private Exception error = null;
private Object backObject = null;
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Exception getError() {
return error;
}
public void error(Exception e) {
this.error = e;
}
public Object getBackObject() {
return backObject;
}
public void setBackObject(Object backObject) {
this.backObject = backObject;
}
}
package com.x.bbs.assemble.control.jaxrs.attachment;
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.CheckPersistType;
import com.x.base.core.entity.annotation.CheckRemoveType;
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.bbs.assemble.control.ThisApplication;
import com.x.bbs.assemble.control.jaxrs.subjectinfo.exception.ExceptionAttachmentIdEmpty;
import com.x.bbs.assemble.control.jaxrs.subjectinfo.exception.ExceptionAttachmentNotExists;
import com.x.bbs.assemble.control.jaxrs.subjectinfo.exception.ExceptionSubjectInfoProcess;
import com.x.bbs.assemble.control.jaxrs.subjectinfo.exception.ExceptionSubjectQueryById;
import com.x.bbs.entity.BBSSubjectAttachment;
import com.x.bbs.entity.BBSSubjectInfo;
public class ActionAttachmentDelete extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionAttachmentDelete.class);
protected ActionResult<Wo> execute(HttpServletRequest request, EffectivePerson effectivePerson, String id) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
BBSSubjectAttachment subjectAttachment = null;
BBSSubjectInfo subjectInfo = null;
StorageMapping mapping = null;
boolean check = true;
if (id == null || id.isEmpty()) {
check = false;
Exception exception = new ExceptionAttachmentIdEmpty();
result.error(exception);
logger.error(exception, effectivePerson, request, null);
}
if (check) {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
subjectAttachment = emc.find(id, BBSSubjectAttachment.class);
if (null == subjectAttachment) {
check = false;
Exception exception = new ExceptionAttachmentNotExists(id);
result.error(exception);
logger.error(exception, effectivePerson, request, null);
}
} catch (Exception e) {
check = false;
Exception exception = new ExceptionSubjectInfoProcess(e, "根据指定ID查询附件信息时发生异常.ID:" + id);
result.error(exception);
logger.error(exception, effectivePerson, request, null);
}
}
if (check) {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
subjectInfo = emc.find(subjectAttachment.getSubjectId(), BBSSubjectInfo.class);
if (null == subjectInfo) {
logger.warn("subjectInfo{id:" + subjectAttachment.getSubjectId() + "} is not exists, anyone can delete the attachments.");
}
} catch (Exception e) {
check = false;
Exception exception = new ExceptionSubjectQueryById(e, subjectAttachment.getSubjectId());
result.error(exception);
logger.error(exception, effectivePerson, request, null);
}
}
if (check) {
if (subjectAttachment != null) {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
mapping = ThisApplication.context().storageMappings().get(BBSSubjectAttachment.class, subjectAttachment.getStorage());
// 对文件进行删除
subjectAttachment.deleteContent(mapping);
// 对数据库记录进行删除
subjectAttachment = emc.find(id, BBSSubjectAttachment.class);
subjectInfo = emc.find(subjectAttachment.getSubjectId(), BBSSubjectInfo.class);
emc.beginTransaction(BBSSubjectAttachment.class);
emc.beginTransaction(BBSSubjectInfo.class);
if (subjectInfo != null && ListTools.isNotEmpty(subjectInfo.getAttachmentList())) {
subjectInfo.getAttachmentList().remove(subjectAttachment.getId());
emc.check(subjectInfo, CheckPersistType.all);
}
emc.remove(subjectAttachment, CheckRemoveType.all);
Wo wo = new Wo();
wo.setId(id);
result.setData(wo);
emc.commit();
} catch (Exception e) {
check = false;
Exception exception = new ExceptionSubjectInfoProcess(e, "根据指定ID删除附件信息时发生异常.ID:" + subjectAttachment.getSubjectId());
result.error(exception);
logger.error(exception, effectivePerson, request, null);
}
}
}
return result;
}
public static class Wo extends WoId {
}
}
\ No newline at end of file
package com.x.bbs.assemble.control.jaxrs.attachment;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.x.base.core.entity.JpaObject;
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.bbs.assemble.control.jaxrs.subjectinfo.exception.ExceptionAttachmentIdEmpty;
import com.x.bbs.assemble.control.jaxrs.subjectinfo.exception.ExceptionAttachmentNotExists;
import com.x.bbs.assemble.control.jaxrs.subjectinfo.exception.ExceptionSubjectInfoProcess;
import com.x.bbs.entity.BBSSubjectAttachment;
public class ActionAttachmentGet extends BaseAction {
private static Logger logger = LoggerFactory.getLogger( ActionAttachmentGet.class );
protected ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id ) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wrap = null;
BBSSubjectAttachment attachmentInfo = null;
Boolean check = true;
if (check) {
if (id == null || id.isEmpty()) {
check = false;
Exception exception = new ExceptionAttachmentIdEmpty();
result.error(exception);
logger.error(exception, effectivePerson, request, null);
}
}
if (check) {
try {
attachmentInfo = subjectInfoServiceAdv.getAttachment(id);
} catch (Exception e) {
check = false;
Exception exception = new ExceptionSubjectInfoProcess(e, "根据指定ID查询附件信息时发生异常.ID:" + id);
result.error(exception);
logger.error(exception, effectivePerson, request, null);
}
}
if (check) {
if (attachmentInfo != null) {
try {
wrap = Wo.copier.copy(attachmentInfo);
result.setData(wrap);
} catch (Exception e) {
check = false;
Exception exception = new ExceptionSubjectInfoProcess( e, "将查询结果转换为可以输出的数据信息时发生异常." );
result.error(exception);
logger.error(exception, effectivePerson, request, null);
}
} else {
Exception exception = new ExceptionAttachmentNotExists(id);
result.error(exception);
logger.error(exception, effectivePerson, request, null);
}
}
return result;
}
public static class Wo extends BBSSubjectAttachment{
private static final long serialVersionUID = -5076990764713538973L;
public static List<String> Excludes = new ArrayList<String>();
public static WrapCopier< BBSSubjectAttachment, Wo > copier = WrapCopierFactory.wo( BBSSubjectAttachment.class, Wo.class, null, JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.bbs.assemble.control.jaxrs.attachment;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.x.base.core.entity.JpaObject;
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.bbs.assemble.control.jaxrs.subjectinfo.exception.ExceptionSubjectNotExists;
import com.x.bbs.assemble.control.jaxrs.subjectinfo.exception.ExceptionSubjectQueryById;
import com.x.bbs.entity.BBSSubjectAttachment;
import com.x.bbs.entity.BBSSubjectInfo;
public class ActionAttachmentListBySubjectId extends BaseAction {
private static Logger logger = LoggerFactory.getLogger( ActionAttachmentListBySubjectId.class );
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, String subjectId ) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<List<Wo>>();
List<Wo> wrapOutSubjectAttachmentList = null;
List<BBSSubjectAttachment> fileInfoList = null;
BBSSubjectInfo subjectInfo = null;
try {
subjectInfo = subjectInfoServiceAdv.get(subjectId);
if (subjectInfo != null) {
if ( subjectInfo.getAttachmentList() != null && subjectInfo.getAttachmentList().size() > 0 ) {
fileInfoList = subjectInfoServiceAdv.listAttachmentByIds( subjectInfo.getAttachmentList() );
} else {
fileInfoList = new ArrayList<BBSSubjectAttachment>();
}
wrapOutSubjectAttachmentList = Wo.copier.copy( fileInfoList );
} else {
Exception exception = new ExceptionSubjectNotExists(subjectId);
result.error(exception);
logger.error(exception, effectivePerson, request, null);
}
if (wrapOutSubjectAttachmentList == null) {
wrapOutSubjectAttachmentList = new ArrayList<Wo>();
}
result.setData(wrapOutSubjectAttachmentList);
} catch (Throwable th) {
Exception exception = new ExceptionSubjectQueryById(th, subjectId);
result.error(exception);
logger.error(exception, effectivePerson, request, null);
}
return result;
}
public static class Wo extends BBSSubjectAttachment{
private static final long serialVersionUID = -5076990764713538973L;
public static List<String> Excludes = new ArrayList<String>();
public static WrapCopier< BBSSubjectAttachment, Wo > copier = WrapCopierFactory.wo( BBSSubjectAttachment.class, Wo.class, null, JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.bbs.assemble.control.jaxrs.attachment;
import javax.servlet.http.HttpServletRequest;
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.WoFile;
import com.x.bbs.assemble.control.ThisApplication;
import com.x.bbs.entity.BBSSubjectAttachment;
public class ActionDownloadWithId extends BaseAction {
ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id ) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
BBSSubjectAttachment attachment = subjectInfoServiceAdv.getAttachment(id);
if ( null == attachment ) {
throw new Exception("附件不存在。id:" + id ) ;
}else {
StorageMapping mapping = ThisApplication.context().storageMappings().get(BBSSubjectAttachment.class, attachment.getStorage());
Wo wo = new Wo(attachment.readContent(mapping),
this.contentType(false, attachment.getName()),
this.contentDisposition(false, attachment.getName()));
result.setData(wo);
}
return result;
}
public static class Wo extends WoFile {
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
}
package com.x.bbs.assemble.control.jaxrs.attachment;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.bbs.assemble.control.service.BBSOperationRecordService;
import com.x.bbs.assemble.control.service.BBSSectionInfoService;
import com.x.bbs.assemble.control.service.BBSSubjectInfoServiceAdv;
public class BaseAction extends StandardJaxrsAction {
protected BBSSubjectInfoServiceAdv subjectInfoServiceAdv = new BBSSubjectInfoServiceAdv();
protected BBSSectionInfoService sectionInfoService = new BBSSectionInfoService();
protected BBSOperationRecordService operationRecordService = new BBSOperationRecordService();
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册