use of com.bc.pmpheep.general.po.Content 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.general.po.Content in project pmph by BCSquad.
the class ContentServiceTest method add.
@Test
@SuppressWarnings("deprecation")
public void add() {
Content content = new Content(html);
Content cnt = contentService.add(content);
contentService.removeAll();
logger.info(cnt.getContent());
Assert.assertNotNull("插入内容后返回的Content.id不应为空", cnt.getId());
logger.info(cnt.getId());
}
use of com.bc.pmpheep.general.po.Content 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.general.po.Content in project pmph by BCSquad.
the class CmsContentServiceImpl method getHelpDetail.
@Override
public Map<String, Object> getHelpDetail(Long id) throws CheckedServiceException {
Map<String, Object> resultMap = new HashMap<String, Object>();
if (ObjectUtil.isNull(id)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
// 按id 获取CmsContent对象
CmsContent cmsContent = cmsContentDao.getCmsContentById(id);
resultMap.put("cmsContent", cmsContent);
// 按mid 获取Content对象
Content content = contentService.get(cmsContent.getMid());
resultMap.put("content", content);
return resultMap;
}
use of com.bc.pmpheep.general.po.Content 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;
}
Aggregations