java使用EasyExcel 导出数据
·
java使用EasyExcel 导出数据
UI
1.按钮
<el-button type="primary" size="small" icon="el-icon-download" @click="downloadClearList" >
导出清算清单
</el-button>
2.方法
downloadClearList(){
this.downloadClearListVisible=!this.downloadClearListVisible
},
3.变量定义
downloadClearListVisible: false,
downloadClearListForm :{
item:'',
time:'',
},
4.弹窗
<el-dialog
title="导出清算清单"
:visible.sync="downloadClearListVisible"
:append-to-body="true"
:close-on-click-modal="false"
width="400px"
>
<el-form ref="downloadClearListForm" :inline="true" :model="downloadClearListForm" class="filter-container" label-width="60px">
<el-form-item label="项目" prop="item">
<el-select v-model="downloadClearListForm.item" style="width: 220px">
<el-option label="本级" value="1"></el-option>
<el-option label="越级" value="2"></el-option>
</el-select>
</el-form-item>
<el-form-item prop="time" label="月份">
<el-date-picker
v-model="downloadClearListForm.time"
type="month"
placeholder="选择月"
value-format="yyyy-MM">
</el-date-picker>
</el-form-item>
<el-form-item >
<el-button size="small" @click="downloadClearListFormCancel()">取消</el-button>
<el-button type="primary" size="small" @click="downloadClearListFormConfirm()">确认</el-button>
</el-form-item>
</el-form>
</el-dialog>
5.提交
//取消下载
downloadClearListFormCancel(){
this.downloadClearListVisible=!this.downloadClearListVisible
},
//确认下载
downloadClearListFormConfirm(){
let fileName ="excel.xlsx";
if (this.downloadClearListForm.item ==='1'){
fileName = "本级清算清单.xlsx"
}else {
fileName = "越级清算清单.xlsx"
}
downloadClearListFormConfirm({
item:this.downloadClearListForm.item,
time:this.downloadClearListForm.time,
}).then(response => {
this.downloadClearListVisible = false
this.$message.success('清算清单下载成功!')
const blob = new Blob([response], { type: 'application/vnd.ms-excel' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = fileName;
link.click();
URL.revokeObjectURL(link.href);
}).catch(e => {
this.downloadClearListVisible = false
this.$message.warning('清算清单下载失败!')
})
},
java
1.controller
/**
* @Author QiYingBo
* @Description //清算清单下载
* @Date 2024/10/25 10:15
* @param response
* @param map
**/
@PostMapping("/downloadClearList.do")
public void downloadClearList(HttpServletResponse response,@RequestBody Map<String,Object> map){
String item = "";
String time = "";
if (map.get("item") != null && !map.get("item").equals("")){
item =map.get("item").toString();
}
if (map.get("time") != null && !map.get("time").equals("")){
time =map.get("time").toString();
}
if (item.equals("1")){//本级
try {
String sheetName = "本级清算清单";
String fileName = "本级清算清单.xlsx";
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
List<ClearList1RespVo> dataList = pieceNumService.downloadClearList1(response, time);
EasyExcel.write(response.getOutputStream(), ClearList1RespVo.class)
.autoCloseStream(false)
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet(sheetName).doWrite(dataList);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else if (item.equals("2")) {//越级
try {
String sheetName = "越级清算清单";
String fileName = "越级清算清单.xlsx";
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
List<ClearList2RespVo> dataList = pieceNumService.downloadClearList2(response, time);
EasyExcel.write(response.getOutputStream(), ClearList2RespVo.class)
.autoCloseStream(false)
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet(sheetName).doWrite(dataList);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
2.vo
package usi.pieceNum.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.sql.Timestamp;
/**
* @author QiYingBo
* @version v1.0
* @ClassName ClearList1RespVo
* @Date: 2024/10/25 15:00
* @Description: 本级清算vo
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ExcelIgnoreUnannotated
public class ClearList1RespVo {
@ExcelProperty(value = "办结月份", index = 0)
private String month_time;
@ExcelProperty(value = "日期", index = 1)
private String day_time;
@ExcelProperty(value = "办结人工号", index = 2)
private String finish_user_id;
@ExcelProperty(value = "办结人姓名", index = 3)
private String finish_user_name;
@ExcelProperty(value = "办结人班组", index = 4)
private String post_name;
@ExcelProperty(value = "工单流水", index = 5)
private String busi_sheet_no;
@ExcelProperty(value = "留单类型", index = 6)
private String comp_type_name;
@ExcelProperty(value = "办结方式", index = 7)
private String finish_type_name;
@ExcelProperty(value = "所发送的短信模板", index = 8)
private String sent_sms_template;
@ExcelProperty(value = "计件项目", index = 9)
private String piece_name;
@ExcelProperty(value = "计件单价", index = 10)
private Float piece_price;
@ExcelProperty(value = "是否计量", index = 11)
private String whether_measure;
@ExcelProperty(value = "是否使用了指定短信模板", index = 12)
private String if_use_sms_template;
@ExcelProperty(value = "是否并单", index = 13)
private String if_consolidation;
@ExcelProperty(value = "外呼流水", index = 14)
private String outbound_call_flow;
@ExcelProperty(value = "外呼时长", index = 15)
private String outbound_call_duration;
@ExcelProperty(value = "所属模块", index = 16)
private String modular;
@ExcelProperty(value = "加入时间", index = 17)
private String insert_time;
@ExcelProperty(value = "是否为排班时长内工作量", index = 18)
private String if_inside;
@ExcelProperty(value = "是否短信办结留单类型", index = 19)
private String is_message_finish;
@ExcelProperty(value = "主叫号码", index = 20)
private String call_no;
@ExcelProperty(value = "业务号码", index = 21)
private String called_no;
@ExcelProperty(value = "联系号码1", index = 22)
private String link_num1;
@ExcelProperty(value = "联系号码2", index = 23)
private String link_num2;
@ExcelProperty(value = "联系情况", index = 24)
private String contact_situation;
@ExcelProperty(value = "是否并单", index = 25)
private String is_consolidate;
@ExcelProperty(value = "是否发送办结短信", index = 26)
private String is_message;
@ExcelProperty(value = "外呼号码", index = 27)
private String revisit_no;
@ExcelProperty(value = "外呼人工号", index = 28)
private String out_staff_id;
@ExcelProperty(value = "挂机方式", index = 29)
private String hang_type;
@ExcelProperty(value = "外呼方式", index = 30)
private String out_call_type;
@ExcelProperty(value = "呼入开始时间", index = 31)
private String income_bgtime;
@ExcelProperty(value = "呼入结束时间", index = 32)
private String income_endtime;
@ExcelProperty(value = "通话开始时间", index = 33)
private String call_bgtime;
@ExcelProperty(value = "通话结束时间", index = 34)
private String call_edtime;
@ExcelProperty(value = "通话时长", index = 35)
private String total_time;
@ExcelProperty(value = "是否一次解决", index = 36)
private String if_one_deal;
@ExcelProperty(value = "满意值", index = 37)
private String satisfaction;
}
package usi.pieceNum.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author QiYingBo
* @version v1.0
* @ClassName ClearList2RespVo
* @Date: 2024/10/25 15:00
* @Description: 越级清算vo
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ExcelIgnoreUnannotated
public class ClearList2RespVo {
@ExcelProperty(value = "办结月份", index = 0)
private String finish_time1;
@ExcelProperty(value = "日期", index = 1)
private String finish_time2;
@ExcelProperty(value = "办结人工号", index = 2)
private String finish_user_id;
@ExcelProperty(value = "办结人姓名", index = 3)
private String finish_user_name;
@ExcelProperty(value = "办结人班组", index = 4)
private String post_name;
@ExcelProperty(value = "工单流水", index = 5)
private String busi_sheet_no;
@ExcelProperty(value = "留单类型", index = 6)
private String comp_type_name;
@ExcelProperty(value = "外呼流水", index = 7)
private String contact_id;
@ExcelProperty(value = "通话时长(秒)", index = 8)
private String talk_time;
@ExcelProperty(value = "计件项目", index = 9)
private String piece_name;
@ExcelProperty(value = "计件单价", index = 10)
private Float piece_price;
@ExcelProperty(value = "是否计量", index = 11)
private String whether_measure;
@ExcelProperty(value = "是否为排班时长内工作量", index = 12)
private String whether_workload_within_duration;
@ExcelProperty(value = "本越级类型", index = 13)
private String type_call;
@ExcelProperty(value = "加入时间", index = 14)
private String insert_time;
@ExcelProperty(value = "是否短信办结留单类型", index = 15)
private String is_message_finish;
@ExcelProperty(value = "主叫号码", index = 16)
private String call_no;
@ExcelProperty(value = "业务号码", index = 17)
private String called_no;
@ExcelProperty(value = "联系号码1", index = 18)
private String link_num1;
@ExcelProperty(value = "联系号码2", index = 19)
private String link_num2;
@ExcelProperty(value = "联系情况", index = 20)
private String contact_situation;
@ExcelProperty(value = "是否并单", index = 21)
private String is_consolidate;
@ExcelProperty(value = "是否发送办结短信", index = 22)
private String is_message;
@ExcelProperty(value = "外呼号码", index = 23)
private String revisit_no;
@ExcelProperty(value = "外呼人工号", index = 24)
private String out_staff_id;
@ExcelProperty(value = "挂机方式", index = 25)
private String hang_type;
@ExcelProperty(value = "外呼方式", index = 26)
private String out_call_type;
@ExcelProperty(value = "呼入开始时间", index = 27)
private String income_bgtime;
@ExcelProperty(value = "呼入结束时间", index = 28)
private String income_endtime;
@ExcelProperty(value = "通话开始时间", index = 29)
private String call_bgtime;
@ExcelProperty(value = "通话结束时间", index = 30)
private String call_edtime;
@ExcelProperty(value = "外呼主键", index = 31)
private String out_key;
@ExcelProperty(value = "所属模块", index = 32)
private String modular;
@ExcelProperty(value = "办结方式", index = 33)
private String finish_type;
@ExcelProperty(value = "是否有简单越级报告撰写量", index = 34)
private String if_easy_num;
@ExcelProperty(value = "是否有复杂越级报告撰写量", index = 35)
private String if_comp_num;
@ExcelProperty(value = "归档月份", index = 36)
private String file_month;
@ExcelProperty(value = "归档日期", index = 37)
private String file_date;
@ExcelProperty(value = "归档时间", index = 38)
private String file_time;
@ExcelProperty(value = "是否包含集团关键字", index = 39)
private String if_jt_key_word;
@ExcelProperty(value = "满意值", index = 40)
private String satisfaction;
@ExcelProperty(value = "是否同一集团流水生成", index = 41)
private String if_one_jt_no;
@ExcelProperty(value = "是否一次解决", index = 42)
private String if_one_deal;
@ExcelProperty(value = "计件类型", index = 43)
private String piece_type;
@ExcelProperty(value = "是否一次通过", index = 44)
private String if_one_pass;
}
3.service
**
* @Author QiYingBo
* @Description //本级清算导出
* @Date 2024/10/25 17:44
* @param response
* @param time
* @return * @return {@link List< ClearList1RespVo> }
**/
public List<ClearList1RespVo> downloadClearList1(HttpServletResponse response, String time) {
List<ClearList1RespVo> clearList1 = new ArrayList<>();
List<Map<String, Object>> maps = pieceNumDao.selectListByAcclayer1(time);
for (int i = 0; i < maps.size(); i++) {
ClearList1RespVo data =ClearList1RespVo.builder()
.month_time(maps.get(i).get("month_time") == null ? "" : maps.get(i).get("month_time").toString())
.day_time(maps.get(i).get("day_time") == null ? "" :maps.get(i).get("day_time").toString())
.finish_user_id(maps.get(i).get("finish_user_id") == null ? "" :maps.get(i).get("finish_user_id").toString())
.finish_user_name(maps.get(i).get("finish_user_name") == null ? "" :maps.get(i).get("finish_user_name").toString())
.post_name(maps.get(i).get("post_name") == null ? "" :maps.get(i).get("post_name").toString())
.busi_sheet_no(maps.get(i).get("busi_sheet_no") == null ? "" :maps.get(i).get("busi_sheet_no").toString())
.comp_type_name(maps.get(i).get("comp_type_name") == null ? "" :maps.get(i).get("comp_type_name").toString())
.finish_type_name(maps.get(i).get("finish_type_name") == null ? "" :maps.get(i).get("finish_type_name").toString())
.sent_sms_template(maps.get(i).get("sent_sms_template") == null ? "" :maps.get(i).get("sent_sms_template").toString())
.piece_name(maps.get(i).get("piece_name") == null ? "" :maps.get(i).get("piece_name").toString())
.piece_price(maps.get(i).get("piece_price") == null ? 0 :Float.parseFloat(maps.get(i).get("piece_price").toString()))
.whether_measure(maps.get(i).get("whether_measure") == null ? "" :maps.get(i).get("whether_measure").toString())
.if_use_sms_template(maps.get(i).get("if_use_sms_template") == null ? "" :maps.get(i).get("if_use_sms_template").toString())
.if_consolidation(maps.get(i).get("if_consolidation") == null ? "" :maps.get(i).get("if_consolidation").toString())
.outbound_call_flow(maps.get(i).get("outbound_call_flow") == null ? "" :maps.get(i).get("outbound_call_flow").toString())
.outbound_call_duration(maps.get(i).get("outbound_call_duration") == null ? "" :maps.get(i).get("outbound_call_duration").toString())
.modular(maps.get(i).get("modular") == null ? "" :maps.get(i).get("modular").toString())
.insert_time(maps.get(i).get("insert_time") == null ? "" :maps.get(i).get("insert_time").toString())
.if_inside(maps.get(i).get("if_inside") == null ? "" :maps.get(i).get("if_inside").toString())
.is_message_finish(maps.get(i).get("is_message_finish") == null ? "" :maps.get(i).get("is_message_finish").toString())
.call_no(maps.get(i).get("call_no") == null ? "" :maps.get(i).get("call_no").toString())
.called_no(maps.get(i).get("called_no") == null ? "" :maps.get(i).get("called_no").toString())
.link_num1(maps.get(i).get("link_num1") == null ? "" :maps.get(i).get("link_num1").toString())
.link_num2(maps.get(i).get("link_num2") == null ? "" :maps.get(i).get("link_num2").toString())
.contact_situation(maps.get(i).get("contact_situation") == null ? "" :maps.get(i).get("contact_situation").toString())
.is_consolidate(maps.get(i).get("is_consolidate") == null ? "" :maps.get(i).get("is_consolidate").toString())
.is_message(maps.get(i).get("is_message") == null ? "" :maps.get(i).get("is_message").toString())
.revisit_no(maps.get(i).get("revisit_no") == null ? "" :maps.get(i).get("revisit_no").toString())
.out_staff_id(maps.get(i).get("out_staff_id") == null ? "" :maps.get(i).get("out_staff_id").toString())
.hang_type(maps.get(i).get("hang_type") == null ? "" :maps.get(i).get("hang_type").toString())
.out_call_type(maps.get(i).get("out_call_type") == null ? "" :maps.get(i).get("out_call_type").toString())
.income_bgtime(maps.get(i).get("income_bgtime") == null ? "" :maps.get(i).get("income_bgtime").toString())
.income_endtime(maps.get(i).get("income_endtime") == null ? "" :maps.get(i).get("income_endtime").toString())
.call_bgtime(maps.get(i).get("call_bgtime") == null ? "" :maps.get(i).get("call_bgtime").toString())
.call_edtime(maps.get(i).get("call_edtime") == null ? "" :maps.get(i).get("call_edtime").toString())
.total_time(maps.get(i).get("total_time") == null ? "" :maps.get(i).get("total_time").toString())
.if_one_deal(maps.get(i).get("if_one_deal") == null ? "" :maps.get(i).get("if_one_deal").toString())
.satisfaction(maps.get(i).get("satisfaction") == null ? "" :maps.get(i).get("satisfaction").toString())
.build();
clearList1.add(data);
}
return clearList1;
}
/**
* @Author QiYingBo
* @Description //越级清算导出
* @Date 2024/10/25 17:45
* @param response
* @param time
* @return * @return {@link java.util.List<usi.pieceNum.vo.ClearList2RespVo> }
**/
public List<ClearList2RespVo> downloadClearList2(HttpServletResponse response, String time) {
List<ClearList2RespVo> clearList2 = new ArrayList<>();
List<Map<String, Object>> maps = pieceNumDao.selectListByAcclayer2(time);
for (int i = 0; i < maps.size(); i++) {
ClearList2RespVo data =ClearList2RespVo.builder()
.finish_time1(maps.get(i).get("finish_time1") == null ? "" : maps.get(i).get("finish_time1").toString())
.finish_time2(maps.get(i).get("finish_time2") == null ? "" : maps.get(i).get("finish_time2").toString())
.finish_user_id(maps.get(i).get("finish_user_id") == null ? "" : maps.get(i).get("finish_user_id").toString())
.finish_user_name(maps.get(i).get("finish_user_name") == null ? "" : maps.get(i).get("finish_user_name").toString())
.post_name(maps.get(i).get("post_name") == null ? "" : maps.get(i).get("post_name").toString())
.busi_sheet_no(maps.get(i).get("busi_sheet_no") == null ? "" : maps.get(i).get("busi_sheet_no").toString())
.comp_type_name(maps.get(i).get("comp_type_name") == null ? "" : maps.get(i).get("comp_type_name").toString())
.contact_id(maps.get(i).get("contact_id") == null ? "" : maps.get(i).get("contact_id").toString())
.talk_time(maps.get(i).get("talk_time") == null ? "" : maps.get(i).get("talk_time").toString())
.piece_name(maps.get(i).get("piece_name") == null ? "" : maps.get(i).get("piece_name").toString())
.piece_price(maps.get(i).get("piece_price") == null ? 0 : Float.parseFloat(maps.get(i).get("piece_price").toString()))
.whether_measure(maps.get(i).get("whether_measure") == null ? "" : maps.get(i).get("whether_measure").toString())
.whether_workload_within_duration(maps.get(i).get("whether_workload_within_duration") == null ? "" : maps.get(i).get("whether_workload_within_duration").toString())
.type_call(maps.get(i).get("type_call") == null ? "" : maps.get(i).get("type_call").toString())
.insert_time(maps.get(i).get("insert_time") == null ? "" : maps.get(i).get("insert_time").toString())
.is_message_finish(maps.get(i).get("is_message_finish") == null ? "" : maps.get(i).get("is_message_finish").toString())
.call_no(maps.get(i).get("call_no") == null ? "" : maps.get(i).get("call_no").toString())
.called_no(maps.get(i).get("called_no") == null ? "" : maps.get(i).get("called_no").toString())
.link_num1(maps.get(i).get("link_num1") == null ? "" : maps.get(i).get("link_num1").toString())
.link_num2(maps.get(i).get("link_num2") == null ? "" : maps.get(i).get("link_num2").toString())
.contact_situation(maps.get(i).get("contact_situation") == null ? "" : maps.get(i).get("contact_situation").toString())
.is_consolidate(maps.get(i).get("is_consolidate") == null ? "" : maps.get(i).get("is_consolidate").toString())
.is_message(maps.get(i).get("is_message") == null ? "" : maps.get(i).get("is_message").toString())
.revisit_no(maps.get(i).get("revisit_no") == null ? "" : maps.get(i).get("revisit_no").toString())
.out_staff_id(maps.get(i).get("out_staff_id") == null ? "" : maps.get(i).get("out_staff_id").toString())
.hang_type(maps.get(i).get("hang_type") == null ? "" : maps.get(i).get("hang_type").toString())
.out_call_type(maps.get(i).get("out_call_type") == null ? "" : maps.get(i).get("out_call_type").toString())
.income_bgtime(maps.get(i).get("income_bgtime") == null ? "" : maps.get(i).get("income_bgtime").toString())
.income_endtime(maps.get(i).get("income_endtime") == null ? "" : maps.get(i).get("income_endtime").toString())
.call_bgtime(maps.get(i).get("call_bgtime") == null ? "" : maps.get(i).get("call_bgtime").toString())
.call_edtime(maps.get(i).get("call_edtime") == null ? "" : maps.get(i).get("call_edtime").toString())
.out_key(maps.get(i).get("out_key") == null ? "" : maps.get(i).get("out_key").toString())
.modular(maps.get(i).get("modular") == null ? "" : maps.get(i).get("modular").toString())
.finish_type(maps.get(i).get("finish_type") == null ? "" : maps.get(i).get("finish_type").toString())
.if_easy_num(maps.get(i).get("if_easy_num") == null ? "" : maps.get(i).get("if_easy_num").toString())
.if_comp_num(maps.get(i).get("if_comp_num") == null ? "" : maps.get(i).get("if_comp_num").toString())
.file_month(maps.get(i).get("file_month") == null ? "" : maps.get(i).get("file_month").toString())
.file_date(maps.get(i).get("file_date") == null ? "" : maps.get(i).get("file_date").toString())
.file_time(maps.get(i).get("file_time") == null ? "" : maps.get(i).get("file_time").toString())
.if_jt_key_word(maps.get(i).get("if_jt_key_word") == null ? "" : maps.get(i).get("if_jt_key_word").toString())
.satisfaction(maps.get(i).get("satisfaction") == null ? "" : maps.get(i).get("satisfaction").toString())
.if_one_jt_no(maps.get(i).get("if_one_jt_no") == null ? "" : maps.get(i).get("if_one_jt_no").toString())
.if_one_deal(maps.get(i).get("if_one_deal") == null ? "" : maps.get(i).get("if_one_deal").toString())
.piece_type(maps.get(i).get("piece_type") == null ? "" : maps.get(i).get("piece_type").toString())
.if_one_pass(maps.get(i).get("if_one_pass") == null ? "" : maps.get(i).get("if_one_pass").toString())
.build();
clearList2.add(data);
}
return clearList2;
}
4.dao
/**
* @Author QiYingBo
* @Description //根据时间查询本级清算清单
* @Date 2024/10/25 10:52
* @param time
* @return * @return {@link List< Map< String, Object>> }
**/
List<Map<String, Object>> selectListByAcclayer1(String time);
/**
* @Author QiYingBo
* @Description //根据时间查询越级清算清单
* @Date 2024/10/25 10:53
* @param time
* @return * @return {@link List< Map< String, Object>> }
**/
List<Map<String, Object>> selectListByAcclayer2(String time);
5.daoImpl
@Override
public List<Map<String, Object>> selectListByAcclayer1(String time) {
String sql = "SELECT * FROM om_list_volume_clear WHERE MONTH_TIME=? limit 1000000";
ArrayList<Object> params = new ArrayList<>();
if(CommonUtil.hasValue(time)){
params.add(time);
}
return this.getJdbcTemplate().queryForList(sql, params.toArray());
}
@Override
public List<Map<String, Object>> selectListByAcclayer2(String time) {
String sql = "select * from om_list_leapfrog_orders_volume_clear where `FILE_MONTH`=? limit 1000000";
ArrayList<Object> params = new ArrayList<>();
if(CommonUtil.hasValue(time)){
params.add(time);
}
return this.getJdbcTemplate().queryForList(sql, params.toArray());
}
仅作为学习笔记!!!
更多推荐
所有评论(0)