From 07c80a52302e47cc4eb5fd19e4eb2dad6c7c7885 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期五, 24 十一月 2023 14:38:34 +0800
Subject: [PATCH] 本地日志文件下载功能完善
---
Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/mapper/LogOperateMapper.java | 16 +
Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/LogApplication.java | 2
Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/ILogLocalService.java | 40 ++
Source/UBCS-WEB/src/views/monitor/log/operateLog.vue | 0
Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogOperateController.java | 23 +
Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogErrorController.java | 5
Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java | 318 +++++++++++++++++++
Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/ILogOperateService.java | 29 +
Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogOperateServiceImpl.java | 52 +++
Source/UBCS-WEB/src/views/monitor/log/authLog.vue | 0
Source/UBCS-WEB/src/views/monitor/log/localLog.vue | 208 +++++++++++++
Source/UBCS-WEB/src/views/monitor/log/loginLog.vue | 139 ++++++++
Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogLocalController.java | 83 +++++
13 files changed, 910 insertions(+), 5 deletions(-)
diff --git a/Source/UBCS-WEB/src/views/monitor/log/authLog.vue b/Source/UBCS-WEB/src/views/monitor/log/authLog.vue
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/UBCS-WEB/src/views/monitor/log/authLog.vue
diff --git a/Source/UBCS-WEB/src/views/monitor/log/localLog.vue b/Source/UBCS-WEB/src/views/monitor/log/localLog.vue
new file mode 100644
index 0000000..9f2a50b
--- /dev/null
+++ b/Source/UBCS-WEB/src/views/monitor/log/localLog.vue
@@ -0,0 +1,208 @@
+<template>
+ <basic-container>
+ <avue-crud ref="crud"
+ v-model="form"
+ :before-close="beforeClose"
+ :before-open="beforeOpen"
+ :data="data"
+ :option="option"
+ :permission="permissionList"
+ :table-loading="loading"
+ @row-del="rowDel"
+ @search-change="searchChange"
+ @search-reset="searchReset"
+ @selection-change="selectionChange"
+ @row-click="clickRowChange"
+ @current-change="currentChange"
+ @size-change="sizeChange"
+ @refresh-change="refreshChange"
+ @on-load="onLoad"
+ @tree-load="treeLoad">
+ <template slot="menu" slot-scope="scope">
+ <el-button
+ icon="el-icon-download el-icon--right"
+ size="small"
+ type="text"
+ :loading="downloadLoading"
+ @click="downLoadLogFile(scope.row)"
+ v-if="permissionList.downLoadBtn"
+ >涓嬭浇
+ </el-button>
+ </template>
+ </avue-crud>
+ </basic-container>
+ </template>
+
+ <script>
+ import {getLazyList, deleteLocalLog,downLoadLog} from "@/api/logs";
+ import func from "@/util/func";
+ import {mapGetters} from "vuex";
+
+ export default {
+ data() {
+ return {
+ form: {},
+ selectionList: [],
+ query: {},
+ logPath: "",
+ loading: true,
+ page: {
+ pageSize: 10,
+ currentPage: 1,
+ total: 0
+ },
+ option: {
+ height: "auto",
+ lazy: true,
+ columnBtn: false,
+ tip: false,
+ searchShow: true,
+ searchMenuSpan: 6,
+ tree: true,
+ border: true,
+ index: true,
+ selection: true,
+ editBtn: false,
+ delBtn: true,
+ addBtn: false,
+ viewBtn: false,
+ // menuWidth: 300,
+ dialogClickModal: false,
+ highlightCurrentRow: true, //琛岄�変腑鏃堕珮浜�
+ rowKey: "logName", //琛屾暟鎹殑 Key锛岀敤鏉ヤ紭鍖� Table 鐨勬覆鏌�
+ column: [
+ {
+ label: "鏈嶅姟鍚嶇О",
+ prop: "serviceName",
+ width:'120',
+ search: true
+ },
+ {
+ label: "鏈嶅姟ID",
+ prop: "serviceId",
+ search: true
+ },
+ {
+ label: "鏃ュ織璺緞",
+ prop: "logPath",
+ width:'160'
+ },
+ {
+ label: "鏃ュ織鍚嶇О",
+ prop: "logName",
+ width:'80',
+ },
+ {
+ label: "鏃ュ織绫诲瀷",
+ prop: "logType"
+ },
+ {
+ label: "鍒涘缓鏃堕棿",
+ prop: "createTime",
+ width:'180'
+ },
+ {
+ label: "鏈�鍚庝慨鏀规椂闂�",
+ prop: "lastModifier",
+ width:'180'
+ }
+ ]
+ },
+ data: [],
+ downloadLoading: false,
+ };
+ },
+ computed: {
+ ...mapGetters(["permission"]),
+ permissionList() {
+ return {
+ delBtn: this.vaildData(this.permission.localLog.localLog_delete, false),
+ downLoadBtn: this.vaildData(this.permission.localLog.localLog_dwonload, false)
+ };
+ }
+ },
+ methods: {
+
+ downLoadLogFile(row){
+ this.downloadLoading = true;
+ let logPath = row.hasChildren ? row.logPath:row.logPath+"\\"+row.logName;
+ downLoadLog(Object.assign({},row,{logFullPaths:logPath})).then(res=>{
+ func.downloadFileByBlobHandler(res);
+ this.downloadLoading = false;
+ }).catch((res)=>{
+ //this.$message.warning(res)
+ this.downloadLoading = false;
+ })
+ },
+ // 琛屽垹闄�
+ rowDel(row, index, done) {
+ this.$confirm("纭畾灏嗛�夋嫨鐨勬棩蹇楁枃浠跺垹闄�?", {
+ confirmButtonText: "纭畾",
+ cancelButtonText: "鍙栨秷",
+ type: "warning"
+ })
+ .then(() => {
+ let logPath = row.hasChildren ? row.logPath:row.logPath+"\\"+row.logName;
+ return deleteLocalLog(Object.assign({},row,{logFullPaths:logPath}));
+ })
+ .then(() => {
+ this.$message({
+ type: "success",
+ message: "鎿嶄綔鎴愬姛!"
+ });
+ // 鏁版嵁鍥炶皟杩涜鍒锋柊
+ done(row);
+ //this.onLoad();
+ });
+ },
+ searchReset() {
+ this.query = {};
+ this.parentId = 0;
+ this.onLoad(this.page);
+ },
+ searchChange(params, done) {
+ this.query = params;
+ this.parentId = '';
+ this.page.currentPage = 1;
+ this.onLoad(this.page, params);
+ done();
+ },
+ clickRowChange(row) {
+ this.$refs.crud.toggleSelection();
+ this.selectionList = row;
+ this.$refs.crud.setCurrentRow(row);
+ this.$refs.crud.toggleRowSelection(row); //閫変腑褰撳墠琛�
+ },
+ selectionChange(list) {
+ this.selectionList = list;
+ this.$refs.crud.setCurrentRow(this.selectionList[list.length - 1]);
+ },
+ selectionClear() {
+ this.selectionList = [];
+ this.$refs.crud.toggleSelection();
+ },
+ refreshChange() {
+ this.onLoad(this.page, this.query);
+ },
+ onLoad(page, params = {}) {
+ this.loading = true;
+ //Object.assign(params, this.query)
+ getLazyList({"logPath": this.logPath}).then(res => {
+ this.data = res.data.data;
+ this.loading = false;
+ this.selectionClear();
+ });
+ },
+ treeLoad(tree, treeNode, resolve) {
+ const logPath = tree.logPath;
+ getLazyList({"logPath": logPath}).then(res => {
+ resolve(res.data.data);
+ });
+ }
+ }
+ };
+ </script>
+
+ <style>
+ </style>
+
\ No newline at end of file
diff --git a/Source/UBCS-WEB/src/views/monitor/log/loginLog.vue b/Source/UBCS-WEB/src/views/monitor/log/loginLog.vue
new file mode 100644
index 0000000..1298f88
--- /dev/null
+++ b/Source/UBCS-WEB/src/views/monitor/log/loginLog.vue
@@ -0,0 +1,139 @@
+<template>
+ <basic-container>
+ <avue-crud :option="option"
+ :table-loading="loading"
+ :data="data"
+ ref="crud"
+ v-model="form"
+ :permission="permissionList"
+ :page.sync="page"
+ :before-open="beforeOpen"
+ @search-change="searchChange"
+ @search-reset="searchReset"
+ @current-change="currentChange"
+ @size-change="sizeChange"
+ @refresh-change="refreshChange"
+ @on-load="onLoad">
+ </avue-crud>
+ </basic-container>
+</template>
+
+<script>
+ import {getUsualList, getUsualLogs} from "@/api/logs";
+ import {mapGetters} from "vuex";
+
+ export default {
+ data() {
+ return {
+ form: {},
+ selectionList: [],
+ query: {},
+ loading: true,
+ page: {
+ pageSize: 10,
+ currentPage: 1,
+ total: 0
+ },
+ option: {
+ height: 'auto',
+ calcHeight: 30,
+ columnBtn:false,
+ tip: false,
+ searchShow: true,
+ searchMenuSpan: 6,
+ border: true,
+ index: true,
+ viewBtn: true,
+ editBtn: false,
+ addBtn: false,
+ delBtn: false,
+ menuWidth: 120,
+ dialogType: 'drawer',
+ column: [
+ {
+ label: "鐢ㄦ埛鍚�",
+ prop: "serviceId",
+ search: true
+ },
+ {
+ label: "濮撳悕",
+ prop: "serverHost",
+ search: true
+ },
+ {
+ label: "鐢ㄦ埛id",
+ prop: "serverIp"
+ },
+ {
+ label: "妯″潡",
+ prop: "env",
+ width:'80'
+ },
+ {
+ label: "鏃堕棿",
+ prop: "logLevel"
+ },
+ {
+ label: "鎿嶄綔缁撴灉",
+ prop: "logId"
+ },
+ {
+ label: "鎻忚堪",
+ prop: "requestUri"
+ },
+ ]
+ },
+ data: []
+ };
+ },
+ computed: {
+ ...mapGetters(["permission"]),
+ permissionList() {
+ return {
+ viewBtn: this.vaildData(this.permission.log_usual.log_usual_view, false)
+ };
+ }
+ },
+ methods: {
+ searchReset() {
+ this.query = {};
+ this.onLoad(this.page);
+ },
+ searchChange(params, done) {
+ this.query = params;
+ this.page.currentPage = 1;
+ this.onLoad(this.page, params);
+ done();
+ },
+ beforeOpen(done, type) {
+ if (["edit", "view"].includes(type)) {
+ getUsualLogs(this.form.id).then(res => {
+ this.form = res.data.data;
+ });
+ }
+ done();
+ },
+ currentChange(currentPage){
+ this.page.currentPage = currentPage;
+ },
+ sizeChange(pageSize){
+ this.page.pageSize = pageSize;
+ },
+ refreshChange() {
+ this.onLoad(this.page, this.query);
+ },
+ onLoad(page, params = {}) {
+ this.loading = true;
+ getUsualList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
+ const data = res.data.data;
+ this.page.total = data.total;
+ this.data = data.records;
+ this.loading = false;
+ });
+ }
+ }
+ };
+</script>
+
+<style>
+</style>
diff --git a/Source/UBCS-WEB/src/views/monitor/log/operateLog.vue b/Source/UBCS-WEB/src/views/monitor/log/operateLog.vue
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Source/UBCS-WEB/src/views/monitor/log/operateLog.vue
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/LogApplication.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/LogApplication.java
index 3cb1c31..ea8f6dd 100644
--- a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/LogApplication.java
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/LogApplication.java
@@ -29,7 +29,7 @@
* @author Chill
*/
@EnableDiscoveryClient
-@EnableFeignClients("org.springblade")
+@EnableFeignClients(basePackages = {"com.vci.ubcs", "org.springblade"})
@SpringBootApplication
public class LogApplication {
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogErrorController.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogErrorController.java
index d040838..e43b0f3 100644
--- a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogErrorController.java
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogErrorController.java
@@ -25,10 +25,7 @@
import org.springblade.core.mp.support.Query;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Map;
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogLocalController.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogLocalController.java
new file mode 100644
index 0000000..8fea8d4
--- /dev/null
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogLocalController.java
@@ -0,0 +1,83 @@
+package com.vci.ubcs.log.controller;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.nacos.common.utils.StringUtils;
+import com.vci.ubcs.log.dto.LocalLogVO;
+import com.vci.ubcs.log.service.ILogLocalService;
+import com.vci.ubcs.log.entity.LocalLog;
+import com.vci.ubcs.resource.utils.FileDownloadUtil;
+import com.vci.ubcs.starter.web.util.ControllerUtil;
+import com.vci.ubcs.starter.web.util.LangBaseUtil;
+import com.vci.ubcs.starter.web.util.VciBaseUtil;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springblade.core.tenant.annotation.NonDS;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springframework.web.bind.annotation.*;
+import springfox.documentation.annotations.ApiIgnore;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.rmi.ServerException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 鏈湴绯荤粺鏃ュ織
+ * @author ludc
+ * @date 2023/10/31 15:37
+ */
+@NonDS
+@Slf4j
+@RestController
+@AllArgsConstructor
+@RequestMapping("/localLog")
+public class LogLocalController {
+
+ private final ILogLocalService logLocalService;
+
+ /**
+ * 鑾峰彇鏃ュ織鏂囦欢鍒楄〃
+ * @param localLog
+ * @return
+ */
+ @PostMapping("/lazy-list")
+ public R<List<LocalLog>> getSystemLogList(@RequestBody LocalLog localLog){
+ return R.data(logLocalService.getSystemLogList(localLog.getLogPath()));
+ }
+
+ /**
+ * 涓嬭浇鏃ュ織鏂囦欢
+ * @param localLogVO 涓嬭浇鏃ュ織鐨勫叏璺緞闆嗗悎
+ * @param response
+ * @return
+ */
+ @RequestMapping(value = "/downLoadLog",method = {RequestMethod.GET,RequestMethod.POST})
+ public void downloadLogByServiceName(@RequestBody LocalLogVO localLogVO, HttpServletResponse response) throws IOException {
+ try {
+ //ControllerUtil.writeFileToResponse(response,excelName);
+ FileDownloadUtil.downloadFileLocal(response, logLocalService.downloadLogByServiceNameAndFileName(localLogVO),true);
+ } catch (Throwable e) {
+ //濡傛灉鍑洪敊,鎶婇敊璇俊鎭啓鍒皌ext
+ String msg = LangBaseUtil.getErrorMsg(e);
+ if(StringUtils.isBlank(msg)){
+ msg = "鏈煡閿欒";
+ }
+ ControllerUtil.writeDataToResponse(response,msg.getBytes(StandardCharsets.UTF_8),null);
+ }
+ }
+
+ /**
+ * 鍒犻櫎鏃ュ織鏂囦欢
+ * @param localLogVO
+ * @return
+ * @throws ServerException
+ */
+ @DeleteMapping("/deleteLogFile")
+ public R deleteLogFile(@RequestBody LocalLogVO localLogVO) throws ServerException {
+ return logLocalService.deleteLogFile(localLogVO);
+ }
+
+}
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogOperateController.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogOperateController.java
new file mode 100644
index 0000000..3263ddd
--- /dev/null
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/controller/LogOperateController.java
@@ -0,0 +1,23 @@
+package com.vci.ubcs.log.controller;
+
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springblade.core.tenant.annotation.NonDS;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 鎿嶄綔鏃ュ織绠$悊:(鍖呮嫭鐧诲綍鏃ュ織銆佹搷浣滄棩蹇椼�佹巿鏉冩棩蹇楋紝浠ュ強绠$悊鍛樼殑浠ヤ笂涓夌鏃ュ織)
+ * @author ludc
+ * @date 2023/11/24 10:43
+ */
+@NonDS
+@Slf4j
+@RestController
+@AllArgsConstructor
+@RequestMapping("/operateLog")
+public class LogOperateController {
+
+
+
+}
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/mapper/LogOperateMapper.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/mapper/LogOperateMapper.java
new file mode 100644
index 0000000..8526497
--- /dev/null
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/mapper/LogOperateMapper.java
@@ -0,0 +1,16 @@
+package com.vci.ubcs.log.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.vci.ubcs.log.entity.LogOperate;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 鎿嶄綔鏃ュ織绠$悊:(鍖呮嫭鐧诲綍鏃ュ織銆佹搷浣滄棩蹇椼�佹巿鏉冩棩蹇楋紝浠ュ強绠$悊鍛樼殑浠ヤ笂涓夌鏃ュ織)
+ * @author ludc
+ * @date 2023/11/24 10:50
+ */
+@Mapper
+public interface LogOperateMapper extends BaseMapper<LogOperate> {
+
+
+}
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/ILogLocalService.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/ILogLocalService.java
new file mode 100644
index 0000000..38a03f0
--- /dev/null
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/ILogLocalService.java
@@ -0,0 +1,40 @@
+package com.vci.ubcs.log.service;
+
+import com.vci.ubcs.log.dto.LocalLogVO;
+import com.vci.ubcs.log.entity.LocalLog;
+import com.vci.ubcs.resource.bo.FileObjectBO;
+import org.springblade.core.tool.api.R;
+
+import java.rmi.ServerException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 鏈湴绯荤粺鏃ュ織
+ * @author ludc
+ * @date 2023/10/31 15:38
+ */
+public interface ILogLocalService {
+
+ /**
+ * 鏌ョ湅锛屾湰鍦扮郴缁熸棩蹇楀垪琛�
+ * @param logParentPath
+ * @return
+ */
+ List<LocalLog> getSystemLogList(String logParentPath);
+
+ /**
+ * 涓嬭浇锛屾牴鎹湇鍔″悕鎵�鍦ㄦ枃浠跺悕鍜屾枃浠跺悕涓嬭浇鏂囦欢
+ * @param localLogVO 涓嬭浇鏃ュ織鐨勫璞�
+ * @return 鏂囦欢鐨勪俊鎭�
+ */
+ FileObjectBO downloadLogByServiceNameAndFileName(LocalLogVO localLogVO) throws ServerException;
+
+ /**
+ * 鍒犻櫎锛屾牴鎹湇鍔℃墍鍦ㄦ枃浠跺悕锛屽拰鏃ュ織鏂囦欢鍚嶇О鍒犻櫎
+ * @param localLogVO
+ * @return 鎵ц缁撴灉
+ */
+ R deleteLogFile(LocalLogVO localLogVO) throws ServerException;
+
+}
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/ILogOperateService.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/ILogOperateService.java
new file mode 100644
index 0000000..6af6c3d
--- /dev/null
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/ILogOperateService.java
@@ -0,0 +1,29 @@
+package com.vci.ubcs.log.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.vci.ubcs.log.entity.LogOperate;
+
+import java.util.List;
+
+/**
+ * 鎿嶄綔鏃ュ織绠$悊:(鍖呮嫭鐧诲綍鏃ュ織銆佹搷浣滄棩蹇椼�佹巿鏉冩棩蹇楋紝浠ュ強绠$悊鍛樼殑浠ヤ笂涓夌鏃ュ織)
+ * @author ludc
+ * @date 2023/11/24 10:50
+ */
+public interface ILogOperateService extends IService<LogOperate> {
+
+ /**
+ * 淇濆瓨鎿嶄綔鏃ュ織
+ * @param logOperate
+ * @return
+ */
+ boolean saveLogOperate(LogOperate logOperate);
+
+ /**
+ * 鏉′欢鏌ヨ鑾峰彇鏃ュ織鍒楄〃
+ * @param logOperate
+ * @return
+ */
+ List<LogOperate> listByCondition(LogOperate logOperate);
+
+}
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java
new file mode 100644
index 0000000..f8ba775
--- /dev/null
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogLocalServiceImpl.java
@@ -0,0 +1,318 @@
+package com.vci.ubcs.log.service.impl;
+
+import com.vci.ubcs.log.dto.LocalLogVO;
+import com.vci.ubcs.log.service.ILogLocalService;
+import com.vci.ubcs.log.entity.LocalLog;
+import com.vci.ubcs.resource.utils.FileUtil;
+import com.vci.ubcs.resource.utils.ZipUtil;
+import com.vci.ubcs.resource.vo.FileObjectVO;
+import com.vci.ubcs.starter.exception.VciBaseException;
+import com.vci.ubcs.starter.web.util.BeanUtil;
+import com.vci.ubcs.starter.web.util.VciBaseUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.IOUtils;
+import org.springblade.core.log.exception.ServiceException;
+import com.vci.ubcs.omd.cache.EnumCache;
+import com.vci.ubcs.omd.enums.EnumEnum;
+import com.vci.ubcs.resource.bo.FileObjectBO;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.Resource;
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.rmi.ServerException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 鏈湴绯荤粺鏃ュ織
+ * @author ludc
+ * @date 2023/10/31 15:39
+ */
+@Service
+@Slf4j
+public class LogLocalServiceImpl implements ILogLocalService{
+
+ /**
+ * 鍚勪釜鏈嶅姟瀛樻斁鐨勭殑鐖惰矾寰�
+ */
+ @Value("${local-log.parent-path:/data1/ubcs/ubcs-server}")
+ private String PARENTPATH;
+
+ /**
+ * 鏃ュ織鏂囦欢鐨勫叿浣撲綅缃�
+ */
+ @Value("${local-log.log-path:/target/log}")
+ private String LOGPATH;
+
+ /**
+ * 褰撳墠鎿嶄綔绯荤粺锛屾槸鍚︿负windows绯荤粺
+ */
+ private Boolean isWindows = true;
+
+ {
+ String os = System.getProperty("os.name").toLowerCase();
+ //榛樿灏遍厤缃负windows鐨勶紝濡傛灉涓嶆槸褰撳墠绯荤粺涓嶆槸windows灏遍渶瑕佸鍏惰浆鎹负linux鐨勬枃浠惰矾寰勬牸寮�
+ if (!os.contains("win")) {
+ this.PARENTPATH = this.PARENTPATH.substring(this.PARENTPATH.lastIndexOf(":") + 1).replace("\\", "/");
+ this.LOGPATH = this.LOGPATH.replace("\\", "/");
+ this.isWindows = false;
+ }
+ }
+
+ /**
+ * 鍘嬬缉鏂囦欢鐨勫伐鍏风被
+ */
+ @Resource
+ private ZipUtil zipUtil;
+
+ /**
+ * 鑾峰彇鏈湴鏃ュ織鍒楄〃
+ * @param logParentPath
+ * @return
+ */
+ //@Override
+ public List<LocalLog> getSystemLogList(String logParentPath) {
+ List<LocalLog> localLogs = new ArrayList<>();
+ // 涓嶄负绌鸿鏄庢槸鍔犺浇褰撳墠杩欎釜鏈嶅姟璺緞涓嬬殑鏃ュ織鏂囦欢
+ if(Func.isNotEmpty(logParentPath)){
+ File file = new File(logParentPath);
+ if (file.isDirectory()) {
+ File[] files = file.listFiles();
+ Arrays.stream(files).forEach(item->{
+ // 缁勫缓鏃ュ織鏂囦欢瀵硅薄
+ LocalLog localLog = new LocalLog();
+ localLog.setLogName(item.getName());
+ localLog.setLogType(getLogType(item.getName()));
+ localLog.setCreateTime(getLastModifiedOrCreatTime(false,logParentPath));
+ localLog.setLastModifier(getLastModifiedOrCreatTime(true,logParentPath));
+ localLog.setLogPath(logParentPath);
+ String serviceId = getServiceId(logParentPath);
+ localLog.setServiceId(serviceId);
+ localLog.setServiceName(getServiceName(serviceId));
+ localLog.setHasChildren(false);
+ localLogs.add(localLog);
+ });
+ }
+ }else {
+ File fileDir = new File(PARENTPATH);
+ File[] childDir = fileDir.listFiles();
+ Arrays.stream(childDir).forEach(dir->{
+ if(dir.getName().contains("ubcs_")){
+ String fullPath = dir.getPath() + LOGPATH;
+ File file = new File(fullPath);
+ LocalLog localLog = new LocalLog();
+ localLog.setLastModifier(getLastModifiedOrCreatTime(true,fullPath));
+ localLog.setCreateTime(getLastModifiedOrCreatTime(false,fullPath));
+ localLog.setLogPath(fullPath);
+ String serviceId = getServiceId(file.getPath());
+ localLog.setServiceId(serviceId);
+ String serviceName = getServiceName(serviceId);
+ localLog.setServiceName(serviceName);
+ localLog.setLogType(serviceName+"鏃ュ織鐖剁洰褰�");
+ localLog.setLogName(serviceName+"鏃ュ織鐖剁洰褰�");
+ localLog.setHasChildren(true);
+ localLogs.add(localLog);
+ }
+ });
+ }
+ return localLogs;
+ }
+
+ /**
+ * 鑾峰彇鏂囦欢鏈�鍚庝慨鏀规垨鑰呭垱寤烘椂闂�
+ * @param isModifier
+ * @return
+ */
+ private String getLastModifiedOrCreatTime(boolean isModifier,String pathStr) {
+ Path path = FileSystems.getDefault().getPath(pathStr);
+ String date = "";
+ try {
+ BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ // 鏄幏鍙栨渶鍚庝慨鏀规椂闂�
+ if(isModifier){
+ date = dateFormat.format(new Date(attr.lastModifiedTime().toMillis()));
+ }else {
+ date = dateFormat.format(new Date(attr.creationTime().toMillis()));
+ }
+ } catch (IOException e) {
+ throw new ServiceException("Error reading file date attributes: " + e.getMessage());
+ }
+ return date;
+ }
+
+ /**
+ * 鑾峰彇鏃ュ織绫诲瀷
+ * @param fileName
+ * @return
+ */
+ private String getLogType(String fileName){
+ //鍒ゆ柇鏃ュ織鐨勭殑绫诲瀷
+ if (fileName.contains("error")) {
+ return "Error";
+ } else if (fileName.contains("info")) {
+ return "Info";
+ } else if (fileName.contains("warning")) {
+ return "Warning";
+ } else {
+ return "Unknown";
+ }
+ }
+
+ /**
+ * 鑾峰彇鏈嶅姟ID
+ * @param servciePath
+ * @return
+ */
+ private String getServiceId(String servciePath){
+ // 鏍规嵁褰撳墠鎿嶄綔绯荤粺鏉ュ喅瀹氭槸閫氳繃浠�涔堝瓧绗︽潵鎴彇
+ String[] parts = servciePath.split(this.isWindows ? "\\\\":"/");
+ String extractedString = "";
+ if(parts.length > 3){
+ extractedString = parts[parts.length - 3];
+ }
+ return extractedString;
+ }
+
+ /**
+ * 鑾峰彇鏈嶅姟鍚嶇О
+ * @param serViceId
+ * @return
+ */
+ private String getServiceName(String serViceId){
+ return EnumCache.getValue(EnumEnum.SERCIVE_NAME_ROLE, serViceId);
+ }
+
+ /**
+ * 鎴彇璺緞涓殑鏃ュ織鏂囦欢鍚嶇О
+ * @param logFullPath
+ * @return
+ */
+ private String getLogFileName(String logFullPath){
+ // 鏍规嵁褰撳墠鎿嶄綔绯荤粺鏉ュ喅瀹氭槸閫氳繃浠�涔堝瓧绗︽潵鎴彇
+ String[] parts = logFullPath.split(this.isWindows ? "\\\\":"/");
+ String logFileName = "";
+ if(parts.length > 3){
+ logFileName = parts[parts.length - 1];
+ }
+ return logFileName;
+ }
+
+ /**
+ * 涓嬭浇鏃ュ織鏂囦欢
+ * @param localLogVO 涓嬭浇鏃ュ織瀵硅薄
+ * @return
+ * @throws ServerException
+ */
+ @Override
+ public FileObjectBO downloadLogByServiceNameAndFileName(LocalLogVO localLogVO) throws ServerException {
+ if(Func.isEmpty(localLogVO) || Func.isEmpty(localLogVO.getLogPath())){
+ throw new ServerException("鏈幏鍙栧埌璇ユ棩蹇楄矾寰勶紒");
+ }
+ FileObjectBO fileObjectBO = new FileObjectBO();
+ String logFullPaths = localLogVO.getLogFullPaths();
+ // 鍒ゆ柇鏄惁鏄埗鐩綍
+ if(!localLogVO.getHasChildren()){
+ //鍙笅杞戒竴涓棩蹇楁枃浠�
+ File file = new File(logFullPaths);
+ if(!file.isFile() || !file.exists()){
+ throw new ServerException("鏈湴鏃ュ織鏂囦欢璺緞"+ logFullPaths +"涓湭鎵惧埌鏃ュ織");
+ }
+ try {
+ fileObjectBO.setName(file.getName());
+ fileObjectBO.setInputStream(new FileInputStream(file));
+ fileObjectBO.setFileLocalPath(logFullPaths);
+ fileObjectBO.setFileExtension(".log");
+ }catch (Throwable e){
+ throw new VciBaseException("鑾峰彇鏂囦欢鐨勬祦鏈夐棶棰�",new String[]{logFullPaths},e);
+ }
+ }else{
+ // 鏄埗鐩綍锛屾墍浠ラ渶瑕佽幏鍙栧埌涓嬮潰鐨勬墍鏈夊瓙鐩綍
+ // 鏈夊涓紝闇�瑕佷娇鐢▃ip杩涜鍘嬬缉
+ String tempFolder = FileUtil.getDefaultTempFolder();
+ File[] file1 = new File(logFullPaths).listFiles();
+ if(file1.length > 0){
+ Arrays.stream(file1).forEach(item->{
+ String fileName = tempFolder + File.separator + System.currentTimeMillis() + ".log";
+ File file = new File(fileName);
+ try {
+ if(!file.exists()) {
+ file.createNewFile();
+ }
+ }catch (Throwable e){
+ throw new VciBaseException("鍒涘缓鏂囦欢鍑洪敊,{0}",new String[]{fileName});
+ }
+ File logFile = new File(item.getPath());
+ if(!logFile.exists() || !logFile.isFile()){
+ throw new VciBaseException("鏈湴鏃ュ織鏂囦欢璺緞"+item.getPath()+"涓湭鎵惧埌鏃ュ織");
+ }
+
+ try(OutputStream os = new FileOutputStream(file);
+ InputStream ins = new FileInputStream(logFile);
+ ){
+ IOUtils.copy(ins,os);
+ }catch (Throwable e){
+ throw new VciBaseException("涓嬭浇鏂囦欢鍒颁复鏃舵枃浠跺す閲屽嚭閿�,{0}",new String[]{fileName});
+ }
+ });
+ String zipName = new File(tempFolder).getPath() + File.separator + getLogFileName(logFullPaths) + "绛�"+file1.length + "涓枃浠�.zip";
+ zipUtil.folderToZipFile(tempFolder,zipName);
+ fileObjectBO.setFileLocalPath(zipName);
+ fileObjectBO.setFileExtension(".log");
+ if(log.isDebugEnabled()){
+ log.debug("涓嬭浇鏂囦欢鐨勪俊鎭�,",zipName);
+ }
+ }
+ }
+ return fileObjectBO;
+ }
+
+ /**
+ * 鍒犻櫎鏃ュ織鏂囦欢
+ * @param localLogVO 鏂囦欢鍏ㄨ矾寰勯泦鍚�
+ * @throws ServerException
+ */
+ @Override
+ public R deleteLogFile(LocalLogVO localLogVO) throws ServerException {
+ List<String> resMsgs = new ArrayList<>();
+ // 鍒ゆ柇鏄惁鏄棩蹇楅《灞傜洰褰�
+ if(localLogVO.getHasChildren()){
+ // 鏄《灞傜洰褰曪紝闇�瑕佸惊鐜幓鍒犻櫎鍖呭惈鐨勬墍鏈夋棩蹇楁枃浠�
+ File parentFile = new File(localLogVO.getLogFullPaths());
+ if(parentFile.isDirectory()){
+ Arrays.stream(parentFile.listFiles()).forEach(logFile->{
+ if (logFile.exists()) {
+ //鍒犻櫎澶辫触鐨勭洿鎺ヨ褰曚笅鏂囦欢鍚�
+ if (!logFile.delete()) {
+ resMsgs.add(getLogFileName(logFile.getPath()));
+ }
+ }
+ });
+ }
+ }else {
+ // 鍗曚釜鍒犻櫎
+ File file = new File(localLogVO.getLogFullPaths());
+ if (file.exists()) {
+ //鍒犻櫎澶辫触鐨勭洿鎺ヨ褰曚笅鏂囦欢鍚�
+ if (!file.delete()) {
+ resMsgs.add(getLogFileName(localLogVO.getLogFullPaths()));
+ }
+ }
+ }
+ return resMsgs.size()==0 ? R.success("鍒犻櫎鎴愬姛!"):R.fail("浠ヤ笅鏃ュ織鏂囦欢锛�"+resMsgs.stream().collect(Collectors.joining(","))+"鍒犻櫎澶辫触!");
+ }
+
+}
diff --git a/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogOperateServiceImpl.java b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogOperateServiceImpl.java
new file mode 100644
index 0000000..9c02711
--- /dev/null
+++ b/Source/UBCS/ubcs-ops/ubcs-log/src/main/java/com/vci/ubcs/log/service/impl/LogOperateServiceImpl.java
@@ -0,0 +1,52 @@
+package com.vci.ubcs.log.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
+import com.vci.ubcs.log.entity.LogOperate;
+import com.vci.ubcs.log.mapper.LogOperateMapper;
+import com.vci.ubcs.log.service.ILogOperateService;
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.tool.utils.Func;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 鎿嶄綔鏃ュ織绠$悊:(鍖呮嫭鐧诲綍鏃ュ織銆佹搷浣滄棩蹇椼�佹巿鏉冩棩蹇楋紝浠ュ強绠$悊鍛樼殑浠ヤ笂涓夌鏃ュ織)
+ * @author ludc
+ * @date 2023/11/24 10:51
+ */
+@Service
+public class LogOperateServiceImpl extends ServiceImpl<LogOperateMapper,LogOperate> implements ILogOperateService {
+
+ @Autowired
+ private LogOperateMapper logOperateMapper;
+
+ /**
+ * 淇濆瓨鎿嶄綔鏃ュ織
+ * @param logOperate
+ * @return
+ */
+ @Override
+ public boolean saveLogOperate(LogOperate logOperate) {
+ if(Func.isEmpty(logOperate)){
+ return false;
+ }
+ return SqlHelper.retBool(logOperateMapper.insert(logOperate));
+ }
+
+ /**
+ * 鏉′欢鏌ヨ鑾峰彇鏃ュ織鍒楄〃
+ * @param logOperate
+ * @return
+ */
+ @Override
+ public List<LogOperate> listByCondition(LogOperate logOperate) {
+ QueryWrapper<LogOperate> queryWrapper = Condition.getQueryWrapper(logOperate);
+ this.list(queryWrapper);
+ return this.list(queryWrapper);
+ }
+
+}
--
Gitblit v1.9.3