use of com.bc.pmpheep.back.po.MaterialExtra in project pmph by BCSquad.
the class MigrationStageTen method materialNotice.
public void materialNotice() {
List<Material> materials = materialService.getListMaterial("轮");
List<CmsCategory> categorys = cmsCategoryService.getCmsCategoryListByCategoryName("公告");
Long categoryId = categorys.get(0).getId();
final String html = "<p><strong><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">$f</span></strong>$d</p>";
final String htmlS1 = "<p><strong><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">$d</span></strong></p>";
final String htmlS2 = "<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; padding: 0px;\">$d</p>";
for (Material material : materials) {
CmsContent cmsContent = new CmsContent();
cmsContent.setParentId(0L);
cmsContent.setCategoryId(categoryId);
cmsContent.setPath("0");
cmsContent.setTitle(material.getMaterialName());
cmsContent.setAuthorType((short) 0);
cmsContent.setMaterialId(material.getId());
/* 生成通知内容 */
StringBuilder sb = new StringBuilder();
String str = html.replace("$f", "截止日期:");
str = str.replace("$d", sdf.format(material.getDeadline()));
sb.append(str);
/* 获取教材联系人 */
List<MaterialContact> contacts = materialContactService.listMaterialContactByMaterialId(categoryId);
if (CollectionUtil.isNotEmpty(contacts)) {
str = htmlS1.replace("$f", "联系人:");
sb.append(str);
for (MaterialContact contact : contacts) {
/* 裴中惠 (电话:010-59787110 , Email:pzh@pmph.com) */
StringBuilder builder = new StringBuilder(contact.getContactUserName());
builder.append(" (电话:");
builder.append(contact.getContactPhone());
builder.append(" , Email:");
builder.append(contact.getContactEmail());
builder.append(")");
str = htmlS2.replace("$d", builder.toString());
sb.append(str);
}
}
str = html.replace("$f", "邮寄地址:");
str = str.replace("$d", material.getMailAddress());
sb.append(str);
/* 获取通知内容和备注 */
MaterialExtra extra = materialExtraService.getMaterialExtraByMaterialId(material.getId());
str = htmlS1.replace("$d", "简 介:");
sb.append(str);
if (null != extra) {
// str = htmlS2.replace("$d", extra.getNotice()) /* 存入MongoDB */
}
Content content = new Content(sb.toString());
content = contentService.add(content);
cmsContent.setMid(content.getId());
}
}
use of com.bc.pmpheep.back.po.MaterialExtra 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.MaterialExtra in project pmph by BCSquad.
the class MaterialExtraServiceImpl method getMaterialExtraAndNoticeDetail.
/**
* <pre>
* 功能描述:根据教材ID查询教材通知详情及附件
* 使用示范:
*
* @param materialId 教材ID
* @return Map<String, Object> 集合
* @throws CheckedServiceException
* </pre>
*
* @throws UnsupportedEncodingException
*/
@Override
public Map<String, Object> getMaterialExtraAndNoticeDetail(Long materialId) throws CheckedServiceException {
if (ObjectUtil.isNull(materialId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材主键为空");
}
Map<String, Object> resultMap = new HashMap<String, Object>();
// 教材通知备注
MaterialExtra materialExtra = null;
// MongoDB中教材通知
String contentText = null;
// 联系人
List<MaterialContact> materialContacts = null;
// 教材通知附件
List<MaterialNoticeAttachment> materialNoticeAttachments = null;
// 教材备注附件
List<MaterialNoteAttachment> materialNoteAttachments = null;
// 教材
Material material = materialService.getMaterialById(materialId);
if (ObjectUtil.notNull(material)) {
// 联系人
materialContacts = materialContactService.listMaterialContactByMaterialId(materialId);
materialExtra = this.getMaterialExtraByMaterialId(materialId);
if (ObjectUtil.notNull(materialExtra)) {
Long materialExtraId = materialExtra.getId();
// 教材通知附件
materialNoticeAttachments = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialExtraId);
// 教材备注附件
materialNoteAttachments = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtraId);
}
// 判断内容是否已经发布或审核通过
String fileNoticeDownLoadType = null;
String fileNoteDownLoadType = null;
if (Const.TRUE.booleanValue() == material.getIsPublished().booleanValue()) {
fileNoticeDownLoadType = Const.MATERIAL_NOTICE_FILE_DOWNLOAD;
fileNoteDownLoadType = Const.MATERIAL_NOTE_FILE_DOWNLOAD;
} else {
fileNoticeDownLoadType = Const.FILE_DOWNLOAD;
fileNoteDownLoadType = Const.FILE_DOWNLOAD;
}
CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
if (ObjectUtil.notNull(cmsContent)) {
Content content = contentService.get(cmsContent.getMid());
if (ObjectUtil.notNull(content)) {
contentText = content.getContent();
}
}
if (CollectionUtil.isNotEmpty(materialNoticeAttachments)) {
for (MaterialNoticeAttachment materialNoticeAttachment : materialNoticeAttachments) {
String attachment = materialNoticeAttachment.getAttachment();
// 拼接附件下载路径
materialNoticeAttachment.setAttachment(fileNoticeDownLoadType + attachment);
}
}
if (CollectionUtil.isNotEmpty(materialNoteAttachments)) {
for (MaterialNoteAttachment materialNoteAttachment : materialNoteAttachments) {
String attachment = materialNoteAttachment.getAttachment();
// 拼接附件下载路径
materialNoteAttachment.setAttachment(fileNoteDownLoadType + attachment);
}
}
}
// 教材
resultMap.put("materialName", material);
// 联系人
resultMap.put("materialContacts", materialContacts);
// 教材通知备注
resultMap.put("materialExtra", materialExtra);
// MongoDB中教材通知
resultMap.put("content", contentText);
// 教材通知附件
resultMap.put("materialNoticeAttachments", materialNoticeAttachments);
// 教材备注附件
resultMap.put("materialNoteAttachments", materialNoteAttachments);
return resultMap;
}
Aggregations