Search in sources :

Example 1 with ExcelFileGenerator

use of com.itrus.portal.utils.ExcelFileGenerator in project portal by ixinportal.

the class TakeBillController method excelExport.

/**
 * @param serviceClientId
 * @param statPeriod
 * @param queryDate1
 * @param queryDate2
 * @param
 * @param userGe
 * @param accountingStrategy
 * @param request
 * @param response
 * @return
 */
@RequestMapping("/excel")
public String excelExport(@RequestParam(value = "appId", required = false) Long appId, @RequestParam(value = "serviceClientId", required = false) Long serviceClientId, @RequestParam(value = "statPeriod", required = false) Long statPeriod, @RequestParam(value = "months", required = false) Long months, @RequestParam(value = "quarters", required = false) Long quarters, @RequestParam(value = "queryDate1", required = false) Integer queryDate1, @RequestParam(value = "queryDate2", required = false) Integer queryDate2, @RequestParam(value = "userGe", required = false) Long userGe, @RequestParam(value = "accountingStrategy", required = false) Long accountingStrategy, HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
    boolean isEmpty = false;
    String serviceName = new String((request.getParameter("serviceName")).getBytes("ISO-8859-1"), "UTF-8");
    Map<String, Object> param = new HashMap<>();
    // 应用id
    if (appId != null) {
        param.put("appId", appId);
    }
    // 服务委托人
    if (serviceClientId != null) {
        param.put("serviceClientId", serviceClientId);
    }
    // 统计周期
    if (null != statPeriod) {
        param.put("period", statPeriod);
    } else {
        param.put("period", 1);
    }
    // 月份 当统计周期为月的时候
    if (null != months) {
        param.put("months", months);
    }
    // 季度 当统计周期为季度的时候
    if (null != quarters) {
        param.put("quarters", quarters);
    }
    // 统计时间 默认从2017年开始有计费服务
    if (null != queryDate1) {
        param.put("queryDate1", queryDate1);
    }
    if (null != queryDate2) {
        param.put("queryDate2", queryDate2);
    } else {
        param.put("queryDate2", 2017);
    }
    // 服务名称
    if (serviceName != null && !"".equals(serviceName)) {
        param.put("serviceName", "%" + serviceName + "%");
    }
    // 使用用途
    if (null != userGe) {
        param.put("userGe", userGe);
    }
    // 计费策略
    if (null != accountingStrategy) {
        param.put("accountingStrategy", accountingStrategy);
    }
    // 存证
    param.put("chargingType", ComNames.SERVICE_TYPE_TAKE);
    // 查询服务名称信息,无返回 返回空界面
    List<Long> serviceLists = sqlSession.selectList("com.itrus.portal.db.ChargingMapper.selectStoreServiceId", param);
    if (serviceLists != null && serviceLists.size() > 0) {
        param.put("serviceLists", serviceLists);
    } else {
        isEmpty = true;
    }
    String connSql = chargService.connSql(statPeriod, new Long(queryDate1), new Long(queryDate2));
    param.put("connSql", connSql);
    List<Map<String, Object>> cAll = sqlSession.selectList("com.itrus.portal.db.ChargingMapper.selectStoreByCondition", param);
    cAll = chargService.explainBillService(cAll);
    cAll = chargService.explainTakeBillCode(cAll);
    if (cAll != null && cAll.size() > 0) {
        // 增加总计行
        cAll = chargService.addBillTotalRow(cAll);
    }
    if (!isEmpty) {
        // 创建excel标头
        ArrayList<String> fildName = chargService.excelStoreBillFildName(statPeriod);
        // 导入内容
        ArrayList<ArrayList<String>> excelFildData = chargService.excelStoreFildData(cAll);
        ExcelFileGenerator generator = new ExcelFileGenerator(fildName, excelFildData);
        try {
            // 重置response对象中的缓冲区,该方法可以不写,但是你要保证response缓冲区没有其他数据,否则导出可能会出现问题,建议加上
            response.reset();
            String filename = "出证服务账单" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + // 设置下载时客户端Excel的名称,此处需要用到encodeFilename()方法来转换编码,否则中文会被过滤掉
            ".xls";
            filename = generator.encodeFilename(filename, request);
            response.setHeader("Content-disposition", "attachment;filename=" + filename);
            response.setCharacterEncoding("utf-8");
            // 由于导出格式是excel的文件,设置导出文件的响应头部信息
            response.setContentType("application/vnd.ms-excel");
            // 生成excel,传递输出流
            // 用response对象获取输出流
            OutputStream os = response.getOutputStream();
            generator.expordExcel(os);
            // 清理刷新缓冲区,将缓存中的数据将数据导出excel
            os.flush();
            // 关闭os
            if (os != null) {
                os.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : OutputStream(java.io.OutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExcelFileGenerator(com.itrus.portal.utils.ExcelFileGenerator) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ExcelFileGenerator

use of com.itrus.portal.utils.ExcelFileGenerator in project portal by ixinportal.

the class PayController method excelExport.

// 导出Excel
@RequestMapping(value = "/excel")
public String excelExport(@RequestParam(value = "sn2", required = false) String sn2, @RequestParam(value = "queryDate12", required = false) Date queryDate12, @RequestParam(value = "queryDate22", required = false) Date queryDate22, @RequestParam(value = "queryDate32", required = false) Date queryDate32, @RequestParam(value = "queryDate42", required = false) Date queryDate42, @RequestParam(value = "projectname2", required = false) String projectname2, @RequestParam(value = "entname2", required = false) String entname2, @RequestParam(value = "way2", required = false) Integer way2, HttpServletRequest request, HttpServletResponse response) {
    Map param = new HashMap();
    // 管理员项目权限
    Long[] projectsOfAdmin = getProjectLongIdsOfAdmin();
    param.put("hasProjects", Arrays.asList(projectsOfAdmin));
    // page,size
    if (StringUtils.isNotEmpty(sn2)) {
        param.put("sn", "%" + sn2 + "%");
    }
    if (way2 != null) {
        if ((int) way2 > 0) {
            param.put("way", way2);
            param.put("payStatus", 1);
        } else {
            param.put("way", way2);
        }
    } else {
        param.put("way", way2);
    }
    param.put("queryDate1", queryDate12);
    param.put("queryDate2", queryDate22);
    param.put("queryDate3", queryDate32);
    param.put("queryDate4", queryDate42);
    if (StringUtils.isNotEmpty(projectname2)) {
        param.put("projectname", "%" + projectname2 + "%");
    }
    if (StringUtils.isNotEmpty(entname2)) {
        param.put("entname", "%" + entname2 + "%");
    }
    param.put("pay_true", 1);
    param.put("status1", 1);
    param.put("desc", 1);
    List<Map> billexall = sqlSession.selectList("com.itrus.portal.db.BillMapper.selectByCondition", param);
    ArrayList<String> fieldName = payService.excelFildName();
    ArrayList<ArrayList<String>> fieldDatas = payService.excelFildData(billexall);
    ExcelFileGenerator generator = new ExcelFileGenerator(fieldName, fieldDatas);
    try {
        // 重置response对象中的缓冲区,该方法可以不写,但是你要保证response缓冲区没有其他数据,否则导出可能会出现问题,建议加上
        response.reset();
        String filename = "支付记录信息" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + // 设置下载时客户端Excel的名称,此处需要用到encodeFilename()方法来转换编码,否则中文会被过滤掉
        ".xls";
        filename = generator.encodeFilename(filename, request);
        response.setHeader("Content-disposition", "attachment;filename=" + filename);
        response.setCharacterEncoding("utf-8");
        // 由于导出格式是excel的文件,设置导出文件的响应头部信息
        response.setContentType("application/vnd.ms-excel");
        // 生成excel,传递输出流
        // 用response对象获取输出流
        OutputStream os = response.getOutputStream();
        generator.expordExcel(os);
        // 清理刷新缓冲区,将缓存中的数据将数据导出excel
        os.flush();
        // 关闭os
        if (os != null) {
            os.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Date(java.util.Date) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ExcelFileGenerator(com.itrus.portal.utils.ExcelFileGenerator) Map(java.util.Map) HashMap(java.util.HashMap) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ExcelFileGenerator

use of com.itrus.portal.utils.ExcelFileGenerator in project portal by ixinportal.

the class PsCourierController method excelExport.

// 导出Excel
@RequestMapping(value = "/excel")
public String excelExport(@RequestParam(value = "sn", required = false) String sn, @RequestParam(value = "projectname", required = false) String projectname, @RequestParam(value = "entname", required = false) String entname, @RequestParam(value = "cost", required = false) Integer cost, @RequestParam(value = "queryDate1", required = false) Date queryDate1, @RequestParam(value = "queryDate2", required = false) Date queryDate2, HttpServletRequest request, HttpServletResponse response) {
    Map param = new HashMap();
    // 管理员项目权限
    Long[] projectsOfAdmin = getProjectLongIdsOfAdmin();
    param.put("hasProjects", Arrays.asList(projectsOfAdmin));
    if (StringUtils.isNotEmpty(sn)) {
        param.put("sn", "%" + sn + "%");
    }
    if (StringUtils.isNotEmpty(projectname)) {
        param.put("projectname", "%" + projectname + "%");
    }
    if (StringUtils.isNotEmpty(entname)) {
        param.put("entname", "%" + entname + "%");
    }
    param.put("cost", cost);
    param.put("queryDate1", queryDate1);
    param.put("queryDate2", queryDate2);
    List<Map> billexall = sqlSession.selectList("com.itrus.portal.db.BillMapper.selectExcelByPsCourier", param);
    ArrayList<String> fieldName = psCourierService.excelFildName();
    ArrayList<ArrayList<String>> fieldDatas = psCourierService.excelFildData(billexall);
    ExcelFileGenerator generator = new ExcelFileGenerator(fieldName, fieldDatas);
    try {
        // 重置response对象中的缓冲区,该方法可以不写,但是你要保证response缓冲区没有其他数据,否则导出可能会出现问题,建议加上
        response.reset();
        String filename = "快递配送信息" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + // 设置下载时客户端Excel的名称,此处需要用到encodeFilename()方法来转换编码,否则中文会被过滤掉
        ".xls";
        filename = generator.encodeFilename(filename, request);
        response.setHeader("Content-disposition", "attachment;filename=" + filename);
        response.setCharacterEncoding("utf-8");
        // 由于导出格式是excel的文件,设置导出文件的响应头部信息
        response.setContentType("application/vnd.ms-excel");
        // 生成excel,传递输出流
        // 用response对象获取输出流
        OutputStream os = response.getOutputStream();
        generator.expordExcel(os);
        // 清理刷新缓冲区,将缓存中的数据将数据导出excel
        os.flush();
        // 关闭os
        if (os != null) {
            os.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Date(java.util.Date) ExcelFileGenerator(com.itrus.portal.utils.ExcelFileGenerator) Map(java.util.Map) HashMap(java.util.HashMap) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ExcelFileGenerator

use of com.itrus.portal.utils.ExcelFileGenerator in project portal by ixinportal.

the class AuthenticationstatisticsController method excelExport.

// 导出Excel
@RequestMapping(value = "/excel")
public String excelExport(@RequestParam(value = "applyname", required = false) String applyname, @RequestParam(value = "Statistics", required = false) Integer Statistics, @RequestParam(value = "year1", required = false) Integer year1, @RequestParam(value = "year2", required = false) Integer year2, @RequestParam(value = "serviceclass", required = false) Long serviceclass, @RequestParam(value = "appServiceName", required = false) String appServiceName, @RequestParam(value = "serviceAuthenticationItem", required = false) String serviceAuthenticationItem, @RequestParam(value = "serviceAuthentication", required = false) String serviceAuthentication, @RequestParam(value = "authenticationResultMessage", required = false) Integer authenticationResultMessage, @RequestParam(value = "checkNumber", required = false) Double checkNumber, Model uiModel, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map param = new HashMap();
    Map param2 = new HashMap();
    Integer year3 = null;
    if (year1 != null) {
        year3 = year1;
    }
    List<Map> RealNameList = new ArrayList<>();
    List<Map<Integer, Integer>> list = new ArrayList<Map<Integer, Integer>>();
    java.util.Date nowdate = new java.util.Date();
    String[] monthList = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };
    String[] seasonList = { "S1", "S2", "S3", "S4" };
    String month = null;
    String season = null;
    String year = null;
    Calendar calendar = Calendar.getInstance();
    Calendar calendar2 = Calendar.getInstance();
    String applyname1 = null;
    if (null != Statistics && Statistics == 12) {
        while (year1 <= year2) {
            for (int j = 0; j <= 11; j++) {
                calendar.set(Calendar.YEAR, year1);
                calendar.set(Calendar.MONTH, j);
                calendar.set(Calendar.DAY_OF_MONTH, 1);
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.MILLISECOND, 0);
                Date dt1 = calendar.getTime();
                calendar2.set(Calendar.YEAR, year1);
                calendar2.set(Calendar.MONTH, j + 1);
                calendar2.set(Calendar.DAY_OF_MONTH, 1);
                calendar2.set(Calendar.HOUR_OF_DAY, 0);
                calendar2.set(Calendar.MINUTE, 0);
                calendar2.set(Calendar.SECOND, 0);
                calendar2.set(Calendar.MILLISECOND, 0);
                Date dt2 = calendar2.getTime();
                if (applyname != null && !"0".equals(applyname)) {
                    param.put("applyname", applyname);
                }
                if (StringUtils.isNotEmpty(appServiceName)) {
                    param.put("appServiceName", appServiceName);
                }
                if (serviceclass == 0) {
                    if (serviceAuthenticationItem != null && !"0".equals(serviceAuthenticationItem)) {
                        param.put("serviceAuthenticationItem", "%" + serviceAuthenticationItem + "%");
                    } else {
                        param.put("serviceAuthenticationItem", null);
                    }
                } else {
                    if (serviceAuthentication != null && !"0".equals(serviceAuthentication)) {
                        param.put("serviceAuthenticationItem", "%" + serviceAuthentication + "%");
                    } else {
                        param.put("serviceAuthenticationItem", null);
                    }
                }
                if (authenticationResultMessage != null && authenticationResultMessage >= 0) {
                    param.put("authenticationResultMessage", authenticationResultMessage);
                } else {
                    param.put("authenticationResultMessage", null);
                }
                if (checkNumber != null && checkNumber > 0) {
                    param.put("checkNumber", checkNumber);
                } else {
                    param.put("checkNumber", null);
                }
                if (serviceclass >= 0) {
                    param.put("serviceclass", serviceclass);
                }
                param.put("serviceclass", null);
                month = year1 + "-" + monthList[j];
                param2.put("month", month);
                param.put("queryDate1", dt1);
                param.put("queryDate2", dt2);
                Integer count1 = null;
                Integer count = null;
                if (serviceclass == 0) {
                    count = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod", param);
                    count1 = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod1", param);
                    RealNameList = realNameService.selectListByRealNameRecordEnt1(param);
                    for (int i = 0; i < RealNameList.size(); i++) {
                        serviceAuthenticationItem = RealNameList.get(i).get("service_authentication_item").toString();
                    }
                } else if (serviceclass == 1) {
                    count = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod", param);
                    count1 = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod1", param);
                    RealNameList = personalNameService.selectListByRealNameRecordEnt1(param);
                    for (int i = 0; i < RealNameList.size(); i++) {
                        serviceAuthentication = RealNameList.get(i).get("service_authentication_item").toString();
                    }
                } else if (serviceclass == 2) {
                    Integer rcount1 = null;
                    Integer rcount = null;
                    Integer pcount1 = null;
                    Integer pcount = null;
                    rcount = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod", param);
                    rcount1 = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod1", param);
                    pcount = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod", param);
                    pcount1 = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod1", param);
                    count = rcount + pcount;
                    count1 = rcount1 + pcount1;
                }
                Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                map.put(1, year1);
                map.put(2, count);
                map.put(3, count1);
                list.add(map);
            // }
            }
            year1++;
        }
    }
    if (null != Statistics && Statistics == 4) {
        while (year1 <= year2) {
            for (int j = 0; j <= 9; j = j + 3) {
                calendar.set(Calendar.YEAR, year1);
                calendar.set(Calendar.MONTH, j);
                calendar.set(Calendar.DAY_OF_MONTH, 1);
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.MILLISECOND, 0);
                Date dt1 = calendar.getTime();
                calendar2.set(Calendar.YEAR, year1);
                calendar2.set(Calendar.MONTH, j + 3);
                calendar2.set(Calendar.DAY_OF_MONTH, 1);
                calendar2.set(Calendar.HOUR_OF_DAY, 0);
                calendar2.set(Calendar.MINUTE, 0);
                calendar2.set(Calendar.SECOND, 0);
                calendar2.set(Calendar.MILLISECOND, 0);
                Date dt2 = calendar2.getTime();
                if (applyname != null && !"0".equals(applyname)) {
                    param.put("applyname", applyname);
                }
                if (StringUtils.isNotEmpty(appServiceName)) {
                    param.put("appServiceName", appServiceName);
                }
                if (serviceAuthenticationItem != null && !"0".equals(serviceAuthenticationItem)) {
                    param.put("serviceAuthenticationItem", "%" + serviceAuthenticationItem + "%");
                } else {
                    param.put("serviceAuthenticationItem", null);
                }
                if (authenticationResultMessage != null && authenticationResultMessage >= 0) {
                    param.put("authenticationResultMessage", authenticationResultMessage);
                } else {
                    param.put("authenticationResultMessage", null);
                }
                if (checkNumber != null && checkNumber > 0) {
                    param.put("checkNumber", checkNumber);
                } else {
                    param.put("checkNumber", null);
                }
                if (serviceclass >= 0) {
                    param.put("serviceclass", serviceclass);
                }
                param.put("serviceclass", null);
                season = year1 + "-" + monthList[j / 3];
                param2.put("season", season);
                param.put("queryDate1", dt1);
                param.put("queryDate2", dt2);
                Integer count1 = null;
                Integer count = null;
                if (serviceclass == 0) {
                    count = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod", param);
                    count1 = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod1", param);
                    RealNameList = realNameService.selectListByRealNameRecordEnt1(param);
                } else if (serviceclass == 1) {
                    count = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod", param);
                    count1 = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod1", param);
                    RealNameList = personalNameService.selectListByRealNameRecordEnt1(param);
                } else if (serviceclass == 2) {
                    Integer rcount1 = null;
                    Integer rcount = null;
                    Integer pcount1 = null;
                    Integer pcount = null;
                    rcount = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod", param);
                    rcount1 = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod1", param);
                    pcount = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod", param);
                    pcount1 = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod1", param);
                    count = rcount + pcount;
                    count1 = rcount1 + pcount1;
                }
                Map<Integer, Integer> map = new HashMap<Integer, Integer>();
                map.put(1, year1);
                map.put(2, count);
                map.put(3, count1);
                list.add(map);
            }
            year1++;
        }
    }
    if (null != Statistics && Statistics == 1) {
        while (year1 <= year2) {
            calendar.set(Calendar.YEAR, year1);
            calendar.set(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            Date dt1 = calendar.getTime();
            calendar2.set(Calendar.YEAR, year1 + 1);
            calendar2.set(Calendar.MONTH, 0);
            calendar2.set(Calendar.DAY_OF_MONTH, 1);
            calendar2.set(Calendar.HOUR_OF_DAY, 0);
            calendar2.set(Calendar.MINUTE, 0);
            calendar2.set(Calendar.SECOND, 0);
            calendar2.set(Calendar.MILLISECOND, 0);
            Date dt2 = calendar2.getTime();
            if (applyname != null && !"0".equals(applyname)) {
                param.put("applyname", applyname);
            }
            if (StringUtils.isNotEmpty(appServiceName)) {
                param.put("appServiceName", appServiceName);
            }
            if (serviceAuthenticationItem != null && !"0".equals(serviceAuthenticationItem)) {
                param.put("serviceAuthenticationItem", "%" + serviceAuthenticationItem + "%");
            } else {
                param.put("serviceAuthenticationItem", null);
            }
            if (authenticationResultMessage != null && authenticationResultMessage >= 0) {
                param.put("authenticationResultMessage", authenticationResultMessage);
            } else {
                param.put("authenticationResultMessage", null);
            }
            if (checkNumber != null && checkNumber > 0) {
                param.put("checkNumber", checkNumber);
            } else {
                param.put("checkNumber", null);
            }
            if (serviceclass >= 0) {
                param.put("serviceclass", serviceclass);
            }
            param.put("serviceclass", null);
            year = year + "Y";
            param2.put("year", year);
            param.put("queryDate1", dt1);
            param.put("queryDate2", dt2);
            Integer count1 = null;
            Integer count = null;
            if (serviceclass == 0) {
                count = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod", param);
                count1 = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod1", param);
                RealNameList = realNameService.selectListByRealNameRecordEnt1(param);
            } else if (serviceclass == 1) {
                count = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod", param);
                count1 = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod1", param);
                RealNameList = personalNameService.selectListByRealNameRecordEnt1(param);
            } else if (serviceclass == 2) {
                Integer rcount1 = null;
                Integer rcount = null;
                Integer pcount1 = null;
                Integer pcount = null;
                rcount = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod", param);
                rcount1 = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectCountByPeriod1", param);
                pcount = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod", param);
                pcount1 = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectCountByPeriod1", param);
                count = rcount + pcount;
                count1 = rcount1 + pcount1;
                RealNameList = personalNameService.selectListByRealNameRecordEnt1(param);
            }
            Map<Integer, Integer> map = new HashMap<Integer, Integer>();
            map.put(1, year1);
            map.put(2, count);
            map.put(3, count1);
            list.add(map);
            year1++;
        }
    }
    Map param3 = new HashMap();
    if (null == applyname || "0".equals(applyname)) {
        applyname = "所有应用";
    }
    if (null == appServiceName || "" == appServiceName) {
        appServiceName = "所有服务";
    }
    String authenticationResultMessage1 = null;
    String checkNumber1 = null;
    for (int j = 0; j < RealNameList.size(); j++) {
        authenticationResultMessage1 = RealNameList.get(j).get("authentication_result_message").toString();
        authenticationResultMessage = Integer.parseInt(authenticationResultMessage1);
        checkNumber1 = RealNameList.get(j).get("check_number").toString();
        checkNumber = Double.parseDouble(checkNumber1);
    }
    checkNumber = checkNumber * 100;
    ArrayList<String> fieldName = authenticationstacsService.excelFieldName();
    String serviceclass1 = serviceclass.toString();
    ArrayList<ArrayList<String>> fieldDatas = authenticationstacsService.excelFieldData(list, applyname, appServiceName, serviceAuthenticationItem, authenticationResultMessage, checkNumber, Statistics, serviceclass1, RealNameList);
    ExcelFileGenerator generator = new ExcelFileGenerator(fieldName, fieldDatas);
    try {
        // 重置response对象中的缓冲区,该方法可以不写,但是你要保证response缓冲区没有其他数据,否则导出可能会出现问题,建议加上
        response.reset();
        // 设置下载时客户端Excel的名称,此处需要用到encodeFilename()方法来转换编码,否则中文会被过滤掉
        String filename = "实名验证统计信息" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
        filename = generator.encodeFilename(filename, request);
        response.setHeader("Content-disposition", "attachment;filename=" + filename);
        response.setCharacterEncoding("utf-8");
        // 由于导出格式是excel的文件,设置导出文件的响应头部信息
        response.setContentType("application/vnd.ms-excel");
        // 生成excel,传递输出流
        // 用response对象获取输出流
        OutputStream os = response.getOutputStream();
        generator.expordExcel(os);
        // 清理刷新缓冲区,将缓存中的数据将数据导出excel
        os.flush();
        // 关闭os
        if (os != null) {
            os.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : HashMap(java.util.HashMap) Date(java.util.Date) Calendar(java.util.Calendar) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Date(java.util.Date) ExcelFileGenerator(com.itrus.portal.utils.ExcelFileGenerator) HashMap(java.util.HashMap) Map(java.util.Map) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ExcelFileGenerator

use of com.itrus.portal.utils.ExcelFileGenerator in project portal by ixinportal.

the class BillController method excelEx.

// 导出Excel
@RequestMapping(value = "/excelEx")
public String excelEx(@RequestParam(value = "sn", required = false) String sn, @RequestParam(value = "projectname", required = false) String projectname, @RequestParam(value = "entname", required = false) String entname, @RequestParam(value = "cost", required = false) Integer cost, @RequestParam(value = "queryDate1", required = false) Date queryDate1, @RequestParam(value = "queryDate2", required = false) Date queryDate2, @RequestParam(value = "type1", required = false) Integer type1, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "phone", required = false) String phone, @RequestParam(value = "status", required = false) Integer status, HttpServletRequest request, HttpServletResponse response) {
    Map param = new HashMap();
    // 管理员项目权限
    Long[] projectsOfAdmin = getProjectLongIdsOfAdmin();
    param.put("hasProjects", Arrays.asList(projectsOfAdmin));
    if (StringUtils.isNotEmpty(sn)) {
        param.put("sn", "%" + sn + "%");
    }
    param.put("queryDate1", queryDate1);
    param.put("queryDate2", queryDate2);
    if (StringUtils.isNotEmpty(projectname) && projectname.contains("宁波")) {
        param.put("projectname", "%" + projectname + "%");
    }
    if (StringUtils.isNotEmpty(entname)) {
        param.put("entname", "%" + entname + "%");
    }
    param.put("type", type1);
    if (StringUtils.isNotEmpty(name)) {
        param.put("name", "%" + name + "%");
    }
    if (StringUtils.isNotEmpty(phone)) {
        param.put("phone", "%" + phone + "%");
    }
    param.put("status", status);
    param.put("desc", 1);
    List<Map> billexall = sqlSession.selectList("com.itrus.portal.db.BillMapper.selectBycertInfo", param);
    ArrayList<String> fieldName = billservice.excelCertName();
    ArrayList<ArrayList<String>> fieldDatas = billservice.excelCertData(billexall);
    ExcelFileGenerator generator = new ExcelFileGenerator(fieldName, fieldDatas);
    try {
        // 重置response对象中的缓冲区,该方法可以不写,但是你要保证response缓冲区没有其他数据,否则导出可能会出现问题,建议加上
        response.reset();
        // 设置下载时客户端Excel的名称,此处需要用到encodeFilename()方法来转换编码,否则中文会被过滤掉
        String filename = "用户信息" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
        filename = generator.encodeFilename(filename, request);
        response.setHeader("Content-disposition", "attachment;filename=" + filename);
        response.setCharacterEncoding("utf-8");
        // 由于导出格式是excel的文件,设置导出文件的响应头部信息
        response.setContentType("application/vnd.ms-excel");
        // 生成excel,传递输出流
        // 用response对象获取输出流
        OutputStream os = response.getOutputStream();
        generator.expordExcel(os);
        // 清理刷新缓冲区,将缓存中的数据将数据导出excel
        os.flush();
        // 关闭os
        if (os != null) {
            os.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : EncDecException(com.itrus.portal.exception.EncDecException) ExcelFileGenerator(com.itrus.portal.utils.ExcelFileGenerator) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ExcelFileGenerator (com.itrus.portal.utils.ExcelFileGenerator)17 SimpleDateFormat (java.text.SimpleDateFormat)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 OutputStream (java.io.OutputStream)12 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 HashMap (java.util.HashMap)10 Map (java.util.Map)10 EncDecException (com.itrus.portal.exception.EncDecException)4 Calendar (java.util.Calendar)4 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 BiffException (jxl.read.biff.BiffException)3 EvidenceBasicInformation (com.itrus.portal.db.EvidenceBasicInformation)2 java.util (java.util)2 RaServiceUnavailable_Exception (cn.topca.tca.ra.service.RaServiceUnavailable_Exception)1 JSONObject (com.alibaba.fastjson.JSONObject)1 AppConfig (com.itrus.portal.db.AppConfig)1 EvidenceOutTemplate (com.itrus.portal.db.EvidenceOutTemplate)1 MsgStatsRecord (com.itrus.portal.db.MsgStatsRecord)1