test:(多数据源)
parent
b89390bbc3
commit
cfb23329d2
|
@ -71,9 +71,6 @@ public class FenceGroups extends BaseEntity {
|
|||
.groupName(fenceGroupsEditReq.getGroupName())
|
||||
.build();
|
||||
}
|
||||
/**
|
||||
*电子围栏集合
|
||||
* */
|
||||
private List<Fences> fencesList;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import com.muyu.domain.req.FencesEditReq;
|
||||
import com.muyu.domain.req.FencesQueryReq;
|
||||
import com.muyu.domain.req.FencesSaveReq;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.naming.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/** 电子围栏
|
||||
* @ClassDescription:
|
||||
|
@ -19,44 +29,99 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class Fences extends BaseEntity {
|
||||
/**
|
||||
*
|
||||
*围栏id
|
||||
* **/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 围栏id */
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
@ApiModelProperty(name = "围栏id", value = "围栏id")
|
||||
private Long id;
|
||||
/**
|
||||
*围栏组id
|
||||
*
|
||||
* **/
|
||||
private String groupId;
|
||||
/**
|
||||
*电子围栏名称
|
||||
*
|
||||
* **/
|
||||
|
||||
/** 围栏组id */
|
||||
@Excel(name = "围栏组id")
|
||||
@ApiModelProperty(name = "围栏组id", value = "围栏组id")
|
||||
private Long groupId;
|
||||
|
||||
/** 电子围栏名称 */
|
||||
@Excel(name = "电子围栏名称")
|
||||
@ApiModelProperty(name = "电子围栏名称", value = "电子围栏名称")
|
||||
private String fenceName;
|
||||
/**
|
||||
*
|
||||
*围栏类型 :原型 多边
|
||||
* **/
|
||||
|
||||
/** 围栏类型 */
|
||||
@Excel(name = "围栏类型")
|
||||
@ApiModelProperty(name = "围栏类型", value = "围栏类型")
|
||||
private String fenceType;
|
||||
/**
|
||||
*
|
||||
*半径
|
||||
* **/
|
||||
private Double radius;
|
||||
/**
|
||||
* 驶入 驶出
|
||||
*
|
||||
* **/
|
||||
|
||||
/** 半径 */
|
||||
@Excel(name = "半径")
|
||||
@ApiModelProperty(name = "半径", value = "半径")
|
||||
private String radius;
|
||||
|
||||
/** 驶入、驶出 */
|
||||
@Excel(name = "驶入、驶出")
|
||||
@ApiModelProperty(name = "驶入、驶出", value = "驶入、驶出")
|
||||
private String eventType;
|
||||
/**
|
||||
*围栏状态
|
||||
*
|
||||
* **/
|
||||
private String staut;
|
||||
/**
|
||||
*坐标
|
||||
*
|
||||
* **/
|
||||
|
||||
/** 围栏状态 */
|
||||
@Excel(name = "围栏状态")
|
||||
@ApiModelProperty(name = "围栏状态", value = "围栏状态")
|
||||
private String status;
|
||||
|
||||
/** 坐标 */
|
||||
@Excel(name = "坐标")
|
||||
@ApiModelProperty(name = "坐标", value = "坐标")
|
||||
private String polygonPoints;
|
||||
|
||||
/**
|
||||
* 围栏坐标
|
||||
*/
|
||||
@Excel(name = "坐标")
|
||||
@ApiModelProperty(name = "坐标", value = "坐标")
|
||||
@TableField(exist = false)
|
||||
private List<Path> path;
|
||||
|
||||
/**
|
||||
* 查询构造器
|
||||
*/
|
||||
public static Fences queryBuild( FencesQueryReq fencesQueryReq){
|
||||
return Fences.builder()
|
||||
.groupId(fencesQueryReq.getGroupId())
|
||||
.fenceName(fencesQueryReq.getFenceName())
|
||||
.fenceType(fencesQueryReq.getFenceType())
|
||||
.radius(fencesQueryReq.getRadius())
|
||||
.eventType(fencesQueryReq.getEventType())
|
||||
.status(fencesQueryReq.getStatus())
|
||||
.polygonPoints(fencesQueryReq.getPolygonPoints())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加构造器
|
||||
*/
|
||||
public static Fences saveBuild(FencesSaveReq fencesSaveReq){
|
||||
return Fences.builder()
|
||||
.groupId(fencesSaveReq.getGroupId())
|
||||
.fenceName(fencesSaveReq.getFenceName())
|
||||
.fenceType(fencesSaveReq.getFenceType())
|
||||
.radius(fencesSaveReq.getRadius())
|
||||
.eventType(fencesSaveReq.getEventType())
|
||||
.status(fencesSaveReq.getStatus())
|
||||
.polygonPoints(fencesSaveReq.getPolygonPoints())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改构造器
|
||||
*/
|
||||
public static Fences editBuild(Long id, FencesEditReq fencesEditReq){
|
||||
return Fences.builder()
|
||||
.id(id)
|
||||
.groupId(fencesEditReq.getGroupId())
|
||||
.fenceName(fencesEditReq.getFenceName())
|
||||
.fenceType(fencesEditReq.getFenceType())
|
||||
.radius(fencesEditReq.getRadius())
|
||||
.eventType(fencesEditReq.getEventType())
|
||||
.status(fencesEditReq.getStatus())
|
||||
.polygonPoints(fencesEditReq.getPolygonPoints())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.domain.req;
|
||||
|
||||
import com.muyu.domain.Fences;
|
||||
import lombok.Data;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -8,6 +9,8 @@ import lombok.experimental.SuperBuilder;
|
|||
import io.swagger.annotations.*;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 电子围栏组对象 fence_groups
|
||||
*
|
||||
|
@ -33,4 +36,6 @@ public class FenceGroupsSaveReq extends BaseEntity {
|
|||
@ApiModelProperty(name = "电子围栏名称", value = "电子围栏名称")
|
||||
private String groupName;
|
||||
|
||||
private List<Fences> fencesList;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.muyu.domain.req;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import io.swagger.annotations.*;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 电子围栏对象 fences
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-06-02
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ApiModel(value = "FencesQueryReq", description = "电子围栏")
|
||||
public class FencesQueryReq extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 围栏组id */
|
||||
@ApiModelProperty(name = "围栏组id", value = "围栏组id")
|
||||
private Long groupId;
|
||||
|
||||
/** 电子围栏名称 */
|
||||
@ApiModelProperty(name = "电子围栏名称", value = "电子围栏名称")
|
||||
private String fenceName;
|
||||
|
||||
/** 围栏类型 */
|
||||
@ApiModelProperty(name = "围栏类型", value = "围栏类型")
|
||||
private String fenceType;
|
||||
|
||||
/** 半径 */
|
||||
@ApiModelProperty(name = "半径", value = "半径")
|
||||
private String radius;
|
||||
|
||||
/** 驶入、驶出 */
|
||||
@ApiModelProperty(name = "驶入、驶出", value = "驶入、驶出")
|
||||
private String eventType;
|
||||
|
||||
/** 围栏状态 */
|
||||
@ApiModelProperty(name = "围栏状态", value = "围栏状态")
|
||||
private String status;
|
||||
|
||||
/** 坐标 */
|
||||
@ApiModelProperty(name = "坐标", value = "坐标")
|
||||
private String polygonPoints;
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.domain.req;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import io.swagger.annotations.*;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 电子围栏对象 fences
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-06-02
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ApiModel(value = "FencesSaveReq", description = "电子围栏")
|
||||
public class FencesSaveReq extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 围栏id */
|
||||
|
||||
@ApiModelProperty(name = "围栏id", value = "围栏id")
|
||||
private Long id;
|
||||
|
||||
/** 围栏组id */
|
||||
|
||||
@ApiModelProperty(name = "围栏组id", value = "围栏组id")
|
||||
private Long groupId;
|
||||
|
||||
/** 电子围栏名称 */
|
||||
|
||||
@ApiModelProperty(name = "电子围栏名称", value = "电子围栏名称")
|
||||
private String fenceName;
|
||||
|
||||
/** 围栏类型 */
|
||||
|
||||
@ApiModelProperty(name = "围栏类型", value = "围栏类型")
|
||||
private String fenceType;
|
||||
|
||||
/** 半径 */
|
||||
|
||||
@ApiModelProperty(name = "半径", value = "半径")
|
||||
private String radius;
|
||||
|
||||
/** 驶入、驶出 */
|
||||
|
||||
@ApiModelProperty(name = "驶入、驶出", value = "驶入、驶出")
|
||||
private String eventType;
|
||||
|
||||
/** 围栏状态 */
|
||||
|
||||
@ApiModelProperty(name = "围栏状态", value = "围栏状态")
|
||||
private String status;
|
||||
|
||||
/** 坐标 */
|
||||
|
||||
@ApiModelProperty(name = "坐标", value = "坐标")
|
||||
private String polygonPoints;
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
<?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-networking</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-networking-many-datasources</artifactId>
|
||||
<description>动态多数据源</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>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/6/3 21:00
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication(exclude = {DynamicDataSourceAutoConfiguration.class
|
||||
,DataSourceAutoConfiguration.class})
|
||||
public class CloudManyDataSourceApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CloudManyDataSourceApplication.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.muyu.config;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
|
||||
import com.muyu.config.holder.DynamicDataSourceHolder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/** 动态数据源调用
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/6/4 8:54
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DynamicDataSource extends AbstractRoutingDataSource {
|
||||
|
||||
|
||||
/***
|
||||
*
|
||||
* 备份所有的数据源信息 备份的是个指针
|
||||
*
|
||||
* **/
|
||||
private Map<Object, Object> defineTargetDataSources;
|
||||
|
||||
|
||||
|
||||
public void put(String key, DruidDataSource value){
|
||||
defineTargetDataSources.put(key,value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 决定当前线程使用那个数据源
|
||||
* **/
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
return DynamicDataSourceHolder.getDynamicDatasourceKey();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.config.contents;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/6/4 9:33
|
||||
*/
|
||||
public class DatasourceContent {
|
||||
|
||||
|
||||
public final static String PASSWORDS = "sal75-z";
|
||||
|
||||
public final static String DATASOURCE_URL = "jdbc:mysql://{}:{}/etl?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai";
|
||||
|
||||
public final static String DATASOURCE_USERNAME = "root";
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.muyu.config.domain.model;
|
||||
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
import static com.muyu.config.contents.DatasourceContent.*;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/6/4 9:30
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class DataSourceInfo {
|
||||
private String key;
|
||||
|
||||
private String url;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String password;
|
||||
|
||||
public static DataSourceInfo getDataSourceInfo(String key,String host,Integer port)
|
||||
{
|
||||
return DataSourceInfo.builder()
|
||||
.key(key)
|
||||
.url(StringUtils.format(DATASOURCE_URL,host,port))
|
||||
.userName(DATASOURCE_USERNAME)
|
||||
.password(PASSWORDS)
|
||||
.build();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.config.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/** 企业信息
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/6/4 14:15
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class EntInfo {
|
||||
|
||||
private String entCode;
|
||||
|
||||
private String ip;
|
||||
|
||||
private Integer port;
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.muyu.config.factory;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.muyu.config.domain.model.DataSourceInfo;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/** 工厂
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/6/4 9:09
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class DruidDataSourceFactory {
|
||||
|
||||
|
||||
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("连接成功");
|
||||
return druidDataSource;
|
||||
} catch (SQLException e) {
|
||||
log.error("连接失败");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.config.holder;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/6/4 14:11
|
||||
*/
|
||||
@Slf4j
|
||||
public class DynamicDataSourceHolder {
|
||||
|
||||
private static final ThreadLocal<String> DYNAMIC_DATASOURCE = new ThreadLocal<>();
|
||||
|
||||
public static void setDynamicDatasourceKey(String key) {
|
||||
log.info("数据源切换为:{}", key);
|
||||
DYNAMIC_DATASOURCE.set(key);
|
||||
}
|
||||
|
||||
public static String getDynamicDatasourceKey() {
|
||||
String key = DYNAMIC_DATASOURCE.get();
|
||||
Assert.notNull(key,"请携带数据表示");
|
||||
return key;
|
||||
}
|
||||
|
||||
public static void removeDynamicDatasourceKey() {
|
||||
log.info("移除数据源:{}", DYNAMIC_DATASOURCE.get());
|
||||
DYNAMIC_DATASOURCE.remove();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.muyu.config.role;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import com.muyu.config.DynamicDataSource;
|
||||
import com.muyu.config.domain.model.DataSourceInfo;
|
||||
import com.muyu.config.domain.model.EntInfo;
|
||||
import com.muyu.config.factory.DruidDataSourceFactory;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/6/4 9:05
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class ManyDataSource {
|
||||
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
new Thread(()-> {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException ignored) {}
|
||||
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);
|
||||
DynamicDataSource dynamicDataSource =SpringUtils.getBean(DynamicDataSource.class);
|
||||
|
||||
EntInfo entInfo = EntInfo.builder()
|
||||
.entCode("ent_4587")
|
||||
.ip("115.159.67.205")
|
||||
.port(3307)
|
||||
.build();
|
||||
DataSourceInfo dataSourceInfo = DataSourceInfo.getDataSourceInfo(entInfo.getEntCode(), entInfo.getIp(), entInfo.getPort());
|
||||
DruidDataSource druidDataSource = druidDataSourceFactory.create(dataSourceInfo);
|
||||
dynamicDataSource.put(dataSourceInfo.getKey(),druidDataSource);
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private List<EntInfo> dataSourceInfoList(){
|
||||
List<EntInfo> list = new ArrayList<>();
|
||||
list.add(
|
||||
EntInfo.builder()
|
||||
.entCode("ent_4587")
|
||||
.ip("115.159.67.205")
|
||||
.port(3307)
|
||||
.build()
|
||||
);
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
||||
Map<Object, Object> map = new HashMap<>();
|
||||
dataSourceInfoList().stream()
|
||||
.map(entInfo -> DataSourceInfo.getDataSourceInfo(entInfo.getEntCode(),entInfo.getIp(),entInfo.getPort()))
|
||||
.forEach(dataSourceInfo -> {
|
||||
map.put(dataSourceInfo.getKey(),druidDataSourceFactory.create(dataSourceInfo));
|
||||
});
|
||||
|
||||
//设置动态数据源
|
||||
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
||||
dynamicDataSource.setTargetDataSources(map);
|
||||
dynamicDataSource.setDefaultTargetDataSource(map);
|
||||
return dynamicDataSource;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Spring Boot Version: ${spring-boot.version}
|
||||
Spring Application Name: ${spring.application.name}
|
|
@ -0,0 +1,28 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9205
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: muyu-many-datasource
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 115.159.67.205:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 115.159.67.205:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
logging:
|
||||
level:
|
||||
com.muyu.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-many-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>
|
|
@ -22,3 +22,4 @@ public class NetworkingApplication {
|
|||
SpringApplication.run(NetworkingApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.system.controller;
|
||||
package com.muyu.networking.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -11,20 +11,13 @@ import com.muyu.domain.req.FenceGroupsSaveReq;
|
|||
import com.muyu.networking.service.FenceGroupsService;
|
||||
import io.swagger.annotations.*;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
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.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -44,7 +37,6 @@ public class FenceGroupsController extends BaseController {
|
|||
* 查询电子围栏组列表
|
||||
*/
|
||||
@ApiOperation("获取电子围栏组列表")
|
||||
@RequiresPermissions("system:groups:list")
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<FenceGroups>> list(FenceGroupsQueryReq fenceGroupsQueryReq) {
|
||||
startPage();
|
||||
|
@ -56,7 +48,6 @@ public class FenceGroupsController extends BaseController {
|
|||
* 导出电子围栏组列表
|
||||
*/
|
||||
@ApiOperation("导出电子围栏组列表")
|
||||
@RequiresPermissions("system:groups:export")
|
||||
@Log(title = "电子围栏组", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, FenceGroups fenceGroups) {
|
||||
|
@ -69,7 +60,7 @@ public class FenceGroupsController extends BaseController {
|
|||
* 获取电子围栏组详细信息
|
||||
*/
|
||||
@ApiOperation("获取电子围栏组详细信息")
|
||||
@RequiresPermissions("system:groups:query")
|
||||
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public Result<FenceGroups> getInfo(@PathVariable("id") Long id) {
|
||||
|
@ -79,7 +70,7 @@ public class FenceGroupsController extends BaseController {
|
|||
/**
|
||||
* 新增电子围栏组
|
||||
*/
|
||||
@RequiresPermissions("system:groups:add")
|
||||
|
||||
@Log(title = "电子围栏组", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增电子围栏组")
|
||||
|
@ -90,7 +81,7 @@ public class FenceGroupsController extends BaseController {
|
|||
/**
|
||||
* 修改电子围栏组
|
||||
*/
|
||||
@RequiresPermissions("system:groups:edit")
|
||||
|
||||
@Log(title = "电子围栏组", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/{id}")
|
||||
@ApiOperation("修改电子围栏组")
|
||||
|
@ -101,7 +92,7 @@ public class FenceGroupsController extends BaseController {
|
|||
/**
|
||||
* 删除电子围栏组
|
||||
*/
|
||||
@RequiresPermissions("system:groups:remove")
|
||||
|
||||
@Log(title = "电子围栏组", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除电子围栏组")
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
package com.muyu.networking.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.domain.Fences;
|
||||
import com.muyu.domain.req.FencesEditReq;
|
||||
import com.muyu.domain.req.FencesQueryReq;
|
||||
|
||||
import com.muyu.networking.service.FenceService;
|
||||
import io.swagger.annotations.*;
|
||||
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;
|
||||
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.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
|
||||
|
||||
/**
|
||||
* 电子围栏Controller
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-06-02
|
||||
*/
|
||||
@Api(tags = "电子围栏")
|
||||
@RestController
|
||||
@RequestMapping("/fences")
|
||||
public class FencesController extends BaseController {
|
||||
@Autowired
|
||||
private FenceService fencesService;
|
||||
|
||||
/**
|
||||
* 查询电子围栏列表
|
||||
*/
|
||||
@ApiOperation("获取电子围栏列表")
|
||||
@RequiresPermissions("system:fences:list")
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<Fences>> list(FencesQueryReq fencesQueryReq) {
|
||||
startPage();
|
||||
List<Fences> list = fencesService.list(Fences.queryBuild(fencesQueryReq));
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出电子围栏列表
|
||||
*/
|
||||
@ApiOperation("导出电子围栏列表")
|
||||
@RequiresPermissions("system:fences:export")
|
||||
@Log(title = "电子围栏", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Fences fences) {
|
||||
List<Fences> list = fencesService.list(fences);
|
||||
ExcelUtil<Fences> util = new ExcelUtil<Fences>(Fences.class);
|
||||
util.exportExcel(response, list, "电子围栏数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取电子围栏详细信息
|
||||
*/
|
||||
@ApiOperation("获取电子围栏详细信息")
|
||||
@RequiresPermissions("system:fences:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public Result<Fences> getInfo(@PathVariable("id") Long id) {
|
||||
return Result.success(fencesService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增电子围栏
|
||||
*/
|
||||
@RequiresPermissions("system:fences:add")
|
||||
@Log(title = "电子围栏", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增电子围栏")
|
||||
public Result<String> add(@RequestBody Fences fences) {
|
||||
fencesService.insertFence(fences);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改电子围栏
|
||||
*/
|
||||
@RequiresPermissions("system:fences:edit")
|
||||
@Log(title = "电子围栏", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/{id}")
|
||||
@ApiOperation("修改电子围栏")
|
||||
public Result<String> edit(@PathVariable Long id, @RequestBody FencesEditReq fencesEditReq) {
|
||||
return toAjax(fencesService.updateById(Fences.editBuild(id,fencesEditReq)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除电子围栏
|
||||
*/
|
||||
@RequiresPermissions("system:fences:remove")
|
||||
@Log(title = "电子围栏", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除电子围栏")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
|
||||
public Result<String> remove(@PathVariable List<Long> ids) {
|
||||
return toAjax(fencesService.removeBatchByIds(ids));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.networking.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.domain.FenceGroups;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/6/2 16:35
|
||||
*/
|
||||
public interface FenceGroupsService extends IService<FenceGroups> {
|
||||
|
||||
/***
|
||||
* 查询电子围栏 组
|
||||
* */
|
||||
public List<FenceGroups> list(FenceGroups fenceGroups);
|
||||
|
||||
|
||||
}
|
|
@ -3,6 +3,8 @@ package com.muyu.networking.service;
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.domain.Fences;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
|
@ -11,6 +13,16 @@ import com.muyu.domain.Fences;
|
|||
*/
|
||||
public interface FenceService extends IService<Fences> {
|
||||
|
||||
int insertFence(Fences fences);
|
||||
/**
|
||||
* 查询电子围栏表
|
||||
*
|
||||
* **/
|
||||
public List<Fences> list(Fences fences);
|
||||
|
||||
|
||||
/***
|
||||
* 添加电子围栏
|
||||
* */
|
||||
public int insertFence(Fences fences);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.networking.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.domain.FenceGroups;
|
||||
import com.muyu.networking.mapper.FenceGroupsMapper;
|
||||
import com.muyu.networking.service.FenceGroupsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/6/2 16:38
|
||||
*/
|
||||
@Service
|
||||
public class FenceGroupsServiceImpl extends ServiceImpl<FenceGroupsMapper, FenceGroups> implements FenceGroupsService {
|
||||
@Override
|
||||
public List<FenceGroups> list(FenceGroups fenceGroups) {
|
||||
LambdaQueryWrapper<FenceGroups> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,23 +1,18 @@
|
|||
package com.muyu.networking.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.domain.Fences;
|
||||
import com.muyu.networking.mapper.FenceMapper;
|
||||
import com.muyu.networking.mapper.FencesMapper;
|
||||
import com.muyu.networking.service.FenceService;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
|
@ -25,11 +20,46 @@ import java.util.stream.Collectors;
|
|||
* @Author: zhangxu
|
||||
* @Created: 2024/5/31 16:23
|
||||
*/
|
||||
public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fences> implements FenceService {
|
||||
@Service
|
||||
public class FenceServiceImpl extends ServiceImpl<FencesMapper, Fences> implements FenceService {
|
||||
|
||||
@Resource
|
||||
private FencesMapper fenceMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<Fences> list(Fences fences) {
|
||||
LambdaQueryWrapper<Fences> fencesLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
if (fences.getId() != null) {
|
||||
fencesLambdaQueryWrapper.eq(Fences::getId, fences.getId());
|
||||
}
|
||||
if (fences.getFenceName() != null) {
|
||||
fencesLambdaQueryWrapper.like(Fences::getFenceName, fences.getFenceName());
|
||||
}
|
||||
if (fences.getFenceType() != null) {
|
||||
fencesLambdaQueryWrapper.eq(Fences::getFenceType, fences.getFenceType());
|
||||
}
|
||||
if (fences.getStatus() != null) {
|
||||
fencesLambdaQueryWrapper.eq(Fences::getStatus, fences.getStatus());
|
||||
}
|
||||
if (fences.getGroupId() != null) {
|
||||
fencesLambdaQueryWrapper.eq(Fences::getGroupId, fences.getGroupId());
|
||||
}
|
||||
|
||||
return list(fencesLambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertFence(Fences fences) {
|
||||
return 0;
|
||||
int count=0;
|
||||
fences.setCreateBy(SecurityUtils.getUsername());
|
||||
fences.setFenceName("电子围栏"+count++);
|
||||
fences.setCreateTime(new Date());
|
||||
String string = fences.getPath().toString();
|
||||
fences.setRadius(string);
|
||||
fences.setPolygonPoints(string);
|
||||
fenceMapper.add(fences);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?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.networking.mapper.FencesMapper">
|
||||
|
||||
<resultMap type="com.muyu.domain.Fences" id="FencesResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="groupId" column="group_id" />
|
||||
<result property="fenceName" column="fence_name" />
|
||||
<result property="fenceType" column="fence_type" />
|
||||
<result property="radius" column="radius" />
|
||||
<result property="eventType" column="event_type" />
|
||||
<result property="status" column="status" />
|
||||
<result property="polygonPoints" column="polygon_points" />
|
||||
<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="selectFencesVo">
|
||||
select id, group_id, fence_name, fence_type, radius, event_type, status, polygon_points, remark, create_by, create_time, update_by, update_time from fences
|
||||
</sql>
|
||||
<insert id="add">
|
||||
insert into fences( fence_name, polygon_points, remark, create_by, create_time, update_by, update_time)
|
||||
values( #{fenceName}, #{polygonPoints}, #{remark}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime})
|
||||
</insert>
|
||||
</mapper>
|
Loading…
Reference in New Issue