Merge branch 'main' of http://www.carsafe-caem.com/toolchaintechnologycenter/spdm-backend
This commit is contained in:
@@ -35,6 +35,12 @@ public class SysLogDTO {
|
|||||||
*/
|
*/
|
||||||
private String createBy;
|
private String createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
private String[] createTimeArr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新时间
|
* 更新时间
|
||||||
*/
|
*/
|
||||||
@@ -85,11 +91,6 @@ public class SysLogDTO {
|
|||||||
*/
|
*/
|
||||||
private String serviceId;
|
private String serviceId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间区间 [开始时间,结束时间]
|
|
||||||
*/
|
|
||||||
private LocalDateTime[] createTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户编号
|
* 租户编号
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.sdm.common.service.lyric;
|
||||||
|
|
||||||
|
public class HkCloudSignObject {
|
||||||
|
|
||||||
|
public String jobNo;
|
||||||
|
|
||||||
|
public String appKey;
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.sdm.common.service.lyric;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class HkUploadFileReq {
|
||||||
|
@Schema(description = "权限编码")
|
||||||
|
public String filePower = "2456236750149124114";
|
||||||
|
|
||||||
|
@Schema(description = "是否加水印")
|
||||||
|
public boolean waterMarkFlag = false;
|
||||||
|
|
||||||
|
@Schema(description = "水印内容")
|
||||||
|
public String waterMarkContent = "";
|
||||||
|
|
||||||
|
@Schema(description = "系统ID")
|
||||||
|
public long sysId = 1691399963692630016L;
|
||||||
|
|
||||||
|
@Schema(description = "表单ID")
|
||||||
|
public long formId = 1847115435993071616L;
|
||||||
|
|
||||||
|
@Schema(description = "控件ID")
|
||||||
|
public long componentInstId = 8000004142460000204L;
|
||||||
|
|
||||||
|
@Schema(description = "表名称")
|
||||||
|
public String tableName = "oa_threee_d_review";
|
||||||
|
|
||||||
|
@Schema(description = "字段名称")
|
||||||
|
public String columnName = "simulation_table;";
|
||||||
|
|
||||||
|
@Schema(description = "项目号")
|
||||||
|
public String xmh = "";
|
||||||
|
|
||||||
|
@Schema(description = "工位号")
|
||||||
|
public String gwh = "";
|
||||||
|
|
||||||
|
@Schema(description = "上传文件")
|
||||||
|
public List<String> files = new ArrayList<String>();
|
||||||
|
}
|
||||||
@@ -0,0 +1,293 @@
|
|||||||
|
package com.sdm.common.service.lyric;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.sdm.common.common.SdmResponse;
|
||||||
|
import com.sdm.common.utils.HttpUtil;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||||
|
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||||
|
import org.apache.http.entity.ContentType;
|
||||||
|
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||||
|
import org.apache.http.entity.mime.content.FileBody;
|
||||||
|
import org.apache.http.entity.mime.content.StringBody;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.ssl.SSLContextBuilder;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.DigestUtils;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.KeyStoreException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class LyricIntegrateService {
|
||||||
|
|
||||||
|
//测试开发环境
|
||||||
|
private final String appKey = "e9eb516aa02a43a29e227a0d901ec5f1";
|
||||||
|
|
||||||
|
private final String appSecret = "9fac43db08634aaf8a9fe5fb9468de9d";
|
||||||
|
//海葵云url
|
||||||
|
private final String HK_CLOUD_URL = "https://v15.lyh.haikuicloud.com";
|
||||||
|
//海葵云获取用户token url后缀
|
||||||
|
private final String HK_USER_TOKEN_URL_SUFFIX = "/merchant/openapi/user/login/jobNo";
|
||||||
|
//海葵云获取单个用户信息url后缀
|
||||||
|
private final String HK_SIMPLE_USER_URL_SUFFIX = "/merchant/api/user/getSimpleUserInfo";
|
||||||
|
//海葵云上传文件url后缀
|
||||||
|
private final String HK_UPLOAD_FILE_URL_SUFFIX = "/haikui-oa/autoCreateFlow/uploadFile";
|
||||||
|
//EP系统URL
|
||||||
|
private final String EP_URL = "https://ep-url.dev.haikuicloud.com";
|
||||||
|
//推送代办状态url后缀
|
||||||
|
private final String QUERY_TODO_STATUS_SUFFIX = "/todoApi/todo/emulation/dm/status";
|
||||||
|
//查询待办结果url后缀
|
||||||
|
private final String QUERY_TODO_RESULT_SUFFIX = "/todoApi/todo/emulation/dm/result";
|
||||||
|
//查询待办附加url后缀
|
||||||
|
private final String QUERY_TOD_ATTACHMENT_SUFFIX = "/todoApi/todo/emulation/dm/attachments";
|
||||||
|
|
||||||
|
//生产环境
|
||||||
|
/**
|
||||||
|
|
||||||
|
|
||||||
|
private final String EP_URL = "https://ep-url.lyh.haikuicloud.com;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成海葵云token签名
|
||||||
|
*
|
||||||
|
* @param appKey
|
||||||
|
* @param appSecret
|
||||||
|
* @param jobNo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String calculateSignHkcloud(String appKey, String appSecret, String jobNo) {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("appKey", appKey);
|
||||||
|
jsonObject.put("appSecret", appSecret);
|
||||||
|
jsonObject.put("jobNo", jobNo);
|
||||||
|
String addSalStr = JSONObject.toJSONString(jsonObject);
|
||||||
|
return DigestUtils.md5DigestAsHex(addSalStr.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取根据工号获取用户token
|
||||||
|
*
|
||||||
|
* @param appKey
|
||||||
|
* @param appSecret
|
||||||
|
* @param jobNo
|
||||||
|
* @param tokenUrl
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getHKCloudToken(String appKey, String appSecret, String jobNo, String tokenUrl) {
|
||||||
|
String sign = calculateSignHkcloud(appKey, appSecret, jobNo);
|
||||||
|
String token = null;
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("jobNo", jobNo);
|
||||||
|
jsonObject.put("appKey", appKey);
|
||||||
|
jsonObject.put("sign", sign);
|
||||||
|
try {
|
||||||
|
String result = HttpUtil.httpPost(tokenUrl, null, jsonObject.toJSONString());
|
||||||
|
JSONObject resultJson = JSONObject.parseObject(result);
|
||||||
|
String code = resultJson.getString("code");
|
||||||
|
if (code.equals("0000")) {
|
||||||
|
JSONObject dataObject = resultJson.getJSONObject("data");
|
||||||
|
if (dataObject != null) {
|
||||||
|
token = dataObject.getString("token");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前用户的
|
||||||
|
*
|
||||||
|
* @param jobNo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public SdmResponse getHKCloudSimpleUserInfo(String jobNo) {
|
||||||
|
SdmResponse response = SdmResponse.success();
|
||||||
|
String tokenUrl = HK_CLOUD_URL + HK_USER_TOKEN_URL_SUFFIX;
|
||||||
|
String token = getHKCloudToken(appKey, appSecret, jobNo, tokenUrl);
|
||||||
|
if (token == null || token.isEmpty()) {
|
||||||
|
response = SdmResponse.failed("获取海葵云token失败");
|
||||||
|
} else {
|
||||||
|
String simpleUserUrl = HK_CLOUD_URL + HK_SIMPLE_USER_URL_SUFFIX;
|
||||||
|
Map<String, String> headers = new HashMap<String, String>();
|
||||||
|
headers.put("authorization", token);
|
||||||
|
try {
|
||||||
|
String result = HttpUtil.httpPost(simpleUserUrl, headers, "");
|
||||||
|
JSONObject resultJson = JSONObject.parseObject(result);
|
||||||
|
String code = resultJson.getString("code");
|
||||||
|
if (code.equals("0000")) {
|
||||||
|
JSONObject dataObject = resultJson.getJSONObject("data");
|
||||||
|
if (dataObject != null) {
|
||||||
|
response.setData(dataObject);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
response = SdmResponse.failed("获取海葵云单个用户信息失败");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
response = SdmResponse.failed("获取海葵云单个用户信息失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建信任所有证书的CloseableHttpClient
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static CloseableHttpClient createHttpsClient() {
|
||||||
|
try {
|
||||||
|
// 1. 构建SSL上下文(信任所有证书)
|
||||||
|
SSLContext sslContext = SSLContextBuilder.create()
|
||||||
|
.loadTrustMaterial(null, (chain, authType) -> true) // 信任所有证书
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 2. 创建SSL连接工厂(忽略主机名验证)
|
||||||
|
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
|
||||||
|
sslContext,
|
||||||
|
NoopHostnameVerifier.INSTANCE // 信任所有主机名
|
||||||
|
);
|
||||||
|
|
||||||
|
// 3. 配置超时参数
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
|
.setConnectTimeout(30000) // 连接超时30秒
|
||||||
|
.setSocketTimeout(300000) // 读取超时5分钟
|
||||||
|
.setConnectionRequestTimeout(5000) // 连接池超时5秒
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 4. 构建HttpClient
|
||||||
|
return HttpClients.custom()
|
||||||
|
.setSSLSocketFactory(sslSocketFactory)
|
||||||
|
.setDefaultRequestConfig(requestConfig)
|
||||||
|
.build();
|
||||||
|
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
|
||||||
|
throw new RuntimeException("创建HTTPS客户端失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传仿真报告
|
||||||
|
*
|
||||||
|
* @param jobNo
|
||||||
|
* @param hkUploadFileReq
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public SdmResponse uploadHkFile(String jobNo, HkUploadFileReq hkUploadFileReq) {
|
||||||
|
SdmResponse response = SdmResponse.failed("文件上传失败");
|
||||||
|
String token = getHKCloudToken(appKey, appSecret, jobNo, HK_CLOUD_URL);
|
||||||
|
if (token == null || token.isEmpty())
|
||||||
|
{
|
||||||
|
response = SdmResponse.failed("获取token失败");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String url = HK_CLOUD_URL + HK_UPLOAD_FILE_URL_SUFFIX;
|
||||||
|
HttpPost httpPost = new HttpPost(url);
|
||||||
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create()
|
||||||
|
.setCharset(StandardCharsets.UTF_8); // 解决中文乱码
|
||||||
|
|
||||||
|
// 添加普通参数
|
||||||
|
builder.addPart("filePower", new StringBody(hkUploadFileReq.filePower,
|
||||||
|
ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
|
||||||
|
builder.addPart("waterMarkFlag", new StringBody(String.valueOf(hkUploadFileReq.waterMarkFlag),
|
||||||
|
ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
|
||||||
|
builder.addPart("waterMarkContent", new StringBody(hkUploadFileReq.waterMarkContent,
|
||||||
|
ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
|
||||||
|
builder.addPart("sysId", new StringBody(String.valueOf(hkUploadFileReq.sysId),
|
||||||
|
ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
|
||||||
|
builder.addPart("formId", new StringBody(String.valueOf(hkUploadFileReq.formId),
|
||||||
|
ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
|
||||||
|
builder.addPart("ComponentInstId", new StringBody(String.valueOf(hkUploadFileReq.componentInstId),
|
||||||
|
ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
|
||||||
|
builder.addPart("tableName", new StringBody(hkUploadFileReq.tableName,
|
||||||
|
ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
|
||||||
|
builder.addPart("columnName", new StringBody(hkUploadFileReq.columnName,
|
||||||
|
ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
|
||||||
|
builder.addPart("xmh", new StringBody(hkUploadFileReq.xmh,
|
||||||
|
ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
|
||||||
|
builder.addPart("gwh", new StringBody(hkUploadFileReq.gwh,
|
||||||
|
ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
|
||||||
|
|
||||||
|
// 追加多个文件(同一字段名files)
|
||||||
|
for (String filePath : hkUploadFileReq.files) {
|
||||||
|
File file = new File(filePath);
|
||||||
|
if (file.exists())
|
||||||
|
builder.addPart("files", new FileBody(file, ContentType.DEFAULT_BINARY, file.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建HttpPost请求
|
||||||
|
httpPost.setEntity(builder.build());
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CloseableHttpClient httpclient = createHttpsClient();
|
||||||
|
CloseableHttpResponse fileResponse = httpclient.execute(httpPost);
|
||||||
|
String responseContent = EntityUtils.toString(fileResponse.getEntity(), StandardCharsets.UTF_8);
|
||||||
|
if(responseContent != null && !responseContent.isEmpty())
|
||||||
|
{
|
||||||
|
JSONObject responseJson = JSONObject.parseObject(responseContent);
|
||||||
|
if(responseJson.containsKey("code"))
|
||||||
|
{
|
||||||
|
String code = responseJson.getString("code");
|
||||||
|
if(code != null && code.equals("0000"))
|
||||||
|
{
|
||||||
|
response = SdmResponse.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
response = SdmResponse.failed("上传文件异常");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推送代办状态
|
||||||
|
* @param todoId
|
||||||
|
* @param reason
|
||||||
|
* @param progress
|
||||||
|
* @param progressDescription
|
||||||
|
* @param userNo
|
||||||
|
* @param statusType doing(启动),turnDown(驳回),pause(暂停),restart(重启),updateProgress(提交进度),finished(完成),closed(关闭)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public SdmResponse pushTodoStatus(int todoId,String reason,int progress,String progressDescription,String userNo,String statusType)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SdmResponse getTodoAttachments()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SdmResponse getTodoList()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,16 +1,20 @@
|
|||||||
package com.sdm.system.controller;
|
package com.sdm.system.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.sdm.common.common.SdmResponse;
|
import com.sdm.common.common.SdmResponse;
|
||||||
import com.sdm.common.feign.inter.system.ISysLogFeignClient;
|
import com.sdm.common.feign.inter.system.ISysLogFeignClient;
|
||||||
import com.sdm.common.log.dto.SysLogDTO;
|
import com.sdm.common.log.dto.SysLogDTO;
|
||||||
import com.sdm.system.service.ISimulationLogService;
|
import com.sdm.system.model.resp.DailyOnlineStateResp;
|
||||||
|
import com.sdm.system.model.resp.LoginStateResp;
|
||||||
|
import com.sdm.system.service.ISysLogService;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springdoc.core.annotations.ParameterObject;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import java.util.List;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -25,7 +29,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
public class SystemLogController implements ISysLogFeignClient {
|
public class SystemLogController implements ISysLogFeignClient {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISimulationLogService logService;
|
private ISysLogService logService;
|
||||||
|
|
||||||
@PostMapping("/saveLog")
|
@PostMapping("/saveLog")
|
||||||
public SdmResponse saveLog(@RequestBody SysLogDTO req)
|
public SdmResponse saveLog(@RequestBody SysLogDTO req)
|
||||||
@@ -33,4 +37,32 @@ public class SystemLogController implements ISysLogFeignClient {
|
|||||||
return logService.saveLog(req);
|
return logService.saveLog(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
* @param page 分页对象
|
||||||
|
* @param sysLog 系统日志
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
public SdmResponse getLogPage(@ParameterObject Page page, @ParameterObject SysLogDTO sysLog) {
|
||||||
|
return logService.getLogByPage(page, sysLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计某时间段的用户登录数
|
||||||
|
* @param sysLog
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/getUserLoginStatistics")
|
||||||
|
public SdmResponse<List<LoginStateResp>> getUserLoginStatistics(@ParameterObject SysLogDTO sysLog) {
|
||||||
|
return logService.getUserLoginStatistics(sysLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某天每小时在线用户统计
|
||||||
|
*/
|
||||||
|
@GetMapping("/getHourlyOnlineStatistics")
|
||||||
|
public SdmResponse<DailyOnlineStateResp> getHourlyOnlineStatistics(@RequestParam @NotNull(message = "日期不能为空") String date) {
|
||||||
|
return logService.getHourlyOnlineStatistics(date);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
system/src/main/java/com/sdm/system/dao/SysLogMapper.java
Normal file
21
system/src/main/java/com/sdm/system/dao/SysLogMapper.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package com.sdm.system.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.sdm.system.model.dto.HourlyOnlineDto;
|
||||||
|
import com.sdm.system.model.entity.SysLog;
|
||||||
|
import com.sdm.system.model.resp.LoginStateResp;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface SysLogMapper extends BaseMapper<SysLog> {
|
||||||
|
|
||||||
|
List<LoginStateResp> countDailyLoginUsers(@Param("startTime") String startTime,
|
||||||
|
@Param("endTime") String endTime);
|
||||||
|
|
||||||
|
List<HourlyOnlineDto> getHourlyOnlineUsers(@Param("date") String date);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.sdm.system.model.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class HourlyOnlineDto {
|
||||||
|
|
||||||
|
@Schema(description = "小时")
|
||||||
|
private String hour;
|
||||||
|
|
||||||
|
@Schema(description = "在线用户数")
|
||||||
|
private Integer onlineCount;
|
||||||
|
|
||||||
|
}
|
||||||
133
system/src/main/java/com/sdm/system/model/entity/SysLog.java
Normal file
133
system/src/main/java/com/sdm/system/model/entity/SysLog.java
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
package com.sdm.system.model.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 日志表
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("sys_log")
|
||||||
|
@ApiModel(value="SysLog对象", description="日志表")
|
||||||
|
public class SysLog implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编号
|
||||||
|
*/
|
||||||
|
@Schema(description = "日志编号")
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志类型
|
||||||
|
*/
|
||||||
|
@Schema(description = "日志类型")
|
||||||
|
@TableField("logType")
|
||||||
|
private String logType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志标题
|
||||||
|
*/
|
||||||
|
@Schema(description = "日志标题")
|
||||||
|
@TableField("title")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建者
|
||||||
|
*/
|
||||||
|
@Schema(description = "创建人")
|
||||||
|
@TableField("createBy")
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
@TableField("createTime")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@Schema(description = "更新时间")
|
||||||
|
@TableField("updateTime")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作IP地址
|
||||||
|
*/
|
||||||
|
@Schema(description = "操作ip地址")
|
||||||
|
@TableField("remoteAddr")
|
||||||
|
private String remoteAddr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户代理
|
||||||
|
*/
|
||||||
|
@Schema(description = "用户代理")
|
||||||
|
@TableField("userAgent")
|
||||||
|
private String userAgent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求URI
|
||||||
|
*/
|
||||||
|
@Schema(description = "请求uri")
|
||||||
|
@TableField("requestUri")
|
||||||
|
private String requestUri;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作方式
|
||||||
|
*/
|
||||||
|
@Schema(description = "操作方式")
|
||||||
|
@TableField("method")
|
||||||
|
private String method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作提交的数据
|
||||||
|
*/
|
||||||
|
@Schema(description = "提交数据")
|
||||||
|
@TableField("params")
|
||||||
|
private String params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行时间
|
||||||
|
*/
|
||||||
|
@Schema(description = "方法执行时间")
|
||||||
|
@TableField("time")
|
||||||
|
private Long time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异常信息
|
||||||
|
*/
|
||||||
|
@Schema(description = "异常信息")
|
||||||
|
@TableField("exception")
|
||||||
|
private String exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务ID
|
||||||
|
*/
|
||||||
|
@Schema(description = "应用标识")
|
||||||
|
@TableField("serviceId")
|
||||||
|
private String serviceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标记
|
||||||
|
*/
|
||||||
|
@Schema(description = "删除标记,1:已删除,0:正常")
|
||||||
|
@TableField("delFlag")
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.sdm.system.model.resp;
|
||||||
|
|
||||||
|
import com.sdm.system.model.dto.HourlyOnlineDto;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DailyOnlineStateResp {
|
||||||
|
|
||||||
|
@Schema(description = "日期")
|
||||||
|
private String date;
|
||||||
|
|
||||||
|
@Schema(description = "每小时统计")
|
||||||
|
private List<HourlyOnlineDto> hourlyStats;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.sdm.system.model.resp;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LoginStateResp {
|
||||||
|
|
||||||
|
@Schema(description = "日期")
|
||||||
|
private String date;
|
||||||
|
|
||||||
|
@Schema(description = "登录用户数")
|
||||||
|
private Integer loginUserCount;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
package com.sdm.system.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.sdm.common.common.SdmResponse;
|
||||||
|
import com.sdm.common.log.dto.SysLogDTO;
|
||||||
|
import com.sdm.system.model.entity.SysLog;
|
||||||
|
import com.sdm.system.model.resp.DailyOnlineStateResp;
|
||||||
|
import com.sdm.system.model.resp.LoginStateResp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 日志表 服务类
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public interface ISysLogService extends IService<SysLog> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询日志
|
||||||
|
* @param page
|
||||||
|
* @param sysLog
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SdmResponse getLogByPage(Page page, SysLogDTO sysLog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计某时间段的用户登录数
|
||||||
|
* @param sysLog
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SdmResponse<List<LoginStateResp>> getUserLoginStatistics(SysLogDTO sysLog);
|
||||||
|
|
||||||
|
SdmResponse<DailyOnlineStateResp> getHourlyOnlineStatistics(String dateStr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入日志
|
||||||
|
* @param sysLog 日志对象
|
||||||
|
* @return true/false
|
||||||
|
*/
|
||||||
|
SdmResponse saveLog(SysLogDTO sysLog);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
|
||||||
|
package com.sdm.system.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.sdm.common.common.SdmResponse;
|
||||||
|
import com.sdm.common.entity.req.system.UserQueryReq;
|
||||||
|
import com.sdm.common.entity.resp.system.CIDUserResp;
|
||||||
|
import com.sdm.common.feign.impl.system.SysUserFeignClientImpl;
|
||||||
|
import com.sdm.common.log.dto.SysLogDTO;
|
||||||
|
import com.sdm.common.utils.CidSysUserUtil;
|
||||||
|
import com.sdm.system.dao.SysLogMapper;
|
||||||
|
import com.sdm.system.model.dto.HourlyOnlineDto;
|
||||||
|
import com.sdm.system.model.entity.SysLog;
|
||||||
|
import com.sdm.system.model.resp.DailyOnlineStateResp;
|
||||||
|
import com.sdm.system.model.resp.LoginStateResp;
|
||||||
|
import com.sdm.system.service.ISysLogService;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 日志表 服务实现类
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ISysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements ISysLogService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
SysUserFeignClientImpl sysUserFeignClient;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SdmResponse<Page> getLogByPage(Page page, SysLogDTO sysLog) {
|
||||||
|
LambdaQueryWrapper<SysLog> wrapper = Wrappers.lambdaQuery();
|
||||||
|
if (StrUtil.isNotBlank(sysLog.getLogType())) {
|
||||||
|
wrapper.eq(SysLog::getLogType, sysLog.getLogType());
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(sysLog.getCreateBy())) {
|
||||||
|
wrapper.eq(SysLog::getCreateBy, sysLog.getCreateBy());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ArrayUtil.isNotEmpty(sysLog.getCreateTime())) {
|
||||||
|
wrapper.ge(SysLog::getCreateTime, sysLog.getCreateTimeArr()[0])
|
||||||
|
.le(SysLog::getCreateTime, sysLog.getCreateTimeArr()[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Page<SysLog> pageData = baseMapper.selectPage(page, wrapper);
|
||||||
|
setCreatorNames(pageData.getRecords());
|
||||||
|
return SdmResponse.success(pageData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SdmResponse<List<LoginStateResp>> getUserLoginStatistics(SysLogDTO sysLog) {
|
||||||
|
List<LoginStateResp> respList = baseMapper.countDailyLoginUsers(sysLog.getCreateTimeArr()[0], sysLog.getCreateTimeArr()[1]);
|
||||||
|
return SdmResponse.success(respList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SdmResponse<DailyOnlineStateResp> getHourlyOnlineStatistics(String dateStr) {
|
||||||
|
// 获取每小时在线用户数
|
||||||
|
List<HourlyOnlineDto> hourlyStats = baseMapper.getHourlyOnlineUsers(dateStr);
|
||||||
|
|
||||||
|
DailyOnlineStateResp result = new DailyOnlineStateResp();
|
||||||
|
result.setDate(dateStr);
|
||||||
|
result.setHourlyStats(hourlyStats);
|
||||||
|
return SdmResponse.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCreatorNames(List<SysLog> list) {
|
||||||
|
try {
|
||||||
|
if (ObjectUtils.isNotEmpty(list)) {
|
||||||
|
// 提取去重的 creatorId
|
||||||
|
List<String> creatorIds = list.stream()
|
||||||
|
.map(SysLog::getCreateBy)
|
||||||
|
.filter(createBy -> !"anonymousUser".equals(createBy))
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// 远程查询用户信息
|
||||||
|
SdmResponse<List<CIDUserResp>> userListSdmRsp = sysUserFeignClient.listUserByIds(
|
||||||
|
UserQueryReq.builder().userIds(creatorIds.stream().map(Long::valueOf).toList()).build()
|
||||||
|
);
|
||||||
|
// 批量设置 creatorName
|
||||||
|
if (userListSdmRsp.isSuccess() && CollectionUtils.isNotEmpty(userListSdmRsp.getData())) {
|
||||||
|
Map<Long, CIDUserResp> cidUserMap = CidSysUserUtil.getCidUserToMap(userListSdmRsp.getData());
|
||||||
|
list.forEach(sysLog -> {
|
||||||
|
Long creatorId = Long.valueOf(sysLog.getCreateBy());
|
||||||
|
CIDUserResp cidUser = cidUserMap.get(creatorId);
|
||||||
|
String username = Objects.isNull(cidUser) ? "" : org.apache.commons.lang3.StringUtils.firstNonBlank(
|
||||||
|
cidUser.getNickname(),
|
||||||
|
cidUser.getUsername(),
|
||||||
|
cidUser.getRealName()
|
||||||
|
);
|
||||||
|
sysLog.setCreateBy(username);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("[getLogByPage] setCreatorNames error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入日志
|
||||||
|
* @param sysLog 日志对象
|
||||||
|
* @return true/false
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public SdmResponse saveLog(SysLogDTO sysLog) {
|
||||||
|
SysLog log = new SysLog();
|
||||||
|
BeanUtils.copyProperties(sysLog, log);
|
||||||
|
return SdmResponse.success(this.save(log));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
59
system/src/main/resources/mapper/SysLogMapper.xml
Normal file
59
system/src/main/resources/mapper/SysLogMapper.xml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?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.sdm.system.dao.SysLogMapper">
|
||||||
|
|
||||||
|
<select id="countDailyLoginUsers" resultType="com.sdm.system.model.resp.LoginStateResp">
|
||||||
|
SELECT
|
||||||
|
DATE(createTime) as date,
|
||||||
|
COUNT(DISTINCT createBy) as loginUserCount
|
||||||
|
FROM sys_log
|
||||||
|
WHERE
|
||||||
|
title LIKE '%登录成功%'
|
||||||
|
AND createTime >= #{startTime}
|
||||||
|
AND createTime <= #{endTime}
|
||||||
|
GROUP BY DATE(createTime)
|
||||||
|
ORDER BY date
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getHourlyOnlineUsers" resultType="com.sdm.system.model.dto.HourlyOnlineDto">
|
||||||
|
SELECT
|
||||||
|
HOUR(hour_time) as hour,
|
||||||
|
COUNT(DISTINCT user_id) as onlineCount
|
||||||
|
FROM (
|
||||||
|
-- 生成时间序列(00:00:00 到 23:00:00)
|
||||||
|
SELECT
|
||||||
|
DATE_ADD(CONCAT(#{date}, ' 00:00:00'), INTERVAL (t0.idx + t1.idx*10 + t2.idx*100) HOUR) as hour_time
|
||||||
|
FROM
|
||||||
|
(SELECT 0 as idx UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t0,
|
||||||
|
(SELECT 0 as idx UNION SELECT 1 UNION SELECT 2) t1,
|
||||||
|
(SELECT 0 as idx) t2
|
||||||
|
WHERE DATE_ADD(CONCAT(#{date}, ' 00:00:00'), INTERVAL (t0.idx + t1.idx*10 + t2.idx*100) HOUR) < DATE_ADD(CONCAT(#{date}, ' 00:00:00'), INTERVAL 24 HOUR)
|
||||||
|
) hours
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT
|
||||||
|
login.createBy as user_id,
|
||||||
|
login.createTime as login_time,
|
||||||
|
-- 如果有退出记录就用退出时间,否则用登录时间+30分钟作为虚拟退出时间
|
||||||
|
COALESCE(
|
||||||
|
MIN(logout.createTime),
|
||||||
|
DATE_ADD(login.createTime, INTERVAL 30 MINUTE)
|
||||||
|
) as logout_time
|
||||||
|
FROM sys_log login
|
||||||
|
LEFT JOIN sys_log logout ON (
|
||||||
|
logout.createBy = login.createBy
|
||||||
|
AND logout.title = '退出登录'
|
||||||
|
AND logout.createTime > login.createTime
|
||||||
|
)
|
||||||
|
WHERE login.title = '登录成功'
|
||||||
|
AND DATE(login.createTime) = #{date}
|
||||||
|
GROUP BY login.createBy, login.createTime
|
||||||
|
) sessions ON (
|
||||||
|
-- 用户在这个小时内在线
|
||||||
|
sessions.login_time <= DATE_ADD(hours.hour_time, INTERVAL 59 MINUTE)
|
||||||
|
AND (sessions.logout_time IS NULL OR sessions.logout_time > hours.hour_time)
|
||||||
|
)
|
||||||
|
GROUP BY HOUR(hour_time)
|
||||||
|
ORDER BY hour
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -163,7 +163,6 @@ public class SimulationTaskPoolServiceImpl extends BaseService implements ISimul
|
|||||||
String fileId = standardIds[1].trim();
|
String fileId = standardIds[1].trim();
|
||||||
fileIdList.add(Long.valueOf(fileId));
|
fileIdList.add(Long.valueOf(fileId));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
SaveFileSimulationMappingReq req = new SaveFileSimulationMappingReq();
|
SaveFileSimulationMappingReq req = new SaveFileSimulationMappingReq();
|
||||||
req.setSimulationPoolTaskId(taskPoolItem.uuid);
|
req.setSimulationPoolTaskId(taskPoolItem.uuid);
|
||||||
@@ -172,7 +171,9 @@ public class SimulationTaskPoolServiceImpl extends BaseService implements ISimul
|
|||||||
req.setFileIds(fileIdList);
|
req.setFileIds(fileIdList);
|
||||||
saveFileSimulationMappingReq.add(req);
|
saveFileSimulationMappingReq.add(req);
|
||||||
}
|
}
|
||||||
simulationMappingFeignClient.batchSaveFileSimulationMapping(saveFileSimulationMappingReq);
|
if(!saveFileSimulationMappingReq.isEmpty()) {
|
||||||
|
simulationMappingFeignClient.batchSaveFileSimulationMapping(saveFileSimulationMappingReq);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1444,7 +1445,7 @@ public class SimulationTaskPoolServiceImpl extends BaseService implements ISimul
|
|||||||
response = SdmResponse.failed("分析项库不存在");
|
response = SdmResponse.failed("分析项库不存在");
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
int oldPoolId = oldPoolBrief.id;
|
int oldPoolId = currPoolBrief.id;
|
||||||
if(updateBean.bNewVersion)
|
if(updateBean.bNewVersion)
|
||||||
{
|
{
|
||||||
//在当前分析项库活动版本记录中生成新版本
|
//在当前分析项库活动版本记录中生成新版本
|
||||||
|
|||||||
Reference in New Issue
Block a user