use of com.bc.pmpheep.back.po.CmsExtra in project pmph by BCSquad.
the class CmsContentServiceImpl method getCmsContentAndContentAndAttachmentById.
@Override
public Map<String, Object> getCmsContentAndContentAndAttachmentById(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);
String authDate = cmsContent.getAuthDate();
if (StringUtil.notEmpty(authDate)) {
cmsContent.setAuthDate(DateUtil.date2Str(DateUtil.str2Date(authDate)));
}
String deadlinePromote = cmsContent.getDeadlinePromote();
if (StringUtil.notEmpty(deadlinePromote)) {
cmsContent.setDeadlinePromote(DateUtil.date2Str(DateUtil.str2Date(deadlinePromote)));
}
String deadlineStick = cmsContent.getDeadlineStick();
if (StringUtil.notEmpty(deadlineStick)) {
cmsContent.setDeadlineStick(DateUtil.date2Str(DateUtil.str2Date(deadlineStick)));
}
String deadlineHot = cmsContent.getDeadlineHot();
if (StringUtil.notEmpty(deadlineHot)) {
cmsContent.setDeadlineHot(DateUtil.date2Str(DateUtil.str2Date(deadlineHot)));
}
resultMap.put("cmsContent", cmsContent);
// 判断内容是否已经发布或审核通过
String fileDownLoadType = null;
if (cmsContent.getIsPublished() || Const.CMS_AUTHOR_STATUS_2.shortValue() == cmsContent.getAuthStatus().shortValue()) {
fileDownLoadType = Const.CMS_FILE_DOWNLOAD;
} else {
fileDownLoadType = Const.FILE_DOWNLOAD;
}
// 按mid 获取Content对象
Content content = contentService.get(cmsContent.getMid());
if (ObjectUtil.isNull(content)) {
content = new Content();
content.setId(cmsContent.getMid());
content.setContent("");
}
resultMap.put("content", content);
// 按contentId 获取CMS内容附件
List<CmsExtra> cmsExtras = cmsExtraService.getCmsExtraByContentId(id);
List<CmsExtra> cmsList = new ArrayList<CmsExtra>(cmsExtras.size());
for (CmsExtra cmsExtra : cmsExtras) {
String attachment = cmsExtra.getAttachment();
if (!attachment.equals(cmsContent.getCover())) {
// 拼接附件下载路径
cmsExtra.setAttachment(fileDownLoadType + attachment);
cmsList.add(cmsExtra);
}
}
resultMap.put("cmsExtras", cmsList);
// 根据MaterialId 获取教材备注附件
List<MaterialNoteAttachment> materialNoteAttachments = null;
if (cmsContent.getIsMaterialEntry()) {
MaterialExtra materialExtra = materialExtraService.getMaterialExtraByMaterialId(cmsContent.getMaterialId());
if (ObjectUtil.notNull(materialExtra)) {
// 教材备注附件
materialNoteAttachments = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtra.getId());
}
}
resultMap.put("MaterialNoteAttachment", materialNoteAttachments);
if (Const.CMS_CATEGORY_ID_1.longValue() == cmsContent.getCategoryId().longValue()) {
// 文章封面图片
CmsExtra cmsExtra = cmsExtraService.getCmsExtraByAttachment(cmsContent.getCover());
String imgFileName = "默认封面.png";
String imgFilePath = RouteUtil.DEFAULT_USER_AVATAR;
if (ObjectUtil.notNull(cmsExtra)) {
imgFileName = cmsExtra.getAttachmentName();
} else {
GridFSDBFile file = fileService.get(cmsContent.getCover());
if (ObjectUtil.notNull(file)) {
imgFileName = file.getFilename();
}
}
resultMap.put("imgFileName", imgFileName);
if (!"DEFAULT".equals(cmsContent.getCover())) {
imgFilePath = cmsContent.getCover();
}
resultMap.put("imgFilePath", imgFilePath);
}
return resultMap;
}
use of com.bc.pmpheep.back.po.CmsExtra in project pmph by BCSquad.
the class CmsExtraServiceTest method testUpdateCmsExtra.
@Test
public void testUpdateCmsExtra() {
CmsExtra cmsExtra = this.addCmsExtra();
Integer count = cmsExtraService.updateCmsExtra(new CmsExtra(cmsExtra.getId(), 2L, "图片路径"));
Assert.assertTrue("是否更新CmsExtra成功", count > 0);
}
Aggregations