⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 articlemngimpl.java

📁 JEECMS是JavaEE版网站管理系统(Java Enterprise Edition Content Manage System)的简称。 基于java技术开发
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		bean.setMember(member);

		bean = save(bean);

		// 写文章内容
		bean.writeContent(contextPvd.getAppRoot(), 0);

		// 栏目文档数量
		CmsChannel chnl = bean.getChannel();
		chnl.setDocCount(chnl.getDocCount() + 1);

		// 新增附件
		addAttachment(bean, rule, member.getMember().getUser(), member);
		return bean;
	}

	private Updater createUpdater(Article bean) {
		Updater updater = Updater.create(bean);
		// 控制不能更新的字段
		updater.exclude(Article.PROP_WEBSITE);
		updater.exclude(Article.PROP_CONFIG);
		updater.exclude(Article.PROP_CONTENT_RES_PATH);
		updater.exclude(Article.PROP_ADMIN_CHECK);
		updater.exclude(Article.PROP_ADMIN_DISABLE);
		updater.exclude(Article.PROP_ADMIN_INPUT);
		updater.exclude(Article.PROP_CHECK);
		updater.exclude(Article.PROP_CHECK_OPINION);
		updater.exclude(Article.PROP_CHECK_STEP);
		updater.exclude(Article.PROP_CHECK_TIME);
		updater.exclude(Article.PROP_CONTENT_RES_PATH);
		updater.exclude(Article.PROP_DISABLE_TIME);
		updater.exclude(Article.PROP_REJECT);
		return updater;
	}

	private void handleTopTimeForUpdate(Article entity, long topTime) {
		if (topTime == -1) {
			// 清空置顶时间
			entity.setSortDate(entity.getReleaseDate());
		} else if (topTime > 0) {
			// 增加指定时间,将小时转换成毫秒
			topTime *= 60 * 60 * 1000;
			entity.setSortDate(new Timestamp(entity.getSortDate().getTime()
					+ topTime));
		} else {
			// do nothing
		}
	}

	private void handleTitleImg(Article arti) {
		// 如果标题图为空,则设置没有标题图片。
		if (StringUtils.isBlank(arti.getTitleImg())) {
			arti.setTitleImg("");
			arti.setHasTitleImg(false);
		} else {
			arti.setHasTitleImg(true);
		}
	}

	private void initDefValue(Article arti) {
		arti.setDisabled(false);
		arti.setReject(false);
		arti.setCheck(false);
		arti.setHasTitleImg(false);
		arti.setCheckStep(-1);
		arti.setCheckOpinion("");
		if (arti.getContent() == null) {
			arti.setContent("");
		}
		if (arti.getBold() == null) {
			arti.setBold(false);
		}
		if (arti.getTopLevel() == null) {
			arti.setTopLevel(0);
		}
		if (arti.getAllowComment() == null) {
			arti.setAllowComment(true);
		}
		if (arti.getDraft() == null) {
			arti.setDraft(false);
		}
		if (arti.getRecommend() == null) {
			arti.setRecommend(false);
		}
		arti.setCommentCount(0);
		arti.setVisitTotal(0L);
		arti.setStatDate(ComUtils.now());
		arti.setVisitToday(0L);
		arti.setVisitWeek(0L);
		arti.setVisitMonth(0L);
		arti.setVisitQuarter(0L);
		arti.setVisitYear(0L);
	}

	private void handleDate(Article arti, long topTime) {
		Date now = ComUtils.now();
		arti.setReleaseSysDate(now);
		// 如果没有输入发布时间,则取系统时间;
		Date relDate = arti.getReleaseDate();
		if (relDate == null) {
			relDate = now;
			arti.setReleaseDate(relDate);
		}
		// 置顶时间
		topTime *= 60 * 60 * 1000;
		arti.setSortDate(new Date(relDate.getTime() + topTime));
	}

	/**
	 * 管理员审核权限作为文章审核级数,然后判断文章是否审核通过。
	 * 
	 * @param arti
	 * @param admin
	 * @param checkCount
	 *            站点审核步骤数
	 */
	private void handleCheckRight(Article arti, CmsAdmin admin, int checkCount) {
		int checkRight = admin.getCheckRight();
		// 审核步骤为自己
		arti.setCheckStep(checkRight);
		// 草稿不能为审核通过
		if (arti.getDraft() || checkCount > checkRight) {
			arti.setCheck(false);
		} else {
			arti.setCheck(true);
		}
		// 修改和添加的时候退回和审核意见都为空
		arti.setReject(false);
		arti.setCheckOpinion("");
		// 修改可以认为是一种审核
		arti.setAdminCheck(admin);
		arti.setCheckTime(ComUtils.now());
	}

	private void addSideArticle(Article entity) {
		// 处理上一篇、下一篇
		if (!entity.getCheck() && entity.getDisabled()) {
			return;
		}
		Long webId = entity.getWebsite().getId();
		Long chnlId = entity.getChannel().getId();
		Article pre = getDao().getSideArticle(webId, chnlId, entity.getId(),
				false);
		if (pre != null) {
			Article next = pre.getNext();
			pre.setNext(entity);
			entity.setPre(pre);
			entity.setNext(next);
		} else {
			Article next = getDao().getSideArticle(webId, chnlId,
					entity.getId(), true);
			if (next != null) {
				next.setPre(entity);
				entity.setNext(next);
			}
		}
	}

	private void removeSideArticle(Article entity) {
		Article pre = entity.getPre();
		Article next = entity.getNext();
		if (pre != null) {
			pre.setNext(next);
		}
		if (next != null) {
			next.setPre(pre);
		}
	}

	/**
	 * 新增附件
	 * 
	 * @param entity
	 * @param rule
	 * @param web
	 * @param user
	 */
	private void addAttachment(Article entity, UploadRule rule, User user,
			CmsMember member) {
		Website web = entity.getWebsite();
		Map<String, UploadFile> uploadFiles = rule.getUploadFiles();
		if (uploadFiles != null) {
			String content = entity.getContent();
			String titleImg = entity.getTitleImg();
			String contentImg = entity.getContentImg();
			Set<String> rmFile = new HashSet<String>();
			Attachment attach;
			UploadFile uf;
			String rootPath = contextPvd.getAppRealPath(web.getUploadRoot()
					.toString());
			for (String name : uploadFiles.keySet()) {
				if (StringUtils.contains(content, name)
						|| StringUtils.contains(titleImg, name)
						|| StringUtils.contains(contentImg, name)) {
					rmFile.add(name);
					attach = new Attachment();
					uf = uploadFiles.get(name);
					attach.setWebsite(web);
					attach.setUser(user);
					attach.setName(uf.getOrigName());
					attach.setFileName(uf.getFileName());
					attach.setFilePath(uf.getRelPath(rootPath));
					attach.setFileSize((int) (uf.getSize() / 1024) + 1);
					attach.setOwnerCtg(Article.ATTACHMENT_CTG);
					attach.setOwnerId(entity.getId());
					attach.setOwnerName(entity.getTitle());
					attach.setOwnerUrl(entity.getUrl());
					attach.setDownCount(0L);
					attach.setCreateTime(ComUtils.now());
					if (entity.getGroup() == null) {
						attach.setFree(true);
					} else {
						attach.setFree(false);
					}
					attach.setLost(false);
					entity.addToAttachments(attach);
					if (member != null) {
						member.addUploadSize((int) uf.getSize());
					}
				}
			}
			for (String name : rmFile) {
				rule.removeUploadFile(name);
			}
		}
	}

	private void removeAttachment(Article entity, boolean removeAll) {
		Set<Attachment> attachs = entity.getAttachments();

		String content = entity.getContentFromFile();
		String titleImg = entity.getTitleImg();
		String contentImg = entity.getContentImg();

		Set<Attachment> rmAttachs = new HashSet<Attachment>();
		String filename;
		for (Attachment attach : attachs) {
			filename = attach.getFileName();
			if (removeAll
					|| (!StringUtils.contains(content, filename)
							&& !StringUtils.contains(titleImg, filename) && !StringUtils
							.contains(contentImg, filename))) {
				String realPath = contextPvd
						.getAppRealPath(attach.getRelPath());
				if (new File(realPath).delete()) {
					log.info("删除附件:{}", realPath);
				} else {
					log.warn("删除附件失败:{}", realPath);
				}
				rmAttachs.add(attach);
			}
		}
		attachs.removeAll(rmAttachs);
	}

	public Article findById(Serializable id) {
		Article arti = super.findById(id);
		if (arti == null) {
			return null;
		}
		// 用于操作文件
		arti.setRootReal(contextPvd.getAppRoot());
		return arti;
	}

	public Article findAndCheckResPath(Serializable id) {
		Article arti = super.findById(id);
		if (arti == null) {
			return null;
		}
		// 用于操作文件
		arti.setRootReal(contextPvd.getAppRoot());
		if (arti.isResPathChannge()) {
			arti.updateResPath();
		}
		return arti;
	}

	@Autowired
	private ContextPvd contextPvd;
	@Autowired
	private CmsAdminMng cmsAdminMng;
	@Autowired
	private ContentCtgMng contentCtgMng;
	@Autowired
	private CmsConfigMng cmsConfigMng;

	@Autowired
	public void setDao(ArticleDao dao) {
		super.setDao(dao);
	}

	protected ArticleDao getDao() {
		return (ArticleDao) super.getDao();
	}
}

⌨️ 快捷键说明

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