diff --git a/yudao-admin-vue3/.env b/yudao-admin-vue3/.env index 4b0f5bf..c18e52e 100644 --- a/yudao-admin-vue3/.env +++ b/yudao-admin-vue3/.env @@ -1,5 +1,5 @@ # 标题 -VITE_APP_TITLE=芋道管理系统 +VITE_APP_TITLE=众悦e家管理系统 # 项目本地运行端口号 VITE_PORT=80 @@ -20,6 +20,6 @@ VITE_APP_DOCALERT_ENABLE=true VITE_APP_BAIDU_CODE = a1ff8825baa73c3a78eb96aa40325abc # 默认账户密码 -VITE_APP_DEFAULT_LOGIN_TENANT = 芋道源码 +VITE_APP_DEFAULT_LOGIN_TENANT = 众悦e家 VITE_APP_DEFAULT_LOGIN_USERNAME = admin VITE_APP_DEFAULT_LOGIN_PASSWORD = admin123 diff --git a/yudao-admin-vue3/public/favicon-old.ico b/yudao-admin-vue3/public/favicon-old.ico new file mode 100644 index 0000000..5a7de08 Binary files /dev/null and b/yudao-admin-vue3/public/favicon-old.ico differ diff --git a/yudao-admin-vue3/public/favicon.ico b/yudao-admin-vue3/public/favicon.ico index 5a7de08..cb16081 100644 Binary files a/yudao-admin-vue3/public/favicon.ico and b/yudao-admin-vue3/public/favicon.ico differ diff --git a/yudao-admin-vue3/src/api/system/operatewarning/index.ts b/yudao-admin-vue3/src/api/system/operatewarning/index.ts new file mode 100644 index 0000000..41b2532 --- /dev/null +++ b/yudao-admin-vue3/src/api/system/operatewarning/index.ts @@ -0,0 +1,47 @@ +import request from '@/config/axios' + +// 告警记录 VO +export interface OperateWarningVO { + id: number // 告警编号 + alarmPolicy: string // 告警策略 + monitoringObject: string // 监控对象 + triggeringCondition: string // 触发条件 + alarmFrequency: string // 告警频率 + notificationChannel: string // 通知渠道 + duration: string // 持续时间 + alarmLevel: string // 告警级别 + alarmStatus: number // 告警状态 +} + +// 告警记录 API +export const OperateWarningApi = { + // 查询告警记录分页 + getOperateWarningPage: async (params: any) => { + return await request.get({ url: `/system/operate-warning/page`, params }) + }, + + // 查询告警记录详情 + getOperateWarning: async (id: number) => { + return await request.get({ url: `/system/operate-warning/get?id=` + id }) + }, + + // 新增告警记录 + createOperateWarning: async (data: OperateWarningVO) => { + return await request.post({ url: `/system/operate-warning/create`, data }) + }, + + // 修改告警记录 + updateOperateWarning: async (data: OperateWarningVO) => { + return await request.put({ url: `/system/operate-warning/update`, data }) + }, + + // 删除告警记录 + deleteOperateWarning: async (id: number) => { + return await request.delete({ url: `/system/operate-warning/delete?id=` + id }) + }, + + // 导出告警记录 Excel + exportOperateWarning: async (params) => { + return await request.download({ url: `/system/operate-warning/export-excel`, params }) + } +} \ No newline at end of file diff --git a/yudao-admin-vue3/src/assets/imgs/logo-old.png b/yudao-admin-vue3/src/assets/imgs/logo-old.png new file mode 100644 index 0000000..7e1043f Binary files /dev/null and b/yudao-admin-vue3/src/assets/imgs/logo-old.png differ diff --git a/yudao-admin-vue3/src/assets/imgs/logo.png b/yudao-admin-vue3/src/assets/imgs/logo.png index 7e1043f..cb16081 100644 Binary files a/yudao-admin-vue3/src/assets/imgs/logo.png and b/yudao-admin-vue3/src/assets/imgs/logo.png differ diff --git a/yudao-admin-vue3/src/assets/imgs/zy-logo.jpg b/yudao-admin-vue3/src/assets/imgs/zy-logo.jpg new file mode 100644 index 0000000..cb16081 Binary files /dev/null and b/yudao-admin-vue3/src/assets/imgs/zy-logo.jpg differ diff --git a/yudao-admin-vue3/src/main.ts b/yudao-admin-vue3/src/main.ts index a0284a5..fb0d1d8 100644 --- a/yudao-admin-vue3/src/main.ts +++ b/yudao-admin-vue3/src/main.ts @@ -111,22 +111,81 @@ watchEffect(() => { // const jsonObject = JSON.parse(content); // const sValue = ref(jsonObject); // console.log("content:", JSON.parse(jsonObject)); + //磁盘告警 if(content === '"diskPull"'){ const open = () => { - ElMessageBox.alert('This is a message', 'Title', { + ElMessageBox.alert('磁盘存储已达溢值,请联系管理员查看原因', '磁盘告警', { // if you want to disable its autofocus // autofocus: false, - confirmButtonText: 'OK', + confirmButtonText: '确定', callback: (action: Action) => { ElMessage({ - type: 'info', - message: `action: ${action}`, + type: 'warning', + message: `关闭成功`, + // message: `action: ${action}`, }) }, }) } open(); } + //进程cpu利用率告警 + if(content === '"processPull"'){ + const open = () => { + ElMessageBox.alert('进程cpu利用率已达溢值,请联系管理员查看原因', '进程cpu利用率告警', { + // if you want to disable its autofocus + // autofocus: false, + confirmButtonText: '确定', + callback: (action: Action) => { + ElMessage({ + type: 'warning', + message: `关闭成功`, + // message: `action: ${action}`, + }) + }, + }) + } + open(); + } + + //系统cpu利用率告警 + if(content === '"systemPull"'){ + const open = () => { + ElMessageBox.alert('系统cpu利用率已达溢值,请联系管理员查看原因', '系统cpu利用率告警', { + // if you want to disable its autofocus + // autofocus: false, + confirmButtonText: '确定', + callback: (action: Action) => { + ElMessage({ + type: 'warning', + message: `关闭成功`, + // message: `action: ${action}`, + }) + }, + }) + } + open(); + } + + //系统内存告警 + if(content === '"HeapPull"'){ + const open = () => { + ElMessageBox.alert('系统内存已达溢值,请联系管理员查看原因', '系统内存告警', { + // if you want to disable its autofocus + // autofocus: false, + confirmButtonText: '确定', + callback: (action: Action) => { + ElMessage({ + type: 'warning', + message: `关闭成功`, + // message: `action: ${action}`, + }) + }, + }) + } + open(); + } + if (!type) { message.error('未知的消息类型:' + data.value) return diff --git a/yudao-admin-vue3/src/views/Home/Index.vue b/yudao-admin-vue3/src/views/Home/Index.vue index ea8789f..ee6b1ea 100644 --- a/yudao-admin-vue3/src/views/Home/Index.vue +++ b/yudao-admin-vue3/src/views/Home/Index.vue @@ -18,7 +18,7 @@ - + @@ -60,7 +60,7 @@ @@ -99,7 +99,7 @@ - + @@ -144,7 +144,7 @@ @@ -218,50 +218,50 @@ const getCount = async () => { let projects = reactive([]) const getProject = async () => { const data = [ - { - name: 'ruoyi-vue-pro', - icon: 'akar-icons:github-fill', - message: 'https://github.com/YunaiV/ruoyi-vue-pro', - personal: 'Spring Boot 单体架构', - time: new Date() - }, - { - name: 'yudao-ui-admin-vue3', - icon: 'logos:vue', - message: 'https://github.com/yudaocode/yudao-ui-admin-vue3', - personal: 'Vue3 + element-plus', - time: new Date() - }, - { - name: 'yudao-ui-admin-vben', - icon: 'logos:vue', - message: 'https://github.com/yudaocode/yudao-ui-admin-vben', - personal: 'Vue3 + vben(antd)', - time: new Date() - }, - { - name: 'yudao-cloud', - icon: 'akar-icons:github', - message: 'https://github.com/YunaiV/yudao-cloud', - personal: 'Spring Cloud 微服务架构', - time: new Date() - }, - { - name: 'yudao-ui-mall-uniapp', - icon: 'logos:vue', - message: 'https://github.com/yudaocode/yudao-ui-admin-uniapp', - personal: 'Vue3 + uniapp', - time: new Date() - }, - { - name: 'yudao-ui-admin-vue2', - icon: 'logos:vue', - message: 'https://github.com/yudaocode/yudao-ui-admin-vue2', - personal: 'Vue2 + element-ui', - time: new Date() - } + // { + // name: 'ruoyi-vue-pro', + // icon: 'akar-icons:github-fill', + // message: 'https://github.com/YunaiV/ruoyi-vue-pro', + // personal: 'Spring Boot 单体架构', + // time: new Date() + // }, + // { + // name: 'yudao-ui-admin-vue3', + // icon: 'logos:vue', + // message: 'https://github.com/yudaocode/yudao-ui-admin-vue3', + // personal: 'Vue3 + element-plus', + // time: new Date() + // }, + // { + // name: 'yudao-ui-admin-vben', + // icon: 'logos:vue', + // message: 'https://github.com/yudaocode/yudao-ui-admin-vben', + // personal: 'Vue3 + vben(antd)', + // time: new Date() + // }, + // { + // name: 'yudao-cloud', + // icon: 'akar-icons:github', + // message: 'https://github.com/YunaiV/yudao-cloud', + // personal: 'Spring Cloud 微服务架构', + // time: new Date() + // }, + // { + // name: 'yudao-ui-mall-uniapp', + // icon: 'logos:vue', + // message: 'https://github.com/yudaocode/yudao-ui-admin-uniapp', + // personal: 'Vue3 + uniapp', + // time: new Date() + // }, + // { + // name: 'yudao-ui-admin-vue2', + // icon: 'logos:vue', + // message: 'https://github.com/yudaocode/yudao-ui-admin-vue2', + // personal: 'Vue2 + element-ui', + // time: new Date() + // } ] - projects = Object.assign(projects, data) + // projects = Object.assign(projects, data) } // 获取通知公告 @@ -301,38 +301,38 @@ let shortcut = reactive([]) const getShortcut = async () => { const data = [ - { - name: 'Github', - icon: 'akar-icons:github-fill', - url: 'github.io' - }, - { - name: 'Vue', - icon: 'logos:vue', - url: 'vuejs.org' - }, - { - name: 'Vite', - icon: 'vscode-icons:file-type-vite', - url: 'https://vitejs.dev/' - }, - { - name: 'Angular', - icon: 'logos:angular-icon', - url: 'github.io' - }, - { - name: 'React', - icon: 'logos:react', - url: 'github.io' - }, - { - name: 'Webpack', - icon: 'logos:webpack', - url: 'github.io' - } + // { + // name: 'Github', + // icon: 'akar-icons:github-fill', + // url: 'github.io' + // }, + // { + // name: 'Vue', + // icon: 'logos:vue', + // url: 'vuejs.org' + // }, + // { + // name: 'Vite', + // icon: 'vscode-icons:file-type-vite', + // url: 'https://vitejs.dev/' + // }, + // { + // name: 'Angular', + // icon: 'logos:angular-icon', + // url: 'github.io' + // }, + // { + // name: 'React', + // icon: 'logos:react', + // url: 'github.io' + // }, + // { + // name: 'Webpack', + // icon: 'logos:webpack', + // url: 'github.io' + // } ] - shortcut = Object.assign(shortcut, data) + // shortcut = Object.assign(shortcut, data) } // 用户来源 diff --git a/yudao-admin-vue3/src/views/Login/Login.vue b/yudao-admin-vue3/src/views/Login/Login.vue index 5d349ce..fa9e652 100644 --- a/yudao-admin-vue3/src/views/Login/Login.vue +++ b/yudao-admin-vue3/src/views/Login/Login.vue @@ -9,7 +9,7 @@ >
- + {{ underlineToHump(appStore.getTitle) }}
diff --git a/yudao-admin-vue3/src/views/Login/components/LoginForm.vue b/yudao-admin-vue3/src/views/Login/components/LoginForm.vue index 3dbaff3..e1644b6 100644 --- a/yudao-admin-vue3/src/views/Login/components/LoginForm.vue +++ b/yudao-admin-vue3/src/views/Login/components/LoginForm.vue @@ -82,7 +82,7 @@ mode="pop" @success="handleLogin" /> - + @@ -184,9 +184,9 @@ const loginData = reactive({ captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE, tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE, loginForm: { - tenantName: import.meta.env.VITE_APP_DEFAULT_LOGIN_TENANT || '', - username: import.meta.env.VITE_APP_DEFAULT_LOGIN_USERNAME || '', - password: import.meta.env.VITE_APP_DEFAULT_LOGIN_PASSWORD || '', + tenantName: '雲頂玖號', + username: 'ydadmin', + password: '123456', captchaVerification: '', rememberMe: true // 默认记录我。如果不需要,可手动修改 } @@ -351,4 +351,4 @@ onMounted(() => { cursor: pointer; } } - + \ No newline at end of file diff --git a/yudao-admin-vue3/src/views/system/operatewarning/OperateWarningForm.vue b/yudao-admin-vue3/src/views/system/operatewarning/OperateWarningForm.vue new file mode 100644 index 0000000..31d980a --- /dev/null +++ b/yudao-admin-vue3/src/views/system/operatewarning/OperateWarningForm.vue @@ -0,0 +1,128 @@ + + \ No newline at end of file diff --git a/yudao-admin-vue3/src/views/system/operatewarning/index.vue b/yudao-admin-vue3/src/views/system/operatewarning/index.vue new file mode 100644 index 0000000..833a9a7 --- /dev/null +++ b/yudao-admin-vue3/src/views/system/operatewarning/index.vue @@ -0,0 +1,265 @@ + + + \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/context/TenantContextHolder.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/context/TenantContextHolder.java index 4e7b5e0..b5f08e9 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/context/TenantContextHolder.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/context/TenantContextHolder.java @@ -36,11 +36,13 @@ public class TenantContextHolder { */ public static Long getRequiredTenantId() { Long tenantId = getTenantId(); - if (tenantId == null) { - throw new NullPointerException("TenantContextHolder 不存在租户编号!可参考文档:" - + DocumentEnum.TENANT.getUrl()); - } - return tenantId; +// if (tenantId == null) { +// throw new NullPointerException("TenantContextHolder 不存在租户编号!可参考文档:" +// + DocumentEnum.TENANT.getUrl()); +// } + +// return tenantId; + return 1L; } public static void setTenantId(Long tenantId) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverExpressController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverExpressController.java index 20cdef5..540f5b6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverExpressController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverExpressController.java @@ -1,11 +1,15 @@ package cn.iocoder.yudao.module.trade.controller.app.delivery; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; import cn.iocoder.yudao.module.trade.controller.app.delivery.vo.express.AppDeliveryExpressRespVO; import cn.iocoder.yudao.module.trade.convert.delivery.DeliveryExpressConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; +import com.alibaba.fastjson.JSONObject; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; @@ -36,4 +40,11 @@ public class AppDeliverExpressController { return success(DeliveryExpressConvert.INSTANCE.convertList03(list)); } + @GetMapping("/realTimeExpressDeliveryQuery") + @Operation(summary = "实时物流查询") + public CommonResult realTimeExpressDeliveryQuery(){ + String deliveryQuery = deliveryExpressService.deliveryQuery(); + return success(deliveryQuery); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 762b238..1b7f551 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.trade.controller.app.order; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; @@ -17,6 +19,8 @@ import cn.iocoder.yudao.module.trade.service.aftersale.AfterSaleService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Maps; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -147,6 +151,32 @@ public class AppTradeOrderController { return success(true); } +// @PostMapping("/test") +// public void test(){ +// //获取access_token +// String accessTokenApiurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx63c280fe3248a3e7&secret=6f270509224a7ae1296bbf1c8cb97aed"; +// HttpResponse get = HttpUtil.createGet(accessTokenApiurl).execute(); +// String body = get.body(); +// System.out.println("-----------------------------------------------"); +// JSONObject jsonObject = JSON.parseObject(body); +// System.out.println(jsonObject); +// System.out.println(body); +// String token = jsonObject.getString("access_token"); +// System.out.println(token); +// System.out.println("-----------------------------------------------"); +// +// String apiurlSec = "https://api.weixin.qq.com/wxa/sec/order/is_trade_managed?access_token="+token; +// JSONObject mapSec = new JSONObject(); +// mapSec.put("out_order_id","wx63c280fe3248a3e7"); +// mapSec.put("openid","wx63c280fe3248a3e7"); +// HttpResponse postSec = HttpUtil.createPost(apiurlSec) +//// .header("Authorization","Bearer 8e79d003102a4b5c80fd823c3c04347c") +//// .header("tenant-id","1") +// .body(mapSec.toJSONString()) +// .execute(); +// String bodySec = postSec.body(); +// } + @DeleteMapping("/cancel") @Operation(summary = "取消交易订单") @Parameter(name = "id", description = "交易订单编号") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressService.java index c504b30..f8722fc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressService.java @@ -79,4 +79,7 @@ public interface DeliveryExpressService { */ List getDeliveryExpressListByStatus(Integer status); + + String deliveryQuery(); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressServiceImpl.java index ec787af..b768357 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressServiceImpl.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.module.trade.service.delivery; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.express.DeliveryExpressCreateReqVO; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.express.DeliveryExpressExportReqVO; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.express.DeliveryExpressPageReqVO; @@ -9,10 +12,13 @@ import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.express.Delive import cn.iocoder.yudao.module.trade.convert.delivery.DeliveryExpressConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import cn.iocoder.yudao.module.trade.dal.mysql.delivery.DeliveryExpressMapper; +import com.alibaba.fastjson.JSONObject; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -30,6 +36,39 @@ public class DeliveryExpressServiceImpl implements DeliveryExpressService { @Resource private DeliveryExpressMapper deliveryExpressMapper; + //签名, 用于验证身份, 按param + key + customer 的顺序进行MD5加密(注意加密后字符串一定要转32位大写), 不需要加上“+”号 + private String getSign(JSONObject param){ + String key = "basdjhabsdjh"; + String customer = "adjashdjahdija"; + String resultStr = param+key+customer; + + try { + // 创建MessageDigest对象,指定使用MD5算法 + MessageDigest md = MessageDigest.getInstance("MD5"); + // 将字符串转换为byte数组 + byte[] inputBytes = resultStr.getBytes(); + // 使用MD5算法更新摘要 + md.update(inputBytes); + // 计算摘要 + byte[] digest = md.digest(); + + // 将byte数组转换为十六进制字符串 + StringBuffer sb = new StringBuffer(); + for (byte b : digest) { + sb.append(String.format("%02x", b & 0xff)); + } + + // 打印MD5加密后的字符串 + System.out.println("MD5 Hash: " + sb.toString()); + return sb.toString().toUpperCase(); + + } catch (NoSuchAlgorithmException e) { + System.out.println("MD5 algorithm not available."); + e.printStackTrace(); + return null; + } + } + @Override public Long createDeliveryExpress(DeliveryExpressCreateReqVO createReqVO) { //校验编码是否唯一 @@ -111,4 +150,24 @@ public class DeliveryExpressServiceImpl implements DeliveryExpressService { return deliveryExpressMapper.selectListByStatus(status); } + @Override + public String deliveryQuery() { + //快递100 查询实时物流api接口地址 + String url = "https://poll.kuaidi100.com/poll/query.do"; + JSONObject mapSec = new JSONObject(); + mapSec.put("customer","");//授权码,请申请企业版获取 + JSONObject paramSec = new JSONObject(); + paramSec.put("com","yuantong");//查询的快递公司的编码, 一律用小写字母 + paramSec.put("num","12345678");//查询的快递单号, 单号的最小长度6个字符,最大长度32个字符 + paramSec.put("phone","13888888888");//收、寄件人的电话号码(手机和固定电话均可,只能填写一个,顺丰速运、顺丰快运必填,其他快递公司选填。如座机号码有分机号,分机号无需传入;如号码是电商虚拟号码需传入“-“后的后四位 + mapSec.put("param",paramSec); + mapSec.put("sign",getSign(paramSec));//签名, 用于验证身份, 按param + key + customer 的顺序进行MD5加密(注意加密后字符串一定要转32位大写), 不需要加上“+”号 + + HttpResponse postSec = HttpUtil.createPost(url) + .header("Content-Type","application/x-www-form-urlencoded") + .body(mapSec.toJSONString()) + .execute(); + return postSec.body(); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 582ab3a..89c9e14 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -507,6 +507,34 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 收货订单 receiveOrder0(order); + + //微信官方收货 + //获取access_token + String accessTokenApiurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx63c280fe3248a3e7&secret=6f270509224a7ae1296bbf1c8cb97aed"; + HttpResponse get = HttpUtil.createGet(accessTokenApiurl).execute(); + String body = get.body(); + System.out.println("-----------------------------------------------"); + JSONObject jsonObject = JSON.parseObject(body); + System.out.println(jsonObject); + System.out.println(body); + String token = jsonObject.getString("access_token"); + System.out.println(token); + System.out.println("-----------------------------------------------"); + + String apiurlSec = "https://api.weixin.qq.com/wxa/sec/order/is_trade_managed?access_token="+token; + JSONObject mapSec = new JSONObject(); + mapSec.put("out_order_id",order.getNo()); + SocialUserRespDTO socialUserRespDTO = socialUserApi.getSocialUserByUserId(1, order.getUserId(), 34); + mapSec.put("openid",socialUserRespDTO.getOpenid()); + HttpResponse postSec = HttpUtil.createPost(apiurlSec) +// .header("Authorization","Bearer 8e79d003102a4b5c80fd823c3c04347c") +// .header("tenant-id","1") + .body(mapSec.toJSONString()) + .execute(); + String bodySec = postSec.body(); + System.out.println("====================="); + System.out.println(bodySec); + System.out.println("====================="); } @Override diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 585308d..90b1961 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -160,4 +160,6 @@ public interface ErrorCodeConstants { // ========== 站内信发送 1-002-028-000 ========== ErrorCode NOTIFY_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1_002_028_000, "模板参数({})缺失"); + ErrorCode OPERATE_WARNING_NOT_EXISTS = new ErrorCode(1_002_028_000, "告警记录不存在"); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/OperateWarningController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/OperateWarningController.java new file mode 100644 index 0000000..018df7d --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/OperateWarningController.java @@ -0,0 +1,95 @@ +package cn.iocoder.yudao.module.system.controller.admin.operatewarning; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.system.controller.admin.operatewarning.vo.*; +import cn.iocoder.yudao.module.system.dal.dataobject.operatewarning.OperateWarningDO; +import cn.iocoder.yudao.module.system.service.operatewarning.OperateWarningService; + +@Tag(name = "管理后台 - 告警记录") +@RestController +@RequestMapping("/system/operate-warning") +@Validated +public class OperateWarningController { + + @Resource + private OperateWarningService operateWarningService; + + @PostMapping("/create") + @Operation(summary = "创建告警记录") + @PreAuthorize("@ss.hasPermission('system:operate-warning:create')") + public CommonResult createOperateWarning(@Valid @RequestBody OperateWarningSaveReqVO createReqVO) { + return success(operateWarningService.createOperateWarning(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新告警记录") + @PreAuthorize("@ss.hasPermission('system:operate-warning:update')") + public CommonResult updateOperateWarning(@Valid @RequestBody OperateWarningSaveReqVO updateReqVO) { + operateWarningService.updateOperateWarning(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除告警记录") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('system:operate-warning:delete')") + public CommonResult deleteOperateWarning(@RequestParam("id") Long id) { + operateWarningService.deleteOperateWarning(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得告警记录") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('system:operate-warning:query')") + public CommonResult getOperateWarning(@RequestParam("id") Long id) { + OperateWarningDO operateWarning = operateWarningService.getOperateWarning(id); + return success(BeanUtils.toBean(operateWarning, OperateWarningRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得告警记录分页") + @PreAuthorize("@ss.hasPermission('system:operate-warning:query')") + public CommonResult> getOperateWarningPage(@Valid OperateWarningPageReqVO pageReqVO) { + PageResult pageResult = operateWarningService.getOperateWarningPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, OperateWarningRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出告警记录 Excel") + @PreAuthorize("@ss.hasPermission('system:operate-warning:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportOperateWarningExcel(@Valid OperateWarningPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = operateWarningService.getOperateWarningPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "告警记录.xls", "数据", OperateWarningRespVO.class, + BeanUtils.toBean(list, OperateWarningRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/vo/OperateWarningPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/vo/OperateWarningPageReqVO.java new file mode 100644 index 0000000..0271cc5 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/vo/OperateWarningPageReqVO.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.system.controller.admin.operatewarning.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 告警记录分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class OperateWarningPageReqVO extends PageParam { + + @Schema(description = "发生时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + + @Schema(description = "告警策略") + private String alarmPolicy; + + @Schema(description = "监控对象") + private String monitoringObject; + + @Schema(description = "触发条件") + private String triggeringCondition; + + @Schema(description = "告警频率") + private String alarmFrequency; + + @Schema(description = "通知渠道") + private String notificationChannel; + + @Schema(description = "持续时间") + private String duration; + + @Schema(description = "告警级别") + private String alarmLevel; + + @Schema(description = "告警状态", example = "2") + private Integer alarmStatus; + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/vo/OperateWarningRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/vo/OperateWarningRespVO.java new file mode 100644 index 0000000..4ebd118 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/vo/OperateWarningRespVO.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.system.controller.admin.operatewarning.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 告警记录 Response VO") +@Data +@ExcelIgnoreUnannotated +public class OperateWarningRespVO { + + @Schema(description = "告警编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "19817") + @ExcelProperty("告警编号") + private Long id; + + @Schema(description = "发生时间") + @ExcelProperty("发生时间") + private LocalDateTime createTime; + + @Schema(description = "告警策略") + @ExcelProperty("告警策略") + private String alarmPolicy; + + @Schema(description = "监控对象") + @ExcelProperty("监控对象") + private String monitoringObject; + + @Schema(description = "触发条件") + @ExcelProperty("触发条件") + private String triggeringCondition; + + @Schema(description = "告警频率") + @ExcelProperty("告警频率") + private String alarmFrequency; + + @Schema(description = "通知渠道") + @ExcelProperty("通知渠道") + private String notificationChannel; + + @Schema(description = "持续时间") + @ExcelProperty("持续时间") + private String duration; + + @Schema(description = "告警级别") + @ExcelProperty("告警级别") + private String alarmLevel; + + @Schema(description = "告警状态", example = "2") + @ExcelProperty("告警状态") + private Integer alarmStatus; + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/vo/OperateWarningSaveReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/vo/OperateWarningSaveReqVO.java new file mode 100644 index 0000000..a576bf9 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/operatewarning/vo/OperateWarningSaveReqVO.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.system.controller.admin.operatewarning.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 告警记录新增/修改 Request VO") +@Data +public class OperateWarningSaveReqVO { + + @Schema(description = "告警编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "19817") + private Long id; + + @Schema(description = "告警策略") + private String alarmPolicy; + + @Schema(description = "监控对象") + private String monitoringObject; + + @Schema(description = "触发条件") + private String triggeringCondition; + + @Schema(description = "告警频率") + private String alarmFrequency; + + @Schema(description = "通知渠道") + private String notificationChannel; + + @Schema(description = "持续时间") + private String duration; + + @Schema(description = "告警级别") + private String alarmLevel; + + @Schema(description = "告警状态", example = "2") + private Integer alarmStatus; + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/operatewarning/OperateWarningDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/operatewarning/OperateWarningDO.java new file mode 100644 index 0000000..5e05fae --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/operatewarning/OperateWarningDO.java @@ -0,0 +1,63 @@ +package cn.iocoder.yudao.module.system.dal.dataobject.operatewarning; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 告警记录 DO + * + * @author 管理员 + */ +@TableName("system_operate_warning") +@KeySequence("system_operate_warning_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class OperateWarningDO extends BaseDO { + + /** + * 告警编号 + */ + @TableId + private Long id; + /** + * 告警策略 + */ + private String alarmPolicy; + /** + * 监控对象 + */ + private String monitoringObject; + /** + * 触发条件 + */ + private String triggeringCondition; + /** + * 告警频率 + */ + private String alarmFrequency; + /** + * 通知渠道 + */ + private String notificationChannel; + /** + * 持续时间 + */ + private String duration; + /** + * 告警级别 + */ + private String alarmLevel; + /** + * 告警状态 + */ + private Integer alarmStatus; + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/operatewarning/OperateWarningMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/operatewarning/OperateWarningMapper.java new file mode 100644 index 0000000..4713a3f --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/operatewarning/OperateWarningMapper.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.system.dal.mysql.operatewarning; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.system.dal.dataobject.operatewarning.OperateWarningDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.system.controller.admin.operatewarning.vo.*; + +/** + * 告警记录 Mapper + * + * @author 管理员 + */ +@Mapper +public interface OperateWarningMapper extends BaseMapperX { + + default PageResult selectPage(OperateWarningPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .betweenIfPresent(OperateWarningDO::getCreateTime, reqVO.getCreateTime()) + .eqIfPresent(OperateWarningDO::getAlarmPolicy, reqVO.getAlarmPolicy()) + .eqIfPresent(OperateWarningDO::getMonitoringObject, reqVO.getMonitoringObject()) + .eqIfPresent(OperateWarningDO::getTriggeringCondition, reqVO.getTriggeringCondition()) + .eqIfPresent(OperateWarningDO::getAlarmFrequency, reqVO.getAlarmFrequency()) + .eqIfPresent(OperateWarningDO::getNotificationChannel, reqVO.getNotificationChannel()) + .eqIfPresent(OperateWarningDO::getDuration, reqVO.getDuration()) + .eqIfPresent(OperateWarningDO::getAlarmLevel, reqVO.getAlarmLevel()) + .eqIfPresent(OperateWarningDO::getAlarmStatus, reqVO.getAlarmStatus()) + .orderByDesc(OperateWarningDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/WarningJob.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/WarningJob.java index b28e873..2ea06ca 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/WarningJob.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/WarningJob.java @@ -1,19 +1,39 @@ package cn.iocoder.yudao.module.system.job; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi; import cn.iocoder.yudao.module.system.api.dict.DictDataApi; import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; +import cn.iocoder.yudao.module.system.dal.dataobject.operatewarning.OperateWarningDO; +import cn.iocoder.yudao.module.system.dal.mysql.operatewarning.OperateWarningMapper; +import cn.iocoder.yudao.module.system.job.vo.CommVo; +import cn.iocoder.yudao.module.system.job.vo.WarningJobVo; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.nio.file.FileStore; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; + +/** + * 1:磁盘告警规则 + * 2:内存告警规则 + * 3:进程cpu利用率告警规则 + * 4:系统cpu利用率告警规则 + * + * package cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder.getRequiredTenantId; + */ + @Component @Slf4j public class WarningJob implements JobHandler { @@ -21,40 +41,132 @@ public class WarningJob implements JobHandler { private WebSocketSenderApi webSocketSenderApi; @Resource private DictDataApi dataApi; + @Resource + private OperateWarningMapper operateWarningMapper; @Override public String execute(String param) throws Exception { + DictDataRespDTO configCountDo = null; + DictDataRespDTO configCountHeapDo = null; + DictDataRespDTO configCountProcessCPUDo = null; + DictDataRespDTO configCountSystemCPUDo = null; + List warningRule = dataApi.getDictDataList("warning_rule"); + for (DictDataRespDTO dictDataRespDTO : warningRule) { + if ("1".equals(dictDataRespDTO.getValue())){ + configCountDo = dictDataRespDTO; + } + if ("2".equals(dictDataRespDTO.getValue())){ + configCountHeapDo = dictDataRespDTO; + } + if ("3".equals(dictDataRespDTO.getValue())){ + configCountProcessCPUDo = dictDataRespDTO; + } + if ("4".equals(dictDataRespDTO.getValue())){ + configCountSystemCPUDo = dictDataRespDTO; + } + } + /** + * 磁盘告警逻辑 + */ try { // 获取文件系统根目录的 FileStore FileStore fileStore = Files.getFileStore(Paths.get("/")); - // 获取总容量 long totalSpace = fileStore.getTotalSpace(); -// System.out.println("Total space: " + totalSpace / 1024 + " kiB"); - // 获取未使用的容量 long usableSpace = fileStore.getUsableSpace(); -// System.out.println("Usable space: " + usableSpace / 1024 + " kiB"); - // 获取已使用的容量 long usedSpace = totalSpace - usableSpace; -// System.out.println("Used space: " + usedSpace / 1024 + " kiB"); - double totalSpacePercentage = ((double) usedSpace / totalSpace) * 100; - DictDataRespDTO configCountDo = null; - List warningRule = dataApi.getDictDataList("warning_rule"); - for (DictDataRespDTO dictDataRespDTO : warningRule) { - if ("磁盘告警规则".equals(dictDataRespDTO.getLabel())){ - configCountDo = dictDataRespDTO; - } - } - if (configCountDo != null && totalSpacePercentage > Integer.parseInt(configCountDo.getValue())){ + if (configCountDo != null && totalSpacePercentage > Integer.parseInt(configCountDo.getLabel())){ webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), 1L, "1", "diskPull"); + OperateWarningDO spaceWarningDO = new OperateWarningDO(); + spaceWarningDO.setAlarmPolicy("磁盘告警策略"); + spaceWarningDO.setMonitoringObject("磁盘"); + spaceWarningDO.setTriggeringCondition("当磁盘占用率达到"+Double.parseDouble(configCountProcessCPUDo.getLabel())*100+"%"); + operateWarningMapper.insert(spaceWarningDO); } } catch (Exception e) { e.printStackTrace(); } -// if () -// webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), 1L, "1", "true"); + /** + * 进程cpu利用率告警逻辑 + */ + HttpResponse response = HttpUtil.createGet("http://localhost:6127/admin/instances/0dea41b65450/actuator/metrics/process.cpu.usage") + .header("Accept","application/json") + .execute(); + String body = response.body(); + // 使用 Jackson 将 JSON 字符串转换为对象 + ObjectMapper mapper = new ObjectMapper(); + WarningJobVo memoryMetrics = mapper.readValue(body, WarningJobVo.class); + for (CommVo measurement : memoryMetrics.getMeasurements()) { + if (Double.parseDouble(measurement.getValue()) > Double.parseDouble(configCountProcessCPUDo.getLabel())){ + webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), 1L, "1", "processPull"); + OperateWarningDO processCPUWarningDO = new OperateWarningDO(); + processCPUWarningDO.setAlarmPolicy("进程cpu利用率告警策略"); + processCPUWarningDO.setMonitoringObject("进程cpu"); + processCPUWarningDO.setTriggeringCondition("当进程cpu利用率达到"+Double.parseDouble(configCountProcessCPUDo.getLabel())*100+"%"); + operateWarningMapper.insert(processCPUWarningDO); + return null; + } + } + + /** + * 系统cpu利用率告警逻辑 + */ + HttpResponse systemCpuResponse = HttpUtil.createGet("http://localhost:6127/admin/instances/0dea41b65450/actuator/metrics/system.cpu.usage") + .header("Accept","application/json") + .execute(); + String systemCpuBody = systemCpuResponse.body(); + // 使用 Jackson 将 JSON 字符串转换为对象 + ObjectMapper systemCpuMapper = new ObjectMapper(); + WarningJobVo systemCpuMemoryMetrics = systemCpuMapper.readValue(systemCpuBody, WarningJobVo.class); + for (CommVo measurement : systemCpuMemoryMetrics.getMeasurements()) { + if (Double.parseDouble(measurement.getValue()) > Double.parseDouble(configCountSystemCPUDo.getLabel())){ + webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), 1L, "1", "systemPull"); + OperateWarningDO systemCpuWarningDO = new OperateWarningDO(); + systemCpuWarningDO.setAlarmPolicy("系统cpu利用率告警策略"); + systemCpuWarningDO.setMonitoringObject("系统cpu"); + systemCpuWarningDO.setTriggeringCondition("当系统cpu利用率达到"+Double.parseDouble(configCountSystemCPUDo.getLabel())*100+"%"); + operateWarningMapper.insert(systemCpuWarningDO); + return null; + } + } + + /** + * 内存告警逻辑 + */ + try { + Process proc = Runtime.getRuntime().exec("systeminfo"); + BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream(), "GBK")); // 指定正确的字符编码,如GBK或UTF-8 + String line; + String totalMemory = null; + String freeMemory = null; + while ((line = reader.readLine()) != null) { + if (line.contains("物理内存总量")) { + totalMemory = line.substring(7, line.length() - 2).replace(",","").trim(); + } + if (line.contains("可用的物理内存")) { + freeMemory = line.substring(8, line.length() - 2).replace(",","").trim(); + } + } + reader.close(); + //剩余内存占比 + double memory = Double.parseDouble(freeMemory) / Double.parseDouble(totalMemory); + //已使用的内存占比 + double useMemory = 1 - memory; + if (useMemory > Double.parseDouble(configCountHeapDo.getLabel())){ + webSocketSenderApi.sendObject(UserTypeEnum.ADMIN.getValue(), 1L, "1", "HeapPull"); + OperateWarningDO heapWarningDO = new OperateWarningDO(); + heapWarningDO.setAlarmPolicy("物理内存告警策略"); + heapWarningDO.setMonitoringObject("物理内存"); + heapWarningDO.setTriggeringCondition("当内存占用率达到"+Double.parseDouble(configCountHeapDo.getLabel())*100+"%"); + operateWarningMapper.insert(heapWarningDO); + return null; + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/vo/CommTwoVo.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/vo/CommTwoVo.java new file mode 100644 index 0000000..a2cfbac --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/vo/CommTwoVo.java @@ -0,0 +1,11 @@ +package cn.iocoder.yudao.module.system.job.vo; + +import lombok.Data; + +import java.util.List; + +@Data +public class CommTwoVo { + private String tag; + private List values; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/vo/CommVo.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/vo/CommVo.java new file mode 100644 index 0000000..ff29d80 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/vo/CommVo.java @@ -0,0 +1,9 @@ +package cn.iocoder.yudao.module.system.job.vo; + +import lombok.Data; + +@Data +public class CommVo { + private String statistic; + private String value; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/vo/WarningJobVo.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/vo/WarningJobVo.java new file mode 100644 index 0000000..84d7251 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/job/vo/WarningJobVo.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.system.job.vo; + +import lombok.Data; + +import java.util.List; + +@Data +public class WarningJobVo { + private String name; + private String description; + private String baseUnit; + private List measurements; + private List availableTags; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/operatewarning/OperateWarningService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/operatewarning/OperateWarningService.java new file mode 100644 index 0000000..512a6ae --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/operatewarning/OperateWarningService.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.system.service.operatewarning; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.system.controller.admin.operatewarning.vo.*; +import cn.iocoder.yudao.module.system.dal.dataobject.operatewarning.OperateWarningDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +/** + * 告警记录 Service 接口 + * + * @author 管理员 + */ +public interface OperateWarningService { + + /** + * 创建告警记录 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createOperateWarning(@Valid OperateWarningSaveReqVO createReqVO); + + /** + * 更新告警记录 + * + * @param updateReqVO 更新信息 + */ + void updateOperateWarning(@Valid OperateWarningSaveReqVO updateReqVO); + + /** + * 删除告警记录 + * + * @param id 编号 + */ + void deleteOperateWarning(Long id); + + /** + * 获得告警记录 + * + * @param id 编号 + * @return 告警记录 + */ + OperateWarningDO getOperateWarning(Long id); + + /** + * 获得告警记录分页 + * + * @param pageReqVO 分页查询 + * @return 告警记录分页 + */ + PageResult getOperateWarningPage(OperateWarningPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/operatewarning/OperateWarningServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/operatewarning/OperateWarningServiceImpl.java new file mode 100644 index 0000000..58b1109 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/operatewarning/OperateWarningServiceImpl.java @@ -0,0 +1,74 @@ +package cn.iocoder.yudao.module.system.service.operatewarning; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import cn.iocoder.yudao.module.system.controller.admin.operatewarning.vo.*; +import cn.iocoder.yudao.module.system.dal.dataobject.operatewarning.OperateWarningDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import cn.iocoder.yudao.module.system.dal.mysql.operatewarning.OperateWarningMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; + +/** + * 告警记录 Service 实现类 + * + * @author 管理员 + */ +@Service +@Validated +public class OperateWarningServiceImpl implements OperateWarningService { + + @Resource + private OperateWarningMapper operateWarningMapper; + + @Override + public Long createOperateWarning(OperateWarningSaveReqVO createReqVO) { + // 插入 + OperateWarningDO operateWarning = BeanUtils.toBean(createReqVO, OperateWarningDO.class); + operateWarningMapper.insert(operateWarning); + // 返回 + return operateWarning.getId(); + } + + @Override + public void updateOperateWarning(OperateWarningSaveReqVO updateReqVO) { + // 校验存在 + validateOperateWarningExists(updateReqVO.getId()); + // 更新 + OperateWarningDO updateObj = BeanUtils.toBean(updateReqVO, OperateWarningDO.class); + operateWarningMapper.updateById(updateObj); + } + + @Override + public void deleteOperateWarning(Long id) { + // 校验存在 + validateOperateWarningExists(id); + // 删除 + operateWarningMapper.deleteById(id); + } + + private void validateOperateWarningExists(Long id) { + if (operateWarningMapper.selectById(id) == null) { + throw exception(OPERATE_WARNING_NOT_EXISTS); + } + } + + @Override + public OperateWarningDO getOperateWarning(Long id) { + return operateWarningMapper.selectById(id); + } + + @Override + public PageResult getOperateWarningPage(OperateWarningPageReqVO pageReqVO) { + return operateWarningMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 98a4663..a76b565 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -73,7 +73,8 @@ spring: # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: - host: 124.70.1.134 # 地址 + host: 120.46.37.243 # 地址 +# host: 124.70.1.134 # 地址 # host: 127.0.0.1 # 地址 port: 6379 # 端口 database: 0 # 数据库索引