replyproxy.java

来自「社区文章采用的是平板、树形自由选择的两种展示方式」· Java 代码 · 共 445 行 · 第 1/2 页

JAVA
445
字号
				int views = (int) this.getRuleService().getElement(model.getForumId(), RuleService.VIEWS,20);
				if(u_score<score){
					throw new ClubException(MessageUtils.getMessage("error_power_score"));
				}
				if(u_money<money){
					throw new ClubException(MessageUtils.getMessage("error_power_money"));
				}
				if(u_credit<credit){
					throw new ClubException(MessageUtils.getMessage("error_power_credit"));
				}
				if(u_views<views){
					throw new ClubException(MessageUtils.getMessage("error_power_views"));
				}
			}
		}
	}
	
	/**
	 * 自动从内容中获取titile
	 * @param model
	 */
	private void autoTitle(Reply model){
		if(Validator.isEmpty(model.getTitle())){
			String content = model.getRContent().getContent();
			content = StringHelper.substring(content,0,500,"");
			content = StringHelper.ubbPattern(content,"\\[(.*?)\\](.*?)\\[/(.*?)\\]","","");
			content = StringHelper.ubbPattern(content,"\\[(.*?)\\]","","");
			content = StringHelper.ubbPattern(content,"<(.*?)>","","");
			if(content.length()>0){
				content = content.replace("\r\n","{r-n}");
				if(content.startsWith("{r-n}")){
					content = StringHelper.substring(content,5,content);
				}
				int n = content.indexOf("{r-n}");
				if(n==-1||n>30){
					n = 30;
				}
				String str = StringHelper.substring(content,0,n,"");
				int i1 = str.length();
				int i2 = model.getRContent().getContent().length();
				logger.debug("model.getRContent().getContent(): "+content);
				logger.debug("original content: "+content);
				logger.debug("auto title: "+str);
				logger.debug("model.getRContent().getContent().length(): "+i2);
				logger.debug("str.length(): "+i1);
				if(i1==i2){
					model.getRContent().setContent("");
					logger.debug("model.getRContent().getContent(): "+model.getRContent().getContent());
				}
				else if(!Validator.isEmpty(str)){
					str+="...";
				}
				model.setTitle(str);
			}
		}
	}
	
	public static void main(String args[]){
		String content = "<afdafds>sdf</dafds>";
		String str = StringHelper.ubbPattern(content,"<(.*?)>","","");
		System.out.println(str);
	}
	
	public void create(Reply model) throws ClubException {
		this.autoTitle(model);
		this.noAllowed(model);
		this.localizeFile(model);
		REPLY_SERVICE.create(model);
		
		/* 更新统计信息 */
		Counters counters = new Counters();
		counters.setReplys(1);
		counters.setForumId(model.getForumId());
		try{
			this.getCountService().doCount(counters);
		}catch(ClubException e){
			logger.error(e.toString());
		}
		
		User tuser = this.getUserService().findById(model.getTopic().getUserId());
		ManageLog log = new ManageLog();
		log.setTopicId(model.getTopicId());
		log.setReplyId(model.getReplyId());
		log.setForumId(model.getForumId());
		log.setTitle(model.getTitle());
		log.setByUserId(model.getUserId());
		log.setByUserName(model.getUserName());
		log.setByUserIp(model.getUserIp());
		log.setCreateDateTime(model.getCreateDateTime());
		this.getUserService().ruleUtils(log,model.getForumId(),3);
		log.setUserName(model.getUserName());
		log.setUserId(model.getUserId());
		log.setIsList(true);
		log.setListByUserName(true);
		log.setMemo("回复文章");
		log.setContent(model.getUserName()+"回复了"+tuser.getUserName()+"的文章!");
		try{
			this.getManageLogService().create(log);
		}catch(ClubException e){
			logger.error(e.toString());
		}
		if(model.getUserId()!=tuser.getUserId()){
			log = new ManageLog();
			log.setTopicId(model.getTopicId());
			log.setReplyId(model.getReplyId());
			log.setForumId(model.getForumId());
			log.setTitle(model.getTopic().getTitle());
			log.setByUserId(model.getUserId());
			log.setByUserName(model.getUserName());
			log.setByUserIp(model.getUserIp());
			log.setCreateDateTime(model.getCreateDateTime());
			this.getUserService().ruleUtils(log,model.getForumId(),6);
			log.setUserName(tuser.getUserName());
			log.setUserId(tuser.getUserId());
			log.setIsList(true);
			log.setListByUserName(true);
			log.setMemo("文章被回复");
			log.setContent(tuser.getUserName()+"文章被"+model.getUserName()+"回复!");
			try{
				this.getManageLogService().create(log);
			}catch(ClubException e){
				logger.error(e.toString());
			}
		}
	}

	public void update(Reply model) throws ClubException {
		this.autoTitle(model);
		/*
		 * 是否具备编辑他人文章的权限
		 */
		boolean updateadmin = USER_POWER.canAccess(model.getSessionUser()
				,model.getForumId()
				,UserPower.ADMINPOWER
				,0);
		/*
		 * 是否具备编辑被回复过的文章的权限 
		 */
		boolean updatereplyed = USER_POWER.canAccess(model.getSessionUser()
				,model.getForumId()
				,UserPower.OPERATEPOWER
				,4);
		
		/*
		 * 是否具备编辑自己文章的权限
		 */
		boolean updatemy = USER_POWER.canAccess(model.getSessionUser()
				,model.getForumId()
				,UserPower.OPERATEPOWER
				,3);
		
		if(!updateadmin){
			//this.setMessage(MessageUtils.getMessage("error_power"));
			/*
			 * 如果用户编辑的是自己的文章
			 */
			if(model.getSessionUser()!=null
					&& model.getSessionUser().getUserId()==model.getUserId())
			{
				/*
				 * 如果用户编辑的是自己的文章
				 */
				if(!updatemy){
					throw new ClubException(MessageUtils.getMessage("error_power"));
				}				
				/*
				 * 判断是否具备编辑被回复过的文章权限
				 */
				if(model.getReplys()>0&&!updatereplyed){
					//this.setMessage(MessageUtils.getMessage("error_update_replyed"));
					throw new ClubException(MessageUtils.getMessage("error_update_replyed"));
				}
			}else{
				//this.setMessage(MessageUtils.getMessage("error_power"));
				throw new ClubException(MessageUtils.getMessage("error_power"));
			}
		}
		this.localizeFile(model);
		REPLY_SERVICE.update(model);
	}

	public int delete(Reply model) {
		return 0;
	}

	public int delete(String[] ids) {
		return 0;
	}

	public List<Reply> findByParameter(TopicParameter param) {
		return REPLY_SERVICE.findByParameter(param);
	}

	public long countByParameter(TopicParameter param) {
		return REPLY_SERVICE.countByParameter(param);
	}
	
	private UserService getUserService() {
		return ServiceWrapper.<UserService>getSingletonInstance(ServiceLocator.USER);
	}

	private CountService getCountService() {
		return ServiceWrapper.<CountService>getSingletonInstance(ServiceLocator.COUNT);
	}
	
	private NoAllowedCharService getNoAllowedCharService(){
		return ServiceWrapper.<NoAllowedCharService>getSingletonInstance(ServiceLocator.NOALLOWEDCHAR);
	}
	
	private ManageLogService getManageLogService() {
		return  ServiceWrapper.<ManageLogService>getSingletonInstance(ServiceLocator.MANAGELOG);
	}
	
	private RuleService getRuleService() {
		return ServiceWrapper.<RuleService>getSingletonInstance(ServiceLocator.RULE);
	}
	
	private MessageService getMessageService(){
		return ServiceWrapper.<MessageService>getSingletonInstance(ServiceLocator.MESSAGE);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?