导入,导出20220506

cotroller:

 /**
     * 手机上网导入
     *
     * @param file
     * @param time
     * @return
     * @throws Exception
     */

    @RequestMapping(value = "/importMobileOnelinTemplate", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
    @ResponseBody
    public String importMobileOnelinTemplate(@RequestParam(value = "file",required = false) MultipartFile file,
                                 @RequestParam(value = "time",required = false) String time
    ) throws Exception {
        try{
            if(null==file){
                return Ajax.responseString(CST.RES_EXCEPTION,"请上传文件!");
            }
            return satisfactionReportService.importMobileOnelinTemplate(file,time);
        }catch (Exception e){
            logger.error(e.toString());
            return Ajax.responseString(CST.RES_EXCEPTION, "操作失败!");
        }
    }

service:

   /**
     * 手机上网导入明细
     * @param file file
     * @param time time
     * @return String
     */
    String importMobileOnelinTemplate(MultipartFile file, String time);

serviceImpl:

 /**
     * 手机上网导入
     *
     * @param file file
     * @param time time
     * @return
     */
    @Override
    public String importMobileOnelinTemplate(MultipartFile file, String time) {
        //解析文件内容
        //获取流对象和文件名
        InputStream inputStream = null;
        Connection connection=null;
        PreparedStatement ps = null;
        PreparedStatement deletePs = null;
        CallableStatement cstmt=null;
        long start = 0;
        try {
            inputStream = file.getInputStream();
            String filename = file.getOriginalFilename();
            Excel2PhoneOnelineInfo excel2PhoneOnelineInfo =new Excel2PhoneOnelineInfo();
            Workbook wb = excel2PhoneOnelineInfo.getWorkbook(inputStream, filename);
            List<MobileReportDetailBean> list = excel2PhoneOnelineInfo.parseExcel(wb);
            try {
                //测试 todo 存入mysql
                start = System.currentTimeMillis();
//                connection = DBUtilMySql.getConnection();
                connection = DBUtilMySql.getConnection();
                //1.设置为不自动提交数据
                connection.setAutoCommit(false);
                //先删除当前日期的数据(防止数据重复)
                StringBuilder deleteSql=new StringBuilder();
                deleteSql.append("delete from md_grp_survey_phone_sjsw_input_data where STAT_MONTH=?");
                deletePs=connection.prepareStatement(deleteSql.toString());
                deletePs.setInt(1,Integer.parseInt(time));
                deletePs.executeUpdate();
                //导入
                StringBuilder sql=new StringBuilder();
                sql.append("INSERT INTO `md_grp_survey_phone_sjsw_input_data`(`stat_month`, `user_id`, `city_name`, `A1`, `A2`, `A3`, `A4`, `A5`, `A6_1`, `A6_2`, `A6_3`, `A6_4`, `A6_5`, `A6_6`, `A6_7`, `A6_98`, `A6_98open`, `A7_1`, `A7_2`, " +
                        "`A7_3`, `A7_4`, `A7_98`, `A7_98open`, `A7_1_1`, `A7_1_2`, " +
                        "`A7_1_3`, `A7_1_4`, `A7_1_5`, `A7_1_98`, " +
                        "`A7_1_98open`, `A7_2_1`, `A7_2_2`, `A7_2_3`," +
                        " `A7_2_4`, `A7_2_5`, `A7_2_6`, `A7_2_7`, `A7_2_8`," +
                        " `A7_2_9`, `A7_2_98`, `A7_2_98open`, `A7_2_99`, `A7_3_1`," +
                        " `A7_3_2`, `A7_3_3`, `A7_3_4`, `A7_3_5`, `A7_3_6`, `A7_3_7`," +
                        " `A7_3_8`, `A7_3_9`, `A7_3_10`, `A7_3_98`, `A7_3_98open`, `A7_3_99`," +
                        " `A7_4_1`, `A7_4_2`, `A7_4_3`, `A7_4_4`, `A7_4_5`, `A7_4_6`, `A7_4_7`, `A7_4_8`," +
                        " `A7_4_98`, `A7_4_98open`, `A7_4_99`, `IS_5G_package`, `IS_5GKH`, `DY500M`) " +
                        "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " +
                        "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," +
                        " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," +
                        " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " +
                        "?, ?, ?, ?, ?, ?, ?, ?, ?)"
                );
                ps = connection.prepareStatement(sql.toString());
                for (int i = 0; i <list.size(); i++) {
                    ps.setInt(1,Integer.parseInt(time));
                    ps.setLong(2,list.get(i).getUserId());
                    ps.setString(3,list.get(i).getCityName());
                    ps.setString(4,list.get(i).getA1());
                    ps.setString(5,list.get(i).getA2());
                    ps.setString(6,list.get(i).getA3());
                    ps.setString(7,list.get(i).getA4());
                    ps.setString(8,list.get(i).getA5());
                    ps.setString(9,list.get(i).getA6_1());
                    ps.setString(10,list.get(i).getA6_2());
                    ps.setString(11,list.get(i).getA6_3());
                    ps.setString(12,list.get(i).getA6_4());
                    ps.setString(13,list.get(i).getA6_5());
                    ps.setString(14,list.get(i).getA6_6());
                    ps.setString(15,list.get(i).getA6_7());
                    ps.setString(16,list.get(i).getA6_98());
                    ps.setString(17,list.get(i).getA6_98open());
                    ps.setString(18,list.get(i).getA7_1());
                    ps.setString(19,list.get(i).getA7_2());
                    ps.setString(20,list.get(i).getA7_3());
                    ps.setString(21,list.get(i).getA7_4());
                    ps.setString(22,list.get(i).getA7_98());
                    ps.setString(23,list.get(i).getA7_98open());
                    ps.setString(24,list.get(i).getA7_1_1());
                    ps.setString(25,list.get(i).getA7_1_2());
                    ps.setString(26,list.get(i).getA7_1_3());
                    ps.setString(27,list.get(i).getA7_1_4());
                    ps.setString(28,list.get(i).getA7_1_5());
                    ps.setString(29,list.get(i).getA7_1_98());
                    ps.setString(30,list.get(i).getA7_1_98open());
                    ps.setString(31,list.get(i).getA7_2_1());
                    ps.setString(32,list.get(i).getA7_2_2());
                    ps.setString(33,list.get(i).getA7_2_3());
                    ps.setString(34,list.get(i).getA7_2_4());
                    ps.setString(35,list.get(i).getA7_2_5());
                    ps.setString(36,list.get(i).getA7_2_6());
                    ps.setString(37,list.get(i).getA7_2_7());
                    ps.setString(38,list.get(i).getA7_2_8());
                    ps.setString(39,list.get(i).getA7_2_9());
                    ps.setString(40,list.get(i).getA7_2_98());
                    ps.setString(41,list.get(i).getA7_2_98open());
                    ps.setString(42,list.get(i).getA7_2_99());
                    ps.setString(43,list.get(i).getA7_3_1());
                    ps.setString(44,list.get(i).getA7_3_2());
                    ps.setString(45,list.get(i).getA7_3_3());
                    ps.setString(46,list.get(i).getA7_3_4());
                    ps.setString(47,list.get(i).getA7_3_5());
                    ps.setString(48,list.get(i).getA7_3_6());
                    ps.setString(49,list.get(i).getA7_3_7());
                    ps.setString(50,list.get(i).getA7_3_8());
                    ps.setString(51,list.get(i).getA7_3_9());
                    ps.setString(52,list.get(i).getA7_3_10());
                    ps.setString(53,list.get(i).getA7_3_98());
                    ps.setString(54,list.get(i).getA7_3_98open());
                    ps.setString(55,list.get(i).getA7_3_99());
                    ps.setString(56,list.get(i).getA7_4_1());
                    ps.setString(57,list.get(i).getA7_4_2());
                    ps.setString(58,list.get(i).getA7_4_3());
                    ps.setString(59,list.get(i).getA7_4_4());
                    ps.setString(60,list.get(i).getA7_4_5());
                    ps.setString(61,list.get(i).getA7_4_6());
                    ps.setString(62,list.get(i).getA7_4_7());
                    ps.setString(63,list.get(i).getA7_4_8());
                    ps.setString(64,list.get(i).getA7_4_98());
                    ps.setString(65,list.get(i).getA7_4_98open());
                    ps.setString(66,list.get(i).getA7_4_99());
                    ps.setString(67,list.get(i).getIs5gPackage());
                    ps.setString(68,list.get(i).getIs5gkh());
                    ps.setString(69,list.get(i).getDY500M());
                    ps.addBatch();

                }
                //2.执行
                ps.executeBatch();

                //2.提交数据
                connection.commit();
            } catch (SQLException throwables) {
                //回滚
                connection.rollback();
                throwables.printStackTrace();
                return Ajax.responseString(CST.RES_LOGIC_ERROR, "导入失败");
            }

            long end = System.currentTimeMillis();
            System.out.println("花费的时间为:" + (end - start));
            ThreadTaskUtils.run(()->{
                //todo 异步
                Connection conn=null;
                CallableStatement ctmt=null;
                try {
                    conn = DBUtilMySql.getConnection();
                    //生产 todo 存入gbase 调用存储过程
                    String sqlCall = "{call sp_mkt_dtl_grp_survey_phone_sjsw_mon(?,?,?)}";
                    ctmt = conn.prepareCall(sqlCall);
                    ctmt.setInt("in_stat_month", Integer.parseInt(time));
                    ctmt.execute();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                    logger.error("存储过程调用失败",throwables);
                }finally {
                    try {
                        if(null != conn){
                            conn.close();
                        }
                        if (null != ctmt){
                            ctmt.close();
                        }
                    } catch (SQLException throwables) {
                        throwables.printStackTrace();
                    }
                }
            });

            return Ajax.responseString(CST.RES_SECCESS, "导入成功");
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("导入失败");
        }finally {
            DBUtilMySql.close(connection, ps, null);
        }
    }

类:

/**
 * 手机上网导入明细
 *
 */
public class Excel2PhoneOnelineInfo extends Excel2Object {
    @Override
    public MobileReportDetailBean convertRowToData(Row row) throws ParseException {
        MobileReportDetailBean mobileReportDetail = new MobileReportDetailBean();
        Cell cell;
        //当前列号,默认值0
        int cellNum = 0;
        //获取最大列号,
        row.getPhysicalNumberOfCells();
        //通过行获取列 获取第一列
        cell = row.getCell(cellNum++);
        String a = convertCellValueToString(cell);
        //通过行获取列 获取第二列
        cell = row.getCell(cellNum++);
        String b = convertCellValueToString(cell);
        //通过行获取列 获取第三列
        cell = row.getCell(cellNum++);
        String c = convertCellValueToString(cell);
        //通过行获取列 获取第四列
        cell = row.getCell(cellNum++);
        String d = convertCellValueToString(cell);
        //通过行获取列 获取第五列
        cell = row.getCell(cellNum++);
        String e = convertCellValueToString(cell);
        //通过行获取列 获取第六列
        cell = row.getCell(cellNum++);
        String f = convertCellValueToString(cell);
        //通过行获取列 获取第七列
        cell = row.getCell(cellNum++);
        String g = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String h = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String i = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String j = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String k = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String m = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String n = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String o = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String p = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String q = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String r = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String s = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String t = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String u = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String v = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String w = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String x = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String y = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String z = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String aa = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String ab = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String ac = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String ad = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String ae = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String af = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String ag = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String ah = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String qw = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String qe = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String qr = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String qt = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String qy = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String qu = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String qi = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String qo = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String qp = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wq = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String we = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wr = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wt = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wy = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wu = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wi = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wo = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wp = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wa = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String ws = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wd = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wf = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wg = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wh = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wj = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wk = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wl = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wz = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wx = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wc = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wv = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String wb = convertCellValueToString(cell);


        cell = row.getCell(cellNum++);
        String fd = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String fg = convertCellValueToString(cell);
        //通过行获取列 获取第八列
        cell = row.getCell(cellNum++);
        String fh = convertCellValueToString(cell);



//        mobileReportDetail.setStatMonth(null== a ? null : Integer.parseInt(a));
        mobileReportDetail.setUserId(null== a ? null : Long.parseLong(a));
        if (!b.contains("市")) {
            b=b+"市";
        }
        mobileReportDetail.setCityName(b);
        mobileReportDetail.setA1(c);
        mobileReportDetail.setA2(d);
        mobileReportDetail.setA3(e);
        mobileReportDetail.setA4(f);
        mobileReportDetail.setA5(g);
        mobileReportDetail.setA6_1(h);
        mobileReportDetail.setA6_2(i);
        mobileReportDetail.setA6_3(j);
        mobileReportDetail.setA6_4(k);
        mobileReportDetail.setA6_5(m);
        mobileReportDetail.setA6_6(n);
        mobileReportDetail.setA6_7(o);
        mobileReportDetail.setA6_98(p);
        mobileReportDetail.setA6_98open(q);
        mobileReportDetail.setA7_1(r);
        mobileReportDetail.setA7_2(s);
        mobileReportDetail.setA7_3(t);
        mobileReportDetail.setA7_4(u);
        mobileReportDetail.setA7_98(v);
        mobileReportDetail.setA7_98open(w);
        mobileReportDetail.setA7_1_1(x);
        mobileReportDetail.setA7_1_2(y);
        mobileReportDetail.setA7_1_3(z);
        mobileReportDetail.setA7_1_4(aa);
        mobileReportDetail.setA7_1_5(ab);
        mobileReportDetail.setA7_1_98(ac);
        mobileReportDetail.setA7_1_98open(ad);
        mobileReportDetail.setA7_2_1(ae);
        mobileReportDetail.setA7_2_2(af);
        mobileReportDetail.setA7_2_3(ag);
        mobileReportDetail.setA7_2_4(ah);
        mobileReportDetail.setA7_2_5(qw);
        mobileReportDetail.setA7_2_6(qe);
        mobileReportDetail.setA7_2_7(qr);
        mobileReportDetail.setA7_2_8(qt);
        mobileReportDetail.setA7_2_9(qy);
        mobileReportDetail.setA7_2_98(qu);
        mobileReportDetail.setA7_2_98open(qi);
        mobileReportDetail.setA7_2_99(qo);
        mobileReportDetail.setA7_3_1(qp);
        mobileReportDetail.setA7_3_2(wq);
        mobileReportDetail.setA7_3_3(we);
        mobileReportDetail.setA7_3_4(wr);
        mobileReportDetail.setA7_3_5(wt);
        mobileReportDetail.setA7_3_6(wy);
        mobileReportDetail.setA7_3_7(wu);
        mobileReportDetail.setA7_3_8(wi);
        mobileReportDetail.setA7_3_9(wo);
        mobileReportDetail.setA7_3_10(wp);
        mobileReportDetail.setA7_3_98(wa);
        mobileReportDetail.setA7_3_98open(ws);
        mobileReportDetail.setA7_3_99(wd);
        mobileReportDetail.setA7_4_1(wf);
        mobileReportDetail.setA7_4_2(wg);
        mobileReportDetail.setA7_4_3(wh);
        mobileReportDetail.setA7_4_4(wj);
        mobileReportDetail.setA7_4_5(wk);
        mobileReportDetail.setA7_4_6(wl);
        mobileReportDetail.setA7_4_7(wz);
        mobileReportDetail.setA7_4_8(wx);
        mobileReportDetail.setA7_4_98(wc);
        mobileReportDetail.setA7_4_98open(wv);
        mobileReportDetail.setA7_4_99(wb);
        mobileReportDetail.setIs5gkh(fd);
        mobileReportDetail.setIs5gkh(fg);
        mobileReportDetail.setDY500M(fh);
return mobileReportDetail;
    }
}

实体类:

/**
 * 手机导出明细实体
 */
public class MobileReportDetailBean implements Serializable {
    private Integer statMonth;
    private Long userId;
    private String parentnameL1;
    private String parentnameL2;
    private String parentnameL3;
    private Integer isInter;
    private String is5gPackage;
    private String is5gkh;
    private String a1;
    private String a2;
    private String a3;
    private String a4;
    private String a5;
    private String a6_1;
    private String a6_2;
    private String a6_3;
    private String a6_4;
    private String a6_5;
    private String a6_6;
    private String a6_7;
    private String a6_98;
    private String a6_98open;
    private String a7_1;
    private String a7_2;
    private String a7_3;
    private String a7_4;
    private String a7_98;
    private String a7_98open;
    private String a7_1_1;
    private String a7_1_2;
    private String a7_1_3;
    private String a7_1_4;
    private String a7_1_5;
    private String a7_1_98;
    private String a7_1_98open;
    private String a7_2_1;
    private String a7_2_2;
    private String a7_2_3;
    private String a7_2_4;
    private String a7_2_5;
    private String a7_2_6;
    private String a7_2_7;
    private String a7_2_8;
    private String a7_2_9;
    private String a7_2_98;
    private String a7_2_98open;
    private String a7_2_99;
    private String a7_3_1;
    private String a7_3_2;
    private String a7_3_3;
    private String a7_3_4;
    private String a7_3_5;
    private String a7_3_6;
    private String a7_3_7;
    private String a7_3_8;
    private String a7_3_9;
    private String a7_3_10;
    private String a7_3_98;
    private String a7_3_98open;
    private String a7_3_99;
    private String a7_4_1;
    private String a7_4_2;
    private String a7_4_3;
    private String a7_4_4;
    private String a7_4_5;
    private String a7_4_6;
    private String a7_4_7;
    private String a7_4_8;
    private String a7_4_98;
    private String a7_4_98open;
    private String a7_4_99;
    private String DY500M;
    private String cityName;

    public Integer getStatMonth() {
        return statMonth;
    }

    public void setStatMonth(Integer statMonth) {
        this.statMonth = statMonth;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getParentnameL1() {
        return parentnameL1;
    }

    public void setParentnameL1(String parentnameL1) {
        this.parentnameL1 = parentnameL1;
    }

    public String getParentnameL2() {
        return parentnameL2;
    }

    public void setParentnameL2(String parentnameL2) {
        this.parentnameL2 = parentnameL2;
    }

    public String getParentnameL3() {
        return parentnameL3;
    }

    public void setParentnameL3(String parentnameL3) {
        this.parentnameL3 = parentnameL3;
    }

    public Integer getIsInter() {
        return isInter;
    }

    public void setIsInter(Integer isInter) {
        this.isInter = isInter;
    }

    public String getIs5gPackage() {
        return is5gPackage;
    }

    public void setIs5gPackage(String is5gPackage) {
        this.is5gPackage = is5gPackage;
    }

    public String getIs5gkh() {
        return is5gkh;
    }

    public void setIs5gkh(String is5gkh) {
        this.is5gkh = is5gkh;
    }

    public String getA1() {
        return a1;
    }

    public void setA1(String a1) {
        this.a1 = a1;
    }

    public String getA2() {
        return a2;
    }

    public void setA2(String a2) {
        this.a2 = a2;
    }

    public String getA3() {
        return a3;
    }

    public void setA3(String a3) {
        this.a3 = a3;
    }

    public String getA4() {
        return a4;
    }

    public void setA4(String a4) {
        this.a4 = a4;
    }

    public String getA5() {
        return a5;
    }

    public void setA5(String a5) {
        this.a5 = a5;
    }

    public String getA6_1() {
        return a6_1;
    }

    public void setA6_1(String a6_1) {
        this.a6_1 = a6_1;
    }

    public String getA6_2() {
        return a6_2;
    }

    public void setA6_2(String a6_2) {
        this.a6_2 = a6_2;
    }

    public String getA6_3() {
        return a6_3;
    }

    public void setA6_3(String a6_3) {
        this.a6_3 = a6_3;
    }

    public String getA6_4() {
        return a6_4;
    }

    public void setA6_4(String a6_4) {
        this.a6_4 = a6_4;
    }

    public String getA6_5() {
        return a6_5;
    }

    public void setA6_5(String a6_5) {
        this.a6_5 = a6_5;
    }

    public String getA6_6() {
        return a6_6;
    }

    public void setA6_6(String a6_6) {
        this.a6_6 = a6_6;
    }

    public String getA6_7() {
        return a6_7;
    }

    public void setA6_7(String a6_7) {
        this.a6_7 = a6_7;
    }

    public String getA6_98() {
        return a6_98;
    }

    public void setA6_98(String a6_98) {
        this.a6_98 = a6_98;
    }

    public String getA6_98open() {
        return a6_98open;
    }

    public void setA6_98open(String a6_98open) {
        this.a6_98open = a6_98open;
    }

    public String getA7_1() {
        return a7_1;
    }

    public void setA7_1(String a7_1) {
        this.a7_1 = a7_1;
    }

    public String getA7_2() {
        return a7_2;
    }

    public void setA7_2(String a7_2) {
        this.a7_2 = a7_2;
    }

    public String getA7_3() {
        return a7_3;
    }

    public void setA7_3(String a7_3) {
        this.a7_3 = a7_3;
    }

    public String getA7_4() {
        return a7_4;
    }

    public void setA7_4(String a7_4) {
        this.a7_4 = a7_4;
    }

    public String getA7_98() {
        return a7_98;
    }

    public void setA7_98(String a7_98) {
        this.a7_98 = a7_98;
    }

    public String getA7_98open() {
        return a7_98open;
    }

    public void setA7_98open(String a7_98open) {
        this.a7_98open = a7_98open;
    }

    public String getA7_1_1() {
        return a7_1_1;
    }

    public void setA7_1_1(String a7_1_1) {
        this.a7_1_1 = a7_1_1;
    }

    public String getA7_1_2() {
        return a7_1_2;
    }

    public void setA7_1_2(String a7_1_2) {
        this.a7_1_2 = a7_1_2;
    }

    public String getA7_1_3() {
        return a7_1_3;
    }

    public void setA7_1_3(String a7_1_3) {
        this.a7_1_3 = a7_1_3;
    }

    public String getA7_1_4() {
        return a7_1_4;
    }

    public void setA7_1_4(String a7_1_4) {
        this.a7_1_4 = a7_1_4;
    }

    public String getA7_1_5() {
        return a7_1_5;
    }

    public void setA7_1_5(String a7_1_5) {
        this.a7_1_5 = a7_1_5;
    }

    public String getA7_1_98() {
        return a7_1_98;
    }

    public void setA7_1_98(String a7_1_98) {
        this.a7_1_98 = a7_1_98;
    }

    public String getA7_1_98open() {
        return a7_1_98open;
    }

    public void setA7_1_98open(String a7_1_98open) {
        this.a7_1_98open = a7_1_98open;
    }

    public String getA7_2_1() {
        return a7_2_1;
    }

    public void setA7_2_1(String a7_2_1) {
        this.a7_2_1 = a7_2_1;
    }

    public String getA7_2_2() {
        return a7_2_2;
    }

    public void setA7_2_2(String a7_2_2) {
        this.a7_2_2 = a7_2_2;
    }

    public String getA7_2_3() {
        return a7_2_3;
    }

    public void setA7_2_3(String a7_2_3) {
        this.a7_2_3 = a7_2_3;
    }

    public String getA7_2_4() {
        return a7_2_4;
    }

    public void setA7_2_4(String a7_2_4) {
        this.a7_2_4 = a7_2_4;
    }

    public String getA7_2_5() {
        return a7_2_5;
    }

    public void setA7_2_5(String a7_2_5) {
        this.a7_2_5 = a7_2_5;
    }

    public String getA7_2_6() {
        return a7_2_6;
    }

    public void setA7_2_6(String a7_2_6) {
        this.a7_2_6 = a7_2_6;
    }

    public String getA7_2_7() {
        return a7_2_7;
    }

    public void setA7_2_7(String a7_2_7) {
        this.a7_2_7 = a7_2_7;
    }

    public String getA7_2_8() {
        return a7_2_8;
    }

    public void setA7_2_8(String a7_2_8) {
        this.a7_2_8 = a7_2_8;
    }

    public String getA7_2_9() {
        return a7_2_9;
    }

    public void setA7_2_9(String a7_2_9) {
        this.a7_2_9 = a7_2_9;
    }

    public String getA7_2_98() {
        return a7_2_98;
    }

    public void setA7_2_98(String a7_2_98) {
        this.a7_2_98 = a7_2_98;
    }

    public String getA7_2_98open() {
        return a7_2_98open;
    }

    public void setA7_2_98open(String a7_2_98open) {
        this.a7_2_98open = a7_2_98open;
    }

    public String getA7_2_99() {
        return a7_2_99;
    }

    public void setA7_2_99(String a7_2_99) {
        this.a7_2_99 = a7_2_99;
    }

    public String getA7_3_1() {
        return a7_3_1;
    }

    public void setA7_3_1(String a7_3_1) {
        this.a7_3_1 = a7_3_1;
    }

    public String getA7_3_2() {
        return a7_3_2;
    }

    public void setA7_3_2(String a7_3_2) {
        this.a7_3_2 = a7_3_2;
    }

    public String getA7_3_3() {
        return a7_3_3;
    }

    public void setA7_3_3(String a7_3_3) {
        this.a7_3_3 = a7_3_3;
    }

    public String getA7_3_4() {
        return a7_3_4;
    }

    public void setA7_3_4(String a7_3_4) {
        this.a7_3_4 = a7_3_4;
    }

    public String getA7_3_5() {
        return a7_3_5;
    }

    public void setA7_3_5(String a7_3_5) {
        this.a7_3_5 = a7_3_5;
    }

    public String getA7_3_6() {
        return a7_3_6;
    }

    public void setA7_3_6(String a7_3_6) {
        this.a7_3_6 = a7_3_6;
    }

    public String getA7_3_7() {
        return a7_3_7;
    }

    public void setA7_3_7(String a7_3_7) {
        this.a7_3_7 = a7_3_7;
    }

    public String getA7_3_8() {
        return a7_3_8;
    }

    public void setA7_3_8(String a7_3_8) {
        this.a7_3_8 = a7_3_8;
    }

    public String getA7_3_9() {
        return a7_3_9;
    }

    public void setA7_3_9(String a7_3_9) {
        this.a7_3_9 = a7_3_9;
    }

    public String getA7_3_10() {
        return a7_3_10;
    }

    public void setA7_3_10(String a7_3_10) {
        this.a7_3_10 = a7_3_10;
    }

    public String getA7_3_98() {
        return a7_3_98;
    }

    public void setA7_3_98(String a7_3_98) {
        this.a7_3_98 = a7_3_98;
    }

    public String getA7_3_98open() {
        return a7_3_98open;
    }

    public void setA7_3_98open(String a7_3_98open) {
        this.a7_3_98open = a7_3_98open;
    }

    public String getA7_3_99() {
        return a7_3_99;
    }

    public void setA7_3_99(String a7_3_99) {
        this.a7_3_99 = a7_3_99;
    }

    public String getA7_4_1() {
        return a7_4_1;
    }

    public void setA7_4_1(String a7_4_1) {
        this.a7_4_1 = a7_4_1;
    }

    public String getA7_4_2() {
        return a7_4_2;
    }

    public void setA7_4_2(String a7_4_2) {
        this.a7_4_2 = a7_4_2;
    }

    public String getA7_4_3() {
        return a7_4_3;
    }

    public void setA7_4_3(String a7_4_3) {
        this.a7_4_3 = a7_4_3;
    }

    public String getA7_4_4() {
        return a7_4_4;
    }

    public void setA7_4_4(String a7_4_4) {
        this.a7_4_4 = a7_4_4;
    }

    public String getA7_4_5() {
        return a7_4_5;
    }

    public void setA7_4_5(String a7_4_5) {
        this.a7_4_5 = a7_4_5;
    }

    public String getA7_4_6() {
        return a7_4_6;
    }

    public void setA7_4_6(String a7_4_6) {
        this.a7_4_6 = a7_4_6;
    }

    public String getA7_4_7() {
        return a7_4_7;
    }

    public void setA7_4_7(String a7_4_7) {
        this.a7_4_7 = a7_4_7;
    }

    public String getA7_4_8() {
        return a7_4_8;
    }

    public void setA7_4_8(String a7_4_8) {
        this.a7_4_8 = a7_4_8;
    }

    public String getA7_4_98() {
        return a7_4_98;
    }

    public void setA7_4_98(String a7_4_98) {
        this.a7_4_98 = a7_4_98;
    }

    public String getA7_4_98open() {
        return a7_4_98open;
    }

    public void setA7_4_98open(String a7_4_98open) {
        this.a7_4_98open = a7_4_98open;
    }

    public String getA7_4_99() {
        return a7_4_99;
    }

    public void setA7_4_99(String a7_4_99) {
        this.a7_4_99 = a7_4_99;
    }

    public String getDY500M() {
        return DY500M;
    }

    public void setDY500M(String DY500M) {
        this.DY500M = DY500M;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }
}

工具类:


import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;


/**
 * @author 陈浩
 */
public abstract class Excel2Object<T> {

    private static final String XLS = "xls";
    private static final String XLSX = "xlsx";

    private static Logger log = LoggerFactory.getLogger(Excel2Object.class);

    /**
     * 根据文件后缀名类型获取对应的工作簿对象
     *
     * @param inputStream 读取文件的输入流
     * @return 包含文件数据的工作簿对象
     * @throws IOException
     */
    public Workbook getWorkbook(InputStream inputStream, String fileName) throws IOException {
        Workbook workbook = null;
        if (fileName.endsWith(XLS)) {
            workbook = new HSSFWorkbook(inputStream);
        } else if (fileName.endsWith(XLSX)) {
            workbook = new XSSFWorkbook(inputStream);
        }
        return workbook;
    }

    /**
     * 读取Excel文件内容
     *
     * @param fileName 要读取的Excel文件所在路径
     * @return 读取结果列表,读取失败时返回null
     */
    public List<T> readExcel(String fileName) {

        Workbook workbook = null;

        FileInputStream inputStream = null;

        try {
            // 获取Excel后缀名
            String fileType = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
            // 获取Excel文件
            File excelFile = new File(fileName);
            if (!excelFile.exists()) {
                return null;
            }

            // 获取Excel工作簿
            inputStream = new FileInputStream(excelFile);
            workbook = getWorkbook(inputStream, fileType);

            // 读取excel中的数据
            List<T> resultDataList = parseExcel(workbook);

            return resultDataList;
        } catch (Exception e) {
            log.info("解析Excel失败,文件名:" + fileName + " 错误信息:" + e.getMessage());
            return null;
        } finally {
            try {

                if (null != inputStream) {
                    inputStream.close();
                }
            } catch (Exception e) {
                log.info("关闭数据流出错!错误信息:" + e.getMessage());
                return null;
            }
        }
    }

    /**
     * 解析Excel数据
     *
     * @param workbook Excel工作簿对象
     * @return 解析结果
     */
    public List<T> parseExcel(Workbook workbook) {
        List<T> resultDataList = new ArrayList<>();
        // 解析sheet
        for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
            Sheet sheet = workbook.getSheetAt(sheetNum);

            // 校验sheet是否合法
            if (sheet == null) {
                continue;
            }

            // 获取第一行数据
            int firstRowNum = sheet.getFirstRowNum();
            Row firstRow = sheet.getRow(firstRowNum);
            if (null == firstRow) {
                log.info("解析Excel失败,在第一行没有读取到任何数据!");
            }

            // 解析每一行的数据,构造数据对象
            int rowStart = firstRowNum + 1;
            int rowEnd = sheet.getPhysicalNumberOfRows();
            for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
                Row row = sheet.getRow(rowNum);
                if (isRowEmpty(row)) {
                    continue;
                }
                if (null == row) {
                    continue;
                }
                //读取当前行的数据,该方法需要重写
                T resultData = null;
                try {
                    resultData = convertRowToData(row);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                if (null == resultData) {
                    log.info("第 " + row.getRowNum() + "行数据不合法,已忽略!");
                    continue;
                }
                resultDataList.add(resultData);
            }
        }

        return resultDataList;
    }

    private boolean isRowEmpty(Row row) {
        for (int c = row.getFirstCellNum(); c < row.getLastCellNum(); c++) {
            Cell cell = row.getCell(c);
            if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
                return false;
            }
        }
        return true;
    }

    /**
     * 将单元格内容转换为字符串
     *
     * @param cell
     * @return
     */
    public static String convertCellValueToString(Cell cell) {
        if (cell == null) {
            return null;
        }
        String returnValue = null;
        switch (cell.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC:   //数字
                Double doubleValue = cell.getNumericCellValue();

                // 格式化科学计数法,取一位整数
                DecimalFormat df = new DecimalFormat("0");
                returnValue = df.format(doubleValue);
                break;
            case Cell.CELL_TYPE_STRING:    //字符串
                returnValue = cell.getStringCellValue();
                break;
            case Cell.CELL_TYPE_BOOLEAN:   //布尔
                Boolean booleanValue = cell.getBooleanCellValue();
                returnValue = booleanValue.toString();
                break;
            case Cell.CELL_TYPE_BLANK:     // 空值
                break;
            case Cell.CELL_TYPE_FORMULA:   // 公式
                returnValue = cell.getCellFormula();
                break;
            case Cell.CELL_TYPE_ERROR:     // 故障
                break;
            default:
                break;
        }
        return returnValue;
    }

    /**
     * 为了灵活使用该工具类,抽取泛型来完成
     * 提取每一行中需要的数据,构造成为一个结果数据对象
     * 当该行中有单元格的数据为空或不合法时,忽略该行的数据
     *
     * @param row 行数据
     * @return 解析后的行数据对象,行数据错误时返回null
     */
    public abstract T convertRowToData(Row row) throws ParseException;
}

~~ ~~

导出

**
导出controller

  /**
     * 手机上网满导出明细
     *
     * @param time time
     * @param city city
     * @param type type
     * @param response response
     * @throws Exception Exception
     */
    @RequestMapping(value = "/exportMobileSatisfactionInfo", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
    @ResponseBody
    public void exportMobileSatisfactionInfo(@RequestParam(value = "time", required = true) String time,
                              @RequestParam(value = "city", required = true) String city,
                              @RequestParam(value = "type", required = true) String type,
                              HttpServletResponse response) throws Exception {
        try{
            satisfactionReportService.exportMobileSatisfactionInfo(time,city,type,response);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

导出service

    /**
     * 手机导出明细
     *
     * @param time time
     * @param city city
     * @param type type
     * @param response response
     */
    void exportMobileSatisfactionInfo(String time, String city, String type, HttpServletResponse response);

导出serviceImpl:

/**
     * 手机导出明细
     *
     * @param time time
     * @param city city
     * @param type type
     * @param response response
     */
    @Override
    public void exportMobileSatisfactionInfo(String time, String city, String type, HttpServletResponse response) {
        try {
            List<MobileReportDetailBean> list = this.getMobileReportDetail(time, city, type);
            String tableName = "导出手机满意度明细报表.xlsx";
            String[] headArr = {"测评时间(格式说明:年月)",
                    "USER-ID",
                    "地市",
                    "区县",
                    "网格",
                    "是否宽带用户(是 1 否 0)",
                    "是否5G套餐",
                    "是否5G客户",
                    "A6_1",
                    "A6_2",
                    "A6_3",
                    "A6_4",
                    "A6_5",
                    "A6_6",
                    "A6_7",
                    "A6_98",
                    "A6_98open",
                    "A7_1",
                    "A7_2",
                    "A7_3",
                    "A7_4",
                    "A7_98",
                    "A7_98open",
                    "A7_1_1",
                    "A7_1_2",
                    "A7_1_3",
                    "A7_1_4",
                    "A7_1_5",
                    "A7_1_98",
                    "A7_1_98open",
                    "A7_2_1",
                    "A7_2_2",
                    "A7_2_3",
                    "A7_2_4",
                    "A7_2_5",
                    "A7_2_6",
                    "A7_2_7",
                    "A7_2_8",
                    "A7_2_9",
                    "A7_2_98",
                    "A7_2_98open",
                    "A7_2_99",
                    "A7_3_1",
                    "A7_3_2",
                    "A7_3_3",
                    "A7_3_4",
                    "A7_3_5",
                    "A7_3_6",
                    "A7_3_7",
                    "A7_3_8",
                    "A7_3_9",
                    "A7_3_10",
                    "A7_3_98",
                    "A7_3_98open",
                    "A7_3_99",
                    "A7_4_1",
                    "A7_4_2",
                    "A7_4_3",
                    "A7_4_4",
                    "A7_4_5",
                    "A7_4_6",
                    "A7_4_7",
                    "A7_4_8",
                    "A7_4_98",
                    "A7_4_98open",
                    "A7_4_99"
            };

            List<String> listNew = new ArrayList<String>();

            for (MobileReportDetailBean s : list) {
                StringBuilder stringBuilder=new StringBuilder();
                stringBuilder.append(s.getStatMonth()).append(",")
                        .append(s.getUserId()).append(",")
                        .append(s.getParentnameL1()).append(",")
                        .append(s.getParentnameL2()).append(",")
                        .append(s.getParentnameL3()).append(",")
                        .append(s.getIsInter()).append(",")
                        .append(s.getIs5gPackage()).append(",")
                        .append(s.getIs5gkh()).append(",")
                        .append(s.getA6_1()).append(",")
                        .append(s.getA6_2()).append(",")
                        .append(s.getA6_3()).append(",")
                        .append(s.getA6_4()).append(",")
                        .append(s.getA6_5()).append(",")
                        .append(s.getA6_6()).append(",")
                        .append(s.getA6_7()).append(",")
                        .append(s.getA6_98()).append(",")
                        .append(s.getA6_98open()).append(",")
                        .append(s.getA7_1()).append(",")
                        .append(s.getA7_2()).append(",")
                        .append(s.getA7_3()).append(",")
                        .append(s.getA7_4()).append(",")
                        .append(s.getA7_98()).append(",")
                        .append(s.getA7_98open()).append(",")
                        .append(s.getA7_1_1()).append(",")
                        .append(s.getA7_1_2()).append(",")
                        .append(s.getA7_1_3()).append(",")
                        .append(s.getA7_1_4()).append(",")
                        .append(s.getA7_1_5()).append(",")
                        .append(s.getA7_1_98()).append(",")
                        .append(s.getA7_1_98open()).append(",")
                        .append(s.getA7_2_1()).append(",")
                        .append(s.getA7_2_2()).append(",")
                        .append(s.getA7_2_3()).append(",")
                        .append(s.getA7_2_4()).append(",")
                        .append(s.getA7_2_5()).append(",")
                        .append(s.getA7_2_6()).append(",")
                        .append(s.getA7_2_7()).append(",")
                        .append(s.getA7_2_8()).append(",")
                        .append(s.getA7_2_98()).append(",")
                        .append(s.getA7_2_98open()).append(",")
                        .append(s.getA7_2_99()).append(",")
                        .append(s.getA7_3_1()).append(",")
                        .append(s.getA7_3_2()).append(",")
                        .append(s.getA7_3_3()).append(",")
                        .append(s.getA7_3_4()).append(",")
                        .append(s.getA7_3_5()).append(",")
                        .append(s.getA7_3_6()).append(",")
                        .append(s.getA7_3_7()).append(",")
                        .append(s.getA7_3_8()).append(",")
                        .append(s.getA7_3_9()).append(",")
                        .append(s.getA7_3_98()).append(",")
                        .append(s.getA7_3_98open()).append(",")
                        .append(s.getA7_3_9()).append(",")
                        .append(s.getA7_3_99()).append(",").append(s.getA7_4_1()).append(",").append(s.getA7_4_2()).append(",").append(s.getA7_4_3())
                        .append(s.getA7_4_4())
                        .append(s.getA7_4_5())
                        .append(s.getA7_4_6())
                        .append(s.getA7_4_7())
                        .append(s.getA7_4_8())
                        .append(s.getA7_4_98())
                        .append(s.getA7_4_98open())
                        .append(s.getA7_4_99());

                listNew.add(stringBuilder.toString());
            }
            XSSFWorkbook wb = this.outExcel(tableName, headArr, listNew);
            OutputStream os = response.getOutputStream();
            tableName = URLEncoder.encode(tableName, "UTF-8");
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-disposition", "attachment;filename=" + tableName);
            response.setHeader("Pragma", "No-cache");
            wb.write(os);
            os.close();
        } catch (IOException e) {
            logger.error(e.toString());
            e.printStackTrace();
        }

    }

    private XSSFWorkbook outExcel(String tableName, String[] headArr, List<String> dataList){
        int cellWidth = 2340;//单元格宽度
        short cellHeight = (short)260;//单元格高度
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFRow row = null;
        XSSFCell cell = null;
        XSSFSheet sheet= wb.createSheet(tableName);
        row = sheet.createRow(0);
        row.setHeight(cellHeight);//设置单元格高度
        for(int i = 0; i < headArr.length; i++){
            cell = row.createCell(i);
            sheet.setColumnWidth(i, cellWidth);//设置sheet单元格宽度
            cell.setCellValue(headArr[i]);
        }
        for(int i = 0; i < dataList.size(); i++){
            String[] dataArr = dataList.get(i).split(",");
            row = sheet.createRow(i + 1);
            row.setHeight(cellHeight);//设置单元格高度
            for(int j = 0; j < dataArr.length; j++){
                cell = row.createCell(j);
                sheet.setColumnWidth(j, cellWidth);//设置sheet单元格宽度
                cell.setCellValue(dataArr[j]);
            }
        }
        return wb;
    }
   // 获取手机报表明细数据
    private List<MobileReportDetailBean> getMobileReportDetail(String time, String city, String type) {
        List<MobileReportDetailBean>list=new ArrayList<>();
        Connection connection=null;
        PreparedStatement ps = null;
        PreparedStatement ps2 = null;
        CallableStatement cstmt=null;
        ResultSet rs = null;
        ResultSet rs2 = null;
        try {
            long start = System.currentTimeMillis();
//            connection = DBUtilMySql.getConnection();
            connection = DBUtilMySql.getConnection();
            //1.设置为不自动提交数据
            StringBuilder sql=new StringBuilder();
            StringBuilder stringBuilder = new StringBuilder();
            sql.append("select * from mkt_dtl_grp_survey_phone_sjsw_mon where STAT_MONTH = ?");
            ps = connection.prepareStatement(sql.toString());
            ps.setInt(1, Integer.parseInt(time));

            stringBuilder.append(" select orgalevel from cas_crm_mm_org_rel_day where orgaid = ? and stat_date = (select max(stat_date) from cas_crm_mm_org_rel_day )");
            ps2 = connection.prepareStatement(stringBuilder.toString());
            ps2.setInt(1, Integer.parseInt(city));
            rs2 = ps2.executeQuery();
            String level = null;
            while (rs2.next()) {
                 level = rs2.getString("orgalevel");
            }
            int i = Integer.parseInt(level) + 1;
            String s = String.valueOf(i);
            if (!city.equals("2000250")) {
                sql.append(" and PARENTID_L"+s +"=?");
                ps = connection.prepareStatement(sql.toString());
                ps.setInt(1, Integer.parseInt(time));
                ps.setInt(2, Integer.parseInt(city));
            }
            rs = ps.executeQuery();
            while (rs.next()) {
                MobileReportDetailBean mobileReportDetailBean = new MobileReportDetailBean();
                mobileReportDetailBean.setA1(rs.getString("A1"));
                mobileReportDetailBean.setA2(rs.getString("A2"));
                mobileReportDetailBean.setA3(rs.getString("A3"));
                mobileReportDetailBean.setA4(rs.getString("A4"));
                mobileReportDetailBean.setA5(rs.getString("A5"));
                mobileReportDetailBean.setA6_1(rs.getString("A6_1"));
                mobileReportDetailBean.setA6_2(rs.getString("A6_2"));
                mobileReportDetailBean.setA6_3(rs.getString("A6_3"));
                mobileReportDetailBean.setA6_4(rs.getString("A6_4"));
                mobileReportDetailBean.setA6_5(rs.getString("A6_5"));
                mobileReportDetailBean.setA6_6(rs.getString("A6_6"));
                mobileReportDetailBean.setA6_7(rs.getString("A6_7"));
                mobileReportDetailBean.setA6_98(rs.getString("A6_98"));
                mobileReportDetailBean.setA6_98open(rs.getString("A6_98open"));
                mobileReportDetailBean.setA7_1(rs.getString("A7_1"));
                mobileReportDetailBean.setA7_2(rs.getString("A7_2"));
                mobileReportDetailBean.setA7_3(rs.getString("A7_3"));
                mobileReportDetailBean.setA7_4(rs.getString("A7_4"));
                mobileReportDetailBean.setA7_98(rs.getString("A7_98"));
                mobileReportDetailBean.setA7_98open(rs.getString("A7_98open"));
                mobileReportDetailBean.setA7_1_1(rs.getString("A7_1_1"));
                mobileReportDetailBean.setA7_1_2(rs.getString("A7_1_2"));
                mobileReportDetailBean.setA7_1_3(rs.getString("A7_1_3"));
                mobileReportDetailBean.setA7_1_4(rs.getString("A7_1_4"));
                mobileReportDetailBean.setA7_1_5(rs.getString("A7_1_5"));
                mobileReportDetailBean.setA7_1_98(rs.getString("A7_1_98"));
                mobileReportDetailBean.setA7_1_98open(rs.getString("A7_1_98open"));
                mobileReportDetailBean.setA7_2_1(rs.getString("A7_2_1"));
                mobileReportDetailBean.setA7_2_2(rs.getString("A7_2_2"));
                mobileReportDetailBean.setA7_2_3(rs.getString("A7_2_3"));
                mobileReportDetailBean.setA7_2_4(rs.getString("A7_2_4"));
                mobileReportDetailBean.setA7_2_5(rs.getString("A7_2_5"));
                mobileReportDetailBean.setA7_2_6(rs.getString("A7_2_6"));
                mobileReportDetailBean.setA7_2_7(rs.getString("A7_2_7"));
                mobileReportDetailBean.setA7_2_8(rs.getString("A7_2_8"));
                mobileReportDetailBean.setA7_2_9(rs.getString("A7_2_9"));
                mobileReportDetailBean.setA7_2_98(rs.getString("A7_2_98"));
                mobileReportDetailBean.setA7_2_98open(rs.getString("A7_2_98open"));
                mobileReportDetailBean.setA7_3_1(rs.getString("A7_3_1"));
                mobileReportDetailBean.setA7_3_2(rs.getString("A7_3_2"));
                mobileReportDetailBean.setA7_3_3(rs.getString("A7_3_3"));
                mobileReportDetailBean.setA7_3_4(rs.getString("A7_3_4"));
                mobileReportDetailBean.setA7_3_5(rs.getString("A7_3_5"));
                mobileReportDetailBean.setA7_3_6(rs.getString("A7_3_6"));
                mobileReportDetailBean.setA7_3_7(rs.getString("A7_3_7"));
                mobileReportDetailBean.setA7_3_8(rs.getString("A7_3_8"));
                mobileReportDetailBean.setA7_3_9(rs.getString("A7_3_9"));
                mobileReportDetailBean.setA7_3_10(rs.getString("A7_3_10"));
                mobileReportDetailBean.setA7_3_98(rs.getString("A7_3_98"));
                mobileReportDetailBean.setA7_3_98open(rs.getString("A7_3_98open"));
                mobileReportDetailBean.setA7_3_99(rs.getString("A7_3_99"));
                mobileReportDetailBean.setA7_4_1(rs.getString("A7_4_1"));
                mobileReportDetailBean.setA7_4_2(rs.getString("A7_4_2"));
                mobileReportDetailBean.setA7_4_3(rs.getString("A7_4_3"));
                mobileReportDetailBean.setA7_4_4(rs.getString("A7_4_4"));
                mobileReportDetailBean.setA7_4_5(rs.getString("A7_4_5"));
                mobileReportDetailBean.setA7_4_6(rs.getString("A7_4_6"));
                mobileReportDetailBean.setA7_4_7(rs.getString("A7_4_7"));
                mobileReportDetailBean.setA7_4_8(rs.getString("A7_4_8"));
                mobileReportDetailBean.setA7_4_98(rs.getString("A7_4_98"));
                mobileReportDetailBean.setA7_4_98open(rs.getString("A7_4_98open"));
                mobileReportDetailBean.setA7_4_99(rs.getString("A7_4_99"));
                mobileReportDetailBean.setStatMonth(rs.getInt("STAT_MONTH"));




                mobileReportDetailBean.setUserId(rs.getLong("user_id"));
                mobileReportDetailBean.setParentnameL1(rs.getString("PARENTNAME_L1"));
                mobileReportDetailBean.setParentnameL2(rs.getString("PARENTNAME_L2"));
                mobileReportDetailBean.setParentnameL3(rs.getString("PARENTNAME_L3"));
                mobileReportDetailBean.setIsInter(rs.getInt("IS_INTER"));
                mobileReportDetailBean.setIs5gkh(rs.getString("IS_5GKH"));
                mobileReportDetailBean.setIs5gPackage(rs.getString("IS_5G_package"));
                list.add(mobileReportDetailBean);
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            DBUtilMySql.close(connection, ps, rs);
        }
        return  null ;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值