Search in sources :

Example 1 with MaterialType

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

the class MigrationStageFour method materialType.

protected void materialType() {
    String tableName = "sys_booktypes";
    // 增加new_pk字段
    JdbcHelper.addColumn(tableName);
    // 取得该表中所有数据
    List<Map<String, Object>> maps = JdbcHelper.queryForList(tableName);
    List<Map<String, Object>> excel = new LinkedList<>();
    Map<String, Object> result = new LinkedHashMap<>();
    int count = 0;
    // 统计正常数据的数量
    int correctCount = 0;
    // 判断该数据是否有相应异常状况的标识
    int[] state = { 0, 0, 0 };
    StringBuilder reason = new StringBuilder();
    StringBuilder dealWith = new StringBuilder();
    // 模块名称
    excptionList.add(new Object[] { "教材类别" });
    // 模块标题
    excptionList.add(new Object[] { "类别名称", "问题", "原因分析", "处理方式" });
    int excptionListOldSize = excptionList.size();
    // 插入除parentid和path的字段;
    for (Map<String, Object> map : maps) {
        /*
			 * 因此表有主要级字段和次要级字段,次要级字段插入新表同时也需导出Excel,因此异常信息不止一条, 用StringBulider进行拼接成最终的异常信息
			 */
        StringBuilder exception = new StringBuilder();
        BigDecimal bookTypesID = (BigDecimal) map.get("BookTypesID");
        BigDecimal parentTypesId = (BigDecimal) map.get("ParentTypesID");
        String typeName = (String) map.get("TypeName");
        if (StringUtil.isEmpty(typeName)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("类型名称为空。"));
            excptionList.add(new Object[] { "", "类型名称为空", "导入的数据错误", "不导入该条数据" });
            excel.add(map);
            if (state[0] == 0) {
                reason.append("找不到教材类型名称。");
                dealWith.append("放弃迁移。");
                state[0] = 1;
            }
            continue;
        }
        /*
			 * 原数据库系统表的数据是按照父-子顺序排列的,因此不许循环可以直接调用获取父节点和path的方法
			 */
        Long parentId = 0L;
        if (parentTypesId.intValue() != 0) {
            parentId = JdbcHelper.getPrimaryKey(tableName, "BookTypesID", parentTypesId);
        }
        String path = JdbcHelper.getPath(tableName, "BookTypesID", "ParentTypesID", parentTypesId);
        Integer sort = (Integer) map.get("Sortno");
        if (ObjectUtil.notNull(sort) && sort < 0) {
            map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("排序为负数。"));
            excptionList.add(new Object[] { typeName, "排序不正确", "导入的数据错误", "设置为'999'导入新库表" });
            sort = 999;
            excel.add(map);
            if (state[1] == 0) {
                reason.append("排序码为负数。");
                dealWith.append("设为默认值999迁入数据库。");
                state[1] = 1;
            }
        }
        String note = (String) map.get("Remark");
        // 书籍分类备注信息比较重要,虽然有默认值,但仍认为是次要级字段
        if (StringUtil.isEmpty(note)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("备注为空。"));
            excptionList.add(new Object[] { typeName, "备注为空", "导入的数据错误", "设置为和类型名称一样导入新库表" });
            note = typeName;
            excel.add(map);
            if (state[2] == 0) {
                reason.append("无备注信息。");
                dealWith.append("备注可以为空,但教材分类备注信息较重要,因此记录下来,照常迁入数据库。");
                state[2] = 1;
            }
        }
        MaterialType materialType = new MaterialType();
        materialType.setParentId(parentId);
        materialType.setPath(path);
        materialType.setTypeName(typeName);
        materialType.setSort(sort);
        materialType.setNote(note);
        materialType = materialTypeService.addMaterialType(materialType);
        count++;
        long pk = materialType.getId();
        // 更新旧表中new_pk字段
        JdbcHelper.updateNewPrimaryKey(tableName, pk, "BookTypesID", bookTypesID);
        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_type");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != maps.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "material_type");
        result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "教材类型表");
        result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, maps.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, maps.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("'{}'表迁移完成,异常条目数量:{}", tableName, excel.size());
    logger.info("原数据库中共有{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "" + tableName + " 表迁移完成" + count + "/" + maps.size());
    SQLParameters.STATISTICS.add(msg);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) LinkedList(java.util.LinkedList) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) MaterialType(com.bc.pmpheep.back.po.MaterialType) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with MaterialType

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

the class MaterialServiceImpl method getMaterialVO.

@Override
public MaterialVO getMaterialVO(Long id) throws CheckedServiceException {
    if (null == id) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材主键为空");
    }
    // 教材主要信息
    Material material = materialDao.getMaterialById(id);
    // 教材主任
    PmphUser director = pmphUserService.get(material.getDirector());
    // 教材类型字符串
    MaterialType materialType = materialTypeService.getMaterialTypeById(material.getMaterialType());
    String mtype = "[]";
    if (null != materialType) {
        mtype = "[" + materialType.getPath().replace("-", ",") + "," + material.getMaterialType() + "]";
        // 去掉 0
        mtype = mtype.replace("[0,", "[").replace("[0", "[");
    }
    // 教材通知备注表
    MaterialExtra materialExtra = materialExtraService.getMaterialExtraByMaterialId(id);
    Gson gson = new Gson();
    // 联系人
    List<MaterialContact> materialContactList = materialContactService.listMaterialContactByMaterialId(id);
    String materialContacts = gson.toJson(materialContactList);
    // 扩展项
    List<MaterialExtension> materialExtensionList = materialExtensionService.getMaterialExtensionByMaterialId(id);
    String materialExtensions = gson.toJson(materialExtensionList);
    // 项目编辑
    List<MaterialProjectEditorVO> materialProjectEditorVOList = materialProjectEditorService.listMaterialProjectEditors(id);
    String materialProjectEditorVOs = gson.toJson(materialProjectEditorVOList);
    // 通知附件信息
    List<MaterialNoticeAttachment> materialNoticeAttachmentList = new ArrayList<MaterialNoticeAttachment>(5);
    if (null != materialExtra) {
        materialNoticeAttachmentList = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialExtra.getId());
    }
    String materialNoticeAttachments = gson.toJson(materialNoticeAttachmentList);
    // 通知备注附件信息
    List<MaterialNoteAttachment> materialNoteAttachmentList = new ArrayList<MaterialNoteAttachment>(5);
    if (null != materialExtra) {
        materialNoteAttachmentList = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtra.getId());
    }
    String materialNoteAttachments = gson.toJson(materialNoteAttachmentList);
    return new MaterialVO(material, director == null ? null : director.getRealname(), mtype, materialExtra, materialContacts, materialExtensions, materialProjectEditorVOs, materialNoticeAttachments, materialNoteAttachments, StringUtil.tentToBinary(material.getPlanPermission()), StringUtil.tentToBinary(material.getProjectPermission()));
}
Also used : MaterialVO(com.bc.pmpheep.back.vo.MaterialVO) MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) PmphUser(com.bc.pmpheep.back.po.PmphUser) MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) MaterialContact(com.bc.pmpheep.back.po.MaterialContact) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) MaterialExtension(com.bc.pmpheep.back.po.MaterialExtension) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) MaterialProjectEditorVO(com.bc.pmpheep.back.vo.MaterialProjectEditorVO) MaterialType(com.bc.pmpheep.back.po.MaterialType) MaterialExtra(com.bc.pmpheep.back.po.MaterialExtra)

Aggregations

MaterialType (com.bc.pmpheep.back.po.MaterialType)2 Material (com.bc.pmpheep.back.po.Material)1 MaterialContact (com.bc.pmpheep.back.po.MaterialContact)1 MaterialExtension (com.bc.pmpheep.back.po.MaterialExtension)1 MaterialExtra (com.bc.pmpheep.back.po.MaterialExtra)1 MaterialNoteAttachment (com.bc.pmpheep.back.po.MaterialNoteAttachment)1 MaterialNoticeAttachment (com.bc.pmpheep.back.po.MaterialNoticeAttachment)1 PmphUser (com.bc.pmpheep.back.po.PmphUser)1 MaterialProjectEditorVO (com.bc.pmpheep.back.vo.MaterialProjectEditorVO)1 MaterialVO (com.bc.pmpheep.back.vo.MaterialVO)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1