Compare commits

...

12 Commits

Author SHA1 Message Date
微醺 c9ec3f3b01 1.报文管理
2.模块管理
更新时间09271529
2024-09-27 15:29:29 +08:00
微醺 dd30d17c40 1.报文管理
2.模块管理
更新时间09231131
2024-09-23 11:31:58 +08:00
xinzirun 68f94b0f26 fix(): 修复依赖冲突问题 2024-09-23 11:28:34 +08:00
xinzirun c470ef9787 Merge branch 'master' of https://gitea.qinmian.online/six-vehicle/cloud-server 2024-09-23 11:25:41 +08:00
liuyibo 50a58d2470 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	cloud-auth/src/main/resources/bootstrap.yml
#	cloud-gateway/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml
#	cloud-visual/cloud-visual-monitor/src/main/resources/bootstrap.yml
2024-09-23 11:17:34 +08:00
liuyibo 17c891ff02 feat():车辆预警策略列表,规则列表,通过策略id查询规则,通过策略表的报文id查询报文 2024-09-23 10:15:46 +08:00
xinzirun 934367b1ea fix(): 修复请求头校验 2024-09-23 08:55:52 +08:00
xinzirun b5757fdead feat(): 新增鉴权Saas标识校验 2024-09-22 10:08:22 +08:00
xinzirun 7c49fee992 fix(): 修复命名空间冲突问题 2024-09-22 10:07:14 +08:00
xinzirun 0b97b1e2ed fix(): 修复空指针异常问题 2024-09-22 10:06:44 +08:00
xinzirun d81b53910e fix(): 修复run()方法 2024-09-21 12:01:34 +08:00
liuyibo 6a55491e45 feat():车辆警告CRUD 2024-09-21 11:59:45 +08:00
103 changed files with 3339 additions and 123 deletions

View File

@ -7,7 +7,7 @@ nacos:
addr: 106.15.136.7:8848
user-name: nacos
password: nacos
namespace: crj
namespace: xzr
# Spring
spring:
application:

View File

@ -21,132 +21,132 @@ public @interface Excel {
/**
* excel
*/
public int sort () default Integer.MAX_VALUE;
public int sort() default Integer.MAX_VALUE;
/**
* Excel.
*/
public String name () default "";
public String name() default "";
/**
* , : yyyy-MM-dd
*/
public String dateFormat () default "";
public String dateFormat() default "";
/**
* (: 0=,1=,2=)
*/
public String readConverterExp () default "";
public String readConverterExp() default "";
/**
*
*/
public String separator () default ",";
public String separator() default ",";
/**
* BigDecimal :-1(BigDecimal)
*/
public int scale () default -1;
public int scale() default -1;
/**
* BigDecimal :BigDecimal.ROUND_HALF_EVEN
*/
public int roundingMode () default BigDecimal.ROUND_HALF_EVEN;
public int roundingMode() default BigDecimal.ROUND_HALF_EVEN;
/**
* excel
*/
public double height () default 14;
public double height() default 14;
/**
* excel
*/
public double width () default 16;
public double width() default 16;
/**
* ,% 90 90%
*/
public String suffix () default "";
public String suffix() default "";
/**
* ,
*/
public String defaultValue () default "";
public String defaultValue() default "";
/**
*
*/
public String prompt () default "";
public String prompt() default "";
/**
* .
*/
public String[] combo () default {};
public String[] combo() default {};
/**
* ,:list)
*/
public boolean needMerge () default false;
public boolean needMerge() default false;
/**
* ,:,.
*/
public boolean isExport () default true;
public boolean isExport() default true;
/**
* ,,
*/
public String targetAttr () default "";
public String targetAttr() default "";
/**
* ,
*/
public boolean isStatistics () default false;
public boolean isStatistics() default false;
/**
* 0 1
*/
public ColumnType cellType () default ColumnType.STRING;
public ColumnType cellType() default ColumnType.STRING;
/**
*
*/
public IndexedColors headerBackgroundColor () default IndexedColors.GREY_50_PERCENT;
public IndexedColors headerBackgroundColor() default IndexedColors.GREY_50_PERCENT;
/**
*
*/
public IndexedColors headerColor () default IndexedColors.WHITE;
public IndexedColors headerColor() default IndexedColors.WHITE;
/**
*
*/
public IndexedColors backgroundColor () default IndexedColors.WHITE;
public IndexedColors backgroundColor() default IndexedColors.WHITE;
/**
*
*/
public IndexedColors color () default IndexedColors.BLACK;
public IndexedColors color() default IndexedColors.BLACK;
/**
*
*/
public HorizontalAlignment align () default HorizontalAlignment.CENTER;
public HorizontalAlignment align() default HorizontalAlignment.CENTER;
/**
*
*/
public Class<?> handler () default ExcelHandlerAdapter.class;
public Class<?> handler() default ExcelHandlerAdapter.class;
/**
*
*/
public String[] args () default {};
public String[] args() default {};
/**
* 012
*/
Type type () default Type.ALL;
Type type() default Type.ALL;
public enum Type {
ALL(0), EXPORT(1), IMPORT(2);

View File

@ -13,5 +13,5 @@ import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Excels {
Excel[] value ();
Excel[] value();
}

View File

@ -45,4 +45,9 @@ public class SecurityConstants {
*
*/
public static final String ROLE_PERMISSION = "role_permission";
/**
* SaaS
*/
public static final String SAAS_KEY = "ent-code";
}

View File

@ -162,4 +162,13 @@ public class JwtUtils {
public static String getValue (Claims claims, String key) {
return Convert.toStr(claims.get(key), "");
}
/**
* SaaS
* @param claims
* @return Saas
*/
public static String getSaaSKey (Claims claims) {
return getValue(claims, SecurityConstants.SAAS_KEY);
}
}

View File

@ -26,7 +26,7 @@ public final class SpringUtils implements BeanFactoryPostProcessor {
*
* @return Object bean
*
* @throws org.springframework.beans.BeansException
* @throws BeansException
*/
@SuppressWarnings("unchecked")
public static <T> T getBean (String name) throws BeansException {
@ -40,7 +40,7 @@ public final class SpringUtils implements BeanFactoryPostProcessor {
*
* @return
*
* @throws org.springframework.beans.BeansException
* @throws BeansException
*/
public static <T> T getBean (Class<T> clz) throws BeansException {
T result = (T) beanFactory.getBean(clz);
@ -65,7 +65,7 @@ public final class SpringUtils implements BeanFactoryPostProcessor {
*
* @return boolean
*
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
* @throws NoSuchBeanDefinitionException
*/
public static boolean isSingleton (String name) throws NoSuchBeanDefinitionException {
return beanFactory.isSingleton(name);
@ -76,7 +76,7 @@ public final class SpringUtils implements BeanFactoryPostProcessor {
*
* @return Class
*
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
* @throws NoSuchBeanDefinitionException
*/
public static Class<?> getType (String name) throws NoSuchBeanDefinitionException {
return beanFactory.getType(name);
@ -89,7 +89,7 @@ public final class SpringUtils implements BeanFactoryPostProcessor {
*
* @return
*
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
* @throws NoSuchBeanDefinitionException
*/
public static String[] getAliases (String name) throws NoSuchBeanDefinitionException {
return beanFactory.getAliases(name);

View File

@ -17,11 +17,11 @@ import java.lang.annotation.Target;
@Target(value = {ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PARAMETER})
@Constraint(validatedBy = {XssValidator.class})
public @interface Xss {
String message ()
String message()
default "不允许任何脚本运行";
Class<?>[] groups () default {};
Class<?>[] groups() default {};
Class<? extends Payload>[] payload () default {};
Class<? extends Payload>[] payload() default {};
}

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-common</artifactId>
<version>3.6.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-common-datascope</artifactId>
<description>
cloud-common-datascope权限范围
</description>
<dependencies>
<!-- MuYu Common Security -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-security</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,28 @@
package com.muyu.common.datascope.annotation;
import java.lang.annotation.*;
/**
*
*
* @author muyu
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface DataScope {
/**
*
*/
public String deptAlias () default "";
/**
*
*/
public String userAlias () default "";
/**
* @RequiresPermissions
*/
public String permission () default "";
}

View File

@ -0,0 +1,149 @@
package com.muyu.common.datascope.aspect;
import com.muyu.common.core.context.SecurityContextHolder;
import com.muyu.common.core.text.Convert;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.common.datascope.annotation.DataScope;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.SysRole;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.domain.LoginUser;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
*
*
* @author muyu
*/
@Aspect
@Component
public class DataScopeAspect {
/**
*
*/
public static final String DATA_SCOPE_ALL = "1";
/**
*
*/
public static final String DATA_SCOPE_CUSTOM = "2";
/**
*
*/
public static final String DATA_SCOPE_DEPT = "3";
/**
*
*/
public static final String DATA_SCOPE_DEPT_AND_CHILD = "4";
/**
*
*/
public static final String DATA_SCOPE_SELF = "5";
/**
*
*/
public static final String DATA_SCOPE = "dataScope";
/**
*
*
* @param joinPoint
* @param user
* @param deptAlias
* @param userAlias
* @param permission
*/
public static void dataScopeFilter (JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, String permission) {
StringBuilder sqlString = new StringBuilder();
List<String> conditions = new ArrayList<String>();
for (SysRole role : user.getRoles()) {
String dataScope = role.getDataScope();
if (!DATA_SCOPE_CUSTOM.equals(dataScope) && conditions.contains(dataScope)) {
continue;
}
if (StringUtils.isNotEmpty(permission) && StringUtils.isNotEmpty(role.getPermissions())
&& !StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission))) {
continue;
}
if (DATA_SCOPE_ALL.equals(dataScope)) {
sqlString = new StringBuilder();
conditions.add(dataScope);
break;
} else if (DATA_SCOPE_CUSTOM.equals(dataScope)) {
sqlString.append(StringUtils.format(
" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias,
role.getRoleId()));
} else if (DATA_SCOPE_DEPT.equals(dataScope)) {
sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
} else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) {
sqlString.append(StringUtils.format(
" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
deptAlias, user.getDeptId(), user.getDeptId()));
} else if (DATA_SCOPE_SELF.equals(dataScope)) {
if (StringUtils.isNotBlank(userAlias)) {
sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));
} else {
// 数据权限为仅本人且没有userAlias别名不查询任何数据
sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
}
}
conditions.add(dataScope);
}
// 多角色情况下所有角色都不包含传递过来的权限字符这个时候sqlString也会为空所以要限制一下,不查询任何数据
if (StringUtils.isEmpty(conditions)) {
sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
}
if (StringUtils.isNotBlank(sqlString.toString())) {
Object params = joinPoint.getArgs()[0];
if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
BaseEntity baseEntity = (BaseEntity) params;
baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
}
}
}
@Before("@annotation(controllerDataScope)")
public void doBefore (JoinPoint point, DataScope controllerDataScope) throws Throwable {
clearDataScope(point);
handleDataScope(point, controllerDataScope);
}
protected void handleDataScope (final JoinPoint joinPoint, DataScope controllerDataScope) {
// 获取当前的用户
LoginUser loginUser = SecurityUtils.getLoginUser();
if (StringUtils.isNotNull(loginUser)) {
SysUser currentUser = loginUser.getSysUser();
// 如果是超级管理员,则不过滤数据
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) {
String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), SecurityContextHolder.getPermission());
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
controllerDataScope.userAlias(), permission);
}
}
}
/**
* sqlparams.dataScope
*/
private void clearDataScope (final JoinPoint joinPoint) {
Object params = joinPoint.getArgs()[0];
if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
BaseEntity baseEntity = (BaseEntity) params;
baseEntity.getParams().put(DATA_SCOPE, "");
}
}
}

View File

@ -11,11 +11,10 @@ import com.muyu.cloud.common.saas.domain.model.EntInfo;
import com.muyu.cloud.common.saas.exception.SaaSException;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.SpringUtils;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.remote.RemoteUserService;
import lombok.extern.log4j.Log4j2;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.AutoConfiguration;
@ -78,7 +77,7 @@ public class ManyDataSource implements ApplicationRunner {
)
.toList();
}else {
log.error("远调数据源错误,远调数据为:{}", JSON.toJSONString(data));
log.error("远调数据源异常,异常信息:{}", JSON.toJSONString(entListResult.getMsg()));
return null;
}
}
@ -91,29 +90,21 @@ public class ManyDataSource implements ApplicationRunner {
*/
@Bean
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
List<DataSourceInfo> sourceInfoList = dataSourceInfoList().stream()
List<EntInfo> entInfoList = dataSourceInfoList();
if(StringUtils.isEmpty(entInfoList)){
throw new SaaSException("数据源信息列表为空或为null");
}
Map<Object, Object> dataSourceMap = dataSourceInfoList().stream()
.map(entInfo -> DataSourceInfo.hostAndPortBuild(
entInfo.getEntCode(),
entInfo.getIp(),
entInfo.getPort()
)
).toList();
Map<Object, Object> dataSourceMap = sourceInfoList.stream().collect(Collectors.toMap(
)
.collect(Collectors.toMap(
dataSourceInfo -> dataSourceInfo.getKey(),
dataSourceInfo -> druidDataSourceFactory.create(dataSourceInfo)
));
// Map<Object, Object> dataSourceMap = dataSourceInfoList().stream()
// .map(entInfo -> DataSourceInfo.hostAndPortBuild(
// entInfo.getEntCode(),
// entInfo.getIp(),
// entInfo.getPort()
// )
// )
// .collect(Collectors.toMap(
// dataSourceInfo -> dataSourceInfo.getKey(),
// dataSourceInfo -> druidDataSourceFactory.create(dataSourceInfo)
// ));
//设置动态数据源
DynamicDataSource dynamicDataSource = new DynamicDataSource();
@ -121,19 +112,4 @@ public class ManyDataSource implements ApplicationRunner {
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
return dynamicDataSource;
}
/**
* SqlSessionFactory Bean MyBatis
* SqlSessionFactory
* SqlSessionFactory
* @param dataSource
* @return SqlSessionFactory
* @throws Exception
*/
@Bean
public SqlSessionFactory sqlSessionFactory(DynamicDataSource dataSource) throws Exception {
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
return sessionFactory.getObject();
}
}

View File

@ -55,6 +55,7 @@ public class TokenService {
claimsMap.put(SecurityConstants.USER_KEY, token);
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
claimsMap.put(SecurityConstants.SAAS_KEY, loginUser.getSysUser().getDatabaseName());
// 接口返回信息
Map<String, Object> rspMap = new HashMap<String, Object>();

View File

@ -12,6 +12,7 @@
<module>cloud-common-log</module>
<module>cloud-common-core</module>
<module>cloud-common-redis</module>
<module>cloud-common-saas</module>
<module>cloud-common-seata</module>
<module>cloud-common-api-doc</module>
<module>cloud-common-security</module>
@ -20,7 +21,6 @@
<module>cloud-common-system</module>
<module>cloud-common-xxl</module>
<module>cloud-common-rabbit</module>
<module>cloud-common-saas</module>
</modules>
<artifactId>cloud-common</artifactId>

View File

@ -56,9 +56,9 @@ public class AuthFilter implements GlobalFilter, Ordered {
if (claims == null) {
return unauthorizedResponse(exchange, "令牌已过期或验证不正确!");
}
String userkey = JwtUtils.getUserKey(claims);
boolean islogin = redisService.hasKey(getTokenKey(userkey));
if (!islogin) {
String userKey = JwtUtils.getUserKey(claims);
boolean isLogin = redisService.hasKey(getTokenKey(userKey));
if (!isLogin) {
return unauthorizedResponse(exchange, "登录状态已过期");
}
String userid = JwtUtils.getUserId(claims);
@ -66,11 +66,14 @@ public class AuthFilter implements GlobalFilter, Ordered {
if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) {
return unauthorizedResponse(exchange, "令牌验证失败");
}
String saaSKey = JwtUtils.getSaaSKey(claims);
// 设置用户信息到请求
addHeader(mutate, SecurityConstants.USER_KEY, userkey);
addHeader(mutate, SecurityConstants.USER_KEY, userKey);
addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid);
addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username);
addHeader(mutate, SecurityConstants.SAAS_KEY, saaSKey);
// 内部请求来源参数清除
removeHeader(mutate, SecurityConstants.FROM_SOURCE);
return chain.filter(exchange.mutate().request(mutate.build()).build());

View File

@ -7,7 +7,7 @@ nacos:
addr: 106.15.136.7:8848
user-name: nacos
password: nacos
namespace: crj
namespace: xzr
# Spring
spring:

View File

@ -1,9 +1,12 @@
package com.muyu;
import com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
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;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/**
*

View File

@ -78,8 +78,6 @@ public class SysCarController extends BaseController {
// 随机生成VIN码
String key2 = RandomUtil.randomNumbers(17);
carVO.setCarVin(key2);
//
carVO.setUserId(SecurityUtils.getUserId());
sysCarService.insertCar(carVO);
return Result.success("车辆添加成功");
}
@ -92,6 +90,8 @@ public class SysCarController extends BaseController {
*/
@PostMapping("updataCar")
public Result updataCar(@RequestBody CarVO carVO){
//
carVO.setUserId(SecurityUtils.getUserId());
sysCarService.updateById(carVO);
return Result.success("车辆修改成功");
}

View File

@ -0,0 +1,68 @@
package com.muyu.car.controller;
import com.muyu.car.domain.CarMessage;
import com.muyu.car.service.SysCarMessageService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/message") // 报文
@Tag(name = "报文",description = "报文模块")
public class SysCarMessageController extends BaseController {
@Autowired
private SysCarMessageService sysCarMessageService;
/**
*
* @return
*/
@PostMapping("selectMessageShow")
public List<CarMessage> selectMessageShow(@RequestParam("templateId") Long templateId){
return sysCarMessageService.selectMessageShow(templateId);
}
/**
* id
* @return
*/
@PostMapping("selectMessageByMessageId")
public CarMessage selectMessageByMessageId(@RequestParam("messageId") Long messageId){
return sysCarMessageService.selectMessageByMessageId(messageId);
}
/**
*
* @return carMessage
*/
@PostMapping("insertMessage")
public Result insertMessage(@RequestBody CarMessage carMessage){
sysCarMessageService.save(carMessage);
return Result.success("添加成功");
}
/**
*
* @return carMessage
*/
@PostMapping("updataMessage")
public Result updataMessage(@RequestBody CarMessage carMessage){
sysCarMessageService.updateById(carMessage);
return Result.success("修改成功");
}
/**
*
* @return carMessage
*/
@PostMapping("deleteMessage")
public Result deleteMessage(@RequestParam("ids") List<Long> ids){
sysCarMessageService.removeBatchByIds(ids);
return Result.success("删除成功");
}
}

View File

@ -0,0 +1,113 @@
package com.muyu.car.controller;
import com.github.pagehelper.util.StringUtil;
import com.muyu.car.domain.CarMessageType;
import com.muyu.car.domain.CarTemplate;
import com.muyu.car.service.SysCarMessageTypeService;
import com.muyu.car.service.SysCarTemplateService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.security.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/type") // 报文类型
@Tag(name = "报文类型",description = "报文类型")
public class SysCarMessageTypeController extends BaseController {
@Autowired
private SysCarMessageTypeService sysCarMessageTypeService;
/**
*
* @return
*/
@PostMapping("messageTypeList")
public List<CarMessageType> messageTypeList(){
List<CarMessageType> list = sysCarMessageTypeService.list();
return list;
}
/**
*
* @param carMessageType
* @return
*/
@PostMapping("insertMessageType")
public Result insertMessageType(@RequestBody CarMessageType carMessageType){
// // token 校验
// if(SecurityUtils.getToken().equals("")){
// return Result.error("token不存在");
// }
// id不能传
// if(carMessageType.getMessageTypeId() > 0 || carMessageType.getMessageTypeId() != null){
// return Result.error("添加要什么ID");
// }
// 报文编码校验
if(StringUtils.isEmpty(carMessageType.getMessageCode())){
return Result.error("报文编码不能为空");
}
// 报文名称校验
if(StringUtils.isEmpty(carMessageType.getMessageName())){
return Result.error("报文名称不能为空");
}
// 报文分类不能为空
if(StringUtils.isEmpty(carMessageType.getMessageClass())){
return Result.error("报文字段类型不能为空");
}
// 执行添加的操作
sysCarMessageTypeService.save(carMessageType);
return Result.success("添加成功");
}
/**
*
* @param carMessageType
* @return
*/
@PostMapping("updateMessageType")
public Result updateMessageType(@RequestBody CarMessageType carMessageType){
// 报文id
if(carMessageType.getMessageTypeId() <= 0){
return Result.error("报文类型id不能为空,这是修改啊哥们");
}
// 报文分类判断
if(StringUtils.isEmpty(carMessageType.getMessageType())){
return Result.error("报文分类不为空");
}
// 报文编码
if(StringUtils.isEmpty(carMessageType.getMessageCode())){
return Result.error("报文编码不能为空");
}
// 报文名称
if(StringUtils.isEmpty(carMessageType.getMessageName())){
return Result.error("报文名称不能为空");
}
// 报文字段类型
if(StringUtils.isEmpty(carMessageType.getMessageClass())){
return Result.error("报文字段类型不能为空");
}
sysCarMessageTypeService.updateById(carMessageType);
return Result.success("报文类型修改成功");
}
@PostMapping("deleteMessageType")
public Result deleteMessageType
(@RequestParam("ids") List<Long> ids){
if(ids.size()<1){
return Result.error("请先选择要删除的数据行");
}
sysCarMessageTypeService.removeBatchByIds(ids);
if(ids.size()==1){
return Result.success("删除成功");
}
if(ids.size()>1){
return Result.success("批量删除成功");
}
return Result.success("删除成功");
}
}

View File

@ -0,0 +1,68 @@
package com.muyu.car.controller;
import com.muyu.car.domain.CarMessage;
import com.muyu.car.domain.CarTemplate;
import com.muyu.car.service.SysCarMessageService;
import com.muyu.car.service.SysCarTemplateService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/template") // 报文
@Tag(name = "模版模块",description = "报文模版模块")
public class SysCarTemplateController extends BaseController {
@Autowired
private SysCarTemplateService sysCarTemplateService;
/**
*
* @return
*/
@PostMapping("selectTemplateShow")
public List<CarTemplate> selectTemplateShow(){
return sysCarTemplateService.selectTemplateShow();
}
/**
* id
* @return
*/
@PostMapping("selectTemplateByTemplateId")
public CarTemplate selectTemplateByTemplateId(@RequestParam("templateId") Long templateId){
return sysCarTemplateService.selectTemplateByTemplateId(templateId);
}
/**
*
* @return carMessage
*/
@PostMapping("insertTemplate")
public Result insertTemplate(@RequestBody CarTemplate carTemplate){
sysCarTemplateService.save(carTemplate);
return Result.success("添加成功");
}
/**
*
* @return carMessage
*/
@PostMapping("updataTemplate")
public Result updataTemplate(@RequestBody CarTemplate carTemplate){
sysCarTemplateService.updateById(carTemplate);
return Result.success("修改成功");
}
/**
*
* @return carMessage
*/
@PostMapping("deleteTemplate")
public Result deleteTemplate(@RequestParam("ids") List<Long> ids){
sysCarTemplateService.removeBatchByIds(ids);
return Result.success("删除成功");
}
}

View File

@ -0,0 +1,74 @@
package com.muyu.car.domain;
import lombok.Data;
import java.util.Date;
@Data
public class Car {
/**
*
*/
private Integer CarId;
/**
*
*/
private String CarFrame;
/**
*
*/
private String CarCoed;
/**
*
*/
private Integer CarColor;
/**
* VIN
*/
private String CarVin;
/**
*
*/
private Integer UserId;
/**
*
*/
private Integer TypeId;
/**
*
*/
private Date AudditTime;
/**
*
*/
private Date LiceseTime;
/**
*
*/
private Date LinsuranceTime;
/**
* 线
*/
private Integer CarStatus;
/**
*
*/
private Date CreatedTime;
/**
*
*/
private Integer CarGears;
/**
*
*/
private String CarModel;
/**
*
*/
private String CarBrand;
}

View File

@ -19,10 +19,6 @@ public class CarMessage {
*/
@TableId(value = "message_id",type = IdType.AUTO)
private Long messageId;
/**
*
*/
private String messageCode;
/**
*
*/
@ -35,22 +31,7 @@ public class CarMessage {
*
*/
private Integer messageEndIndex;
/**
*
*/
private String messageDataType;
/**
*
*/
private double fixedValue;
/**
*
*/
private double minimumValue;
/**
*
*/
private double maximumValue;
/**
* id
*/

View File

@ -18,7 +18,7 @@ public class CarMessageType {
*
*/
@TableId(value = "message_type_id",type = IdType.AUTO)
private Integer messageTypeId;
private Long messageTypeId;
/**
*
*/

View File

@ -19,7 +19,7 @@ public class CarTemplate {
*
*/
@TableId(value = "template_id",type = IdType.AUTO)
private Integer templateId;
private Long templateId;
/**
*
*/

View File

@ -39,10 +39,6 @@ public class SysCar {
* VIN
*/
private String carVin;
/**
*
*/
private Long carUserId;
/**
*
*/
@ -98,5 +94,13 @@ public class SysCar {
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "最后一次离线时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date carLastOfflineTime;
private Integer Car_id;
private Integer car_deman;
private Integer cae_color;
private Integer vin;
private Integer user_id;
private Integer type_id;
private Integer stete;
private Integer auddit;
private String brand;
}

View File

@ -50,4 +50,11 @@ public class CarDTO {
* 线 1. 2. 3.
*/
private Integer carStatus;
/**
*
*/
@TableField(exist = false)
private String companyName;
}

View File

@ -40,10 +40,6 @@ public class CarVO {
* VIN
*/
private String carVin;
/**
*
*/
private Long carUserId;
/**
*
*/
@ -120,4 +116,10 @@ public class CarVO {
@TableField(exist = false)
private Integer gearType;
/**
*
*/
@TableField(exist = false)
private String companyName;
}

View File

@ -0,0 +1,17 @@
package com.muyu.car.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.car.domain.CarMessage;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface SysCarMessageMapper extends BaseMapper<CarMessage> {
/**
*
* @param templateId
* @return
*/
List<CarMessage> selectMessageShow(Long templateId);
}

View File

@ -0,0 +1,13 @@
package com.muyu.car.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.car.domain.CarMessageType;
import com.muyu.car.domain.CarTemplate;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface SysCarMessageTypeMapper extends BaseMapper<CarMessageType> {
}

View File

@ -0,0 +1,17 @@
package com.muyu.car.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.car.domain.CarMessage;
import com.muyu.car.domain.CarTemplate;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface SysCarTemplateMapper extends BaseMapper<CarTemplate> {
/**
*
* @return
*/
List<CarTemplate> selectTemplateShow();
}

View File

@ -0,0 +1,15 @@
package com.muyu.car.mq.consumer;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
@Component //消费者
public class TextConsumer {
// @RabbitListener(bindings = @QueueBinding(value = @Queue("aaaa"),
// exchange = @Exchange(value = "aaaaa")))
// @RabbitListener(bindings = )
}

View File

@ -0,0 +1,19 @@
package com.muyu.car.mq.producer;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.AccessType;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
@Component // 生产者
public class TextProducer {
@Autowired
private RabbitTemplate rabbitTemplate;
@GetMapping("aaa")
public String aaa(){
rabbitTemplate.convertAndSend("aaaa","abc","jsijx");
return "ok";
}
}

View File

@ -0,0 +1,22 @@
package com.muyu.car.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.car.domain.CarMessage;
import java.util.List;
public interface SysCarMessageService extends IService<CarMessage> {
/**
*
* @param templateId
* @return
*/
List<CarMessage> selectMessageShow(Long templateId);
/**
* id
* @param messageId
* @return
*/
CarMessage selectMessageByMessageId(Long messageId);
}

View File

@ -0,0 +1,35 @@
package com.muyu.car.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.car.domain.CarMessageType;
import com.muyu.car.domain.CarTemplate;
import com.muyu.common.core.domain.Result;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface SysCarMessageTypeService extends IService<CarMessageType> {
/**
*
* @param carMessageType
*/
void insertMessageType(CarMessageType carMessageType);
// /**
// * 报文类型列表
// * @return
// */
// List<CarMessageType> messageTypeList();
/**
*
* @param carMessageType
*/
void updateMessageType(CarMessageType carMessageType);
/**
*
* @param ids
*/
void deleteMessageType(@Param("ids") List<Long> ids);
}

View File

@ -0,0 +1,22 @@
package com.muyu.car.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.car.domain.CarMessage;
import com.muyu.car.domain.CarTemplate;
import java.util.List;
public interface SysCarTemplateService extends IService<CarTemplate> {
/**
*
* @return
*/
List<CarTemplate> selectTemplateShow();
/**
* id
* @param messageId
* @return
*/
CarTemplate selectTemplateByTemplateId(Long messageId);
}

View File

@ -2,18 +2,12 @@ package com.muyu.car.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.car.domain.CarCompany;
import com.muyu.car.domain.dto.CarDTO;
import com.muyu.car.domain.vo.CarVO;
import com.muyu.car.mapper.SysCarCompanyMapper;
import com.muyu.car.mapper.SysCarMapper;
import com.muyu.car.service.SysCarCompanyService;
import com.muyu.car.service.SysCarService;
import com.muyu.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author zmw
* @description: plus

View File

@ -0,0 +1,36 @@
package com.muyu.car.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.car.domain.CarMessage;
import com.muyu.car.mapper.SysCarMessageMapper;
import com.muyu.car.service.SysCarMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SysCarMessageServiceImpl extends ServiceImpl<SysCarMessageMapper, CarMessage> implements SysCarMessageService {
@Autowired
private SysCarMessageMapper sysCarMessageMapper;
/**
*
* @param templateId
* @return
*/
@Override
public List<CarMessage> selectMessageShow(Long templateId) {
return sysCarMessageMapper.selectMessageShow(templateId);
}
/**
* id
* @param messageId
* @return
*/
@Override
public CarMessage selectMessageByMessageId(Long messageId) {
return sysCarMessageMapper.selectById(messageId);
}
}

View File

@ -0,0 +1,58 @@
package com.muyu.car.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.car.domain.CarMessageType;
import com.muyu.car.domain.CarTemplate;
import com.muyu.car.mapper.SysCarMessageTypeMapper;
import com.muyu.car.mapper.SysCarTemplateMapper;
import com.muyu.car.service.SysCarMessageTypeService;
import com.muyu.car.service.SysCarTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SysCarMessageTypeServiceImpl extends ServiceImpl<SysCarMessageTypeMapper, CarMessageType> implements SysCarMessageTypeService {
@Autowired
private SysCarMessageTypeMapper sysCarMessageTypeMapper;
/**
*
* @param carMessageType
*/
@Override
public void insertMessageType(CarMessageType carMessageType) {
sysCarMessageTypeMapper.insert(carMessageType);
}
// /**
// * 类型列表
// * @return
// */
// @Override
// public List<CarMessageType> messageTypeList() {
// return sysCarMessageTypeMapper.;
// }
/**
*
* @param carMessageType
*/
@Override
public void updateMessageType(CarMessageType carMessageType) {
sysCarMessageTypeMapper.updateById(carMessageType);
}
/**
*
* @param ids
*/
@Override
public void deleteMessageType(List<Long> ids) {
sysCarMessageTypeMapper.deleteBatchIds(ids);
}
}

View File

@ -1,5 +1,6 @@
package com.muyu.car.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.car.domain.CarCompany;
import com.muyu.car.domain.SysCar;

View File

@ -0,0 +1,38 @@
package com.muyu.car.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.car.domain.CarMessage;
import com.muyu.car.domain.CarTemplate;
import com.muyu.car.mapper.SysCarMessageMapper;
import com.muyu.car.mapper.SysCarTemplateMapper;
import com.muyu.car.service.SysCarMessageService;
import com.muyu.car.service.SysCarTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SysCarTemplateServiceImpl extends ServiceImpl<SysCarTemplateMapper, CarTemplate> implements SysCarTemplateService {
@Autowired
private SysCarTemplateMapper sysCarTemplateMapper;
/**
*
* @return
*/
@Override
public List<CarTemplate> selectTemplateShow() {
return sysCarTemplateMapper.selectTemplateShow();
}
/**
* id
* @param templateId
* @return
*/
@Override
public CarTemplate selectTemplateByTemplateId(Long templateId) {
return sysCarTemplateMapper.selectById(templateId);
}
}

View File

@ -0,0 +1,10 @@
package com.muyu.car.text;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;
@Component
public class CarText {
}

View File

@ -0,0 +1,60 @@
# Tomcat
server:
port: 10066
# nacos线上地址
nacos:
addr: 106.15.136.7:8848
user-name: nacos
password: nacos
namespace: zmw
# 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-car
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

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.car.mapper.SysCarMessageMapper">
<!-- 查询所有报文信息 -->
<!-- 查询所有报文信息 -->
<select id="selectMessageShow" resultType="com.muyu.car.domain.CarMessage">
SELECT
tcm.*
FROM
`t_car_message` tcm
WHERE
tcm.template_id = #{templateId}
</select>
</mapper>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.car.mapper.SysCarTemplateMapper">
<!-- 查询所有报文信息 -->
<select id="selectTemplateShow" resultType="com.muyu.car.domain.CarTemplate">
select * from `t_template`
</select>
</mapper>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.car.mapper.SysCarMessageTypeMapper">
<!-- 查询所有报文信息 -->
</mapper>

View File

@ -72,6 +72,12 @@
<groupId>com.muyu</groupId>
<artifactId>cloud-common-api-doc</artifactId>
</dependency>
<!-- SaaS-->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-saas</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -1,14 +1,21 @@
package com.muyu;
import com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
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;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@EnableCustomConfig
@EnableMyFeignClients
@SpringBootApplication
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
DruidDataSourceAutoConfigure.class,
DynamicDataSourceAutoConfiguration.class
})
public class CloudFaultApplication {
public static void main(String[] args) {
SpringApplication.run(CloudFaultApplication.class,args);

View File

@ -7,7 +7,7 @@ nacos:
addr: 106.15.136.7:8848
user-name: nacos
password: nacos
namespace: crj
namespace: xzr
spring:
application:

View File

@ -7,7 +7,7 @@ nacos:
addr: 106.15.136.7:8848
user-name: nacos
password: nacos
namespace: crj
namespace: xzr
# Spring
spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 106.15.136.7:8848
user-name: nacos
password: nacos
namespace: crj
namespace: xzr
# Spring
spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 106.15.136.7:8848
user-name: nacos
password: nacos
namespace: crj
namespace: xzr
spring:
amqp:

View File

@ -7,7 +7,7 @@ nacos:
addr: 106.15.136.7:8848
user-name: nacos
password: nacos
namespace: crj
namespace: xzr
# Spring
spring:

96
cloud-warn/pom.xml 100644
View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-server</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>cloud-warn</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- MuYu Common DataSource -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-datasource</artifactId>
</dependency>
<!-- MuYu Common DataScope -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-datascope</artifactId>
</dependency>
<!-- MuYu Common Log -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-log</artifactId>
</dependency>
<!-- 接口模块 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-api-doc</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,20 @@
package com.muyu;
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 muyu
*/
@EnableCustomConfig
//@EnableCustomSwagger2
@EnableMyFeignClients
@SpringBootApplication
public class CloudWarnApplication {
public static void main (String[] args) {
SpringApplication.run(CloudWarnApplication.class, args);
}
}

View File

@ -0,0 +1,39 @@
package com.muyu.warn.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.common.core.domain.Result;
import com.muyu.warn.domain.CarMessage;
import com.muyu.warn.service.CarMessageService;
import com.muyu.warn.service.CarTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @ClassName CarMessageController
* @Description
* @Author YiBo.Liu
* @Date 2024/9/22 22:28
*/
@RestController
@RequestMapping("/carMessage")
public class CarMessageController {
@Autowired
private CarMessageService carMessageService;
/**
* id
* @param templateId
* @return
*/
@GetMapping("/selectByTemplateId")
private Result<List<CarMessage>> selectByTemplateId(@RequestParam("templateId") Integer templateId) {
return Result.success(carMessageService.list
(new LambdaQueryWrapper<CarMessage>().eq(CarMessage::getTemplateId, templateId)));
}
}

View File

@ -0,0 +1,47 @@
package com.muyu.warn.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.common.core.domain.Result;
import com.muyu.warn.domain.CarType;
import com.muyu.warn.service.CarTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @ClassName CarController
* @Description Controller
* @Author YiBo.Liu
* @Date 2024/9/22 16:52
*/
@RestController
@RequestMapping("/carType")
public class CarTypeController {
@Autowired
private CarTypeService carTypeService;
/**
*
* @return carTypeList
*/
@GetMapping("/carTypeList")
private Result<List<CarType>> carTypeList() {
List<CarType> carTypeList = carTypeService.list();
return Result.success(carTypeList);
}
/**
* id
* @param catTypeId
* @return
*/
@PostMapping("/catTypeId")
private Result<CarType> catTypeId(@RequestParam("catTypeId") Integer catTypeId) {
CarType carType = carTypeService.findById(catTypeId);
return Result.success(carType);
}
}

View File

@ -0,0 +1,37 @@
package com.muyu.warn.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.common.core.domain.Result;
import com.muyu.warn.domain.Template;
import com.muyu.warn.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName Template
* @Description
* @Author YiBo.Liu
* @Date 2024/9/22 18:37
*/
@RestController
@RequestMapping("/template")
public class TemplateController {
@Autowired
private TemplateService templateService;
/**
* id
* @param templateId
* @return
*/
@GetMapping("/findByTemplateId")
private Result findByTemplateId(@RequestParam("templateId") Integer templateId) {
return Result.success(templateService.getOne(
new LambdaQueryWrapper<Template>().eq(Template::getTemplateId, templateId)));
}
}

View File

@ -0,0 +1,110 @@
package com.muyu.warn.controller;
import java.util.Arrays;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.warn.domain.WarnLogs;
import com.muyu.warn.service.IWarnLogsService;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.security.utils.SecurityUtils;
import org.springframework.validation.annotation.Validated;
import com.muyu.common.core.web.page.TableDataInfo;
/**
* Controller
*
* @author muyu
* @date 2024-09-20
*/
@RestController
@RequestMapping("/logs")
public class WarnLogsController extends BaseController
{
@Resource
private IWarnLogsService warnLogsService;
/**
*
*/
@RequiresPermissions("warn:logs:list")
@GetMapping("/list")
public Result<TableDataInfo<WarnLogs>> list(WarnLogs warnLogs)
{
startPage();
List<WarnLogs> list = warnLogsService.selectWarnLogsList(warnLogs);
return getDataTable(list);
}
/**
*
*/
@RequiresPermissions("warn:logs:export")
@PostMapping("/export")
public void export(HttpServletResponse response, WarnLogs warnLogs)
{
List<WarnLogs> list = warnLogsService.selectWarnLogsList(warnLogs);
ExcelUtil<WarnLogs> util = new ExcelUtil<WarnLogs>(WarnLogs.class);
util.exportExcel(response, list, "预警日志数据");
}
/**
*
*/
@RequiresPermissions("warn:logs:query")
@GetMapping(value = "/{id}")
public Result<List<WarnLogs>> getInfo(@PathVariable("id") Long id)
{
return success(warnLogsService.selectWarnLogsById(id));
}
/**
*
*/
@RequiresPermissions("warn:logs:add")
@PostMapping
public Result<Integer> add(
@Validated @RequestBody WarnLogs warnLogs)
{
if (warnLogsService.checkIdUnique(warnLogs)) {
return error("新增 预警日志 '" + warnLogs + "'失败,预警日志已存在");
}
return toAjax(warnLogsService.save(warnLogs));
}
/**
*
*/
@RequiresPermissions("warn:logs:edit")
@PutMapping
public Result<Integer> edit(
@Validated @RequestBody WarnLogs warnLogs)
{
if (!warnLogsService.checkIdUnique(warnLogs)) {
return error("修改 预警日志 '" + warnLogs + "'失败,预警日志不存在");
}
return toAjax(warnLogsService.updateById(warnLogs));
}
/**
*
*/
@RequiresPermissions("warn:logs:remove")
@DeleteMapping("/{ids}")
public Result<Integer> remove(@PathVariable("ids") Long[] ids)
{
warnLogsService.removeBatchByIds(Arrays.asList(ids));
return success();
}
}

View File

@ -0,0 +1,120 @@
package com.muyu.warn.controller;
import java.util.Arrays;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.servlet.http.HttpServletResponse;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.warn.domain.WarnRule;
import com.muyu.warn.service.IWarnRuleService;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.security.utils.SecurityUtils;
import org.springframework.validation.annotation.Validated;
import com.muyu.common.core.web.page.TableDataInfo;
/**
* Controller
*
* @author muyu
* @date 2024-09-20
*/
@RestController
@RequestMapping("/rule")
public class WarnRuleController extends BaseController
{
@Resource
private IWarnRuleService warnRuleService;
/**
*
*/
@RequiresPermissions("warn:rule:list")
@GetMapping("/list")
public Result<TableDataInfo<WarnRule>> list(WarnRule warnRule)
{
startPage();
List<WarnRule> list = warnRuleService.selectWarnRuleList(warnRule);
return getDataTable(list);
}
/**
*
*/
@RequiresPermissions("warn:rule:export")
@PostMapping("/export")
public void export(HttpServletResponse response, WarnRule warnRule)
{
List<WarnRule> list = warnRuleService.selectWarnRuleList(warnRule);
ExcelUtil<WarnRule> util = new ExcelUtil<WarnRule>(WarnRule.class);
util.exportExcel(response, list, "预警规则数据");
}
/**
*
*/
@RequiresPermissions("warn:rule:query")
@GetMapping(value = "/{id}")
public Result<List<WarnRule>> getInfo(@PathVariable("id") Long id)
{
return success(warnRuleService.selectWarnRuleById(id));
}
/**
*
*/
@RequiresPermissions("warn:rule:add")
@PostMapping
public Result<Integer> add(
@Validated @RequestBody WarnRule warnRule)
{
if (warnRuleService.checkIdUnique(warnRule)) {
return error("新增 预警规则 '" + warnRule + "'失败,预警规则已存在");
}
return toAjax(warnRuleService.save(warnRule));
}
/**
*
*/
@RequiresPermissions("warn:rule:edit")
@PutMapping
public Result<Integer> edit(
@Validated @RequestBody WarnRule warnRule)
{
if (!warnRuleService.checkIdUnique(warnRule)) {
return error("修改 预警规则 '" + warnRule + "'失败,预警规则不存在");
}
return toAjax(warnRuleService.updateById(warnRule));
}
/**
*
*/
@RequiresPermissions("warn:rule:remove")
@DeleteMapping("/{ids}")
public Result<Integer> remove(@PathVariable("ids") Long[] ids)
{
warnRuleService.removeBatchByIds(Arrays.asList(ids));
return success();
}
/**
* id
* @param strategyId
* @return
*/
@GetMapping("/selectByStrategyId")
public Result<List<WarnRule>> selectByStrategyId
(@RequestParam("strategyId") Long strategyId){
List<WarnRule> list = warnRuleService.list
(new LambdaQueryWrapper<WarnRule>().eq(WarnRule::getStrategyId, strategyId));
return success(list);
}
}

View File

@ -0,0 +1,123 @@
package com.muyu.warn.controller;
import java.util.Arrays;
import java.util.List;
import com.muyu.warn.domain.Resp.WarnStrategyList;
import jakarta.servlet.http.HttpServletResponse;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.warn.domain.WarnStrategy;
import com.muyu.warn.service.IWarnStrategyService;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.security.utils.SecurityUtils;
import org.springframework.validation.annotation.Validated;
import com.muyu.common.core.web.page.TableDataInfo;
/**
* Controller
*
* @author muyu
* @date 2024-09-20
*/
@RestController
@RequestMapping("/strategy")
public class WarnStrategyController extends BaseController
{
@Resource
private IWarnStrategyService warnStrategyService;
/**
*
*/
@RequiresPermissions("warn:strategy:list")
@GetMapping("/list")
public Result<TableDataInfo<WarnStrategy>> list(WarnStrategy warnStrategy)
{
startPage();
List<WarnStrategy> list = warnStrategyService.selectWarnStrategyList(warnStrategy);
return getDataTable(list);
}
/**
*
*/
@RequiresPermissions("warn:strategy:export")
@PostMapping("/export")
public void export(HttpServletResponse response, WarnStrategy warnStrategy)
{
List<WarnStrategy> list = warnStrategyService.selectWarnStrategyList(warnStrategy);
ExcelUtil<WarnStrategy> util = new ExcelUtil<WarnStrategy>(WarnStrategy.class);
util.exportExcel(response, list, "预警策略数据");
}
/**
*
*/
@RequiresPermissions("warn:strategy:query")
@GetMapping(value = "/{id}")
public Result<List<WarnStrategy>> getInfo(@PathVariable("id") Long id)
{
return success(warnStrategyService.selectWarnStrategyById(id));
}
/**
*
*/
@RequiresPermissions("warn:strategy:add")
@PostMapping
public Result<Integer> add(
@Validated @RequestBody WarnStrategy warnStrategy)
{
if (warnStrategyService.checkIdUnique(warnStrategy)) {
return error("新增 预警策略 '" + warnStrategy + "'失败,预警策略已存在");
}
return toAjax(warnStrategyService.save(warnStrategy));
}
/**
*
*/
@RequiresPermissions("warn:strategy:edit")
@PutMapping
public Result<Integer> edit(
@Validated @RequestBody WarnStrategy warnStrategy)
{
if (!warnStrategyService.checkIdUnique(warnStrategy)) {
return error("修改 预警策略 '" + warnStrategy + "'失败,预警策略不存在");
}
return toAjax(warnStrategyService.updateById(warnStrategy));
}
/**
*
*/
@RequiresPermissions("warn:strategy:remove")
@DeleteMapping("/{ids}")
public Result<Integer> remove(@PathVariable("ids") Long[] ids)
{
warnStrategyService.removeBatchByIds(Arrays.asList(ids));
return success();
}
/**
*
* @param warnStrategy
* @return
*/
@PostMapping("/strategyRuleList")
public Result<List<WarnStrategyList>> StrategyRuleList(@RequestBody WarnStrategy warnStrategy){
List<WarnStrategyList> list = warnStrategyService.strategyList(warnStrategy);
return Result.success(list);
}
}

View File

@ -0,0 +1,50 @@
package com.muyu.warn.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @ClassName CarMessage
* @Description
* @Author YiBo.Liu
* @Date 2024/9/22 22:24
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Tag(name = "报文表")
@TableName(value = "t_car_message")
public class CarMessage {
/**
*
*/
private Long messageId;
/**
*
*/
private String messageType;
/**
*
*/
private Integer messageStartIndex;
/**
*
*/
private Integer messageEndIndex;
/**
* id
*/
private Long templateId;
/**
*
*/
private String messageLabel;
}

View File

@ -0,0 +1,42 @@
package com.muyu.warn.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @ClassName CarType
* @Description
* @Author YiBo.Liu
* @Date 2024/9/22 16:53
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Tag(name = "车辆类型表")
@TableName(value = "t_car_type")
public class CarType {
/**
* id
*/
private Integer carTypeId;
/**
*
*/
private String carTypeName;
/**
* id
*/
private Integer templateId;
}

View File

@ -0,0 +1,60 @@
package com.muyu.warn.domain.Resp;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.muyu.common.core.annotation.Excel;
import com.muyu.warn.domain.WarnRule;
import com.muyu.warn.domain.WarnStrategy;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.function.Supplier;
/**
* @ClassName StrategyRuleList
* @Description
* @Author YiBo.Liu
* @Date 2024/9/22 15:07
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Tag(name = "策略规则一对多")
public class StrategyRuleList {
/** 策略id */
@TableId( type = IdType.AUTO)
private Long id;
/** 车辆类型id */
@Excel(name = "车辆类型id")
private Long carTypeId;
/** 策略名称 */
@Excel(name = "策略名称")
private String strategyName;
/** 报文模版id */
@Excel(name = "报文模版id")
private Long msgId;
private List<WarnRule> warnRuleList;
// private static StrategyRuleList strategyRuleList
// (WarnStrategy warnStrategy, Supplier<Long> supplierId) {
// return StrategyRuleList.builder()
// .id(warnStrategy.getId())
// .carTypeId(warnStrategy.getCarTypeId())
// .strategyName(warnStrategy.getStrategyName())
// .msgId(warnStrategy.getMsgId())
// .warnRuleList(supplierId)
// .build();
// }
}

View File

@ -0,0 +1,70 @@
package com.muyu.warn.domain.Resp;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.muyu.common.core.annotation.Excel;
import com.muyu.warn.domain.WarnRule;
import com.muyu.warn.domain.WarnStrategy;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @ClassName WarnStrategyList
* @Description
* @Author YiBo.Liu
* @Date 2024/9/21 18:45
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Tag(name = "策略规则双表联查")
public class WarnStrategyList {
/** 策略id */
private Long strategyId;
/** 车辆类型id */
private Long carTypeId;
/** 策略名称 */
private String strategyName;
/** 报文模版id */
private Long msgId;
/** 规则id */
private Long ruleId;
/** 规则名称 */
private String ruleName;
/** 报文数据类型id */
private Long msgTypeId;
/** 滑窗时间 */
private Long slideTime;
/** 滑窗频率 */
private Long slideFrequency;
/** 最大值 */
private Long maxValue;
/** 最小值 */
private Long minValue;
/** 报文数据名称 */
private String messageName;;
}

View File

@ -0,0 +1,40 @@
package com.muyu.warn.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @ClassName Template
* @Description
* @Author YiBo.Liu
* @Date 2024/9/22 16:54
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Tag(name = "模板表")
@TableName(value = "t_template")
public class Template {
/**
* id
*/
private Integer templateId;
/**
*
*/
private String templateName;
/**
*
*/
private String templateDescribe;
}

View File

@ -0,0 +1,91 @@
package com.muyu.warn.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
/**
* warn_logs
*
* @author muyu
* @date 2024-09-20
*/
@Data
@Setter
@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("warn_logs")
public class WarnLogs{
private static final long serialVersionUID = 1L;
/** 预警日志id */
@TableId( type = IdType.AUTO)
private Long id;
/** 车辆vin码 */
@Excel(name = "车辆vin码")
private String vin;
/** 规则id */
@Excel(name = "规则id")
private Long warnRuleId;
/** 开始时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date startTime;
/** 结束时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd")
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;
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("vin", getVin())
.append("warnRuleId", getWarnRuleId())
.append("startTime", getStartTime())
.append("endTime", getEndTime())
.append("maxValue", getMaxValue())
.append("minValue", getMinValue())
.append("avgValue", getAvgValue())
.append("medianValue", getMedianValue())
.append("status", getStatus())
.toString();
}
}

View File

@ -0,0 +1,77 @@
package com.muyu.warn.domain;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
/**
* warn_rule
*
* @author muyu
* @date 2024-09-20
*/
@Data
@Setter
@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("warn_rule")
public class WarnRule{
private static final long serialVersionUID = 1L;
/** 规则id */
@TableId( type = IdType.AUTO)
private Long id;
/** 规则名称 */
@Excel(name = "规则名称")
private String ruleName;
/** 策略id */
@Excel(name = "策略id")
private Long strategyId;
/** 报文数据类型id */
@Excel(name = "报文数据类型id")
private Long msgTypeId;
/** 滑窗时间 */
@Excel(name = "滑窗时间")
private Long slideTime;
/** 滑窗频率 */
@Excel(name = "滑窗频率")
private Long slideFrequency;
/** 最大值 */
@Excel(name = "最大值")
private Long maxValue;
/** 最小值 */
@Excel(name = "最小值")
private Long minValue;
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("ruleName", getRuleName())
.append("strategyId", getStrategyId())
.append("msgTypeId", getMsgTypeId())
.append("slideTime", getSlideTime())
.append("slideFrequency", getSlideFrequency())
.append("maxValue", getMaxValue())
.append("minValue", getMinValue())
.toString();
}
}

View File

@ -0,0 +1,57 @@
package com.muyu.warn.domain;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
/**
* warn_strategy
*
* @author muyu
* @date 2024-09-20
*/
@Data
@Setter
@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("warn_strategy")
public class WarnStrategy{
private static final long serialVersionUID = 1L;
/** 策略id */
@TableId( type = IdType.AUTO)
private Long id;
/** 车辆类型id */
@Excel(name = "车辆类型id")
private Long carTypeId;
/** 策略名称 */
@Excel(name = "策略名称")
private String strategyName;
/** 报文模版id */
@Excel(name = "报文模版id")
private Long templateId;
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("carTypeId", getCarTypeId())
.append("strategyName", getStrategyName())
.append("msgId", getTemplateId())
.toString();
}
}

View File

@ -0,0 +1,9 @@
package com.muyu.warn.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.warn.domain.CarMessage;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface CarMessageMapper extends BaseMapper<CarMessage> {
}

View File

@ -0,0 +1,12 @@
package com.muyu.warn.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.warn.domain.CarType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface CarTypeMapper extends BaseMapper<CarType> {
CarType findById(@Param("catTypeId") Integer catTypeId);
}

View File

@ -0,0 +1,9 @@
package com.muyu.warn.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.warn.domain.Template;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TemplateMapper extends BaseMapper<Template> {
}

View File

@ -0,0 +1,16 @@
package com.muyu.warn.mapper;
import com.muyu.warn.domain.WarnLogs;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* Mapper
*
* @author muyu
* @date 2024-09-20
*/
@Mapper
public interface WarnLogsMapper extends BaseMapper<WarnLogs>{
}

View File

@ -0,0 +1,16 @@
package com.muyu.warn.mapper;
import com.muyu.warn.domain.WarnRule;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* Mapper
*
* @author muyu
* @date 2024-09-20
*/
@Mapper
public interface WarnRuleMapper extends BaseMapper<WarnRule>{
}

View File

@ -0,0 +1,20 @@
package com.muyu.warn.mapper;
import com.muyu.warn.domain.Resp.WarnStrategyList;
import com.muyu.warn.domain.WarnStrategy;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* Mapper
*
* @author muyu
* @date 2024-09-20
*/
@Mapper
public interface WarnStrategyMapper extends BaseMapper<WarnStrategy>{
List<WarnStrategyList> strategyList(WarnStrategy warnStrategy);
}

View File

@ -0,0 +1,7 @@
package com.muyu.warn.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.warn.domain.CarMessage;
public interface CarMessageService extends IService<CarMessage> {
}

View File

@ -0,0 +1,9 @@
package com.muyu.warn.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.warn.domain.CarType;
public interface CarTypeService extends IService<CarType> {
CarType findById(Integer catTypeId);
}

View File

@ -0,0 +1,37 @@
package com.muyu.warn.service;
import java.util.List;
import com.muyu.warn.domain.WarnLogs;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* Service
*
* @author muyu
* @date 2024-09-20
*/
public interface IWarnLogsService extends IService<WarnLogs> {
/**
*
*
* @param id
* @return
*/
public WarnLogs selectWarnLogsById(Long id);
/**
*
*
* @param warnLogs
* @return
*/
public List<WarnLogs> selectWarnLogsList(WarnLogs warnLogs);
/**
* id
* @param warnLogs
* @return
*/
Boolean checkIdUnique(WarnLogs warnLogs);
}

View File

@ -0,0 +1,39 @@
package com.muyu.warn.service;
import java.util.List;
import com.muyu.warn.domain.WarnRule;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* Service
*
* @author muyu
* @date 2024-09-20
*/
public interface IWarnRuleService extends IService<WarnRule> {
/**
*
*
* @param id
* @return
*/
public WarnRule selectWarnRuleById(Long id);
/**
*
*
* @param warnRule
* @return
*/
public List<WarnRule> selectWarnRuleList(WarnRule warnRule);
/**
* id
* @param warnRule
* @return
*/
Boolean checkIdUnique(WarnRule warnRule);
}

View File

@ -0,0 +1,42 @@
package com.muyu.warn.service;
import java.util.List;
import com.muyu.warn.domain.Resp.WarnStrategyList;
import com.muyu.warn.domain.WarnStrategy;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* Service
*
* @author muyu
* @date 2024-09-20
*/
public interface IWarnStrategyService extends IService<WarnStrategy> {
/**
*
*
* @param id
* @return
*/
public WarnStrategy selectWarnStrategyById(Long id);
/**
*
*
* @param warnStrategy
* @return
*/
public List<WarnStrategy> selectWarnStrategyList(WarnStrategy warnStrategy);
/**
* id
* @param warnStrategy
* @return
*/
Boolean checkIdUnique(WarnStrategy warnStrategy);
List<WarnStrategyList> strategyList(WarnStrategy warnStrategy);
}

View File

@ -0,0 +1,7 @@
package com.muyu.warn.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.warn.domain.Template;
public interface TemplateService extends IService<Template> {
}

View File

@ -0,0 +1,24 @@
package com.muyu.warn.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.warn.domain.CarMessage;
import com.muyu.warn.mapper.CarMessageMapper;
import com.muyu.warn.service.CarMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @ClassName CarMessageServiceImpl
* @Description
* @Author YiBo.Liu
* @Date 2024/9/22 22:29
*/
@Service
public class CarMessageServiceImpl
extends ServiceImpl<CarMessageMapper, CarMessage>
implements CarMessageService {
@Autowired
private CarMessageMapper carMessageMapper;
}

View File

@ -0,0 +1,29 @@
package com.muyu.warn.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.warn.domain.CarType;
import com.muyu.warn.mapper.CarTypeMapper;
import com.muyu.warn.service.CarTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @ClassName CarServiceImpl
* @Description
* @Author YiBo.Liu
* @Date 2024/9/22 16:52
*/
@Service
public class CarTypeTypeServiceImpl
extends ServiceImpl<CarTypeMapper, CarType>
implements CarTypeService {
@Autowired
private CarTypeMapper carTypeMapper;
@Override
public CarType findById(Integer catTypeId) {
CarType carType= carTypeMapper.findById(catTypeId);
return carType;
}
}

View File

@ -0,0 +1,24 @@
package com.muyu.warn.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.warn.domain.Template;
import com.muyu.warn.mapper.TemplateMapper;
import com.muyu.warn.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @ClassName TemplateServiceImpl
* @Description
* @Author YiBo.Liu
* @Date 2024/9/22 18:38
*/
@Service
public class TemplateServiceImpl
extends ServiceImpl<TemplateMapper, Template>
implements TemplateService {
@Autowired
private TemplateMapper templateMapper;
}

View File

@ -0,0 +1,92 @@
package com.muyu.warn.service.impl;
import java.util.List;
import org.springframework.stereotype.Service;
import com.muyu.warn.mapper.WarnLogsMapper;
import com.muyu.warn.domain.WarnLogs;
import com.muyu.warn.service.IWarnLogsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import org.springframework.util.Assert;
/**
* Service
*
* @author muyu
* @date 2024-09-20
*/
@Service
public class WarnLogsServiceImpl
extends ServiceImpl<WarnLogsMapper, WarnLogs>
implements IWarnLogsService {
/**
*
*
* @param id
* @return
*/
@Override
public WarnLogs selectWarnLogsById(Long id)
{
LambdaQueryWrapper<WarnLogs> queryWrapper = new LambdaQueryWrapper<>();
Assert.notNull(id, "id不可为空");
queryWrapper.eq(WarnLogs::getId, id);
return this.getOne(queryWrapper);
}
/**
*
*
* @param warnLogs
* @return
*/
@Override
public List<WarnLogs> selectWarnLogsList(WarnLogs warnLogs)
{
LambdaQueryWrapper<WarnLogs> 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<WarnLogs> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(WarnLogs::getId, warnLogs.getId());
return this.count(queryWrapper) > 0;
}
}

View File

@ -0,0 +1,88 @@
package com.muyu.warn.service.impl;
import java.util.List;
import org.springframework.stereotype.Service;
import com.muyu.warn.mapper.WarnRuleMapper;
import com.muyu.warn.domain.WarnRule;
import com.muyu.warn.service.IWarnRuleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import org.springframework.util.Assert;
/**
* Service
*
* @author muyu
* @date 2024-09-20
*/
@Service
public class WarnRuleServiceImpl
extends ServiceImpl<WarnRuleMapper, WarnRule>
implements IWarnRuleService {
/**
*
*
* @param id
* @return
*/
@Override
public WarnRule selectWarnRuleById(Long id)
{
LambdaQueryWrapper<WarnRule> queryWrapper = new LambdaQueryWrapper<>();
Assert.notNull(id, "id不可为空");
queryWrapper.eq(WarnRule::getId, id);
return this.getOne(queryWrapper);
}
/**
*
*
* @param warnRule
* @return
*/
@Override
public List<WarnRule> selectWarnRuleList(WarnRule warnRule)
{
LambdaQueryWrapper<WarnRule> queryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotNull(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<WarnRule> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(WarnRule::getId, warnRule.getId());
return this.count(queryWrapper) > 0;
}
}

View File

@ -0,0 +1,88 @@
package com.muyu.warn.service.impl;
import java.util.List;
import com.muyu.common.core.domain.Result;
import com.muyu.warn.domain.Resp.WarnStrategyList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.stereotype.Service;
import com.muyu.warn.mapper.WarnStrategyMapper;
import com.muyu.warn.domain.WarnStrategy;
import com.muyu.warn.service.IWarnStrategyService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import org.springframework.util.Assert;
/**
* Service
*
* @author muyu
* @date 2024-09-20
*/
@Service
public class WarnStrategyServiceImpl
extends ServiceImpl<WarnStrategyMapper, WarnStrategy>
implements IWarnStrategyService {
@Autowired
private WarnStrategyMapper warnStrategyMapper;
/**
*
*
* @param id
* @return
*/
@Override
public WarnStrategy selectWarnStrategyById(Long id)
{
LambdaQueryWrapper<WarnStrategy> queryWrapper = new LambdaQueryWrapper<>();
Assert.notNull(id, "id不可为空");
queryWrapper.eq(WarnStrategy::getId, id);
return this.getOne(queryWrapper);
}
/**
*
*
* @param warnStrategy
* @return
*/
@Override
public List<WarnStrategy> selectWarnStrategyList(WarnStrategy warnStrategy)
{
LambdaQueryWrapper<WarnStrategy> queryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotNull(warnStrategy.getCarTypeId())){
queryWrapper.eq(WarnStrategy::getCarTypeId, warnStrategy.getCarTypeId());
}
if (StringUtils.isNotNull(warnStrategy.getStrategyName())){
queryWrapper.like(WarnStrategy::getStrategyName, warnStrategy.getStrategyName());
}
if (StringUtils.isNotNull(warnStrategy.getTemplateId())){
queryWrapper.eq(WarnStrategy::getTemplateId, warnStrategy.getTemplateId());
}
return this.list(queryWrapper);
}
/**
*
* @param warnStrategy
* @return
*/
@Override
public Boolean checkIdUnique(WarnStrategy warnStrategy) {
LambdaQueryWrapper<WarnStrategy> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(WarnStrategy::getId, warnStrategy.getId());
return this.count(queryWrapper) > 0;
}
@Override
public List<WarnStrategyList> strategyList(WarnStrategy warnStrategy) {
return warnStrategyMapper.strategyList(warnStrategy);
}
}

View File

@ -0,0 +1,49 @@
# Tomcat
server:
port: 9710
# nacos线上地址
nacos:
addr: 106.15.136.7:8848
user-name: nacos
password: nacos
namespace: lyb
spring:
application:
# 应用名称
name: cloud-warn
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: ${nacos.addr}
# nacos用户名89
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}
logging:
level:
com.muyu.system.mapper: DEBUG

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.warn.mapper.CarTypeMapper">
<select id="findById" resultType="com.muyu.warn.domain.CarType">
select * from t_car_type where t_car_type.car_type_id = #{catTypeId}
</select>
</mapper>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.warn.mapper.WarnStrategyMapper">
<select id="strategyList" resultType="com.muyu.warn.domain.Resp.WarnStrategyList">
SELECT
s.id AS strategy_id,
s.msg_id,
s.car_type_id,
s.strategy_name,
r.id AS rule_id,
r.max_value,
r.min_value,
r.msg_type_id,
r.rule_name,
r.slide_frequency,
r.slide_time,
r.strategy_id,
t_message_type.message_name
FROM
warn_strategy s
LEFT JOIN warn_rule r ON s.id = r.strategy_id
LEFT JOIN t_message_type on r.msg_type_id = t_message_type.message_type_id
</select>
</mapper>

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-server</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>cloud-weixin-mp</artifactId>
<version>3.6.3</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- SpringBoot Web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.20</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.43</version>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-core</artifactId>
<version>3.6.3</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,17 @@
package com.muyu;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
*@ClassName SpringBoot
*@Description
*@Author YiBo.Liu
*@Date 2024/9/17 17:01
*/
@SpringBootApplication
public class SpringBoot {
public static void main(String[] args) {
SpringApplication.run(SpringBoot.class, args);
}
}

View File

@ -0,0 +1,27 @@
package com.muyu.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @ClassName TextMessage
* @Description
* @Author YiBo.Liu
* @Date 2024/9/17 21:06
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@XStreamAlias("item")
public class Article {
@XStreamAlias("Title")
private String title;
@XStreamAlias("Description")
private String description;
@XStreamAlias("PicUrl")
private String picUrl;
@XStreamAlias("Url")
private String url;
}

View File

@ -0,0 +1,34 @@
package com.muyu.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @ClassName TextMessage
* @Description
* @Author YiBo.Liu
* @Date 2024/9/17 21:06
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@XStreamAlias("xml")
public class NewMessage {
@XStreamAlias("ToUserName")
private String toUserName;
@XStreamAlias("FromUserName")
private String fromUserName;
@XStreamAlias("CreateTime")
private long createTime;
@XStreamAlias("MsgType")
private String msgType;
@XStreamAlias("ArticleCount")
private int articleCount;
@XStreamAlias("Articles")
private List<Article> articles;
}

View File

@ -0,0 +1,51 @@
package com.muyu.message;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @ClassName TextMessage
* @Description
* @Author YiBo.Liu
* @Date 2024/9/17 21:06
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@XStreamAlias("xml")
public class TextMessage {
/**
*
*/
@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;
}

View File

@ -0,0 +1,30 @@
package com.muyu.token;
import lombok.Data;
/**
* @ClassName AccessToken
* @Description
* @Author YiBo.Liu
* @Date 2024/9/18 15:48
*/
@Data
public class AccessToken {
private String access_token;
private long expires_in;
public void setExpiresTime(long expiresIn) {
this.expires_in = System.currentTimeMillis()+expiresIn*1000;
}
/**
*
* @return
*/
public boolean isExpired() {
return System.currentTimeMillis()>this.expires_in;
}
}

View File

@ -0,0 +1,36 @@
package com.muyu.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(MediaType.parse("application/json; charset=utf-8"), params);
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;
}
}
}

View File

@ -0,0 +1,41 @@
package com.muyu.util;
import com.alibaba.fastjson2.JSON;
import com.muyu.token.AccessToken;
import org.springframework.stereotype.Component;
/**
* @ClassName AccessToken
* @Description
* @Author YiBo.Liu
* @Date 2024/9/18 15:48
*/
@Component
public class TokenUtil {
private final static String APP_ID = "wx74741af76decd078";
private final static String APP_SECRET ="540af183133e701051b726f936ebbfe9";
private static AccessToken accessToken = new AccessToken();
public 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);
AccessToken wechatToken = JSON.parseObject(request, AccessToken.class);
if (wechatToken != null) {
accessToken.setExpiresTime(wechatToken.getExpires_in());
accessToken.setAccess_token(wechatToken.getAccess_token());
}
}
/**
* AccessToken
* @return
*/
public static String getAccessToken(){
getToken();
return accessToken.getAccess_token();
}
}

View File

@ -0,0 +1,39 @@
package com.muyu.util;
import okhttp3.*;
import java.io.IOException;
public class WechatUtil {
public static void send(String toUser,String content) {
String accessToken = TokenUtil.getAccessToken();
if (!accessToken.equals("")) {
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + accessToken;
String jsonStr = "{\"touser\":\"" + toUser + "\",\"msgtype\":\"text\",\"text\":{\"content\":\"" + content + "\"}}";
OkHttpClient client = new OkHttpClient();
// 构建请求
RequestBody requestBody = RequestBody.create(jsonStr, MediaType.get("application/json; charset=utf-8"));
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.addHeader("Content-Type", "application/json; charset=utf-8")
.build();
// 发送请求
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
// 输出响应
System.out.println(response.body().string());
}catch (IOException e) {
e.printStackTrace();
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More