Search in sources :

Example 1 with MaterialNoteAttachment

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

the class MigrationStageFour method transferMaterialNoteAttachment.

protected void transferMaterialNoteAttachment() {
    String sql = "select " + "a.new_pk materid, " + "b.filedir, " + "b.filename " + "from teach_material a  " + "LEFT JOIN pub_addfileinfo b on b.tablekeyid = a.materid " + "where b.childsystemname='notice' and tablename='TEACH_MATERIAL' ";
    List<Map<String, Object>> materialMaterialNoteAttachmentList = JdbcHelper.getJdbcTemplate().queryForList(sql);
    List<Map<String, Object>> excel = new LinkedList<>();
    Map<String, Object> result = new LinkedHashMap<>();
    int count = 0;
    int correctCount = 0;
    int[] state = { 0, 0, 0, 0 };
    StringBuilder reason = new StringBuilder();
    StringBuilder dealWith = new StringBuilder();
    // 模块名称
    excptionList.add(new Object[] { "教材备注附件" });
    // 模块标题
    excptionList.add(new Object[] { "所属教材名称", "备注附件名称", "问题", "原因分析", "处理方式" });
    int excptionListOldSize = excptionList.size();
    for (Map<String, Object> map : materialMaterialNoteAttachmentList) {
        StringBuilder exception = new StringBuilder();
        Long newMaterid = (Long) map.get("materid");
        String matername = (newMaterid == null ? "" : materialService.getMaterialNameById(newMaterid));
        if (ObjectUtil.isNull(newMaterid)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("教材id为空。"));
            excel.add(map);
            excptionList.add(new Object[] { matername, (String) map.get("filename"), "找不到对应教材", "新建的教材被删除", "不导入该条信息" });
            if (state[0] == 0) {
                reason.append("找不到教材的唯一标识。");
                dealWith.append("放弃迁移。");
                state[0] = 1;
            }
            continue;
        }
        // 文件名
        String fileName = (String) map.get("filename");
        if (StringUtil.isEmpty(fileName)) {
            fileName = "-";
            excptionList.add(new Object[] { matername, fileName, "文件名称为空", "", "设置为'-'导入新库表" });
            map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("文件名称为空。设置为'-'导入新库表"));
            if (state[1] == 0) {
                reason.append("找不到相关的文件名称。");
                dealWith.append("设为默认值迁入数据库。");
                state[1] = 1;
            }
            excel.add(map);
        }
        Long materialExtraId = mps.get(newMaterid);
        if (ObjectUtil.isNull(materialExtraId)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("找不到相关的通知内容。"));
            excptionList.add(new Object[] { matername, fileName, "找不到关联的通知", "新建的教材被删除", "不导入该条信息" });
            excel.add(map);
            if (state[2] == 0) {
                reason.append("找不到相关的通知内容。");
                dealWith.append("放弃迁移。");
                state[2] = 1;
            }
            continue;
        }
        MaterialNoteAttachment materialNoteAttachment = new MaterialNoteAttachment();
        materialNoteAttachment.setMaterialExtraId(materialExtraId);
        // 先用一个临时的"-"占位,不然会报错;
        materialNoteAttachment.setAttachment("-");
        materialNoteAttachment.setAttachmentName(fileName);
        materialNoteAttachment.setDownload(1L);
        materialNoteAttachment = materialNoteAttachmentService.addMaterialNoteAttachment(materialNoteAttachment);
        count++;
        if (ObjectUtil.notNull(materialNoteAttachment.getId())) {
            String mongoId = null;
            try {
                mongoId = fileService.migrateFile((String) map.get("filedir"), FileType.MATERIAL_NOTE_ATTACHMENT, materialNoteAttachment.getId());
            } catch (IOException ex) {
                logger.error("文件读取异常,路径<{}>,异常信息:{}", (String) map.get("filedir"), ex.getMessage());
                map.put(SQLParameters.EXCEL_EX_HEADER, "文件读取异常。");
                excel.add(map);
                if (state[3] == 0) {
                    reason.append("找不到相关的备注文件。");
                    dealWith.append("放弃迁移。");
                    state[3] = 1;
                }
            }
            if (null != mongoId) {
                materialNoteAttachment.setAttachment(mongoId);
                materialNoteAttachmentService.updateMaterialNoteAttachment(materialNoteAttachment);
            } else {
                materialNoteAttachmentService.deleteMaterialNoteAttachmentById(materialNoteAttachment.getId());
                excptionList.add(new Object[] { matername, fileName, "找不到备注文件", "文件丢失", "不导入该条信息" });
            }
        }
        if (null == map.get("exception")) {
            correctCount++;
        }
    }
    // 没有错误数据
    if (excptionList.size() == excptionListOldSize) {
        excptionList.remove(excptionList.size() - 1);
        excptionList.remove(excptionList.size() - 1);
    } else {
        // 插入一个空行
        excptionList.add(new String[] { "" });
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "教材备注附件表", "material_note_attachment");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != materialMaterialNoteAttachmentList.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "material_note_attachment");
        result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "教材备注附件表");
        result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, materialMaterialNoteAttachmentList.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, materialMaterialNoteAttachmentList.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("教材通知附件表迁移了{}条数据", count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "教材备注附件表  表迁移完成" + count + "/" + materialMaterialNoteAttachmentList.size());
    SQLParameters.STATISTICS.add(msg);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) IOException(java.io.IOException) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with MaterialNoteAttachment

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

the class MaterialNoteAttachmentServiceTest method testDeleteMaterialNoteAttachmentByMaterialExtraId.

@Test
@Rollback(Const.ISROLLBACK)
public void testDeleteMaterialNoteAttachmentByMaterialExtraId() {
    MaterialNoteAttachment materialNoteAttachment = new MaterialNoteAttachment();
    materialNoteAttachment.setMaterialExtraId(2L);
    materialNoteAttachment.setAttachment("--");
    materialNoteAttachment.setAttachmentName("---");
    materialNoteAttachment.setDownload(1L);
    materialNoteAttachment.setAttachmentName("++++++");
    materialNoteAttachmentService.addMaterialNoteAttachment(materialNoteAttachment);
    // 根据主键MaterialExtraId获取
    Assert.assertTrue("获取失败", materialNoteAttachmentService.deleteMaterialNoteAttachmentByMaterialExtraId(2L) != null);
}
Also used : MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 3 with MaterialNoteAttachment

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

the class MaterialNoteAttachmentServiceTest method testDeleteMaterialNoteAttachmentById.

@Test
@Rollback(Const.ISROLLBACK)
public void testDeleteMaterialNoteAttachmentById() {
    MaterialNoteAttachment materialNoteAttachment = new MaterialNoteAttachment();
    materialNoteAttachment.setMaterialExtraId(2L);
    materialNoteAttachment.setAttachment("--");
    materialNoteAttachment.setAttachmentName("---");
    materialNoteAttachment.setDownload(1L);
    materialNoteAttachment.setAttachmentName("++++++");
    materialNoteAttachmentService.addMaterialNoteAttachment(materialNoteAttachment);
    // 根据主键id获取
    Assert.assertTrue("获取失败", materialNoteAttachmentService.deleteMaterialNoteAttachmentById(materialNoteAttachment.getId()) != null);
}
Also used : MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 4 with MaterialNoteAttachment

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

the class MaterialNoteAttachmentServiceTest method testAddMaterialNoteAttachment.

@Test
@Rollback(Const.ISROLLBACK)
public void testAddMaterialNoteAttachment() {
    MaterialNoteAttachment materialNoteAttachment = new MaterialNoteAttachment();
    materialNoteAttachment.setMaterialExtraId(2L);
    materialNoteAttachment.setAttachment("--");
    materialNoteAttachment.setAttachmentName("---");
    materialNoteAttachment.setDownload(1L);
    // 新增
    materialNoteAttachment = materialNoteAttachmentService.addMaterialNoteAttachment(materialNoteAttachment);
    Assert.assertTrue("新增失败", materialNoteAttachment.getId() != null);
}
Also used : MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 5 with MaterialNoteAttachment

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

the class MaterialExtraServiceImpl method updateMaterialExtraAndNoticeFile.

/**
 * <pre>
 * 功能描述:编辑通知详情
 * 使用示范:
 *
 * &#64;param materialExtraVO MaterialExtraVO
 * &#64;return Map<String, Object>集合
 * &#64;throws CheckedServiceException
 * </pre>
 */
@Override
public Integer updateMaterialExtraAndNoticeFile(MaterialExtraVO materialExtraVO) throws CheckedServiceException, IOException {
    // 教材ID
    Long materialId = materialExtraVO.getMaterialId();
    if (ObjectUtil.isNull(materialId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材ID为空");
    }
    String materialName = materialExtraVO.getMaterialName();
    if (StringUtil.isEmpty(materialName)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材名称为空");
    }
    String content = materialExtraVO.getContent();
    if (StringUtil.isEmpty(content)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材通知为空");
    }
    // MongoDB 内容插入
    Content contentObj = contentService.add(new Content(content));
    if (ObjectUtil.isNull(contentObj)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.OBJECT_NOT_FOUND, "教材通知保存失败");
    }
    Material material = materialService.getMaterialById(materialId);
    if (StringUtil.isEmpty(materialExtraVO.getContent())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材通知内容为空");
    }
    // 内容ID
    Long cmsContentId = null;
    CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
    if (ObjectUtil.notNull(cmsContent)) {
        cmsContentId = cmsContent.getId();
        String mid = null;
        if (StringUtil.notEmpty(cmsContent.getMid())) {
            mid = cmsContent.getMid();
        }
        // 存在就更新
        Integer count = cmsContentService.updateCmsContent(new CmsContent(cmsContent.getId(), contentObj.getId(), DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime())));
        if (count > 0) {
            // 删除之前教材通知内容
            contentService.delete(mid);
        }
    } else {
        // 保存CMSContent内容
        CmsContent cmsContentObj = cmsContentService.addCmsContent(new CmsContent(0L, "0", contentObj.getId(), materialName, Const.CMS_AUTHOR_TYPE_0, false, true, material.getFounderId(), DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()), materialId, Const.CMS_CATEGORY_ID_3, Const.TRUE, "DEFAULT"));
        if (ObjectUtil.isNull(cmsContentObj.getId())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "创建教材通知公告失败");
        }
        cmsContentId = cmsContentObj.getId();
    }
    // 先删除教材通知附件
    List<CmsExtra> cmsExtras = cmsExtraService.getCmsExtraByContentId(cmsContentId);
    if (CollectionUtil.isNotEmpty(cmsExtras)) {
        List<Long> cmsExtraIds = new ArrayList<Long>();
        for (CmsExtra cmsExtra : cmsExtras) {
            cmsExtraIds.add(cmsExtra.getId());
        }
        cmsExtraService.deleteCmsExtraByIds(cmsExtraIds);
    }
    // 教材通知附件
    List<MaterialNoticeAttachment> materialNoticeAttachments = null;
    // 教材备注附件
    List<MaterialNoteAttachment> materialNoteAttachments = null;
    // 教材通知备注
    MaterialExtra materialExtra = this.getMaterialExtraByMaterialId(materialId);
    if (ObjectUtil.notNull(materialExtra)) {
        Long materialExtraId = materialExtra.getId();
        if (ObjectUtil.notNull(materialExtraId)) {
            // 教材通知附件
            materialNoticeAttachments = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialExtraId);
            // 教材备注附件
            materialNoteAttachments = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtraId);
            // 教材通知附件保存到CMS附件表中
            for (MaterialNoticeAttachment mna : materialNoticeAttachments) {
                cmsExtraService.addCmsExtra(new CmsExtra(cmsContentId, mna.getAttachment(), mna.getAttachmentName(), 0L));
            }
            for (MaterialNoteAttachment ma : materialNoteAttachments) {
                cmsExtraService.addCmsExtra(new CmsExtra(cmsContentId, ma.getAttachment(), ma.getAttachmentName(), 0L));
            }
        }
    }
    // 教材通知附件
    // String[] noticeFiles = materialExtraVO.getNoticeFiles();
    // if (ArrayUtil.isNotEmpty(noticeFiles)) {
    // this.saveFileToMongoDB(noticeFiles, materialExtraId, NOTICE);
    // }
    // 教材通知附件MongoDB对应ID
    String[] noticeAttachments = materialExtraVO.getNoticeAttachments();
    if (ArrayUtil.isNotEmpty(noticeAttachments)) {
        // 删除MaterialNoticeAttachment 表
        materialNoticeAttachmentService.deleteMaterialNoticeAttachmentByAttachments(noticeAttachments);
        // 删除MongoDB对应的文件
        for (int i = 0; i < noticeAttachments.length; i++) {
            fileService.remove(noticeAttachments[i]);
        }
    }
    // 教材备注附件
    // String[] noteFiles = materialExtraVO.getNoteFiles();
    // if (ArrayUtil.isNotEmpty(noteFiles)) {
    // this.saveFileToMongoDB(noteFiles, materialExtraId, NOTE);
    // }
    // 教材备注附件MongoDB对应ID
    String[] noteAttachments = materialExtraVO.getNoteAttachments();
    if (ArrayUtil.isNotEmpty(noteAttachments)) {
        // 删除MaterialNoteAttachment 表
        materialNoteAttachmentService.deleteMaterialNoteAttachmentByAttachments(noteAttachments);
        // 删除MongoDB对应的文件
        for (int i = 0; i < noteAttachments.length; i++) {
            fileService.remove(noteAttachments[i]);
        }
    }
    return 1;
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) CmsExtra(com.bc.pmpheep.back.po.CmsExtra) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) MaterialExtra(com.bc.pmpheep.back.po.MaterialExtra)

Aggregations

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