刘武 2024-09-26 20:13:13 +08:00
commit bbebab923a
20 changed files with 222 additions and 256 deletions

View File

@ -16,7 +16,7 @@ public class SysCarVo extends SysCar {
@Excel(name = "车辆类型名称") @Excel(name = "车辆类型名称")
private String typeName; private String typeName;
@Excel(name = "策略名称") @Excel(name = "策略名称")
private Long strategyName; private String strategyName;

View File

@ -21,4 +21,10 @@ public interface SysCarMapper extends BaseMapper<SysCar> {
List<SysCarFaultLogVo> findFenceByCarVin(@Param("carVin") String carVin); List<SysCarFaultLogVo> findFenceByCarVin(@Param("carVin") String carVin);
//修改车辆
Integer updSysCarById(SysCar sysCar);
//添加车辆信息
Integer addSysCar(SysCar sysCar);
} }

View File

@ -30,7 +30,7 @@ public class SysCarServiceImpl extends ServiceImpl<SysCarMapper,SysCar> impleme
@Override @Override
public int addSysCar(SysCar sysCar) { public int addSysCar(SysCar sysCar) {
return sysCarMapper.insert(sysCar); return sysCarMapper.addSysCar(sysCar);
} }
@Override @Override
@ -40,7 +40,7 @@ public class SysCarServiceImpl extends ServiceImpl<SysCarMapper,SysCar> impleme
@Override @Override
public int updateSysCar(SysCar sysCar) { public int updateSysCar(SysCar sysCar) {
return sysCarMapper.updateById(sysCar); return sysCarMapper.updSysCarById(sysCar);
} }
@Override @Override

View File

@ -3,6 +3,29 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.mapper.SysCarMapper"> <mapper namespace="com.muyu.mapper.SysCarMapper">
<insert id="addSysCar">
INSERT INTO `four`.`sys_car`
( `car_vin`, `car_type_id`, `state`, `car_motor_manufacturer`, `car_motor_model`,
`car_battery_manufacturer`, `car_battery_model`, `strategy_id`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`)
VALUES (#{carVin}, #{carTypeId}, '1', #{carMotorManufacturer}, #{carMotorModel},
#{carBatteryManufacturer}, #{carBatteryModel}, #{strategyId},#{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{remark})
</insert>
<update id="updSysCarById">
UPDATE `four`.`sys_car`
SET `car_vin` = #{carVin},
`car_type_id` = #{carTypeId},
`state` = #{state},
`car_motor_manufacturer` = #{carMotorManufacturer},
`car_motor_model` = #{carMotorModel},
`car_battery_manufacturer` = #{carBatteryManufacturer},
`car_battery_model` = #{carBatteryModel},
`strategy_id` = #{strategyId},
`create_by` = #{createBy},
`create_time` = #{createTime},
`update_by` = #{updateBy},
`update_time` = #{updateTime},
`remark` = #{remark} WHERE `id` = #{id}
</update>
<select id="selectSysCarVoList" resultType="com.muyu.domain.resp.SysCarVo"> <select id="selectSysCarVoList" resultType="com.muyu.domain.resp.SysCarVo">
SELECT * ,car_type.type_name,warn_strategy.strategy_name SELECT * ,car_type.type_name,warn_strategy.strategy_name
FROM `sys_car` FROM `sys_car`

View File

@ -1,55 +0,0 @@
package com.template.controller;
import lombok.extern.log4j.Log4j2;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* @Authorliuxinyue
* @Packagecom.template.controller
* @Projectcloud-server
* @nameServiceController
* @Date2024/9/22 22:12
*/
@Log4j2
public class ServiceController {
private final String IOTDB_DRIVER="org.apache.iotdb.jdbc.IoTDBDriver";
private static final String url="jdbc:iotdb://47.116.173.119:6667/";
private static final String userName="root";
private static final String passWord="root";
public void ToIoTDB(String url, String userName, String passWord){
log.info("Connecting to IoTDB");
log.info("地址是:"+url);
log.info("用户名是:"+userName);
log.info("密码是:"+passWord);
log.info("红红火火恍恍惚惚");
}
public static void main(String[] args) {
try{
Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
DriverManager.getConnection(url,userName,passWord);
}catch(SQLException e){
log.error("SQLException: " + e.getMessage());
log.error("SQLState: " + e.getSQLState());
log.error("VendorError: " + e.getErrorCode());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
private void createConnection() throws ClassNotFoundException, SQLException {
try{
Class.forName(IOTDB_DRIVER);
DriverManager.getConnection(url,userName,passWord);
}catch(SQLException e){
log.error("SQLException: " + e.getMessage());
log.error("SQLState: " + e.getSQLState());
log.error("VendorError: " + e.getErrorCode());
}
}
}

View File

@ -0,0 +1,22 @@
package com.template.domain.resp;
import com.template.domain.CarType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Authorliuxinyue
* @Packagecom.template.domain.resp
* @Projectcloud-server
* @nameCarTypeResp
* @Date2024/9/25 22:09
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CarTypeResp extends CarType{
private String templateName;
}

View File

@ -2,9 +2,12 @@ package com.template.mapper;
import com.template.domain.CarType; import com.template.domain.CarType;
import com.template.domain.SysCar; import com.template.domain.SysCar;
import com.template.domain.resp.CarTypeResp;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* @Authorliuxinyue * @Authorliuxinyue
* @Packagecom.template.mapper * @Packagecom.template.mapper
@ -19,4 +22,5 @@ public interface CarMapper {
CarType carMapper(@Param("carTypeId") Long carTypeId); CarType carMapper(@Param("carTypeId") Long carTypeId);
List<CarTypeResp> findAllCars();
} }

View File

@ -1,5 +1,6 @@
package com.template.mapper; package com.template.mapper;
import com.template.domain.MessageTemplateType;
import com.template.domain.Template; import com.template.domain.Template;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -20,4 +21,6 @@ public interface TemplateMapper {
Template findTemplateByName(@Param("typeName") String typeName); Template findTemplateByName(@Param("typeName") String typeName);
List<MessageTemplateType> findTemplateById(@Param("templateId") Integer templateId);
} }

View File

@ -2,6 +2,9 @@ package com.template.service;
import com.template.domain.CarType; import com.template.domain.CarType;
import com.template.domain.SysCar; import com.template.domain.SysCar;
import com.template.domain.resp.CarTypeResp;
import java.util.List;
/** /**
* @Authorliuxinyue * @Authorliuxinyue
@ -15,4 +18,7 @@ public interface CarService {
CarType findCarTypeById(Long carTypeId); CarType findCarTypeById(Long carTypeId);
List<CarTypeResp> findAllCars();
} }

View File

@ -1,5 +1,6 @@
package com.template.service; package com.template.service;
import com.template.domain.MessageTemplateType;
import com.template.domain.Template; import com.template.domain.Template;
import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException; import org.apache.iotdb.rpc.StatementExecutionException;
@ -20,4 +21,6 @@ public interface TemplateService {
void messageParsing(String templateMessage) throws SQLException, IoTDBConnectionException, ClassNotFoundException, StatementExecutionException; void messageParsing(String templateMessage) throws SQLException, IoTDBConnectionException, ClassNotFoundException, StatementExecutionException;
List<MessageTemplateType> findTemplateById(Integer templateId);
} }

View File

@ -2,11 +2,14 @@ package com.template.service.impl;
import com.template.domain.CarType; import com.template.domain.CarType;
import com.template.domain.SysCar; import com.template.domain.SysCar;
import com.template.domain.resp.CarTypeResp;
import com.template.mapper.CarMapper; import com.template.mapper.CarMapper;
import com.template.service.CarService; import com.template.service.CarService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* @Authorliuxinyue * @Authorliuxinyue
* @Packagecom.template.service.impl * @Packagecom.template.service.impl
@ -31,4 +34,10 @@ public class CarServiceImpl implements CarService {
return carMapper.carMapper(carTypeId); return carMapper.carMapper(carTypeId);
} }
@Override
public List<CarTypeResp> findAllCars() {
return carMapper.findAllCars();
}
} }

View File

@ -5,7 +5,7 @@ import com.template.mapper.TemplateMapper;
import com.template.service.CarService; import com.template.service.CarService;
import com.template.service.MessageTemplateTypeService; import com.template.service.MessageTemplateTypeService;
import com.template.service.TemplateService; import com.template.service.TemplateService;
import com.template.util.ToIoTDB;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException; import org.apache.iotdb.rpc.StatementExecutionException;
@ -14,6 +14,7 @@ import org.apache.iotdb.session.SessionDataSet;
import org.apache.iotdb.session.util.Version; import org.apache.iotdb.session.util.Version;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -40,7 +41,7 @@ public class TemplateServiceImpl implements TemplateService{
private MessageTemplateTypeService messageTemplateTypeService; private MessageTemplateTypeService messageTemplateTypeService;
@Autowired @Autowired
private ToIoTDB toIoTDB; private RedisTemplate redisTemplate;
@Override @Override
public List<Template> templateList() { public List<Template> templateList() {
@ -74,6 +75,11 @@ public class TemplateServiceImpl implements TemplateService{
CarType carTypeById = carService.findCarTypeById(carByVin.getCarTypeId()); CarType carTypeById = carService.findCarTypeById(carByVin.getCarTypeId());
//查询报文模版 //查询报文模版
Template templateDate=templateMapper.findTemplateByName(carTypeById.getTypeName()); Template templateDate=templateMapper.findTemplateByName(carTypeById.getTypeName());
log.info("取出Redis中对象报文模版信息");
List range = redisTemplate.opsForList().range("VehicleType", 0, -1);
range.forEach(o -> {
});
//根据报文模版的ID查询对应的模版 //根据报文模版的ID查询对应的模版
List<MessageTemplateType> messageByTemplateName = messageTemplateTypeService.findMessageByTemplateName(templateDate.getTemplateId()); List<MessageTemplateType> messageByTemplateName = messageTemplateTypeService.findMessageByTemplateName(templateDate.getTemplateId());
//将模版里面有的配置进行循环 //将模版里面有的配置进行循环
@ -91,6 +97,10 @@ public class TemplateServiceImpl implements TemplateService{
} }
} }
@Override
public List<MessageTemplateType> findTemplateById(Integer templateId) {
return templateMapper.findTemplateById(templateId);
}
public void insertIoTDB(JSONObject jsonObject) throws SQLException, ClassNotFoundException, IoTDBConnectionException, StatementExecutionException { public void insertIoTDB(JSONObject jsonObject) throws SQLException, ClassNotFoundException, IoTDBConnectionException, StatementExecutionException {

View File

@ -1,22 +0,0 @@
package com.template.util;
import java.sql.Connection;
/**
* @Authorliuxinyue
* @Packagecom.template.util
* @Projectcloud-server
* @nameIOTDBConnectionTets
* @Date2024/9/24 10:34
*/
public class IOTDBConnectionTets {
private static final String url = "jdbc:iotdb://47.116.173.119:6667/";
private static final String username = "root";
private static final String password = "root";
public static void main(String[] args) {
Connection conn = new IOTdbJDBCUtils(url, username, password).getConnection();
System.out.println(conn != null ? "打开连接成功!" : "打开连接失败!");
IOTdbJDBCUtils.close(conn);
}
}

View File

@ -1,62 +0,0 @@
package com.template.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* @Authorliuxinyue
* @Packagecom.template.util
* @Projectcloud-server
* @nameIOTdbJDBCUtils
* @Date2024/9/24 10:18
*/
public class IOTdbJDBCUtils {
private static final String driver = "org.apache.iotdb.jdbc.IoTDBDriver";
private final String url;
private final String username;
private final String password;
public IOTdbJDBCUtils(String url, String username, String password) {
this.url = url;
this.username = username;
this.password = password;
}
static {
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("当前加载的驱动不存在........,请检查后重试!");
}
}
public Connection getConnection() {
Connection connection = null;
try {
connection = DriverManager.getConnection(url, username, password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return connection;
}
public static void close(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}

View File

@ -0,0 +1,53 @@
package com.template.util;
import lombok.extern.log4j.Log4j2;
import java.nio.charset.StandardCharsets;
/**
* @Authorliuxinyue
* @Packagecom.template.util
* @Projectcloud-server
* @nameStringCutterUtils
* @Date2024/9/25 21:18
*/
@Log4j2
public class StringCutterUtils {
public static String hexadecimalCharacter(String s){
StringBuilder stringBuilder = new StringBuilder();
int len = s.length();
for (int i = 0; i < len; i++) {
char c = s.charAt(i);
String hexString = Integer.toHexString(c);
stringBuilder.append(hexString+" ");
}
return stringBuilder.toString();
}
public static void main(String[] args) {
String s = hexadecimalCharacter("3C3F786D6C2076657273696F6E3D22312E30223F3E0D0A3C6D6F6E69746F72526F6F7420747970653D22706172616D223E3C73796E6368726F6E697A65537970746F6D206576656E743D22302220696E697469616C3D2274727565223E3C416374696F6E5F4543473E3C52687974686D3E53696E75733C2F52687974686D3E3C48523E38303C2F48523E3C454D443E4E6F204368616E67653C2F454D443E3C436F6E647563743E303C2F436F6E647563743E3C2F416374696F6E5F4543473E3C416374696F6E5F4F7361742076616C75653D2239342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F425020697352656C617469766550657263656E743D2266616C7365223E3C536872696E6B2076616C75653D22313230222F3E3C537472657463682076616C75653D223830222F3E3C2F416374696F6E5F42503E3C416374696F6E5F5265737020627265617468547970653D224E6F726D616C222076616C75653D2231342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F6574434F322076616C75653D2233342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F54656D70657261747572652076616C75653D2233352E32222F3E3C416374696F6E5F4356502076616C75653D22362E30222F3E3C416374696F6E5F5041504469612076616C75653D223130222F3E3C416374696F6E5F5041505379732076616C75653D223235222F3E3C416374696F6E5F57502076616C75653D2239222F3E3C2F73796E6368726F6E697A65537970746F6D3E3C2F6D6F6E69746F72526F6F743E0D0A");
String string = toString(s);
log.info(string);
}
public static String toString(String s){
if(s==null || s.equals("")){
return null;
}
log.info("将字符串中的空格去除");
s = s.replace(" ", "");
byte[] bytes = new byte[s.length() / 2];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) (0xff & Integer.parseInt(s.substring(i*2,i*2+2), 16));
}
s=new String(bytes, StandardCharsets.UTF_8);
return s;
}
}

View File

@ -0,0 +1,60 @@
package com.template.util;
import com.template.domain.MessageTemplateType;
import com.template.domain.SysCar;
import com.template.domain.Template;
import com.template.domain.resp.CarTypeResp;
import com.template.service.CarService;
import com.template.service.TemplateService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
/**
* @Authorliuxinyue
* @Packagecom.template.util
* @Projectcloud-server
* @nameSynchronizingTemplate
* @Date2024/9/25 20:03
*/
@Component
@Log4j2
public class SynchronizingTemplate {
//调用报文模版列表接口
@Resource
private TemplateService templateService;
//redis
@Resource
private RedisTemplate redisTemplate;
@Autowired
private CarService carService;
@PostConstruct
public void synchronizeTemplate() {
//获取所有报文模版的ID
log.info("获取所有报文模版的ID");
List<Template> templates = templateService.templateList();
templates.forEach(template -> {
Integer templateId = template.getTemplateId(); //报文模版ID
List<MessageTemplateType> list=templateService.findTemplateById(templateId); //根据报文模版ID查询所有的报文模版
ListOperations<String,Object> listOperations = redisTemplate.opsForList(); //将报文信息存储到redis中
redisTemplate.delete(template.getTemplateName());//因为每一次添加缓存的时候不会覆盖之前的数据 所有将数据先清空
List<CarTypeResp> allCars = carService.findAllCars();//查询所有车辆 里面有模版名称
redisTemplate.opsForList().leftPushAll("VehicleType", allCars);//将车辆类型放入列表
listOperations.leftPushAll(template.getTemplateName(), list); //将报文信息存储到redis中
List range = redisTemplate.opsForList().range("VehicleType", 0, -1);
range.forEach(o -> {
log.info("数据为:"+o);
});
});
}
}

View File

@ -1,36 +0,0 @@
package com.template.util;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Configuration;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* @Authorliuxinyue
* @Packagecom.template.util
* @Projectcloud-server
* @nameToIoTDB IoTDB
* @Date2024/9/20 19:40
*/
@Log4j2
@Configuration
public class ToIoTDB {
private final String IOTDB_DRIVER="org.apache.iotdb.jdbc.IoTDBDriver";
private static final String url="jdbc:iotdb://47.116.173.119:6667/";
private static final String userName="root";
private static final String passWord="root";
public Connection getConnection() throws ClassNotFoundException, SQLException {
Connection connection=null;
try{
Class.forName(IOTDB_DRIVER);
connection = DriverManager.getConnection(url, userName, passWord);
}catch(SQLException e){
log.error("SQLException: " + e.getMessage());
log.error("SQLState: " + e.getSQLState());
log.error("VendorError: " + e.getErrorCode());
}
return connection;
}
}

View File

@ -1,76 +0,0 @@
package com.template.util;
import org.springframework.beans.factory.annotation.Autowired;
import java.sql.*;
/**
* @Authorliuxinyue
* @Packagecom.template.util
* @Projectcloud-server
* @nameToIoTDBTest
* @Date2024/9/24 10:12
*/
public class ToIoTDBTest {
private static final String host = "47.116.173.119";
private static final String url = "jdbc:iotdb://" + host + ":6667/";
private static final String username = "root";
private static final String password = "root";
public static void main(String[] args) throws SQLException, ClassNotFoundException {
ToIoTDB toIoTDB = new ToIoTDB();
Connection connection = toIoTDB.getConnection();
// Connection connection = (Connection) new IOTdbJDBCUtils(url, username, password).getConnection();
System.out.println(connection!=null?"打开连接成功!":"打开连接失败!");
ResultSet rs=null;
String storgeGroup="root.test";
Statement statement = connection.createStatement();
String sql=String.format("set storage group to %s",storgeGroup);
statement = connection.createStatement();
int i = statement.executeUpdate(sql);
System.out.println("当前创建组的结果为:"+i);
//查看创建的组是否存在
sql="SHOW STORAGE GROUPS"; //查看所有的存储组
rs= statement.executeQuery(sql);
outputResult(rs);
sql=String.format("show storage group %s",storgeGroup);
rs=statement.executeQuery(sql);
outputResult(rs);
//统计存在的数量
sql=String.format("count storage group %s",storgeGroup);
rs=statement.executeQuery(sql);
outputResult(rs);
}
private static void outputResult(ResultSet resultSet) throws SQLException {
if (resultSet != null) {
System.out.println("--------------------------");
final ResultSetMetaData metaData = resultSet.getMetaData();
final int columnCount = metaData.getColumnCount();
for (int i = 0; i < columnCount; i++) {
System.out.print(metaData.getColumnLabel(i + 1) + ", ");
}
System.out.println();
while (resultSet.next()) {
for (int i = 1;; i++) {
System.out.print(resultSet.getString(i));
if (i < columnCount) {
System.out.print(", ");
} else {
System.out.println();
break;
}
}
}
System.out.println("--------------------------\n");
}
}
}

View File

@ -10,4 +10,14 @@
<select id="carMapper" resultType="com.template.domain.CarType"> <select id="carMapper" resultType="com.template.domain.CarType">
select * from car_type where id=#{carTypeId} select * from car_type where id=#{carTypeId}
</select> </select>
<select id="findAllCars" resultType="com.template.domain.resp.CarTypeResp">
SELECT
car_type.*,
t_template.template_name
FROM
car_type
LEFT JOIN t_template ON car_type.template_id = t_template.template_id
</select>
</mapper> </mapper>

View File

@ -11,5 +11,13 @@
<select id="findTemplateByName" resultType="com.template.domain.Template"> <select id="findTemplateByName" resultType="com.template.domain.Template">
select * from t_template where template_name=#{typeName} select * from t_template where template_name=#{typeName}
</select> </select>
<select id="findTemplateById" resultType="com.template.domain.MessageTemplateType">
SELECT
*
FROM
message_template_type
WHERE
template_id = #{templateId}
</select>
</mapper> </mapper>