use of com.bc.pmpheep.back.po.MaterialNoticeAttachment 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;
}
use of com.bc.pmpheep.back.po.MaterialNoticeAttachment in project pmph by BCSquad.
the class MaterialExtraServiceImpl method saveFileToMongoDB.
/**
* <pre>
* 功能描述:保存文件到MongoDB
* 使用示范:
*
* @param files 临时文件路径
* @param materialExtraId 教材通知备注ID
* @param materialType 教材通知/备注
* @throws CheckedServiceException
* </pre>
*/
@SuppressWarnings("unused")
private void saveFileToMongoDB(String[] files, Long materialExtraId, String materialType) throws CheckedServiceException, IOException {
// 保存附件到MongoDB
if (ArrayUtil.isNotEmpty(files)) {
for (int i = 0; i < files.length; i++) {
File file = FileUpload.getFileByFilePath(files[i]);
// 循环获取file数组中得文件
if (StringUtil.notEmpty(file.getName())) {
String gridFSFileId = fileService.saveLocalFile(file, FileType.CMS_ATTACHMENT, materialExtraId);
if (StringUtil.isEmpty(gridFSFileId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.FILE_UPLOAD_FAILED, "文件上传失败!");
}
// 教材备注附件保存
if (NOTE.equals(materialType)) {
MaterialNoteAttachment materialNoteAttachment = materialNoteAttachmentService.addMaterialNoteAttachment(new MaterialNoteAttachment(materialExtraId, gridFSFileId, file.getName(), null));
if (ObjectUtil.isNull(materialNoteAttachment.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.PO_ADD_FAILED, "教材备注附件新增失败");
}
}
// 教材通知附件保存
if (NOTICE.equals(materialType)) {
MaterialNoticeAttachment materialNoticeAttachment = materialNoticeAttachmentService.addMaterialNoticeAttachment(new MaterialNoticeAttachment(materialExtraId, gridFSFileId, file.getName(), null));
if (ObjectUtil.isNull(materialNoticeAttachment.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.PO_ADD_FAILED, "教材通知附件新增失败");
}
}
}
// 删除本地临时文件
FileUtil.delFile(files[i]);
}
}
}
use of com.bc.pmpheep.back.po.MaterialNoticeAttachment in project pmph by BCSquad.
the class MaterialNoticeAttachmentServiceTest method testGetMaterialNoticeAttachmentsByMaterialExtraId.
@Test
@Rollback(Const.ISROLLBACK)
public void testGetMaterialNoticeAttachmentsByMaterialExtraId() {
MaterialNoticeAttachment materialNoticeAttachment = new MaterialNoticeAttachment();
materialNoticeAttachment.setMaterialExtraId(2L);
materialNoticeAttachment.setAttachment("--");
materialNoticeAttachment.setAttachmentName("---");
materialNoticeAttachment.setDownload(1L);
materialNoticeAttachment = materialNoticeAttachmentService.addMaterialNoticeAttachment(materialNoticeAttachment);
// 再插入一个对象
materialNoticeAttachment = new MaterialNoticeAttachment();
materialNoticeAttachment.setMaterialExtraId(2L);
materialNoticeAttachment.setAttachment("---");
materialNoticeAttachment.setAttachmentName("----");
materialNoticeAttachment.setDownload(1L);
materialNoticeAttachment = materialNoticeAttachmentService.addMaterialNoticeAttachment(materialNoticeAttachment);
// 根据MaterialExtraId获取
List<MaterialNoticeAttachment> materialNoticeAttachments = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialNoticeAttachment.getMaterialExtraId());
Assert.assertTrue("获取失败", materialNoticeAttachments != null);
}
use of com.bc.pmpheep.back.po.MaterialNoticeAttachment in project pmph by BCSquad.
the class MaterialNoticeAttachmentServiceTest method testDeleteMaterialNoticeAttachmentsByMaterialExtraId.
@Test
@Rollback(Const.ISROLLBACK)
public void testDeleteMaterialNoticeAttachmentsByMaterialExtraId() {
MaterialNoticeAttachment materialNoticeAttachment = new MaterialNoticeAttachment();
materialNoticeAttachment.setMaterialExtraId(2L);
materialNoticeAttachment.setAttachment("--");
materialNoticeAttachment.setAttachmentName("---");
materialNoticeAttachment.setDownload(1L);
materialNoticeAttachment = materialNoticeAttachmentService.addMaterialNoticeAttachment(materialNoticeAttachment);
// 再插入一个对象
materialNoticeAttachment = new MaterialNoticeAttachment();
materialNoticeAttachment.setMaterialExtraId(2L);
materialNoticeAttachment.setAttachment("---");
materialNoticeAttachment.setAttachmentName("----");
materialNoticeAttachment.setDownload(1L);
materialNoticeAttachment = materialNoticeAttachmentService.addMaterialNoticeAttachment(materialNoticeAttachment);
// 删除通过MaterialExtraId
Integer res = materialNoticeAttachmentService.deleteMaterialNoticeAttachmentsByMaterialExtraId(materialNoticeAttachment.getMaterialExtraId());
Assert.assertTrue("deleteMaterialNoticeAttachmentsByMaterialExtraId删除失败", res > 0);
Assert.assertTrue("deleteMaterialNoticeAttachmentsByMaterialExtraId删除失败", materialNoticeAttachmentService.deleteMaterialNoticeAttachmentsByMaterialExtraId(r.nextLong()) >= 0);
}
use of com.bc.pmpheep.back.po.MaterialNoticeAttachment in project pmph by BCSquad.
the class MaterialNoticeAttachmentServiceTest method testUpdateMaterialNoticeAttachment.
@Test
@Rollback(Const.ISROLLBACK)
public void testUpdateMaterialNoticeAttachment() {
MaterialNoticeAttachment materialNoticeAttachment = new MaterialNoticeAttachment();
materialNoticeAttachment.setMaterialExtraId(2L);
materialNoticeAttachment.setAttachment("--");
materialNoticeAttachment.setAttachmentName("---");
materialNoticeAttachment.setDownload(1L);
materialNoticeAttachment = materialNoticeAttachmentService.addMaterialNoticeAttachment(materialNoticeAttachment);
// 修改
materialNoticeAttachment.setAttachmentName("++++++");
Integer res = materialNoticeAttachmentService.updateMaterialNoticeAttachment(materialNoticeAttachment);
Assert.assertTrue("updateMaterialNoticeAttachment更新失败", res != null);
materialNoticeAttachment.setId(r.nextLong());
materialNoticeAttachmentService.updateMaterialNoticeAttachment(materialNoticeAttachment);
}
Aggregations