Commit 942ea1e0 authored by wdy's avatar wdy

Merge branch 'wangdingyi' into 'dev'

查询在线用户

See merge request !208
parents d667891b 457d9b80
package com.ruoyi.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@ApiModel
@TableName(value ="t_test_records")
@Data
public class TestRecords {
@ApiModelProperty("主键")
@TableId(type = IdType.ASSIGN_ID)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long id;
@ApiModelProperty("关联项目id")
private String taskId;
@ApiModelProperty("用例名称")
private String usecase;
@ApiModelProperty("用例id")
private String usecaseId;
@ApiModelProperty("测试时间")
private Date testTime;
@ApiModelProperty("用例简述")
private String description;
@ApiModelProperty("风险等级")
private String riskLevel;
@ApiModelProperty("测试方法")
private String testMethod;
@ApiModelProperty("测试结果")
private String testResult;
@ApiModelProperty("测试结果描述")
private String testResultDescription;
@ApiModelProperty("漏洞危害")
private String loophole;
}
package com.ruoyi.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.TestRecords;
import org.springframework.stereotype.Repository;
@Repository
public interface TestRecordsMapper extends BaseMapper<TestRecords> {
}
package com.ruoyi.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.domain.TestRecords;
public interface TestRecordsService extends IService<TestRecords> {
}
package com.ruoyi.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.domain.TestRecords;
import com.ruoyi.mapper.TestRecordsMapper;
import com.ruoyi.service.TestRecordsService;
import okhttp3.Request;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
@Transactional
@Service
public class TestRecordsServiceImpl extends ServiceImpl<TestRecordsMapper, TestRecords> implements TestRecordsService {
public void getValue() throws IOException {
JSONObject jsonObject = getInverseParamByUrl("http://10.12.48.78:8090/DescribeProjectTestResult");
}
// public static void main(String[] args) throws IOException {
// JSONObject jsonObject = getInverseParamByUrl("http://10.12.48.78:8090/DescribeProjectTestResult");
//
// System.out.println("jsonObject = " + jsonObject);
// }
/**
* 通过API获取反参
* @param apiUrl
* @return
* @throws IOException
*/
public static JSONObject getInverseParamByUrl(String apiUrl) throws IOException {
// 调用请求
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
// 解析成JSON对象
String jsonResponseString = response.toString();
JSONObject jsonObject = JSONObject.parseObject(jsonResponseString);
return jsonObject;
}
public static void main(String[] args) throws UnsupportedEncodingException {
// 创建一个Request对象
// Request request = new Request();
// request.setParam1("project_items;1");
// request.setParam2("ALL");
//
// // 将Request对象转换为JSON字符串
// Gson gson = new GsonBuilder().create();
// String jsonRequest = gson.toJson(request);
try {
String apiUrl = "http://10.12.48.78:8090/DescribeProjectTestResult"; // 第三方URL
String param1 = "project_items;1";
String param2 = "ALL";
String postData = String.format("param1=%s&param2=%s",
URLEncoder.encode(param1, "UTF-8"),
URLEncoder.encode(param2, "UTF-8"));
URL url = new URL(apiUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
// 设置请求体
DataOutputStream outputStream = new DataOutputStream(conn.getOutputStream());
outputStream.writeBytes(postData);
outputStream.flush();
outputStream.close();
int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
String responseBody = response.toString();
JSONObject jsonObject = JSONObject.parseObject(responseBody);
System.out.println("Response body: " + responseBody);
System.out.println("jsonObject = " + jsonObject);
} else {
System.out.println("Request failed. Response code: " + responseCode);
}
conn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.mapper.TestRecordsMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.domain.TestRecords">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="taskId" column="task_id" jdbcType="VARCHAR"/>
<result property="usecase" column="usecase" jdbcType="VARCHAR"/>
<result property="usecaseId" column="usecase_id" jdbcType="VARCHAR"/>
<result property="testTime" column="test_time" jdbcType="TIMESTAMP"/>
<result property="description" column="description" jdbcType="VARCHAR"/>
<result property="riskLevel" column="risk_level" jdbcType="VARCHAR"/>
<result property="testMethod" column="test_method" jdbcType="VARCHAR"/>
<result property="testResult" column="test_result" jdbcType="VARCHAR"/>
<result property="testResultDescription" column="test_result_description" jdbcType="VARCHAR"/>
<result property="loophole" column="loophole" jdbcType="VARCHAR"/>
</resultMap>
</mapper>
......@@ -24,7 +24,7 @@ public class SysUserOnlineServiceImpl implements ISysUserOnlineService
@Override
public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user)
{
if (StringUtils.equals(ipaddr, user.getIpaddr()))
if (StringUtils.contains(ipaddr, user.getIpaddr()))
{
return loginUserToUserOnline(user);
}
......@@ -41,7 +41,7 @@ public class SysUserOnlineServiceImpl implements ISysUserOnlineService
@Override
public SysUserOnline selectOnlineByUserName(String userName, LoginUser user)
{
if (StringUtils.equals(userName, user.getUsername()))
if (StringUtils.contains(userName, user.getUsername()))
{
return loginUserToUserOnline(user);
}
......@@ -59,7 +59,7 @@ public class SysUserOnlineServiceImpl implements ISysUserOnlineService
@Override
public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user)
{
if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername()))
if (StringUtils.contains(ipaddr, user.getIpaddr()) && StringUtils.contains(userName, user.getUsername()))
{
return loginUserToUserOnline(user);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment