From 6a413e0ce0d191a7d46270b85f3bc66ebb4cf789 Mon Sep 17 00:00:00 2001 From: yuan <1363654894@qq.com> Date: Sat, 21 Sep 2024 11:51:40 +0800 Subject: [PATCH] =?UTF-8?q?feat():=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloud-auth/src/main/resources/bootstrap.yml | 2 +- cloud-common/cloud-common-wechat/pom.xml | 62 ++++++ .../common/wechat/domain/AccessToken.java | 23 +++ .../muyu/common/wechat/domain/Articles.java | 38 ++++ .../common/wechat/domain/NewsMessage.java | 50 +++++ .../common/wechat/domain/TextMessage.java | 40 ++++ .../src/test/java/com/muyu/AppTest.java | 38 ++++ cloud-common/pom.xml | 1 + .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- cloud-modules/cloud-modules-warn/pom.xml | 112 +++++++++++ .../com/muyu/warn/CloudWarnApplication.java | 23 +++ .../warn/controller/WarnLogsController.java | 111 +++++++++++ .../warn/controller/WarnRuleController.java | 106 ++++++++++ .../controller/WarnStrategyController.java | 106 ++++++++++ .../java/com/muyu/warn/domain/WarnLogs.java | 104 ++++++++++ .../java/com/muyu/warn/domain/WarnRule.java | 74 +++++++ .../com/muyu/warn/domain/WarnStrategy.java | 58 ++++++ .../com/muyu/warn/mapper/WarnLogsMapper.java | 18 ++ .../com/muyu/warn/mapper/WarnRuleMapper.java | 17 ++ .../muyu/warn/mapper/WarnStrategyMapper.java | 17 ++ .../muyu/warn/service/WarnLogsService.java | 40 ++++ .../muyu/warn/service/WarnRuleService.java | 39 ++++ .../warn/service/WarnStrategyService.java | 39 ++++ .../service/impl/WarnLogsServiceImpl.java | 98 ++++++++++ .../service/impl/WarnRuleServiceImpl.java | 88 +++++++++ .../service/impl/WarnStrategyServiceImpl.java | 76 +++++++ .../src/main/resources/banner.txt | 2 + .../src/main/resources/bootstrap.yml | 60 ++++++ .../src/main/resources/logback/dev.xml | 74 +++++++ .../src/main/resources/logback/prod.xml | 81 ++++++++ .../src/main/resources/logback/test.xml | 81 ++++++++ .../src/test/java/com/muyu/AppTest.java | 38 ++++ cloud-modules/cloud-modules-wechat/pom.xml | 120 ++++++++++++ .../com/muyu/wechat/WeChatApplication.java | 15 ++ .../muyu/wechat/controller/WXController.java | 185 ++++++++++++++++++ .../java/com/muyu/wechat/token/TokenUtil.java | 41 ++++ .../com/muyu/wechat/util/OkHttpUtils.java | 36 ++++ .../java/com/muyu/wechat/util/WordUtil.java | 43 ++++ .../src/main/resources/banner.txt | 2 + .../src/main/resources/bootstrap.yml | 60 ++++++ .../src/main/resources/logback/dev.xml | 74 +++++++ .../src/main/resources/logback/prod.xml | 81 ++++++++ .../src/main/resources/logback/test.xml | 81 ++++++++ .../src/test/java/com/muyu/AppTest.java | 38 ++++ cloud-modules/pom.xml | 1 + .../src/main/resources/bootstrap.yml | 4 +- pom.xml | 1 + 50 files changed, 2499 insertions(+), 7 deletions(-) create mode 100644 cloud-common/cloud-common-wechat/pom.xml create mode 100644 cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/AccessToken.java create mode 100644 cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/Articles.java create mode 100644 cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/NewsMessage.java create mode 100644 cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/TextMessage.java create mode 100644 cloud-common/cloud-common-wechat/src/test/java/com/muyu/AppTest.java create mode 100644 cloud-modules/cloud-modules-warn/pom.xml create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/CloudWarnApplication.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnLogsController.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnRuleController.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnStrategyController.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnLogs.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnRule.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnStrategy.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnLogsMapper.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnRuleMapper.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnStrategyMapper.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnLogsService.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnRuleService.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnStrategyService.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnLogsServiceImpl.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnRuleServiceImpl.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnStrategyServiceImpl.java create mode 100644 cloud-modules/cloud-modules-warn/src/main/resources/banner.txt create mode 100644 cloud-modules/cloud-modules-warn/src/main/resources/bootstrap.yml create mode 100644 cloud-modules/cloud-modules-warn/src/main/resources/logback/dev.xml create mode 100644 cloud-modules/cloud-modules-warn/src/main/resources/logback/prod.xml create mode 100644 cloud-modules/cloud-modules-warn/src/main/resources/logback/test.xml create mode 100644 cloud-modules/cloud-modules-warn/src/test/java/com/muyu/AppTest.java create mode 100644 cloud-modules/cloud-modules-wechat/pom.xml create mode 100644 cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/WeChatApplication.java create mode 100644 cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/controller/WXController.java create mode 100644 cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/token/TokenUtil.java create mode 100644 cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/util/OkHttpUtils.java create mode 100644 cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/util/WordUtil.java create mode 100644 cloud-modules/cloud-modules-wechat/src/main/resources/banner.txt create mode 100644 cloud-modules/cloud-modules-wechat/src/main/resources/bootstrap.yml create mode 100644 cloud-modules/cloud-modules-wechat/src/main/resources/logback/dev.xml create mode 100644 cloud-modules/cloud-modules-wechat/src/main/resources/logback/prod.xml create mode 100644 cloud-modules/cloud-modules-wechat/src/main/resources/logback/test.xml create mode 100644 cloud-modules/cloud-modules-wechat/src/test/java/com/muyu/AppTest.java diff --git a/cloud-auth/src/main/resources/bootstrap.yml b/cloud-auth/src/main/resources/bootstrap.yml index 1cdb12c..5c1d2ce 100644 --- a/cloud-auth/src/main/resources/bootstrap.yml +++ b/cloud-auth/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 159.75.188.178:8848 user-name: nacos password: nacos - namespace: eight + namespace: psr # Spring spring: application: diff --git a/cloud-common/cloud-common-wechat/pom.xml b/cloud-common/cloud-common-wechat/pom.xml new file mode 100644 index 0000000..a6b8105 --- /dev/null +++ b/cloud-common/cloud-common-wechat/pom.xml @@ -0,0 +1,62 @@ + + 4.0.0 + + com.muyu + cloud-common + 3.6.3 + + + cloud-common-wechat + jar + + cloud-common-wechat + http://maven.apache.org + + + UTF-8 + + + + + + + com.muyu + cloud-common-core + + + + org.dom4j + dom4j + 2.1.3 + + + + + + com.thoughtworks.xstream + xstream + 1.4.20 + + + + com.squareup.okhttp3 + okhttp + 4.9.3 + + + + + com.alibaba + fastjson + 1.2.83 + + + + junit + junit + 3.8.1 + test + + + diff --git a/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/AccessToken.java b/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/AccessToken.java new file mode 100644 index 0000000..9fd2940 --- /dev/null +++ b/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/AccessToken.java @@ -0,0 +1,23 @@ +package com.muyu.common.wechat.domain; + +import lombok.Data; + +/** + * @author 24415 + */ +@Data +public class AccessToken { + + private String access_token; + + private Long expires_in; + + public void setExpiresTime(Long expiresIn) { + this.expires_in = System.currentTimeMillis()+expiresIn*1000; + } + + public boolean isExpired(Long expiresIn){ + long now = System.currentTimeMillis(); + return now>expiresIn; + } +} diff --git a/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/Articles.java b/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/Articles.java new file mode 100644 index 0000000..7464399 --- /dev/null +++ b/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/Articles.java @@ -0,0 +1,38 @@ +package com.muyu.common.wechat.domain; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author:蓬叁 + * @Package:com.muyu.wxapplication.massage + * @Project:WXApplication + * @name:Articles + * @Date:2024/9/18 下午10:14 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@XStreamAlias("item") +public class Articles { +// +// +// <![CDATA[title1]]> +// +// +// +// +// + + @XStreamAlias("Title") + private String title ; + @XStreamAlias("Description") + private String description ; + @XStreamAlias("PicUrl") + private String picUrl ; + @XStreamAlias("Url") + private String url ; + +} diff --git a/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/NewsMessage.java b/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/NewsMessage.java new file mode 100644 index 0000000..d0654a7 --- /dev/null +++ b/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/NewsMessage.java @@ -0,0 +1,50 @@ +package com.muyu.common.wechat.domain; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @Author:蓬叁 + * @Package:com.muyu.wxapplication.massage + * @Project:WXApplication + * @name:ImageText + * @Date:2024/9/18 下午9:27 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@XStreamAlias("xml") +public class NewsMessage { +// +// +// 12345678 +// +// 1 +// +// +// <![CDATA[title1]]> +// +// +// +// +// + + @XStreamAlias("ToUserName") + private String toUserName ; + @XStreamAlias("FromUserName") + private String fromUserName ; + @XStreamAlias("CreateTime") + private long createTime ; + @XStreamAlias("MsgType") + private String msgType ; + @XStreamAlias("ArticleCount") + private Integer articleCount ; + @XStreamAlias("Articles") + private List articles ; + + +} diff --git a/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/TextMessage.java b/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/TextMessage.java new file mode 100644 index 0000000..1877430 --- /dev/null +++ b/cloud-common/cloud-common-wechat/src/main/java/com/muyu/common/wechat/domain/TextMessage.java @@ -0,0 +1,40 @@ +package com.muyu.common.wechat.domain; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author:蓬叁 + * @Package:com.muyu.wxapplication.massage + * @Project:WXApplication + * @name:TextMessage + * @Date:2024/9/18 上午11:33 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@XStreamAlias("xml") +public class TextMessage { + + //起一个别名 因为我们微信返回信息与java代码格式规范发生冲突 + //微信格式 ToUserName + //JAVA格式 toUserName + @XStreamAlias("ToUserName") + private String toUserName; + @XStreamAlias("FromUserName") + private String fromUserName; + @XStreamAlias("CreateTime") + private long createTime; + @XStreamAlias("MsgType") + private String msgType; + @XStreamAlias("Content") + private String content; + +} +// +// +// 12345678 +// +// diff --git a/cloud-common/cloud-common-wechat/src/test/java/com/muyu/AppTest.java b/cloud-common/cloud-common-wechat/src/test/java/com/muyu/AppTest.java new file mode 100644 index 0000000..34d0e0a --- /dev/null +++ b/cloud-common/cloud-common-wechat/src/test/java/com/muyu/AppTest.java @@ -0,0 +1,38 @@ +package com.muyu; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/cloud-common/pom.xml b/cloud-common/pom.xml index d00dfc6..4bafd31 100644 --- a/cloud-common/pom.xml +++ b/cloud-common/pom.xml @@ -20,6 +20,7 @@ cloud-common-system cloud-common-xxl cloud-common-rabbit + cloud-common-wechat cloud-common diff --git a/cloud-gateway/src/main/resources/bootstrap.yml b/cloud-gateway/src/main/resources/bootstrap.yml index 7f67420..4e3a874 100644 --- a/cloud-gateway/src/main/resources/bootstrap.yml +++ b/cloud-gateway/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 159.75.188.178:8848 user-name: nacos password: nacos - namespace: eight + namespace: psr # Spring spring: diff --git a/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml index a02fcfb..88d6a5f 100644 --- a/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 159.75.188.178:8848 user-name: nacos password: nacos - namespace: eight + namespace: psr # Spring spring: diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml index 4663d03..b51413a 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 159.75.188.178:8848 user-name: nacos password: nacos - namespace: eight + namespace: psr # Spring spring: diff --git a/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml index 91799f9..7cd9457 100644 --- a/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 159.75.188.178:8848 user-name: nacos password: nacos - namespace: eight + namespace: psr # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # Spring spring: diff --git a/cloud-modules/cloud-modules-warn/pom.xml b/cloud-modules/cloud-modules-warn/pom.xml new file mode 100644 index 0000000..61995bf --- /dev/null +++ b/cloud-modules/cloud-modules-warn/pom.xml @@ -0,0 +1,112 @@ + + 4.0.0 + + com.muyu + cloud-modules + 3.6.3 + + + cloud-modules-warn + jar + + cloud-modules-warn + http://maven.apache.org + + + UTF-8 + + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + com.mysql + mysql-connector-j + + + + + com.muyu + cloud-common-datasource + + + + + com.muyu + cloud-common-datascope + + + + + com.muyu + cloud-common-log + + + + + com.muyu + cloud-common-api-doc + + + + + com.muyu + cloud-common-xxl + + + + com.muyu + cloud-common-rabbit + + + + junit + junit + 3.8.1 + test + + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/CloudWarnApplication.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/CloudWarnApplication.java new file mode 100644 index 0000000..e744a01 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/CloudWarnApplication.java @@ -0,0 +1,23 @@ +package com.muyu.warn; + +import com.muyu.common.security.annotation.EnableCustomConfig; +import com.muyu.common.security.annotation.EnableMyFeignClients; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn + * @Project:cloud-server-8 + * @name:CloudWarnApplication + * @Date:2024/9/20 下午8:33 + */ +@EnableCustomConfig +//@EnableCustomSwagger2 +@EnableMyFeignClients +@SpringBootApplication +public class CloudWarnApplication { + public static void main(String[] args) { + SpringApplication.run(CloudWarnApplication.class, args); + } +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnLogsController.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnLogsController.java new file mode 100644 index 0000000..7393306 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnLogsController.java @@ -0,0 +1,111 @@ +package com.muyu.warn.controller; + +import com.muyu.common.core.domain.Result; +import com.muyu.common.core.utils.poi.ExcelUtil; +import com.muyu.common.core.web.controller.BaseController; +import com.muyu.common.core.web.page.TableDataInfo; +import com.muyu.common.security.annotation.RequiresPermissions; +import com.muyu.common.security.utils.SecurityUtils; +import com.muyu.warn.domain.WarnLogs; +import com.muyu.warn.domain.WarnStrategy; +import com.muyu.warn.service.WarnLogsService; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; +import java.util.List; + +import static com.muyu.common.core.domain.Result.error; +import static com.muyu.common.core.domain.Result.success; +import static com.muyu.common.core.utils.PageUtils.startPage; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.controller + * @Project:cloud-server-8 + * @name:WarnLogsController + * @Date:2024/9/20 下午7:29 + */ +@RestController +@RequestMapping("/logs") +public class WarnLogsController extends BaseController { + + @Autowired private WarnLogsService warnLogsService; + + /** + * 查询预警日志列表 + */ + @RequiresPermissions("platform:logs:list") + @GetMapping("/list") + public Result> list(WarnLogs warnLogs) + { + startPage(); + List list = warnLogsService.selectWarnLogsList(warnLogs); + return getDataTable(list); + } + + /** + * 导出预警日志列表 + */ + @RequiresPermissions("platform:logs:export") + @PostMapping("/export") + public void export(HttpServletResponse response, WarnLogs warnLogs) + { + List list = warnLogsService.selectWarnLogsList(warnLogs); + ExcelUtil util = new ExcelUtil(WarnLogs.class); + util.exportExcel(response, list, "预警日志数据"); + } + + /** + * 获取预警日志详细信息 + */ + @RequiresPermissions("platform:logs:query") + @GetMapping(value = "/{id}") + public Result> getInfo(@PathVariable("id") Long id) + { + return success(warnLogsService.selectWarnLogsById(id)); + } + + /** + * 新增预警日志 + */ + @RequiresPermissions("platform:logs:add") + @PostMapping + public Result add( + @Validated @RequestBody WarnLogs warnLogs) + { + if (warnLogsService.checkIdUnique(warnLogs)) { + return error("新增 预警日志 '" + warnLogs + "'失败,预警日志已存在"); + } + return toAjax(warnLogsService.save(warnLogs)); + } + + /** + * 修改预警日志 + */ + @RequiresPermissions("platform:logs:edit") + @PutMapping + public Result edit( + @Validated @RequestBody WarnLogs warnLogs) + { + if (!warnLogsService.checkIdUnique(warnLogs)) { + return error("修改 预警日志 '" + warnLogs + "'失败,预警日志不存在"); + } +// warnLogs.setUpdateBy(SecurityUtils.getUsername()); + return toAjax(warnLogsService.updateById(warnLogs)); + } + + /** + * 删除预警日志 + */ + @RequiresPermissions("platform:logs:remove") + @DeleteMapping("/{ids}") + public Result remove(@PathVariable("ids") Long[] ids) + { + warnLogsService.removeBatchByIds(Arrays.asList(ids)); + return success(); + } + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnRuleController.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnRuleController.java new file mode 100644 index 0000000..844b28d --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnRuleController.java @@ -0,0 +1,106 @@ +package com.muyu.warn.controller; + +import com.muyu.common.core.domain.Result; +import com.muyu.common.core.utils.poi.ExcelUtil; +import com.muyu.common.core.web.controller.BaseController; +import com.muyu.common.core.web.page.TableDataInfo; +import com.muyu.common.security.annotation.RequiresPermissions; +import com.muyu.common.security.utils.SecurityUtils; +import com.muyu.warn.domain.WarnRule; +import com.muyu.warn.service.WarnRuleService; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.Arrays; +import java.util.List; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.controller + * @Project:cloud-server-8 + * @name:WarnLogsController + * @Date:2024/9/20 下午7:29 + */ +@RestController +@RequestMapping("/rule") +public class WarnRuleController extends BaseController +{ + @Resource + private WarnRuleService warnRuleService; + + /** + * 查询预警规则列表 + */ + @RequiresPermissions("platform:rule:list") + @GetMapping("/list") + public Result> list(WarnRule warnRule) + { + startPage(); + List list = warnRuleService.selectWarnRuleList(warnRule); + return getDataTable(list); + } + + /** + * 导出预警规则列表 + */ + @RequiresPermissions("platform:rule:export") + @PostMapping("/export") + public void export(HttpServletResponse response, WarnRule warnRule) + { + List list = warnRuleService.selectWarnRuleList(warnRule); + ExcelUtil util = new ExcelUtil(WarnRule.class); + util.exportExcel(response, list, "预警规则数据"); + } + + /** + * 获取预警规则详细信息 + */ + @RequiresPermissions("platform:rule:query") + @GetMapping(value = "/{id}") + public Result> getInfo(@PathVariable("id") Long id) + { + return success(warnRuleService.selectWarnRuleById(id)); + } + + /** + * 新增预警规则 + */ + @RequiresPermissions("platform:rule:add") + @PostMapping + public Result add( + @Validated @RequestBody WarnRule warnRule) + { + if (warnRuleService.checkIdUnique(warnRule)) { + return error("新增 预警规则 '" + warnRule + "'失败,预警规则已存在"); + } + return toAjax(warnRuleService.save(warnRule)); + } + + /** + * 修改预警规则 + */ + @RequiresPermissions("platform:rule:edit") + @PutMapping + public Result edit( + @Validated @RequestBody WarnRule warnRule) + { + if (!warnRuleService.checkIdUnique(warnRule)) { + return error("修改 预警规则 '" + warnRule + "'失败,预警规则不存在"); + } +// warnRule.setUpdateBy(SecurityUtils.getUsername()); + return toAjax(warnRuleService.updateById(warnRule)); + } + + /** + * 删除预警规则 + */ + @RequiresPermissions("platform:rule:remove") + @DeleteMapping("/{ids}") + public Result remove(@PathVariable("ids") Long[] ids) + { + warnRuleService.removeBatchByIds(Arrays.asList(ids)); + return success(); + } +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnStrategyController.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnStrategyController.java new file mode 100644 index 0000000..9515767 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/controller/WarnStrategyController.java @@ -0,0 +1,106 @@ +package com.muyu.warn.controller; + +import com.muyu.common.core.domain.Result; +import com.muyu.common.core.utils.poi.ExcelUtil; +import com.muyu.common.core.web.controller.BaseController; +import com.muyu.common.core.web.page.TableDataInfo; +import com.muyu.common.security.annotation.RequiresPermissions; +import com.muyu.common.security.utils.SecurityUtils; +import com.muyu.warn.domain.WarnStrategy; +import com.muyu.warn.service.WarnStrategyService; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.Arrays; +import java.util.List; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.controller + * @Project:cloud-server-8 + * @name:WarnLogsController + * @Date:2024/9/20 下午7:29 + */ +@RestController +@RequestMapping("/strategy") +public class WarnStrategyController extends BaseController +{ + @Resource + private WarnStrategyService warnStrategyService; + + /** + * 查询预警策略列表 + */ + @RequiresPermissions("platform:strategy:list") + @GetMapping("/list") + public Result> list(WarnStrategy warnStrategy) + { + startPage(); + List list = warnStrategyService.selectWarnStrategyList(warnStrategy); + return getDataTable(list); + } + + /** + * 导出预警策略列表 + */ + @RequiresPermissions("platform:strategy:export") + @PostMapping("/export") + public void export(HttpServletResponse response, WarnStrategy warnStrategy) + { + List list = warnStrategyService.selectWarnStrategyList(warnStrategy); + ExcelUtil util = new ExcelUtil(WarnStrategy.class); + util.exportExcel(response, list, "预警策略数据"); + } + + /** + * 获取预警策略详细信息 + */ + @RequiresPermissions("platform:strategy:query") + @GetMapping(value = "/{id}") + public Result> getInfo(@PathVariable("id") Long id) + { + return success(warnStrategyService.selectWarnStrategyById(id)); + } + + /** + * 新增预警策略 + */ + @RequiresPermissions("platform:strategy:add") + @PostMapping + public Result add( + @Validated @RequestBody WarnStrategy warnStrategy) + { + if (warnStrategyService.checkIdUnique(warnStrategy)) { + return error("新增 预警策略 '" + warnStrategy + "'失败,预警策略已存在"); + } + return toAjax(warnStrategyService.save(warnStrategy)); + } + + /** + * 修改预警策略 + */ + @RequiresPermissions("platform:strategy:edit") + @PutMapping + public Result edit( + @Validated @RequestBody WarnStrategy warnStrategy) + { + if (!warnStrategyService.checkIdUnique(warnStrategy)) { + return error("修改 预警策略 '" + warnStrategy + "'失败,预警策略不存在"); + } +// warnStrategy.setUpdateBy(SecurityUtils.getUsername()); + return toAjax(warnStrategyService.updateById(warnStrategy)); + } + + /** + * 删除预警策略 + */ + @RequiresPermissions("platform:strategy:remove") + @DeleteMapping("/{ids}") + public Result remove(@PathVariable("ids") Long[] ids) + { + warnStrategyService.removeBatchByIds(Arrays.asList(ids)); + return success(); + } +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnLogs.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnLogs.java new file mode 100644 index 0000000..6b6e28b --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnLogs.java @@ -0,0 +1,104 @@ +package com.muyu.warn.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.muyu.common.core.annotation.Excel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.domain + * @Project:cloud-server-8 + * @name:WarnLogs + * @Date:2024/9/20 下午7:11 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("warn_logs") +public class WarnLogs { + + /** + * 预警日志id + */ + @Excel(name = "预警日志id", cellType = Excel.ColumnType.NUMERIC) + @TableId( type = IdType.AUTO) + private Long id ; + /** + * 车辆vin码 + */ + @Excel(name = "车辆vin码") + private String vin ; + /** + * 规则id + */ + @Excel(name = "规则id") + private Long warnRuleId ; + /** + * 开始时间 + */ + @Excel(name = "开始时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date startTime ; + /** + * 结束时间 + */ + @Excel(name = "结束时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date endTime ; + /** + * 最大值 + */ + @Excel(name = "最大值") + private Long maxValue ; + /** + * 最小值 + */ + @Excel(name = "最小值") + private Long minValue ; + /** + * 平均值 + */ + @Excel(name = "平均值") + private Long avgValue ; + /** + * 中位数 + */ + @Excel(name = "中位数") + private Long medianValue ; + /** + * 是否发送预警 + */ + @Excel(name = "是否发送预警") + private Long status ; +// /** +// * 创建人 +// */ +// @Excel(name = "创建人") +// private String createBy ; +// /** +// * 创建时间 +// */ +// @Excel(name = "创建时间") +// private String createTime ; +// /** +// * 更新人 +// */ +// @Excel(name = "更新人") +// private String updateBy ; +// /** +// * 更新时间 +// */ +// @Excel(name = "更新时间") +// private String updateTime ; + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnRule.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnRule.java new file mode 100644 index 0000000..c798e92 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnRule.java @@ -0,0 +1,74 @@ +package com.muyu.warn.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.muyu.common.core.annotation.Excel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.domain + * @Project:cloud-server-8 + * @name:WarnRule + * @Date:2024/9/20 下午7:20 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("warn_rule") +public class WarnRule { + + /** + * 规则id + */ + @TableId( type = IdType.AUTO) + private Long id ; + /** + * 规则名称 + */ + private String ruleName ; + /** + * 策略id + */ + private Long strategyId ; + /** + * 报文数据类型id + */ + private Long msgTypeId ; + /** + * 滑窗时间 + */ + private Long slideTime ; + /** + * 滑窗频率 + */ + private Long slideFrequency ; + /** + * 最大值 + */ + private Long maxValue ; + /** + * 最小值 + */ + private Long minValue ; +// /** +// * 创建人 +// */ +// private String createBy ; +// /** +// * 创建时间 +// */ +// private String createTime ; +// /** +// * 更新人 +// */ +// private String updateBy ; +// /** +// * 更新时间 +// */ +// private String updateTime ; + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnStrategy.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnStrategy.java new file mode 100644 index 0000000..f2f1ed8 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/domain/WarnStrategy.java @@ -0,0 +1,58 @@ +package com.muyu.warn.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.muyu.common.core.annotation.Excel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.domain + * @Project:cloud-server-8 + * @name:WarnStrategy + * @Date:2024/9/20 下午7:27 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("warn_strategy") +public class WarnStrategy { + + /** + * 策略id + */ + @TableId( type = IdType.AUTO) + private Long id ; + /** + * 车辆类型id + */ + private Long carTypeId ; + /** + * 策略名称 + */ + private String strategyName ; + /** + * 报文模版id + */ + private Long msgId ; +// /** +// * 创建人 +// */ +// private String createBy ; +// /** +// * 创建时间 +// */ +// private String createTime ; +// /** +// * 更新人 +// */ +// private String updateBy ; +// /** +// * 更新时间 +// */ +// private String updateTime ; + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnLogsMapper.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnLogsMapper.java new file mode 100644 index 0000000..7ed3e6b --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnLogsMapper.java @@ -0,0 +1,18 @@ +package com.muyu.warn.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muyu.warn.domain.WarnLogs; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.mapper + * @Project:cloud-server-8 + * @name:WarnLogsMapper + * @Date:2024/9/20 下午7:31 + */ +@Mapper +public interface WarnLogsMapper extends BaseMapper { + + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnRuleMapper.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnRuleMapper.java new file mode 100644 index 0000000..a975a63 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnRuleMapper.java @@ -0,0 +1,17 @@ +package com.muyu.warn.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muyu.warn.domain.WarnRule; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.controller + * @Project:cloud-server-8 + * @name:WarnLogsController + * @Date:2024/9/20 下午7:29 + */ +@Mapper +public interface WarnRuleMapper extends BaseMapper { + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnStrategyMapper.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnStrategyMapper.java new file mode 100644 index 0000000..bb7fb53 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/mapper/WarnStrategyMapper.java @@ -0,0 +1,17 @@ +package com.muyu.warn.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muyu.warn.domain.WarnStrategy; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.controller + * @Project:cloud-server-8 + * @name:WarnLogsController + * @Date:2024/9/20 下午7:29 + */ +@Mapper +public interface WarnStrategyMapper extends BaseMapper { + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnLogsService.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnLogsService.java new file mode 100644 index 0000000..12a0248 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnLogsService.java @@ -0,0 +1,40 @@ +package com.muyu.warn.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muyu.warn.domain.WarnLogs; + +import java.util.List; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.service + * @Project:cloud-server-8 + * @name:WarnLogsService + * @Date:2024/9/20 下午7:32 + */ +public interface WarnLogsService extends IService { + + /** + * 精确查询预警日志 + * + * @param id 预警日志主键 + * @return 预警日志 + */ + public WarnLogs selectWarnLogsById(Long id); + + /** + * 查询预警日志列表 + * + * @param warnLogs 预警日志 + * @return 预警日志集合 + */ + public List selectWarnLogsList(WarnLogs warnLogs); + + /** + * 判断 预警日志 id是否唯一 + * @param warnLogs 预警日志 + * @return 结果 + */ + Boolean checkIdUnique(WarnLogs warnLogs); + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnRuleService.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnRuleService.java new file mode 100644 index 0000000..88351e5 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnRuleService.java @@ -0,0 +1,39 @@ +package com.muyu.warn.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muyu.warn.domain.WarnRule; + +import java.util.List; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.controller + * @Project:cloud-server-8 + * @name:WarnLogsController + * @Date:2024/9/20 下午7:29 + */ +public interface WarnRuleService extends IService { + /** + * 精确查询预警规则 + * + * @param id 预警规则主键 + * @return 预警规则 + */ + public WarnRule selectWarnRuleById(Long id); + + /** + * 查询预警规则列表 + * + * @param warnRule 预警规则 + * @return 预警规则集合 + */ + public List selectWarnRuleList(WarnRule warnRule); + + /** + * 判断 预警规则 id是否唯一 + * @param warnRule 预警规则 + * @return 结果 + */ + Boolean checkIdUnique(WarnRule warnRule); + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnStrategyService.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnStrategyService.java new file mode 100644 index 0000000..0aa6963 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/WarnStrategyService.java @@ -0,0 +1,39 @@ +package com.muyu.warn.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muyu.warn.domain.WarnStrategy; + +import java.util.List; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.controller + * @Project:cloud-server-8 + * @name:WarnLogsController + * @Date:2024/9/20 下午7:29 + */ +public interface WarnStrategyService extends IService { + /** + * 精确查询预警策略 + * + * @param id 预警策略主键 + * @return 预警策略 + */ + public WarnStrategy selectWarnStrategyById(Long id); + + /** + * 查询预警策略列表 + * + * @param warnStrategy 预警策略 + * @return 预警策略集合 + */ + public List selectWarnStrategyList(WarnStrategy warnStrategy); + + /** + * 判断 预警策略 id是否唯一 + * @param warnStrategy 预警策略 + * @return 结果 + */ + Boolean checkIdUnique(WarnStrategy warnStrategy); + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnLogsServiceImpl.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnLogsServiceImpl.java new file mode 100644 index 0000000..5e98ccb --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnLogsServiceImpl.java @@ -0,0 +1,98 @@ +package com.muyu.warn.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Assert; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muyu.common.core.utils.StringUtils; +import com.muyu.warn.domain.WarnLogs; +import com.muyu.warn.mapper.WarnLogsMapper; +import com.muyu.warn.service.WarnLogsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.service.impl + * @Project:cloud-server-8 + * @name:WarnLogsServiceImpl + * @Date:2024/9/20 下午7:39 + */ +@Service +public class WarnLogsServiceImpl + extends ServiceImpl + implements WarnLogsService { + + @Autowired private WarnLogsMapper warnLogsMapper; + + /** + * 精确查询预警日志 + * + * @param id 预警日志主键 + * @return 预警日志 + */ + @Override + public WarnLogs selectWarnLogsById(Long id) + { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + Assert.notNull(id, "id不可为空"); + queryWrapper.eq(WarnLogs::getId, id); + return this.getOne(queryWrapper); + } + + + /** + * 查询预警日志列表 + * + * @param warnLogs 预警日志 + * @return 预警日志 + */ + @Override + public List selectWarnLogsList(WarnLogs warnLogs) + { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + if (StringUtils.isNotEmpty(warnLogs.getVin())){ + queryWrapper.eq(WarnLogs::getVin, warnLogs.getVin()); + } + if (StringUtils.isNotNull(warnLogs.getWarnRuleId())){ + queryWrapper.eq(WarnLogs::getWarnRuleId, warnLogs.getWarnRuleId()); + } + if (StringUtils.isNotNull(warnLogs.getStartTime())){ + queryWrapper.eq(WarnLogs::getStartTime, warnLogs.getStartTime()); + } + if (StringUtils.isNotNull(warnLogs.getEndTime())){ + queryWrapper.eq(WarnLogs::getEndTime, warnLogs.getEndTime()); + } + if (StringUtils.isNotNull(warnLogs.getMaxValue())){ + queryWrapper.eq(WarnLogs::getMaxValue, warnLogs.getMaxValue()); + } + if (StringUtils.isNotNull(warnLogs.getMinValue())){ + queryWrapper.eq(WarnLogs::getMinValue, warnLogs.getMinValue()); + } + if (StringUtils.isNotNull(warnLogs.getAvgValue())){ + queryWrapper.eq(WarnLogs::getAvgValue, warnLogs.getAvgValue()); + } + if (StringUtils.isNotNull(warnLogs.getMedianValue())){ + queryWrapper.eq(WarnLogs::getMedianValue, warnLogs.getMedianValue()); + } + if (StringUtils.isNotNull(warnLogs.getStatus())){ + queryWrapper.eq(WarnLogs::getStatus, warnLogs.getStatus()); + } + return this.list(queryWrapper); + } + + /** + * 唯一 判断 + * @param warnLogs 预警日志 + * @return 预警日志 + */ + @Override + public Boolean checkIdUnique(WarnLogs warnLogs) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(WarnLogs::getId, warnLogs.getId()); + return this.count(queryWrapper) > 0; + } + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnRuleServiceImpl.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnRuleServiceImpl.java new file mode 100644 index 0000000..9466bbd --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnRuleServiceImpl.java @@ -0,0 +1,88 @@ +package com.muyu.warn.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muyu.common.core.utils.StringUtils; +import com.muyu.warn.domain.WarnRule; +import com.muyu.warn.mapper.WarnRuleMapper; +import com.muyu.warn.service.WarnRuleService; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.List; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.controller + * @Project:cloud-server-8 + * @name:WarnLogsController + * @Date:2024/9/20 下午7:29 + */ +@Service +public class WarnRuleServiceImpl + extends ServiceImpl + implements WarnRuleService { + + /** + * 精确查询预警规则 + * + * @param id 预警规则主键 + * @return 预警规则 + */ + @Override + public WarnRule selectWarnRuleById(Long id) + { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + Assert.notNull(id, "id不可为空"); + queryWrapper.eq(WarnRule::getId, id); + return this.getOne(queryWrapper); + } + + + /** + * 查询预警规则列表 + * + * @param warnRule 预警规则 + * @return 预警规则 + */ + @Override + public List selectWarnRuleList(WarnRule warnRule) + { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + if (StringUtils.isNotEmpty(warnRule.getRuleName())){ + queryWrapper.like(WarnRule::getRuleName, warnRule.getRuleName()); + } + if (StringUtils.isNotNull(warnRule.getStrategyId())){ + queryWrapper.eq(WarnRule::getStrategyId, warnRule.getStrategyId()); + } + if (StringUtils.isNotNull(warnRule.getMsgTypeId())){ + queryWrapper.eq(WarnRule::getMsgTypeId, warnRule.getMsgTypeId()); + } + if (StringUtils.isNotNull(warnRule.getSlideTime())){ + queryWrapper.eq(WarnRule::getSlideTime, warnRule.getSlideTime()); + } + if (StringUtils.isNotNull(warnRule.getSlideFrequency())){ + queryWrapper.eq(WarnRule::getSlideFrequency, warnRule.getSlideFrequency()); + } + if (StringUtils.isNotNull(warnRule.getMaxValue())){ + queryWrapper.eq(WarnRule::getMaxValue, warnRule.getMaxValue()); + } + if (StringUtils.isNotNull(warnRule.getMinValue())){ + queryWrapper.eq(WarnRule::getMinValue, warnRule.getMinValue()); + } + return this.list(queryWrapper); + } + + /** + * 唯一 判断 + * @param warnRule 预警规则 + * @return 预警规则 + */ + @Override + public Boolean checkIdUnique(WarnRule warnRule) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(WarnRule::getId, warnRule.getId()); + return this.count(queryWrapper) > 0; + } + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnStrategyServiceImpl.java b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnStrategyServiceImpl.java new file mode 100644 index 0000000..28d67e1 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/java/com/muyu/warn/service/impl/WarnStrategyServiceImpl.java @@ -0,0 +1,76 @@ +package com.muyu.warn.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muyu.common.core.utils.StringUtils; +import com.muyu.warn.domain.WarnStrategy; +import com.muyu.warn.mapper.WarnStrategyMapper; +import com.muyu.warn.service.WarnStrategyService; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.List; + +/** + * @Author:蓬叁 + * @Package:com.muyu.warn.controller + * @Project:cloud-server-8 + * @name:WarnLogsController + * @Date:2024/9/20 下午7:29 + */ +@Service +public class WarnStrategyServiceImpl + extends ServiceImpl + implements WarnStrategyService { + + /** + * 精确查询预警策略 + * + * @param id 预警策略主键 + * @return 预警策略 + */ + @Override + public WarnStrategy selectWarnStrategyById(Long id) + { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + Assert.notNull(id, "id不可为空"); + queryWrapper.eq(WarnStrategy::getId, id); + return this.getOne(queryWrapper); + } + + + /** + * 查询预警策略列表 + * + * @param warnStrategy 预警策略 + * @return 预警策略 + */ + @Override + public List selectWarnStrategyList(WarnStrategy warnStrategy) + { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + if (StringUtils.isNotNull(warnStrategy.getCarTypeId())){ + queryWrapper.eq(WarnStrategy::getCarTypeId, warnStrategy.getCarTypeId()); + } + if (StringUtils.isNotEmpty(warnStrategy.getStrategyName())){ + queryWrapper.like(WarnStrategy::getStrategyName, warnStrategy.getStrategyName()); + } + if (StringUtils.isNotNull(warnStrategy.getMsgId())){ + queryWrapper.eq(WarnStrategy::getMsgId, warnStrategy.getMsgId()); + } + return this.list(queryWrapper); + } + + /** + * 唯一 判断 + * @param warnStrategy 预警策略 + * @return 预警策略 + */ + @Override + public Boolean checkIdUnique(WarnStrategy warnStrategy) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(WarnStrategy::getId, warnStrategy.getId()); + return this.count(queryWrapper) > 0; + } + +} diff --git a/cloud-modules/cloud-modules-warn/src/main/resources/banner.txt b/cloud-modules/cloud-modules-warn/src/main/resources/banner.txt new file mode 100644 index 0000000..0dd5eee --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/resources/banner.txt @@ -0,0 +1,2 @@ +Spring Boot Version: ${spring-boot.version} +Spring Application Name: ${spring.application.name} diff --git a/cloud-modules/cloud-modules-warn/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-warn/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..a06d101 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/resources/bootstrap.yml @@ -0,0 +1,60 @@ +# Tomcat +server: + port: 10004 + +# nacos线上地址 +nacos: + addr: 159.75.188.178:8848 + user-name: nacos + password: nacos + namespace: psr +# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all +# Spring +spring: + amqp: + deserialization: + trust: + all: true + main: + allow-bean-definition-overriding: true + application: + # 应用名称 + name: cloud-warn + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + config: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + # 系统共享配置 + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # 系统环境Config共享配置 + - application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # xxl-job 配置文件 + - application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # rabbit 配置文件 + - application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} +logging: + level: + com.muyu.system.mapper: DEBUG diff --git a/cloud-modules/cloud-modules-warn/src/main/resources/logback/dev.xml b/cloud-modules/cloud-modules-warn/src/main/resources/logback/dev.xml new file mode 100644 index 0000000..2fd61ae --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/resources/logback/dev.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-warn/src/main/resources/logback/prod.xml b/cloud-modules/cloud-modules-warn/src/main/resources/logback/prod.xml new file mode 100644 index 0000000..8f5aff5 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/resources/logback/prod.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-warn/src/main/resources/logback/test.xml b/cloud-modules/cloud-modules-warn/src/main/resources/logback/test.xml new file mode 100644 index 0000000..8f5aff5 --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/main/resources/logback/test.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-warn/src/test/java/com/muyu/AppTest.java b/cloud-modules/cloud-modules-warn/src/test/java/com/muyu/AppTest.java new file mode 100644 index 0000000..34d0e0a --- /dev/null +++ b/cloud-modules/cloud-modules-warn/src/test/java/com/muyu/AppTest.java @@ -0,0 +1,38 @@ +package com.muyu; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/cloud-modules/cloud-modules-wechat/pom.xml b/cloud-modules/cloud-modules-wechat/pom.xml new file mode 100644 index 0000000..a6e67f8 --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/pom.xml @@ -0,0 +1,120 @@ + + 4.0.0 + + com.muyu + cloud-server + 3.6.3 + ../../pom.xml + + + cloud-modules-wechat + jar + + cloud-modules-wechat + http://maven.apache.org + + + UTF-8 + + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + com.mysql + mysql-connector-j + + + + + com.muyu + cloud-common-datasource + + + + + com.muyu + cloud-common-datascope + + + + + com.muyu + cloud-common-log + + + + + com.muyu + cloud-common-api-doc + + + + + com.muyu + cloud-common-xxl + + + + com.muyu + cloud-common-rabbit + + + + junit + junit + 3.8.1 + test + + + + com.muyu + cloud-common-wechat + 3.6.3 + + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + + diff --git a/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/WeChatApplication.java b/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/WeChatApplication.java new file mode 100644 index 0000000..806d21e --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/WeChatApplication.java @@ -0,0 +1,15 @@ +package com.muyu.wechat; + +import com.muyu.common.security.annotation.EnableMyFeignClients; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableMyFeignClients +public class WeChatApplication { + + public static void main(String[] args) { + SpringApplication.run(WeChatApplication.class, args); + } + +} diff --git a/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/controller/WXController.java b/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/controller/WXController.java new file mode 100644 index 0000000..95d33f4 --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/controller/WXController.java @@ -0,0 +1,185 @@ +package com.muyu.wechat.controller; + +import com.muyu.common.wechat.domain.Articles; +import com.muyu.common.wechat.domain.NewsMessage; +import com.muyu.common.wechat.domain.TextMessage; +import com.muyu.wechat.util.WordUtil; +import com.thoughtworks.xstream.XStream; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.http.HttpServletRequest; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.*; + +/** + * @Author:蓬叁 + * @Package:com.muyu.wxapplication.controller + * @Project:WXApplication + * @name:WXController + * @Date:2024/9/17 下午8:27 + */ +@RestController +public class WXController { + + @GetMapping("/hello") + public String hello(){ + return "Hello Wechat"; + } + + @GetMapping("/wechat") + public String check( + @RequestParam("signature") String signature, + @RequestParam("timestamp") String timestamp, + @RequestParam("nonce") String nonce, + @RequestParam("echostr") String echostr + ){ +// 1)将token、timestamp、nonce三个参数进行字典序排序 + String token = "Psan"; + List list = Arrays.asList(token, timestamp, nonce); + //排序 + Collections.sort(list); +// 2)将三个参数字符串拼接成一个字符串进行sha1加密 + StringBuilder stringBuilder = new StringBuilder(); + for (String s : list) { + stringBuilder.append(s); + } + //加密 + try { + MessageDigest instance = MessageDigest.getInstance("sha1"); + //使用sha1进行加密,获得byte数组 + byte[] digest = instance.digest(stringBuilder.toString().getBytes()); + StringBuilder sum = new StringBuilder(); + for (byte b : digest) { + sum.append(Integer.toHexString((b>>4)&15)); + sum.append(Integer.toHexString(b&15)); + } + System.out.println("signature:"+signature); + System.out.println("sum:"+sum); +// 3)开发者获得加密后的字符串可与signature对比,标识该请求来源于微信 + if (!StringUtils.isEmpty(signature)&&signature.equals(sum.toString())){ + return echostr; + } + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + return null; + } + + @PostMapping("/") + public String receiveMessage(HttpServletRequest request) throws IOException { + ServletInputStream inputStream = request.getInputStream(); + +// 查看发送信息类型 +// byte[] bytes = new byte[1024]; +// int len = 0; +// while ((len = inputStream.read(bytes)) != -1) { +// System.out.println(new String(bytes, 0, len)); +// } + + HashMap map = new HashMap<>(); + // xstream工具类 + SAXReader reader = new SAXReader(); + try { + //读取request输入流,获取Document对象 + Document document = reader.read(inputStream); + //获取root节点 + Element rootElement = document.getRootElement(); + //获取所有子节点 + List elements = rootElement.elements(); + for (Element element : elements) { + map.put(element.getName(), element.getStringValue()); + } + } catch (DocumentException e) { + throw new RuntimeException(e); + } + System.out.println(map); + String massage = null; + if ("图文".equals(map.get("Content"))) { + massage = getReplyNewsMessage(map); + } else { + massage = getReplyMessage(map); + } +// String massage = getReplyMessageByWord(map); + return massage; + } + + /** + * 获得回复的信息内容 + * @param map + * @return xml格式的字符串 + */ + private String getReplyMessage(HashMap map) { + TextMessage textMessage = new TextMessage(); + textMessage.setToUserName(map.get("FromUserName")); + textMessage.setFromUserName(map.get("ToUserName")); + textMessage.setMsgType("text"); + textMessage.setContent("你好吖"); + textMessage.setCreateTime(System.currentTimeMillis()/1000); + + //XStream将java对象转换为xml字符串 + XStream xStream = new XStream(); + xStream.processAnnotations(TextMessage.class); + String xml = xStream.toXML(textMessage); + return xml; + } + + /** + * 获得同义词 + * @param map + * @return xml格式的字符串 + */ + private String getReplyMessageByWord(HashMap map) { + TextMessage textMessage = new TextMessage(); + textMessage.setToUserName(map.get("FromUserName")); + textMessage.setFromUserName(map.get("ToUserName")); + textMessage.setMsgType("text"); + textMessage.setContent(WordUtil.getWords(map.get("Content"))); + textMessage.setCreateTime(System.currentTimeMillis()/1000); + + //XStream将java对象转换为xml字符串 + XStream xStream = new XStream(); + xStream.processAnnotations(TextMessage.class); + String xml = xStream.toXML(textMessage); + return xml; + } + + /** + * 获得回复的图文信息内容 + * @param map + * @return + */ + private String getReplyNewsMessage(HashMap map) { + NewsMessage newsMessage = new NewsMessage(); + newsMessage.setToUserName(map.get("FromUserName")); + newsMessage.setFromUserName(map.get("ToUserName")); + newsMessage.setMsgType("news"); + newsMessage.setCreateTime(System.currentTimeMillis()/1000); + newsMessage.setArticleCount(1); + List articles = new ArrayList<>(); + Articles article = new Articles(); + article.setTitle("蓬叁测试公众号"); + article.setDescription("来自蓬叁"); + article.setUrl("http://www.psan.com"); + article.setPicUrl("http://mmbiz.qpic.cn/mmbiz_jpg/ZR9F78J7iasww9HxBJRjsBMInrZ78YbXzKvgwy6iabyfZCiaM0CJKzOIS3fUAboIbh07s8icPfYW7RMiajLmx2opticw/0"); + articles.add(article); + newsMessage.setArticles(articles); + + //XStream将java对象转换为xml字符串 + XStream xStream = new XStream(); + xStream.processAnnotations(NewsMessage.class); + String xml = xStream.toXML(newsMessage); + return xml; + } + +} diff --git a/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/token/TokenUtil.java b/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/token/TokenUtil.java new file mode 100644 index 0000000..643267e --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/token/TokenUtil.java @@ -0,0 +1,41 @@ +package com.muyu.wechat.token; + +import com.alibaba.fastjson.JSON; +import com.muyu.common.wechat.domain.AccessToken; +import com.muyu.wechat.util.OkHttpUtils; +import org.springframework.stereotype.Component; + +@Component +public class TokenUtil { + public final static String APP_ID = "wx962013f3b1eb0a51"; + + public final static String APP_SECRET ="5c4c0b2130e6fdf86d989237f9e201dc"; + + public static void main(String[] args) { + System.out.println(getAccessToken()); + System.out.println(getAccessToken()); + } + + //域名 + public final static String REDIRECT_DOMAIN ="er6zej.natappfree.cc"; + + private static AccessToken accessToken = new AccessToken(); + +// {"access_token":"84_E1XHZXQpPj-K6mbCRmGn58iIPU3w7ViwtZRwAt5QN39FP9VBLPq57S_XjRQY88upoYyT4Boil2P6gY8uoKLHuth-W5OczJzr5EGZoWeh2PwhTKEfR1NcCWjqgTYJREcAIAZHU","expires_in":7200} + private static void getToken(){ + String url = String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s",APP_ID,APP_SECRET); + String request = OkHttpUtils.sendGetRequest(url); + System.out.println(request); + AccessToken wechatToken = JSON.parseObject(request, AccessToken.class); + //redisService.setCacheObject("WECHAT_TOKEN",wechatToken.getAccessToken(),wechatToken.getExpiresIn(), TimeUnit.SECONDS); + if (wechatToken != null) { + accessToken.setExpiresTime(wechatToken.getExpires_in()); + accessToken.setAccess_token(wechatToken.getAccess_token()); + } + } + public static String getAccessToken(){ + getToken(); + return accessToken.getAccess_token(); + } + +} diff --git a/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/util/OkHttpUtils.java b/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/util/OkHttpUtils.java new file mode 100644 index 0000000..8b6e2dd --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/util/OkHttpUtils.java @@ -0,0 +1,36 @@ +package com.muyu.wechat.util; + +import okhttp3.*; + +import java.io.IOException; + +public class OkHttpUtils { + + private static final OkHttpClient client = new OkHttpClient(); + + public static String sendGetRequest(String urlString) { + Request request = new Request.Builder() + .url(urlString) + .build(); + try (Response response = client.newCall(request).execute()) { + return response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + public static String sendPostRequest(String urlString, String params) { + RequestBody requestBody = RequestBody.create(params, MediaType.parse("application/json; charset=utf-8")); + Request request = new Request.Builder() + .url(urlString) + .post(requestBody) + .build(); + try (Response response = client.newCall(request).execute()) { + return response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/util/WordUtil.java b/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/util/WordUtil.java new file mode 100644 index 0000000..4d86e2e --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/src/main/java/com/muyu/wechat/util/WordUtil.java @@ -0,0 +1,43 @@ +package com.muyu.wechat.util; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +/** + * @Author:蓬叁 + * @Package:com.muyu.wxapplication.util + * @Project:WXApplication + * @name:WordUtil + * @Date:2024/9/18 下午7:38 + */ +public class WordUtil { + + //接口地址 + public static final String WORD_URL = "http://apis.juhe.cn/tyfy/query"; + + //申请接口的请求key + // TODO: 您需要改变自己的请求key + public static final String KEY = "f9ef42f215679f6995585159c3e1073e"; + + public static String getWords(String word){ + //发送http请求的url + String url = String.format(WORD_URL, KEY); + final String reponse = OkHttpUtils.sendPostRequest(url,JSONObject.toJSONString(word)); + System.out.println("接口返回:"+reponse); + JSONObject jsonObject = JSONObject.parseObject(reponse) ; + Integer error_code = jsonObject.getInteger("error_code"); + if (error_code == 0){ + System.out.println("调用接口成功"); + JSONObject result = jsonObject.getJSONObject("result"); + JSONArray words = result.getJSONArray("words"); + StringBuilder stringBuilder = new StringBuilder(); + words.stream().forEach(w -> stringBuilder.append(w + "")); + System.out.println(stringBuilder); + return stringBuilder.toString(); + } else { + System.out.println("调用接口失败:" + jsonObject.getString("reason")); + } + return null; + } + +} diff --git a/cloud-modules/cloud-modules-wechat/src/main/resources/banner.txt b/cloud-modules/cloud-modules-wechat/src/main/resources/banner.txt new file mode 100644 index 0000000..0dd5eee --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/src/main/resources/banner.txt @@ -0,0 +1,2 @@ +Spring Boot Version: ${spring-boot.version} +Spring Application Name: ${spring.application.name} diff --git a/cloud-modules/cloud-modules-wechat/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-wechat/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..030843a --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/src/main/resources/bootstrap.yml @@ -0,0 +1,60 @@ +# Tomcat +server: + port: 10003 + +# nacos线上地址 +nacos: + addr: 159.75.188.178:8848 + user-name: nacos + password: nacos + namespace: psr +# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all +# Spring +spring: + amqp: + deserialization: + trust: + all: true + main: + allow-bean-definition-overriding: true + application: + # 应用名称 + name: cloud-wechat + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + config: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + # 系统共享配置 + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # 系统环境Config共享配置 + - application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # xxl-job 配置文件 + - application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # rabbit 配置文件 + - application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} +logging: + level: + com.muyu.system.mapper: DEBUG diff --git a/cloud-modules/cloud-modules-wechat/src/main/resources/logback/dev.xml b/cloud-modules/cloud-modules-wechat/src/main/resources/logback/dev.xml new file mode 100644 index 0000000..2fd61ae --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/src/main/resources/logback/dev.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-wechat/src/main/resources/logback/prod.xml b/cloud-modules/cloud-modules-wechat/src/main/resources/logback/prod.xml new file mode 100644 index 0000000..8f5aff5 --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/src/main/resources/logback/prod.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-wechat/src/main/resources/logback/test.xml b/cloud-modules/cloud-modules-wechat/src/main/resources/logback/test.xml new file mode 100644 index 0000000..8f5aff5 --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/src/main/resources/logback/test.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-wechat/src/test/java/com/muyu/AppTest.java b/cloud-modules/cloud-modules-wechat/src/test/java/com/muyu/AppTest.java new file mode 100644 index 0000000..34d0e0a --- /dev/null +++ b/cloud-modules/cloud-modules-wechat/src/test/java/com/muyu/AppTest.java @@ -0,0 +1,38 @@ +package com.muyu; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/cloud-modules/pom.xml b/cloud-modules/pom.xml index ba0d555..aaf18a0 100644 --- a/cloud-modules/pom.xml +++ b/cloud-modules/pom.xml @@ -12,6 +12,7 @@ cloud-modules-system cloud-modules-gen cloud-modules-file + cloud-modules-warn cloud-modules diff --git a/cloud-visual/cloud-visual-monitor/src/main/resources/bootstrap.yml b/cloud-visual/cloud-visual-monitor/src/main/resources/bootstrap.yml index ae51cac..d6abfab 100644 --- a/cloud-visual/cloud-visual-monitor/src/main/resources/bootstrap.yml +++ b/cloud-visual/cloud-visual-monitor/src/main/resources/bootstrap.yml @@ -1,13 +1,13 @@ # Tomcat server: - port: 9100 + port: 9101 # nacos线上地址 nacos: addr: 159.75.188.178:8848 user-name: nacos password: nacos - namespace: eight + namespace: psr # Spring spring: diff --git a/pom.xml b/pom.xml index b30f0df..91dbc8e 100644 --- a/pom.xml +++ b/pom.xml @@ -275,6 +275,7 @@ cloud-visual cloud-modules cloud-common + cloud-modules/cloud-modules-wechat pom