Merge branch 'dev' of https://gitea.qinmian.online/group-four/cloud-car into dev
commit
b26bb59183
|
@ -7,6 +7,7 @@ import com.muyu.auth.form.RegisterBody;
|
|||
import com.muyu.auth.service.SysFirmService;
|
||||
import com.muyu.auth.service.SysLoginService;
|
||||
import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
|
||||
import com.muyu.common.core.constant.SecurityConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.JwtUtils;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
|
@ -14,6 +15,8 @@ import com.muyu.common.security.auth.AuthUtil;
|
|||
import com.muyu.common.security.service.TokenService;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
@ -32,6 +35,7 @@ import java.sql.Connection;
|
|||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* token 控制
|
||||
|
@ -51,6 +55,9 @@ public class TokenController {
|
|||
@Autowired
|
||||
private SysFirmService sysFirmService;
|
||||
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@PostMapping("login")
|
||||
@Operation(summary = "登录", description = "登录")
|
||||
public Result<?> login (@RequestBody LoginBody form) {
|
||||
|
@ -120,6 +127,13 @@ public class TokenController {
|
|||
} else {
|
||||
log.warn("数据库 {} 创建成功", settlement.getDatabaseName());
|
||||
|
||||
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setCreateTime(new Date());
|
||||
sysUser.setUserName(settlement.getFirmName());
|
||||
sysUser.setDatabaseName(settlement.getDatabaseName());
|
||||
remoteUserService.addUser(sysUser, SecurityConstants.INNER);
|
||||
|
||||
// 切换到新的数据库连接
|
||||
Connection connection = null;
|
||||
try {
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: yzl
|
||||
namespace: four
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
|
|
|
@ -36,7 +36,7 @@ public class RabbitMQConsumerUtil {
|
|||
* @param message
|
||||
* @param channel
|
||||
*/
|
||||
@RabbitListener(queuesToDeclare = @Queue(name = "basic"))
|
||||
// @RabbitListener(queuesToDeclare = @Queue(name = "basic"))
|
||||
public void rabbitMQBasicConsumer(String data ,Message message , Channel channel) {
|
||||
log.info("当前时间:{} :RabbitMQConsumerUtil : {}", new Date(), message);
|
||||
try {
|
||||
|
|
|
@ -33,9 +33,10 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -1,36 +1,32 @@
|
|||
package com.muyu.cloud.common.many.datasource;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
||||
import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
|
||||
import com.muyu.cloud.common.many.datasource.domain.model.DataSourceInfo;
|
||||
import com.muyu.cloud.common.many.datasource.factory.DruidDataSourceFactory;
|
||||
import com.muyu.cloud.common.many.datasource.init.InitDataSource;
|
||||
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
|
||||
import com.muyu.cloud.common.saas.domain.Datasource;
|
||||
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.system.domain.Datasource;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteSaaSService;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 多数据源
|
||||
* @author liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: 多数据源
|
||||
* @Version: 1.0
|
||||
|
@ -39,9 +35,14 @@ import java.util.Map;
|
|||
@Component
|
||||
@AutoConfiguration(before = {MybatisPlusAutoConfiguration.class, MybatisAutoConfiguration.class})
|
||||
public class ManyDataSource implements ApplicationRunner{
|
||||
|
||||
@Autowired
|
||||
private InitDataSource initDataSource;
|
||||
|
||||
|
||||
private List<EntInfo> dataSourceInfoList(){
|
||||
RemoteSaaSService remoteSaaSService = SpringUtils.getBean(RemoteSaaSService.class);
|
||||
Result<List<Datasource>> tableDataInfoResult = remoteSaaSService.findDatabaseList();
|
||||
Result<List<Datasource>> tableDataInfoResult = initDataSource.initDatasource();
|
||||
if (tableDataInfoResult==null){
|
||||
throw new SaaSException("saas远调数据源错误");
|
||||
}
|
||||
|
@ -63,7 +64,6 @@ public class ManyDataSource implements ApplicationRunner{
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// private List<EntInfo> dataPrimarySourceInfoList(){
|
||||
// List<EntInfo> list = new ArrayList<>();
|
||||
// list.add(
|
||||
|
@ -75,7 +75,6 @@ public class ManyDataSource implements ApplicationRunner{
|
|||
// );
|
||||
// return list;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
||||
// 企业列表 企业CODE,端口,IP
|
||||
|
@ -94,7 +93,6 @@ public class ManyDataSource implements ApplicationRunner{
|
|||
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
|
||||
return dynamicDataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package com.muyu.cloud.common.many.datasource.constents;
|
||||
|
||||
/**
|
||||
* 数据源常量
|
||||
* @author liuwu
|
||||
* @author DongZl
|
||||
* @description: 数据源常量
|
||||
* @Date 2023-8-1 上午 11:02
|
||||
*/
|
||||
|
@ -17,8 +16,4 @@ public class DatasourceContent {
|
|||
public final static String IP = "47.101.53.251";
|
||||
|
||||
public final static Integer PORT = 3306;
|
||||
|
||||
public static String getDatasourceUrl(String databaseName) {
|
||||
return String.format(DATASOURCE_URL,USER_NAME,PASSWORD,IP,PORT, databaseName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,7 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 数据源实体类
|
||||
* @author liuwu
|
||||
* @author DongZl
|
||||
* @description: 数据源实体类
|
||||
* @Date 2023-8-1 上午 11:15
|
||||
*/
|
||||
|
|
|
@ -8,8 +8,7 @@ import org.springframework.stereotype.Component;
|
|||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Druid工厂
|
||||
* @author liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: Druid工厂
|
||||
* @Version: 1.0
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.springframework.util.Assert;
|
|||
/**
|
||||
* 数据源切换处理
|
||||
*
|
||||
* @author liuwu
|
||||
* @author Dongzl
|
||||
*/
|
||||
@Slf4j
|
||||
public class DynamicDataSourceHolder {
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.muyu.cloud.common.many.datasource.init;
|
||||
|
||||
|
||||
import com.muyu.cloud.common.saas.domain.Datasource;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class InitDataSource {
|
||||
|
||||
public static final String USER="root";
|
||||
public static final String PASSWORD="Lw030106";
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public Result<List<Datasource>> initDatasource(){
|
||||
ArrayList<Datasource> list = new ArrayList<>();
|
||||
|
||||
try {
|
||||
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
|
||||
Connection connection= DriverManager.getConnection("jdbc:mysql://47.101.53.251:3306/datasource?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&useSSL=false",USER,PASSWORD);
|
||||
String sql="select * from `datasource` ";
|
||||
|
||||
Statement stmt = connection.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
|
||||
while (rs.next()){
|
||||
Datasource datasource = new Datasource();
|
||||
datasource.setId(rs.getInt("id"));
|
||||
datasource.setFirmName(rs.getString("firm_name"));
|
||||
datasource.setDatabaseName(rs.getString("database_name"));
|
||||
list.add(datasource);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return Result.success(list);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
package com.muyu.cloud.common.saas.contents;
|
||||
|
||||
/**
|
||||
* SAAS常量
|
||||
* @author liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: SAAS常量
|
||||
* @Version: 1.0
|
||||
|
|
|
@ -6,7 +6,7 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: 企业信息
|
||||
* @Version: 1.0
|
||||
|
|
|
@ -4,8 +4,7 @@ package com.muyu.cloud.common.saas.exception;
|
|||
import com.muyu.common.core.exception.ServiceException;
|
||||
|
||||
/**
|
||||
* SaaS异常类
|
||||
* @author liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: SaaS异常类
|
||||
* @Version: 1.0
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package com.muyu.cloud.common.saas.interceptor;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cloud.common.saas.contents.SaaSConstant;
|
||||
import com.muyu.cloud.common.many.datasource.holder.DynamicDataSourceHolder;
|
||||
import com.muyu.cloud.common.saas.exception.SaaSException;
|
||||
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
|
||||
import com.muyu.cloud.common.saas.contents.SaaSConstant;
|
||||
import com.muyu.cloud.common.saas.exception.SaaSException;
|
||||
import com.muyu.common.core.utils.ServletUtils;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
@ -14,8 +13,7 @@ import org.springframework.web.servlet.AsyncHandlerInterceptor;
|
|||
|
||||
|
||||
/**
|
||||
* SAAS拦截器
|
||||
* @author liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: SAAS拦截器
|
||||
* @Version: 1.0
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
com.muyu.cloud.common.saas.interceptor.WebMvcSaaSConfig
|
||||
com.muyu.cloud.common.many.datasource.ManyDataSource
|
||||
com.muyu.cloud.common.many.datasource.factory.DruidDataSourceFactory
|
||||
com.muyu.cloud.common.many.datasource.init.InitDataSource
|
|
@ -8,6 +8,7 @@ import com.muyu.common.system.domain.SysUser;
|
|||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -52,4 +53,12 @@ public interface RemoteUserService {
|
|||
*/
|
||||
@PostMapping("/user/enterprise")
|
||||
Result<Boolean>settlementEnterpriseInfo(@RequestBody Business enterprise, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 用户添加
|
||||
* @param sysUser
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/user/addUser")
|
||||
public Result<Integer> addUser(@RequestBody SysUser sysUser,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);
|
||||
}
|
||||
|
|
|
@ -45,6 +45,12 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
return Result.error("入驻企业失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Integer> addUser(SysUser sysUser, String source) {
|
||||
return Result.error("用户添加失败");
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,6 +114,18 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu.common</groupId>
|
||||
<artifactId>saas-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>saas-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
|
|
|
@ -55,7 +55,6 @@ public class MqConsumer {
|
|||
/**
|
||||
* -----------------------------------以下为异步业务操作----------------------------
|
||||
*/
|
||||
List<SysCarVo> carList = sysCarCacheService.get("carList");
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,6 +29,9 @@ public class AddDatabaseListener implements EventListener {
|
|||
values.add((String) value);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.event.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
/**
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.event.service
|
||||
* @name:IncidentService
|
||||
* @Date:2024/10/9 15:02
|
||||
*/
|
||||
public interface IncidentService {
|
||||
|
||||
void warnEventProcess(JSONObject jsonObject) throws Exception;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
package com.muyu.event.service.impl;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cache.MessageTemplateTypeCacheService;
|
||||
import com.muyu.cache.SysCarCacheService;
|
||||
import com.muyu.cache.WarnRuleCacheService;
|
||||
import com.muyu.cache.WarnStrategyCacheService;
|
||||
import com.muyu.common.domain.MessageTemplateType;
|
||||
import com.muyu.common.domain.SysCar;
|
||||
import com.muyu.common.domain.resp.SysCarVo;
|
||||
import com.muyu.common.domain.resp.WarnRuleResp;
|
||||
import com.muyu.common.domain.resp.WarnStrategyResp;
|
||||
import com.muyu.event.consumer.MessageConsumer;
|
||||
import com.muyu.event.service.IncidentService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
/**
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.event.service.impl
|
||||
* @name:IncidentServiceImpl
|
||||
* @Date:2024/10/9 15:02
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class IncidentServiceImpl implements IncidentService {
|
||||
private static int DURATION_SECONDS = 5;
|
||||
private static List<JSONObject> receivedStrings = new ArrayList<>();
|
||||
private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static int elapsedSeconds = 0;
|
||||
private static String file="elapsed";
|
||||
private static List<MessageTemplateType> messageTemplateTypes=null;
|
||||
private static Long msgTypeId=null;
|
||||
//滑窗时间
|
||||
private static Long slideTime=null;
|
||||
//增长率
|
||||
private static Long slideFrequency=null;
|
||||
//预警策略
|
||||
@Resource
|
||||
private WarnStrategyCacheService warnStrategyCacheService;
|
||||
//车辆
|
||||
@Resource
|
||||
private SysCarCacheService sysCarCacheService;
|
||||
//预警规则
|
||||
@Resource
|
||||
private WarnRuleCacheService warnRuleCacheService;
|
||||
//报文模版
|
||||
@Resource
|
||||
private MessageTemplateTypeCacheService messageTemplateTypeCacheService;
|
||||
|
||||
private final String topic="four_car";
|
||||
|
||||
@Autowired
|
||||
private MessageConsumer messageConsumer;
|
||||
|
||||
@Autowired
|
||||
public KafkaConsumer consumer;
|
||||
|
||||
@Override
|
||||
public void warnEventProcess(JSONObject jsonObject) throws Exception {
|
||||
|
||||
receivedStrings.add(jsonObject);
|
||||
//协议解析:每秒穿过来一个JSONObject jsonObject; 添加进receivedStrings
|
||||
//根据这个车辆VIN查询出他对应的车辆类型
|
||||
String carVin=null;
|
||||
//报文模版的ID
|
||||
Integer templateId=null;
|
||||
for (JSONObject receivedString : receivedStrings) {
|
||||
carVin = (String) receivedString.get("carVin");
|
||||
}
|
||||
SysCar carByVin = null;
|
||||
List<SysCarVo> carVoList = sysCarCacheService.get(sysCarCacheService.keyPre());
|
||||
Map<String, SysCarVo> carMap = carVoList.stream()
|
||||
.collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity()));
|
||||
//获取到了这个车辆的信息
|
||||
carByVin = carMap.get(carVin);
|
||||
//获取到这辆车绑定的报文模版
|
||||
templateId=carByVin.getTemplateId();
|
||||
//这个是这辆车对应的所有策略
|
||||
List<WarnStrategyResp> carWithWarnStrategyList=null;
|
||||
List<WarnStrategyResp> warnStrategyResps = warnStrategyCacheService.get(warnStrategyCacheService.keyPre());
|
||||
for (WarnStrategyResp warnStrategyResp : warnStrategyResps) {
|
||||
if(warnStrategyResp.getCarTypeId()==carByVin.getCarTypeId()){
|
||||
carWithWarnStrategyList.add(warnStrategyResp);
|
||||
}
|
||||
}
|
||||
//该车对应的所有预警规则
|
||||
List<WarnRuleResp> warnRuleResp=null;
|
||||
List<WarnRuleResp> warnRuleResps = warnRuleCacheService.get(warnRuleCacheService.keyPre());
|
||||
for (WarnStrategyResp warnStrategyResp : carWithWarnStrategyList) {
|
||||
for (WarnRuleResp ruleResp : warnRuleResps) {
|
||||
if(warnStrategyResp.getId().equals(ruleResp.getStrategyId())){
|
||||
warnRuleResp.add(ruleResp);
|
||||
}
|
||||
}
|
||||
}
|
||||
//报文模版
|
||||
messageTemplateTypes = messageTemplateTypeCacheService.get(messageTemplateTypeCacheService.keyPre());
|
||||
for (WarnRuleResp ruleResp : warnRuleResp) {
|
||||
//每一个规则他绑定了报文模版里面对应的一个配置 比如:电池,或者车速
|
||||
msgTypeId = ruleResp.getMsgTypeId();
|
||||
//将规则中对应的滑窗时间赋值为DURATION_SECONDS
|
||||
DURATION_SECONDS = Math.toIntExact(ruleResp.getSlideTime());
|
||||
slideFrequency = ruleResp.getSlideFrequency();
|
||||
}
|
||||
// 定义一个任务,每秒执行一次
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 清理超过的数据
|
||||
cleanUpOldStrings();
|
||||
// 检查超速条件
|
||||
checkForSpeeding();
|
||||
}
|
||||
};
|
||||
// 每隔1秒执行一次任务
|
||||
scheduler.scheduleAtFixedRate(task, 0, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
// 清理超过60秒的数据
|
||||
private static void cleanUpOldStrings() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
receivedStrings.removeIf(jsonObject ->
|
||||
currentTime - jsonObject.getLong("time") > TimeUnit.SECONDS.toMillis(DURATION_SECONDS)
|
||||
);
|
||||
}
|
||||
// 检查是否有超速情况
|
||||
private static void checkForSpeeding() {
|
||||
if (receivedStrings.size() < 2) return; // 如果数据不足,直接返回
|
||||
for (int i = 0; i < receivedStrings.size(); i++) {
|
||||
JSONObject current = receivedStrings.get(i);
|
||||
JSONObject next = receivedStrings.get(i + 1);
|
||||
for (MessageTemplateType messageTemplateType : messageTemplateTypes) {
|
||||
if(messageTemplateType.getMessageTemplateTypeId().equals(msgTypeId)){
|
||||
Short currentElapsed = current.getShort(messageTemplateType.getMessageField());
|
||||
Short nextElapsed = next.getShort(messageTemplateType.getMessageField());
|
||||
if (nextElapsed > currentElapsed + slideFrequency) {
|
||||
log.info("出错啦,出错啦,您的"+messageTemplateType.getMessageField()+"不正常,请检查!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: yzl
|
||||
namespace: lxy
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: yzl
|
||||
namespace: lxy
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: yzl
|
||||
namespace: lxy
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -302,4 +302,11 @@ public class SysUserController extends BaseController {
|
|||
public Result deptTree (SysDept dept) {
|
||||
return success(deptService.selectDeptTreeList(dept));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/addUser")
|
||||
public Result<Integer> addUser(@RequestBody SysUser sysUser){
|
||||
Integer i = userService.addUser(sysUser);
|
||||
return Result.success(i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,5 +158,8 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||
List<SysUser> selectCompanyList();
|
||||
|
||||
|
||||
Integer addUser(SysUser sysUser);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -230,5 +230,6 @@ public interface SysUserService extends IService<SysUser> {
|
|||
|
||||
List<SysUser> selectCompanyList();
|
||||
|
||||
Integer addUser(SysUser sysUser);
|
||||
|
||||
}
|
||||
|
|
|
@ -518,4 +518,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
return userMapper.selectCompanyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer addUser(SysUser sysUser) {
|
||||
return userMapper.addUser(sysUser);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="remark" column="remark"/>
|
||||
<result property="databaseName" column="database_name"/>
|
||||
<association property="dept" javaType="com.muyu.common.system.domain.SysDept" resultMap="deptResult"/>
|
||||
<collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>
|
||||
</resultMap>
|
||||
|
@ -204,6 +205,7 @@
|
|||
<if test="status != null and status != ''">status,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
<if test="databaseName !=null and databaseName!=''">database_name,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="userId != null and userId != ''">#{userId},</if>
|
||||
|
@ -218,6 +220,7 @@
|
|||
<if test="status != null and status != ''">#{status},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="databaseName!=null and databaseName!=''">#{databaseName}</if>
|
||||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
@ -228,6 +231,11 @@
|
|||
INSERT INTO `saas`.`tb_enterprise` (`enterprise_id`, `enterprise_name`, `enterprise_car_count`, `enterprise_fence_count`, `enterprise_database_name`)
|
||||
VALUES (NULL, #{firmName}, 0, 0, #{databaseName});
|
||||
</insert>
|
||||
<insert id="addUser">
|
||||
INSERT INTO `four`.`sys_user`
|
||||
(`dept_id`, `user_name`, `nick_name`, `user_type`, `email`, `phonenumber`, `sex`, `avatar`, `password`, `status`, `del_flag`, `login_ip`, `login_date`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`, `database_name`)
|
||||
VALUES ( 105, #{userName}, '若依', '00', 'ry@qq.com', '15666666666', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '0', '47.101.53.251', '2024-05-23 15:08:18', 'admin', #{createTime}, '', NULL, '测试员', #{databaseName});
|
||||
</insert>
|
||||
|
||||
<update id="updateUser" parameterType="com.muyu.common.system.domain.SysUser">
|
||||
update sys_user
|
||||
|
|
|
@ -30,9 +30,7 @@ import java.util.Optional;
|
|||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.mqtt.configure
|
||||
* @Project:cloud-server
|
||||
|
@ -60,7 +58,6 @@ public class MqttConfigure {
|
|||
|
||||
@PostConstruct
|
||||
public void MQTTMonitoring(){
|
||||
|
||||
String topic = "car";
|
||||
int qos = 2;
|
||||
String broker = "tcp://47.101.53.251:1883";
|
||||
|
@ -107,7 +104,6 @@ public class MqttConfigure {
|
|||
me.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject messageParsing(String templateMessage) {
|
||||
//给一个JSON对象
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
@ -115,7 +111,8 @@ public class MqttConfigure {
|
|||
if (templateMessage.length() < 18) {
|
||||
throw new RuntimeException("The vehicle message is incorrect");
|
||||
}
|
||||
//将报文进行切割
|
||||
//将 templateMessage 按空格切割成多个字符串,得到一个字符串数组 hexArray。接着,
|
||||
// 将每个十六进制字符串转换成十进制整数,然后再转换为字符,最后将所有字符拼接成一个完整的字符串 result。
|
||||
String[] hexArray = templateMessage.split(" ");
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String hex : hexArray) {
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package com.muyu.template.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.template.controller
|
||||
* @name:TemplateController
|
||||
* @Date:2024/10/7 10:28
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/template")
|
||||
@AllArgsConstructor
|
||||
@Tag(name = "协议解析管理",description = "协议解析管理")
|
||||
@Log4j2
|
||||
public class TemplateController {
|
||||
}
|
|
@ -1,203 +1,135 @@
|
|||
package com.muyu.template;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.muyu.common.domain.*;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.cache.MessageTemplateTypeCacheService;
|
||||
import com.muyu.cache.SysCarCacheService;
|
||||
import com.muyu.cache.WarnRuleCacheService;
|
||||
import com.muyu.cache.WarnStrategyCacheService;
|
||||
import com.muyu.common.domain.MessageTemplateType;
|
||||
import com.muyu.common.domain.SysCar;
|
||||
import com.muyu.common.domain.resp.SysCarVo;
|
||||
import com.muyu.common.domain.resp.WarnRuleResp;
|
||||
import com.muyu.common.domain.resp.WarnStrategyResp;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
/**
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.template
|
||||
* @name:test
|
||||
* @Date:2024/10/4 9:42
|
||||
* @name:test2
|
||||
* @Date:2024/10/6 10:34
|
||||
*/
|
||||
@Log4j2
|
||||
public class test {
|
||||
|
||||
private static int DURATION_SECONDS = 60;
|
||||
private static int DURATION_SECONDS = 5;
|
||||
private static List<JSONObject> receivedStrings = new ArrayList<>();
|
||||
private static int elapsedSeconds = 0;
|
||||
private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static int elapsedSeconds = 0;
|
||||
private static String file="elapsed";
|
||||
private static List<MessageTemplateType> messageTemplateTypes=null;
|
||||
private static Long msgTypeId=null;
|
||||
//滑窗时间
|
||||
private static Long slideTime=null;
|
||||
//增长率
|
||||
private static Long slideFrequency=null;
|
||||
//预警策略
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
private WarnStrategyCacheService warnStrategyCacheService;
|
||||
//车辆
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
private SysCarCacheService sysCarCacheService;
|
||||
//预警规则
|
||||
@Resource
|
||||
private WarnRuleCacheService warnRuleCacheService;
|
||||
//报文模版
|
||||
@Resource
|
||||
private MessageTemplateTypeCacheService messageTemplateTypeCacheService;
|
||||
|
||||
public void main(String[] args) {
|
||||
String message="7E 36 33 59 43 5a 44 59 36 33 33 36 43 38 48 34 43 41 31 37 32 37 36 36 38 35 39 37 37 38 39 31 32 31 2e 34 37 34 30 30 30 30 33 31 2e 32 33 30 30 30 31 30 31 38 2e 30 30 30 31 38 38 31 2e 37 39 30 30 30 30 35 36 31 30 30 30 33 31 30 30 30 36 38 39 39 30 30 30 30 30 50 31 30 39 30 39 2e 35 30 30 32 34 30 30 30 30 31 33 32 36 35 37 33 39 30 36 37 30 30 30 30 32 31 31 30 30 31 33 32 35 30 30 30 30 36 37 30 30 30 2e 32 32 30 30 30 30 37 35 30 30 30 30 31 33 31 30 30 30 30 35 37 30 30 30 30 33 30 30 30 34 30 30 30 37 39 30 30 30 30 32 30 30 30 30 30 31 37 30 30 30 30 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 55 7E";
|
||||
//车类型
|
||||
Long carTypeId=null;
|
||||
//查找车对应的类型
|
||||
List<SysCar> carList = redisService.getCacheList("car");
|
||||
for (SysCar sysCar : carList) {
|
||||
if(sysCar.getCarVin().equals("1HGCM82633A123456")){
|
||||
//获取到车的类型ID
|
||||
carTypeId = sysCar.getCarTypeId();
|
||||
//协议解析:每秒穿过来一个JSONObject jsonObject; 添加进receivedStrings
|
||||
//根据这个车辆VIN查询出他对应的车辆类型
|
||||
String carVin=null;
|
||||
//报文模版的ID
|
||||
Integer templateId=null;
|
||||
for (JSONObject receivedString : receivedStrings) {
|
||||
carVin = receivedString.getStr("carVin");
|
||||
}
|
||||
SysCar carByVin = null;
|
||||
List<SysCarVo> carVoList = sysCarCacheService.get(sysCarCacheService.keyPre());
|
||||
Map<String, SysCarVo> carMap = carVoList.stream()
|
||||
.collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity()));
|
||||
//获取到了这个车辆的信息
|
||||
carByVin = carMap.get(carVin);
|
||||
//获取到这辆车绑定的报文模版
|
||||
templateId=carByVin.getTemplateId();
|
||||
//这个是这辆车对应的所有策略
|
||||
List<WarnStrategyResp> carWithWarnStrategyList=null;
|
||||
List<WarnStrategyResp> warnStrategyResps = warnStrategyCacheService.get(warnStrategyCacheService.keyPre());
|
||||
for (WarnStrategyResp warnStrategyResp : warnStrategyResps) {
|
||||
if(warnStrategyResp.getCarTypeId()==carByVin.getCarTypeId()){
|
||||
carWithWarnStrategyList.add(warnStrategyResp);
|
||||
}
|
||||
}
|
||||
|
||||
//查找车类型对应的策略
|
||||
List<WarnStrategy> warnStrategyList = null;
|
||||
//该车绑定的报文模版
|
||||
Long templateId=null;
|
||||
//获取到车的类型之后 查找对应的策略
|
||||
List<WarnStrategy> warnStrategy = redisService.getCacheList("warnStrategy");
|
||||
for (WarnStrategy strategy : warnStrategy) {
|
||||
if(strategy.getCarTypeId().equals(carTypeId)){
|
||||
templateId=strategy.getTemplateId();
|
||||
warnStrategyList.add(strategy);
|
||||
}
|
||||
}
|
||||
|
||||
//报文模版 根据templateId取出对应的模版
|
||||
List<MessageTemplateType> templateTypeList1=null;
|
||||
List<MessageTemplateType> templateTypeList = redisService.getCacheList("templateTypeList");
|
||||
for (MessageTemplateType messageTemplateType : templateTypeList) {
|
||||
if(messageTemplateType.getTemplateId().equals(templateId)){
|
||||
templateTypeList1.add(messageTemplateType);
|
||||
}
|
||||
}
|
||||
|
||||
//获取策略对应的规则列表
|
||||
List<WarnRule> warnRule = redisService.getCacheList("warnRule");
|
||||
//车辆对应的规则
|
||||
List<WarnRule> warnRuleList = null;
|
||||
for (WarnRule rule : warnRule) {
|
||||
for (WarnStrategy strategy : warnStrategyList) {
|
||||
if(rule.getStrategyId()==strategy.getId()){
|
||||
warnRuleList.add(rule);
|
||||
//该车对应的所有预警规则
|
||||
List<WarnRuleResp> warnRuleResp=null;
|
||||
List<WarnRuleResp> warnRuleResps = warnRuleCacheService.get(warnRuleCacheService.keyPre());
|
||||
for (WarnStrategyResp warnStrategyResp : carWithWarnStrategyList) {
|
||||
for (WarnRuleResp ruleResp : warnRuleResps) {
|
||||
if(warnStrategyResp.getId().equals(ruleResp.getStrategyId())){
|
||||
warnRuleResp.add(ruleResp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String templateIds=null;
|
||||
for (WarnRule rule : warnRuleList) {
|
||||
//滑窗时间
|
||||
Long slideTime = rule.getSlideTime();
|
||||
if(slideTime!=null){
|
||||
DURATION_SECONDS= Math.toIntExact(slideTime);
|
||||
}
|
||||
templateIds+=","+rule.getMsgTypeId();
|
||||
//报文模版
|
||||
messageTemplateTypes = messageTemplateTypeCacheService.get(messageTemplateTypeCacheService.keyPre());
|
||||
for (WarnRuleResp ruleResp : warnRuleResp) {
|
||||
//每一个规则他绑定了报文模版里面对应的一个配置 比如:电池,或者车速
|
||||
msgTypeId = ruleResp.getMsgTypeId();
|
||||
//将规则中对应的滑窗时间赋值为DURATION_SECONDS
|
||||
DURATION_SECONDS = Math.toIntExact(ruleResp.getSlideTime());
|
||||
slideFrequency = ruleResp.getSlideFrequency();
|
||||
}
|
||||
|
||||
String[] templateIdSplit = templateIds.split(",");
|
||||
//最终获取到的报文模版 使用他进行比较
|
||||
List<MessageTemplateType> messageTemplateTypes=null;
|
||||
for (String s : templateIdSplit) {
|
||||
for (MessageTemplateType messageTemplateType : templateTypeList1) {
|
||||
if(s.equals(messageTemplateType.getTemplateId())){
|
||||
messageTemplateTypes.add(messageTemplateType);
|
||||
}
|
||||
// 定义一个任务,每秒执行一次
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 清理超过的数据
|
||||
cleanUpOldStrings();
|
||||
// 检查超速条件
|
||||
checkForSpeeding();
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject entries = messageParsing(message);
|
||||
//将解析后的数据添加到List<JSONObject> receivedStrings中
|
||||
receivedStrings.add(entries);
|
||||
cleanUpOldStrings();
|
||||
checkForSpeeding();
|
||||
};
|
||||
// 每隔1秒执行一次任务
|
||||
scheduler.scheduleAtFixedRate(task, 0, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
// 清理超过指定秒数内的数据
|
||||
// 清理超过60秒的数据
|
||||
private static void cleanUpOldStrings() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
receivedStrings.removeIf(jsonObject ->
|
||||
currentTime - jsonObject.getLong("time") > TimeUnit.SECONDS.toMillis(DURATION_SECONDS)
|
||||
);
|
||||
}
|
||||
|
||||
// 检查是否有超速情况
|
||||
private static void checkForSpeeding() {
|
||||
if (receivedStrings.size() < 2) return; // 如果数据不足,直接返回
|
||||
for (int i = 0; i < receivedStrings.size() - 1; i++) {
|
||||
JSONObject current = receivedStrings.get(i);
|
||||
JSONObject next = receivedStrings.get(i + 1);
|
||||
Short currentElapsed = current.getShort(file);
|
||||
Short nextElapsed = next.getShort(file);
|
||||
// 检查条件,如果相差大于12,则记录错误
|
||||
if (nextElapsed > currentElapsed + 12) {
|
||||
System.out.println("出错啦,出错啦,车子超速啦!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//解析报文的方法
|
||||
public JSONObject messageParsing(String templateMessage) {
|
||||
//给一个JSON对象
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//先截取出VIN码 然后根据VIN码查询这个车属于什么类型
|
||||
if (templateMessage.length() < 18) {
|
||||
throw new RuntimeException("The vehicle message is incorrect");
|
||||
}
|
||||
//将报文进行切割
|
||||
String[] hexArray = templateMessage.split(" ");
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String hex : hexArray) {
|
||||
int decimal = Integer.parseInt(hex, 16);
|
||||
result.append((char) decimal);
|
||||
}
|
||||
//取出VIN码
|
||||
String carVin = result.substring(0, 18 - 1);
|
||||
log.info("carVin码为:" + carVin);
|
||||
//根据VIN码获取车辆信息
|
||||
SysCar carByVin = null;
|
||||
List<SysCar> carList = redisService.getCacheList("carList");
|
||||
for (SysCar sysCar : carList) {
|
||||
if(sysCar.getCarVin().equals(carVin)){
|
||||
carByVin=sysCar;
|
||||
}
|
||||
}
|
||||
log.info("车辆信息为:" + carByVin);
|
||||
//对应车辆所对应的报文模版
|
||||
Integer templateId = carByVin.getTemplateId();
|
||||
List<MessageTemplateType> templateTypeList;
|
||||
//key
|
||||
String redisKey = "messageTemplateType" + templateId;
|
||||
//key存在
|
||||
if (redisTemplate.hasKey(redisKey)) {
|
||||
|
||||
List list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
||||
|
||||
templateTypeList = list.stream().map(o -> JSON.parseObject(o.toString(), MessageTemplateType.class))
|
||||
.toList();
|
||||
} else {
|
||||
List<MessageTemplateType> templateTypeList1=null;
|
||||
List<MessageTemplateType> templateTypeList2 = redisService.getCacheList("templateTypeList");
|
||||
for (MessageTemplateType messageTemplateType : templateTypeList2) {
|
||||
if(messageTemplateType.getTemplateId()==templateId){
|
||||
templateTypeList1.add(messageTemplateType);
|
||||
for (int i = 0; i < receivedStrings.size(); i++) {
|
||||
JSONObject current = receivedStrings.get(i);
|
||||
JSONObject next = receivedStrings.get(i + 1);
|
||||
for (MessageTemplateType messageTemplateType : messageTemplateTypes) {
|
||||
if(messageTemplateType.getMessageTemplateTypeId().equals(msgTypeId)){
|
||||
Short currentElapsed = current.getShort(messageTemplateType.getMessageField());
|
||||
Short nextElapsed = next.getShort(messageTemplateType.getMessageField());
|
||||
if (nextElapsed > currentElapsed + slideFrequency) {
|
||||
log.info("出错啦,出错啦,您的"+messageTemplateType.getMessageField()+"不正常,请检查!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
templateTypeList = templateTypeList1;
|
||||
templateTypeList.forEach(
|
||||
templateType ->
|
||||
redisTemplate.opsForList().rightPush(
|
||||
redisKey, JSON.toJSONString(templateType)
|
||||
)
|
||||
);
|
||||
}
|
||||
//将模版里面有的配置进行循环
|
||||
for (MessageTemplateType messageTemplateType : templateTypeList) {
|
||||
//开始位置
|
||||
Integer startIndex = messageTemplateType.getStartIndex() - 1;
|
||||
//结束位置
|
||||
Integer endIndex = messageTemplateType.getEndIndex();
|
||||
//将每个解析后的字段都存入到JSON对象中
|
||||
jsonObject.put(messageTemplateType.getMessageField(),result.substring(startIndex, endIndex));
|
||||
}
|
||||
log.info("解析后的报文是:" + jsonObject);
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
package com.muyu.template;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
/**
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.template
|
||||
* @name:test2
|
||||
* @Date:2024/10/6 10:34
|
||||
*/
|
||||
@Log4j2
|
||||
public class test2 {
|
||||
|
||||
private static final int DURATION_SECONDS = 5;
|
||||
private static List<JSONObject> receivedStrings = new ArrayList<>();
|
||||
private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static int elapsedSeconds = 0;
|
||||
private static String file="elapsed";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 定义一个任务,每秒执行一次
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JSONObject stringFromSource = getStringFromSource(); // 模拟获取字符串
|
||||
receivedStrings.add(stringFromSource);
|
||||
System.out.println("Received: " + stringFromSource);
|
||||
// 清理超过的数据
|
||||
cleanUpOldStrings();
|
||||
// 检查超速条件
|
||||
checkForSpeeding();
|
||||
}
|
||||
};
|
||||
// 每隔1秒执行一次任务
|
||||
scheduler.scheduleAtFixedRate(task, 0, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
// 模拟从某个源获取字符串的方法
|
||||
private static JSONObject getStringFromSource() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("message", "Hello World");
|
||||
jsonObject.put("time", System.currentTimeMillis());
|
||||
jsonObject.put("elapsed", elapsedSeconds);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
||||
// 清理超过60秒的数据
|
||||
private static void cleanUpOldStrings() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
receivedStrings.removeIf(jsonObject ->
|
||||
currentTime - jsonObject.getLong("time") > TimeUnit.SECONDS.toMillis(DURATION_SECONDS)
|
||||
);
|
||||
}
|
||||
|
||||
// 检查是否有超速情况
|
||||
private static void checkForSpeeding() {
|
||||
if (receivedStrings.size() < 2) return; // 如果数据不足,直接返回
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("message", "Hello World");
|
||||
jsonObject.put("time", System.currentTimeMillis());
|
||||
jsonObject.put("elapsed", 100);
|
||||
|
||||
for (int i = 0; i < receivedStrings.size() - 1; i++) {
|
||||
JSONObject current = receivedStrings.get(i);
|
||||
JSONObject next = receivedStrings.get(i + 1);
|
||||
|
||||
Short currentElapsed = current.getShort(file);
|
||||
Short nextElapsed = next.getShort(file);
|
||||
receivedStrings.add(jsonObject);
|
||||
// 检查条件,如果相差大于12,则记录错误
|
||||
if (nextElapsed > currentElapsed + 12) {
|
||||
System.out.println("出错啦,出错啦,车子超速啦!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 15277
|
||||
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: lxy
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
amqp:
|
||||
deserialization:
|
||||
trust:
|
||||
all: true
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
application:
|
||||
# 应用名称
|
||||
name: cloud-template
|
||||
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}
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.muyu.system.mapper: DEBUG
|
|
@ -52,6 +52,13 @@
|
|||
<artifactId>kafka-clients</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.baomidou</groupId>-->
|
||||
<!-- <artifactId>mybatis-plus-boot-starter</artifactId>-->
|
||||
<!-- <version>3.5.1</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -30,7 +30,7 @@ public class MessageTemplateType implements Serializable {
|
|||
* 主键
|
||||
*/
|
||||
@TableId(value = "message_template_type_id",type = IdType.AUTO)
|
||||
private String messageTemplateTypeId;
|
||||
private Long messageTemplateTypeId;
|
||||
/**
|
||||
* 报文类别
|
||||
*/
|
||||
|
|
|
@ -106,6 +106,7 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-xxl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
<artifactId>service-rpc</artifactId>
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package com.muyu.server;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* saas模块启动类
|
||||
* @author YuPing
|
||||
|
@ -11,7 +16,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
* @Version 1.0
|
||||
* @Data 2024-09-28 17:34:31
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(exclude = {
|
||||
DataSourceAutoConfiguration.class,
|
||||
DruidDataSourceAutoConfigure.class,
|
||||
DynamicDataSourceAutoConfiguration.class
|
||||
})
|
||||
@EnableCustomConfig
|
||||
@EnableMyFeignClients
|
||||
public class SaasApplication {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -21,8 +21,6 @@ import java.util.List;
|
|||
* @Date 2024/9/29 12:06
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/carType")
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.muyu.common.core.constant.SecurityConstants;
|
|||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.domain.Enterprise;
|
||||
import com.muyu.common.system.domain.Business;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import com.muyu.common.util.PageUtils;
|
||||
import com.muyu.server.controller.form.DeleteEnterpriseByIds;
|
||||
|
@ -27,6 +28,7 @@ import java.sql.Connection;
|
|||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -95,8 +97,14 @@ public class EnterpriseController {
|
|||
business.setDatabaseName(form.getEnterpriseDatabaseName());
|
||||
remoteUserService.settlementEnterpriseInfo(business, SecurityConstants.INNER);
|
||||
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setDatabaseName(form.getEnterpriseDatabaseName());
|
||||
sysUser.setUserName(form.getEnterpriseName());
|
||||
sysUser.setCreateTime(new Date());
|
||||
remoteUserService.addUser(sysUser, SecurityConstants.INNER);
|
||||
String createDatabaseUrl="jdbc:mysql://"+ DatasourceContent.IP+":"+DatasourceContent.PORT+"?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
|
||||
String createDatabaseSql = "CREATE DATABASE IF NOT EXISTS " + form.getEnterpriseDatabaseName() + ";";
|
||||
|
||||
try (Connection adminConn = DriverManager.getConnection(createDatabaseUrl, DatasourceContent.USER_NAME, DatasourceContent.PASSWORD);
|
||||
Statement stmt = adminConn.createStatement()) {
|
||||
|
||||
|
@ -122,6 +130,8 @@ public class EnterpriseController {
|
|||
ClassPathResource rc = new ClassPathResource("static/saas.sql");
|
||||
EncodedResource er = new EncodedResource(rc, "utf-8");
|
||||
ScriptUtils.executeSqlScript(connection, er);
|
||||
|
||||
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
|
|
@ -17,7 +17,8 @@ import java.util.List;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
* 报文模版管理
|
||||
* @author liuxinyue
|
||||
* @Package:com.template.controller
|
||||
* @Project:cloud-server-c
|
||||
* @name:TemplateController
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.muyu.server.service.CarTypeService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,76 +11,6 @@ nacos:
|
|||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
kafka:
|
||||
producer:
|
||||
# Kafka服务器
|
||||
bootstrap-servers: 150.158.33.234:9092
|
||||
# 开启事务,必须在开启了事务的方法中发送,否则报错
|
||||
transaction-id-prefix: kafkaTx-
|
||||
# 发生错误后,消息重发的次数,开启事务必须设置大于0。
|
||||
retries: 3
|
||||
# acks=0 : 生产者在成功写入消息之前不会等待任何来自服务器的响应。
|
||||
# acks=1 : 只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。
|
||||
# acks=all :只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。
|
||||
acks: all
|
||||
# 开启事务时,必须设置为all
|
||||
# 当有多个消息需要被发送到同一个分区时,生产者会把它们放在同一个批次里。该参数指定了一个批次可以使用的内存大小,按照字节数计算。
|
||||
batch-size: 16384
|
||||
# 生产者内存缓冲区的大小。
|
||||
buffer-memory: 1024000
|
||||
# 键的序列化方式
|
||||
key-serializer: org.apache.kafka.common.serialization.StringSerializer
|
||||
# 值的序列化方式(建议使用Json,这种序列化方式可以无需额外配置传输实体类)
|
||||
value-serializer: org.apache.kafka.common.serialization.StringSerializer
|
||||
consumer:
|
||||
# Kafka服务器
|
||||
group-id: my-kafka
|
||||
# 自动提交的时间间隔 在spring boot 2.X 版本中这里采用的是值的类型为Duration 需要符合特定的格式,如1S,1M,2H,5D
|
||||
#auto-commit-interval: 2s
|
||||
# 该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
|
||||
# earliest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,从头开始消费分区的记录
|
||||
# latest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,消费新产生的该分区下的数据(在消费者启动之后生成的记录)
|
||||
# none:当各分区都存在已提交的offset时,从提交的offset开始消费;只要有一个分区不存在已提交的offset,则抛出异常
|
||||
auto-offset-reset: latest
|
||||
# 是否自动提交偏移量,默认值是true,为了避免出现重复数据和数据丢失,可以把它设置为false,然后手动提交偏移量
|
||||
enable-auto-commit: true
|
||||
# 键的反序列化方式
|
||||
#key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
||||
key-deserializer: org.apache.kafka.common.serialization.StringSerializer
|
||||
# 值的反序列化方式(建议使用Json,这种序列化方式可以无需额外配置传输实体类)
|
||||
value-deserializer: org.apache.kafka.common.serialization.StringSerializer
|
||||
# 这个参数定义了poll方法最多可以拉取多少条消息,默认值为500。如果在拉取消息的时候新消息不足500条,那有多少返回多少;如果超过500条,每次只返回500。
|
||||
# 这个默认值在有些场景下太大,有些场景很难保证能够在5min内处理完500条消息,
|
||||
# 如果消费者无法在5分钟内处理完500条消息的话就会触发reBalance,
|
||||
# 然后这批消息会被分配到另一个消费者中,还是会处理不完,这样这批消息就永远也处理不完。
|
||||
# 要避免出现上述问题,提前评估好处理一条消息最长需要多少时间,然后覆盖默认的max.poll.records参数
|
||||
# 注:需要开启BatchListener批量监听才会生效,如果不开启BatchListener则不会出现reBalance情况
|
||||
max-poll-records: 500
|
||||
bootstrap-servers: 150.158.33.234:9092
|
||||
auto-commit-interval: 5000
|
||||
fetch-max-wait: 500
|
||||
fetch-min-size: 1
|
||||
heartbeat-interval: 3000
|
||||
properties:
|
||||
# 两次poll之间的最大间隔,默认值为5分钟。如果超过这个间隔会触发reBalance
|
||||
max:
|
||||
poll:
|
||||
interval:
|
||||
ms: 600000
|
||||
# 当broker多久没有收到consumer的心跳请求后就触发reBalance,默认值是10s
|
||||
session:
|
||||
timeout:
|
||||
ms: 10000
|
||||
listener:
|
||||
# 在侦听器容器中运行的线程数,一般设置为 机器数*分区数
|
||||
concurrency: 4
|
||||
# 自动提交关闭,需要设置手动消息确认
|
||||
ack-mode: manual_immediate
|
||||
# 消费监听接口监听的主题不存在时,默认会报错,所以设置为false忽略错误
|
||||
missing-topics-fatal: false
|
||||
# 两次poll之间的最大间隔,默认值为5分钟。如果超过这个间隔会触发reBalance
|
||||
poll-timeout: 600000
|
||||
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
|
|
|
@ -31,15 +31,14 @@
|
|||
insert into tb_enterprise
|
||||
set enterprise_name = #{enterpriseName},
|
||||
enterprise_car_count = #{enterpriseCarCount},
|
||||
enterprise_fence_count = #{enterpriseFenceCount},
|
||||
enterprise_database_name=#{enterpriseDatabaseName}
|
||||
enterprise_fence_count = #{enterpriseFenceCount}
|
||||
</insert>
|
||||
|
||||
|
||||
|
||||
<!--根据编号查询企业信息-->
|
||||
<select id="searchById" resultType="java.util.HashMap">
|
||||
select enterprise_id,enterprise_name,enterprise_car_count,enterprise_fence_count,enterprise_database_name
|
||||
select enterprise_id,enterprise_name,enterprise_car_count,enterprise_fence_count
|
||||
from tb_enterprise
|
||||
where enterprise_id = #{enterpriseId}
|
||||
</select>
|
||||
|
@ -48,8 +47,7 @@
|
|||
update tb_enterprise
|
||||
set enterprise_name = #{enterpriseName},
|
||||
enterprise_car_count = #{enterpriseCarCount},
|
||||
enterprise_fence_count = #{enterpriseFenceCount},
|
||||
enterprise_database_name=#{enterpriseDatabaseName}
|
||||
enterprise_fence_count = #{enterpriseFenceCount}
|
||||
where enterprise_id = #{enterpriseId} and enterprise_id != 0
|
||||
</update>
|
||||
|
||||
|
|
|
@ -77,5 +77,7 @@
|
|||
<select id="findCarByVin" resultType="com.muyu.common.domain.SysCar">
|
||||
select * from sys_car where car_vin=#{carVin}
|
||||
</select>
|
||||
|
||||
<select id="selectByCarVin" resultType="com.muyu.common.domain.SysCar">
|
||||
select * from sys_car where car_cin=#{carVin}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?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.server.mapper.TemplateNeedMapper">
|
||||
|
||||
<select id="selectByTemplateId" resultType="com.muyu.common.domain.MessageTemplateType">
|
||||
SELECT * FROM `message_template_type` WHERE template_id=#{templateId}
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,140 @@
|
|||
<?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.server.mapper.SysCarFaultMapper">
|
||||
|
||||
<resultMap type="com.muyu.common.domain.SysCarFault" id="SysCarFaultResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="faultCode" column="fault_code" />
|
||||
<result property="faultName" column="fault_name" />
|
||||
<result property="typeId" column="type_id" />
|
||||
<result property="faultLabel" column="fault_label" />
|
||||
<result property="faultBit" column="fault_bit" />
|
||||
<result property="faultValue" column="fault_value" />
|
||||
<result property="faultRank" column="fault_rank" />
|
||||
<result property="faultDesc" column="fault_desc" />
|
||||
<result property="faultMinThreshold" column="fault_min_threshold" />
|
||||
<result property="faultMaxThreshold" column="fault_max_threshold" />
|
||||
<result property="status" column="status" />
|
||||
<result property="warnStatus" column="warn_status" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="carTypeId" column="car_type_id"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysCarFaultVo">
|
||||
select id, fault_code, fault_name, type_id, fault_label, fault_bit, fault_value, fault_rank, fault_desc, fault_min_threshold, fault_max_threshold, status, warn_status, remark, create_by, create_time, update_by, update_time,car_type_id from sys_car_fault
|
||||
</sql>
|
||||
|
||||
<select id="selectSysCarFaultList" parameterType="com.muyu.common.domain.SysCarFault" resultMap="SysCarFaultResult">
|
||||
<include refid="selectSysCarFaultVo"/>
|
||||
<where>
|
||||
<if test="faultCode != null and faultCode != ''"> and fault_code = #{faultCode}</if>
|
||||
<if test="faultBit != null and faultBit != ''"> and fault_bit = #{faultBit}</if>
|
||||
<if test="faultRank != null "> and fault_rank = #{faultRank}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectSysCarFaultById" parameterType="Long" resultMap="SysCarFaultResult">
|
||||
<include refid="selectSysCarFaultVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
<select id="selectSysCarFaultIds" resultMap="SysCarFaultResult">
|
||||
<include refid="selectSysCarFaultVo"/>
|
||||
where id in
|
||||
<foreach collection="array" item="id" index="index" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<insert id="insertSysCarFault" parameterType="com.muyu.common.domain.SysCarFault" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into sys_car_fault
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="faultCode != null and faultCode != ''">fault_code,</if>
|
||||
<if test="faultName != null">fault_name,</if>
|
||||
<if test="typeId != null">type_id,</if>
|
||||
<if test="faultLabel != null">fault_label,</if>
|
||||
<if test="faultBit != null">fault_bit,</if>
|
||||
<if test="faultValue != null">fault_value,</if>
|
||||
<if test="faultRank != null">fault_rank,</if>
|
||||
<if test="faultDesc != null">fault_desc,</if>
|
||||
<if test="faultMinThreshold != null">fault_min_threshold,</if>
|
||||
<if test="faultMaxThreshold != null">fault_max_threshold,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="warnStatus != null">warn_status,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="carTypeId !=null">car_type_id</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="faultCode != null and faultCode != ''">#{faultCode},</if>
|
||||
<if test="faultName != null">#{faultName},</if>
|
||||
<if test="typeId != null">#{typeId},</if>
|
||||
<if test="faultLabel != null">#{faultLabel},</if>
|
||||
<if test="faultBit != null">#{faultBit},</if>
|
||||
<if test="faultValue != null">#{faultValue},</if>
|
||||
<if test="faultRank != null">#{faultRank},</if>
|
||||
<if test="faultDesc != null">#{faultDesc},</if>
|
||||
<if test="faultMinThreshold != null">#{faultMinThreshold},</if>
|
||||
<if test="faultMaxThreshold != null">#{faultMaxThreshold},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="warnStatus != null">#{warnStatus},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="carTypeId != null">#{catTypeId}</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateSysCarFault" parameterType="com.muyu.common.domain.SysCarFault">
|
||||
update sys_car_fault
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="faultCode != null and faultCode != ''">fault_code = #{faultCode},</if>
|
||||
<if test="faultName != null">fault_name = #{faultName},</if>
|
||||
<if test="typeId != null">type_id = #{typeId},</if>
|
||||
<if test="faultLabel != null">fault_label = #{faultLabel},</if>
|
||||
<if test="faultBit != null">fault_bit = #{faultBit},</if>
|
||||
<if test="faultValue != null">fault_value = #{faultValue},</if>
|
||||
<if test="faultRank != null">fault_rank = #{faultRank},</if>
|
||||
<if test="faultDesc != null">fault_desc = #{faultDesc},</if>
|
||||
<if test="faultMinThreshold != null">fault_min_threshold = #{faultMinThreshold},</if>
|
||||
<if test="faultMaxThreshold != null">fault_max_threshold = #{faultMaxThreshold},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="warnStatus != null">warn_status = #{warnStatus},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="carTypeId !=null">car_type_id=#{catTypeId}</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteSysCarFaultById" parameterType="Long">
|
||||
delete from sys_car_fault where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteSysCarFaultByIds" parameterType="String">
|
||||
delete from sys_car_fault where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<update id="enableWarningsById" parameterType="Long">
|
||||
update sys_car_fault set warn_status = 0 where id = #{id}
|
||||
</update>
|
||||
<update id="disableWarningsById" parameterType="Long">
|
||||
update sys_car_fault set warn_status = 1 where id = #{id}
|
||||
</update>
|
||||
</mapper>
|
|
@ -0,0 +1,7 @@
|
|||
<?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.server.mapper.DataTypeMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,7 @@
|
|||
<?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.server.mapper.MessageTemplateTypeMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,23 @@
|
|||
<?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.server.mapper.TemplateMapper">
|
||||
|
||||
<select id="templateList" resultType="com.muyu.common.domain.Template">
|
||||
select * from t_template
|
||||
</select>
|
||||
|
||||
<select id="findTemplateByName" resultType="com.muyu.common.domain.Template">
|
||||
select * from t_template where template_name=#{typeName}
|
||||
</select>
|
||||
<select id="findTemplateById" resultType="com.muyu.common.domain.MessageTemplateType">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
message_template_type
|
||||
WHERE
|
||||
template_id = #{templateId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue