springboot导出cvs

public ApiResultI18n exportDeviceManReport(HttpServletResponse response,@RequestBody ReportPartBean reportPartBean,HttpServletRequest httpServletRequest) {
        String language =httpServletRequest.getHeader("language");
        List<Map<String, Object>> dataList = null;
        List<DeviceManReportBean> deviceList = reportService.exportDeviceManReport(reportPartBean);// 查询到要导出的信息
        if (deviceList.size() == 0) {
            return ApiResultI18n.myResponse(ResponseCodeI18n.NO_DATA_EXPORT,null,language);
            //return ResultUtil.error(301,"无数据导出!");
        }
        String fName = "设备管理_";
        String sTitle = "设备号,设备名称,绑定人,绑定时间,产品组,大区,国家,代理商";
        if("en_US".equals(language)){
            fName = "DeviceManagement_";
            sTitle = "Device number,Device name,Binding user,Last binding,Device type,Region,Country,Dealer";
        }
        String mapKey = "deviceNum,deviceName,userMobile,bindingTime,prodGroupDesc,regionDesc,countryDesc,agentDesc";
        dataList = new ArrayList<>();
        Map<String, Object> map = null;
        for (DeviceManReportBean de : deviceList) {
            map = new HashMap<>();
            map.put("deviceNum", de.getDeviceNum());
            map.put("deviceName", de.getDeviceName());
            map.put("userMobile", de.getUserMobile()==null?"":de.getUserMobile());
            if(null!=de.getBindingTime() && !" ".equals(de.getBindingTime())){
                map.put("bindingTime", DateFormatUtils.format(de.getBindingTime(), "yyyy-MM-dd HH:mm:ss"));
            }else{
                map.put("bindingTime", de.getBindingTime()==null?"":de.getBindingTime());
            }
            map.put("prodGroupDesc", de.getProdGroupDesc());
            map.put("regionDesc", de.getRegionDesc());
            map.put("countryDesc", de.getCountryDesc());
            map.put("agentDesc", de.getAgentDesc());
            //map.put("createDate", DateFormatUtils.format(order.getCreateDate(), "yyyy/MM/dd HH:mm"));
            dataList.add(map);
        }
        try (final OutputStream os = response.getOutputStream()) {
            ExportUtil.responseSetProperties(fName, response);
            ExportUtil.doExport(dataList, sTitle, mapKey, os);
            return null;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ApiResultI18n.myResponse(ResponseCodeI18n.Data_Export_Error,null,language);
        //return ResultUtil.error(302,"数据导出出错!");
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值