Execl導入功能(兩種方式)

  • (1)系統默認一種:配置數據源:oracle 物理表:**主鍵字段:UUID(API)
  • (2)ImportExcelAction
    • excelModelId   配個id
    • startRow 1
  • 建一個Excel導入處理類(InsureRiskPRExeclProcess)每次導入表都會在表裏插入數據,每次都需要先清空再插入
  • 添加excel展示類(列名)

InsureRiskPRExeclProcess類代碼:

/**

 *

 */

package com.hyf.marketRisk.provider;

 

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

 

import org.springframework.stereotype.Controller;

import org.springframework.transaction.annotation.Transactional;

 

import com.bstek.bdf2.core.orm.jdbc.JdbcDao;

import com.bstek.bdf2.importexcel.model.CellWrapper;

import com.bstek.bdf2.importexcel.model.ExcelDataWrapper;

import com.bstek.bdf2.importexcel.model.RowWrapper;

import com.bstek.bdf2.importexcel.processor.IExcelProcessor;

import com.hyf.utils.CommUtils;

 

/**

 * @param 保費和風險數據導入

 * @author chenbin

 * @date 2016-12-9上午11:49:57

 */

@Controller

public class InsureRiskPRExeclProcess extends JdbcDao implements

        IExcelProcessor {

 

    /* (non-Javadoc)

     * @see com.bstek.bdf2.importexcel.processor.IExcelProcessor#execute(com.bstek.bdf2.importexcel.model.ExcelDataWrapper)

     */

    @Override

    @Transactional

    public int execute(ExcelDataWrapper arg0) throws Exception {

        List<Map<String,Object>> list  = new ArrayList<Map<String,Object>>();

        List<RowWrapper> listRow =  (List<RowWrapper>) arg0.rowWrappers;

        for(int i=0;i<listRow.size();i++){

            RowWrapper row = listRow.get(i);

            List<CellWrapper> listCell =  (List<CellWrapper>) row.getCellWrappers();

            if(i==0){

            }else if(i>=0){

                Map<String,Object> map = new HashMap<String,Object>();

                for(CellWrapper cell : listCell){

                    Object value = cell.getValue();

                    if(cell.getName().equals("類型")){

                        map.put("type", CommUtils.getStr(value));

                    }else if(cell.getName().equals("過去12個月非比例分保分出保費")){

                        map.put("chubaofei", CommUtils.getStr(value));

                    }else if(cell.getName().equals("過去12個月非比例分保分入保費")){

                        map.put("rubaofei", value==null ? null : CommUtils.getDouble(value));

                    }else if(cell.getName().equals("過去12個月非比例分保淨分出保費")){

                        map.put("baojingfen", value==null ? null : CommUtils.getDouble(value));

                    }else if(cell.getName().equals("過去12個月自留保費")){

                        map.put("ziliubaofei", value==null ? null : CommUtils.getDouble(value));

                    }else if(cell.getName().equals("再保後未決賠款準備金")){

                        map.put("peikuanjin", value==null ? null : CommUtils.getDouble(value));

                    }else if(cell.getName().equals("綜合成本率")){

                        map.put("chengbenlv", value==null ? null : CommUtils.getDouble(value));

                    }else if(cell.getName().equals("綜合成本率變動")){

                        map.put("change", value==null ? null : CommUtils.getDouble(value));

                    }else if(cell.getName().equals("未決賠款準備金回溯偏差率的算術平均數")){

                        map.put("average", value==null ? null : CommUtils.getDouble(value));

                    }else if(cell.getName().equals("備註")){

                        map.put("remark", value==null ? null : CommUtils.getDouble(value));

                    }

                }

                list.add(map);

            }

        }

        //刪除已經存在的數據

        String sql  = "delete from SC_UNLISTINSURANCE_CLR_DATA where 1=1";

        this.getJdbcTemplate().execute(sql);

        for(Map<String,Object> map : list){

            //類型

            String type = CommUtils.getStr(map.get("type"));

            //過去12個月非比例分保分出保費

            Double chubaofei = CommUtils.getDouble(map.get("chubaofei"));

            //過去12個月非比例分保分入保費

            Double rubaofei = CommUtils.getDouble(map.get("rubaofei"));

            //過去12個月非比例分保淨分出保費

            Double baojingfen = CommUtils.getDouble(map.get("baojingfen"));

            //過去12個月自留保費

            Double ziliubaofei = CommUtils.getDouble(map.get("ziliubaofei"));

            //再保後未決賠款準備金

            Double peikuanjin = CommUtils.getDouble(map.get("peikuanjin"));

            //綜合成本率

            Double chengbenlv = CommUtils.getDouble(map.get("chengbenlv"));

            //綜合成本率變動

            Double change = CommUtils.getDouble(map.get("change"));

            //未決賠款準備金回溯偏差率的算術平均數

            Double average = CommUtils.getDouble(map.get("average"));

            //備註

            String remark = CommUtils.getStr(map.get("remark"));

            if(!remark.equals("")){

                sql = "insert into SC_UNLISTINSURANCE_CLR_DATA (ID_,type,chubaofei,rubaofei,baojingfen,ziliubaofei,peikuanjin,chengbenlv,change,average,remark) " +

                        "values('"+CommUtils.getUUID()+"','"+type+"',"+chubaofei+",'"+rubaofei+"','"+baojingfen+"',"+ziliubaofei+","+peikuanjin+","+chengbenlv+","+change+","+average+","+remark+") ";

                this.getJdbcTemplate().execute(sql);

            }else{

                sql = "insert into SC_UNLISTINSURANCE_CLR_DATA (ID_,type,chubaofei,rubaofei,baojingfen,ziliubaofei,peikuanjin,chengbenlv,change,average,remark) " +

                        "values('"+CommUtils.getUUID()+"','"+type+"',"+chubaofei+",'"+rubaofei+"','"+baojingfen+"',"+ziliubaofei+","+peikuanjin+","+chengbenlv+","+change+","+average+",null) ";

                this.getJdbcTemplate().execute(sql);

            }

 

        }

        return list.size();

    }

 

    @Override

    public String getName() {

        // TODO Auto-generated method stub

        return null;

    }

 

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章