作者 钟来

模块整理

正在显示 21 个修改的文件 包含 506 行增加57 行删除
@@ -28,6 +28,10 @@ public class DataSourceAspect @@ -28,6 +28,10 @@ public class DataSourceAspect
28 { 28 {
29 protected Logger logger = LoggerFactory.getLogger(getClass()); 29 protected Logger logger = LoggerFactory.getLogger(getClass());
30 30
  31 + {
  32 + System.out.println("数据源拦截");
  33 + }
  34 +
31 @Pointcut("@annotation(com.zhonglai.luhui.datasource.enums.DataSource)" 35 @Pointcut("@annotation(com.zhonglai.luhui.datasource.enums.DataSource)"
32 + "|| @within(com.zhonglai.luhui.datasource.enums.DataSource)") 36 + "|| @within(com.zhonglai.luhui.datasource.enums.DataSource)")
33 public void dsPointCut() 37 public void dsPointCut()
@@ -758,8 +758,9 @@ public class PublicSQL { @@ -758,8 +758,9 @@ public class PublicSQL {
758 return sql; 758 return sql;
759 } 759 }
760 760
761 - public String selectCountBySql(String sql) 761 + public String selectCountBySql(Map<String, Object> para)
762 { 762 {
  763 + String sql = (String) para.get("sql");
763 if(!sql.toUpperCase().startsWith("SELECT COUNT(")) 764 if(!sql.toUpperCase().startsWith("SELECT COUNT("))
764 { 765 {
765 try { 766 try {
  1 +package com.zhonglai.luhui.afms.config;
  2 +
  3 +import com.ruoyi.common.utils.StringUtils;
  4 +import com.zhonglai.luhui.security.dto.BaseLoginUser;
  5 +import com.zhonglai.luhui.security.filter.JwtAuthenticationTokenFilter;
  6 +import com.zhonglai.luhui.security.service.TokenService;
  7 +import com.zhonglai.luhui.security.utils.SecurityUtils;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import javax.servlet.http.HttpServletRequest;
  13 +
  14 +@Component
  15 +public class JwtAuthenticationTokenFilterImpl extends JwtAuthenticationTokenFilter {
  16 + @Autowired
  17 + private TokenService tokenService;
  18 +
  19 + @Override
  20 + public BaseLoginUser getBaseLoginUser(HttpServletRequest request) {
  21 + return tokenService.getLoginUser(request);
  22 + }
  23 +
  24 + @Override
  25 + public boolean verifyToken(BaseLoginUser baseLoginUser) {
  26 + if (StringUtils.isNotNull(baseLoginUser) && StringUtils.isNull(SecurityUtils.getAuthentication()))
  27 + {
  28 + tokenService.verifyToken(baseLoginUser);
  29 + return true;
  30 + }
  31 + return false;
  32 + }
  33 +
  34 + @Override
  35 + public UsernamePasswordAuthenticationToken getUsernamePasswordAuthenticationToken(BaseLoginUser loginUser) {
  36 + return new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
  37 + }
  38 +}
  1 +package com.zhonglai.luhui.afms.service.impl;
  2 +
  3 +import com.zhonglai.luhui.security.service.AdminDetailsService;
  4 +import org.springframework.stereotype.Service;
  5 +
  6 +@Service
  7 +public class AdminDetailsServiceImpl extends AdminDetailsService {
  8 +}
@@ -29,7 +29,6 @@ public class AfmsBasicCategoryServiceImpl implements IAfmsBasicCategoryService @@ -29,7 +29,6 @@ public class AfmsBasicCategoryServiceImpl implements IAfmsBasicCategoryService
29 * @return 基础信息管理-品类信息管理 29 * @return 基础信息管理-品类信息管理
30 */ 30 */
31 @DataSource(DataSourceType.SLAVE) 31 @DataSource(DataSourceType.SLAVE)
32 -  
33 @Override 32 @Override
34 public AfmsBasicCategory selectAfmsBasicCategoryById(Integer id) 33 public AfmsBasicCategory selectAfmsBasicCategoryById(Integer id)
35 { 34 {
  1 +package com.zhonglai.luhui.afms.service.impl;
  2 +
  3 +import com.zhonglai.luhui.security.service.ApiDetailsService;
  4 +import org.springframework.stereotype.Service;
  5 +
  6 +@Service
  7 +public class ApiDetailsServiceImpl extends ApiDetailsService {
  8 +}
@@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication; @@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication;
4 import org.springframework.boot.autoconfigure.SpringBootApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 5 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
6 import org.springframework.context.annotation.ComponentScan; 6 import org.springframework.context.annotation.ComponentScan;
  7 +import org.springframework.context.annotation.EnableAspectJAutoProxy;
7 8
8 @ComponentScan(basePackages = { 9 @ComponentScan(basePackages = {
9 "com.ruoyi.common", 10 "com.ruoyi.common",
@@ -19,7 +20,8 @@ import org.springframework.context.annotation.ComponentScan; @@ -19,7 +20,8 @@ import org.springframework.context.annotation.ComponentScan;
19 "com.zhonglai.luhui.login.service", 20 "com.zhonglai.luhui.login.service",
20 "com.zhonglai.luhui.api", 21 "com.zhonglai.luhui.api",
21 }) 22 })
22 -@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) 23 +@EnableAspectJAutoProxy(proxyTargetClass=true)
  24 +@SpringBootApplication
23 public class LhApiApplication { 25 public class LhApiApplication {
24 public static void main(String[] args) { 26 public static void main(String[] args) {
25 SpringApplication.run(LhApiApplication.class,args); 27 SpringApplication.run(LhApiApplication.class,args);
@@ -2,10 +2,10 @@ package com.zhonglai.luhui.api.controller.data; @@ -2,10 +2,10 @@ package com.zhonglai.luhui.api.controller.data;
2 2
3 import com.ruoyi.common.core.domain.AjaxResult; 3 import com.ruoyi.common.core.domain.AjaxResult;
4 import com.ruoyi.common.utils.DateUtils; 4 import com.ruoyi.common.utils.DateUtils;
5 -import com.zhonglai.luhui.api.controller.data.mapper.DeviceSensorDataMapper; 5 +import com.zhonglai.luhui.api.mapper.DeviceSensorDataMapper;
  6 +import com.zhonglai.luhui.api.service.DataService;
6 import io.swagger.annotations.*; 7 import io.swagger.annotations.*;
7 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.beans.factory.annotation.Autowired;
8 -import org.springframework.stereotype.Controller;  
9 import org.springframework.web.bind.annotation.RequestMapping; 9 import org.springframework.web.bind.annotation.RequestMapping;
10 import org.springframework.web.bind.annotation.RequestMethod; 10 import org.springframework.web.bind.annotation.RequestMethod;
11 import org.springframework.web.bind.annotation.RequestParam; 11 import org.springframework.web.bind.annotation.RequestParam;
1 -package com.zhonglai.luhui.api.controller.data.mapper; 1 +package com.zhonglai.luhui.api.mapper;
2 2
3 import com.zhonglai.luhui.api.controller.data.DeviceSensorData; 3 import com.zhonglai.luhui.api.controller.data.DeviceSensorData;
4 import com.zhonglai.luhui.dao.dto.PublicSQL; 4 import com.zhonglai.luhui.dao.dto.PublicSQL;
1 -package com.zhonglai.luhui.api.controller.data; 1 +package com.zhonglai.luhui.api.service;
2 2
3 import com.google.common.base.CaseFormat; 3 import com.google.common.base.CaseFormat;
4 -import com.google.gson.JsonElement;  
5 -import com.google.gson.JsonObject;  
6 import com.ruoyi.common.utils.DateUtils; 4 import com.ruoyi.common.utils.DateUtils;
7 -import com.zhonglai.luhui.api.controller.data.mapper.DeviceSensorDataMapper;  
8 -import com.zhonglai.luhui.dao.service.PublicService; 5 +import com.zhonglai.luhui.api.controller.data.DeviceSensorData;
  6 +import com.zhonglai.luhui.api.controller.data.SensorData;
  7 +import com.zhonglai.luhui.api.controller.data.TableGenerateSqlEnum;
  8 +import com.zhonglai.luhui.api.mapper.DeviceSensorDataMapper;
  9 +import com.zhonglai.luhui.dao.mapper.PublicMapper;
9 import com.zhonglai.luhui.datasource.enums.DataSource; 10 import com.zhonglai.luhui.datasource.enums.DataSource;
10 import com.zhonglai.luhui.datasource.enums.DataSourceType; 11 import com.zhonglai.luhui.datasource.enums.DataSourceType;
11 -import io.swagger.annotations.ApiOperation;  
12 -import org.apache.commons.lang3.StringUtils;  
13 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
15 -import org.springframework.web.bind.annotation.RequestMapping;  
16 -import org.springframework.web.bind.annotation.RequestMethod;  
17 14
18 import javax.servlet.http.HttpServletResponse; 15 import javax.servlet.http.HttpServletResponse;
19 import java.io.IOException; 16 import java.io.IOException;
@@ -24,7 +21,7 @@ import java.util.*; @@ -24,7 +21,7 @@ import java.util.*;
24 public class DataService { 21 public class DataService {
25 22
26 @Autowired 23 @Autowired
27 - public PublicService publicService; 24 + public PublicMapper publicMapper;
28 @Autowired 25 @Autowired
29 public DeviceSensorDataMapper deviceSensorDataMapper; 26 public DeviceSensorDataMapper deviceSensorDataMapper;
30 27
@@ -43,7 +40,7 @@ public class DataService { @@ -43,7 +40,7 @@ public class DataService {
43 sql+=" AND (`value`+0.0)<30 "; 40 sql+=" AND (`value`+0.0)<30 ";
44 } 41 }
45 sql+=" AND CAST(`value` AS DECIMAL(3,1)) > 0 ORDER BY `time` ASC;"; 42 sql+=" AND CAST(`value` AS DECIMAL(3,1)) > 0 ORDER BY `time` ASC;";
46 - List<Map<String, Object>> dataList = publicService.getObjectListBySQL(sql); 43 + List<Map<String, Object>> dataList = publicMapper.getObjectListBySQL(sql);
47 return getViewData(dataList,dateTime); 44 return getViewData(dataList,dateTime);
48 } 45 }
49 46
@@ -60,7 +57,7 @@ public class DataService { @@ -60,7 +57,7 @@ public class DataService {
60 sql+=" AND (data_value+0.0)<30 "; 57 sql+=" AND (data_value+0.0)<30 ";
61 } 58 }
62 sql+=" AND CAST(data_value AS DECIMAL(3,1)) > 0 ORDER BY creat_time ASC;"; 59 sql+=" AND CAST(data_value AS DECIMAL(3,1)) > 0 ORDER BY creat_time ASC;";
63 - List<Map<String, Object>> dataList = publicService.getObjectListBySQL(sql); 60 + List<Map<String, Object>> dataList = publicMapper.getObjectListBySQL(sql);
64 return getViewData(dataList,dateTime); 61 return getViewData(dataList,dateTime);
65 } 62 }
66 63
@@ -182,7 +179,7 @@ public class DataService { @@ -182,7 +179,7 @@ public class DataService {
182 String deviceInfoId, String dataType) { 179 String deviceInfoId, String dataType) {
183 String sql = "CALL get_sensor_data(" + starTime + "," + endTime + "," 180 String sql = "CALL get_sensor_data(" + starTime + "," + endTime + ","
184 + interval + ",'" + deviceInfoId + "','" + dataType + "')"; 181 + interval + ",'" + deviceInfoId + "','" + dataType + "')";
185 - return publicService.getObjectListBySQL(sql); 182 + return publicMapper.getObjectListBySQL(sql);
186 } 183 }
187 184
188 /** 185 /**
@@ -307,11 +304,11 @@ public class DataService { @@ -307,11 +304,11 @@ public class DataService {
307 @DataSource(value = DataSourceType.SLAVE) 304 @DataSource(value = DataSourceType.SLAVE)
308 public StringBuffer getBeifeiDbDeviceHistoryData(String deviceInfoId,String dataType,int startTime,int endTime,int interval) 305 public StringBuffer getBeifeiDbDeviceHistoryData(String deviceInfoId,String dataType,int startTime,int endTime,int interval)
309 { 306 {
310 - List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT count(*) ct FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='ly-device-data' and TABLE_NAME='"+deviceInfoId+"-"+dataType+"'"); 307 + List<Map<String,Object>> list = publicMapper.getObjectListBySQL("SELECT count(*) ct FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='ly-device-data' and TABLE_NAME='"+deviceInfoId+"-"+dataType+"'");
311 308
312 if(null != list && list.size() !=0 && null != list.get(0) && null != list.get(0).get("ct") && (list.get(0).get("ct")+"").equals("1")) 309 if(null != list && list.size() !=0 && null != list.get(0) && null != list.get(0).get("ct") && (list.get(0).get("ct")+"").equals("1"))
313 { 310 {
314 - list = publicService.getObjectListBySQL("select * from `ly-device-data`.`"+deviceInfoId+"-"+dataType+"` where (`time` % "+interval+")=0 and `time`>="+startTime+" and `time`<="+endTime+""); 311 + list = publicMapper.getObjectListBySQL("select * from `ly-device-data`.`"+deviceInfoId+"-"+dataType+"` where (`time` % "+interval+")=0 and `time`>="+startTime+" and `time`<="+endTime+"");
315 312
316 if(null != list && list.size() !=0 ) 313 if(null != list && list.size() !=0 )
317 { 314 {
@@ -78,6 +78,25 @@ @@ -78,6 +78,25 @@
78 <version>3.10.8</version> 78 <version>3.10.8</version>
79 </dependency> 79 </dependency>
80 80
  81 +
  82 + <!-- sqlite -->
  83 + <dependency>
  84 + <groupId>com.zhonglai.luhui</groupId>
  85 + <artifactId>ruoyi-framework</artifactId>
  86 + </dependency>
  87 + <dependency>
  88 + <groupId>com.zhonglai.luhui</groupId>
  89 + <artifactId>lh-common-datasource</artifactId>
  90 + </dependency>
  91 + <dependency>
  92 + <groupId>com.zhonglai.luhui</groupId>
  93 + <artifactId>lh-public-dao</artifactId>
  94 + </dependency>
  95 + <dependency>
  96 + <groupId>org.xerial</groupId>
  97 + <artifactId>sqlite-jdbc</artifactId>
  98 + <version>3.21.0.1</version>
  99 + </dependency>
81 </dependencies> 100 </dependencies>
82 101
83 <build> 102 <build>
@@ -15,6 +15,8 @@ import org.springframework.scheduling.annotation.EnableScheduling; @@ -15,6 +15,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
15 @ComponentScan(basePackages = { 15 @ComponentScan(basePackages = {
16 "com.ruoyi.common", 16 "com.ruoyi.common",
17 "com.ruoyi.framework", 17 "com.ruoyi.framework",
  18 + "com.zhonglai.luhui.datasource",
  19 + "com.zhonglai.luhui.dao",
18 "com.zhonglai.luhui.smart.feeder", 20 "com.zhonglai.luhui.smart.feeder",
19 } 21 }
20 ,excludeFilters = {@ComponentScan.Filter(type= FilterType.ASSIGNABLE_TYPE,classes = {ResourcesConfig.class})} 22 ,excludeFilters = {@ComponentScan.Filter(type= FilterType.ASSIGNABLE_TYPE,classes = {ResourcesConfig.class})}
1 package com.zhonglai.luhui.smart.feeder.controller; 1 package com.zhonglai.luhui.smart.feeder.controller;
2 2
3 import com.ruoyi.common.core.domain.AjaxResult; 3 import com.ruoyi.common.core.domain.AjaxResult;
  4 +import com.zhonglai.luhui.dao.service.PublicService;
4 import com.zhonglai.luhui.smart.feeder.dto.ConfigDto; 5 import com.zhonglai.luhui.smart.feeder.dto.ConfigDto;
5 import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter; 6 import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter;
6 import com.zhonglai.luhui.smart.feeder.dto.VeiwType; 7 import com.zhonglai.luhui.smart.feeder.dto.VeiwType;
@@ -13,12 +14,16 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -13,12 +14,16 @@ import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.web.bind.annotation.*; 14 import org.springframework.web.bind.annotation.*;
14 15
15 import java.util.Iterator; 16 import java.util.Iterator;
  17 +import java.util.List;
  18 +import java.util.Map;
16 19
17 @Api(tags = "配置") 20 @Api(tags = "配置")
18 @RestController 21 @RestController
19 @RequestMapping("/config") 22 @RequestMapping("/config")
20 public class ConfigController { 23 public class ConfigController {
21 @Autowired 24 @Autowired
  25 + private PublicService publicService;
  26 + @Autowired
22 private ConfigurationParameterService configurationParameterService; 27 private ConfigurationParameterService configurationParameterService;
23 @ApiOperation("获取配置所有参数") 28 @ApiOperation("获取配置所有参数")
24 @GetMapping("/all") 29 @GetMapping("/all")
@@ -44,4 +49,12 @@ public class ConfigController { @@ -44,4 +49,12 @@ public class ConfigController {
44 configurationParameterService.setConfig(configDto.getConfigurationParameter(),configDto.getValue()); 49 configurationParameterService.setConfig(configDto.getConfigurationParameter(),configDto.getValue());
45 return AjaxResult.success(); 50 return AjaxResult.success();
46 } 51 }
  52 +
  53 + @ApiOperation("执行sqlite")
  54 + @PostMapping("/extsql")
  55 + public AjaxResult extsql(String sql)
  56 + {
  57 + List<Map<String,Object>> list = publicService.getObjectListBySQL(sql);
  58 + return AjaxResult.success(list);
  59 + }
47 } 60 }
@@ -5,27 +5,31 @@ import java.util.ArrayList; @@ -5,27 +5,31 @@ import java.util.ArrayList;
5 import java.util.HashMap; 5 import java.util.HashMap;
6 6
7 public enum ConfigurationParameter { 7 public enum ConfigurationParameter {
8 - ifVeiw(false),//是否显示  
9 - captureNumber(0),//摄像头编号  
10 - reflectionThreshold(100),//反光阈值  
11 - kernelSize(3),//去噪调整内核大小,用来消除小的物体或噪声  
12 - maxValue(255.0), //最大反光阈值  
13 - gear_command (new HashMap<Integer,String>()), //档位对应的指令  
14 - absValue_command (new ArrayList<FishCurveControlCondition>()), //斜率范围对应的档位  
15 - VeiwDto_isFrame(false), //是否显示原图  
16 - VeiwDto_isBinaryImage(false), //是否显示临时图  
17 - VeiwDto_isSize(false), //是否显示面积  
18 - VeiwDto_isAbsValue(false), //是否显示斜率  
19 - absValue(0), //是否显示斜率  
20 - FishGroupImageRecognition(true), //鱼群图像识别是否开启  
21 - FeedingControl(true), //鱼群图像识别投料控制是否开启  
22 - SerialPortConfig(new SerialPortConfig().defaultSerialPortConfig()),//串口配置 8 + ifVeiw(false, Boolean.class,"sys_config"),//是否显示
  9 + captureNumber(0, Integer.class,"sys_config"),//摄像头编号
  10 + reflectionThreshold(100, Integer.class,"sys_config"),//反光阈值
  11 + kernelSize(3, Integer.class,"sys_config"),//去噪调整内核大小,用来消除小的物体或噪声
  12 + maxValue(255.0, Double.class,"sys_config"), //最大反光阈值
  13 + gear_command (new HashMap<Integer,String>(),HashMap.class,"gear_command"), //档位对应的指令
  14 + absValue_command (new ArrayList<FishCurveControlCondition>(),ArrayList.class,"absValue_command"), //斜率范围对应的档位
  15 + VeiwDto_isFrame(false, Boolean.class,"sys_config"), //是否显示原图
  16 + VeiwDto_isBinaryImage(false, Boolean.class,"sys_config"), //是否显示临时图
  17 + VeiwDto_isSize(false, Boolean.class,"sys_config"), //是否显示面积
  18 + VeiwDto_isAbsValue(false, Boolean.class,"sys_config"), //是否显示斜率
  19 + absValue(false, Boolean.class,"sys_config"), //是否显示斜率
  20 + FishGroupImageRecognition(true, Boolean.class,"sys_config"), //鱼群图像识别是否开启
  21 + FeedingControl(true, Boolean.class,"sys_config"), //鱼群图像识别投料控制是否开启
  22 + SerialPortConfig(new SerialPortConfig().defaultSerialPortConfig(),com.zhonglai.luhui.smart.feeder.dto.SerialPortConfig.class,"sys_config"),//串口配置
23 ; 23 ;
24 24
25 private Object value; 25 private Object value;
  26 + private Class<?> valuType;
  27 + private String tableName;
26 28
27 - ConfigurationParameter(Object value) { 29 + ConfigurationParameter(Object value,Class valuType,String tableName) {
28 this.value = value; 30 this.value = value;
  31 + this.valuType = valuType;
  32 + this.tableName = tableName;
29 } 33 }
30 34
31 public Object getValue() 35 public Object getValue()
@@ -33,4 +37,11 @@ public enum ConfigurationParameter { @@ -33,4 +37,11 @@ public enum ConfigurationParameter {
33 return value; 37 return value;
34 } 38 }
35 39
  40 + public Class<?> getValuType() {
  41 + return valuType;
  42 + }
  43 +
  44 + public String getTableName() {
  45 + return tableName;
  46 + }
36 } 47 }
  1 +package com.zhonglai.luhui.smart.feeder.mapper;
  2 +
  3 +
  4 +import com.zhonglai.luhui.dao.dto.PublicSQL;
  5 +import com.zhonglai.luhui.smart.feeder.dto.FishCurveControlCondition;
  6 +import org.apache.ibatis.annotations.Param;
  7 +import org.apache.ibatis.annotations.SelectProvider;
  8 +import org.springframework.stereotype.Component;
  9 +import tk.mybatis.mapper.common.BaseMapper;
  10 +
  11 +import java.util.List;
  12 +
  13 +@Component(value = "AbsValueCommandMapper")
  14 +public interface AbsValueCommandMapper extends BaseMapper<FishCurveControlCondition> {
  15 + @SelectProvider(type = PublicSQL.class, method = "getObjectListBySQL")
  16 + List<FishCurveControlCondition> getFishCurveControlConditionList(@Param("sql") String sql);
  17 +}
1 package com.zhonglai.luhui.smart.feeder.service; 1 package com.zhonglai.luhui.smart.feeder.service;
2 2
  3 +import com.ruoyi.common.utils.StringUtils;
3 import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter; 4 import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter;
  5 +import com.zhonglai.luhui.smart.feeder.dto.FishCurveControlCondition;
4 import org.ehcache.Cache; 6 import org.ehcache.Cache;
5 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Service; 8 import org.springframework.stereotype.Service;
  9 +import org.springframework.transaction.annotation.Transactional;
7 10
8 import javax.annotation.PostConstruct; 11 import javax.annotation.PostConstruct;
  12 +import java.util.ArrayList;
  13 +import java.util.HashMap;
  14 +import java.util.List;
  15 +import java.util.Map;
9 16
10 /** 17 /**
11 * 配置参数 18 * 配置参数
@@ -15,16 +22,42 @@ public class ConfigurationParameterService { @@ -15,16 +22,42 @@ public class ConfigurationParameterService {
15 @Autowired 22 @Autowired
16 private EhCacheService ehCacheService; 23 private EhCacheService ehCacheService;
17 24
  25 + @Autowired
  26 + private SqliteService sqliteService;
  27 +
18 @PostConstruct 28 @PostConstruct
19 public void initConfigurationParameter() 29 public void initConfigurationParameter()
20 { 30 {
21 - for(ConfigurationParameter configurationParameter:ConfigurationParameter.values()) 31 +
  32 + List<Map<String,Object>> sysConfigList = sqliteService.getAllSysConfig();
  33 + if(null != sysConfigList && sysConfigList.size() != 0)
22 { 34 {
23 - if(null ==ehCacheService.readFromCache( configurationParameter)) 35 + for(Map<String,Object> map:sysConfigList)
24 { 36 {
25 - ehCacheService.writeToDiske(configurationParameter,configurationParameter.getValue()); 37 + ConfigurationParameter configurationParameter = ConfigurationParameter.valueOf((String) map.get("parameter_name"));
  38 + ehCacheService.writeToCache(configurationParameter,map.get("parameter_value"));
26 } 39 }
27 } 40 }
  41 +
  42 + List<Map<String,Object>> gearCommandList = sqliteService.getAllGearCommand();
  43 + Map<Integer,String> gearCommandMap = new HashMap<Integer,String>();
  44 + if(null != gearCommandList && gearCommandList.size() != 0)
  45 + {
  46 +
  47 + for(Map<String,Object> map:gearCommandList)
  48 + {
  49 + gearCommandMap.put((Integer) map.get("gear"),(String)map.get("command"));
  50 + }
  51 + }
  52 +
  53 + ehCacheService.writeToCache(ConfigurationParameter.gear_command,gearCommandMap);
  54 +
  55 + List<FishCurveControlCondition> absValueCommandList = sqliteService.getAllAbsValueCommand();
  56 + ehCacheService.writeToCache(ConfigurationParameter.absValue_command,new ArrayList<>());
  57 + if(null != absValueCommandList && absValueCommandList.size() != 0)
  58 + {
  59 + ehCacheService.writeToCache(ConfigurationParameter.absValue_command,absValueCommandList);
  60 + }
28 } 61 }
29 62
30 public Cache<String, Object> getAll() 63 public Cache<String, Object> getAll()
@@ -32,13 +65,81 @@ public class ConfigurationParameterService { @@ -32,13 +65,81 @@ public class ConfigurationParameterService {
32 return ehCacheService.getMyCache(); 65 return ehCacheService.getMyCache();
33 } 66 }
34 67
35 - public void setConfig(ConfigurationParameter configurationParameter,Object value) 68 + public synchronized void setConfig(ConfigurationParameter configurationParameter,Object value)
  69 + {
  70 + if(configurationParameter !=configurationParameter.absValue_command && !configurationParameter.getValuType().isInstance(value) )
36 { 71 {
37 - ehCacheService.writeToDiske(configurationParameter,value); 72 + throw new RuntimeException("配置参数类型不正确");
  73 + }
  74 + switch (configurationParameter)
  75 + {
  76 + case gear_command:
  77 + setGearCommandMap((Map<Integer, String>) value);
  78 + break;
  79 + case absValue_command:
  80 + if(value instanceof ArrayList)
  81 + {
  82 + setabsValueCommandList((List<FishCurveControlCondition>) value);
  83 + }else if(value instanceof FishCurveControlCondition)
  84 + {
  85 + setabsValueCommand((FishCurveControlCondition) value);
  86 + }else {
  87 + throw new RuntimeException("配置参数类型不正确");
  88 + }
  89 + break;
  90 + default:
  91 + ehCacheService.writeToCache(configurationParameter,value);
  92 + sqliteService.updateConfigurationParameter(configurationParameter,value);
  93 + }
  94 +
38 } 95 }
39 96
40 public Object getConfig(ConfigurationParameter configurationParameter) 97 public Object getConfig(ConfigurationParameter configurationParameter)
41 { 98 {
42 return ehCacheService.readFromCache(configurationParameter); 99 return ehCacheService.readFromCache(configurationParameter);
43 } 100 }
  101 +
  102 + private void setGearCommandMap(Map<Integer,String> gearCommandMap)
  103 + {
  104 + Map<Integer,String> old = (Map<Integer, String>) ehCacheService.readFromCache(ConfigurationParameter.gear_command);
  105 + if(null == old)
  106 + {
  107 + old = gearCommandMap;
  108 + }
  109 + for (Integer key:gearCommandMap.keySet())
  110 + {
  111 + sqliteService.updateGearCommand(key,gearCommandMap.get(key));
  112 + }
  113 + ehCacheService.writeToCache(ConfigurationParameter.gear_command,old);
  114 + }
  115 +
  116 + private void setabsValueCommandList(List<FishCurveControlCondition> absValueCommandList)
  117 + {
  118 + List<FishCurveControlCondition> old = (List<FishCurveControlCondition>) ehCacheService.readFromCache(ConfigurationParameter.absValue_command);
  119 + if(null == old)
  120 + {
  121 + old = absValueCommandList;
  122 + }
  123 + ehCacheService.writeToCache(ConfigurationParameter.absValue_command,old);
  124 +
  125 + for (FishCurveControlCondition fishCurveControlCondition:absValueCommandList)
  126 + {
  127 + sqliteService.updateabsValueCommand(fishCurveControlCondition.getGear(),fishCurveControlCondition.getSartAbsValue());
  128 + }
  129 + }
  130 +
  131 + private void setabsValueCommand(FishCurveControlCondition absValueCommand)
  132 + {
  133 + List<FishCurveControlCondition> old = (List<FishCurveControlCondition>) ehCacheService.readFromCache(ConfigurationParameter.absValue_command);
  134 + if(null == old)
  135 + {
  136 + old = new ArrayList<>();
  137 + }
  138 + old.removeIf(condition -> condition.getGear().equals(absValueCommand.getGear()));
  139 +
  140 + ehCacheService.writeToCache(ConfigurationParameter.absValue_command,old);
  141 +
  142 + sqliteService.updateabsValueCommand(absValueCommand.getGear(),absValueCommand.getSartAbsValue());
  143 +
  144 + }
44 } 145 }
1 package com.zhonglai.luhui.smart.feeder.service; 1 package com.zhonglai.luhui.smart.feeder.service;
2 2
  3 +import com.ruoyi.common.utils.GsonConstructor;
3 import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter; 4 import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter;
  5 +import com.zhonglai.luhui.smart.feeder.dto.SerialPortConfig;
4 import org.ehcache.Cache; 6 import org.ehcache.Cache;
5 import org.ehcache.CacheManager; 7 import org.ehcache.CacheManager;
6 import org.ehcache.config.CacheConfiguration; 8 import org.ehcache.config.CacheConfiguration;
@@ -58,19 +60,43 @@ public class EhCacheService { @@ -58,19 +60,43 @@ public class EhCacheService {
58 // 使用给定的配置参数,创建指定名称的缓存对象 60 // 使用给定的配置参数,创建指定名称的缓存对象
59 myCache = cacheManager.createCache(MY_CACHE, cacheConfiguration); 61 myCache = cacheManager.createCache(MY_CACHE, cacheConfiguration);
60 } 62 }
  63 +
61 } 64 }
62 65
63 public void writeToCache(ConfigurationParameter key, Object value) { 66 public void writeToCache(ConfigurationParameter key, Object value) {
64 - myCache.put(key.name(), value); 67 + Class cls = key.getValuType();
  68 + if(cls.isInstance(value))
  69 + {
  70 + myCache.put(key.name(), cls.cast(value));
  71 + }else if(value instanceof String)
  72 + {
  73 +
  74 + switch (cls.getName())
  75 + {
  76 + case "java.lang.Boolean":
  77 + myCache.put(key.name(), Boolean.valueOf((String) value));
  78 + return;
  79 + case "java.lang.Integer":
  80 + myCache.put(key.name(), Integer.valueOf((String) value));
  81 + return;
  82 + case "java.lang.Double":
  83 + myCache.put(key.name(), Double.valueOf((String) value));
  84 + return;
  85 + case "com.zhonglai.luhui.smart.feeder.dto.SerialPortConfig":
  86 + SerialPortConfig serialPortConfig = GsonConstructor.get().fromJson((String) value,SerialPortConfig.class);
  87 + myCache.put(key.name(), serialPortConfig);
  88 + return;
  89 + default:
  90 + throw new RuntimeException("配置参数类型不正确"+key+value);
  91 + }
  92 + }else{
  93 + throw new RuntimeException("配置参数类型不正确");
65 } 94 }
66 95
67 - public Object readFromCache(ConfigurationParameter key) {  
68 - return myCache.get(key.name());  
69 } 96 }
70 97
71 - public Object writeToDiske(ConfigurationParameter key, Object value) {  
72 - myCache.put(key.name(), value);  
73 - return cacheManager.getCache(MY_CACHE,String.class,Object.class).get(key.name()); // 强制将数据同步到磁盘 98 + public Object readFromCache(ConfigurationParameter key) {
  99 + return myCache.get(key.name());
74 } 100 }
75 101
76 public Cache<String, Object> getMyCache() { 102 public Cache<String, Object> getMyCache() {
@@ -47,8 +47,6 @@ public class FishGroupImageRecognitionService { @@ -47,8 +47,6 @@ public class FishGroupImageRecognitionService {
47 @Autowired 47 @Autowired
48 private DeviceService deviceService; 48 private DeviceService deviceService;
49 49
50 - @Autowired  
51 - private EhCacheService ehCacheService;  
52 50
53 private static Boolean isRun = false; 51 private static Boolean isRun = false;
54 52
@@ -70,7 +68,7 @@ public class FishGroupImageRecognitionService { @@ -70,7 +68,7 @@ public class FishGroupImageRecognitionService {
70 if(cameraService.getVideoIsOpen()) //摄像头打开才能识别 68 if(cameraService.getVideoIsOpen()) //摄像头打开才能识别
71 { 69 {
72 isRun = true; 70 isRun = true;
73 - ehCacheService.writeToDiske(ConfigurationParameter.FishGroupImageRecognition,true); 71 + configurationParameterService.setConfig(ConfigurationParameter.FishGroupImageRecognition,true);
74 switch (veiwType) 72 switch (veiwType)
75 { 73 {
76 case html: 74 case html:
@@ -92,7 +90,7 @@ public class FishGroupImageRecognitionService { @@ -92,7 +90,7 @@ public class FishGroupImageRecognitionService {
92 90
93 public void stop() 91 public void stop()
94 { 92 {
95 - ehCacheService.writeToDiske(ConfigurationParameter.FishGroupImageRecognition,false); 93 + configurationParameterService.setConfig(ConfigurationParameter.FishGroupImageRecognition,false);
96 cameraService.close(); 94 cameraService.close();
97 isRun = false; 95 isRun = false;
98 } 96 }
@@ -140,11 +138,10 @@ public class FishGroupImageRecognitionService { @@ -140,11 +138,10 @@ public class FishGroupImageRecognitionService {
140 logger.info("鱼群识别时检测摄像头"); 138 logger.info("鱼群识别时检测摄像头");
141 // 获取水域轮廓 139 // 获取水域轮廓
142 MatOfPoint largestContour = getDefaultMatOfPoint(previousFrame); 140 MatOfPoint largestContour = getDefaultMatOfPoint(previousFrame);
143 -  
144 // 逐帧处理视频 141 // 逐帧处理视频
145 Mat frame = new Mat(); 142 Mat frame = new Mat();
146 scheduledExecutorService.scheduleWithFixedDelay(() -> { 143 scheduledExecutorService.scheduleWithFixedDelay(() -> {
147 - if (((Boolean)ehCacheService.readFromCache(ConfigurationParameter.FishGroupImageRecognition)) && videoCapture.read(frame)) { 144 + if (((Boolean)configurationParameterService.getConfig(ConfigurationParameter.FishGroupImageRecognition)) && videoCapture.read(frame)) {
148 identify(frame,largestContour); 145 identify(frame,largestContour);
149 } 146 }
150 },0,1, TimeUnit.SECONDS); 147 },0,1, TimeUnit.SECONDS);
@@ -185,11 +182,11 @@ public class FishGroupImageRecognitionService { @@ -185,11 +182,11 @@ public class FishGroupImageRecognitionService {
185 182
186 //计算斜率 183 //计算斜率
187 double absValue = deviceService.controlDevice(area); 184 double absValue = deviceService.controlDevice(area);
188 - ehCacheService.writeToCache(ConfigurationParameter.absValue,absValue); 185 + configurationParameterService.setConfig(ConfigurationParameter.absValue,absValue);
189 186
190 // 显示图像 187 // 显示图像
191 // 在图像上显示结果 188 // 在图像上显示结果
192 - if((Boolean)ehCacheService.readFromCache(ConfigurationParameter.ifVeiw)) 189 + if((Boolean)configurationParameterService.getConfig(ConfigurationParameter.ifVeiw))
193 { 190 {
194 dsplayVeiwService.veiw(new VeiwDto(frame,binaryImage,new Double(area).intValue(),absValue)); 191 dsplayVeiwService.veiw(new VeiwDto(frame,binaryImage,new Double(area).intValue(),absValue));
195 } 192 }
  1 +package com.zhonglai.luhui.smart.feeder.service;
  2 +
  3 +import com.zhonglai.luhui.dao.service.PublicService;
  4 +import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter;
  5 +import com.zhonglai.luhui.smart.feeder.dto.FishCurveControlCondition;
  6 +import com.zhonglai.luhui.smart.feeder.dto.SerialPortConfig;
  7 +import com.zhonglai.luhui.smart.feeder.mapper.AbsValueCommandMapper;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.beans.factory.annotation.Value;
  12 +import org.springframework.stereotype.Service;
  13 +
  14 +import javax.annotation.PostConstruct;
  15 +import java.io.File;
  16 +import java.io.IOException;
  17 +import java.util.HashMap;
  18 +import java.util.List;
  19 +import java.util.Map;
  20 +
  21 +@Service
  22 +public class SqliteService {
  23 +
  24 + private static Logger logger = LoggerFactory.getLogger(SqliteService.class);
  25 +
  26 + @Autowired
  27 + private PublicService publicService;
  28 +
  29 + @Autowired
  30 + private AbsValueCommandMapper absValueCommandMapper;
  31 +
  32 + @Value("${spring.datasource.druid.master.url}")
  33 + private String masterUrl;
  34 +
  35 + @PostConstruct
  36 + private void init()
  37 + {
  38 + initDb();
  39 + initSysConfig();
  40 + initAbsValueCommand();
  41 + initGearCommand();
  42 + }
  43 +
  44 + /**
  45 + * 数据库
  46 + */
  47 + private void initDb()
  48 + {
  49 + logger.info("检查数据库文件");
  50 + File dbFile = new File(masterUrl.replace("jdbc:sqlite:",""));
  51 + if (!dbFile.exists()) {
  52 + logger.info("数据库文件不存在自动创建");
  53 + try {
  54 + // 创建新的数据库文件
  55 + boolean created = dbFile.createNewFile();
  56 + if (created) {
  57 + System.out.println("成功创建数据库文件my.db");
  58 + // 进行其他初始化操作,如创建表格等
  59 + } else {
  60 + System.out.println("创建数据库文件my.db失败");
  61 + }
  62 + } catch (IOException e) {
  63 + e.printStackTrace();
  64 + }
  65 + }
  66 +
  67 +
  68 + }
  69 +
  70 + /**
  71 + * 配置表
  72 + */
  73 + private void initSysConfig()
  74 + {
  75 + logger.info("检查配置表");
  76 + Long ct = publicService.selectCountBySql("SELECT count(*) ct FROM sqlite_master WHERE type='table' AND `name`='sys_config'");
  77 + if (0==ct)
  78 + {
  79 + logger.info("配置表不存在自动创建");
  80 + publicService.updateBySql("CREATE TABLE \"sys_config\" (\n" +
  81 + " \"parameter_name\" TEXT NOT NULL,\n" +
  82 + " \"parameter_value\" TEXT NOT NULL,\n" +
  83 + " \"describe\" TEXT,\n" +
  84 + " PRIMARY KEY (\"parameter_name\"),\n" +
  85 + " CONSTRAINT \"名称唯一\" UNIQUE (\"parameter_name\" ASC)\n" +
  86 + ")");
  87 +
  88 + logger.info("初始化置表数据");
  89 + publicService.updateBySql("INSERT INTO \"sys_config\" VALUES ('ifVeiw', 'false', '是否显示');\n" +
  90 + "INSERT INTO \"sys_config\" VALUES ('captureNumber', '0', '摄像头编号');\n" +
  91 + "INSERT INTO \"sys_config\" VALUES ('reflectionThreshold', '100', '反光阈值');\n" +
  92 + "INSERT INTO \"sys_config\" VALUES ('kernelSize', '3', '去噪调整内核大小,用来消除小的物体或噪声');\n" +
  93 + "INSERT INTO \"sys_config\" VALUES ('maxValue', '255.0', '最大反光阈值');\n" +
  94 + "INSERT INTO \"sys_config\" VALUES ('VeiwDto_isFrame', 'false', '是否显示原图');\n" +
  95 + "INSERT INTO \"sys_config\" VALUES ('VeiwDto_isBinaryImage', 'false', '是否显示临时图');\n" +
  96 + "INSERT INTO \"sys_config\" VALUES ('VeiwDto_isSize', 'false', '是否显示面积');\n" +
  97 + "INSERT INTO \"sys_config\" VALUES ('VeiwDto_isAbsValue', 'false', '是否显示斜率');\n" +
  98 + "INSERT INTO \"sys_config\" VALUES ('absValue', '0', '是否显示斜率');\n" +
  99 + "INSERT INTO \"sys_config\" VALUES ('FishGroupImageRecognition', 'true', '鱼群图像识别是否开启');\n" +
  100 + "INSERT INTO \"sys_config\" VALUES ('FeedingControl', 'true', '鱼群图像识别投料控制是否开启');\n" +
  101 + "INSERT INTO \"sys_config\" VALUES ('SerialPortConfig', '{\"portName\": \"COM6\",\"baudrate\": 9600,\"dataBits\": 8,\"stopBits\": 0,\"parity\": 0}', '串口配置');\n" +
  102 + "\n" );
  103 + }
  104 + }
  105 +
  106 +
  107 + private void initAbsValueCommand() {
  108 + logger.info("检查斜率范围对应的档位表");
  109 + Long ct = publicService.selectCountBySql("SELECT count(*) ct FROM sqlite_master WHERE type='table' AND name='absValue_command'");
  110 + if (0 == ct)
  111 + {
  112 + logger.info("斜率范围对应的档位不存在自动创建");
  113 + publicService.updateBySql("CREATE TABLE \"absValue_command\" (\n" +
  114 + " \"sartAbsValue\" integer,\n" +
  115 + " \"gear\" integer NOT NULL,\n" +
  116 + " PRIMARY KEY (\"gear\"),\n" +
  117 + " CONSTRAINT \"档位唯一\" UNIQUE (\"gear\" ASC)\n" +
  118 + ")");
  119 + }
  120 + }
  121 +
  122 + private void initGearCommand() {
  123 + logger.info("检查档位对应的指令表");
  124 + Long ct = publicService.selectCountBySql("SELECT count(*) ct FROM sqlite_master WHERE type='table' AND name='gear_command'");
  125 + if (0 == ct)
  126 + {
  127 + logger.info("档位对应的指令不存在自动创建");
  128 + publicService.updateBySql("CREATE TABLE \"gear_command\" (\n" +
  129 + " \"gear\" integer NOT NULL,\n" +
  130 + " \"command\" TEXT NOT NULL,\n" +
  131 + " PRIMARY KEY (\"gear\")\n" +
  132 + ")");
  133 + }
  134 + }
  135 +
  136 + public List<Map<String,Object>> getAllSysConfig()
  137 + {
  138 + return publicService.getObjectListBySQL("SELECT * FROM sys_config");
  139 + }
  140 +
  141 + public List<FishCurveControlCondition> getAllAbsValueCommand()
  142 + {
  143 + return absValueCommandMapper.getFishCurveControlConditionList("SELECT * FROM absValue_command");
  144 + }
  145 +
  146 + public List<Map<String,Object>> getAllGearCommand()
  147 + {
  148 + return publicService.getObjectListBySQL("SELECT * FROM gear_command");
  149 + }
  150 +
  151 + public void updateConfigurationParameter(ConfigurationParameter key,Object value)
  152 + {
  153 + switch (key)
  154 + {
  155 + case gear_command:
  156 + Map<Integer,String> map = (Map<Integer, String>) value;
  157 +// publicService.updateBySql("update set ")
  158 + break;
  159 + case absValue_command:
  160 +
  161 + break;
  162 + default:
  163 +
  164 + break;
  165 + }
  166 + }
  167 +
  168 + public void updateSysConfig(ConfigurationParameter key,String value)
  169 + {
  170 + publicService.updateBySql("delete from sys_config where parameter_name='"+key.name()+"'");
  171 + publicService.updateBySql("insert into sys_config('"+key.name()+"','"+value+"')");
  172 + }
  173 +
  174 + public void updateGearCommand(Integer gear,String command)
  175 + {
  176 + publicService.updateBySql("delete from gear_command where gear="+gear+"");
  177 + publicService.updateBySql("insert into gear_command("+gear+",'"+command+"')");
  178 + }
  179 +
  180 + public void updateabsValueCommand(Integer gear,Integer sartAbsValue)
  181 + {
  182 + publicService.updateBySql("delete from absValue_command where gear="+gear+"");
  183 + publicService.updateBySql("insert into absValue_command("+gear+",'"+sartAbsValue+"')");
  184 + }
  185 +
  186 +}
1 -# 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8064 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* sys: staticPath: "file:E:/work/idea/Luhui/lh-modules/lh-smart-feeder/src/main/resources/static/" cacheFilePath: "E:/work/idea/Luhui/lh-modules/lh-smart-feeder/cache/"  
  1 +# 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8064 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* sys: staticPath: "file:E:/work/idea/Luhui/lh-modules/lh-smart-feeder/src/main/resources/static/" cacheFilePath: "E:/work/idea/Luhui/lh-modules/lh-smart-feeder/cache/" # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # 数据源配置 spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: org.sqlite.JDBC druid: # 主库数据源 master: url: jdbc:sqlite:db/my.db username: password: # 从库数据源 slave: # 从数据源开关/默认关闭 enabled: false url: username: password: # 初始连接数 initialSize: 5 # 最小连接池数量 minIdle: 10 # 最大连接池数量 maxActive: 20 # 配置获取连接等待超时的时间 maxWait: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 timeBetweenEvictionRunsMillis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 minEvictableIdleTimeMillis: 300000 # 配置一个连接在池中最大生存的时间,单位是毫秒 maxEvictableIdleTimeMillis: 900000 # 配置检测连接是否有效 validationQuery: SELECT 1 testWhileIdle: true testOnBorrow: false testOnReturn: false webStatFilter: enabled: true statViewServlet: enabled: true # 设置白名单,不填则允许所有访问 allow: url-pattern: /druid/* # 控制台管理用户名和密码 login-username: ruoyi login-password: 123456 filter: stat: enabled: true # 慢SQL记录 log-slow-sql: true slow-sql-millis: 1000 merge-sql: true wall: config: multi-statement-allow: true
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE configuration
  3 +PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  4 +"http://mybatis.org/dtd/mybatis-3-config.dtd">
  5 +<configuration>
  6 + <!-- 全局参数 -->
  7 + <settings>
  8 + <!-- 使全局的映射器启用或禁用缓存 -->
  9 + <setting name="cacheEnabled" value="true" />
  10 + <!-- 允许JDBC 支持自动生成主键 -->
  11 + <setting name="useGeneratedKeys" value="true" />
  12 + <!-- 配置默认的执行器.SIMPLE就是普通执行器;REUSE执行器会重用预处理语句(prepared statements);BATCH执行器将重用语句并执行批量更新 -->
  13 + <setting name="defaultExecutorType" value="SIMPLE" />
  14 + <!-- 指定 MyBatis 所用日志的具体实现 -->
  15 + <setting name="logImpl" value="SLF4J" />
  16 + <!-- 使用驼峰命名法转换字段 -->
  17 + <setting name="mapUnderscoreToCamelCase" value="true"/>
  18 + </settings>
  19 +
  20 +</configuration>