use of com.bc.pmpheep.back.po.CmsContent in project pmph by BCSquad.
the class MigrationStageTen method cmsContent.
public void cmsContent() {
// 要迁移的旧库表名
String tableName = "site_article";
// 增加new_pk字段
JdbcHelper.addColumn(tableName);
// 取得该表中所有数据
List<Map<String, Object>> maps = JdbcHelper.queryForList(tableName);
List<Map<String, Object>> excel = new LinkedList<>();
Map<String, Object> result = new LinkedHashMap<>();
int correctCount = 0;
int[] state = { 0, 0, 0, 0, 0, 0 };
StringBuilder reason = new StringBuilder();
StringBuilder dealWith = new StringBuilder();
String sql = "SELECT sysflag FROM sys_user WHERE userid = ?";
// 迁移成功的条目数
int count = 0;
for (Map<String, Object> map : maps) {
CmsContent cmsContent = new CmsContent();
// 全是文章,没有评论
cmsContent.setParentId(0L);
cmsContent.setPath("0");
String title = (String) map.get("title");
if (StringUtil.isEmpty(title)) {
map.put(SQLParameters.EXCEL_EX_HEADER, "内容标题为空");
excel.add(map);
logger.error("内容标题为空,本条数据无效,将记录在Excel中");
if (state[0] == 0) {
reason.append("找不到内容标题。");
dealWith.append("放弃迁移。");
state[0] = 1;
}
continue;
}
cmsContent.setTitle(title);
String ct = (String) map.get("content");
if (StringUtil.isEmpty(ct)) {
map.put(SQLParameters.EXCEL_EX_HEADER, "文章内容为空");
excel.add(map);
logger.error("文章内容为空,本条数据无效,将记录在Excel中");
if (state[1] == 0) {
reason.append("找不到文章的内容。");
dealWith.append("放弃迁移。");
state[1] = 1;
}
continue;
}
BigDecimal colid = (BigDecimal) map.get("colid");
Long pk = JdbcHelper.getPrimaryKey("site_column", "colid", colid);
if (null == pk) {
map.put(SQLParameters.EXCEL_EX_HEADER, "获取site_column表new_pk字段失败,colid=" + colid);
excel.add(map);
logger.error("获取site_column表new_pk字段失败,此结果将被记录在Excel中");
if (state[2] == 0) {
reason.append("找不到对应的分类栏目。");
dealWith.append("放弃迁移。");
state[2] = 1;
}
continue;
}
cmsContent.setCategoryId(pk);
String brief = (String) map.get("brief");
if (StringUtil.notEmpty(brief)) {
cmsContent.setSummary(brief);
}
/* 判断作者类型 */
String userid = (String) map.get("publisheruserid");
Long userId = JdbcHelper.getPrimaryKey("sys_user", "userid", userid);
if (null == userId) {
map.put(SQLParameters.EXCEL_EX_HEADER, "未找到成员在sys_user表中的对应主键");
excel.add(map);
logger.error("未找到成员在sys_user表中的对应主键,此结果将被记录在Excel中");
if (state[3] == 0) {
reason.append("找不到对应的作者信息。");
dealWith.append("放弃迁移。");
state[3] = 1;
}
continue;
} else {
cmsContent.setAuthorId(userId);
Integer sysflag = JdbcHelper.getJdbcTemplate().queryForObject(sql, Integer.class, userid);
switch(sysflag) {
case 0:
cmsContent.setAuthorType((short) 1);
break;
case 1:
cmsContent.setAuthorType((short) 2);
break;
default:
map.put(SQLParameters.EXCEL_EX_HEADER, "小组成员对应的sysflag无法识别");
excel.add(map);
logger.error("小组成员对应的sysflag无法识别,此结果将被记录在Excel中");
if (state[4] == 0) {
reason.append("找不到作者对应的人员类型。");
dealWith.append("放弃迁移。");
state[4] = 1;
}
continue;
}
}
Integer clicknum = (Integer) map.get("clicknum");
cmsContent.setClicks(clicknum.longValue());
Integer isallowpublish = (Integer) map.get("isallowpublish");
cmsContent.setIsPublished(isallowpublish == 1);
Integer isaudit = (Integer) map.get("isaudit");
if (null == isaudit || 1 == isaudit) {
cmsContent.setAuthStatus((short) 2);
} else {
cmsContent.setAuthStatus((short) 0);
}
/* 获取审核者主键 */
String audituser = (String) map.get("audituser");
if (StringUtil.notEmpty(audituser)) {
Long authUserId = JdbcHelper.getPrimaryKey("sys_user", "userid", audituser);
if (null == authUserId) {
map.put(SQLParameters.EXCEL_EX_HEADER, "未找到成员在sys_user表中的对应主键");
excel.add(map);
logger.error("未找到成员在sys_user表中的对应主键,此结果将被记录在Excel中");
if (state[5] == 0) {
reason.append("找不到对应的审核者的信息。");
dealWith.append("放弃迁移。");
state[5] = 1;
}
continue;
} else {
cmsContent.setAuthUserId(authUserId);
}
/* 获取审核时间 */
String auditdate = (String) map.get("auditdate");
cmsContent.setAuthDate(auditdate);
}
/* 创建时间以最后更新时间为准(原来的createtime大部分为空) */
String lastupdatetime = map.get("lastupdatetime").toString();
cmsContent.setGmtCreate(Timestamp.valueOf(lastupdatetime));
// String materid = (String) map.get("materid");
/* 以下处理文章内容 */
// 先保存实体类,调用MongoDB方法后再更新
cmsContent.setMid("Pending");
cmsContent = cmsContentService.addCmsContent(cmsContent);
pk = cmsContent.getId();
if (ct.contains("src=")) {
List<String> srcs = JdbcHelper.getImgSrc(ct);
for (String src : srcs) {
try {
String mongoId = fileService.migrateFile(src.replace("/pmph_imesp", ""), FileType.CMS_IMG, pk);
ct = ct.replace(src, "/pmpheep/image/" + mongoId);
} catch (IOException ex) {
logger.warn("无法根据文章内容中的图片路径找到指定文件{}", ex.getMessage());
}
}
}
Content content = new Content(ct);
content = contentService.add(content);
cmsContent.setMid(content.getId());
// 更新文章
cmsContentService.updateCmsContent(cmsContent);
Double artid = (Double) map.get("artid");
// 更新旧表中new_pk字段
JdbcHelper.updateNewPrimaryKey(tableName, pk, "artid", artid);
count++;
if (null == map.get("exception")) {
correctCount++;
}
}
if (excel.size() > 0) {
try {
excelHelper.exportFromMaps(excel, "CMS内容表", "cms_content");
} catch (IOException ex) {
logger.error("异常数据导出到Excel失败", ex);
}
}
if (correctCount != maps.size()) {
result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "cms_content");
result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "CMS内容表");
result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, maps.size());
result.put(SQLParameters.EXCEL_HEADER_MIGRATED_DATA, count);
result.put(SQLParameters.EXCEL_HEADER_CORECT_DATA, correctCount);
result.put(SQLParameters.EXCEL_HEADER_TRANSFERED_DATA, count - correctCount);
result.put(SQLParameters.EXCEL_HEADER_NO_MIGRATED_DATA, maps.size() - count);
result.put(SQLParameters.EXCEL_HEADER_EXCEPTION_REASON, reason.toString());
result.put(SQLParameters.EXCEL_HEADER_DEAL_WITH, dealWith.toString());
SQLParameters.STATISTICS_RESULT.add(result);
}
logger.info("'{}'表迁移完成,异常条目数量:{}", tableName, excel.size());
logger.info("原数据库中共有{}条数据,迁移了{}条数据", maps.size(), count);
if (SQLParameters.STATISTICS_RESULT.size() > 0) {
try {
excelHelper.exportFromResultMaps(SQLParameters.STATISTICS_RESULT, "总体统计结果", null);
} catch (IOException ex) {
logger.error("异常数据导出到Excel失败", ex);
}
}
}
use of com.bc.pmpheep.back.po.CmsContent in project pmph by BCSquad.
the class MaterialExtraServiceImpl method updateMaterialExtraAndNoticeFile.
/**
* <pre>
* 功能描述:编辑通知详情
* 使用示范:
*
* @param materialExtraVO MaterialExtraVO
* @return Map<String, Object>集合
* @throws CheckedServiceException
* </pre>
*/
@Override
public Integer updateMaterialExtraAndNoticeFile(MaterialExtraVO materialExtraVO) throws CheckedServiceException, IOException {
// 教材ID
Long materialId = materialExtraVO.getMaterialId();
if (ObjectUtil.isNull(materialId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材ID为空");
}
String materialName = materialExtraVO.getMaterialName();
if (StringUtil.isEmpty(materialName)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材名称为空");
}
String content = materialExtraVO.getContent();
if (StringUtil.isEmpty(content)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材通知为空");
}
// MongoDB 内容插入
Content contentObj = contentService.add(new Content(content));
if (ObjectUtil.isNull(contentObj)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.OBJECT_NOT_FOUND, "教材通知保存失败");
}
Material material = materialService.getMaterialById(materialId);
if (StringUtil.isEmpty(materialExtraVO.getContent())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材通知内容为空");
}
// 内容ID
Long cmsContentId = null;
CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
if (ObjectUtil.notNull(cmsContent)) {
cmsContentId = cmsContent.getId();
String mid = null;
if (StringUtil.notEmpty(cmsContent.getMid())) {
mid = cmsContent.getMid();
}
// 存在就更新
Integer count = cmsContentService.updateCmsContent(new CmsContent(cmsContent.getId(), contentObj.getId(), DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime())));
if (count > 0) {
// 删除之前教材通知内容
contentService.delete(mid);
}
} else {
// 保存CMSContent内容
CmsContent cmsContentObj = cmsContentService.addCmsContent(new CmsContent(0L, "0", contentObj.getId(), materialName, Const.CMS_AUTHOR_TYPE_0, false, true, material.getFounderId(), DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()), materialId, Const.CMS_CATEGORY_ID_3, Const.TRUE, "DEFAULT"));
if (ObjectUtil.isNull(cmsContentObj.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "创建教材通知公告失败");
}
cmsContentId = cmsContentObj.getId();
}
// 先删除教材通知附件
List<CmsExtra> cmsExtras = cmsExtraService.getCmsExtraByContentId(cmsContentId);
if (CollectionUtil.isNotEmpty(cmsExtras)) {
List<Long> cmsExtraIds = new ArrayList<Long>();
for (CmsExtra cmsExtra : cmsExtras) {
cmsExtraIds.add(cmsExtra.getId());
}
cmsExtraService.deleteCmsExtraByIds(cmsExtraIds);
}
// 教材通知附件
List<MaterialNoticeAttachment> materialNoticeAttachments = null;
// 教材备注附件
List<MaterialNoteAttachment> materialNoteAttachments = null;
// 教材通知备注
MaterialExtra materialExtra = this.getMaterialExtraByMaterialId(materialId);
if (ObjectUtil.notNull(materialExtra)) {
Long materialExtraId = materialExtra.getId();
if (ObjectUtil.notNull(materialExtraId)) {
// 教材通知附件
materialNoticeAttachments = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialExtraId);
// 教材备注附件
materialNoteAttachments = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtraId);
// 教材通知附件保存到CMS附件表中
for (MaterialNoticeAttachment mna : materialNoticeAttachments) {
cmsExtraService.addCmsExtra(new CmsExtra(cmsContentId, mna.getAttachment(), mna.getAttachmentName(), 0L));
}
for (MaterialNoteAttachment ma : materialNoteAttachments) {
cmsExtraService.addCmsExtra(new CmsExtra(cmsContentId, ma.getAttachment(), ma.getAttachmentName(), 0L));
}
}
}
// 教材通知附件
// String[] noticeFiles = materialExtraVO.getNoticeFiles();
// if (ArrayUtil.isNotEmpty(noticeFiles)) {
// this.saveFileToMongoDB(noticeFiles, materialExtraId, NOTICE);
// }
// 教材通知附件MongoDB对应ID
String[] noticeAttachments = materialExtraVO.getNoticeAttachments();
if (ArrayUtil.isNotEmpty(noticeAttachments)) {
// 删除MaterialNoticeAttachment 表
materialNoticeAttachmentService.deleteMaterialNoticeAttachmentByAttachments(noticeAttachments);
// 删除MongoDB对应的文件
for (int i = 0; i < noticeAttachments.length; i++) {
fileService.remove(noticeAttachments[i]);
}
}
// 教材备注附件
// String[] noteFiles = materialExtraVO.getNoteFiles();
// if (ArrayUtil.isNotEmpty(noteFiles)) {
// this.saveFileToMongoDB(noteFiles, materialExtraId, NOTE);
// }
// 教材备注附件MongoDB对应ID
String[] noteAttachments = materialExtraVO.getNoteAttachments();
if (ArrayUtil.isNotEmpty(noteAttachments)) {
// 删除MaterialNoteAttachment 表
materialNoteAttachmentService.deleteMaterialNoteAttachmentByAttachments(noteAttachments);
// 删除MongoDB对应的文件
for (int i = 0; i < noteAttachments.length; i++) {
fileService.remove(noteAttachments[i]);
}
}
return 1;
}
use of com.bc.pmpheep.back.po.CmsContent in project pmph by BCSquad.
the class MaterialExtraServiceImpl method noticePublished.
@Override
public Integer noticePublished(Long materialId, List<Long> orgIds, String sessionId) throws CheckedServiceException, IOException {
if (CollectionUtil.isEmpty(orgIds)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "机构为空");
}
// 防止网络延迟重复提交
Set<Long> newOrgIdSet = new HashSet<>();
newOrgIdSet.addAll(orgIds);
List<Long> listOrgIds = new ArrayList<Long>(newOrgIdSet.size());
listOrgIds.addAll(newOrgIdSet);
// 获取当前用户
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
}
Integer count = 0;
List<MaterialOrg> materialOrgList = new ArrayList<MaterialOrg>(listOrgIds.size());
// 根据教材ID查询教材-机构关联表
List<Long> OrgIds = materialOrgService.getListMaterialOrgByMaterialId(materialId);
if (CollectionUtil.isEmpty(OrgIds)) {
// 为空,初次发布
for (Long orgId : listOrgIds) {
materialOrgList.add(new MaterialOrg(materialId, orgId));
}
count = materialOrgService.addMaterialOrgs(materialOrgList);
if (count > 0) {
systemMessageService.materialSend(materialId, listOrgIds, pmphUser, false);
/*以下向主任和项目编辑发送微信推送*/
// 企业微信推送对象的微信id集合
Set<String> touserOpenidSet = new HashSet<String>();
List<Long> useridList = new ArrayList<Long>();
String touser = "";
Set<String> touserIdSet = new HashSet<String>();
String contactUserNamesStr = "";
String projectEditorNamesStr = "";
List<MaterialContact> materialContactList = materialContactService.listMaterialContactByMaterialId(materialId);
List<MaterialProjectEditorVO> materialProjectEditorVOList = materialProjectEditorService.listMaterialProjectEditors(materialId);
Material material = materialService.getMaterialById(materialId);
// 获取主任
PmphUser director = pmphUserService.get(material.getDirector());
// 主任加入企业微信推送对象集合
touserOpenidSet.add(director.getOpenid());
useridList.add(director.getId());
for (MaterialProjectEditorVO materialProjectEditorVO : materialProjectEditorVOList) {
projectEditorNamesStr += materialProjectEditorVO.getRealname() + ",";
PmphUser projectEditorUser = pmphUserService.get(materialProjectEditorVO.getEditorId());
// 项目编辑加入企业微信推送对象集合
touserOpenidSet.add(projectEditorUser.getOpenid());
useridList.add(projectEditorUser.getId());
}
for (MaterialContact materialContact : materialContactList) {
contactUserNamesStr += materialContact.getContactUserName() + ",";
}
projectEditorNamesStr = projectEditorNamesStr.substring(0, projectEditorNamesStr.lastIndexOf(",") > 0 ? projectEditorNamesStr.lastIndexOf(",") : projectEditorNamesStr.length());
contactUserNamesStr = contactUserNamesStr.substring(0, contactUserNamesStr.lastIndexOf(",") > 0 ? contactUserNamesStr.lastIndexOf(",") : contactUserNamesStr.length());
String msg1 = director.getRealname() + "已被选为“" + material.getMaterialName() + "”的主任。";
String msg2 = projectEditorNamesStr + "已被选为“" + material.getMaterialName() + "”的项目编辑。";
String msg3 = contactUserNamesStr + "已被选为“" + material.getMaterialName() + "”的联系人。";
touserOpenidSet.remove(null);
touser = touserOpenidSet.toString();
if (touserOpenidSet.size() > 0) {
wxqyUserService.sendTextMessage("0", "0", touser, "", "", "text", msg1, (short) 0, "");
wxqyUserService.sendTextMessage("0", "0", touser, "", "", "text", msg2, (short) 0, "");
wxqyUserService.sendTextMessage("0", "0", touser, "", "", "text", msg3, (short) 0, "");
}
wxSendMessageService.batchInsertWxMessage(msg1, 0, useridList, "0", "0", "");
wxSendMessageService.batchInsertWxMessage(msg2, 0, useridList, "0", "0", "");
wxSendMessageService.batchInsertWxMessage(msg3, 0, useridList, "0", "0", "");
}
} else {
// 不为空
// 新选中的机构
List<Long> newOrgIds = new ArrayList<Long>();
for (Long orgId : listOrgIds) {
if (!OrgIds.contains(orgId)) {
newOrgIds.add(orgId);
materialOrgList.add(new MaterialOrg(materialId, orgId));
}
}
List<Long> i1 = new ArrayList<>();
// 当前提交
i1.addAll(listOrgIds);
List<Long> i2 = new ArrayList<>();
// 以保存
i2.addAll(OrgIds);
List<Long> i3 = new ArrayList<>();
for (Long i : i2) {
if (!i1.contains(i)) {
i3.add(i);
}
}
if (CollectionUtil.isEmpty(materialOrgList)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.ILLEGAL_PARAM, "当前选中的学校已收到消息,无需要再次发送");
}
if (CollectionUtil.isNotEmpty(materialOrgList)) {
count = materialOrgService.addMaterialOrgs(materialOrgList);
if (count > 0) {
systemMessageService.materialSend(materialId, newOrgIds, pmphUser, false);
}
}
}
CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
if (ObjectUtil.notNull(cmsContent)) {
// throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA,
// CheckedExceptionResult.NULL_PARAM, "没有找到对应的教材通知信息");
cmsContentService.updateCmsContent(new CmsContent(cmsContent.getId(), true, false, Const.CMS_AUTHOR_STATUS_2, // authUserId
0L, // 为0代表系统审核
DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime())));
}
count = materialService.updateMaterial(new Material(materialId, true), sessionId);
return count;
}
use of com.bc.pmpheep.back.po.CmsContent in project pmph by BCSquad.
the class CmsContentServiceImpl method recommendlist.
@Override
public PageResult<Map<String, Object>> recommendlist(Integer recommendPageSize, Integer recommendPageNumber, Long currentCmsId, Boolean relationCms, String cmsTitle, String cmsAuthorName) {
if (ObjectUtil.isNull(currentCmsId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
CmsContent mainArticle = cmsContentDao.getCmsContentById(currentCmsId);
PageParameter<Map<String, Object>> pageParameter = new PageParameter<>(recommendPageNumber, recommendPageSize);
Map<String, Object> params = new HashMap<String, Object>();
params.put("currentCmsId", currentCmsId);
params.put("relationCms", relationCms);
params.put("cmsTitle", cmsTitle);
params.put("cmsAuthorName", cmsAuthorName);
params.put("apporpc", 3 - mainArticle.getApporpc());
PageResult<Map<String, Object>> pageResult = new PageResult<>();
pageParameter.setParameter(params);
int total = cmsContentDao.recommendTotal(pageParameter);
if (total > 0) {
PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
pageResult.setRows(cmsContentDao.recommendlist(pageParameter));
}
pageResult.setTotal(total);
return pageResult;
}
use of com.bc.pmpheep.back.po.CmsContent 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);
cmsContent.setIsStaging(true);
// }
} 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() && 2 != cmsContent.getAuthStatus()) {
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 (cmsContent.getIsOriginal() != null && cmsContent.getIsOriginal()) {
writerPointLogService.addWriterPointLogByRuleName("原创文章", 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;
}
Aggregations