反射生成不同类型模板

        Company41ReqDTO query = reqDTO.getQuery();
        reqDTO.setPageNum(CommonConstant.EXPORT_START_PAGE);
        reqDTO.setPageSize(CommonConstant.EXPORT_MAX_SIZE);
        Up4Enum e = Up4Enum.getEnumByCode(query.getType());
        ActionUtils.doIfObjNull(e,() -> {
            throw new BusinessException("param of 'type' error");
        });
        Class<?> templateClass = null;
        List<Object> templateList = new ArrayList<>();
        switch (e){
            case UP_GAUGE: templateClass = Company41GaugeTemplate.class;break;
            case UP_BOARD: templateClass = Company41BoardTemplate.class;break;
            case UP_CLOUD: templateClass = Company41CloudTemplate.class;break;
            case UP_MARK: templateClass = Company41MarkTemplate.class;break;
        }
        try {
            List<Company41VO> recordList = this.listCompany41(reqDTO).getRecords();
            for(Company41VO company41 : recordList){
                Object template = templateClass.newInstance();
                if(e.getCode().equals("UP_GAUGE")){
                    Company41GaugeTemplate t = (Company41GaugeTemplate)template;
                    BeanUtils.copyProperties(company41,t);
                    t.setProduct(StrUtils.list2str(company41.getProductList()));
                    templateList.add(t);
                }else if(e.getCode().equals("UP_BOARD")){
                    Company41BoardTemplate t = (Company41BoardTemplate)template;
                    BeanUtils.copyProperties(company41,t);
                    t.setProduct(StrUtils.list2str(company41.getProductList()));
                    templateList.add(t);
                }else if(e.getCode().equals("UP_CLOUD")){
                    Company41CloudTemplate t = (Company41CloudTemplate)template;
                    BeanUtils.copyProperties(company41,t);
                    t.setProduct(StrUtils.list2str(company41.getProductList()));
                    templateList.add(t);
                }else{
                    Company41MarkTemplate t = (Company41MarkTemplate)template;
                    BeanUtils.copyProperties(company41,t);
                    t.setProduct(StrUtils.list2str(company41.getProductList()));
                    templateList.add(t);
                }
            }
        }catch (Exception exception){

        }
        String result = ossService.uploadExcelReturnPath(e.getName(), e.getName(),templateClass,templateList);
        return result;
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值