Browse Source

feat: 多数据源配置

TwoKe945 1 năm trước cách đây
mục cha
commit
9b51b7e6c7

+ 9 - 0
ljclw-core/pom.xml

@@ -25,6 +25,15 @@
             <scope>test</scope>
         </dependency>
 
+
+        <!-- 防止进入swagger页面报类型转换错误,排除3.0.0中的引用,手动增加1.6.2版本 -->
+        <dependency>
+            <groupId>io.swagger</groupId>
+            <artifactId>swagger-models</artifactId>
+            <version>1.6.2</version>
+        </dependency>
+
+
         <dependency>
             <groupId>com.ruoyi</groupId>
             <artifactId>ruoyi-common</artifactId>

+ 26 - 0
ljclw-core/src/main/java/com/ruizheng/clw/config/CustomMyBatisPlusConfig.java

@@ -0,0 +1,26 @@
+package com.ruizheng.clw.config;
+
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class CustomMyBatisPlusConfig {
+ 
+    /**
+     * 分页插件,一缓和二缓遵循mybatis的规则
+     */
+    @Bean
+    public MybatisPlusInterceptor mybatisPlusInterceptor() {
+        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
+        // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求  默认false
+         paginationInnerInterceptor.setOverflow(false);
+        // 设置最大单页限制数量,默认 500 条,-1 不受限制
+        paginationInnerInterceptor.setMaxLimit(-1L);
+        interceptor.addInnerInterceptor(paginationInnerInterceptor);
+
+        return interceptor;
+    }
+}

+ 35 - 0
ljclw-core/src/main/java/com/ruizheng/clw/controller/CarInfoController.java

@@ -0,0 +1,35 @@
+package com.ruizheng.clw.controller;
+
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruizheng.clw.domain.CarInfo;
+import com.ruizheng.clw.service.CarInfoService;
+import com.ruoyi.common.annotation.DataSource;
+import com.ruoyi.common.enums.DataSourceType;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api("车辆信息")
+@RestController
+@RequestMapping("/car")
+public class CarInfoController {
+
+    @Autowired
+    private CarInfoService carInfoService;
+
+    @GetMapping("/page")
+    @ApiOperation("查询车辆列表")
+    @DataSource(DataSourceType.SLAVE)
+    public Object get() {
+        return carInfoService.page(new Page<CarInfo>(1, 10));
+    }
+
+    @GetMapping("/list")
+    public String index() {
+        return "11";
+    }
+}

+ 250 - 0
ljclw-core/src/main/java/com/ruizheng/clw/domain/CarInfo.java

@@ -0,0 +1,250 @@
+package com.ruizheng.clw.domain;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Getter
+@Setter
+@ToString
+@TableName("mhjyztk.hzfk_clw_xfcl")
+public class CarInfo {
+    /**
+     * id
+     */
+    @TableId
+    private Long id;
+    /**
+     * 组织id
+     */
+    private Long orgId;
+    /**
+     * 部门id
+     */
+    private Long depId;
+    /**
+     * 创建时间
+     */
+    private Date gmtCreate;
+    /**
+     * 修改时间
+     */
+    private Date gmtModified;
+    /**
+     * 车牌号码
+     */
+    private String plateNumber;
+    /**
+     * 负责人
+     */
+    private Long userId;
+    /**
+     * 车辆类型
+     */
+    private Long categoryId;
+    /**
+     * 终端绑定
+     */
+    private String terminalBind;
+    /**
+     * 车辆来源:0采购 1自购
+     */
+    private Integer source;
+    /**
+     * 0国产 1进口
+     */
+    private Integer domesticImport;
+    /**
+     * 制造国
+     */
+    private String manufactureCountry;
+    /**
+     * 制造企业
+     */
+    private String manufactureCompany;
+    /**
+     * 车辆品牌
+     */
+    private String brand;
+    /**
+     * 车辆型号
+     */
+    private String model;
+    /**
+     * 车辆识别代号
+     */
+    private String identificationCode;
+    /**
+     * 车身颜色
+     */
+    private String color;
+    /**
+     * 颜料种类
+     */
+    private String fuelType;
+    /**
+     * 发动机号
+     */
+    private String engineNumber;
+    /**
+     * 发动机排量
+     */
+    private String emissions;
+    /**
+     * 发动机功率
+     */
+    private String power;
+    /**
+     * 车辆长度
+     */
+    private String length;
+    /**
+     * 车辆宽度
+     */
+    private String width;
+    /**
+     * 车辆高度
+     */
+    private String height;
+    /**
+     * 车辆重量
+     */
+    private String weight;
+    /**
+     * 油箱容积
+     */
+    private String fuelCapacity;
+    /**
+     * 座位数量
+     */
+    private Integer seatNumber;
+    /**
+     * 气缸数量
+     */
+    private Integer cylinderNumber;
+    /**
+     * 出厂日期
+     */
+    private Date manufactureDate;
+    /**
+     * 装备日期
+     */
+    private Date allocateDate;
+    /**
+     * 备注
+     */
+    private String remark;
+    /**
+     * 照片,多张图片通过英文都好隔开
+     */
+    private String photo;
+    /**
+     * 文档,多张图片通过英文都好隔开
+     */
+    private String document;
+    /**
+     * 在线状态,0离线,1:在线
+     */
+    private Integer onlineStatus;
+    /**
+     * 车辆状态:0可使用、1使用中、2维修中、3已停用
+     */
+    private Integer status;
+    /**
+     * sim卡号
+     */
+    private String simNumber;
+    /**
+     * 类型,0作战车辆、1私家车
+     */
+    private Integer type;
+    /**
+     * 联系电话
+     */
+    private String phone;
+    /**
+     * 车主姓名
+     */
+    private String owner;
+    /**
+     * 第三方车辆ID
+     */
+    private Long thirdVehicleId;
+    /**
+     * 液位展示JSON串
+     */
+    private String liquidConfig;
+    /**
+     * 百公里油耗(L)
+     */
+    private String fuelConsumption;
+    /**
+     * 重庆车辆ID
+     */
+    private String cqVehicleId;
+    /**
+     * 车辆类型名称
+     */
+    private String cryName;
+    /**
+     * 机构名称
+     */
+    private String depName;
+    /**
+     * 机构电话
+     */
+    private String tel;
+    /**
+     * 机构责任人
+     */
+    private String managerName;
+    /**
+     * 机构责任人电话
+     */
+    private String managerPhone;
+    /**
+     * 定位数据
+     */
+    private String location;
+    /**
+     * 价格
+     */
+    private BigDecimal bidPrice;
+    /**
+     * 是否物联,0否,1是
+     */
+    private Integer iot;
+    /**
+     * 所属机构经度
+     */
+    private String ssjgjd;
+    /**
+     * 所属机构维度
+     */
+    private String ssjgwd;
+    /**
+     * 所属机构地址
+     */
+    private String ssjgdz;
+    /**
+     * 所属机构经度
+     */
+    private Long electricFenceId;
+    /**
+     * 电子围栏ID
+     */
+    private String cqState;
+    /**
+     * 离线时间
+     */
+    private Date offlineTime;
+    /**
+     * 车速限制(KM/H)
+     */
+    private String speedLimit;
+}

+ 15 - 0
ljclw-core/src/main/java/com/ruizheng/clw/mapper/CarInfoMapper.java

@@ -0,0 +1,15 @@
+package com.ruizheng.clw.mapper;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruizheng.clw.domain.CarInfo;
+import com.ruoyi.common.annotation.DataSource;
+import com.ruoyi.common.enums.DataSourceType;
+import org.springframework.stereotype.Repository;
+
+
+@Repository
+public interface CarInfoMapper extends BaseMapper<CarInfo> {
+
+
+}

+ 8 - 0
ljclw-core/src/main/java/com/ruizheng/clw/service/CarInfoService.java

@@ -0,0 +1,8 @@
+package com.ruizheng.clw.service;
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruizheng.clw.domain.CarInfo;
+
+public interface CarInfoService extends IService<CarInfo> {
+}

+ 12 - 0
ljclw-core/src/main/java/com/ruizheng/clw/service/imple/CarInfoServiceImpl.java

@@ -0,0 +1,12 @@
+package com.ruizheng.clw.service.imple;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruizheng.clw.domain.CarInfo;
+import com.ruizheng.clw.mapper.CarInfoMapper;
+import com.ruizheng.clw.service.CarInfoService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CarInfoServiceImpl extends ServiceImpl<CarInfoMapper, CarInfo> implements CarInfoService {
+
+}

+ 6 - 0
ruoyi-admin/pom.xml

@@ -24,6 +24,12 @@
             <optional>true</optional> <!-- 表示依赖不会传递 -->
         </dependency>
 
+        <dependency>
+            <groupId>org.postgresql</groupId>
+            <artifactId>postgresql</artifactId>
+            <version>42.6.0</version>
+        </dependency>
+
         <!-- swagger3-->
         <dependency>
             <groupId>io.springfox</groupId>

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysLogininforController.java

@@ -16,9 +16,9 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.framework.web.service.SysPasswordService;
 import com.ruoyi.system.domain.SysLogininfor;
 import com.ruoyi.system.service.ISysLogininforService;
+import com.ruoyi.framework.web.service.SysPasswordService;
 
 /**
  * 系统访问记录

+ 8 - 9
ruoyi-admin/src/main/resources/application-druid.yml

@@ -2,20 +2,19 @@
 spring:
     datasource:
         type: com.alibaba.druid.pool.DruidDataSource
-        driverClassName: com.mysql.cj.jdbc.Driver
         druid:
             # 主库数据源
             master:
                 url: jdbc:mysql://localhost:3306/ljclw-db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                 username: root
                 password: root1234
-            # 从库数据源
+                driverClassName: com.mysql.cj.jdbc.Driver
             slave:
-                # 从数据源开关/默认关闭
-                enabled: false
-                url: 
-                username: 
-                password: 
+                enabled: true
+                url: jdbc:postgresql://23.123.252.238:5432/assets?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai
+                username: gpadmin
+                password: dbadmin
+                driverClassName: org.postgresql.Driver
             # 初始连接数
             initialSize: 5
             # 最小连接池数量
@@ -35,11 +34,11 @@ spring:
             # 配置一个连接在池中最大生存的时间,单位是毫秒
             maxEvictableIdleTimeMillis: 900000
             # 配置检测连接是否有效
-            validationQuery: SELECT 1 FROM DUAL
+            validationQuery: SELECT 1
             testWhileIdle: true
             testOnBorrow: false
             testOnReturn: false
-            webStatFilter: 
+            webStatFilter:
                 enabled: true
             statViewServlet:
                 enabled: true

+ 4 - 3
ruoyi-admin/src/main/resources/application.yml

@@ -109,10 +109,11 @@ mybatis-plus:
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 
 # PageHelper分页插件
-pagehelper: 
-  helperDialect: mysql
+pagehelper:
+#  helperDialect: mysql
   supportMethodsArguments: true
-  params: count=countSql 
+  params: count=countSql
+  auto-runtime-dialect: true
 
 # Swagger配置
 swagger: