大数据中如何实现导入

发布时间:2021-11-17 13:44:45 作者:小新
来源:亿速云 阅读:143

这篇文章将为大家详细讲解有关大数据中如何实现导入,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

   
    @PostConstruct
    public void init(){
        format = new SimpleDateFormat(CollectChargeEnum.DATEFORMAT.getName());
        headers = new String[]{"停车场名称", "车牌号", "支付方式", "账号类型", "交易号", "支付金额", "支付时间", "平帐状态"};
        exportFields = new String[]{"stoppingPlaceName", "vehicleNo", "payTypeName", "chargeType", "transactionNo", "payCharge", "payTime", "flatAccountStatusName"};
        setMethodName = new String[]{"setStoppingPlaceId", "setVehicleNo", "setPayType", "setChargeType", "setTransactionNo", "setPayCharge", "setPayTime", "setFlatAccountStatus"};
        intFileIndex = Arrays.asList(new Integer[]{2,7});
    }




@Override
    public boolean importExcel(MultipartFile importFile) throws BizException{
        List<FlatAccoutEntity> listFlatAccountInfo = new ArrayList<FlatAccoutEntity>(100);
        // 解析Excel importFile文件, 0 sheet页
        List<Map<String,String>> readExcel = ExcelUtil.readExcel(importFile, 0);
        // 获取当期时间

        // 获取用户信息
        net.sf.json.JSONObject userInfo = CurrentUserInfoUtil.getCurrentUserInfo(redisTemplate);
        // 获取用户名
        String userName = userInfo.get("userName").toString();
        // 获取小区id
        String stoppingPlaceId = currloginInfoService.getCurrLoginStoppingPlaceId();
        // 获取停车场name
        StoppingPlaceInfomationEntity stoppingPlaceInfomation = stoppingPlaceInfomationService.getById(stoppingPlaceId);
        String stoppingPlaceName = StringUtils.EMPTY;
        if(stoppingPlaceInfomation!=null) {
            stoppingPlaceName = stoppingPlaceInfomation.getStoppingPlaceName();
        }
        // 循环获取数据
        for (Map<String, String> map : readExcel) {
            FlatAccoutEntity accoutEntity = new FlatAccoutEntity();
            // 判断是否是该停车场
            if(StringUtils.isNotEmpty(map.get("停车场名称")) && stoppingPlaceName.equals(map.get("停车场名称"))) {
            }else {
                throw new BizException("10003","该数据不是当前停车场");
            }
            // 设置停车场
            accoutEntity.setStoppingPlaceId(stoppingPlaceId);
            // excel中第1列是停车场名称,不需要取
            for(int i=1;i<headers.length;i++) {
                String valueStr = map.get(headers[i]);
                // 判断该字段是否为数字
                if(intFileIndex.contains(i)){
                    int  valueInt = -1;
                    // 将valueStr转换为int
                    // 若是支付方式
                    if(i==2){
                        valueInt = EnumUtils.getPayTypeValue(valueStr);
                    }
                    // 若是平帐状态
                    if(i==7){
                        valueInt = EnumUtils.getFlatStatusValue(valueStr);
                    }
                    // 调用该字段的set方法
                    MethodUtils.callSetMethod(accoutEntity,setMethodName[i], Integer.class,valueInt);
                }else if(i==6){
                    // 转换为日期格式
                    try {
                        final Date valueDate = format.parse(valueStr);
                        MethodUtils.callSetMethod(accoutEntity,setMethodName[i],Date.class,valueDate);
                    } catch (ParseException e) {
                        log.error(e);
                        continue;
                    }
                }else {
                    // 其余都是str类型 不需要转换类型
                    MethodUtils.callSetMethod(accoutEntity,setMethodName[i],String.class,valueStr);
                }

            }
            listFlatAccountInfo.add(accoutEntity);
        }
        // 保存数据至数据库
        boolean saveResult = this.saveBatch(listFlatAccountInfo);
        return saveResult;

    }

关于“大数据中如何实现导入”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

推荐阅读:
  1. python中如何实现包的导入
  2. Java实现excel大数据量导入

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

大数据

上一篇:Java8怎么实现通过行为参数传递代码

下一篇:jquery如何获取tr里面有几个td

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》