Merge remote-tracking branch 'origin/master' into dev.breakdown

dev.breakdown
袁子龙 2024-09-26 20:25:22 +08:00
commit 82052d32e1
51 changed files with 543 additions and 301 deletions

View File

@ -57,6 +57,10 @@
<groupId>com.muyu</groupId>
<artifactId>cloud-common-api-doc</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
</dependencies>

View File

@ -1,7 +1,9 @@
package com.muyu.auth.controller;
import com.muyu.auth.form.Firm;
import com.muyu.auth.form.LoginBody;
import com.muyu.auth.form.RegisterBody;
import com.muyu.auth.service.SysFirmService;
import com.muyu.auth.service.SysLoginService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.JwtUtils;
@ -30,11 +32,22 @@ public class TokenController {
@Autowired
private SysLoginService sysLoginService;
@Autowired
private SysFirmService sysFirmService;
@PostMapping("login")
public Result<?> login (@RequestBody LoginBody form) {
//查询用户公司是否存在
Firm firm = sysFirmService.findFirmByName(form.getFirmName());
//不能存在提示
if (firm.getDatabaseName()==null){
return Result.error(null,"公司不存在");
}
// 用户登录
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
LoginUser userInfo = sysLoginService.login(firm.getDatabaseName(),form.getUsername(), form.getPassword());
// 获取登录token
return Result.success(tokenService.createToken(userInfo));
}

View File

@ -0,0 +1,20 @@
package com.muyu.auth.form;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Firm {
private Integer id;
private String firmName;
private String databaseName;
}

View File

@ -1,11 +1,22 @@
package com.muyu.auth.form;
import lombok.Data;
/**
*
*
* @author muyu
*/
@Data
public class LoginBody {
/**
*
*/
private String firmName;
/**
*
*/
@ -17,19 +28,5 @@ public class LoginBody {
private String password;
public String getUsername () {
return username;
}
public void setUsername (String username) {
this.username = username;
}
public String getPassword () {
return password;
}
public void setPassword (String password) {
this.password = password;
}
}

View File

@ -0,0 +1,56 @@
package com.muyu.auth.service;
import com.muyu.auth.form.Firm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
@Component
public class SysFirmService {
static final String USER="root";
static final String PASSWORD="Lw030106";
@Autowired
private RedisTemplate redisTemplate;
public Firm findFirmByName(String firmName){
Firm firm = new Firm();
try {
// Class.forName("com.mysql.cj.jdbc.Driver");
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` where firm_name = '"+firmName+"'";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()){
firm.setId(rs.getInt("id"));
firm.setFirmName(rs.getString("firm_name"));
firm.setDatabaseName(rs.getString("database_name"));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
//数据源不为空
if (firm!=null){
redisTemplate.opsForValue().set("datasource",firm.getDatabaseName());
}
return firm;
};
}

View File

@ -12,6 +12,7 @@ import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.utils.ip.IpUtils;
import com.muyu.common.redis.service.RedisService;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.Firm;
import com.muyu.common.system.remote.RemoteUserService;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.domain.LoginUser;
@ -40,7 +41,7 @@ public class SysLoginService {
/**
*
*/
public LoginUser login (String username, String password) {
public LoginUser login (String databaseName,String username, String password) {
// 用户名或密码为空 错误
if (StringUtils.isAnyBlank(username, password)) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
@ -64,8 +65,14 @@ public class SysLoginService {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾访问IP已被列入系统黑名单");
throw new ServiceException("很遗憾访问IP已被列入系统黑名单");
}
Firm firm = new Firm();
firm.setDatabaseName(databaseName);
firm.setUserName(username);
// 查询用户信息
Result<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
Result<LoginUser> userResult = remoteUserService.getUserInfo(firm, SecurityConstants.INNER);
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: yzl
namespace: four
# Spring
spring:
application:

View File

@ -0,0 +1,22 @@
package com.muyu.common.system.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Firm {
private Integer id;
private String firmName;
private String databaseName;
private String userName;
}

View File

@ -4,6 +4,7 @@ import com.muyu.common.core.constant.SecurityConstants;
import com.muyu.common.core.constant.ServiceNameConstants;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.system.domain.Firm;
import com.muyu.common.system.domain.SysFirmUser;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
@ -23,13 +24,13 @@ public interface RemoteUserService {
/**
*
*
* @param username
* @param
* @param source
*
* @return
*/
@GetMapping("/user/info/{username}")
public Result<LoginUser> getUserInfo (@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/user/info")
public Result<LoginUser> getUserInfo (@RequestBody Firm firm, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
*

View File

@ -2,6 +2,7 @@ package com.muyu.common.system.remote.factory;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.system.domain.Firm;
import com.muyu.common.system.domain.SysFirmUser;
import com.muyu.common.system.remote.RemoteUserService;
import com.muyu.common.system.domain.SysUser;
@ -26,8 +27,10 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
public RemoteUserService create (Throwable throwable) {
log.error("用户服务调用失败:{}", throwable.getMessage());
return new RemoteUserService() {
@Override
public Result<LoginUser> getUserInfo (String username, String source) {
public Result<LoginUser> getUserInfo(Firm firm, String source) {
return Result.error("获取用户失败:" + throwable.getMessage());
}

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: yzl
namespace: four
# Spring
spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: yzl
namespace: four
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -80,6 +80,11 @@
<artifactId>cloud-common-api-doc</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-saas</artifactId>
</dependency>
</dependencies>

View File

@ -16,7 +16,7 @@ public class SysCarVo extends SysCar {
@Excel(name = "车辆类型名称")
private String typeName;
@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);
//修改车辆
Integer updSysCarById(SysCar sysCar);
//添加车辆信息
Integer addSysCar(SysCar sysCar);
}

View File

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

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: lgy
namespace: four
# Spring
spring:

View File

@ -3,6 +3,29 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<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 * ,car_type.type_name,warn_strategy.strategy_name
FROM `sys_car`

View File

@ -86,6 +86,12 @@
<groupId>com.muyu</groupId>
<artifactId>cloud-common-rabbit</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-saas</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -1,9 +1,13 @@
package com.muyu.fence;
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;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
*
@ -13,7 +17,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableCustomConfig
//@EnableCustomSwagger2
@EnableMyFeignClients
@SpringBootApplication
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
DruidDataSourceAutoConfigure.class,
DynamicDataSourceAutoConfiguration.class
})
public class CloudElectronicFenceApplication {
public static void main (String[] args) {
SpringApplication.run(CloudElectronicFenceApplication.class, args);

View File

@ -6,7 +6,7 @@ nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: lgy
namespace: four
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -59,6 +59,18 @@
<groupId>com.muyu</groupId>
<artifactId>cloud-common-api-doc</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-3-starter</artifactId>
<version>1.2.23</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
<version>4.3.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@ -1,15 +1,23 @@
package com.muyu.file;
import com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
*
*
* @author muyu
*/
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
DruidDataSourceAutoConfigure.class,
DynamicDataSourceAutoConfiguration.class
})
@EnableFeignClients
public class CloudFileApplication {
public static void main (String[] args) {
SpringApplication.run(CloudFileApplication.class, args);

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: yzl
namespace: four
# Spring
spring:

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: yzl
namespace: four
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -78,6 +78,8 @@
<artifactId>cloud-common-xxl</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -1,5 +1,6 @@
package com.muyu.system;
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;

View File

@ -9,6 +9,7 @@ import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.service.TokenService;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.Firm;
import com.muyu.common.system.remote.RemoteFileService;
import com.muyu.common.system.domain.SysFile;
import com.muyu.common.system.domain.SysUser;
@ -44,7 +45,7 @@ public class SysProfileController extends BaseController {
@GetMapping
public Result profile () {
String username = SecurityUtils.getUsername();
SysUser user = userService.selectUserByUserName(username);
SysUser user = userService.selectUserByName(username);
return Result.success(
ProfileResp.builder()
.roleGroup( userService.selectUserRoleGroup(username) )
@ -87,7 +88,8 @@ public class SysProfileController extends BaseController {
@PutMapping("/updatePwd")
public Result updatePwd (String oldPassword, String newPassword) {
String username = SecurityUtils.getUsername();
SysUser user = userService.selectUserByUserName(username);
SysUser user = userService.selectUserByName(username);
String password = user.getPassword();
if (!SecurityUtils.matchesPassword(oldPassword, password)) {
return error("修改密码失败,旧密码错误");

View File

@ -10,10 +10,7 @@ import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.InnerAuth;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.SysDept;
import com.muyu.common.system.domain.SysRole;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.common.system.domain.*;
import com.muyu.system.domain.resp.AuthRoleResp;
import com.muyu.system.domain.resp.UserDetailInfoResp;
import com.muyu.system.domain.resp.UserInfoResp;
@ -103,9 +100,9 @@ public class SysUserController extends BaseController {
*
*/
@InnerAuth
@GetMapping("/info/{username}")
public Result<LoginUser> info (@PathVariable("username") String username) {
SysUser sysUser = userService.selectUserByUserName(username);
@PostMapping("/info")
public Result<LoginUser> info (@RequestBody Firm firm) {
SysUser sysUser = userService.selectUserByUserName(firm);
if (StringUtils.isNull(sysUser)) {
return Result.error("用户名或密码错误");
}

View File

@ -18,6 +18,7 @@ public interface SysDictTypeMapper extends BaseMapper<SysDictType> {
*
* @return
*/
public List<SysDictType> selectDictTypeList (SysDictType dictType);
/**

View File

@ -46,7 +46,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
*
* @return
*/
public SysUser selectUserByUserName (String userName);
public SysUser selectUserByUserName (@Param("userName") String userName);
/**
* ID

View File

@ -1,6 +1,7 @@
package com.muyu.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.system.domain.Firm;
import com.muyu.common.system.domain.SysUser;
import java.util.List;
@ -45,7 +46,7 @@ public interface SysUserService extends IService<SysUser> {
*
* @return
*/
public SysUser selectUserByUserName (String userName);
public SysUser selectUserByUserName (Firm firm);
/**
* ID
@ -228,4 +229,6 @@ public interface SysUserService extends IService<SysUser> {
List<SysUser> selectCompanyList();
SysUser selectUserByName(String username);
}

View File

@ -8,6 +8,8 @@ import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.utils.bean.BeanValidators;
import com.muyu.common.datascope.annotation.DataScope;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.Firm;
import com.muyu.common.system.domain.SysDept;
import com.muyu.common.system.domain.SysRole;
import com.muyu.common.system.domain.SysUser;
import com.muyu.system.domain.SysPost;
@ -24,6 +26,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@ -98,8 +101,108 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
* @return
*/
@Override
public SysUser selectUserByUserName (String userName) {
return userMapper.selectUserByUserName(userName);
public SysUser selectUserByUserName (Firm firm) {
String databaseName = firm.getDatabaseName();
String userName = firm.getUserName();
String user="root";
String password="Lw030106";
SysUser sysUser=new SysUser();
try {
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
Connection connection = DriverManager.getConnection("jdbc:mysql://47.101.53.251:3306/"+databaseName+"?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&useSSL=false", user, password);
String sql="select u.user_id,\n" +
" u.dept_id,\n" +
" u.user_name,\n" +
" u.nick_name,\n" +
" u.email,\n" +
" u.avatar,\n" +
" u.phonenumber,\n" +
" u.password,\n" +
" u.sex,\n" +
" u.status,\n" +
" u.database_name,\n" +
" u.del_flag,\n" +
" u.login_ip,\n" +
" u.login_date,\n" +
" u.create_by,\n" +
" u.create_time,\n" +
" u.remark,\n" +
" d.dept_id,\n" +
" d.parent_id,\n" +
" d.ancestors,\n" +
" d.dept_name,\n" +
" d.order_num,\n" +
" d.leader,\n" +
" d.status as dept_status,\n" +
" r.role_id,\n" +
" r.role_name,\n" +
" r.role_key,\n" +
" r.role_sort,\n" +
" r.data_scope,\n" +
" r.status as role_status " +
" from sys_user u\n" +
" left join sys_dept d on u.dept_id = d.dept_id\n" +
" left join sys_user_role ur on u.user_id = ur.user_id\n" +
" left join sys_role r on r.role_id = ur.role_id" +
" where u.del_flag = '0' and u.user_name = '"+userName+"'";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()){
sysUser.setUserId(rs.getLong("user_id"));
sysUser.setDeptId(rs.getLong("dept_id"));
sysUser.setUserName(rs.getString("user_name"));
sysUser.setNickName(rs.getString("nick_name"));
sysUser.setEmail(rs.getString("email"));
sysUser.setAvatar(rs.getString("avatar"));
sysUser.setPhonenumber(rs.getString("phonenumber"));
sysUser.setPassword(rs.getString("password"));
sysUser.setSex(rs.getString("sex"));
sysUser.setStatus(rs.getString("status"));
sysUser.setDatabaseName(rs.getString("database_name"));
sysUser.setDelFlag(rs.getString("del_flag"));
sysUser.setLoginIp(rs.getString("login_ip"));
sysUser.setLoginDate(rs.getDate("login_date"));
sysUser.setCreateBy(rs.getString("create_by"));
sysUser.setCreateTime(rs.getDate("create_time"));
SysDept sysDept = new SysDept();
sysDept.setDeptId(rs.getLong("dept_id"));
sysDept.setParentId(rs.getLong("parent_id"));
sysDept.setAncestors(rs.getString("ancestors"));
sysDept.setDeptName(rs.getString("dept_name"));
sysDept.setOrderNum(rs.getInt("order_num"));
sysDept.setLeader(rs.getString("leader"));
sysDept.setStatus(rs.getString("dept_status"));
sysUser.setDept(sysDept);
SysRole sysRole = new SysRole();
sysRole.setRoleId(rs.getLong("role_id"));
sysRole.setRoleName(rs.getString("role_name"));
sysRole.setRoleKey(rs.getString("role_key"));
sysRole.setRoleSort(rs.getInt("role_sort"));
sysRole.setDataScope(rs.getString("data_scope"));
sysRole.setStatus(rs.getString("role_status"));
ArrayList<SysRole> sysRoles = new ArrayList<>();
sysRoles.add(sysRole);
sysUser.setRoles(sysRoles);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return sysUser;
// return userMapper.selectUserByUserName(userName);
}
/**
@ -506,4 +609,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return userMapper.selectCompanyList();
}
@Override
public SysUser selectUserByName(String username) {
return userMapper.selectUserByUserName(username);
}
}

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: yzl
namespace: four
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

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

View File

@ -1,5 +1,6 @@
package com.template.mapper;
import com.template.domain.MessageTemplateType;
import com.template.domain.Template;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -20,4 +21,6 @@ public interface TemplateMapper {
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.SysCar;
import com.template.domain.resp.CarTypeResp;
import java.util.List;
/**
* @Authorliuxinyue
@ -15,4 +18,7 @@ public interface CarService {
CarType findCarTypeById(Long carTypeId);
List<CarTypeResp> findAllCars();
}

View File

@ -1,5 +1,6 @@
package com.template.service;
import com.template.domain.MessageTemplateType;
import com.template.domain.Template;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
@ -20,4 +21,6 @@ public interface TemplateService {
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.SysCar;
import com.template.domain.resp.CarTypeResp;
import com.template.mapper.CarMapper;
import com.template.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Authorliuxinyue
* @Packagecom.template.service.impl
@ -31,4 +34,10 @@ public class CarServiceImpl implements CarService {
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.MessageTemplateTypeService;
import com.template.service.TemplateService;
import com.template.util.ToIoTDB;
import lombok.extern.log4j.Log4j2;
import org.apache.iotdb.rpc.IoTDBConnectionException;
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.tsfile.file.metadata.enums.TSDataType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.sql.*;
import java.util.ArrayList;
@ -40,7 +41,7 @@ public class TemplateServiceImpl implements TemplateService{
private MessageTemplateTypeService messageTemplateTypeService;
@Autowired
private ToIoTDB toIoTDB;
private RedisTemplate redisTemplate;
@Override
public List<Template> templateList() {
@ -74,6 +75,11 @@ public class TemplateServiceImpl implements TemplateService{
CarType carTypeById = carService.findCarTypeById(carByVin.getCarTypeId());
//查询报文模版
Template templateDate=templateMapper.findTemplateByName(carTypeById.getTypeName());
log.info("取出Redis中对象报文模版信息");
List range = redisTemplate.opsForList().range("VehicleType", 0, -1);
range.forEach(o -> {
});
//根据报文模版的ID查询对应的模版
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 {

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 * from car_type where id=#{carTypeId}
</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>

View File

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

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: yzl
namespace: four
# Spring
spring: