导出按钮

时间:2020-05-12
本文章向大家介绍导出按钮,主要包括导出按钮使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

场景:导出列表查询项

/**
* 导出接口日志
*
* @param
* @return com.vteam.vtarm.api.RespEntity
* @author 程序员girl
* @date 2020/4/26 下午 3:36
*/
@PostMapping(value = "/doExportApiLog")
@RequiredAuthorize(permissions = {PermissionConstants.Operation.STATISTICS_LOG_INTERFACE_EXPORT})
public RespEntity doExportApiLog(@RequestBody ReqEntity reqEntity) {
FlogApiMVo flogApiMVo = JSON.parseObject(reqEntity.getData(), FlogApiMVo.class);

SmeAssert.notNull(flogApiMVo.getResponseTimeStart(), "请输入响应开始日期");
flogApiMVo.setResponseTimeStart(flogApiMVo.getResponseTimeStart().with(LocalTime.MIN));
SmeAssert.notNull(flogApiMVo.getResponseTimeEnd(), "请输入响应结束日期");
flogApiMVo.setResponseTimeEnd(flogApiMVo.getResponseTimeEnd().with(LocalTime.MAX));
long endDay = flogApiMVo.getResponseTimeEnd().getYear();
long createDay = flogApiMVo.getResponseTimeStart().getYear();
long days = endDay - createDay;
boolean bl = days <= 366;
SmeAssert.isTrue(bl, "响应日期相差不能大于一年");
List<FlogApiMVo> flogApiMVoList = flogApiMService.listApiLogByCondition(flogApiMVo);
SmeAssert.notEmpty(flogApiMVoList, "暂无数据,不可导出");
final String userid = RequestStore.getLoginUser().getUserid();
exportTaskExecutor.execute(() -> {

if (CollectionUtils.isNotEmpty(flogApiMVoList)) {
// 处理导出的数据
this.doExportData(flogApiMVoList);
}

// 接口日志列表
String fileName = sxssfExportExecutor.executeForLocal(flogApiMVoList, FlogApiMVo.class, "FlogApiMVo_ExportTemplate.xlsx");

// 发送消息
Set<SipaBurMVo> receiverSet = new HashSet<>();
SipaBurMVo receiver = sipaBurMService.getUserInfoByUserid(userid);
receiverSet.add(receiver);

Map<String, Object> model = new HashMap<>(2);
model.put("actionName", "接口日志");
model.put("filePath", fileName);
MessageModel messageModel = MessageModel.build().createMessageModel(null, receiverSet,
MessageTemplateConstants.EXPORT_FILE.getTemplateName(), FieldContants.FbtxNot.PUSH_TYPE_SYSTEM, model,
new MessageModel.Channel[]{MessageModel.Channel.WS});
messageProducer.send(messageModel);

// 移除任务标记
stringValueContainer.delete(ExportFileAspect.BASE_CACHE_KEY + userid);
});
return RespEntity.ok();
}

/**
* 处理导出的数据
*
* @author 程序员girl
* @date 2020/4/30 下午 6:49
*/
private void doExportData(List<FlogApiMVo> flogApiMVoList) {
final String SUCCESS = "成功";
final String FAILD = "失败";
final String IN = "I";
final String OUT = "O";
final String CLIENT = "用户端";
final String SERVICE = "服务端";
if (CollectionUtils.isNotEmpty(flogApiMVoList)) {
for (int i = 0; i < flogApiMVoList.size(); i++) {
FlogApiMVo flogApiMVo = flogApiMVoList.get(i);
// 序号
flogApiMVo.setIndex(i + 1);
flogApiMVo.setApiName(flogApiMVo.getApiName());
flogApiMVo.setRequestDate(flogApiMVo.getRequestTime().format(DateUtils.FMT_DATE));
flogApiMVo.setResponseDate(flogApiMVo.getResponseTime().format(DateUtils.FMT_DATE));
// 接口类型
if (IN.equals(flogApiMVo.getApiType())) {
flogApiMVo.setInterfaceType(CLIENT);
} else if (OUT.equals(flogApiMVo.getApiType())) {
flogApiMVo.setInterfaceType(SERVICE);
}
// 响应状态
if (FieldContants.FlogApiM.RESULT_CODE_SUCCESS.equals(flogApiMVo.getResultCode())) {
flogApiMVo.setStatus(SUCCESS);
} else {
flogApiMVo.setStatus(FAILD);
}
}
}
}
2.接口日志表扩展视图类

vue页面导出页面:

export default {
data() {
const getCurrentDate = _ => {
let currentDate = moment().format('YYYY-MM-DD')
return currentDate
}
const get12MonthBefore = _ => { ---------------这里主要是日期能显示当前的日期
      let before12month = moment().subtract(1, 'years').format('YYYY-MM-DD')
return before12month
}
return {
loading: false,
dateList: [get12MonthBefore(), getCurrentDate()],
params: {
apiName: '',
responseTimeStart: '',
responseTimeEnd: '',
resultCode: '',
apiType: ''
},
// 返回结果
self: {
aplList: [],
total: 0
},
// 分页信息
page: {
pageNum: 1,
pageSize: this.$store.getters.pageSizeArr[0]
},
apiTypeList: [{ key: '', value: '全部' },
{ key: 'O', value: '客户端' }, { key: 'I', value: '服务端' }],
resultCodeList: [{ key: '', value: '全部' }, { key: '200', value: '成功' },
{ key: '-1', value: '失败' }]
}
},
beforeMount() {
this.getPageData()
},
methods: {
getPageData() {
this.loading = true
if (this.dateList && this.dateList.length) {
this.params.responseTimeStart = this.dateList[0]
this.params.responseTimeEnd = this.dateList[1]
} else {
this.params.responseTimeStart = ''
this.params.responseTimeEnd = ''
}

let data = {
data: this.params,
pageNum: this.page.pageNum,
pageSize: this.page.pageSize
}

api.findApiLogPage(data).then(
res => {
this.loading = false
this.self.apiList = res.data.apiList
this.self.total = res.totalCount
},
err => {
this.loading = false
}
)
},
queryApiInfo(refcode) {
this.$router.push({
name: 'statistics-api-detail',
params: {
refcode: refcode
}
})
},

getApiType(type) {
if (type != '') {
if (type == 'O') {
return '客户端'
} else {
return '服务端'
}
}
},
getResult(code) {
if (code) {
if (code == '200') {
return '成功'
} else {
return '失败'
}
}
},

// 导出Excel
exportData() {
this.loading = true
if (this.dateList && this.dateList.length) {
this.params.responseTimeStart = this.dateList[0]
this.params.responseTimeEnd = this.dateList[1]
} else {
this.params.responseTimeStart = ''
this.params.responseTimeEnd = ''
}
// 组装查询条件
let data = {
data: this.params,
pageNum: this.page.pageNum,
pageSize: this.page.pageSize
}
api.doExportApiLog(data).then(
res => {
this.loading = false
this.$notify.info({
title: '消息',
message: '文件正在生成中,休息一会再来下载吧!'
})
},
err => {
this.loading = false
}
)
},

// 按文件名下载
getFileByFileName(fileName) {
apiFile.getFileByFileName(fileName, '接口日志')
},

/**
* 每页笔数改变事件
*/
handleSizeChange(val) {
this.page.pageSize = val
this.getPageData()
},
/**
* 当前页数改变事件
*/
handleCurrentChange(val) {
this.page.pageNum = val
this.getPageData()
}
}
}
</script>

原文地址:https://www.cnblogs.com/fshow/p/12877490.html