Browse Source

增加外部接口监测导出功能

develop
Mr.Wang 5 months ago
parent
commit
cb73f1e5c2
  1. 33
      ruoyi-ui/src/views/monitor/Interface/index.vue
  2. 37
      zc-business/src/main/java/com/zc/business/domain/ExternalInterfaceMonitoring.java
  3. 61
      zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java

33
ruoyi-ui/src/views/monitor/Interface/index.vue

@ -28,9 +28,22 @@
/>
</el-select>
</el-form-item>
<el-form-item label="时间范围" prop="dateTime">
<el-date-picker
v-model="queryParams.dateTime"
type="datetimerange"
format="yyyy-MM-dd HH:mm:ss"
value-format="yyyy-MM-dd HH:mm:ss"
range-separator="-"
@change="handleProcessingTime "
start-placeholder="开始日期"
end-placeholder="结束日期">
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
</el-form-item>
</el-form>
@ -114,7 +127,10 @@ export default {
pageSize: 10,
interfaceOwnership: undefined,
interfaceName: undefined,
operationStatus: undefined
operationStatus: undefined,
dateTime: undefined,
startTime: undefined,
endTime: undefined
},
interfaceData: [],
interfaceResult: undefined,
@ -163,6 +179,21 @@ export default {
handleClose() {
this.openView = false
this.interfaceResult = undefined
},
/** 处理时间选择器组件 */
handleProcessingTime() {
if (this.queryParams.dateTime.length > 0) {
this.queryParams.startTime = this.queryParams.dateTime[0]
this.queryParams.endTime = this.queryParams.dateTime[1]
}
},
/** 导出按钮操作 */
handleExport() {
this.download('/externalInterface/export', {
...this.queryParams
}, '外部接口监测.xlsx')
}
}

37
zc-business/src/main/java/com/zc/business/domain/ExternalInterfaceMonitoring.java

@ -1,6 +1,8 @@
package com.zc.business.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
@ -30,19 +32,48 @@ public class ExternalInterfaceMonitoring {
@ApiModelProperty("接口所属")
private Integer interfaceOwnership;
@Excel(name = "接口所属名称")
@TableField(exist = false)
@ApiModelProperty("接口所属名称")
private String interfaceOwnershipName;
@Excel(name = "接口名称")
@ApiModelProperty("接口名称")
private String interfaceName;
@Excel(name = "操作人")
@ApiModelProperty("操作人")
private String operatorName;
@Excel(name = "操作状态")
@TableField(exist = false)
@ApiModelProperty("操作状态名称")
private String operationStatusName;
@ApiModelProperty("操作状态")
private Integer operationStatus;
@ApiModelProperty("操作结果")
private String operationResult;
@Excel(name = "操作时间",dateFormat = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@ApiModelProperty("操作时间")
private Date operationTime;
@Excel(name = "操作结果")
@ApiModelProperty("操作结果")
private String operationResult;
/**
* 开始时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(exist = false)
@ApiModelProperty("开始时间")
private Date startTime;
/**
* 结束时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(exist = false)
@ApiModelProperty("结束时间")
private Date endTime;
}

61
zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java

@ -14,6 +14,7 @@ import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.service.ISysConfigService;
import com.zc.business.controller.DcNmcController;
@ -29,14 +30,19 @@ import com.zc.common.core.httpclient.request.RequestParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import okhttp3.*;
import org.apache.poi.ss.SpreadsheetVersion;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
@ -76,6 +82,30 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
@GetMapping("/list")
public TableDataInfo list(ExternalInterfaceMonitoring externalInterfaceMonitoring) {
startPage();
List<ExternalInterfaceMonitoring> list = selectExternal(externalInterfaceMonitoring);
return getDataTable(list);
}
/**
* 外部接口监测数据导出
*/
@PostMapping("/export")
public void export(HttpServletResponse response, ExternalInterfaceMonitoring externalInterfaceMonitoring) throws UnsupportedEncodingException {
List<ExternalInterfaceMonitoring> list = selectExternal(externalInterfaceMonitoring);
list.forEach(external -> {
external.setOperationStatusName(external.getOperationStatus().equals(UniversalEnum.ONE.getNumber()) ? "成功" : "失败");
external.setInterfaceOwnershipName(Arrays.stream(InterfaceOwnershipEnum.values())
.filter(interfaceOwnershipEnum -> interfaceOwnershipEnum.getCode().equals(external.getInterfaceOwnership()))
.findFirst()
.map(InterfaceOwnershipEnum::getOwnershipName)
.orElse(UniversalEnum.OTHER.getValue()));
});
ExcelUtil<ExternalInterfaceMonitoring> util = new ExcelUtil<>(ExternalInterfaceMonitoring.class);
resetCellMaxTextLength();
util.exportExcel(response, list, "外部接口监测数据");
}
public List<ExternalInterfaceMonitoring> selectExternal(ExternalInterfaceMonitoring externalInterfaceMonitoring) {
LambdaQueryWrapper<ExternalInterfaceMonitoring> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (externalInterfaceMonitoring.getInterfaceOwnership() != null) {
lambdaQueryWrapper.eq(ExternalInterfaceMonitoring::getInterfaceOwnership, externalInterfaceMonitoring.getInterfaceOwnership());
@ -86,9 +116,15 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
if (externalInterfaceMonitoring.getInterfaceName() != null) {
lambdaQueryWrapper.like(ExternalInterfaceMonitoring::getInterfaceName, externalInterfaceMonitoring.getInterfaceName());
}
if (externalInterfaceMonitoring.getStartTime() != null && externalInterfaceMonitoring.getEndTime() != null) {
lambdaQueryWrapper.between(
ExternalInterfaceMonitoring::getOperationTime,
externalInterfaceMonitoring.getStartTime(),
externalInterfaceMonitoring.getEndTime()
);
}
lambdaQueryWrapper.orderByDesc(ExternalInterfaceMonitoring::getOperationTime);
List<ExternalInterfaceMonitoring> list = externalInterfaceMonitoringMapper.selectList(lambdaQueryWrapper);
return getDataTable(list);
return externalInterfaceMonitoringMapper.selectList(lambdaQueryWrapper);
}
@Scheduled(cron = "0 0/15 * * * ?")
@ -842,4 +878,25 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
voiceBroadcastingToken = JSONObject.parseObject(response.body().string()).getString("accessToken");
}
}
/**
* 利用反射修改单元格最大长度
*/
public static void resetCellMaxTextLength() {
SpreadsheetVersion excel2007 = SpreadsheetVersion.EXCEL2007;
if (Integer.MAX_VALUE != excel2007.getMaxTextLength()) {
Field field;
try {
// SpreadsheetVersion.EXCEL2007的_maxTextLength变量
field = excel2007.getClass().getDeclaredField("_maxTextLength");
// 关闭反射机制的安全检查,可以提高性能
field.setAccessible(true);
// 重新设置这个变量属性值
field.set(excel2007, Integer.MAX_VALUE);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

Loading…
Cancel
Save