feat(完善多数据源)
commit
b03a40ab79
|
@ -15,6 +15,10 @@ public class ServiceNameConstants {
|
|||
* 系统模块的serviceid
|
||||
*/
|
||||
public static final String SYSTEM_SERVICE = "ruoyi-system";
|
||||
/**
|
||||
* 企业模块
|
||||
*/
|
||||
public static final String COMPANY_ENTERPRISE = "ruoyi-company";
|
||||
|
||||
/**
|
||||
* 文件服务的serviceid
|
||||
|
|
|
@ -39,5 +39,11 @@
|
|||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||
<version>4.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-company-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -2,11 +2,15 @@ package com.muyu.clw.common.many.datasource;
|
|||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.muyu.clw.common.many.datasource.domain.model.DataSourceInfo;
|
||||
import com.muyu.clw.common.many.remote.RemoteEnterpriseService;
|
||||
import com.muyu.clw.common.saas.domain.model.EntInfo;
|
||||
import com.muyu.clw.common.many.datasource.factory.DruidDataSourceFactory;
|
||||
import com.muyu.clw.common.many.datasource.role.DynamicDataSource;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import com.muyu.domain.Enterprise;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -30,22 +34,33 @@ import java.util.Map;
|
|||
@Log4j2
|
||||
@Component
|
||||
public class ManyDataSource {
|
||||
public static List<EntInfo> dataSourceInfoList() {
|
||||
@Autowired
|
||||
private RemoteEnterpriseService remoteEnterpriseService;
|
||||
public List<EntInfo> dataSourceInfoList() {
|
||||
|
||||
Result<List<Enterprise>> enterprise = remoteEnterpriseService.enterpriseAllList();
|
||||
|
||||
List<Enterprise> enterpriseList = enterprise.getData();
|
||||
|
||||
|
||||
List<EntInfo> list = new ArrayList<>();
|
||||
|
||||
for (Enterprise enterprise1 : enterpriseList) {
|
||||
list.add(
|
||||
EntInfo.builder()
|
||||
.entCode("ent_6330")
|
||||
.entCode("ent_"+enterprise1.getContactPhone().substring(enterprise1.getContactPhone().length()-4))
|
||||
.ip("123.56.102.11")
|
||||
.port(3308)
|
||||
.port((int) (3306+enterprise1.getId()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public static DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
||||
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
||||
|
||||
Map<Object, Object> dataSourceMap = new HashMap<>();
|
||||
dataSourceInfoList()
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.clw.common.many.remote;
|
||||
|
||||
import com.muyu.clw.common.many.remote.factory.RemoteEnterpriseFallbackFactory;
|
||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.domain.Enterprise;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务
|
||||
*
|
||||
* @author muyu
|
||||
*/
|
||||
@FeignClient(
|
||||
contextId = "remoteEnterpriseService",
|
||||
value = ServiceNameConstants.COMPANY_ENTERPRISE,
|
||||
fallbackFactory = RemoteEnterpriseFallbackFactory.class
|
||||
)
|
||||
public interface RemoteEnterpriseService {
|
||||
|
||||
@GetMapping("/enterprise/enterpriseAllList")
|
||||
public Result<List<Enterprise>> enterpriseAllList();
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.clw.common.many.remote.factory;
|
||||
|
||||
import com.muyu.clw.common.many.remote.RemoteEnterpriseService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.domain.Enterprise;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName RemoteEnterpriseFallbackFactory
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/6/7 21:55
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class RemoteEnterpriseFallbackFactory implements FallbackFactory<RemoteEnterpriseService> {
|
||||
private static final Logger log = LoggerFactory.getLogger(RemoteEnterpriseFallbackFactory.class);
|
||||
|
||||
@Override
|
||||
public RemoteEnterpriseService create(Throwable cause) {
|
||||
log.error("日志服务调用失败:{}", cause.getMessage());
|
||||
return new RemoteEnterpriseService() {
|
||||
@Override
|
||||
public Result<List<Enterprise>> enterpriseAllList() {
|
||||
return Result.error("企业获取失败:{}"+cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -2,3 +2,4 @@ com.muyu.clw.common.saas.interceptor.WebMvcSaaSConfig
|
|||
com.muyu.clw.common.many.datasource.factory.DruidDataSourceFactory
|
||||
com.muyu.clw.common.many.datasource.ManyDataSource
|
||||
com.muyu.clw.common.saas.domain.model.EntInfo
|
||||
com.muyu.clw.common.many.remote.factory.RemoteEnterpriseFallbackFactory
|
||||
|
|
|
@ -89,7 +89,7 @@ public class Enterprise extends BaseEntity
|
|||
@Excel(name = "服务级别")
|
||||
private Integer serviceLevel;
|
||||
|
||||
/** 开通服务id */
|
||||
/** 开通服务级别*/
|
||||
@Excel(name = "开通服务级别")
|
||||
private Integer openServerId;
|
||||
private String openServerId;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.domain.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 查询企业信息
|
||||
*
|
||||
* @ClassName EnterpriseReq
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/6/7 15:26
|
||||
*/
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EnterpriseReq {
|
||||
private String legalPerson;
|
||||
private String contactPhone;
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.muyu.authentication.service.IEnterpriseService;
|
||||
import com.muyu.domain.vo.EnterpriseReq;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.muyu.common.log.annotation.Log;
|
||||
|
@ -25,6 +26,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
@RequestMapping("/enterprise")
|
||||
public class EnterpriseController extends BaseController
|
||||
{
|
||||
|
||||
@Autowired
|
||||
private IEnterpriseService enterpriseService;
|
||||
|
||||
|
@ -96,5 +98,31 @@ public class EnterpriseController extends BaseController
|
|||
return toAjax(enterpriseService.deleteEnterpriseByIds(ids));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/enterpriseList")
|
||||
public Result<Enterprise> enterpriseList(@RequestBody EnterpriseReq enterpriseReq){
|
||||
return Result.success(
|
||||
enterpriseService.enterpriseList(enterpriseReq)
|
||||
);
|
||||
}
|
||||
|
||||
@PostMapping("/enterpriseUpdate")
|
||||
public Result<String> enterpriseUpdate(@RequestBody Enterprise enterprise){
|
||||
return Result.success(
|
||||
enterpriseService.enterpriseUpdate(enterprise)
|
||||
);
|
||||
}
|
||||
|
||||
@PostMapping("/enterpriseUpdateId")
|
||||
public Result<String> enterpriseUpdateId(@RequestParam Long id){
|
||||
return Result.success(
|
||||
enterpriseService.enterpriseUpdateId(id)
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/enterpriseAllList")
|
||||
public Result<List<Enterprise>> enterprise(){
|
||||
return Result.success(
|
||||
enterpriseService.list()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.domain.Enterprise;
|
||||
import com.muyu.domain.vo.EnterpriseReq;
|
||||
|
||||
/**
|
||||
* 企业Service接口
|
||||
|
@ -61,4 +62,10 @@ public interface IEnterpriseService extends IService<Enterprise>
|
|||
*/
|
||||
public int deleteEnterpriseById(Long id);
|
||||
|
||||
Enterprise enterpriseList(EnterpriseReq enterpriseReq);
|
||||
|
||||
String enterpriseUpdate(Enterprise enterprise);
|
||||
|
||||
String enterpriseUpdateId(Long id);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,21 @@
|
|||
package com.muyu.authentication.service.impl;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.muyu.authentication.mapper.EnterpriseMapper;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import com.muyu.domain.vo.EnterpriseReq;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -122,4 +130,95 @@ public class EnterpriseServiceImpl extends ServiceImpl<EnterpriseMapper,Enterpri
|
|||
{
|
||||
return enterpriseMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enterprise enterpriseList(EnterpriseReq enterpriseReq) {
|
||||
return enterpriseMapper.selectOne(
|
||||
new LambdaQueryWrapper<>(){{
|
||||
eq(Enterprise::getLegalPerson, enterpriseReq.getLegalPerson());
|
||||
eq(Enterprise::getContactPhone, enterpriseReq.getContactPhone());
|
||||
}}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String enterpriseUpdate(Enterprise enterprise) {
|
||||
return enterpriseMapper.updateById(
|
||||
Enterprise.builder()
|
||||
.id(enterprise.getId())
|
||||
.enterpriseName(enterprise.getEnterpriseName())
|
||||
.legalPerson(enterprise.getLegalPerson())
|
||||
.businessLicenseNumber(enterprise.getBusinessLicenseNumber())
|
||||
.establishmentDate(enterprise.getEstablishmentDate())
|
||||
.businessScope(enterprise.getBusinessScope())
|
||||
.address(enterprise.getAddress())
|
||||
.contactPhone(enterprise.getContactPhone())
|
||||
.email(enterprise.getEmail())
|
||||
.status(enterprise.getStatus())
|
||||
.registrationDate(enterprise.getRegistrationDate())
|
||||
.authenticationDate(enterprise.getAuthenticationDate())
|
||||
.examineStatus(0)
|
||||
.build()
|
||||
)>0?"提交审核成功":"提交审核失败";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String enterpriseUpdateId(Long id) {
|
||||
String s = enterpriseMapper.updateById(
|
||||
Enterprise.builder()
|
||||
.id(id)
|
||||
.authenticationDate(new Date())
|
||||
.examineStatus(1)
|
||||
.serviceLevel(1)
|
||||
.openServerId("初级")
|
||||
.build()
|
||||
) > 0 ? "审核成功" : "审核失败";
|
||||
if (s.equals("审核成功")) {
|
||||
Enterprise enterprise = enterpriseMapper.selectOne(
|
||||
new LambdaQueryWrapper<>() {{
|
||||
eq(Enterprise::getId, id);
|
||||
}}
|
||||
);
|
||||
try {
|
||||
getHttp(enterprise);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return s;
|
||||
}else {
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void getHttp(Enterprise enterprise) throws Exception {
|
||||
// 创建HttpClient实例
|
||||
HttpClient httpClient = HttpClient.newHttpClient();
|
||||
|
||||
String substring = enterprise.getContactPhone().substring(enterprise.getContactPhone().length() - 4);
|
||||
// 创建参数JSON对象
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ObjectNode requestBody = objectMapper.createObjectNode();
|
||||
requestBody.put("entId", "ent_"+substring+"_"+(3306+enterprise.getId()));
|
||||
requestBody.put("mysqlPort", 3306+enterprise.getId());
|
||||
String jsonBody = objectMapper.writeValueAsString(requestBody);
|
||||
|
||||
// 创建httpRequest
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://101.34.243.166/webhook/创建企业数据库"))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(jsonBody))
|
||||
.build();
|
||||
|
||||
// 发送请求并获取响应
|
||||
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
// 处理响应
|
||||
int statusCode = response.statusCode();
|
||||
String responseBody = response.body();
|
||||
log.info("状态码:{}",statusCode);
|
||||
log.info("响应:{}",responseBody);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
/**
|
||||
* @ClassName Text
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/6/7 18:45
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public class Text {
|
||||
public static void getHttp() throws Exception {
|
||||
// 创建HttpClient实例
|
||||
HttpClient httpClient = HttpClient.newHttpClient();
|
||||
|
||||
// 创建参数JSON对象
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ObjectNode requestBody = objectMapper.createObjectNode();
|
||||
requestBody.put("entId", "ent_9999_240529");
|
||||
requestBody.put("mysqlPort", "3200");
|
||||
String jsonBody = objectMapper.writeValueAsString(requestBody);
|
||||
|
||||
// 创建httpRequest
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://101.34.243.166/webhook/创建企业数据库"))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(jsonBody))
|
||||
.build();
|
||||
|
||||
// 发送请求并获取响应
|
||||
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
// 处理响应
|
||||
int statusCode = response.statusCode();
|
||||
String responseBody = response.body();
|
||||
System.out.println("状态码: " + statusCode);
|
||||
System.out.println("响应: " + responseBody);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
getHttp();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue