作者 钟来

模块整理

@@ -7,6 +7,7 @@ import com.zhonglai.luhui.api.controller.data.SensorData; @@ -7,6 +7,7 @@ import com.zhonglai.luhui.api.controller.data.SensorData;
7 import com.zhonglai.luhui.api.controller.data.TableGenerateSqlEnum; 7 import com.zhonglai.luhui.api.controller.data.TableGenerateSqlEnum;
8 import com.zhonglai.luhui.api.mapper.DeviceSensorDataMapper; 8 import com.zhonglai.luhui.api.mapper.DeviceSensorDataMapper;
9 import com.zhonglai.luhui.dao.mapper.PublicMapper; 9 import com.zhonglai.luhui.dao.mapper.PublicMapper;
  10 +import com.zhonglai.luhui.datasource.config.DynamicDataSourceContextHolder;
10 import com.zhonglai.luhui.datasource.enums.DataSource; 11 import com.zhonglai.luhui.datasource.enums.DataSource;
11 import com.zhonglai.luhui.datasource.enums.DataSourceType; 12 import com.zhonglai.luhui.datasource.enums.DataSourceType;
12 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
@@ -304,6 +305,7 @@ public class DataService { @@ -304,6 +305,7 @@ public class DataService {
304 @DataSource(value = DataSourceType.SLAVE) 305 @DataSource(value = DataSourceType.SLAVE)
305 public StringBuffer getBeifeiDbDeviceHistoryData(String deviceInfoId,String dataType,int startTime,int endTime,int interval) 306 public StringBuffer getBeifeiDbDeviceHistoryData(String deviceInfoId,String dataType,int startTime,int endTime,int interval)
306 { 307 {
  308 + DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
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+"'"); 309 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+"'");
308 310
309 if(null != list && list.size() !=0 && null != list.get(0) && null != list.get(0).get("ct") && (list.get(0).get("ct")+"").equals("1")) 311 if(null != list && list.size() !=0 && null != list.get(0) && null != list.get(0).get("ct") && (list.get(0).get("ct")+"").equals("1"))
@@ -321,9 +323,13 @@ public class DataService { @@ -321,9 +323,13 @@ public class DataService {
321 sb.append(map.get("value")); 323 sb.append(map.get("value"));
322 sb.append("\r\n"); 324 sb.append("\r\n");
323 } 325 }
  326 + // 销毁数据源 在执行方法之后
  327 + DynamicDataSourceContextHolder.clearDataSourceType();
324 return sb; 328 return sb;
325 } 329 }
326 } 330 }
  331 + // 销毁数据源 在执行方法之后
  332 + DynamicDataSourceContextHolder.clearDataSourceType();
327 return null; 333 return null;
328 } 334 }
329 335
@@ -335,7 +341,6 @@ public class DataService { @@ -335,7 +341,6 @@ public class DataService {
335 * @param date 指定天数 341 * @param date 指定天数
336 * @return 342 * @return
337 */ 343 */
338 - @DataSource(value = DataSourceType.SLAVE)  
339 public StringBuffer getDeviceTimeData(String deviceInfoId, String dataType, Date date, int interval) { 344 public StringBuffer getDeviceTimeData(String deviceInfoId, String dataType, Date date, int interval) {
340 345
341 String dataTypestr = dataType; 346 String dataTypestr = dataType;