📄 groupofforumserviceimpl.java
字号:
/*
* Created on 2007-3-4
* Last modified on 2007-8-22
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.service.security;
import java.util.List;
import org.apache.log4j.Logger;
import com.yeqiangwei.club.cache.Cache;
import com.yeqiangwei.club.cache.CacheFactory;
import com.yeqiangwei.club.cache.CacheKeys;
import com.yeqiangwei.club.cache.CacheRegion;
import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;
import com.yeqiangwei.club.dao.GroupOfForumDAO;
import com.yeqiangwei.club.dao.model.GroupOfForum;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.param.GroupOfForumParameter;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.service.model.GroupOfForumModel;
import com.yeqiangwei.club.service.model.UserModel;
import com.yeqiangwei.club.service.user.UserService;
import com.yeqiangwei.club.util.BeanLocator;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.util.Validator;
import com.yeqiangwei.util.TypeChange;
public class GroupOfForumServiceImpl implements GroupOfForumService{
private static final Logger logger = Logger.getLogger(GroupOfForumServiceImpl.class.getName());
private Cache groupOfForumCache = CacheFactory.creator(CacheRegion.GROUPOFFORUM);
public static void main(String args[]){
com.yeqiangwei.club.dao.hibernate.ConnectionManager.init();
GroupOfForumServiceImpl s = new GroupOfForumServiceImpl();
GroupOfForumParameter param = new GroupOfForumParameter();
List<GroupOfForumModel> list = s.findByParameter(param);
for(int i=0; i<list.size(); i++){
GroupOfForumModel model = list.get(i);
System.out.println(model.getUserName());
}
}
/**
* return GroupOfForumModel BO
*/
public GroupOfForumModel findById(int id) {
if(id>0){
GroupOfForum item = this.getGroupOfForumDAO().findById(id);
if(!Validator.isEmpty(item)){
GroupOfForumModel model = new GroupOfForumModel();
BeanUtils.copyProperties(model,item); //PO->BO
return model;
}else{
return null;
}
}else{
logger.error("GroupOfForumModel groupOfForumId==0");
return null;
}
}
public GroupOfForumModel createOrUpdate(GroupOfForumModel model) throws ClubException {
if(model.getGroupOfForumId()>0){
return this.update(model);
}else{
return this.create(model);
}
}
private GroupOfForumModel createOrUpdateUtils(GroupOfForumModel model, boolean iscreate) throws ClubException {
if(Validator.isEmpty(model)||Validator.isEmpty(model.getUserName())){
//this.setMessage(super.getMessage("error_empty"));
throw new ClubException(MessageUtils.getMessage("error_empty"));
}else{
GroupOfForum item = null;
UserModel user = this.getUserService().findByUserName(model.getUserName());
if(!Validator.isEmpty(user)){
model.setUserId(user.getUserId());
model.setUserName(user.getUserName());
//user.setGroupId(model.getGroupId());
if(model.getGroupOfForumId()>0){
item = this.getGroupOfForumDAO().findById(model.getGroupOfForumId());
}else{
item = new GroupOfForum();
}
BeanUtils.copyProperties(item,model); //BO->PO
if(iscreate){
this.getGroupOfForumDAO().create(item);
if(item.getGroupOfForumId()==0){
throw new ClubException(MessageUtils.getMessage("error_system"));
}
}else{
this.getGroupOfForumDAO().update(item);
}
BeanUtils.copyProperties(model,item); //PO->BO
groupOfForumCache.clear();
}else{
throw new ClubException(MessageUtils.getMessage("error_notfind_user"));
}
}
return model;
}
public GroupOfForumModel create(GroupOfForumModel model) throws ClubException{
return this.createOrUpdateUtils(model,true);
}
public GroupOfForumModel update(GroupOfForumModel model) throws ClubException {
return this.createOrUpdateUtils(model,false);
}
public int delete(GroupOfForumModel model) throws ClubException {
if(model.getGroupOfForumId()<1){
throw new ClubException(MessageUtils.getMessage("error_parameter"));
}else{
GroupOfForum item = new GroupOfForum();
BeanUtils.copyProperties(item,model); //BO->PO
groupOfForumCache.clear(); //清理缓存
return this.getGroupOfForumDAO().delete(item);
}
}
public int delete(String[] ids) throws ClubException {
int c = 0;
int e = 0;
if(Validator.isEmpty(ids)){
//this.setMessage(super.getMessage("error_delete_noid"));
throw new ClubException(MessageUtils.getMessage("error_parameter"));
}else{
for(int i=0; i<ids.length; i++){
int id = TypeChange.stringToInt(ids[i]);
GroupOfForumModel model = new GroupOfForumModel();
model.setGroupOfForumId(id);
if(this.delete(model)>0){
c++;
}else{
e++;
}
}
}
return c;
}
/**
* 根据组ID和版面ID查找,以确定是否为这个版面设定了单独设定了组权限
*/
@SuppressWarnings("unchecked")
public List<GroupOfForumModel> findByGroupIdAndForumId(int groupId, int forumId) {
StringBuffer sb = new StringBuffer("gid");
sb.append(groupId);
sb.append("fid");
sb.append(forumId);
Boolean isput = (Boolean) groupOfForumCache.get(sb.toString()+"-isput");
List<GroupOfForumModel> list = (List) groupOfForumCache.get(sb.toString());
if(Validator.isEmpty(list)&&Validator.isEmpty(isput)){
GroupOfForumParameter param = new GroupOfForumParameter();
param.setForumId(forumId);
param.setGroupId(groupId);
list = this.findByParameter(param);
groupOfForumCache.put(sb.toString(),list);
groupOfForumCache.put(sb.toString()+"-isput",new Boolean(true));
}
return list;
}
public List<GroupOfForumModel> findByParameter(GroupOfForumParameter param) {
List<GroupOfForum> list = this.getGroupOfForumDAO().findByParameter(param);
List<GroupOfForumModel> mlist = BeanUtils.<GroupOfForum,GroupOfForumModel>copyList(list, BeanLocator.GROUPOFFORUMMODEL);
return mlist;
}
public long countByParameter(GroupOfForumParameter param) {
return this.getGroupOfForumDAO().countByParameter(param);
}
/**
*
*/
@SuppressWarnings("unchecked")
public List<GroupOfForumModel> findByForumId(int forumId) {
Boolean isput = (Boolean) groupOfForumCache.get(CacheKeys.getGroupOfForumKeyByForumId(forumId)+"-isput");
List<GroupOfForumModel> list = (List) groupOfForumCache.get(CacheKeys.getGroupOfForumKeyByForumId(forumId));
if(Validator.isEmpty(list)&&Validator.isEmpty(isput)){
GroupOfForumParameter param = new GroupOfForumParameter();
param.setForumId(forumId);
list = this.findByParameter(param);
groupOfForumCache.put(CacheKeys.getGroupOfForumKeyByForumId(forumId),list);
groupOfForumCache.put(CacheKeys.getGroupOfForumKeyByForumId(forumId)+"-isput", new Boolean(true));
}
return list;
}
/**
*
*/
public GroupOfForumModel findByForumIdAndUserId(int forumId, int userId){
List<GroupOfForumModel>list = this.findByForumId(forumId);
if(!Validator.isEmpty(list)){
for(int i=0; i<list.size(); i++){
GroupOfForumModel model = list.get(i);
if(!Validator.isEmpty(model)){
if(model.getUserId()==userId){
return model;
}
}
}
}
return null;
}
public GroupOfForumDAO getGroupOfForumDAO() {
return DAOWrapper.<GroupOfForumDAO>getSingletonInstance(DAOLocator.GROUPOFFORUM);
}
public UserService getUserService() {
return ServiceWrapper.<UserService>getSingletonInstance(ServiceLocator.USER);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -