溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

大數(shù)據(jù)中如何實現(xiàn)導入

發(fā)布時間:2021-11-17 13:44:45 來源:億速云 閱讀:153 作者:小新 欄目:大數(shù)據(jù)

這篇文章將為大家詳細講解有關大數(shù)據(jù)中如何實現(xiàn)導入,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

   
    @PostConstruct
    public void init(){
        format = new SimpleDateFormat(CollectChargeEnum.DATEFORMAT.getName());
        headers = new String[]{"停車場名稱", "車牌號", "支付方式", "賬號類型", "交易號", "支付金額", "支付時間", "平帳狀態(tài)"};
        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();
        // 獲取小區(qū)id
        String stoppingPlaceId = currloginInfoService.getCurrLoginStoppingPlaceId();
        // 獲取停車場name
        StoppingPlaceInfomationEntity stoppingPlaceInfomation = stoppingPlaceInfomationService.getById(stoppingPlaceId);
        String stoppingPlaceName = StringUtils.EMPTY;
        if(stoppingPlaceInfomation!=null) {
            stoppingPlaceName = stoppingPlaceInfomation.getStoppingPlaceName();
        }
        // 循環(huán)獲取數(shù)據(jù)
        for (Map<String, String> map : readExcel) {
            FlatAccoutEntity accoutEntity = new FlatAccoutEntity();
            // 判斷是否是該停車場
            if(StringUtils.isNotEmpty(map.get("停車場名稱")) && stoppingPlaceName.equals(map.get("停車場名稱"))) {
            }else {
                throw new BizException("10003","該數(shù)據(jù)不是當前停車場");
            }
            // 設置停車場
            accoutEntity.setStoppingPlaceId(stoppingPlaceId);
            // excel中第1列是停車場名稱,不需要取
            for(int i=1;i<headers.length;i++) {
                String valueStr = map.get(headers[i]);
                // 判斷該字段是否為數(shù)字
                if(intFileIndex.contains(i)){
                    int  valueInt = -1;
                    // 將valueStr轉換為int
                    // 若是支付方式
                    if(i==2){
                        valueInt = EnumUtils.getPayTypeValue(valueStr);
                    }
                    // 若是平帳狀態(tài)
                    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);
        }
        // 保存數(shù)據(jù)至數(shù)據(jù)庫
        boolean saveResult = this.saveBatch(listFlatAccountInfo);
        return saveResult;

    }

關于“大數(shù)據(jù)中如何實現(xiàn)導入”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI