feax:()添加企业的时候添加一个单独的库和表

dev.entOperation
crj 2024-09-30 16:41:06 +08:00
parent 517c18f215
commit 0c7795ea71
11 changed files with 99 additions and 27 deletions

View File

@ -136,6 +136,7 @@ public class SysLoginService {
if (Result.FAIL == registerResult.getCode()) { if (Result.FAIL == registerResult.getCode()) {
throw new ServiceException(registerResult.getMsg()); throw new ServiceException(registerResult.getMsg());
} }
recordLogService.recordLogininfor(username,Constants.REGISTER,"注册成功"); recordLogService.recordLogininfor(username,Constants.REGISTER,"注册成功");
} }
} }

View File

@ -91,21 +91,19 @@ public class ManyDataSource implements ApplicationRunner {
@Bean @Bean
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) { public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
List<EntInfo> entInfoList = dataSourceInfoList(); List<EntInfo> entInfoList = dataSourceInfoList();
if(StringUtils.isEmpty(entInfoList)){ if (StringUtils.isNotEmpty(entInfoList)) {
throw new SaaSException("数据信息列表为空或为null"); throw new SaaSException("数据信息列表为空或为null");
} }
Map<Object, Object> dataSourceMap = dataSourceInfoList().stream() Map<Object,Object> dataSourceMap = dataSourceInfoList().stream()
.map(entInfo -> DataSourceInfo.hostAndPortBuild( .map(entInfo -> DataSourceInfo.hostAndPortBuild(
entInfo.getEntCode(), entInfo.getEntCode(),
entInfo.getIp(), entInfo.getIp(),
entInfo.getPort() entInfo.getPort()
)
) )
.collect(Collectors.toMap( ).collect(Collectors.toMap(
dataSourceInfo -> dataSourceInfo.getKey(), dataSourceInfo -> dataSourceInfo.getKey(),
dataSourceInfo -> druidDataSourceFactory.create(dataSourceInfo) dataSourceInfo -> druidDataSourceFactory.create(dataSourceInfo)
)); ));
//设置动态数据源 //设置动态数据源
DynamicDataSource dynamicDataSource = new DynamicDataSource(); DynamicDataSource dynamicDataSource = new DynamicDataSource();
dynamicDataSource.setTargetDataSources(dataSourceMap); dynamicDataSource.setTargetDataSources(dataSourceMap);

View File

@ -1,8 +1,9 @@
package com.muyu.cloud.common.many.datasource.constents; package com.muyu.cloud.common.many.datasource.constents;
/** /**
* @Author: zi run *
* @Date 2024/9/20 14:52 * @Author chenruijia
* @Date 2024/9/29 17:52
* @Description * @Description
*/ */
public class DatasourceContent { public class DatasourceContent {

View File

@ -8,6 +8,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
*
* @Author: zi run * @Author: zi run
* @Date 2024/9/20 14:52 * @Date 2024/9/20 14:52
* @Description * @Description

View File

@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
import java.sql.SQLException; import java.sql.SQLException;
/** /**
* Druid
* @Author: zi run * @Author: zi run
* @Date 2024/9/20 14:52 * @Date 2024/9/20 14:52
* @Description Druid * @Description Druid

View File

@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
*
* @Author: zi run * @Author: zi run
* @Date 2024/9/20 14:52 * @Date 2024/9/20 14:52
* @Description * @Description

View File

@ -37,7 +37,6 @@ public class SysCarFault extends BaseEntity {
* *
*/ */
@Schema(defaultValue = "车辆故障编码",type = "String",description = "车辆故障编码") @Schema(defaultValue = "车辆故障编码",type = "String",description = "车辆故障编码")
@Excel
private String faultCode; private String faultCode;
/** /**
* ID * ID
@ -53,31 +52,26 @@ public class SysCarFault extends BaseEntity {
* VIN * VIN
*/ */
@Schema(defaultValue = "故障VIN编码",type = "String",description = "故障VIN编码") @Schema(defaultValue = "故障VIN编码",type = "String",description = "故障VIN编码")
@Excel
private String carVin; private String carVin;
/** /**
* *
*/ */
@Schema(defaultValue = "车辆故障标签",type = "String",description = "车辆故障标签") @Schema(defaultValue = "车辆故障标签",type = "String",description = "车辆故障标签")
@Excel
private String faultLabel; private String faultLabel;
/** /**
* *
*/ */
@Schema(defaultValue = "车辆故障位",type = "String",description = "车辆故障位") @Schema(defaultValue = "车辆故障位",type = "String",description = "车辆故障位")
@Excel
private String faultBit; private String faultBit;
/** /**
* *
*/ */
@Schema(defaultValue = "车辆故障值",type = "String",description = "车辆故障值") @Schema(defaultValue = "车辆故障值",type = "String",description = "车辆故障值")
@Excel
private String faultValue; private String faultValue;
/** /**
* *
*/ */
@Schema(defaultValue = "故障级别",type = "String",description = "故障级别") @Schema(defaultValue = "故障级别",type = "String",description = "故障级别")
@Excel
private String faultWarn; private String faultWarn;
/** /**
* Y.N. * Y.N.
@ -88,7 +82,6 @@ public class SysCarFault extends BaseEntity {
* *
*/ */
@Schema(defaultValue = "故障描述信息",type = "String",description = "故障描述信息") @Schema(defaultValue = "故障描述信息",type = "String",description = "故障描述信息")
@Excel
private String faultDesc; private String faultDesc;
/** /**
* (1. 2. 3. 4.) * (1. 2. 3. 4.)

View File

@ -83,6 +83,14 @@
<artifactId>cloud-modules-enterprise-common</artifactId> <artifactId>cloud-modules-enterprise-common</artifactId>
</dependency> </dependency>
<!-- MySQL连接支持 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency> <dependency>
<groupId>com.github.yulichang</groupId> <groupId>com.github.yulichang</groupId>
<artifactId>mybatis-plus-join</artifactId> <artifactId>mybatis-plus-join</artifactId>

View File

@ -40,7 +40,7 @@ public class SysCarFaultController extends BaseController
* *
*/ */
@RequestMapping(value = "/list", method = RequestMethod.GET) @RequestMapping(value = "/list", method = RequestMethod.GET)
public Result<List<SysCarFault>> list(@RequestBody SysCarFault sysCarFault) public Result<List<SysCarFault>> list(SysCarFault sysCarFault)
{ {
List<SysCarFault> list = sysCarFaultService.selectSysCarFaultList(sysCarFault); List<SysCarFault> list = sysCarFaultService.selectSysCarFaultList(sysCarFault);
return success(list); return success(list);

View File

@ -28,7 +28,7 @@ import java.util.List;
@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
@RequestMapping(value = "/ent") @RequestMapping(value = "/ent")
@Tag(name = "SysEntController",description = "企业管理") @Tag(name = "企业信息",description = "企业管理")
public class SysEntController extends BaseController { public class SysEntController extends BaseController {
/** /**
@ -66,7 +66,7 @@ public class SysEntController extends BaseController {
* @param entId ID * @param entId ID
* @return * @return
*/ */
@GetMapping(value = "/{entId}") @GetMapping(value = "/getById/{entId}")
@Operation(summary = "根据ID获取企业信息", description = "根据企业唯一标识获取单体企业信息") @Operation(summary = "根据ID获取企业信息", description = "根据企业唯一标识获取单体企业信息")
public Result<EntResp> getById( public Result<EntResp> getById(
@Schema(title = "企业ID", type = "Long", defaultValue = "1", description = "企业唯一标识") @Schema(title = "企业ID", type = "Long", defaultValue = "1", description = "企业唯一标识")
@ -79,7 +79,7 @@ public class SysEntController extends BaseController {
* @param entAddReq * @param entAddReq
* @return * @return
*/ */
@PostMapping @PostMapping(value = "/save")
@Operation(summary = "添加企业信息", description = "将企业信息添加到系统中") @Operation(summary = "添加企业信息", description = "将企业信息添加到系统中")
public Result<String> save(@Validated @RequestBody EntAddReq entAddReq) { public Result<String> save(@Validated @RequestBody EntAddReq entAddReq) {
sysEntService.save(EntAddReq.addBuild(entAddReq)); sysEntService.save(EntAddReq.addBuild(entAddReq));
@ -92,7 +92,7 @@ public class SysEntController extends BaseController {
* @param entUpdateReq * @param entUpdateReq
* @return * @return
*/ */
@PutMapping(value = "/{entId}") @PutMapping(value = "/update/{entId}")
@Operation(summary = "修改企业信息",description = "根据企业唯一标识修改企业信息") @Operation(summary = "修改企业信息",description = "根据企业唯一标识修改企业信息")
public Result<String> update(@Schema(title = "企业ID",type = "Long",defaultValue = "1",description = "企业唯一标识") public Result<String> update(@Schema(title = "企业ID",type = "Long",defaultValue = "1",description = "企业唯一标识")
@NotNull(message = "企业ID不能为空") @PathVariable(value = "entId") Long entId, @NotNull(message = "企业ID不能为空") @PathVariable(value = "entId") Long entId,
@ -106,13 +106,11 @@ public class SysEntController extends BaseController {
* @param entId ID * @param entId ID
* @return * @return
*/ */
@RequestMapping(value = "/entId",method = RequestMethod.DELETE) @RequestMapping(value = "/remove/{entId}",method = RequestMethod.DELETE)
@Operation(summary = "删除企业信息",description = "根据企业唯一标识删除企业记录") @Operation(summary = "删除企业信息",description = "根据企业唯一标识删除企业记录")
public Result<String> remove(@Schema(title = "企业ID",type = "Long",defaultValue = "1",description = "企业唯一标识") public Result<String> remove(@Schema(title = "企业ID",type = "Long",defaultValue = "1",description = "企业唯一标识")
@NotNull(message = "企业ID不能为空") @PathVariable(value = "entId")Long entId){ @NotNull(message = "企业ID不能为空") @PathVariable(value = "entId")Long entId){
sysEntService.removeById(entId); sysEntService.removeById(entId);
return Result.success(null,Constants.SUCCESS_MESSAGE); return Result.success(null,Constants.SUCCESS_MESSAGE);
} }
// @RequestMapping(value = "findId",)
} }

View File

@ -16,6 +16,7 @@ import com.muyu.system.domain.resp.AuthRoleResp;
import com.muyu.system.domain.resp.UserDetailInfoResp; import com.muyu.system.domain.resp.UserDetailInfoResp;
import com.muyu.system.domain.resp.UserInfoResp; import com.muyu.system.domain.resp.UserInfoResp;
import com.muyu.system.service.*; import com.muyu.system.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -23,6 +24,11 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -32,6 +38,7 @@ import java.util.stream.Collectors;
* *
* @author muyu * @author muyu
*/ */
@Slf4j
@RestController @RestController
@RequestMapping("/user") @RequestMapping("/user")
public class SysUserController extends BaseController { public class SysUserController extends BaseController {
@ -119,11 +126,17 @@ public class SysUserController extends BaseController {
@InnerAuth @InnerAuth
@PostMapping("/register") @PostMapping("/register")
public Result<Boolean> register (@RequestBody RegisterBody registerBody) { public Result<Boolean> register (@RequestBody RegisterBody registerBody) {
// String username = registerBody.getUsername();
String username = registerBody.getUsername(); String username = registerBody.getUsername();
SysUser sysUser = new SysUser();
sysUser.setUserName(username);
if (!userService.checkUserNameUnique(sysUser)) {
return Result.error("保存用户'" + username + "'失败,注册账号已存在");
}
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) { if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
return Result.error("当前系统没有开启注册功能!"); return Result.error("当前系统没有开启注册功能!");
} }
SysUser sysUser = SysUser.builder().userName(username).build(); // SysUser sysUser = SysUser.builder().userName(username).build();
if (!userService.checkUserNameUnique(sysUser)) { if (!userService.checkUserNameUnique(sysUser)) {
return Result.error("保存用户'" + username + "'失败,注册账号已存在"); return Result.error("保存用户'" + username + "'失败,注册账号已存在");
} }
@ -151,7 +164,64 @@ public class SysUserController extends BaseController {
sysUser.setDeptId(sysDept.getDeptId()); sysUser.setDeptId(sysDept.getDeptId());
sysUser.setNickName(registerBody.getUsername()); sysUser.setNickName(registerBody.getUsername());
sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword())); sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword()));
sysUser.setNickName("注册");
boolean b = userService.registerUser(sysUser);
if (b == true) {
//数据库驱动
String mysqlDriver = "com.mysql.jdbc.Driver";
//数据库地址
String url = "jdbc:mysql://106.15.136.7:3306/";
//数据库用户名
String name = "root";
//数据库密码
String password = "Six@211206";
Collection collection = null;
Collection stmt = null;
//创建数据库SQL
try {
Class.forName(mysqlDriver);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
String databaseSQL = "create database "+username ;
//添加企业信息
String tableSQL = "create table sys_ent (id int auto_increment primary key comment '主键id'," +
"name varchar(16) comment '企业名称'," +
"leader varchar(16) comment '负责人'," +
"phone varchar(11) comment '联系电话'," +
"email varchar(32) comment '邮箱'," +
"ent_code varchar(64) comment '企业编码'," +
"ent_status varchar(64) comment '企业状态'," +
"create_by varchar(32) comment '创建人'," +
"update_by varchar(32) comment '创建时间'," +
"create_time datetime comment '修改人'," +
"update_time datetime comment '修改时间'," +
"remark varchar(32) comment '备注')";
//连接数据库
try {
Connection connection = DriverManager.getConnection(url, name, password);
//用于执行编译sql语句的对象
Statement connStatement = connection.createStatement();
if (connection != null) {
//执行建库语句
connStatement.executeUpdate(databaseSQL);
log.info("创建数据库成功");
//连接新建数据库
Connection connection1 = DriverManager.getConnection(url + username, name, password);
if (connection1 != null) {
log.info("连接数据库成功"+username);
Statement statement = connection1.createStatement();
//执行建表语句
statement.executeUpdate(tableSQL);
log.info("创建表成功");
return Result.success();
}
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return Result.success(userService.registerUser(sysUser)); return Result.success(userService.registerUser(sysUser));
} }