Search in sources :

Example 1 with MaterialExtension

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

the class ExcelHelper method generateDeclarationEtcBOHeader.

private Sheet generateDeclarationEtcBOHeader(List<MaterialExtension> extensions, Sheet sheet) {
    Field[] fields = DeclarationEtcBO.class.getDeclaredFields();
    Row r1 = sheet.createRow(0);
    Row r2 = sheet.createRow(1);
    Cell numcell = r1.createCell(0);
    numcell.setCellValue("序号");
    CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
    sheet.addMergedRegion(region);
    int count = 1;
    for (Field field : fields) {
        // 可访问性设置
        field.setAccessible(true);
        /* 仅查找与ExcelHeader注解匹配的表头 */
        if (field.isAnnotationPresent(ExcelHeader.class)) {
            ExcelHeader excelHeader = (ExcelHeader) field.getAnnotation(ExcelHeader.class);
            String headerName = excelHeader.header();
            if (StringUtil.notEmpty(headerName)) {
                switch(headerName) {
                    case "学习经历":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 3);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("起止时间");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("学校名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("所学专业");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("学历");
                            sheet.setColumnWidth(count, 3 * 512);
                            count++;
                            break;
                        }
                    case "工作经历":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 2);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("起止时间");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("工作单位");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("职位");
                            sheet.setColumnWidth(count, 3 * 512);
                            count++;
                            break;
                        }
                    case "教学经历":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 2);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("起止时间");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("学校名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("教学科目");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            break;
                        }
                    case "个人成就":
                        {
                            Cell r1cell = r1.createCell(count);
                            r2.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 1, count, count);
                            sheet.setColumnWidth(count, 15 * 512);
                            sheet.addMergedRegion(region);
                            count++;
                            break;
                        }
                    case "学术兼职":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 2);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("兼职学术组织");
                            sheet.setColumnWidth(count, 7 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("级别");
                            sheet.setColumnWidth(count, 3 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("职务");
                            sheet.setColumnWidth(count, 3 * 512);
                            count++;
                            break;
                        }
                    case "本套上版教材参编情况":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 4);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("教材名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("编写职务");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("是否数字编辑");
                            sheet.setColumnWidth(count, 7 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("出版单位");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("出版时间");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            break;
                        }
                    case "精品课程建设情况":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 2);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("课程名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("课程级别");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("全年课时");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            break;
                        }
                    case "主编国家级规划教材情况":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 2);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("教材名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("标准书号");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("教材级别");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            break;
                        }
                    case "人卫社教材编写情况":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 5);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("教材名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("级别");
                            sheet.setColumnWidth(count, 3 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("编写职务");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("是否数字编辑");
                            sheet.setColumnWidth(count, 7 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("出版时间");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("标准书号");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            break;
                        }
                    case "其他社教材编写情况":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 6);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("教材名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("级别");
                            sheet.setColumnWidth(count, 3 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("编写职务");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("是否数字编辑");
                            sheet.setColumnWidth(count, 7 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("出版社");
                            sheet.setColumnWidth(count, 4 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("出版时间");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("标准书号");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            break;
                        }
                    case "参加人卫慕课、数字教材编写情况":
                        {
                            Cell r1cell = r1.createCell(count);
                            r2.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 1, count, count);
                            sheet.setColumnWidth(count, 15 * 512);
                            sheet.addMergedRegion(region);
                            count++;
                            break;
                        }
                    case "科研情况":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 2);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("课题名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("审批单位");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("获奖情况");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            break;
                        }
                    case "学术专著":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 4);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("专著名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("专著发表日期");
                            sheet.setColumnWidth(count, 7 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("出版方式");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("出版单位");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("出版时间");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            break;
                        }
                    case "出版行业获奖情况":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 2);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("奖项名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("评奖单位");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("获奖时间");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            break;
                        }
                    case "SCI论文投稿及影响因子情况":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 3);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("论文名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("期刊名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("期刊SCI影响因子");
                            sheet.setColumnWidth(count, 9 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("发表时间");
                            sheet.setColumnWidth(count, 3 * 512);
                            count++;
                            break;
                        }
                    case "临床医学获奖情况":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 2);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("奖项名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("奖项级别");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("获奖时间");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            break;
                        }
                    case "学术荣誉授予情况":
                        {
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 0, count, count + 2);
                            sheet.addMergedRegion(region);
                            Cell r2cell = r2.createCell(count);
                            r2cell.setCellValue("荣誉名称");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("荣誉级别");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            r2cell = r2.createCell(count);
                            r2cell.setCellValue("授予时间");
                            sheet.setColumnWidth(count, 5 * 512);
                            count++;
                            break;
                        }
                    case "编写内容意向":
                        {
                            Cell r1cell = r1.createCell(count);
                            r2.createCell(count);
                            r1cell.setCellValue(headerName);
                            region = new CellRangeAddress(0, 1, count, count);
                            sheet.setColumnWidth(count, 15 * 512);
                            sheet.addMergedRegion(region);
                            count++;
                            break;
                        }
                    case "作家扩展项":
                        {
                            if (extensions == null || extensions.isEmpty()) {
                                break;
                            }
                            Cell r1cell = r1.createCell(count);
                            r1cell.setCellValue(headerName);
                            if (extensions.size() > 1) {
                                region = new CellRangeAddress(0, 0, count, count + extensions.size() - 1);
                                sheet.addMergedRegion(region);
                            }
                            for (MaterialExtension extension : extensions) {
                                Cell cell = r2.createCell(count);
                                String extensionName = extension.getExtensionName() == null ? "" : extension.getExtensionName();
                                cell.setCellValue(extensionName);
                                int length = extension.getExtensionName().length() > 10 ? 10 : extension.getExtensionName().length();
                                sheet.setColumnWidth(count, length * 512);
                                count++;
                            }
                            // count++;
                            break;
                        }
                    default:
                        Cell cell = r1.createCell(count);
                        r2.createCell(count);
                        // 设置基本列宽度
                        sheet.setColumnWidth(count, (headerName.length() + 1) * 512);
                        cell.setCellValue(headerName);
                        region = new CellRangeAddress(0, 1, count, count);
                        sheet.addMergedRegion(region);
                        count++;
                        break;
                }
            }
        }
    }
    return sheet;
}
Also used : Field(java.lang.reflect.Field) MaterialExtension(com.bc.pmpheep.back.po.MaterialExtension) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Cell(org.apache.poi.ss.usermodel.Cell) ExcelHeader(com.bc.pmpheep.annotation.ExcelHeader)

Example 2 with MaterialExtension

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

the class WordHelper method fromDeclarationEtcBOList.

/**
 * 从一个或多个专家信息对象中读取数据,转化成若干Word文档
 *
 * @param materialName
 *            教材名称
 * @param list
 *            DeclarationEtcBO实例集合
 * @param filter
 *            使用可填项的二进制选中
 * @param extensions
 *            教材扩展项
 * @return 包含文档名称和Word格式文档的键值对
 * @throws CheckedServiceException
 *             已检查的异常
 */
public HashMap<String, XWPFDocument> fromDeclarationEtcBOList(String materialName, List<DeclarationEtcBO> list, String filter, List<MaterialExtension> extensions) throws CheckedServiceException {
    InputStream is;
    XWPFDocument document;
    String path = this.getClass().getClassLoader().getResource("ResumeTemplate.docx").getPath();
    HashMap<String, XWPFDocument> map = new HashMap<>(list.size());
    for (DeclarationEtcBO bo : list) {
        try {
            is = new FileInputStream(path);
            document = new XWPFDocument(is);
        } catch (IOException ex) {
            logger.error("读取Word模板文件'ResumeTemplate.docx'时出现错误:{}", ex.getMessage());
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.FILE_CREATION_FAILED, "未找到模板文件");
        }
        if (StringUtil.notEmpty(materialName)) {
            List<XWPFRun> runs = document.getParagraphs().get(0).getRuns();
            runs.get(0).setText(materialName.concat("申报表"), 0);
        }
        List<XWPFParagraph> xwpfParagraphs = document.getParagraphs();
        List<XWPFTable> tables = document.getTables();
        int i = 21;
        XWPFTable old = tables.get(19);
        for (MaterialExtension extension : extensions) {
            XmlCursor cursor = xwpfParagraphs.get(i).getCTP().newCursor();
            // ---这个是关键
            XWPFParagraph xwpfParagraph = document.insertNewParagraph(cursor);
            CTPPr pPPr = xwpfParagraph.getCTP().getPPr() != null ? xwpfParagraph.getCTP().getPPr() : xwpfParagraph.getCTP().addNewPPr();
            CTSpacing pSpacing = pPPr.getSpacing() != null ? pPPr.getSpacing() : pPPr.addNewSpacing();
            pSpacing.setLine(BigInteger.valueOf(360L));
            pSpacing.setBeforeLines(BigInteger.valueOf(100L));
            XWPFRun xwpfRun = xwpfParagraph.createRun();
            xwpfRun.setText(extension.getExtensionName());
            xwpfRun.setFontSize(12);
            xwpfRun.setFontFamily("宋体");
            xwpfRun.setBold(true);
            /* 以下填充扩展项内容 */
            cursor = xwpfParagraphs.get(i + 1).getCTP().newCursor();
            XWPFTable t = document.insertNewTbl(cursor);
            XWPFTableRow row = t.getRow(0);
            XWPFTableCell cell = row.getCell(0);
            CTTc cttc = cell.getCTTc();
            CTTcPr tcpr = cttc.addNewTcPr();
            CTTblWidth tcw = tcpr.addNewTcW();
            tcw.setType(old.getRow(0).getCell(0).getCTTc().getTcPr().getTcW().getType());
            tcw.setW(old.getRow(0).getCell(0).getCTTc().getTcPr().getTcW().getW());
            if (old.getRow(0).getCell(0).getCTTc().getTcPr().getGridSpan() != null) {
                tcpr.setGridSpan(old.getRow(0).getCell(0).getCTTc().getTcPr().getGridSpan());
            }
            if (!bo.getDecExtensionVOs().isEmpty()) {
                for (DecExtensionVO decExtensionVO : bo.getDecExtensionVOs()) {
                    if (extension.getId().equals(decExtensionVO.getExtensionId())) {
                        String content = decExtensionVO.getContent();
                        if (StringUtil.notEmpty(content)) {
                            XWPFRun run = cell.getParagraphs().get(0).createRun();
                            run.setText(content);
                        }
                        break;
                    }
                }
            }
            i++;
        }
        /* 申报单位 */
        String chosenOrgName = bo.getChosenOrgName();
        if (StringUtil.notEmpty(chosenOrgName)) {
            xwpfParagraphs.get(i).createRun().setText(chosenOrgName);
        }
        String filename = generateFileName(bo);
        fillDeclarationPosition(tables.get(0), bo);
        fillDeclarationData(tables.get(1), bo);
        fillDecEduExpData(tables.get(2), bo.getDecEduExps());
        fillDecWorkExpData(tables.get(3), bo.getDecWorkExps());
        fillDecTeachExpData(tables.get(4), bo.getDecTeachExps());
        fillDecAchievementData(tables.get(5), bo.getDecAchievement());
        fillDecAcadeData(tables.get(6), bo.getDecAcades());
        fillDecLastPositionData(tables.get(7), bo.getDecLastPositions());
        fillDecNationalPlanData(tables.get(8), bo.getDecNationalPlans());
        fillDecTextbookPmphData(tables.get(9), bo.getDecTextbookPmphs());
        fillDecTextbookData(tables.get(10), bo.getDecTextbooks());
        fillDecMoocDigitalData(tables.get(11), bo.getDecMoocDigital());
        fillDecCourseConstructionData(tables.get(12), bo.getDecCourseConstructions());
        fillDecResearchData(tables.get(13), bo.getDecResearchs());
        fillDecMonographData(tables.get(14), bo.getDecMonographs());
        fillDecPublishRewardData(tables.get(15), bo.getPublishRewards());
        fillDecSciData(tables.get(16), bo.getDecScis());
        fillDecClinicalRewardData(tables.get(17), bo.getDecClinicalRewards());
        fillDecAcadeRewardData(tables.get(18), bo.getDecAcadeRewards());
        fillDecIntentionData(tables.get(19), bo.getDecIntention());
        map.put(filename, removeEmptyTables(document, filter));
        map.put(filename, document);
    }
    return map;
}
Also used : CTTblWidth(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth) XWPFTableCell(org.apache.poi.xwpf.usermodel.XWPFTableCell) HashMap(java.util.HashMap) CTSpacing(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing) DeclarationEtcBO(com.bc.pmpheep.back.bo.DeclarationEtcBO) XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument) CTTc(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc) XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XWPFTable(org.apache.poi.xwpf.usermodel.XWPFTable) DecExtensionVO(com.bc.pmpheep.back.vo.DecExtensionVO) MaterialExtension(com.bc.pmpheep.back.po.MaterialExtension) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) XmlCursor(org.apache.xmlbeans.XmlCursor) XWPFTableRow(org.apache.poi.xwpf.usermodel.XWPFTableRow) XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTTcPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr)

Example 3 with MaterialExtension

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

the class MigrationStageFour method materialExtension.

protected void materialExtension() {
    String tableName = "teach_material_extend";
    String sql = "select " + "a.expendid, " + "b.new_pk materid, " + "a.expendname, " + "a.isfill from  " + "teach_material_extend a  " + "LEFT JOIN teach_material b on b.materid=a.materid  " + "where b.materid is not null ";
    // 增加new_pk字段
    JdbcHelper.addColumn(tableName);
    List<Map<String, Object>> maps = 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 };
    StringBuilder reason = new StringBuilder();
    StringBuilder dealWith = new StringBuilder();
    // 模块名称
    excptionList.add(new Object[] { "教材扩展项" });
    // 模块标题
    excptionList.add(new Object[] { "教材名称", "扩展项名称", "问题", "原因分析", "处理方式" });
    int excptionListOldSize = excptionList.size();
    for (Map<String, Object> materialExtension : maps) {
        String oldExpendid = (String) materialExtension.get("expendid");
        StringBuilder exception = new StringBuilder();
        Long materid = (Long) materialExtension.get("materid");
        String matername = (materid == null ? "" : materialService.getMaterialNameById(materid));
        if (ObjectUtil.isNull(materid)) {
            materialExtension.put(SQLParameters.EXCEL_EX_HEADER, exception.append("教材id为空。"));
            excel.add(materialExtension);
            excptionList.add(new Object[] { matername, (String) materialExtension.get("expendname"), "找不到对应教材", "新建的教材被删除", "不导入该条数据" });
            if (state[0] == 0) {
                reason.append("找不到教材的唯一标识。");
                dealWith.append("放弃迁移。");
                state[0] = 1;
            }
            continue;
        }
        String expendname = (String) materialExtension.get("expendname");
        if (StringUtil.isEmpty(expendname)) {
            materialExtension.put(SQLParameters.EXCEL_EX_HEADER, exception.append("扩展名称为空。设定默认值\"-\""));
            excel.add(materialExtension);
            expendname = "-";
            excptionList.add(new Object[] { matername, expendname, "扩展项名称为空", "专家平台为空", "设置为'-'导入新库表" });
            if (state[1] == 0) {
                reason.append("找不到教材的扩展项名称。");
                dealWith.append("设为默认值迁入数据库。");
                state[1] = 1;
            }
        }
        MaterialExtension newMaterialExtension = new MaterialExtension();
        newMaterialExtension.setMaterialId(materid);
        newMaterialExtension.setExtensionName(expendname);
        newMaterialExtension.setIsRequired("1".equals(String.valueOf(materialExtension.get("isfill"))));
        newMaterialExtension = materialExtensionService.addMaterialExtension(newMaterialExtension);
        count++;
        long pk = newMaterialExtension.getId();
        // 更新旧表中new_pk字段
        JdbcHelper.updateNewPrimaryKey(tableName, pk, "expendid", oldExpendid);
        if (null == materialExtension.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_extension");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != maps.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "material_extension");
        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) MaterialExtension(com.bc.pmpheep.back.po.MaterialExtension) 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 4 with MaterialExtension

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

the class MaterialServiceImpl method addOrUpdateMaterial.

@Override
public Long addOrUpdateMaterial(HttpServletRequest request, MaterialVO materialVO, // MultipartFile[] noteFiles,
boolean isUpdate) throws CheckedServiceException, IOException {
    if (null == request.getSession(false)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "会话过期");
    }
    // 获取当前用户
    String sessionId = CookiesUtil.getSessionId(request);
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == pmphUser) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
    }
    Material material = materialVO.getMaterial();
    // 如果是更新教材,判断主键
    if (isUpdate && (null == material.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材更新时主键为空");
    }
    // 教材名称的验证
    if (StringUtil.isEmpty(material.getMaterialName())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材名称为空");
    }
    if (material.getMaterialName().length() > 50) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "教材名称过长");
    }
    // 教材轮次验证
    if (null == material.getMaterialRound()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材轮次为空");
    }
    // 显示报名截止时间
    if (null == material.getDeadline()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "显示报名截止时间为空");
    }
    // 如果是新建教材,显示报名截止时间必须大于当前时间
    if (!isUpdate && material.getDeadline().getTime() <= new Date().getTime()) {
    // throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
    // CheckedExceptionResult.ILLEGAL_PARAM,
    // "显示报名截止时间必须大于当前时间");
    }
    // 实际报名截止日期
    if (null == material.getActualDeadline()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "实际报名截止日期为空");
    }
    // 如果是新建教材,实际报名截止日期必须大于当前时间
    if (!isUpdate && material.getActualDeadline().getTime() <= new Date().getTime()) {
    // throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
    // CheckedExceptionResult.ILLEGAL_PARAM,
    // "实际报名截止日期必须大于当前时间");
    }
    // 实际报名截止日期和显示报名截止时间比较
    if (material.getActualDeadline().getTime() < material.getDeadline().getTime()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "实际报名截止日期不能小于显示报名截止时间");
    }
    // 年龄计算截止日期
    if (null == material.getAgeDeadline()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "年龄计算截止日期为空");
    }
    // 邮寄地址验证
    if (StringUtil.isEmpty(material.getMailAddress())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "邮寄地址为空");
    }
    if (material.getMailAddress().length() > 100) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "邮寄地址过长");
    }
    // 教材类型验证
    String materialType = materialVO.getMaterialType();
    if (StringUtil.isEmpty(materialType) || "[]".equals(materialType.replace(" ", "")) || "[NaN]".equals(materialType.replace(" ", ""))) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材类型为空");
    }
    if (null == material.getDirector()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材主任为空");
    }
    // 教材通知备注内容验证
    MaterialExtra materialExtra = materialVO.getMaterialExtra();
    if (StringUtil.isEmpty(materialExtra.getNotice())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材通知内容为空");
    }
    if (materialExtra.getNotice().length() > 2000) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "教材通知内容过长");
    }
    // }
    if ("null".equals(materialExtra.getNote()) || "[]".equals(materialExtra.getNote())) {
        materialExtra.setNote("");
    }
    if (null != materialExtra.getNote() && materialExtra.getNote().length() > 2000) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "教材备注内容过长");
    }
    Gson gson = new Gson();
    // 获取主任
    PmphUser director = pmphUserService.get(material.getDirector());
    if (null == director) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "找不到对应的主任");
    } else if (null == director.getDepartmentId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "主任对应的机构为空");
    }
    // //给主任添加角色
    // String roleName="主任";//通过roleName查询roleid
    // List<PmphRole> pmphRoles=pmphRoleService.getList(roleName);
    // if (ObjectUtil.isNull(material.getDirector()) ||
    // ObjectUtil.isNull(pmphRoles.get(0).getId())) {
    // throw new CheckedServiceException(CheckedExceptionBusiness.ROLE_MANAGEMENT,
    // CheckedExceptionResult.NULL_PARAM, "角色ID或主任ID为空时禁止新增");
    // }
    // //先查看该主任是否已有主任角色 没有则新加
    // List<PmphUserRole>
    // pmphUserRoles=pmphRoleService.getUserRoleList(material.getDirector(),pmphRoles.get(0).getId());
    // if(ObjectUtil.isNull(pmphUserRoles)&&pmphUserRoles.size() == 0){
    // pmphRoleService.addUserRole(material.getDirector(),
    // pmphRoles.get(0).getId());
    // }
    // 教材所属部门
    material.setDepartmentId(director.getDepartmentId());
    // 修改人
    material.setMenderId(pmphUser.getId());
    // 教材类型
    List<Long> materialTypeList = gson.fromJson(materialType, new TypeToken<ArrayList<Long>>() {
    }.getType());
    material.setMaterialType(materialTypeList.get(materialTypeList.size() - 1));
    // 设置权限
    material.setPlanPermission(Integer.valueOf(materialVO.getCehuaPowers(), 2));
    material.setProjectPermission(Integer.valueOf(materialVO.getProjectEditorPowers(), 2));
    // 保存或者更新教材
    if (isUpdate) {
        materialDao.updateMaterial(material);
    } else {
        // 创建人
        material.setFounderId(pmphUser.getId());
        materialDao.addMaterial(material);
    }
    Long materialId = material.getId();
    // 扩展项转换
    List<MaterialExtension> oldMaterialExtensionlist = materialExtensionService.getMaterialExtensionByMaterialId(materialId);
    String newMaterialExtensionIds = ",";
    String materialExtensions = materialVO.getMaterialExtensions();
    if (!StringUtil.isEmpty(materialExtensions)) {
        List<MaterialExtension> materialExtensionlist = gson.fromJson(materialExtensions, new TypeToken<ArrayList<MaterialExtension>>() {
        }.getType());
        for (MaterialExtension materialExtension : materialExtensionlist) {
            if (null == materialExtension) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "扩展项对象为空");
            }
            if (StringUtil.isEmpty(materialExtension.getExtensionName())) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "扩展项名称为空");
            }
            if (materialExtension.getExtensionName().length() > 100) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "扩展项名称太长");
            }
            materialExtension.setMaterialId(materialId);
            if (null == materialExtension.getId()) {
                // 保存或者修改扩展项
                materialExtensionService.addMaterialExtension(materialExtension);
            } else {
                materialExtensionService.updateMaterialExtension(materialExtension);
            }
            newMaterialExtensionIds += materialExtension.getId() + ",";
        }
    }
    for (MaterialExtension oldMaterialExtension : oldMaterialExtensionlist) {
        // 删除删除的MaterialExtension
        if (!newMaterialExtensionIds.contains("," + oldMaterialExtension.getId() + ",")) {
            // 不包含
            // 删除扩展项
            materialExtensionService.deleteMaterialExtensionById(oldMaterialExtension.getId());
            // 删除扩展值
            decExtensionService.deleteDecExtensionByExtensionId(oldMaterialExtension.getId());
        }
    }
    // 联系人转换
    String materialContacts = materialVO.getMaterialContacts();
    // 删除已经有的联系人
    materialContactService.deleteMaterialContactsByMaterialId(materialId);
    if (StringUtil.isEmpty(materialContacts)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "教材联系人参数有误");
    }
    List<MaterialContact> materialContactlist = gson.fromJson(materialContacts, new TypeToken<ArrayList<MaterialContact>>() {
    }.getType());
    if (null == materialContactlist || materialContactlist.size() == 0) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材联系人为空");
    }
    for (MaterialContact materialContact : materialContactlist) {
        if (null == materialContact) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材联系人对象为空");
        }
        if (null == materialContact.getContactUserId()) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系人为空");
        }
        if (StringUtil.isEmpty(materialContact.getContactUserName())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系人姓名为空");
        }
        if (materialContact.getContactUserName().length() > 20) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系人姓名太长");
        }
        if (StringUtil.isEmpty(materialContact.getContactPhone())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系电话为空");
        }
        if (materialContact.getContactPhone().length() > 25) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系电话太长");
        }
        if (StringUtil.isEmpty(materialContact.getContactEmail())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系邮箱为空");
        }
        if (materialContact.getContactEmail().length() > 40) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系邮箱太长");
        }
        if (null == materialContact.getSort()) {
            materialContact.setSort(999);
        }
        materialContact.setMaterialId(materialId);
        // 保存联系人
        materialContactService.addMaterialContact(materialContact);
    }
    // 项目编辑转换
    // 先删除该教材下的项目编辑
    materialProjectEditorService.deleteMaterialProjectEditorByMaterialId(materialId);
    String materialProjectEditors = materialVO.getMaterialProjectEditors();
    if (StringUtil.isEmpty(materialProjectEditors)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "教材项目编辑参数有误");
    }
    List<MaterialProjectEditorVO> materialProjectEditorVOlist = gson.fromJson(materialProjectEditors, new TypeToken<ArrayList<MaterialProjectEditorVO>>() {
    }.getType());
    for (MaterialProjectEditorVO materialProjectEditorVO : materialProjectEditorVOlist) {
        if (null == materialProjectEditorVO || null == materialProjectEditorVO.getEditorId()) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "项目编辑为空");
        }
        MaterialProjectEditor materialProjectEditor = new MaterialProjectEditor();
        materialProjectEditor.setEditorId(materialProjectEditorVO.getEditorId());
        materialProjectEditor.setMaterialId(materialId);
        // 保存项目编辑
        materialProjectEditorService.addMaterialProjectEditor(materialProjectEditor);
    // // 项目编辑绑定角色
    // String rolename="项目编辑";//通过roleName查询roleid
    // List<PmphRole> pmphRoleList=pmphRoleService.getList(rolename);
    // if (ObjectUtil.isNull(materialId) ||
    // ObjectUtil.isNull(pmphRoleList.get(0).getId())) {
    // throw new CheckedServiceException(CheckedExceptionBusiness.ROLE_MANAGEMENT,
    // CheckedExceptionResult.NULL_PARAM, "角色ID或项目编辑ID为空时禁止新增");
    // }
    // //判断该用户是否有项目编辑角色 若没有则新加
    // List<PmphUserRole> pmphUserRoles2=pmphRoleService.getUserRoleList(materialId,
    // pmphRoleList.get(0).getId());
    // if(ObjectUtil.isNull(pmphUserRoles2) && pmphUserRoles2.size() == 0){
    // roleDao.addUserRole(materialId, pmphRoleList.get(0).getId());//给项目编辑绑定角色
    // }
    }
    // 保存教材通知备注
    materialExtra.setMaterialId(materialId);
    if (null == materialExtra.getId()) {
        materialExtraService.addMaterialExtra(materialExtra);
    } else {
        materialExtraService.updateMaterialExtra(materialExtra);
    }
    // 保存通知附件
    String materialNoticeAttachments = materialVO.getMaterialNoticeAttachments();
    if (StringUtil.isEmpty(materialNoticeAttachments)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材通知附件为空");
    }
    List<MaterialNoticeAttachment> materialNoticeAttachmentlist = gson.fromJson(materialNoticeAttachments, new TypeToken<ArrayList<MaterialNoticeAttachment>>() {
    }.getType());
    // 原来有的通知附件
    List<MaterialNoticeAttachment> oldMaterialNoticeAttachmentlist = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialExtra.getId());
    String newTempNoticeFileIds = ",";
    for (MaterialNoticeAttachment materialNoticeAttachment : materialNoticeAttachmentlist) {
        if (null == materialNoticeAttachment.getId()) {
            String tempFileId = materialNoticeAttachment.getAttachment();
            byte[] fileByte = (byte[]) request.getSession(false).getAttribute(tempFileId);
            String fileName = (String) request.getSession(false).getAttribute("fileName_" + tempFileId);
            materialNoticeAttachment.setAttachment(String.valueOf(new Date().getTime()));
            materialNoticeAttachment.setAttachmentName(fileName);
            materialNoticeAttachment.setDownload(0L);
            materialNoticeAttachment.setMaterialExtraId(materialExtra.getId());
            // 保存通知
            materialNoticeAttachmentService.addMaterialNoticeAttachment(materialNoticeAttachment);
            String noticeId;
            // 保存通知文件
            InputStream sbs = new ByteArrayInputStream(fileByte);
            noticeId = fileService.save(sbs, fileName, FileType.MATERIAL_NOTICE_ATTACHMENT, materialNoticeAttachment.getId());
            materialNoticeAttachment.setAttachment(noticeId);
            // 更新通知
            materialNoticeAttachmentService.updateMaterialNoticeAttachment(materialNoticeAttachment);
        // 移除session的文件
        // request.getSession(false).removeAttribute(tempFileId);
        // request.getSession(false).removeAttribute("fileName_" + tempFileId);
        } else {
            newTempNoticeFileIds += materialNoticeAttachment.getId() + ",";
        }
    }
    for (MaterialNoticeAttachment materialNoticeAttachment : oldMaterialNoticeAttachmentlist) {
        if (!newTempNoticeFileIds.contains("," + materialNoticeAttachment.getId() + ",")) {
            // 不包含
            // 删除文件
            fileService.remove(materialNoticeAttachment.getAttachment());
            materialNoticeAttachmentService.deleteMaterialNoticeAttachmentById(materialNoticeAttachment.getId());
        }
    }
    // 备注附件保存
    String materialNoteAttachments = materialVO.getMaterialNoteAttachments();
    if (StringUtil.isEmpty(materialNoteAttachments)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材备注附件为空");
    }
    List<MaterialNoteAttachment> materialNoteAttachmentList = gson.fromJson(materialNoteAttachments, new TypeToken<ArrayList<MaterialNoteAttachment>>() {
    }.getType());
    // 原来的备注文件
    List<MaterialNoteAttachment> oldMaterialNoteAttachmentlist = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtra.getId());
    String newTempNoteFileIds = ",";
    for (MaterialNoteAttachment materialNoteAttachment : materialNoteAttachmentList) {
        if (null == materialNoteAttachment.getId()) {
            String tempFileId = materialNoteAttachment.getAttachment();
            byte[] file = (byte[]) request.getSession(false).getAttribute(tempFileId);
            String fileName = (String) request.getSession(false).getAttribute("fileName_" + tempFileId);
            materialNoteAttachment.setAttachment(String.valueOf(new Date().getTime()));
            materialNoteAttachment.setAttachmentName(fileName);
            materialNoteAttachment.setDownload(0L);
            materialNoteAttachment.setMaterialExtraId(materialExtra.getId());
            // 保存备注
            materialNoteAttachmentService.addMaterialNoteAttachment(materialNoteAttachment);
            String noticeId;
            InputStream sbs = new ByteArrayInputStream(file);
            // 保存备注文件
            noticeId = fileService.save(sbs, fileName, FileType.MATERIAL_NOTICE_ATTACHMENT, materialNoteAttachment.getId());
            materialNoteAttachment.setAttachment(noticeId);
            // 更新备注
            materialNoteAttachmentService.updateMaterialNoteAttachment(materialNoteAttachment);
        // 移除session的文件
        // request.getSession().removeAttribute(tempFileId);
        // request.getSession().removeAttribute("fileName_" + tempFileId);
        } else {
            newTempNoteFileIds += materialNoteAttachment.getId() + ",";
        }
    }
    for (MaterialNoteAttachment materialNoteAttachment : oldMaterialNoteAttachmentlist) {
        if (!newTempNoteFileIds.contains("," + materialNoteAttachment.getId() + ",")) {
            // 不包含
            // 删除文件
            fileService.remove(materialNoteAttachment.getAttachment());
            materialNoteAttachmentService.deleteMaterialNoteAttachmentById(materialNoteAttachment.getId());
        }
    }
    CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
    String title = material.getMaterialName();
    if (null != cmsContent && null != cmsContent.getTitle() && !title.equals(cmsContent.getTitle())) {
        cmsContent.setTitle(title);
        cmsContentService.updateCmsContent(cmsContent);
    }
    /**
     * // 判断教材备注附件和教材通知附件 List<MaterialNoticeAttachment>
     * materialNoticeAttachmentlist = new ArrayList<MaterialNoticeAttachment>(5);
     * String materialNoticeAttachments=materialVO.getMaterialNoticeAttachments();
     * if (!StringUtil.isEmpty(materialNoticeAttachments)) {
     * materialNoticeAttachmentlist = gson.fromJson(materialNoticeAttachments, new
     * TypeToken<ArrayList<MaterialNoticeAttachment>>() { }.getType()); } if (null
     * != noticeFiles && noticeFiles.length > 0) { for (MultipartFile notice :
     * noticeFiles) { if (null == notice || !(notice instanceof MultipartFile)) {
     * throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
     * CheckedExceptionResult.NULL_PARAM, "教材通知附件为空"); } if
     * (notice.getName().length() > 80) { throw new
     * CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
     * CheckedExceptionResult.ILLEGAL_PARAM, "教材通知附件文件名过长"); } } } if ((null ==
     * noticeFiles && materialNoticeAttachmentlist.size() == 0) ||
     * (materialNoticeAttachmentlist.size() + noticeFiles.length == 0)) {//
     * 已有的数量加上新增的数量 throw new
     * CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
     * CheckedExceptionResult.NULL_PARAM, "教材通知附件为空"); }
     * List<MaterialNoteAttachment> materialNoteAttachmentList = new
     * ArrayList<MaterialNoteAttachment>(5); String materialNoteAttachments =
     * materialVO.getMaterialNoteAttachments(); if
     * (!StringUtil.isEmpty(materialNoteAttachments)) { materialNoteAttachmentList =
     * gson.fromJson(materialNoteAttachments, new
     * TypeToken<ArrayList<MaterialNoteAttachment>>() { }.getType()); } if (null !=
     * noteFiles && noteFiles.length > 0) { for (MultipartFile note : noteFiles) {
     * if (null == note || !(note instanceof MultipartFile)) { throw new
     * CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
     * CheckedExceptionResult.NULL_PARAM, "教材备注附件为空"); } if (note.getName().length()
     * > 80) { throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
     * CheckedExceptionResult.ILLEGAL_PARAM, "教材备注附件文件名过长"); } } } if ((null ==
     * noteFiles && materialNoteAttachmentList.size() == 0) ||
     * (materialNoteAttachmentList.size() + noteFiles.length == 0)) {// 已有的数量加上新增的数量
     * throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
     * CheckedExceptionResult.NULL_PARAM, "教材备注附件为空"); } // 保存教材通知附件
     * List<MaterialNoticeAttachment> oldMaterialNoticeAttachmentlist =
     * materialNoticeAttachmentService
     * .getMaterialNoticeAttachmentsByMaterialExtraId(materialExtra.getId()); String
     * newMaterialNoticeAttachmentIds = ","; for (MaterialNoticeAttachment
     * materialNoticeAttachment : materialNoticeAttachmentlist) { if (null ==
     * materialNoticeAttachment.getId()) { throw new
     * CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
     * CheckedExceptionResult.NULL_PARAM, "教材通知id为空"); }
     * newMaterialNoticeAttachmentIds += materialNoticeAttachment.getId() + ","; }
     * if (null != noticeFiles && noticeFiles.length > 0) { for (MultipartFile
     * notice : noticeFiles) { MaterialNoticeAttachment materialNoticeAttachment =
     * new MaterialNoticeAttachment();
     * materialNoticeAttachment.setAttachment("---------");
     * materialNoticeAttachment.setAttachmentName(notice.getOriginalFilename());
     * materialNoticeAttachment.setDownload(0L);
     * materialNoticeAttachment.setMaterialExtraId(materialExtra.getId()); // 保存通知
     * materialNoticeAttachmentService.addMaterialNoticeAttachment(materialNoticeAttachment);
     * String noticeId; // 保存通知文件 noticeId = fileService.save(notice,
     * FileType.MATERIAL_NOTICE_ATTACHMENT, materialNoticeAttachment.getId());
     *
     * materialNoticeAttachment.setAttachment(noticeId); // 更新通知
     * materialNoticeAttachmentService.updateMaterialNoticeAttachment(materialNoticeAttachment);
     * newMaterialNoticeAttachmentIds += materialNoticeAttachment.getId() + ","; } }
     * for (MaterialNoticeAttachment materialNoticeAttachment :
     * oldMaterialNoticeAttachmentlist) { if
     * (!newMaterialNoticeAttachmentIds.contains("," +
     * materialNoticeAttachment.getId() + ",")) {// 不包含
     * fileService.remove(materialNoticeAttachment.getAttachment()); // 删除文件
     * materialNoticeAttachmentService
     * .deleteMaterialNoticeAttachmentById(materialNoticeAttachment.getId()); } } //
     * 保存教材备注附件 List<MaterialNoteAttachment> oldMaterialNoteAttachmentlist =
     * materialNoteAttachmentService
     * .getMaterialNoteAttachmentByMaterialExtraId(materialExtra.getId()); String
     * newMaterialNoteAttachmentIds = ","; for (MaterialNoteAttachment
     * materialNoteAttachment : materialNoteAttachmentList) { if (null ==
     * materialNoteAttachment.getId()) { throw new
     * CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
     * CheckedExceptionResult.NULL_PARAM, "教材备注id为空"); }
     * newMaterialNoteAttachmentIds += materialNoteAttachment.getId() + ","; } if
     * (null != noteFiles && noteFiles.length > 0) { for (MultipartFile note :
     * noteFiles) { MaterialNoteAttachment materialNoteAttachment = new
     * MaterialNoteAttachment(); materialNoteAttachment.setAttachment("---------");
     * materialNoteAttachment.setAttachmentName(note.getOriginalFilename());
     * materialNoteAttachment.setDownload(0L);
     * materialNoteAttachment.setMaterialExtraId(materialExtra.getId()); // 保存备注
     * materialNoteAttachmentService.addMaterialNoteAttachment(materialNoteAttachment);
     * String noticeId; // 保存备注文件 noticeId = fileService.save(note,
     * FileType.MATERIAL_NOTICE_ATTACHMENT, materialNoteAttachment.getId());
     * materialNoteAttachment.setAttachment(noticeId); // 更新备注
     * materialNoteAttachmentService.updateMaterialNoteAttachment(materialNoteAttachment);
     * newMaterialNoteAttachmentIds += materialNoteAttachment.getId() + ","; } } for
     * (MaterialNoteAttachment materialNoteAttachment :
     * oldMaterialNoteAttachmentlist) { if
     * (!newMaterialNoteAttachmentIds.contains("," + materialNoteAttachment.getId()
     * + ",")) {// 不包含 fileService.remove(materialNoteAttachment.getAttachment());
     * // 删除文件 materialNoteAttachmentService
     * .deleteMaterialNoteAttachmentById(materialNoteAttachment.getId()); } }
     */
    return material.getId();
}
Also used : MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) MaterialContact(com.bc.pmpheep.back.po.MaterialContact) Gson(com.google.gson.Gson) MaterialProjectEditorVO(com.bc.pmpheep.back.vo.MaterialProjectEditorVO) MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) CmsContent(com.bc.pmpheep.back.po.CmsContent) MaterialProjectEditor(com.bc.pmpheep.back.po.MaterialProjectEditor) PmphUser(com.bc.pmpheep.back.po.PmphUser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MaterialExtension(com.bc.pmpheep.back.po.MaterialExtension) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) Date(java.util.Date) ByteArrayInputStream(java.io.ByteArrayInputStream) TypeToken(com.google.gson.reflect.TypeToken) MaterialExtra(com.bc.pmpheep.back.po.MaterialExtra)

Example 5 with MaterialExtension

use of com.bc.pmpheep.back.po.MaterialExtension 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

MaterialExtension (com.bc.pmpheep.back.po.MaterialExtension)6 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)3 Material (com.bc.pmpheep.back.po.Material)2 MaterialContact (com.bc.pmpheep.back.po.MaterialContact)2 MaterialExtra (com.bc.pmpheep.back.po.MaterialExtra)2 MaterialNoteAttachment (com.bc.pmpheep.back.po.MaterialNoteAttachment)2 MaterialNoticeAttachment (com.bc.pmpheep.back.po.MaterialNoticeAttachment)2 PmphUser (com.bc.pmpheep.back.po.PmphUser)2 DecExtensionVO (com.bc.pmpheep.back.vo.DecExtensionVO)2 MaterialProjectEditorVO (com.bc.pmpheep.back.vo.MaterialProjectEditorVO)2 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Cell (org.apache.poi.ss.usermodel.Cell)2 ExcelHeader (com.bc.pmpheep.annotation.ExcelHeader)1 DeclarationEtcBO (com.bc.pmpheep.back.bo.DeclarationEtcBO)1 CmsContent (com.bc.pmpheep.back.po.CmsContent)1 MaterialProjectEditor (com.bc.pmpheep.back.po.MaterialProjectEditor)1 MaterialType (com.bc.pmpheep.back.po.MaterialType)1