更新项目
parent
10341472e9
commit
efae57b545
|
@ -3,7 +3,7 @@
|
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu</artifactId>
|
||||
<artifactId>muyu-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -46,11 +46,15 @@
|
|||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Security-->
|
||||
<!-- muyu Common Security-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -78,5 +82,4 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
package com.muyu.auth.service;
|
||||
|
||||
import com.muyu.common.core.constant.CacheConstants;
|
||||
import com.muyu.common.core.constant.Constants;
|
||||
import com.muyu.common.core.constant.SecurityConstants;
|
||||
|
@ -12,9 +11,9 @@ 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.remote.RemoteUserService;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package com.muyu.auth.service;
|
||||
|
||||
|
||||
import com.muyu.common.core.constant.Constants;
|
||||
import com.muyu.common.core.constant.SecurityConstants;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.core.utils.ip.IpUtils;
|
||||
import com.muyu.common.system.remote.RemoteLogService;
|
||||
import com.muyu.common.system.domain.SysLogininfor;
|
||||
import com.muyu.common.system.remote.RemoteLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@ spring:
|
|||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 127.0.0.1:8848
|
||||
server-addr: 175.24.138.82:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 127.0.0.1:8848
|
||||
server-addr: 175.24.138.82:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-business</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-data-plus</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
|
@ -0,0 +1,133 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-business</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-data-service</artifactId>
|
||||
<description>
|
||||
muyu-data-service运营中心
|
||||
</description>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join</artifactId>
|
||||
<version>1.2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-business</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</dependency>
|
||||
<!--rabbitMQ-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-system</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger UI -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- muyu Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- muyu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- muyu Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- muyu Common Swagger -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- 加入maven deploy插件,当在deploy时,忽略些model-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.business.Job;
|
||||
|
||||
|
||||
|
||||
import com.muyu.business.service.impl.EntinfoServiceImpl;
|
||||
import com.muyu.common.business.domain.Entinfo;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName ManyJob
|
||||
* @Date 2024/06/06 18:32
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class ManyJob {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private EntinfoServiceImpl entinfoService;
|
||||
|
||||
|
||||
// @Scheduled(cron = "*/10 * * * * *") // 每10分钟执行一次
|
||||
public void manyJob(){
|
||||
redisService.deleteObject("entinfo");
|
||||
List<Entinfo> list = entinfoService.list();
|
||||
redisService.setCacheList("entinfo",list);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.business;
|
||||
|
||||
|
||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName muyuBusinessApplication
|
||||
* @Date 2024/05/26 15:00
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class MuyuBusinessApplication {
|
||||
public static void main (String[] args) {
|
||||
SpringApplication.run(MuyuBusinessApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.muyu.business.config;
|
||||
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* 消息发送确认配置 消息发送到交换机的确认
|
||||
*/
|
||||
@Component
|
||||
public class ConfirmCallbackConfig implements RabbitTemplate.ConfirmCallback {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
/**
|
||||
* @PostContruct是spring框架的注解,在⽅法上加该注解会在项⽬启动的时候执⾏该⽅法,也可以理解为在spring容器初始化的时候执
|
||||
* @PostConstruct bean 被初始化的时候执行的方法的注解
|
||||
* @PreDestory bean 被销毁的时候执行的方法的注解
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
rabbitTemplate.setConfirmCallback(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 交换机不管是否收到消息的一个回调方法
|
||||
*
|
||||
* @param correlationData 消息相关数据
|
||||
* @param ack 交换机是否收到消息
|
||||
* @param cause 失败原因
|
||||
*/
|
||||
@Override
|
||||
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
||||
if (ack) {
|
||||
// 消息投递到 broker 的状态,true表示成功
|
||||
System.out.println("消息发送成功!");
|
||||
} else {
|
||||
// 发送异常
|
||||
System.out.println("发送异常原因 = " + cause);
|
||||
// TODO 可以将消息 内容 以及 失败的原因 记录到 日志表中
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.business.config;
|
||||
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* RabbitAdmin是RabbitMQ的一个Java客户端库,它提供了管理RabbitMQ资源的功能。它是通过与RabbitMQ服务器进行交互来执行管理操作的。
|
||||
*/
|
||||
@Configuration
|
||||
public class RabbitAdminConfig {
|
||||
|
||||
@Value("${spring.rabbitmq.host}")
|
||||
private String host;
|
||||
@Value("${spring.rabbitmq.username}")
|
||||
private String username;
|
||||
@Value("${spring.rabbitmq.password}")
|
||||
private String password;
|
||||
@Value("${spring.rabbitmq.virtualhost}")
|
||||
private String virtualhost;
|
||||
|
||||
/**
|
||||
* 构建 RabbitMQ的连接工厂
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public ConnectionFactory connectionFactory() {
|
||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
||||
connectionFactory.setAddresses(host);
|
||||
connectionFactory.setUsername(username);
|
||||
connectionFactory.setPassword(password);
|
||||
connectionFactory.setVirtualHost(virtualhost);
|
||||
// 配置发送确认回调时,次配置必须配置,否则即使在RabbitTemplate配置了ConfirmCallback也不会生效
|
||||
connectionFactory.setPublisherConfirmType(CachingConnectionFactory.ConfirmType.CORRELATED);
|
||||
connectionFactory.setPublisherReturns(true);
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自己初始化 RabbitAdmin
|
||||
* @param connectionFactory
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
|
||||
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
|
||||
rabbitAdmin.setAutoStartup(true);
|
||||
return rabbitAdmin;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.business.config;
|
||||
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class RabbitmqConfig {
|
||||
// 消息转换配置
|
||||
@Bean
|
||||
public MessageConverter jsonMessageConverter() {
|
||||
// 使用json序列化方式,进行消息转换
|
||||
return new Jackson2JsonMessageConverter();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.business.config;
|
||||
|
||||
import org.springframework.amqp.core.ReturnedMessage;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* 消息发送到队列的确认 一旦消息发送到队列失败 则会执行 returnedMessage 方法
|
||||
*/
|
||||
@Component
|
||||
public class ReturnCallbackConfig implements RabbitTemplate.ReturnsCallback {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@PostConstruct // @PostContruct是spring框架的注解,在⽅法上加该注解会在项⽬启动的时候执⾏该⽅法,也可以理解为在spring容器初始化的时候执
|
||||
public void init() {
|
||||
rabbitTemplate.setReturnsCallback(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息发送到 队列失败 执行的 方法
|
||||
* @param returnedMessage the returned message and metadata.
|
||||
*/
|
||||
@Override
|
||||
public void returnedMessage(ReturnedMessage returnedMessage) {
|
||||
System.out.println("消息" + returnedMessage.getMessage().toString() + "被交换机" + returnedMessage.getExchange() + "回退!"
|
||||
+ "退回原因为:" + returnedMessage.getReplyText());
|
||||
// 回退了所有的信息,可做补偿机制 记录到 数据库
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package com.muyu.business.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import com.muyu.business.domain.Business;
|
||||
import com.muyu.business.service.IBusinessService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.common.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
/**
|
||||
* 企业Controller
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-05-26
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/business")
|
||||
public class BusinessController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IBusinessService businessService;
|
||||
|
||||
/**
|
||||
* 查询企业列表
|
||||
*/
|
||||
// @RequiresPermissions("system:business:list")
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<Business>> list(Business business)
|
||||
{
|
||||
startPage();
|
||||
List<Business> list = businessService.selectBusinessList(business);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出企业列表
|
||||
*/
|
||||
// @RequiresPermissions("system:business:export")
|
||||
@Log(title = "企业", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Business business)
|
||||
{
|
||||
List<Business> list = businessService.selectBusinessList(business);
|
||||
ExcelUtil<Business> util = new ExcelUtil<Business>(Business.class);
|
||||
util.exportExcel(response, list, "企业数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业详细信息
|
||||
*/
|
||||
// @RequiresPermissions("system:business:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(businessService.selectBusinessById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增企业
|
||||
*/
|
||||
// @RequiresPermissions("system:business:add")
|
||||
@Log(title = "企业", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public Result add(@RequestBody Business business)
|
||||
{
|
||||
return toAjax(businessService.insertBusiness(business));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改企业
|
||||
*/
|
||||
// @RequiresPermissions("system:business:edit")
|
||||
@Log(title = "企业", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public Result edit(@RequestBody Business business)
|
||||
{
|
||||
return toAjax(businessService.updateBusiness(business));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除企业
|
||||
*/
|
||||
// @RequiresPermissions("system:business:remove")
|
||||
@Log(title = "企业", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(businessService.deleteBusinessByIds(ids));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
package com.muyu.business.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.muyu.business.domain.Cart;
|
||||
import com.muyu.business.domain.CartVo;
|
||||
import com.muyu.business.service.IEntinfoService;
|
||||
import com.muyu.business.service.PlusService;
|
||||
import com.muyu.common.business.domain.Entinfo;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.common.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 多数据源Controller
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/entinfo")
|
||||
public class EntinfoController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IEntinfoService entinfoService;
|
||||
|
||||
@Autowired
|
||||
private PlusService plusService;
|
||||
|
||||
@PostMapping("cartLiat")
|
||||
public Result cartList(@RequestBody CartVo cartVo){
|
||||
List<Cart> list = plusService.list();
|
||||
System.out.println(list);
|
||||
return plusService.cartList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询多数据源列表
|
||||
*/
|
||||
// @RequiresPermissions("system:entinfo:list")
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<Entinfo>> list(Entinfo entinfo)
|
||||
{
|
||||
startPage();
|
||||
List<Entinfo> list = entinfoService.selectEntinfoList(entinfo);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping("listAll")
|
||||
public List<Entinfo> listAll(){
|
||||
List<Entinfo> list = entinfoService.list();
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出多数据源列表
|
||||
*/
|
||||
// @RequiresPermissions("system:entinfo:export")
|
||||
@Log(title = "多数据源", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Entinfo entinfo)
|
||||
{
|
||||
List<Entinfo> list = entinfoService.selectEntinfoList(entinfo);
|
||||
ExcelUtil<Entinfo> util = new ExcelUtil<Entinfo>(Entinfo.class);
|
||||
util.exportExcel(response, list, "多数据源数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多数据源详细信息
|
||||
*/
|
||||
// @RequiresPermissions("system:entinfo:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(entinfoService.selectEntinfoById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增多数据源
|
||||
*/
|
||||
// @RequiresPermissions("system:entinfo:add")
|
||||
@Log(title = "多数据源", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public Result add(@RequestBody Entinfo entinfo)
|
||||
{
|
||||
return toAjax(entinfoService.insertEntinfo(entinfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改多数据源
|
||||
*/
|
||||
// @RequiresPermissions("system:entinfo:edit")
|
||||
@Log(title = "多数据源", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public Result edit(@RequestBody Entinfo entinfo)
|
||||
{
|
||||
return toAjax(entinfoService.updateEntinfo(entinfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除多数据源
|
||||
*/
|
||||
// @RequiresPermissions("system:entinfo:remove")
|
||||
@Log(title = "多数据源", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(entinfoService.deleteEntinfoByIds(ids));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.business.controller;
|
||||
|
||||
|
||||
import com.muyu.business.domain.Business;
|
||||
import com.muyu.business.mapper.BusinessMapper;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName PlusController
|
||||
* @Date 2024/06/09 15:28
|
||||
*/
|
||||
public class PlusController{
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.business.domain;
|
||||
|
||||
|
||||
import com.muyu.common.system.domain.SysRole;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xiaohuang
|
||||
* @description: 授权角色返回结果集
|
||||
* @Date 2023-6-19 下午 02:50
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AuthRoleResp {
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
private SysUser user;
|
||||
|
||||
/**
|
||||
* 角色集合
|
||||
*/
|
||||
private List<SysRole> roles;
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package com.muyu.business.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* 企业对象 business
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-05-26
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("business")
|
||||
public class Business extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 企业主键 */
|
||||
@Excel(name = "企业主键")
|
||||
@TableId( type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/** 企业名称 */
|
||||
@Excel(name = "企业名称")
|
||||
private String name;
|
||||
|
||||
/** 企业法定代表人 */
|
||||
@Excel(name = "企业法定代表人")
|
||||
private String businessPerson;
|
||||
|
||||
/** 营业编码 */
|
||||
@Excel(name = "营业编码")
|
||||
private String businessLincenseNumber;
|
||||
|
||||
/** 企业创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "企业创建时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date businessCreateTime;
|
||||
|
||||
/** 企业电话 */
|
||||
@Excel(name = "企业电话")
|
||||
private String businessPhone;
|
||||
|
||||
/** 企业邮箱 */
|
||||
@Excel(name = "企业邮箱")
|
||||
private String businessEmail;
|
||||
|
||||
/** 企业状态 */
|
||||
@Excel(name = "企业状态")
|
||||
private String businessStates;
|
||||
|
||||
/** 入驻车联网平台时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "入驻车联网平台时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date businessRegistrationDate;
|
||||
|
||||
/** 服务等级0/1/2 */
|
||||
@Excel(name = "服务等级0/1/2")
|
||||
private String serviceLevel;
|
||||
|
||||
/** 认证等级0/1 */
|
||||
@Excel(name = "认证等级0/1")
|
||||
private String authentication;
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.business.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName Cart
|
||||
* @Date 2024/06/09 15:40
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("cart")
|
||||
public class Cart {
|
||||
|
||||
// @TableId
|
||||
private Long id;
|
||||
|
||||
// @TableField(value = "name")
|
||||
private String name;
|
||||
|
||||
// @TableField(value = "type_id")
|
||||
private Long typeId;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.business.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName BusinessVo
|
||||
* @Date 2024/06/09 15:34
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class CartVo {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String typeName;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.muyu.business.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName Type
|
||||
* @Date 2024/06/09 15:40
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("type")
|
||||
public class Type {
|
||||
|
||||
// @TableId
|
||||
private Long id;
|
||||
|
||||
// @TableField(value = "type_name")
|
||||
private String typeName;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.business.feign;
|
||||
|
||||
|
||||
|
||||
import com.muyu.common.business.domain.Entinfo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName EntInfoFeign
|
||||
* @Date 2024/06/07 17:25
|
||||
*/
|
||||
@FeignClient(value = "muyu-business-service")
|
||||
public interface EntInfoFeign {
|
||||
@GetMapping("/entinfo/listAll")
|
||||
public List<Entinfo> listAll();
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.business.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.business.domain.Business;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 企业Mapper接口
|
||||
* @date 2024-05-26
|
||||
*/
|
||||
public interface BusinessMapper extends BaseMapper<Business>
|
||||
{
|
||||
/**
|
||||
* 查询企业
|
||||
*
|
||||
* @param id 企业主键
|
||||
* @return 企业
|
||||
*/
|
||||
public Business selectBusinessById(Long id);
|
||||
|
||||
/**
|
||||
* 查询企业列表
|
||||
*
|
||||
* @param business 企业
|
||||
* @return 企业集合
|
||||
*/
|
||||
public List<Business> selectBusinessList(Business business);
|
||||
|
||||
/**
|
||||
* 新增企业
|
||||
*
|
||||
* @param business 企业
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertBusiness(Business business);
|
||||
|
||||
/**
|
||||
* 修改企业
|
||||
*
|
||||
* @param business 企业
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateBusiness(Business business);
|
||||
|
||||
/**
|
||||
* 删除企业
|
||||
*
|
||||
* @param id 企业主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteBusinessById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除企业
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteBusinessByIds(Long[] ids);
|
||||
|
||||
Result<LoginUser> info(@Param("userId") Long userId);
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.muyu.business.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.common.business.domain.Entinfo;
|
||||
|
||||
/**
|
||||
* 多数据源Mapper接口
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
public interface EntinfoMapper extends BaseMapper<Entinfo>
|
||||
{
|
||||
/**
|
||||
* 查询多数据源
|
||||
*
|
||||
* @param id 多数据源主键
|
||||
* @return 多数据源
|
||||
*/
|
||||
public Entinfo selectEntinfoById(Long id);
|
||||
|
||||
/**
|
||||
* 查询多数据源列表
|
||||
*
|
||||
* @param entinfo 多数据源
|
||||
* @return 多数据源集合
|
||||
*/
|
||||
public List<Entinfo> selectEntinfoList(Entinfo entinfo);
|
||||
|
||||
/**
|
||||
* 新增多数据源
|
||||
*
|
||||
* @param entinfo 多数据源
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertEntinfo(Entinfo entinfo);
|
||||
|
||||
/**
|
||||
* 修改多数据源
|
||||
*
|
||||
* @param entinfo 多数据源
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateEntinfo(Entinfo entinfo);
|
||||
|
||||
/**
|
||||
* 删除多数据源
|
||||
*
|
||||
* @param id 多数据源主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEntinfoById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除多数据源
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEntinfoByIds(Long[] ids);
|
||||
|
||||
Entinfo selectEntinfo(Entinfo business);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.business.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.muyu.business.domain.Cart;
|
||||
import com.muyu.business.domain.CartVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName PlusMapper
|
||||
* @Date 2024/06/09 15:33
|
||||
*/
|
||||
@Mapper
|
||||
public interface PlusMapper extends MPJBaseMapper<Cart> {
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.business.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.muyu.business.domain.Cart;
|
||||
import com.muyu.business.domain.Type;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName PlusMapper
|
||||
* @Date 2024/06/09 15:33
|
||||
*/
|
||||
@Mapper
|
||||
public interface TypeMapper extends BaseMapper<Type> {
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.muyu.business.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.business.domain.Business;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 企业Service接口
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-05-26
|
||||
*/
|
||||
public interface IBusinessService extends IService<Business>
|
||||
{
|
||||
/**
|
||||
* 查询企业
|
||||
*
|
||||
* @param id 企业主键
|
||||
* @return 企业
|
||||
*/
|
||||
public Business selectBusinessById(Long id);
|
||||
|
||||
/**
|
||||
* 查询企业列表
|
||||
*
|
||||
* @param business 企业
|
||||
* @return 企业集合
|
||||
*/
|
||||
public List<Business> selectBusinessList(Business business);
|
||||
|
||||
/**
|
||||
* 新增企业
|
||||
*
|
||||
* @param business 企业
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertBusiness(Business business);
|
||||
|
||||
/**
|
||||
* 修改企业
|
||||
*
|
||||
* @param business 企业
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateBusiness(Business business);
|
||||
|
||||
/**
|
||||
* 批量删除企业
|
||||
*
|
||||
* @param ids 需要删除的企业主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteBusinessByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除企业信息
|
||||
*
|
||||
* @param id 企业主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteBusinessById(Long id);
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.muyu.business.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.business.domain.Entinfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 多数据源Service接口
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
public interface IEntinfoService extends IService<Entinfo>
|
||||
{
|
||||
/**
|
||||
* 查询多数据源
|
||||
*
|
||||
* @param id 多数据源主键
|
||||
* @return 多数据源
|
||||
*/
|
||||
public Entinfo selectEntinfoById(Long id);
|
||||
|
||||
/**
|
||||
* 查询多数据源列表
|
||||
*
|
||||
* @param entinfo 多数据源
|
||||
* @return 多数据源集合
|
||||
*/
|
||||
public List<Entinfo> selectEntinfoList(Entinfo entinfo);
|
||||
|
||||
/**
|
||||
* 新增多数据源
|
||||
*
|
||||
* @param entinfo 多数据源
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertEntinfo(Entinfo entinfo);
|
||||
|
||||
/**
|
||||
* 修改多数据源
|
||||
*
|
||||
* @param entinfo 多数据源
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateEntinfo(Entinfo entinfo);
|
||||
|
||||
/**
|
||||
* 批量删除多数据源
|
||||
*
|
||||
* @param ids 需要删除的多数据源主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEntinfoByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除多数据源信息
|
||||
*
|
||||
* @param id 多数据源主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEntinfoById(Long id);
|
||||
|
||||
Entinfo selectEntinfo(Entinfo business);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.business.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseService;
|
||||
import com.muyu.business.domain.Cart;
|
||||
import com.muyu.business.domain.CartVo;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
|
||||
/**
|
||||
* @ClassName PlusService
|
||||
* @Description 描述
|
||||
* @Author xiaohuang
|
||||
* @Date 2024/06/09 15:36
|
||||
*/
|
||||
public interface PlusService extends IService<Cart> {
|
||||
Result cartList();
|
||||
|
||||
}
|
|
@ -0,0 +1,235 @@
|
|||
package com.muyu.business.service.impl;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.muyu.business.domain.Business;
|
||||
|
||||
import com.muyu.business.mapper.BusinessMapper;
|
||||
//import com.muyu.business.remote.factory.RemoteUserLoginFactory;
|
||||
import com.muyu.business.service.IBusinessService;
|
||||
import com.muyu.common.business.domain.Entinfo;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
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 org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 企业Service业务层处理
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-05-26
|
||||
*/
|
||||
@Service
|
||||
public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
|
||||
implements IBusinessService
|
||||
{
|
||||
@Autowired
|
||||
private BusinessMapper businessMapper;
|
||||
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 查询企业
|
||||
*
|
||||
* @param id 企业主键
|
||||
* @return 企业
|
||||
*/
|
||||
@Override
|
||||
public Business selectBusinessById(Long id)
|
||||
{
|
||||
return businessMapper.selectBusinessById(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询企业列表
|
||||
*
|
||||
* @param business 企业
|
||||
* @return 企业
|
||||
*/
|
||||
@Override
|
||||
public List<Business> selectBusinessList(Business business)
|
||||
{
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
SysUser user = remoteUserService.selectByUserId(loginUser.getUserid());
|
||||
if (user.getUserType().equals("00")) {
|
||||
return businessMapper.selectBusinessList(business);
|
||||
}
|
||||
business.setId(Long.valueOf(user.getUserType()));
|
||||
return businessMapper.selectBusinessList(business);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增企业
|
||||
*
|
||||
* @param business 企业
|
||||
* @return 结果
|
||||
*/
|
||||
// @Autowired
|
||||
// private RemoteUserLoginFactory remoteUserLoginFactory;
|
||||
@Override
|
||||
public int insertBusiness(Business business)
|
||||
{
|
||||
business.setCreateTime(DateUtils.getNowDate());
|
||||
int i = businessMapper.insertBusiness(business);
|
||||
System.out.println(business);
|
||||
SysUser sysUser = SysUser.builder()
|
||||
.userName(business.getName())
|
||||
.password("admin123")
|
||||
.nickName(business.getName())
|
||||
.email(business.getBusinessEmail())
|
||||
.phonenumber(business.getBusinessPhone())
|
||||
.loginIp("111.229.102.61")
|
||||
.roleId(Long.valueOf(101))
|
||||
.userType(String.valueOf(business.getId()))
|
||||
.build();
|
||||
Result add = remoteUserService.add(sysUser);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改企业
|
||||
*
|
||||
* @param business 企业
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateBusiness(Business business)
|
||||
{
|
||||
business.setUpdateTime(DateUtils.getNowDate());
|
||||
httpConnectMysql(business);
|
||||
return businessMapper.updateBusiness(business);
|
||||
}
|
||||
@Autowired
|
||||
private EntinfoServiceImpl entinfoService;
|
||||
|
||||
/**
|
||||
* 判断redis是否存在端口号
|
||||
* @param business
|
||||
*/
|
||||
public void httpConnectMysql(Business business){
|
||||
redisService.deleteObject("entinfo");
|
||||
List<Entinfo> list = entinfoService.list();
|
||||
if(list.size()!=0){
|
||||
redisService.setCacheList("entinfo",list);
|
||||
}
|
||||
if (business.getBusinessStates().equals("2")) {
|
||||
SysUser sysUser = remoteUserService.userById(business.getId());
|
||||
sysUser.setRoleId(Long.valueOf(2));
|
||||
remoteUserService.updateById(sysUser);
|
||||
Entinfo build = Entinfo.builder()
|
||||
.entCode("test_" + business.getId())
|
||||
.ip("175.24.138.82")
|
||||
.port(Integer.valueOf(3306 + Integer.valueOf(String.valueOf(business.getId())))).build();
|
||||
Entinfo entinfo =entinfoService.selectEntinfo(build);
|
||||
if (entinfo==null){
|
||||
extracted(business);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* http URL 进行创建Mysql Docker
|
||||
* @param business
|
||||
*/
|
||||
private void extracted(Business business) {
|
||||
String postUrl="http://175.24.138.82:10006/webhook/%E6%9C%AA%E5%91%BD%E5%90%8D%E9%A1%B9%E7%9B%AE";
|
||||
HashMap<String, String> hashMap = new HashMap<>();
|
||||
hashMap.put("businessId",business.getId()+ business.getName());
|
||||
hashMap.put("mysqlPort",String.valueOf(3306+ business.getId()));
|
||||
String json = JSON.toJSONString(hashMap);
|
||||
// 3.创建连接与设置连接参数
|
||||
URL urlObj = null;
|
||||
try {
|
||||
urlObj = new URL(postUrl);
|
||||
HttpURLConnection httpConn = (HttpURLConnection) urlObj.openConnection();
|
||||
httpConn.setRequestMethod("POST");
|
||||
httpConn.setRequestProperty("Charset", "UTF-8");
|
||||
// POST请求且JSON数据,必须设置
|
||||
httpConn.setRequestProperty("Content-Type", "application/json");
|
||||
// 打开输出流,默认是false
|
||||
httpConn.setDoOutput(true);
|
||||
// // 打开输入流,默认是true,可省略
|
||||
// httpConn.setDoInput(true);
|
||||
// 4.从HttpURLConnection获取输出流和写数据
|
||||
OutputStream oStream = httpConn.getOutputStream();
|
||||
oStream.write(json.getBytes());
|
||||
oStream.flush();
|
||||
// 5.发起http调用(getInputStream触发http请求)
|
||||
if (httpConn.getResponseCode() != 200) {
|
||||
throw new Exception("调用服务端异常.");
|
||||
}
|
||||
// 6.从HttpURLConnection获取输入流和读数据
|
||||
BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(httpConn.getInputStream()));
|
||||
String resultData = br.readLine();
|
||||
System.out.println("从服务端返回结果: " + resultData);
|
||||
// 7.关闭HttpURLConnection连接
|
||||
httpConn.disconnect();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Entinfo build = Entinfo.builder()
|
||||
.entCode("test_" + business.getId())
|
||||
.ip("175.24.138.82")
|
||||
.port(Integer.valueOf(3306 + Integer.valueOf(String.valueOf(business.getId())))).build();
|
||||
entinfoService.insertEntinfo(build);
|
||||
rabbitTemplate.convertAndSend("muyu-vehicle-exchange",JSON.toJSONString(build),message ->{
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
//设置消息延迟时间为5秒
|
||||
message.getMessageProperties().setDelay(5000);
|
||||
return message;
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除企业
|
||||
*
|
||||
* @param ids 需要删除的企业主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteBusinessByIds(Long[] ids)
|
||||
{
|
||||
return businessMapper.deleteBusinessByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除企业信息
|
||||
*
|
||||
* @param id 企业主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteBusinessById(Long id)
|
||||
{
|
||||
return businessMapper.deleteBusinessById(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package com.muyu.business.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.business.mapper.EntinfoMapper;
|
||||
import com.muyu.business.service.IEntinfoService;
|
||||
import com.muyu.common.business.domain.Entinfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 多数据源Service业务层处理
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
@Service
|
||||
public class EntinfoServiceImpl extends ServiceImpl<EntinfoMapper, Entinfo>
|
||||
implements IEntinfoService
|
||||
{
|
||||
@Autowired
|
||||
private EntinfoMapper entinfoMapper;
|
||||
|
||||
/**
|
||||
* 查询多数据源
|
||||
*
|
||||
* @param id 多数据源主键
|
||||
* @return 多数据源
|
||||
*/
|
||||
@Override
|
||||
public Entinfo selectEntinfoById(Long id)
|
||||
{
|
||||
return entinfoMapper.selectEntinfoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询多数据源列表
|
||||
*
|
||||
* @param entinfo 多数据源
|
||||
* @return 多数据源
|
||||
*/
|
||||
@Override
|
||||
public List<Entinfo> selectEntinfoList(Entinfo entinfo)
|
||||
{
|
||||
return entinfoMapper.selectEntinfoList(entinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增多数据源
|
||||
*
|
||||
* @param entinfo 多数据源
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertEntinfo(Entinfo entinfo)
|
||||
{
|
||||
return entinfoMapper.insertEntinfo(entinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改多数据源
|
||||
*
|
||||
* @param entinfo 多数据源
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateEntinfo(Entinfo entinfo)
|
||||
{
|
||||
return entinfoMapper.updateEntinfo(entinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除多数据源
|
||||
*
|
||||
* @param ids 需要删除的多数据源主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteEntinfoByIds(Long[] ids)
|
||||
{
|
||||
return entinfoMapper.deleteEntinfoByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除多数据源信息
|
||||
*
|
||||
* @param id 多数据源主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteEntinfoById(Long id)
|
||||
{
|
||||
return entinfoMapper.deleteEntinfoById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entinfo selectEntinfo(Entinfo business) {
|
||||
return entinfoMapper.selectEntinfo(business);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.muyu.business.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.base.MPJBaseServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.muyu.business.domain.Cart;
|
||||
import com.muyu.business.domain.CartVo;
|
||||
import com.muyu.business.domain.Type;
|
||||
import com.muyu.business.mapper.PlusMapper;
|
||||
import com.muyu.business.mapper.TypeMapper;
|
||||
import com.muyu.business.service.PlusService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName PlusServiceImpl
|
||||
* @Date 2024/06/09 15:37
|
||||
*/
|
||||
@Service
|
||||
public class PlusServiceImpl extends MPJBaseServiceImpl<PlusMapper, Cart> implements PlusService {
|
||||
|
||||
@Autowired
|
||||
private PlusMapper plusMapper;
|
||||
|
||||
@Autowired
|
||||
private TypeMapper typeMapper;
|
||||
|
||||
@Override
|
||||
public Result cartList() {
|
||||
MPJLambdaWrapper<Cart> mpjLambdaWrapper = new MPJLambdaWrapper<Cart>()
|
||||
.selectAll( Cart.class) //查询主表所有的字段
|
||||
.select(Type::getTypeName) //查询类型名称
|
||||
.leftJoin(Type.class, Type::getId, Cart::getTypeId);//左连接查询,相当于 left join type on dept.id=user.dept_id
|
||||
List<CartVo> cartList = plusMapper.selectJoinList(CartVo.class, mpjLambdaWrapper);
|
||||
return Result.success(cartList);
|
||||
// MPJLambdaWrapper<Cart> mpjLambdaWrapper1 = new MPJLambdaWrapper<>();
|
||||
// MPJLambdaWrapper<Cart> lambdaWrapper = mpjLambdaWrapper1.eq(Cart::getId, "1");
|
||||
|
||||
|
||||
// List<Cart> list = this.list();
|
||||
// list.stream().forEach(cart -> {
|
||||
// LambdaQueryWrapper<Type> typeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// Type type = typeMapper.selectOne(typeLambdaQueryWrapper.eq(Type::getId, cart.getTypeId()));
|
||||
// cart.setName(type.getTypeName());
|
||||
// });
|
||||
// System.out.println(list);
|
||||
// return Result.success(list,cartList.toString());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.muyu.business.text; /**
|
||||
* xioahuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName text
|
||||
* @Date 2024/05/29 10:31
|
||||
*/
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DatabaseInitializer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String postUrl="http://122.51.111.225:10006/webhook/%E6%96%B0%E5%BB%BA%E4%BC%81%E4%B8%9A%E6%95%B0%E6%8D%AE%E6%BA%90";
|
||||
HashMap<String, String> hashMap = new HashMap<>();
|
||||
hashMap.put("businessId",40+"jhghj");
|
||||
hashMap.put("mysqlPort",String.valueOf(3301));
|
||||
String json = JSON.toJSONString(hashMap);
|
||||
// 3.创建连接与设置连接参数
|
||||
URL urlObj = null;
|
||||
try {
|
||||
urlObj = new URL(postUrl);
|
||||
HttpURLConnection httpConn = (HttpURLConnection) urlObj.openConnection();
|
||||
httpConn.setRequestMethod("POST");
|
||||
httpConn.setRequestProperty("Charset", "UTF-8");
|
||||
// POST请求且JSON数据,必须设置
|
||||
httpConn.setRequestProperty("Content-Type", "application/json");
|
||||
// 打开输出流,默认是false
|
||||
httpConn.setDoOutput(true);
|
||||
// 打开输入流,默认是true,可省略
|
||||
httpConn.setDoInput(true);
|
||||
// 4.从HttpURLConnection获取输出流和写数据
|
||||
OutputStream oStream = httpConn.getOutputStream();
|
||||
oStream.write(json.getBytes());
|
||||
oStream.flush();
|
||||
// 5.发起http调用(getInputStream触发http请求)
|
||||
if (httpConn.getResponseCode() != 200) {
|
||||
throw new Exception("调用服务端异常.");
|
||||
}
|
||||
// 6.从HttpURLConnection获取输入流和读数据
|
||||
BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(httpConn.getInputStream()));
|
||||
String resultData = br.readLine();
|
||||
System.out.println("从服务端返回结果: " + resultData);
|
||||
// 7.关闭HttpURLConnection连接
|
||||
httpConn.disconnect();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9211
|
||||
# Spring
|
||||
spring:
|
||||
rabbitmq:
|
||||
username: guest
|
||||
password: guest
|
||||
virtualHost: /
|
||||
port: 5672
|
||||
host: 175.24.138.82
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||
publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
|
||||
publisher-returns: true #确认消息已发送到队列(Queue)
|
||||
application:
|
||||
# 应用名称
|
||||
name: muyu-business
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 175.24.138.82:8848
|
||||
# 命名空间
|
||||
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 175.24.138.82:8848
|
||||
# 命名空间
|
||||
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
logging:
|
||||
level:
|
||||
com.muyu.business.mapper: DEBUG
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/muyu-data-business"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,125 @@
|
|||
<?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.business.mapper.BusinessMapper">
|
||||
|
||||
<resultMap type="com.muyu.business.domain.Business" id="BusinessResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="name" column="name" />
|
||||
<result property="businessPerson" column="business_person" />
|
||||
<result property="businessLincenseNumber" column="business_lincense_number" />
|
||||
<result property="businessCreateTime" column="business_create_time" />
|
||||
<result property="businessPhone" column="business_phone" />
|
||||
<result property="businessEmail" column="business_email" />
|
||||
<result property="businessStates" column="business_states" />
|
||||
<result property="businessRegistrationDate" column="business_registration_date" />
|
||||
<result property="serviceLevel" column="service_level" />
|
||||
<result property="authentication" column="authentication" />
|
||||
<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" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectBusinessVo">
|
||||
select id, name, business_person, business_lincense_number, business_create_time, business_phone, business_email, business_states, business_registration_date, service_level, authentication, remark, create_by, create_time, update_by, update_time from business
|
||||
</sql>
|
||||
|
||||
<select id="selectBusinessList" parameterType="com.muyu.business.domain.Business" resultMap="BusinessResult">
|
||||
<include refid="selectBusinessVo"/>
|
||||
<where>
|
||||
<if test="id != null and id != ''"> and id = #{id}</if>
|
||||
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
|
||||
<if test="businessPerson != null and businessPerson != ''"> and business_person = #{businessPerson}</if>
|
||||
<if test="businessLincenseNumber != null and businessLincenseNumber != ''"> and business_lincense_number = #{businessLincenseNumber}</if>
|
||||
<if test="businessCreateTime != null "> and business_create_time = #{businessCreateTime}</if>
|
||||
<if test="businessPhone != null and businessPhone != ''"> and business_phone = #{businessPhone}</if>
|
||||
<if test="businessEmail != null and businessEmail != ''"> and business_email = #{businessEmail}</if>
|
||||
<if test="businessStates != null and businessStates != ''"> and business_states = #{businessStates}</if>
|
||||
<if test="businessRegistrationDate != null "> and business_registration_date = #{businessRegistrationDate}</if>
|
||||
<if test="serviceLevel != null and serviceLevel != ''"> and service_level = #{serviceLevel}</if>
|
||||
<if test="authentication != null and authentication != ''"> and authentication = #{authentication}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectBusinessById" parameterType="Long" resultMap="BusinessResult">
|
||||
<include refid="selectBusinessVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
<select id="info" resultType="com.muyu.common.system.domain.LoginUser">
|
||||
select * from sys_user where id=#{userId}
|
||||
</select>
|
||||
|
||||
<insert id="insertBusiness" parameterType="com.muyu.business.domain.Business" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into business
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="name != null">name,</if>
|
||||
<if test="businessPerson != null">business_person,</if>
|
||||
<if test="businessLincenseNumber != null">business_lincense_number,</if>
|
||||
<if test="businessCreateTime != null">business_create_time,</if>
|
||||
<if test="businessPhone != null">business_phone,</if>
|
||||
<if test="businessEmail != null">business_email,</if>
|
||||
<if test="businessStates != null">business_states,</if>
|
||||
<if test="businessRegistrationDate != null">business_registration_date,</if>
|
||||
<if test="serviceLevel != null">service_level,</if>
|
||||
<if test="authentication != null">authentication,</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>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="businessPerson != null">#{businessPerson},</if>
|
||||
<if test="businessLincenseNumber != null">#{businessLincenseNumber},</if>
|
||||
<if test="businessCreateTime != null">#{businessCreateTime},</if>
|
||||
<if test="businessPhone != null">#{businessPhone},</if>
|
||||
<if test="businessEmail != null">#{businessEmail},</if>
|
||||
<if test="businessStates != null">#{businessStates},</if>
|
||||
<if test="businessRegistrationDate != null">#{businessRegistrationDate},</if>
|
||||
<if test="serviceLevel != null">#{serviceLevel},</if>
|
||||
<if test="authentication != null">#{authentication},</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>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateBusiness" parameterType="com.muyu.business.domain.Business">
|
||||
update business
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="businessPerson != null">business_person = #{businessPerson},</if>
|
||||
<if test="businessLincenseNumber != null">business_lincense_number = #{businessLincenseNumber},</if>
|
||||
<if test="businessCreateTime != null">business_create_time = #{businessCreateTime},</if>
|
||||
<if test="businessPhone != null">business_phone = #{businessPhone},</if>
|
||||
<if test="businessEmail != null">business_email = #{businessEmail},</if>
|
||||
<if test="businessStates != null">business_states = #{businessStates},</if>
|
||||
<if test="businessRegistrationDate != null">business_registration_date = #{businessRegistrationDate},</if>
|
||||
<if test="serviceLevel != null">service_level = #{serviceLevel},</if>
|
||||
<if test="authentication != null">authentication = #{authentication},</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>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteBusinessById" parameterType="Long">
|
||||
delete from business where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteBusinessByIds" parameterType="String">
|
||||
delete from business where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
|
@ -0,0 +1,74 @@
|
|||
<?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.business.mapper.EntinfoMapper">
|
||||
|
||||
<resultMap type="com.muyu.common.business.domain.Entinfo" id="EntinfoResult">
|
||||
<result property="entCode" column="ent_code" />
|
||||
<result property="ip" column="ip" />
|
||||
<result property="port" column="port" />
|
||||
<result property="id" column="id" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectEntinfoVo">
|
||||
select ent_code, ip, port, id from entinfo
|
||||
</sql>
|
||||
|
||||
<select id="selectEntinfoList" parameterType="com.muyu.common.business.domain.Entinfo" resultMap="EntinfoResult">
|
||||
<include refid="selectEntinfoVo"/>
|
||||
<where>
|
||||
<if test="entCode != null and entCode != ''"> and ent_code = #{entCode}</if>
|
||||
<if test="ip != null and ip != ''"> and ip = #{ip}</if>
|
||||
<if test="port != null "> and port = #{port}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectEntinfoById" parameterType="Long" resultMap="EntinfoResult">
|
||||
<include refid="selectEntinfoVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
<select id="selectEntinfo" resultType="com.muyu.common.business.domain.Entinfo">
|
||||
<include refid="selectEntinfoVo"/>
|
||||
<where>
|
||||
<if test="entCode != null and entCode != ''"> and ent_code = #{entCode}</if>
|
||||
<if test="ip != null and ip != ''"> and ip = #{ip}</if>
|
||||
<if test="port != null "> and port = #{port}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertEntinfo" parameterType="com.muyu.common.business.domain.Entinfo" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into entinfo
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="entCode != null">ent_code,</if>
|
||||
<if test="ip != null">ip,</if>
|
||||
<if test="port != null">port,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="entCode != null">#{entCode},</if>
|
||||
<if test="ip != null">#{ip},</if>
|
||||
<if test="port != null">#{port},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateEntinfo" parameterType="com.muyu.common.business.domain.Entinfo">
|
||||
update entinfo
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="entCode != null">ent_code = #{entCode},</if>
|
||||
<if test="ip != null">ip = #{ip},</if>
|
||||
<if test="port != null">port = #{port},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteEntinfoById" parameterType="Long">
|
||||
delete from entinfo where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteEntinfoByIds" parameterType="String">
|
||||
delete from entinfo where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-business</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>muyu-data-plus</module>
|
||||
<module>muyu-data-service</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<description>
|
||||
muyu-business系统模块
|
||||
</description>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-cloud-datasource</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-datasource-service</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<description>
|
||||
muyu-datasource-service多数据源配置
|
||||
</description>
|
||||
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger UI -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<!-- <version>${swagger.fox.version}</version>-->
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- muyu Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- muyu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- muyu Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- muyu Common Swagger -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- 加入maven deploy插件,当在deploy时,忽略些model-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,71 @@
|
|||
package com.muyu.datasource;
|
||||
|
||||
|
||||
import com.muyu.datasource.config.factory.DruidDataSourceFactory;
|
||||
import com.muyu.datasource.config.role.DynamicDataSource;
|
||||
import com.muyu.datasource.domain.DataSourceInfo;
|
||||
import com.muyu.datasource.domain.EntInfo;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 数据源配置
|
||||
* @Date 2023-8-1 上午 11:05
|
||||
*/
|
||||
@Log4j2
|
||||
@Configuration
|
||||
public class ManyDataSource {
|
||||
|
||||
|
||||
private List<EntInfo> dataSourceInfoList(){
|
||||
List<EntInfo> databaseNameList = new ArrayList<>(){{
|
||||
add(EntInfo.builder()
|
||||
.entCode("test_1")
|
||||
.ip("175.24.138.82")
|
||||
.port(3306)
|
||||
.build());
|
||||
add(EntInfo.builder()
|
||||
.entCode("test_2")
|
||||
.ip("122.51.111.225")
|
||||
.port(6666)
|
||||
.build());
|
||||
add(EntInfo.builder()
|
||||
.entCode("test_3")
|
||||
.ip("122.51.111.225")
|
||||
.port(3333)
|
||||
.build());
|
||||
}};
|
||||
return databaseNameList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
||||
|
||||
//查企业
|
||||
Map<Object, Object> dataSourceMap = new HashMap<>();
|
||||
dataSourceInfoList()
|
||||
.stream()
|
||||
.map(entInfo-> DataSourceInfo.hostAndPortBuild(entInfo.getEntCode(),entInfo.getIp(),entInfo.getPort()))
|
||||
.forEach(dataSourceInfo -> {
|
||||
dataSourceMap.put(dataSourceInfo.getKey(), druidDataSourceFactory.create(dataSourceInfo));
|
||||
});
|
||||
//设置动态数据源
|
||||
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
||||
// dynamicDataSource.setDefaultTargetDataSource(masterDataSource());
|
||||
dynamicDataSource.setTargetDataSources(dataSourceMap);
|
||||
//将数据源信息备份在defineTargetDataSources中
|
||||
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
|
||||
return dynamicDataSource;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.datasource;
|
||||
|
||||
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
|
||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName ZhiLianDataSourceApplication
|
||||
* @Date 2024/06/03 14:06
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication(exclude = {DynamicDataSourceAutoConfiguration.class, DataSourceAutoConfiguration.class })
|
||||
public class MuYuDataSourceApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MuYuDataSourceApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.datasource.config;
|
||||
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
|
||||
import com.muyu.datasource.config.holder.DynamicDataSourceHolder;
|
||||
import org.aspectj.lang.annotation.After;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 数据源切面
|
||||
* @Date 2023-8-2 下午 08:26
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class DataSourceAsp {
|
||||
|
||||
@Pointcut("execution(public * com.muyu.vehicle.controller.*Controller.*(..))")
|
||||
public void pointcut () {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 的每一個方法執行之前 執行的處理
|
||||
*/
|
||||
@Before("pointcut()")
|
||||
public void beforeMethod() {
|
||||
Long storeId = SecurityUtils.getLoginUser().getUserid();
|
||||
DynamicDataSourceHolder.setDynamicDataSourceKey("test_"+storeId);
|
||||
}
|
||||
/**
|
||||
* 的每一個方法執行之后 執行的處理
|
||||
* 无论正常还是异常终了
|
||||
* 不能接受到返回值
|
||||
*/
|
||||
@After("pointcut()")
|
||||
public void afterMethod() {
|
||||
DynamicDataSourceHolder.removeDynamicDataSourceKey();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.muyu.datasource.config.factory;
|
||||
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
import com.muyu.datasource.domain.DataSourceInfo;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName DruidDataSourceFactory
|
||||
* @Date 2024/06/04 14:47
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class DruidDataSourceFactory {
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 根据传递的数据源信息测试数据库连接
|
||||
* @Author Dongzl
|
||||
*/
|
||||
public DruidDataSource create(DataSourceInfo dataSourceInfo) {
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
druidDataSource.setUrl(dataSourceInfo.getUrl());
|
||||
druidDataSource.setUsername(dataSourceInfo.getUserName());
|
||||
druidDataSource.setPassword(dataSourceInfo.getPassword());
|
||||
druidDataSource.setBreakAfterAcquireFailure(true);
|
||||
druidDataSource.setConnectionErrorRetryAttempts(0);
|
||||
try {
|
||||
druidDataSource.getConnection(2000);
|
||||
log.info("{} -> 数据源连接成功", dataSourceInfo.getKey());
|
||||
return druidDataSource;
|
||||
} catch (SQLException throwables) {
|
||||
log.error("数据源 {} 连接失败,用户名:{},密码 {}",dataSourceInfo.getUrl(),dataSourceInfo.getUserName(),dataSourceInfo.getPassword());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.datasource.config.holder;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* 数据源切换处理
|
||||
*
|
||||
* @author Dongzl
|
||||
*/
|
||||
@Slf4j
|
||||
public class DynamicDataSourceHolder {
|
||||
/**
|
||||
* 保存动态数据源名称
|
||||
*/
|
||||
private static final ThreadLocal<String> DYNAMIC_DATASOURCE_KEY = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 设置/切换数据源,决定当前线程使用哪个数据源
|
||||
*/
|
||||
public static void setDynamicDataSourceKey(String key){
|
||||
log.info("数据源切换为:{}",key);
|
||||
DYNAMIC_DATASOURCE_KEY.set(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取动态数据源名称,默认使用mater数据源
|
||||
*/
|
||||
public static String getDynamicDataSourceKey(){
|
||||
String key = DYNAMIC_DATASOURCE_KEY.get();
|
||||
Assert.notNull(key, "请携带数据标识");
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除当前数据源
|
||||
*/
|
||||
public static void removeDynamicDataSourceKey(){
|
||||
log.info("移除数据源:{}",DYNAMIC_DATASOURCE_KEY.get());
|
||||
DYNAMIC_DATASOURCE_KEY.remove();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.datasource.config.role;
|
||||
|
||||
|
||||
import com.muyu.datasource.config.holder.DynamicDataSourceHolder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 动态数据源
|
||||
* 调用AddDefineDataSource组件的addDefineDynamicDataSource()方法,获取原来targetdatasources的map,并将新的数据源信息添加到map中,并替换targetdatasources中的map
|
||||
* 切换数据源时可以使用@DataSource(value = "数据源名称"),或者DynamicDataSourceContextHolder.setContextKey("数据源名称")
|
||||
* @author Dongzl
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DynamicDataSource extends AbstractRoutingDataSource {
|
||||
/**
|
||||
* 备份所有数据源信息, 指针!!
|
||||
*/
|
||||
private Map<Object, Object> defineTargetDataSources;
|
||||
|
||||
/**
|
||||
* 决定当前线程使用哪个数据源
|
||||
*/
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
return DynamicDataSourceHolder.getDynamicDataSourceKey();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.datasource.contents;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 数据源常量
|
||||
* @Date 2023-8-1 上午 11:02
|
||||
*/
|
||||
public class DatasourceContent {
|
||||
|
||||
public final static String DATASOURCE_URL = "jdbc:mysql://{}:{}/muyu-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
|
||||
|
||||
public final static String USER_NAME = "root";
|
||||
|
||||
public final static String PASSWORD = "root";
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.muyu.datasource.domain;
|
||||
|
||||
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import static com.muyu.datasource.contents.DatasourceContent.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 数据源实体类
|
||||
* @Date 2023-8-1 上午 11:15
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DataSourceInfo {
|
||||
|
||||
/**
|
||||
* 键
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
public static DataSourceInfo hostAndPortBuild(String key,String host, Integer port){
|
||||
return DataSourceInfo.builder()
|
||||
.key(key)
|
||||
.url(StringUtils.format(DATASOURCE_URL, host,port))
|
||||
.password(PASSWORD)
|
||||
.userName(USER_NAME)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.datasource.domain;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* xiaohuang
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName EntInfo
|
||||
* @Date 2024/06/04 14:34
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class EntInfo {
|
||||
private String entCode;
|
||||
|
||||
//ip
|
||||
private String ip;
|
||||
|
||||
//端口
|
||||
private Integer port;
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.muyu.datasource.util;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
import com.muyu.datasource.ManyDataSource;
|
||||
import com.muyu.datasource.config.factory.DruidDataSourceFactory;
|
||||
import com.muyu.datasource.config.role.DynamicDataSource;
|
||||
import com.muyu.datasource.domain.DataSourceInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 数据源工具类
|
||||
* @Author Dongzl
|
||||
* @Date 2022/8/18 17:20
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DataSourceService {
|
||||
|
||||
@Autowired
|
||||
private ManyDataSource druidConfig;
|
||||
|
||||
@Autowired
|
||||
private DruidDataSourceFactory druidDataSourceFactory;
|
||||
|
||||
@Resource
|
||||
private DynamicDataSource dynamicDataSource;
|
||||
|
||||
public void addDataSource(DataSourceInfo dataSourceInfo){
|
||||
addDefineDynamicDataSource(druidDataSourceFactory.create(dataSourceInfo), dataSourceInfo.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 将新增的数据源加入到备份数据源map中
|
||||
* @Author Dongzl
|
||||
*/
|
||||
public void addDefineDynamicDataSource(DruidDataSource druidDataSource, String dataSourceName){
|
||||
Map<Object, Object> defineTargetDataSources = dynamicDataSource.getDefineTargetDataSources();
|
||||
defineTargetDataSources.put(dataSourceName, druidDataSource);
|
||||
dynamicDataSource.setTargetDataSources(defineTargetDataSources);
|
||||
dynamicDataSource.afterPropertiesSet();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9206
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: muyu-datasource
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 175.24.138.82:8848
|
||||
# 命名空间
|
||||
namespace: muyu
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 175.24.138.82:8848
|
||||
# 命名空间
|
||||
namespace: muyu
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
#logging:
|
||||
# level:
|
||||
# com.muyu.system.mapper: DEBUG
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/muyu-datasource"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-cloud-datasource</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>muyu-datasource-service</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-common-business</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- muyu Common Core-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcutil-jdk15on</artifactId>
|
||||
<version>1.69</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,46 @@
|
|||
package com.muyu.common.business.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* 多数据源对象 entinfo
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("entinfo")
|
||||
public class Entinfo extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 数据源key */
|
||||
@Excel(name = "数据源key")
|
||||
private String entCode;
|
||||
|
||||
/** 数据源ip */
|
||||
@Excel(name = "数据源ip")
|
||||
private String ip;
|
||||
|
||||
/** 数据源端口 */
|
||||
@Excel(name = "数据源端口")
|
||||
private Integer port;
|
||||
|
||||
/** 数据源ID */
|
||||
private Long id;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.common.business.remote;
|
||||
|
||||
import com.muyu.common.business.domain.Entinfo;
|
||||
import com.muyu.common.business.remote.factory.RemoteBusinessFallbackFactory;
|
||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务
|
||||
*
|
||||
* @author muyu
|
||||
*/
|
||||
@FeignClient(contextId = "remoteBusinessService", value = ServiceNameConstants.SYSTEM_BUSINESS, fallbackFactory = RemoteBusinessFallbackFactory.class)
|
||||
public interface RemoteBusinessService {
|
||||
|
||||
|
||||
@GetMapping("/entinfo/listAll")
|
||||
public List<Entinfo> listAll();
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.common.business.remote.factory;
|
||||
|
||||
import com.muyu.common.business.domain.Entinfo;
|
||||
import com.muyu.common.business.remote.RemoteBusinessService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务降级处理
|
||||
*
|
||||
* @author muyu
|
||||
*/
|
||||
@Component
|
||||
public class RemoteBusinessFallbackFactory implements FallbackFactory<RemoteBusinessService> {
|
||||
private static final Logger log = LoggerFactory.getLogger(RemoteBusinessFallbackFactory.class);
|
||||
|
||||
@Override
|
||||
public RemoteBusinessService create (Throwable throwable) {
|
||||
log.error("用户服务调用失败:{}", throwable.getMessage());
|
||||
return new RemoteBusinessService(){
|
||||
|
||||
|
||||
@Override
|
||||
public List<Entinfo> listAll() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
com.muyu.common.business.remote.factory.RemoteBusinessFallbackFactory
|
|
@ -15,6 +15,7 @@ public class ServiceNameConstants {
|
|||
* 系统模块的serviceid
|
||||
*/
|
||||
public static final String SYSTEM_SERVICE = "muyu-system";
|
||||
public static final String SYSTEM_BUSINESS = "muyu-business";
|
||||
|
||||
/**
|
||||
* 文件服务的serviceid
|
||||
|
|
|
@ -58,7 +58,7 @@ public class IpUtils {
|
|||
ip = request.getRemoteAddr();
|
||||
}
|
||||
|
||||
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : getMultistageReverseProxyIp(ip);
|
||||
return "0:0:0:0:0:0:0:1".equals(ip) ? "111.229.102.61" : getMultistageReverseProxyIp(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,7 @@ public class IpUtils {
|
|||
*/
|
||||
public static boolean internalIp (String ip) {
|
||||
byte[] addr = textToNumericFormatV4(ip);
|
||||
return internalIp(addr) || "127.0.0.1".equals(ip);
|
||||
return internalIp(addr) || "111.229.102.61".equals(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,7 +197,7 @@ public class IpUtils {
|
|||
return InetAddress.getLocalHost().getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
}
|
||||
return "127.0.0.1";
|
||||
return "111.229.102.61";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,12 +26,12 @@ import java.util.Map;
|
|||
public class BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 搜索值
|
||||
*/
|
||||
@JsonIgnore
|
||||
@TableField(exist = false)
|
||||
private String searchValue;
|
||||
// /**
|
||||
// * 搜索值
|
||||
// */
|
||||
// @JsonIgnore
|
||||
// @TableField(exist = false)
|
||||
// private String searchValue;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<!-- MuYu Common Security -->
|
||||
<!-- muyu Common Security -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-security</artifactId>
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.lang.annotation.*;
|
|||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface DataScope {
|
||||
|
||||
/**
|
||||
* 部门表的别名
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<!-- MuYu Common Security -->
|
||||
<!-- muyu Common Security -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-security</artifactId>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Core-->
|
||||
<!-- muyu Common Core-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-core</artifactId>
|
||||
|
|
|
@ -22,13 +22,13 @@
|
|||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Redis-->
|
||||
<!-- muyu Common Redis-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common System-->
|
||||
<!-- muyu Common System-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-system</artifactId>
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# com.muyu.common.swagger.config.SwaggerAutoConfiguration
|
||||
# com.muyu.common.swagger.config.SwaggerWebConfiguration
|
||||
# com.muyu.common.swagger.config.SwaggerBeanPostProcessor
|
||||
# config.swagger.com.muyu.common.SwaggerAutoConfiguration
|
||||
# config.swagger.com.muyu.common.SwaggerWebConfiguration
|
||||
# config.swagger.com.muyu.common.SwaggerBeanPostProcessor
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- MuYu Common Core-->
|
||||
<!-- muyu Common Core-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-core</artifactId>
|
||||
|
|
|
@ -85,6 +85,11 @@ public class SysUser extends BaseEntity {
|
|||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 用户类型(00系统用户)
|
||||
*/
|
||||
private String userType;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
*/
|
||||
|
@ -323,6 +328,7 @@ public class SysUser extends BaseEntity {
|
|||
.append("updateTime", getUpdateTime())
|
||||
.append("remark", getRemark())
|
||||
.append("dept", getDept())
|
||||
.append("userType",userType)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import com.muyu.common.system.domain.SysFile;
|
|||
import com.muyu.common.system.remote.factory.RemoteFileFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
@ -26,4 +28,10 @@ public interface RemoteFileService {
|
|||
*/
|
||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public Result<SysFile> upload (@RequestPart(value = "file") MultipartFile file);
|
||||
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result getInfo(@PathVariable("id") Long id);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ import com.muyu.common.core.domain.Result;
|
|||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import lombok.extern.java.Log;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
|
@ -26,7 +28,6 @@ public interface RemoteUserService {
|
|||
*/
|
||||
@GetMapping("/user/info/{username}")
|
||||
public Result<LoginUser> getUserInfo (@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 注册用户信息
|
||||
*
|
||||
|
@ -37,4 +38,21 @@ public interface RemoteUserService {
|
|||
*/
|
||||
@PostMapping("/user/register")
|
||||
public Result<Boolean> registerUserInfo (@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
@PostMapping("/user")
|
||||
public Result add (@Validated @RequestBody SysUser user);
|
||||
|
||||
@GetMapping("/user/info/{username}")
|
||||
public Result<LoginUser> info (@PathVariable("username") String username);
|
||||
|
||||
@GetMapping("/user/authRole/{userId}")
|
||||
public Result authRole (@PathVariable("userId") Long userId);
|
||||
|
||||
@GetMapping("/user/selectByUserId/{userId}")
|
||||
public SysUser selectByUserId (@PathVariable("userId") Long userId);
|
||||
|
||||
@GetMapping("/user/userById/{userId}")
|
||||
public SysUser userById (@PathVariable("userId") Long UserType);
|
||||
@PostMapping("/user/updateById")
|
||||
public Result updateById (@RequestBody SysUser user);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,13 @@ public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileServ
|
|||
public Result<SysFile> upload (MultipartFile file) {
|
||||
return Result.error("上传文件失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getInfo(Long id) {
|
||||
return Result.error("获取失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,36 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
public Result<Boolean> registerUserInfo (SysUser sysUser, String source) {
|
||||
return Result.error("注册用户失败:" + throwable.getMessage());
|
||||
}
|
||||
@Override
|
||||
public Result add(SysUser user) {
|
||||
return Result.error("注册用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<LoginUser> info(String username) {
|
||||
return Result.error("注册用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result authRole(Long userId) {
|
||||
return Result.error("注册用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser selectByUserId(Long userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser userById(Long userType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result updateById(SysUser user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu</artifactId>
|
||||
<artifactId>muyu-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -18,6 +18,7 @@
|
|||
<module>muyu-common-datascope</module>
|
||||
<module>muyu-common-datasource</module>
|
||||
<module>muyu-common-system</module>
|
||||
<module>muyu-common-business</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>muyu-common</artifactId>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu</artifactId>
|
||||
<artifactId>muyu-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -70,7 +70,7 @@
|
|||
<artifactId>kaptcha</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Redis-->
|
||||
<!-- muyu Common Redis-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-redis</artifactId>
|
||||
|
@ -88,6 +88,11 @@
|
|||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -14,10 +14,10 @@ public interface ValidateCodeService {
|
|||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
public Result createCaptcha () throws IOException, CaptchaException;
|
||||
public Result createCaptcha() throws IOException, CaptchaException;
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*/
|
||||
public void checkCaptcha (String key, String value) throws CaptchaException;
|
||||
public void checkCaptcha(String key, String value) throws CaptchaException;
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ spring:
|
|||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 127.0.0.1:8848
|
||||
server-addr: 175.24.138.82:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 127.0.0.1:8848
|
||||
server-addr: 175.24.138.82:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
@ -28,12 +28,12 @@ spring:
|
|||
eager: true
|
||||
transport:
|
||||
# 控制台地址
|
||||
dashboard: 127.0.0.1:8718
|
||||
dashboard: 175.24.138.82:8718
|
||||
# nacos配置持久化
|
||||
datasource:
|
||||
ds1:
|
||||
nacos:
|
||||
server-addr: 127.0.0.1:8848
|
||||
server-addr: 175.24.138.82:8848
|
||||
dataId: sentinel-muyu-gateway
|
||||
groupId: DEFAULT_GROUP
|
||||
data-type: json
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-iotdb</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
<artifactId>iotdb-session</artifactId>
|
||||
<version>0.14.0-preview1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.83</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- kafka -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.iotdb;
|
||||
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName MuyuIotdbApplication
|
||||
* @Date 2024/05/21 17:01
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class MuyuIotdbApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MuyuIotdbApplication.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
package com.muyu.iotdb.config;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.apache.iotdb.session.Session;
|
||||
import org.apache.iotdb.session.SessionDataSet;
|
||||
import org.apache.iotdb.session.util.Version;
|
||||
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
|
||||
import org.apache.iotdb.tsfile.write.record.Tablet;
|
||||
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.rmi.ServerException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* description: iotdb 配置工具类(常用部分,如需要可以自行扩展)
|
||||
* 注意:可以不需要创建分组,插入时默认前两个节点名称为分组名称 比如: root.a1eaKSRpRty.CA3013A303A25467 或者
|
||||
* root.a1eaKSRpRty.CA3013A303A25467.heart 他们的分组都为 root.a1eaKSRpRty
|
||||
* author: zhouhong
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
@Configuration
|
||||
public class IotDBSessionConfig {
|
||||
|
||||
private static Session session;
|
||||
private static final String LOCAL_HOST = "175.24.138.82";
|
||||
@Bean
|
||||
public Session getSession() throws IoTDBConnectionException, StatementExecutionException {
|
||||
if (session == null) {
|
||||
log.info("正在连接iotdb.......");
|
||||
session = new Session.Builder().host(LOCAL_HOST).port(6667).username("root").password("root").version(Version.V_0_13).build();
|
||||
session.open(false);
|
||||
session.setFetchSize(100);
|
||||
log.info("iotdb连接成功~");
|
||||
// 设置时区
|
||||
session.setTimeZone("+08:00");
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* description: 带有数据类型的添加操作 - insertRecord没有指定类型
|
||||
* author: zhouhong
|
||||
* @param * @param deviceId:节点路径如:root.a1eaKSRpRty.CA3013A303A25467
|
||||
* time:时间戳
|
||||
* measurementsList:物理量 即:属性
|
||||
* type:数据类型: BOOLEAN((byte)0), INT32((byte)1),INT64((byte)2),FLOAT((byte)3),DOUBLE((byte)4),TEXT((byte)5),VECTOR((byte)6);
|
||||
* valuesList:属性值 --- 属性必须与属性值一一对应
|
||||
* @return
|
||||
*/
|
||||
public void insertRecordType(String deviceId, Long time,List<String> measurementsList, TSDataType type,List<Object> valuesList) throws StatementExecutionException, IoTDBConnectionException, ServerException {
|
||||
if (measurementsList.size() != valuesList.size()) {
|
||||
throw new ServerException("measurementsList 与 valuesList 值不对应");
|
||||
}
|
||||
List<TSDataType> types = new ArrayList<>();
|
||||
measurementsList.forEach(item -> {
|
||||
types.add(type);
|
||||
});
|
||||
session.insertRecord(deviceId, time, measurementsList, types, valuesList);
|
||||
}
|
||||
/**
|
||||
* description: 带有数据类型的添加操作 - insertRecord没有指定类型
|
||||
* author: zhouhong
|
||||
* @param deviceId:节点路径如:root.a1eaKSRpRty.CA3013A303A25467
|
||||
* @param time:时间戳
|
||||
* @param measurementsList:物理量 即:属性
|
||||
* @param valuesList:属性值 --- 属性必须与属性值一一对应
|
||||
* @return
|
||||
*/
|
||||
public void insertRecord(String deviceId, Long time,List<String> measurementsList, List<String> valuesList) throws StatementExecutionException, IoTDBConnectionException, ServerException {
|
||||
if (measurementsList.size() == valuesList.size()) {
|
||||
session.insertRecord(deviceId, time, measurementsList, valuesList);
|
||||
} else {
|
||||
log.error("measurementsList 与 valuesList 值不对应");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* description: 批量插入
|
||||
* author: zhouhong
|
||||
*/
|
||||
public void insertRecords(List<String> deviceIdList, List<Long> timeList, List<List<String>> measurementsList, List<List<String>> valuesList) throws StatementExecutionException, IoTDBConnectionException, ServerException {
|
||||
if (measurementsList.size() == valuesList.size()) {
|
||||
session.insertRecords(deviceIdList, timeList, measurementsList, valuesList);
|
||||
} else {
|
||||
log.error("measurementsList 与 valuesList 值不对应");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* description: 插入操作
|
||||
* author: zhouhong
|
||||
* @param deviceId:节点路径如:root.a1eaKSRpRty.CA3013A303A25467
|
||||
* @param time:时间戳
|
||||
* @param schemaList: 属性值 + 数据类型 例子: List<MeasurementSchema> schemaList = new ArrayList<>(); schemaList.add(new MeasurementSchema("breath", TSDataType.INT64));
|
||||
* @param maxRowNumber:
|
||||
* @return
|
||||
*/
|
||||
public void insertTablet(String deviceId, Long time,List<MeasurementSchema> schemaList, List<Object> valueList,int maxRowNumber) throws StatementExecutionException, IoTDBConnectionException {
|
||||
|
||||
Tablet tablet = new Tablet(deviceId, schemaList, maxRowNumber);
|
||||
// 向iotdb里面添加数据
|
||||
int rowIndex = tablet.rowSize++;
|
||||
tablet.addTimestamp(rowIndex, time);
|
||||
for (int i = 0; i < valueList.size(); i++) {
|
||||
tablet.addValue(schemaList.get(i).getMeasurementId(), rowIndex, valueList.get(i));
|
||||
}
|
||||
if (tablet.rowSize == tablet.getMaxRowNumber()) {
|
||||
session.insertTablet(tablet, true);
|
||||
tablet.reset();
|
||||
}
|
||||
if (tablet.rowSize != 0) {
|
||||
session.insertTablet(tablet);
|
||||
tablet.reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* description: 根据SQL查询
|
||||
* author: zhouhong
|
||||
*/
|
||||
public SessionDataSet query(String sql) throws StatementExecutionException, IoTDBConnectionException {
|
||||
return session.executeQueryStatement(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* description: 删除分组 如 root.a1eaKSRpRty
|
||||
* author: zhouhong
|
||||
* @param groupName:分组名称
|
||||
* @return
|
||||
*/
|
||||
public void deleteStorageGroup(String groupName) throws StatementExecutionException, IoTDBConnectionException {
|
||||
session.deleteStorageGroup(groupName);
|
||||
}
|
||||
|
||||
/**
|
||||
* description: 根据Timeseries删除 如:root.a1eaKSRpRty.CA3013A303A25467.breath (个人理解:为具体的物理量)
|
||||
* author: zhouhong
|
||||
*/
|
||||
public void deleteTimeseries(String timeseries) throws StatementExecutionException, IoTDBConnectionException {
|
||||
session.deleteTimeseries(timeseries);
|
||||
}
|
||||
/**
|
||||
* description: 根据Timeseries批量删除
|
||||
* author: zhouhong
|
||||
*/
|
||||
public void deleteTimeserieList(List<String> timeseriesList) throws StatementExecutionException, IoTDBConnectionException {
|
||||
session.deleteTimeseries(timeseriesList);
|
||||
}
|
||||
|
||||
/**
|
||||
* description: 根据分组批量删除
|
||||
* author: zhouhong
|
||||
*/
|
||||
public void deleteStorageGroupList(List<String> storageGroupList) throws StatementExecutionException, IoTDBConnectionException {
|
||||
session.deleteStorageGroups(storageGroupList);
|
||||
}
|
||||
|
||||
/**
|
||||
* description: 根据路径和结束时间删除 结束时间之前的所有数据
|
||||
* author: zhouhong
|
||||
*/
|
||||
public void deleteDataByPathAndEndTime(String path, Long endTime) throws StatementExecutionException, IoTDBConnectionException {
|
||||
session.deleteData(path, endTime);
|
||||
}
|
||||
/**
|
||||
* description: 根据路径集合和结束时间批量删除 结束时间之前的所有数据
|
||||
* author: zhouhong
|
||||
*/
|
||||
public void deleteDataByPathListAndEndTime(List<String> pathList, Long endTime) throws StatementExecutionException, IoTDBConnectionException {
|
||||
session.deleteData(pathList, endTime);
|
||||
}
|
||||
/**
|
||||
* description: 根据路径集合和时间段批量删除
|
||||
* author: zhouhong
|
||||
*/
|
||||
public void deleteDataByPathListAndTime(List<String> pathList, Long startTime,Long endTime) throws StatementExecutionException, IoTDBConnectionException {
|
||||
session.deleteData(pathList, startTime, endTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package com.muyu.iotdb.config;
|
||||
|
||||
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
|
||||
import org.springframework.kafka.config.KafkaListenerContainerFactory;
|
||||
import org.springframework.kafka.core.ConsumerFactory;
|
||||
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
|
||||
import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
|
||||
import org.springframework.kafka.listener.ContainerProperties;
|
||||
import org.springframework.kafka.support.serializer.JsonDeserializer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 徐一杰
|
||||
* @date 2022/10/31 18:05
|
||||
* kafka配置,也可以写在yml,这个文件会覆盖yml
|
||||
*/
|
||||
@SpringBootConfiguration
|
||||
public class KafkaConsumerConfig {
|
||||
|
||||
@Value("${spring.kafka.consumer.bootstrap-servers}")
|
||||
private String bootstrapServers;
|
||||
|
||||
@Value("${spring.kafka.consumer.group-id}")
|
||||
private String groupId;
|
||||
|
||||
@Value("${spring.kafka.consumer.enable-auto-commit}")
|
||||
private boolean enableAutoCommit;
|
||||
|
||||
@Value("${spring.kafka.properties.session.timeout.ms}")
|
||||
private String sessionTimeout;
|
||||
|
||||
@Value("${spring.kafka.properties.max.poll.interval.ms}")
|
||||
private String maxPollIntervalTime;
|
||||
|
||||
@Value("${spring.kafka.consumer.max-poll-records}")
|
||||
private String maxPollRecords;
|
||||
@Value("${spring.kafka.consumer.auto-offset-reset}")
|
||||
private String autoOffsetReset;
|
||||
@Value("${spring.kafka.listener.concurrency}")
|
||||
private Integer concurrency;
|
||||
@Value("${spring.kafka.listener.missing-topics-fatal}")
|
||||
private boolean missingTopicsFatal;
|
||||
@Value("${spring.kafka.listener.poll-timeout}")
|
||||
private long pollTimeout;
|
||||
|
||||
@Bean
|
||||
public Map<String, Object> consumerConfigs() {
|
||||
|
||||
Map<String, Object> propsMap = new HashMap<>(16);
|
||||
propsMap.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
|
||||
propsMap.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
|
||||
//是否自动提交偏移量,默认值是true,为了避免出现重复数据和数据丢失,可以把它设置为false,然后手动提交偏移量
|
||||
propsMap.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, enableAutoCommit);
|
||||
//自动提交的时间间隔,自动提交开启时生效
|
||||
propsMap.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "2000");
|
||||
//该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
|
||||
//earliest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,从头开始消费分区的记录
|
||||
//latest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,消费新产生的该分区下的数据(在消费者启动之后生成的记录)
|
||||
//none:当各分区都存在已提交的offset时,从提交的offset开始消费;只要有一个分区不存在已提交的offset,则抛出异常
|
||||
propsMap.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, autoOffsetReset);
|
||||
//两次poll之间的最大间隔,默认值为5分钟。如果超过这个间隔会触发reBalance
|
||||
propsMap.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, maxPollIntervalTime);
|
||||
//这个参数定义了poll方法最多可以拉取多少条消息,默认值为500。如果在拉取消息的时候新消息不足500条,那有多少返回多少;如果超过500条,每次只返回500。
|
||||
//这个默认值在有些场景下太大,有些场景很难保证能够在5min内处理完500条消息,
|
||||
//如果消费者无法在5分钟内处理完500条消息的话就会触发reBalance,
|
||||
//然后这批消息会被分配到另一个消费者中,还是会处理不完,这样这批消息就永远也处理不完。
|
||||
//要避免出现上述问题,提前评估好处理一条消息最长需要多少时间,然后覆盖默认的max.poll.records参数
|
||||
//注:需要开启BatchListener批量监听才会生效,如果不开启BatchListener则不会出现reBalance情况
|
||||
propsMap.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, maxPollRecords);
|
||||
//当broker多久没有收到consumer的心跳请求后就触发reBalance,默认值是10s
|
||||
propsMap.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, sessionTimeout);
|
||||
//序列化(建议使用Json,这种序列化方式可以无需额外配置传输实体类)
|
||||
propsMap.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
|
||||
propsMap.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
|
||||
return propsMap;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConsumerFactory<Object, Object> consumerFactory() {
|
||||
// 配置消费者的 Json 反序列化的可信赖包,反序列化实体类需要
|
||||
try (JsonDeserializer<Object> deserializer = new JsonDeserializer<>()) {
|
||||
deserializer.trustedPackages("*");
|
||||
return new DefaultKafkaConsumerFactory<>(consumerConfigs(), new JsonDeserializer<>(), deserializer);
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<Object, Object>> kafkaListenerContainerFactory() {
|
||||
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||
factory.setConsumerFactory(consumerFactory());
|
||||
//在侦听器容器中运行的线程数,一般设置为 机器数*分区数
|
||||
factory.setConcurrency(concurrency);
|
||||
//消费监听接口监听的主题不存在时,默认会报错,所以设置为false忽略错误
|
||||
factory.setMissingTopicsFatal(missingTopicsFatal);
|
||||
// 自动提交关闭,需要设置手动消息确认
|
||||
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
|
||||
factory.getContainerProperties().setPollTimeout(pollTimeout);
|
||||
// 设置为批量监听,需要用List接收
|
||||
// factory.setBatchListener(true);
|
||||
return factory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package com.muyu.iotdb.config;
|
||||
|
||||
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.kafka.core.ProducerFactory;
|
||||
import org.springframework.kafka.transaction.KafkaTransactionManager;
|
||||
import org.springframework.kafka.support.serializer.JsonSerializer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 消息生产者对象的配置 构建 KafkaTemplate 设置发送消息带事务
|
||||
*/
|
||||
@SpringBootConfiguration
|
||||
public class KafkaProviderConfig {
|
||||
|
||||
@Value("${spring.kafka.producer.bootstrap-servers}")
|
||||
private String bootstrapServers;
|
||||
@Value("${spring.kafka.producer.transaction-id-prefix}")
|
||||
private String transactionIdPrefix;
|
||||
@Value("${spring.kafka.producer.acks}")
|
||||
private String acks;
|
||||
@Value("${spring.kafka.producer.retries}")
|
||||
private String retries;
|
||||
@Value("${spring.kafka.producer.batch-size}")
|
||||
private String batchSize;
|
||||
@Value("${spring.kafka.producer.buffer-memory}")
|
||||
private String bufferMemory;
|
||||
|
||||
@Bean
|
||||
public Map<String, Object> producerConfigs() {
|
||||
Map<String, Object> props = new HashMap<>(16);
|
||||
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
|
||||
//acks=0 : 生产者在成功写入消息之前不会等待任何来自服务器的响应。
|
||||
//acks=1 : 只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。
|
||||
//acks=all :只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。
|
||||
//开启事务必须设为all
|
||||
props.put(ProducerConfig.ACKS_CONFIG, acks);
|
||||
//发生错误后,消息重发的次数,开启事务必须大于0
|
||||
props.put(ProducerConfig.RETRIES_CONFIG, retries);
|
||||
//当多个消息发送到相同分区时,生产者会将消息打包到一起,以减少请求交互. 而不是一条条发送
|
||||
//批次的大小可以通过batch.size 参数设置.默认是16KB
|
||||
//较小的批次大小有可能降低吞吐量(批次大小为0则完全禁用批处理)。
|
||||
//比如说,kafka里的消息5秒钟Batch才凑满了16KB,才能发送出去。那这些消息的延迟就是5秒钟
|
||||
//实测batchSize这个参数没有用
|
||||
props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize);
|
||||
//有的时刻消息比较少,过了很久,比如5min也没有凑够16KB,这样延时就很大,所以需要一个参数. 再设置一个时间,到了这个时间,
|
||||
//即使数据没达到16KB,也将这个批次发送出去
|
||||
props.put(ProducerConfig.LINGER_MS_CONFIG, "5000");
|
||||
//生产者内存缓冲区的大小
|
||||
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory);
|
||||
//反序列化,和生产者的序列化方式对应
|
||||
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
|
||||
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
|
||||
return props;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ProducerFactory<Object, Object> producerFactory() {
|
||||
DefaultKafkaProducerFactory<Object, Object> factory = new DefaultKafkaProducerFactory<>(producerConfigs());
|
||||
//开启事务,会导致 LINGER_MS_CONFIG 配置失效
|
||||
factory.setTransactionIdPrefix(transactionIdPrefix);
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KafkaTransactionManager<Object, Object> kafkaTransactionManager(ProducerFactory<Object, Object> producerFactory) {
|
||||
return new KafkaTransactionManager<>(producerFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 kafkaTemplate
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public KafkaTemplate<Object, Object> kafkaTemplate() {
|
||||
return new KafkaTemplate<>(producerFactory());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.iotdb.config;
|
||||
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.apache.kafka.clients.producer.RecordMetadata;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.kafka.support.ProducerListener;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* @author 徐一杰
|
||||
* @date 2022/10/31 15:41
|
||||
* kafka消息发送回调
|
||||
*/
|
||||
@Component
|
||||
public class KafkaSendResultHandler implements ProducerListener<Object, Object> {
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate<Object, Object> kafkaTemplate;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
this.kafkaTemplate.setProducerListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(ProducerRecord producerRecord, RecordMetadata recordMetadata) {
|
||||
System.out.println("消息发送成功:" + producerRecord.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ProducerRecord producerRecord, @Nullable RecordMetadata recordMetadata, Exception exception) {
|
||||
System.out.println("消息发送失败:" + producerRecord.toString() + exception.getMessage());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.iotdb.config;
|
||||
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.springframework.kafka.listener.KafkaListenerErrorHandler;
|
||||
import org.springframework.kafka.listener.ListenerExecutionFailedException;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author 徐一杰
|
||||
* @date 2022/10/31 15:27
|
||||
* 异常处理
|
||||
*/
|
||||
@Component
|
||||
public class MyKafkaListenerErrorHandler implements KafkaListenerErrorHandler {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Object handleError(@NonNull Message<?> message, @NonNull ListenerExecutionFailedException exception) {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Object handleError(@NonNull Message<?> message, @NonNull ListenerExecutionFailedException exception,
|
||||
Consumer<?, ?> consumer) {
|
||||
System.out.println("消息详情:" + message);
|
||||
System.out.println("异常信息::" + exception);
|
||||
System.out.println("消费者详情::" + consumer.groupMetadata());
|
||||
System.out.println("监听主题::" + consumer.listTopics());
|
||||
return KafkaListenerErrorHandler.super.handleError(message, exception, consumer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.muyu.iotdb.consumer;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.kafka.support.Acknowledgment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @ClassName:
|
||||
* @Description:
|
||||
* @Author: zhuwenqiang
|
||||
* @Date: 2023/11/2
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class HelloWorldKafkaConsumer {
|
||||
|
||||
@KafkaListener(topics = { "biwe-topic" })
|
||||
public void helloWorldKafkaConsumer(ConsumerRecord<String, String> record1) {
|
||||
// String key = record1.key();
|
||||
// String value = record1.value();
|
||||
|
||||
// 创建 properties 对象 配置 kafka消费者的配置信息
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "111.229.102.61:9092");
|
||||
// 设置 键值的反序列化方式
|
||||
properties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
|
||||
properties.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
|
||||
// 配置 分组 ***
|
||||
properties.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "bw2");
|
||||
|
||||
// 创建 kafka 消息消费者对象
|
||||
KafkaConsumer<String, String> kafkaConsumer = new KafkaConsumer<String, String>(properties);
|
||||
// 订阅主题
|
||||
kafkaConsumer.subscribe(Collections.singleton("bwie-topic"));
|
||||
while (true) {
|
||||
// 拉取消息
|
||||
ConsumerRecords<String, String> records = kafkaConsumer.poll(Duration.ofMillis(2000));
|
||||
// 遍历
|
||||
records.forEach(record -> {
|
||||
String key = record.key();
|
||||
String value = record.value();
|
||||
System.out.println("消息者消息成功,消息的key:" + key + ",value:" + value);
|
||||
});
|
||||
}
|
||||
// log.info("消息的消费者接收到消息,消息的key:{},value:{}", key, value);
|
||||
}
|
||||
|
||||
@KafkaListener(topics = {"topic1", "topic2"},
|
||||
containerFactory = "kafkaListenerContainerFactory",
|
||||
errorHandler = "myKafkaListenerErrorHandler")
|
||||
public void helloWorldKafkaConsumer(ConsumerRecord<String, String> record,
|
||||
Acknowledgment acknowledgment) {
|
||||
String key = record.key();
|
||||
String value = record.value();
|
||||
log.info("消息的消费者接收到消息,消息的key:{},value:{}", key, value);
|
||||
// 手动确认
|
||||
acknowledgment.acknowledge();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.iotdb.consumer;
|
||||
|
||||
/**
|
||||
* @ClassName:
|
||||
* @Description:
|
||||
* @Author: zhuwenqiang
|
||||
* @Date: 2023/11/2
|
||||
*/
|
||||
public class KafkaConsumerQuickStart {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
package com.muyu.iotdb.controller;
|
||||
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName IotDbController
|
||||
* @Date 2024/05/21 16:55
|
||||
*/
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.iotdb.config.IotDBSessionConfig;
|
||||
import com.muyu.iotdb.domain.IotDbParam;
|
||||
import com.muyu.iotdb.service.IotDbServer;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.apache.kafka.common.serialization.StringSerializer;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.rmi.ServerException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* description: iotdb 控制层
|
||||
* date: 2022/8/15 21:50
|
||||
* author: zhouhong
|
||||
*/
|
||||
@Log4j2
|
||||
@RestController
|
||||
public class IotDbController {
|
||||
|
||||
@Resource
|
||||
private IotDbServer iotDbServer;
|
||||
@Resource
|
||||
private IotDBSessionConfig iotDBSessionConfig;
|
||||
|
||||
/**
|
||||
* 插入数据
|
||||
* @param iotDbParam
|
||||
*/
|
||||
@PostMapping("/api/device/insert")
|
||||
public Result insert(@RequestBody IotDbParam iotDbParam) throws StatementExecutionException, ServerException, IoTDBConnectionException {
|
||||
iotDbServer.insertData(iotDbParam);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("getMsg")
|
||||
public void getMsg(@RequestParam("mgs") String msg){
|
||||
//TODO 发送消息 Kafka
|
||||
//TODO 用来配置 kafka消息生产者对象的配置信息
|
||||
Properties properties = new Properties();
|
||||
//TODO 配置 host
|
||||
properties.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "122.51.111.225:9092");
|
||||
//TODO 配置 键值的序列化方式
|
||||
properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
|
||||
properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
|
||||
//TODO 配置消息的确认
|
||||
properties.setProperty(ProducerConfig.ACKS_CONFIG, "all");
|
||||
//TODO 设置重试次数
|
||||
properties.setProperty(ProducerConfig.RETRIES_CONFIG, "3");
|
||||
//TODO 消息压缩
|
||||
properties.setProperty(ProducerConfig.COMPRESSION_TYPE_CONFIG, "gzip");
|
||||
//TODO 创建消息生产者对象
|
||||
KafkaProducer<String, String> kafkaProducer = new KafkaProducer<String, String>(properties);
|
||||
|
||||
//TODO 发送消息
|
||||
//TODO 创建 消息记录
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<String, String>("bwie-topic", "key", msg);
|
||||
// TODO kafkaProducer.send(producerRecord);
|
||||
|
||||
//TODO 异步发送
|
||||
kafkaProducer.send(producerRecord, (metadata, exception) -> {
|
||||
if (exception == null) {
|
||||
//TODO 获取消息发送的分区
|
||||
int partition = metadata.partition();
|
||||
// TODO 消息的偏移量
|
||||
long offset = metadata.offset();
|
||||
//TODO 主题
|
||||
String topic = metadata.topic();
|
||||
System.out.println("发送成功,消息的分区:" + partition + ",消息的偏移量:" + offset + ",主题:" + topic);
|
||||
} else {
|
||||
System.out.println("发送失败,异常信息:" + exception);
|
||||
}
|
||||
});
|
||||
|
||||
//TODO 关闭 kafkaProducer
|
||||
kafkaProducer.close();
|
||||
}
|
||||
/**
|
||||
* 查询数据
|
||||
* @param iotDbParam
|
||||
*/
|
||||
@PostMapping("/api/device/queryData")
|
||||
public Result queryDataFromIotDb(@RequestBody IotDbParam iotDbParam) throws Exception {
|
||||
return Result.success(iotDbServer.queryDataFromIotDb(iotDbParam));
|
||||
}
|
||||
/**
|
||||
* 删除分组
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/api/device/deleteGroup")
|
||||
public Result deleteGroup() throws StatementExecutionException, IoTDBConnectionException {
|
||||
iotDBSessionConfig.deleteStorageGroup("root.a1eaKSRpRty");
|
||||
iotDBSessionConfig.deleteStorageGroup("root.smartretirement");
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.iotdb.domain;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName IotDbParam
|
||||
* @Date 2024/05/21 16:06
|
||||
*/
|
||||
@Data
|
||||
public class IotDbParam {
|
||||
/**
|
||||
* 产品PK
|
||||
*/
|
||||
private String pk;
|
||||
/**
|
||||
* 设备号
|
||||
*/
|
||||
private String sn;
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
private Long time;
|
||||
/**
|
||||
* 实时呼吸
|
||||
*/
|
||||
private String breath;
|
||||
/**
|
||||
* 实时心率
|
||||
*/
|
||||
private String heart;
|
||||
/**
|
||||
* 查询开始时间
|
||||
*/
|
||||
private String startTime;
|
||||
/**
|
||||
* 查询结束时间
|
||||
*/
|
||||
private String endTime;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.iotdb.domain;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName IotDbResult
|
||||
* @Date 2024/05/21 16:10
|
||||
*/
|
||||
@Data
|
||||
public class IotDbResult {
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
private String time;
|
||||
/**
|
||||
* 产品PK
|
||||
*/
|
||||
private String pk;
|
||||
/**
|
||||
* 设备号
|
||||
*/
|
||||
private String sn;
|
||||
/**
|
||||
* 实时呼吸
|
||||
*/
|
||||
private String breath;
|
||||
/**
|
||||
* 实时心率
|
||||
*/
|
||||
private String heart;
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.iotdb.producer;
|
||||
|
||||
/**
|
||||
* @ClassName:
|
||||
* @Description:
|
||||
* @Author: zhuwenqiang
|
||||
* @Date: 2023/11/2
|
||||
*/
|
||||
public class KafkaProducerQuickStart {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 消息队列模式:
|
||||
* 点对点: 1 : 1
|
||||
*
|
||||
* 发布订阅: 1 : N
|
||||
*
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.iotdb.service;
|
||||
|
||||
|
||||
import com.muyu.iotdb.domain.IotDbParam;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName IotDbServer
|
||||
* @Date 2024/05/21 16:56
|
||||
*/
|
||||
public interface IotDbServer {
|
||||
void insertData(IotDbParam iotDbParam);
|
||||
|
||||
Object queryDataFromIotDb(IotDbParam iotDbParam);
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
package com.muyu.iotdb.service.impl;
|
||||
|
||||
|
||||
import com.muyu.iotdb.domain.IotDbParam;
|
||||
import com.muyu.iotdb.domain.IotDbResult;
|
||||
import com.muyu.iotdb.service.IotDbServer;
|
||||
import com.muyu.iotdb.config.IotDBSessionConfig;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.apache.iotdb.session.SessionDataSet;
|
||||
import org.apache.iotdb.tsfile.read.common.Field;
|
||||
import org.apache.iotdb.tsfile.read.common.RowRecord;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.rmi.ServerException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName IotDbServerImpl
|
||||
* @Date 2024/05/21 16:55
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class IotDbServerImpl implements IotDbServer {
|
||||
|
||||
@Resource
|
||||
private IotDBSessionConfig iotDBSessionConfig;
|
||||
|
||||
@Override
|
||||
public void insertData(IotDbParam iotDbParam) {
|
||||
// iotDbParam: 模拟设备上报消息
|
||||
// bizkey: 业务唯一key PK :产品唯一编码 SN:设备唯一编码
|
||||
String deviceId = "root.bizkey."+ iotDbParam.getPk() + "." + iotDbParam.getSn();
|
||||
// 将设备上报的数据存入数据库(时序数据库)
|
||||
List<String> measurementsList = new ArrayList<>();
|
||||
measurementsList.add("heart");
|
||||
measurementsList.add("breath");
|
||||
List<String> valuesList = new ArrayList<>();
|
||||
valuesList.add(String.valueOf(iotDbParam.getHeart()));
|
||||
valuesList.add(String.valueOf(iotDbParam.getBreath()));
|
||||
try {
|
||||
iotDBSessionConfig.insertRecord(deviceId, iotDbParam.getTime(), measurementsList, valuesList);
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (StatementExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ServerException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IotDbResult> queryDataFromIotDb(IotDbParam iotDbParam) {
|
||||
List<IotDbResult> iotDbResultList = new ArrayList<>();
|
||||
|
||||
if (null != iotDbParam.getPk() && null != iotDbParam.getSn()) {
|
||||
String sql = "select * from root.bizkey."+ iotDbParam.getPk() +"." + iotDbParam.getSn() + " where time >= "
|
||||
+ iotDbParam.getStartTime() + " and time < " + iotDbParam.getEndTime();
|
||||
SessionDataSet sessionDataSet = null;
|
||||
try {
|
||||
sessionDataSet = iotDBSessionConfig.query(sql);
|
||||
} catch (StatementExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
List<String> columnNames = sessionDataSet.getColumnNames();
|
||||
List<String> titleList = new ArrayList<>();
|
||||
// 排除Time字段 -- 方便后面后面拼装数据
|
||||
for (int i = 1; i < columnNames.size(); i++) {
|
||||
String[] temp = columnNames.get(i).split("\\.");
|
||||
titleList.add(temp[temp.length - 1]);
|
||||
}
|
||||
// 封装处理数据
|
||||
try {
|
||||
packagingData(iotDbParam, iotDbResultList, sessionDataSet, titleList);
|
||||
} catch (StatementExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
log.info("PK或者SN不能为空!!");
|
||||
}
|
||||
return iotDbResultList;
|
||||
}
|
||||
/**
|
||||
* 封装处理数据
|
||||
* @param iotDbParam
|
||||
* @param iotDbResultList
|
||||
* @param sessionDataSet
|
||||
* @param titleList
|
||||
* @throws StatementExecutionException
|
||||
* @throws IoTDBConnectionException
|
||||
*/
|
||||
private void packagingData(IotDbParam iotDbParam, List<IotDbResult> iotDbResultList, SessionDataSet sessionDataSet, List<String> titleList)
|
||||
throws StatementExecutionException, IoTDBConnectionException {
|
||||
int fetchSize = sessionDataSet.getFetchSize();
|
||||
if (fetchSize > 0) {
|
||||
while (sessionDataSet.hasNext()) {
|
||||
IotDbResult iotDbResult = new IotDbResult();
|
||||
RowRecord next = sessionDataSet.next();
|
||||
List<Field> fields = next.getFields();
|
||||
String timeString = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(next.getTimestamp());
|
||||
iotDbResult.setTime(timeString);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
Field field = fields.get(i);
|
||||
// 这里的需要按照类型获取
|
||||
map.put(titleList.get(i), field.getObjectValue(field.getDataType()).toString());
|
||||
}
|
||||
iotDbResult.setTime(timeString);
|
||||
iotDbResult.setPk(iotDbParam.getPk());
|
||||
iotDbResult.setSn(iotDbParam.getSn());
|
||||
iotDbResult.setHeart(map.get("heart"));
|
||||
iotDbResult.setBreath(map.get("breath"));
|
||||
iotDbResultList.add(iotDbResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9009
|
||||
# Spring
|
||||
spring:
|
||||
kafka:
|
||||
producer:
|
||||
# Kafka服务器
|
||||
bootstrap-servers: 175.24.138.82:9092
|
||||
# 开启事务,必须在开启了事务的方法中发送,否则报错
|
||||
transaction-id-prefix: kafkaTx-
|
||||
# 发生错误后,消息重发的次数,开启事务必须设置大于0。
|
||||
retries: 3
|
||||
# acks=0 : 生产者在成功写入消息之前不会等待任何来自服务器的响应。
|
||||
# acks=1 : 只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。
|
||||
# acks=all :只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。
|
||||
# 开启事务时,必须设置为all
|
||||
acks: all
|
||||
# 当有多个消息需要被发送到同一个分区时,生产者会把它们放在同一个批次里。该参数指定了一个批次可以使用的内存大小,按照字节数计算。
|
||||
batch-size: 16384
|
||||
# 生产者内存缓冲区的大小。
|
||||
buffer-memory: 1024000
|
||||
# 键的序列化方式
|
||||
key-serializer: org.springframework.kafka.support.serializer.JsonSerializer
|
||||
# 值的序列化方式(建议使用Json,这种序列化方式可以无需额外配置传输实体类)
|
||||
value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
|
||||
|
||||
consumer:
|
||||
# Kafka服务器
|
||||
bootstrap-servers: 175.24.138.82:9092
|
||||
group-id: firstGroup
|
||||
# 自动提交的时间间隔 在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: false
|
||||
# 键的反序列化方式
|
||||
#key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
||||
key-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
|
||||
# 值的反序列化方式(建议使用Json,这种序列化方式可以无需额外配置传输实体类)
|
||||
value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
|
||||
# 配置消费者的 Json 反序列化的可信赖包,反序列化实体类需要
|
||||
properties:
|
||||
spring:
|
||||
json:
|
||||
trusted:
|
||||
packages: "*"
|
||||
# 这个参数定义了poll方法最多可以拉取多少条消息,默认值为500。如果在拉取消息的时候新消息不足500条,那有多少返回多少;如果超过500条,每次只返回500。
|
||||
# 这个默认值在有些场景下太大,有些场景很难保证能够在5min内处理完500条消息,
|
||||
# 如果消费者无法在5分钟内处理完500条消息的话就会触发reBalance,
|
||||
# 然后这批消息会被分配到另一个消费者中,还是会处理不完,这样这批消息就永远也处理不完。
|
||||
# 要避免出现上述问题,提前评估好处理一条消息最长需要多少时间,然后覆盖默认的max.poll.records参数
|
||||
# 注:需要开启BatchListener批量监听才会生效,如果不开启BatchListener则不会出现reBalance情况
|
||||
max-poll-records: 3
|
||||
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
|
||||
main:
|
||||
allow-circular-references: true # 允许循环依赖
|
||||
jackson: # json 序列化 和 返序列化 转换
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: bwie-kafka
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 175.24.138.82:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 175.24.138.82:8848
|
||||
# namespace: a9b66e92-e507-47ba-9674-6f939f793aca
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -55,13 +55,13 @@
|
|||
</dependency>
|
||||
|
||||
|
||||
<!-- MuYu Common Swagger -->
|
||||
<!-- muyu Common Swagger -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common System-->
|
||||
<!-- muyu Common System-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-system</artifactId>
|
|
@ -12,8 +12,8 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||
*/
|
||||
@EnableCustomSwagger2
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||
public class MuYuFileApplication {
|
||||
public class MuyuFileApplication {
|
||||
public static void main (String[] args) {
|
||||
SpringApplication.run(MuYuFileApplication.class, args);
|
||||
SpringApplication.run(MuyuFileApplication.class, args);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue