Execl导入功能(两种方式)

来源:互联网 发布:mac 邮件 qq企业邮箱 编辑:程序博客网 时间:2024/06/03 20:24
  • (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;
    }

}

0 0
原创粉丝点击