Search in sources :

Example 6 with DecClinicalReward

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

the class ExcelHelper method fromDeclarationEtcBOList.

/**
 * 根据业务对象(包含子集合的BO)集合创建工作簿
 *
 * @param material
 *            申报表所属教材对象
 * @param extensions
 *            教材扩展项集合
 * @param dataSource
 *            业务对象(BO)集合
 * @param sheetName
 *            要生成的Excel表名(非文件名)
 * @return Excel工作簿
 */
public Workbook fromDeclarationEtcBOList(Material material, List<MaterialExtension> extensions, List<DeclarationEtcBO> dataSource, String sheetName) throws CheckedServiceException, IllegalArgumentException, IllegalAccessException {
    if (null == dataSource || dataSource.isEmpty()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用于导出Excel的数据源为空");
    }
    Workbook workbook = new HSSFWorkbook();
    Sheet sheet = workbook.createSheet(sheetName);
    // 生成表头
    sheet = generateDeclarationEtcBOHeader(extensions, sheet);
    // 设置表头样式
    headerStyleSetup(workbook, 2);
    Field[] fields = dataSource.get(0).getClass().getDeclaredFields();
    /* 设置行计数器 */
    int rowCount = 2;
    /* 记录列数和最大列宽 */
    ColumnProperties columnProperties = new ColumnProperties(1, new int[sheet.getRow(1).getLastCellNum()]);
    /* 遍历list中的对象 */
    Iterator iterator = dataSource.iterator();
    while (iterator.hasNext()) {
        Object object = iterator.next();
        Row row = sheet.createRow(rowCount);
        /* 设置序号及宽度 */
        row.createCell(0).setCellValue(String.valueOf(rowCount - 1));
        columnProperties.setMaxElement(0, 2);
        /* 设置列计数器 */
        columnProperties.setColCount(1);
        for (Field field : fields) {
            // 可访问性设置
            field.setAccessible(true);
            if (field.isAnnotationPresent(ExcelHeader.class)) {
                ExcelHeader excelHeader = (ExcelHeader) field.getAnnotation(ExcelHeader.class);
                String headerName = excelHeader.header();
                if (StringUtil.notEmpty(headerName)) {
                    switch(headerName) {
                        case "学习经历":
                            {
                                List<DecEduExp> list = (List<DecEduExp>) field.get(object);
                                columnProperties = fillDecEduExpData(list, row, columnProperties);
                                break;
                            }
                        case "工作经历":
                            {
                                List<DecWorkExp> list = (List<DecWorkExp>) field.get(object);
                                columnProperties = fillDecWorkExpData(list, row, columnProperties);
                                break;
                            }
                        case "教学经历":
                            {
                                List<DecTeachExp> list = (List<DecTeachExp>) field.get(object);
                                columnProperties = fillDecTeachExpData(list, row, columnProperties);
                                break;
                            }
                        case "个人成就":
                            {
                                DecAchievement decAchievement = (DecAchievement) field.get(object);
                                columnProperties = fillDecAchievementData(decAchievement, row, columnProperties);
                                break;
                            }
                        case "学术兼职":
                            {
                                List<DecAcade> list = (List<DecAcade>) field.get(object);
                                columnProperties = fillDecAcadeData(list, row, columnProperties);
                                break;
                            }
                        case "本套上版教材参编情况":
                            {
                                List<DecLastPosition> list = (List<DecLastPosition>) field.get(object);
                                columnProperties = fillDecLastPositionData(list, row, columnProperties);
                                break;
                            }
                        case "精品课程建设情况":
                            {
                                List<DecCourseConstruction> list = (List<DecCourseConstruction>) field.get(object);
                                columnProperties = fillDecCourseConstructionData(list, row, columnProperties);
                                break;
                            }
                        case "主编国家级规划教材情况":
                            {
                                List<DecNationalPlan> list = (List<DecNationalPlan>) field.get(object);
                                columnProperties = fillDecNationalPlanData(list, row, columnProperties);
                                break;
                            }
                        case "人卫社教材编写情况":
                            {
                                List<DecTextbookPmph> list = (List<DecTextbookPmph>) field.get(object);
                                columnProperties = fillDecTextbookPmphData(list, row, columnProperties);
                                break;
                            }
                        case "其他社教材编写情况":
                            {
                                List<DecTextbook> list = (List<DecTextbook>) field.get(object);
                                columnProperties = fillDecTextbookData(list, row, columnProperties);
                                break;
                            }
                        case "参加人卫慕课、数字教材编写情况":
                            {
                                DecMoocDigital decMoocDigital = (DecMoocDigital) field.get(object);
                                columnProperties = fillDecMoocDigitalData(decMoocDigital, row, columnProperties);
                                break;
                            }
                        case "科研情况":
                            {
                                List<DecResearch> list = (List<DecResearch>) field.get(object);
                                columnProperties = fillDecResearchData(list, row, columnProperties);
                                break;
                            }
                        case "学术专著":
                            {
                                List<DecMonograph> list = (List<DecMonograph>) field.get(object);
                                columnProperties = fillDecMonographData(list, row, columnProperties);
                                break;
                            }
                        case "出版行业获奖情况":
                            {
                                List<DecPublishReward> list = (List<DecPublishReward>) field.get(object);
                                columnProperties = fillDecPublishRewardData(list, row, columnProperties);
                                break;
                            }
                        case "SCI论文投稿及影响因子情况":
                            {
                                List<DecSci> list = (List<DecSci>) field.get(object);
                                columnProperties = fillDecSciData(list, row, columnProperties);
                                break;
                            }
                        case "临床医学获奖情况":
                            {
                                List<DecClinicalReward> list = (List<DecClinicalReward>) field.get(object);
                                columnProperties = fillDecClinicalRewardData(list, row, columnProperties);
                                break;
                            }
                        case "学术荣誉授予情况":
                            {
                                List<DecAcadeReward> list = (List<DecAcadeReward>) field.get(object);
                                columnProperties = fillDecAcadeRewardData(list, row, columnProperties);
                                break;
                            }
                        case "编写内容意向":
                            {
                                DecIntention decIntention = (DecIntention) field.get(object);
                                columnProperties = fillDecIntentionData(decIntention, row, columnProperties);
                                break;
                            }
                        case "作家扩展项":
                            {
                                if (extensions == null || extensions.isEmpty()) {
                                    break;
                                }
                                List<DecExtensionVO> list = (List<DecExtensionVO>) field.get(object);
                                columnProperties = fillDecExtensionVODataPlus(extensions, list, row, columnProperties);
                                break;
                            }
                        default:
                            Object o = field.get(object);
                            Cell cell = row.createCell(columnProperties.getColCount());
                            if (null != o) {
                                String value = o.toString();
                                cell.setCellValue(value);
                                if (value.length() > columnProperties.getCurrentMaxElement()) {
                                    columnProperties.setCurrentMaxElement(value.length());
                                }
                            }
                            columnProperties.setColCount(columnProperties.getColCount() + 1);
                            break;
                    }
                }
            }
        }
        rowCount++;
    }
    /* 样式调整 */
    workbook = dataStyleSetup(workbook, 2, rowCount, columnProperties);
    /* 以下隐藏多余的列 */
    return clearColumns(workbook, material);
}
Also used : DecMonograph(com.bc.pmpheep.back.po.DecMonograph) DecEduExp(com.bc.pmpheep.back.po.DecEduExp) DecTextbookPmph(com.bc.pmpheep.back.po.DecTextbookPmph) DecAchievement(com.bc.pmpheep.back.po.DecAchievement) DecSci(com.bc.pmpheep.back.po.DecSci) Field(java.lang.reflect.Field) DecClinicalReward(com.bc.pmpheep.back.po.DecClinicalReward) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ExcelHeader(com.bc.pmpheep.annotation.ExcelHeader) Cell(org.apache.poi.ss.usermodel.Cell) DecMoocDigital(com.bc.pmpheep.back.po.DecMoocDigital) DecTextbook(com.bc.pmpheep.back.po.DecTextbook) DecLastPosition(com.bc.pmpheep.back.po.DecLastPosition) DecPublishReward(com.bc.pmpheep.back.po.DecPublishReward) DecExtensionVO(com.bc.pmpheep.back.vo.DecExtensionVO) DecAcade(com.bc.pmpheep.back.po.DecAcade) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) DecIntention(com.bc.pmpheep.back.po.DecIntention) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) DecCourseConstruction(com.bc.pmpheep.back.po.DecCourseConstruction) Row(org.apache.poi.ss.usermodel.Row) DecTeachExp(com.bc.pmpheep.back.po.DecTeachExp) DecWorkExp(com.bc.pmpheep.back.po.DecWorkExp) Sheet(org.apache.poi.ss.usermodel.Sheet) DecResearch(com.bc.pmpheep.back.po.DecResearch) DecNationalPlan(com.bc.pmpheep.back.po.DecNationalPlan) DecAcadeReward(com.bc.pmpheep.back.po.DecAcadeReward)

Aggregations

DecClinicalReward (com.bc.pmpheep.back.po.DecClinicalReward)6 DecAcade (com.bc.pmpheep.back.po.DecAcade)4 DecAcadeReward (com.bc.pmpheep.back.po.DecAcadeReward)4 DecAchievement (com.bc.pmpheep.back.po.DecAchievement)4 DecCourseConstruction (com.bc.pmpheep.back.po.DecCourseConstruction)4 DecEduExp (com.bc.pmpheep.back.po.DecEduExp)4 DecIntention (com.bc.pmpheep.back.po.DecIntention)4 DecLastPosition (com.bc.pmpheep.back.po.DecLastPosition)4 DecMonograph (com.bc.pmpheep.back.po.DecMonograph)4 DecMoocDigital (com.bc.pmpheep.back.po.DecMoocDigital)4 DecNationalPlan (com.bc.pmpheep.back.po.DecNationalPlan)4 DecPublishReward (com.bc.pmpheep.back.po.DecPublishReward)4 DecResearch (com.bc.pmpheep.back.po.DecResearch)4 DecSci (com.bc.pmpheep.back.po.DecSci)4 DecTeachExp (com.bc.pmpheep.back.po.DecTeachExp)4 DecTextbook (com.bc.pmpheep.back.po.DecTextbook)4 DecTextbookPmph (com.bc.pmpheep.back.po.DecTextbookPmph)4 DecWorkExp (com.bc.pmpheep.back.po.DecWorkExp)4 DecExtensionVO (com.bc.pmpheep.back.vo.DecExtensionVO)4 ArrayList (java.util.ArrayList)4