use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.
the class CmsContentServiceImpl method addCmsContent.
@Override
public CmsContent addCmsContent(CmsContent cmsContent, String[] files, String content, String scheduledTime, String sessionId, HttpServletRequest request) throws CheckedServiceException, IOException {
// 获取当前登陆用户
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (StringUtil.isEmpty(content)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "内容参数为空");
}
if (ObjectUtil.isNull(cmsContent.getCategoryId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "所属栏目不能为空");
}
if (ObjectUtil.isNull(cmsContent.getMaterialId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "教材ID不能为空");
}
// MongoDB 内容插入
Content contentObj = contentService.add(new Content(content));
if (StringUtil.isEmpty(contentObj.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "Content对象内容保存失败");
}
// 内容保存
// 上级id
cmsContent.setParentId(cmsContent.getCategoryId());
// cmsContent.setPath(cmsContent.getPath());// 根节点路径
// 内容id
cmsContent.setMid(contentObj.getId());
// 作者类型
cmsContent.setAuthorType(Const.CMS_AUTHOR_TYPE_1);
// 作者id
cmsContent.setAuthorId(pmphUser.getId());
// cmsContent.setMaterialId(cmsContent.getMaterialId());// 教材ID,为0表示未选择教材
String summary = SummaryUtil.htmlToText(content);
summary = summary.substring(0, Math.min(summary.length(), 60));
cmsContent.setSummary(summary);
if (Const.TRUE == cmsContent.getIsPublished()) {
cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_2);
}
// 信息快报/公告管理(发布),审核时间就为当前时间
if (ObjectUtil.notNull(cmsContent.getAuthStatus())) {
if (Const.CMS_AUTHOR_STATUS_2.shortValue() == cmsContent.getAuthStatus()) {
cmsContent.setAuthUserId(pmphUser.getId());
cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_2);
cmsContent.setAuthDate(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
cmsContent.setIsPublished(true);
}
}
if (ObjectUtil.notNull(cmsContent.getIsStaging())) {
if (Const.TRUE.booleanValue() == cmsContent.getIsStaging().booleanValue()) {
// 信息快报/公告管理(暂存)
cmsContent.setAuthUserId(pmphUser.getId());
cmsContent.setAuthStatus(null);
cmsContent.setAuthDate(null);
cmsContent.setIsPublished(false);
}
}
// 获取新增后的主键ID
Long contentId = this.addCmsContent(cmsContent).getId();
if (ObjectUtil.isNull(contentId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "CmsContent添加内容失败");
}
// 定时发布
// if (Const.TRUE.booleanValue() == cmsContent.getIsScheduled().booleanValue())
// {
// if (StringUtil.isEmpty(scheduledTime)) {
// throw new CheckedServiceException(CheckedExceptionBusiness.CMS,
// CheckedExceptionResult.NULL_PARAM, "定时发布时间参数为空");
// }
// cmsScheduleService.addCmsSchedule(new CmsSchedule(contentId,
// DateUtil.str2Timestam(scheduledTime)));
// }
// 保存附件到MongoDB
this.saveFileToMongoDB(request, files, null, contentId);
return cmsContent;
}
use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.
the class CmsContentServiceImpl method listCmsContent.
@Override
public PageResult<CmsContentVO> listCmsContent(PageParameter<CmsContentVO> pageParameter, String sessionId) throws CheckedServiceException {
// 获取当前登陆用户
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (Const.CMS_CATEGORY_ID_1.longValue() == pageParameter.getParameter().getCategoryId()) {
pageParameter.getParameter().setIsAdmin(true);
} else {
pageParameter.getParameter().setIsAdmin(pmphUser.getIsAdmin());
}
pageParameter.getParameter().setAuthorId(pmphUser.getId());
PageResult<CmsContentVO> pageResult = new PageResult<CmsContentVO>();
// 将页面大小和页面页码拷贝
PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
// if(cmsContentDao.getCmsContentByAuthorId(pageParameter.getParameter().getAuthorId()).size()>0){
// 包含数据总条数的数据集
List<CmsContentVO> cmsContentList = cmsContentDao.listCmsContent(pageParameter);
if (CollectionUtil.isNotEmpty(cmsContentList)) {
Integer count = cmsContentList.get(0).getCount();
pageResult.setTotal(count);
pageResult.setRows(cmsContentList);
}
// }
return pageResult;
}
use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.
the class CmsContentServiceImpl method updateCmsContent.
@Override
public Integer updateCmsContent(CmsContent cmsContent, String[] files, String[] imgFile, String content, String[] attachment, String[] imgAttachment, String scheduledTime, String sessionId, HttpServletRequest request) throws CheckedServiceException, IOException {
Integer count = 0;
// 获取当前登陆用户
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (StringUtil.notEmpty(content)) {
// 更新MongoDB 内容
contentService.update(new Content(cmsContent.getMid(), content));
}
if (ObjectUtil.isNull(cmsContent)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
if (ObjectUtil.isNull(cmsContent.getMaterialId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "教材ID为空");
}
// 信息快报/公告管理(发布),审核时间就为当前时间
if (Const.CMS_AUTHOR_STATUS_2 == cmsContent.getAuthStatus().shortValue()) {
cmsContent.setAuthUserId(pmphUser.getId());
cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_2);
cmsContent.setIsStaging(Const.FALSE);
cmsContent.setAuthDate(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
cmsContent.setIsPublished(true);
} else if (Const.CMS_AUTHOR_STATUS_0 == cmsContent.getAuthStatus().shortValue()) {
if (cmsContent.getIsStaging()) {
// 信息快报/公告管理(暂存)
cmsContent.setAuthUserId(pmphUser.getId());
cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_0);
cmsContent.setAuthDate(null);
cmsContent.setIsPublished(false);
}
} else if (Const.CMS_AUTHOR_STATUS_1.shortValue() == cmsContent.getAuthStatus().shortValue()) {
// 文章管理,退回
cmsContent.setAuthUserId(pmphUser.getId());
cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_1);
cmsContent.setAuthDate(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
cmsContent.setIsDeleted(false);
cmsContent.setIsPublished(false);
}
if (cmsContent.getCategoryId() == Const.CMS_CATEGORY_ID_1 && cmsContent.getAuthorType() == Const.CMS_AUTHOR_TYPE_2 && cmsContent.getAuthStatus() == Const.CMS_AUTHOR_STATUS_0 && Const.TRUE == cmsContent.getIsStaging()) {
cmsContent.setIsStaging(false);
}
// 再次编辑时间
cmsContent.setGmtReedit(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
// 撤销
if (null != cmsContent.getIsPublished()) {
cmsContent.setIsStaging(cmsContent.getIsPublished());
} else {
cmsContent.setIsStaging(false);
}
count = cmsContentDao.updateCmsContent(cmsContent);
if (// 内容管理,退回发送消息
count > 0 && Const.CMS_AUTHOR_STATUS_1.shortValue() == cmsContent.getAuthStatus().shortValue()) {
// MongoDB 消息插入
String categoryName = "文章管理";
if (Const.CMS_CATEGORY_ID_2.longValue() == cmsContent.getCategoryId().longValue()) {
categoryName = "信息快报管理";
} else if (Const.CMS_CATEGORY_ID_3.longValue() == cmsContent.getCategoryId().longValue()) {
categoryName = "公告管理";
}
// 退回时发送消息内容
StringBuilder sb = new StringBuilder();
sb.append(categoryName);
sb.append("中您添加的《 ");
sb.append(cmsContent.getTitle());
sb.append(" 》已被退回 !");
if (StringUtil.notEmpty(cmsContent.getReturnReason())) {
sb.append("<br/><br/>退回理由为:");
sb.append(cmsContent.getReturnReason());
}
Message message = messageService.add(new Message(sb.toString()));
if (StringUtil.isEmpty(message.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
}
String returnContentTitle = "内容管理审核退回";
// 系统消息
List<UserMessage> userMessageList = new ArrayList<UserMessage>(4);
userMessageList.add(new UserMessage(message.getId(), returnContentTitle, Const.MSG_TYPE_1, pmphUser.getId(), Const.SENDER_TYPE_1, cmsContent.getAuthorId(), cmsContent.getAuthorType(), 0L));
// 发送消息
if (CollectionUtil.isNotEmpty(userMessageList)) {
// 插入消息发送对象数据
userMessageService.addUserMessageBatch(userMessageList);
// websocket发送的id集合
List<String> websocketUserIds = new ArrayList<String>();
for (UserMessage userMessage : userMessageList) {
websocketUserIds.add(userMessage.getReceiverType() + "_" + userMessage.getReceiverId());
}
// webscokt发送消息
if (CollectionUtil.isNotEmpty(websocketUserIds)) {
WebScocketMessage webScocketMessage = new WebScocketMessage(message.getId(), Const.MSG_TYPE_1, pmphUser.getId(), pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, returnContentTitle, message.getContent(), DateUtil.getCurrentTime());
myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
}
}
}
// 当文章通过的时候给用户增加积分
if (Const.CMS_CATEGORY_ID_1.longValue() == cmsContent.getCategoryId().longValue() && Const.CMS_AUTHOR_STATUS_2.shortValue() == cmsContent.getAuthStatus().shortValue() && Const.CMS_AUTHOR_TYPE_2 == cmsContent.getAuthorType()) {
String ruleName = "发表文章";
writerPointLogService.addWriterPointLogByRuleName(ruleName, cmsContent.getAuthorId());
}
// 删除附件
if (ArrayUtil.isNotEmpty(attachment)) {
// 删除CmsExtra 表
cmsExtraService.deleteCmsExtraByAttachment(attachment);
// 删除MongoDB对应的文件
for (int i = 0; i < attachment.length; i++) {
fileService.remove(attachment[i]);
}
}
// 文章封面
if (ArrayUtil.isNotEmpty(imgAttachment)) {
// 删除CmsExtra 表
cmsExtraService.deleteCmsExtraByAttachment(imgAttachment);
// 删除MongoDB对应的文件
for (int i = 0; i < imgAttachment.length; i++) {
fileService.remove(imgAttachment[i]);
}
if (ArrayUtil.isEmpty(imgFile)) {
// 如果删除了封面没上传,就使用默认封面
this.updateCmsContent(new CmsContent(cmsContent.getId(), "DEFAULT"));
}
}
// 保存附件到MongoDB
this.saveFileToMongoDB(request, files, imgFile, cmsContent.getId());
return count;
}
use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.
the class CmsManualServiceImpl method addCmsManual.
@Override
public CmsManual addCmsManual(CmsManual cmsManual, String sessionId) throws CheckedServiceException {
// 获取当前登陆用户
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
cmsManual.setUserId(pmphUser.getId());
this.addCmsManual(cmsManual);
return cmsManual;
}
use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.
the class CmsManualServiceImpl method listCmsManual.
@Override
public PageResult<CmsManualVO> listCmsManual(PageParameter<CmsManualVO> pageParameter, String sessionId) throws CheckedServiceException {
// 获取当前登陆用户
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
PageResult<CmsManualVO> pageResult = new PageResult<CmsManualVO>();
// 将页面大小和页面页码拷贝
PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
// 包含数据总条数的数据集
List<CmsManualVO> cmsManualVOs = cmsManualDao.listCmsManual(pageParameter);
if (CollectionUtil.isNotEmpty(cmsManualVOs)) {
Integer count = cmsManualVOs.get(0).getCount();
pageResult.setTotal(count);
pageResult.setRows(cmsManualVOs);
}
return pageResult;
}
Aggregations