Search in sources :

Example 6 with MaterialNoticeAttachment

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;
}
Also used : MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) CmsContent(com.bc.pmpheep.back.po.CmsContent) HashMap(java.util.HashMap) MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) MaterialContact(com.bc.pmpheep.back.po.MaterialContact) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) MaterialExtra(com.bc.pmpheep.back.po.MaterialExtra)

Example 7 with MaterialNoticeAttachment

use of com.bc.pmpheep.back.po.MaterialNoticeAttachment in project pmph by BCSquad.

the class MaterialExtraServiceImpl method saveFileToMongoDB.

/**
 * <pre>
 * 功能描述:保存文件到MongoDB
 * 使用示范:
 *
 * &#64;param files 临时文件路径
 * &#64;param materialExtraId 教材通知备注ID
 * &#64;param materialType 教材通知/备注
 * &#64;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]);
        }
    }
}
Also used : MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) File(java.io.File)

Example 8 with MaterialNoticeAttachment

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);
}
Also used : MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 9 with MaterialNoticeAttachment

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);
}
Also used : MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 10 with MaterialNoticeAttachment

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);
}
Also used : MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Aggregations

MaterialNoticeAttachment (com.bc.pmpheep.back.po.MaterialNoticeAttachment)11 MaterialNoteAttachment (com.bc.pmpheep.back.po.MaterialNoteAttachment)5 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)5 BaseTest (com.bc.pmpheep.test.BaseTest)5 Test (org.junit.Test)5 Rollback (org.springframework.test.annotation.Rollback)5 Material (com.bc.pmpheep.back.po.Material)4 MaterialExtra (com.bc.pmpheep.back.po.MaterialExtra)4 CmsContent (com.bc.pmpheep.back.po.CmsContent)3 MaterialContact (com.bc.pmpheep.back.po.MaterialContact)3 MaterialExtension (com.bc.pmpheep.back.po.MaterialExtension)2 PmphUser (com.bc.pmpheep.back.po.PmphUser)2 MaterialProjectEditorVO (com.bc.pmpheep.back.vo.MaterialProjectEditorVO)2 Content (com.bc.pmpheep.general.po.Content)2 Gson (com.google.gson.Gson)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CmsExtra (com.bc.pmpheep.back.po.CmsExtra)1 MaterialProjectEditor (com.bc.pmpheep.back.po.MaterialProjectEditor)1 MaterialType (com.bc.pmpheep.back.po.MaterialType)1