Jelajahi Sumber

报表修改

wangli 4 tahun lalu
induk
melakukan
ffdf584010

+ 212 - 0
sms_water/src/main/java/com/huaxu/common/Global.java

@@ -0,0 +1,212 @@
+/**
+ * Copyright &copy;1997-2017 <a href="http://www.hxiswater.com">huaxutech</a> All rights reserved.
+ */
+package com.huaxu.common;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.io.IOUtils;
+import org.springframework.core.io.DefaultResourceLoader;
+
+import com.google.common.collect.Maps;
+
+public class Global {
+
+	/**
+	 * 当前对象实例
+	 */
+	private static Global global = new Global();
+	
+	/**
+	 * 保存全局属性值
+	 */
+	private static Map<String, String> map = Maps.newHashMap();
+	
+	/**
+	 * 属性文件加载对象
+	 */
+	private static PropertiesLoader loader = new PropertiesLoader("application.properties");
+
+	/**
+	 * 显示/隐藏
+	 */
+	public static final String SHOW = "1";
+	public static final String HIDE = "0";
+
+	/**
+	 * 是/否
+	 */
+	public static final String YES = "1";
+	public static final String NO = "0";
+	
+	/**
+	 * 对/错
+	 */
+	public static final String TRUE = "true";
+	public static final String FALSE = "false";
+	
+	/**
+	 * 上传文件基础虚拟路径
+	 */
+	public static final String USERFILES_BASE_URL = "/userfiles/";
+	
+	/**
+	 * 获取当前对象实例
+	 */
+	public static Global getInstance() {
+		return global;
+	}
+	
+	/**
+	 * 获取配置
+	 * @see {fns:getConfig('adminPath')}
+	 */
+	public static String getConfig(String key) {
+		String value = map.get(key);
+		if (value == null){
+			value = loader.getProperty(key);
+			map.put(key, value != null ? value : StringUtils.EMPTY);
+		}
+		return value;
+	}
+	/**
+	 * 获取配置文件带中文
+	 * @param key
+	 * @return
+	 */
+	public static String getConfigName(String key) {
+		Properties pros = new Properties();
+	    String value = "";
+	    try {
+	      pros.load(new InputStreamReader(Object.class.getResourceAsStream("/jeesite.properties"), "UTF-8"));
+	      value = pros.get(key).toString();
+	    } catch (IOException e) {
+	    	//
+	    }
+	    return value;
+	}
+	
+	/**
+	 * 获取管理端根路径
+	 */
+	public static String getAdminPath() {
+		return getConfig("adminPath");
+	}
+	
+	/**
+	 * 获取前端根路径
+	 */
+	public static String getFrontPath() {
+		return getConfig("frontPath");
+	}
+	
+	/**
+	 * 获取URL后缀
+	 */
+	public static String getUrlSuffix() {
+		return getConfig("urlSuffix");
+	}
+	
+	/**
+	 * 是否是演示模式,演示模式下不能修改用户、角色、密码、菜单、授权
+	 */
+	public static Boolean isDemoMode() {
+		String dm = getConfig("demoMode");
+		return "true".equals(dm) || "1".equals(dm);
+	}
+	
+	/**
+	 * 在修改系统用户和角色时是否同步到Activiti
+	 */
+	public static Boolean isSynActivitiIndetity() {
+		String dm = getConfig("activiti.isSynActivitiIndetity");
+		return "true".equals(dm) || "1".equals(dm);
+	}
+    
+	/**
+	 * 页面获取常量
+	 * @see {fns:getConst('YES')}
+	 */
+	public static Object getConst(String field) {
+		try {
+			return Global.class.getField(field).get(null);
+		} catch (Exception e) {
+			// 异常代表无配置,这里什么也不做
+		}
+		return null;
+	}
+
+	/**
+	 * 获取上传文件的根目录
+	 * @return
+	 */
+//	public static String getUserfilesBaseDir() {
+//		String dir = getConfig("userfiles.basedir");
+//		if (StringUtils.isBlank(dir)){
+//			try {
+//				dir = ServletContextFactory.getServletContext().getRealPath("/");
+//			} catch (Exception e) {
+//				return "";
+//			}
+//		}
+//		if(!dir.endsWith("/")) {
+//			dir += "/";
+//		}
+////		System.out.println("userfiles.basedir: " + dir);
+//		return dir;
+//	}
+	
+    /**
+     * 获取工程路径
+     * @return
+     */
+    public static String getProjectPath(){
+    	// 如果配置了工程路径,则直接返回,否则自动获取。
+		String projectPath = Global.getConfig("projectPath");
+		if (StringUtils.isNotBlank(projectPath)){
+			return projectPath;
+		}
+		try {
+			File file = new DefaultResourceLoader().getResource("").getFile();
+			if (file != null){
+				while(true){
+					File f = new File(file.getPath() + File.separator + "src" + File.separator + "main");
+					if (f == null || f.exists()){
+						break;
+					}
+					if (file.getParentFile() != null){
+						file = file.getParentFile();
+					}else{
+						break;
+					}
+				}
+				projectPath = file.toString();
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return projectPath;
+    }
+    public String dd(String key){
+		InputStream inputStream = null;
+		try {
+			 inputStream =new DefaultResourceLoader().getResource("").getInputStream();
+			new Properties().load(inputStream);
+		} catch (IOException e) {
+			e.printStackTrace();
+		} finally {
+			IOUtils.closeQuietly(inputStream);
+		}
+
+		return "";
+	}
+    public static void main(String[] args) {
+    	System.out.println(Global.getConfig("spring.profiles.active"));
+	}
+	
+}

+ 154 - 0
sms_water/src/main/java/com/huaxu/common/PropertiesLoader.java

@@ -0,0 +1,154 @@
+/**
+ * Copyright (c) 2005-2011 springside.org.cn
+ * 
+ * $Id: PropertiesLoader.java 1690 2012-02-22 13:42:00Z calvinxiu $
+ */
+package com.huaxu.common;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.NoSuchElementException;
+import java.util.Properties;
+
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+
+/**
+ * Properties文件载入工具类. 可载入多个properties文件, 相同的属性在最后载入的文件中的值将会覆盖之前的值,但以System的Property优先.
+ * @author calvin
+ * @version 2013-05-15
+ */
+public class PropertiesLoader {
+
+	private static Logger logger = LoggerFactory.getLogger(PropertiesLoader.class);
+
+	private static ResourceLoader resourceLoader = new DefaultResourceLoader();
+
+	private final Properties properties;
+
+	public PropertiesLoader(String... resourcesPaths) {
+		properties = loadProperties(resourcesPaths);
+	}
+
+	public Properties getProperties() {
+		return properties;
+	}
+
+	/**
+	 * 取出Property,但以System的Property优先,取不到返回空字符串.
+	 */
+	private String getValue(String key) {
+		String systemProperty = System.getProperty(key);
+		if (systemProperty != null) {
+			return systemProperty;
+		}
+		if (properties.containsKey(key)) {
+	        return properties.getProperty(key);
+	    }
+	    return "";
+	}
+
+	/**
+	 * 取出String类型的Property,但以System的Property优先,如果都为Null则抛出异常.
+	 */
+	public String getProperty(String key) {
+		String value = getValue(key);
+		if (value == null) {
+			throw new NoSuchElementException();
+		}
+		return value;
+	}
+
+	/**
+	 * 取出String类型的Property,但以System的Property优先.如果都为Null则返回Default值.
+	 */
+	public String getProperty(String key, String defaultValue) {
+		String value = getValue(key);
+		return value != null ? value : defaultValue;
+	}
+
+	/**
+	 * 取出Integer类型的Property,但以System的Property优先.如果都为Null或内容错误则抛出异常.
+	 */
+	public Integer getInteger(String key) {
+		String value = getValue(key);
+		if (value == null) {
+			throw new NoSuchElementException();
+		}
+		return Integer.valueOf(value);
+	}
+
+	/**
+	 * 取出Integer类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容错误则抛出异常
+	 */
+	public Integer getInteger(String key, Integer defaultValue) {
+		String value = getValue(key);
+		return value != null ? Integer.valueOf(value) : defaultValue;
+	}
+
+	/**
+	 * 取出Double类型的Property,但以System的Property优先.如果都为Null或内容错误则抛出异常.
+	 */
+	public Double getDouble(String key) {
+		String value = getValue(key);
+		if (value == null) {
+			throw new NoSuchElementException();
+		}
+		return Double.valueOf(value);
+	}
+
+	/**
+	 * 取出Double类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容错误则抛出异常
+	 */
+	public Double getDouble(String key, Integer defaultValue) {
+		String value = getValue(key);
+		return value != null ? Double.valueOf(value) : defaultValue;
+	}
+
+	/**
+	 * 取出Boolean类型的Property,但以System的Property优先.如果都为Null抛出异常,如果内容不是true/false则返回false.
+	 */
+	public Boolean getBoolean(String key) {
+		String value = getValue(key);
+		if (value == null) {
+			throw new NoSuchElementException();
+		}
+		return Boolean.valueOf(value);
+	}
+
+	/**
+	 * 取出Boolean类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容不为true/false则返回false.
+	 */
+	public Boolean getBoolean(String key, boolean defaultValue) {
+		String value = getValue(key);
+		return value != null ? Boolean.valueOf(value) : defaultValue;
+	}
+
+	/**
+	 * 载入多个文件, 文件路径使用Spring Resource格式.
+	 */
+	private Properties loadProperties(String... resourcesPaths) {
+		Properties props = new Properties();
+
+		for (String location : resourcesPaths) {
+
+//			logger.debug("Loading properties file from:" + location);
+
+			InputStream is = null;
+			try {
+				Resource resource = resourceLoader.getResource(location);
+				is = resource.getInputStream();
+				props.load(is);
+			} catch (IOException ex) {
+				logger.info("Could not load properties from path:" + location + ", " + ex.getMessage());
+			} finally {
+				IOUtils.closeQuietly(is);
+			}
+		}
+		return props;
+	}
+}

+ 65 - 0
sms_water/src/main/java/com/huaxu/controller/TestDataController.java

@@ -0,0 +1,65 @@
+package com.huaxu.controller;
+
+import com.huaxu.entity.DayReportEntity;
+import com.huaxu.service.TestDataService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020/12/14 11:29
+ */
+@RestController
+@RequestMapping("/TestDataController")
+@Api(tags = "数据测试")
+public class TestDataController {
+    @Autowired
+    private TestDataService testDataService;
+
+    @RequestMapping(value="createDataByDay" , method = RequestMethod.GET)
+    @ApiOperation(value = "生成日数据")
+    public void createDataByDay(
+            @ApiParam("设备id") @RequestParam Long id,
+             @ApiParam("开始时间,yyyy-MM-dd") @RequestParam String beginDate,
+            @ApiParam("结束时间,yyyy-MM-dd")@RequestParam String endDate){
+        LocalDate localDate1 =LocalDate.now();
+        LocalDate localDate2 =LocalDate.now();
+        if(null != beginDate){
+            localDate1 = LocalDate.parse(beginDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+            localDate2 = LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        }
+
+        List<DayReportEntity> dayReportEntity = testDataService.selectDeviceInfo(id);
+        testDataService.createDataByDay(dayReportEntity,localDate1,localDate2.plusDays(1));
+        testDataService.createDataByMonth(id,localDate1,localDate2.plusDays(1));
+        testDataService.createDataByYear(id,localDate1,localDate2.plusDays(1));
+        testDataService.createAlarmByDay(id.intValue(),localDate1,localDate2.plusDays(1),100);
+    }
+
+    @RequestMapping(value="createAlarmDataByDay" , method = RequestMethod.GET)
+    @ApiOperation(value = "生成报警数据")
+    public void createAlarmDataByDay(
+            @ApiParam("设备id") @RequestParam Long id,
+            @ApiParam("报警信息条数") @RequestParam Integer number,
+            @ApiParam("开始时间,yyyy-MM-dd") @RequestParam String beginDate,
+            @ApiParam("结束时间,yyyy-MM-dd")@RequestParam String endDate) {
+        LocalDate localDate1 = LocalDate.now();
+        LocalDate localDate2 = LocalDate.now();
+        if (null != beginDate) {
+            localDate1 = LocalDate.parse(beginDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+            localDate2 = LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        }
+        testDataService.createAlarmByDay(id.intValue(),localDate1,localDate2.plusDays(1),number);
+    }
+}

+ 20 - 0
sms_water/src/main/java/com/huaxu/dao/TestDataMapper.java

@@ -0,0 +1,20 @@
+package com.huaxu.dao;
+
+import com.huaxu.entity.DayReportEntity;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020/12/14 15:35
+ */
+@Mapper
+public interface TestDataMapper {
+
+    List<DayReportEntity> selectDeviceInfo(@Param("id") Long id);
+    void batchInsertYearReport(@Param("year") Integer year, @Param("id")Long id);
+    void batchInsertMonthReport(@Param("year") Integer year, @Param("month")Integer month, @Param("id")Long id);
+}

+ 31 - 2
sms_water/src/main/java/com/huaxu/rabbitmq/ReceiveData.java

@@ -100,7 +100,36 @@ public class ReceiveData {
             if(StringUtils.isBlank(devcieCode)){
                 return ;
             }
-            MonitorDataEntity monitorDataEntity =  monitorDataService.getDeviceMonitorInfoByDeviceCode(devcieCode);
+            List<MonitorDataEntity> list = new ArrayList<>();
+            //暂时测试共用一个设备数据
+            MonitorDataEntity monitorDataEntity0 =  monitorDataService.getDeviceMonitorInfoByDeviceCode(devcieCode);
+            MonitorDataEntity monitorDataEntity1 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("SDD5456");
+            MonitorDataEntity monitorDataEntity2 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("AJH1210");
+            MonitorDataEntity monitorDataEntity3 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("WL20201215A");
+            MonitorDataEntity monitorDataEntity4 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("WL20201215B");
+            MonitorDataEntity monitorDataEntity5 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("WL20201215C");
+            MonitorDataEntity monitorDataEntity6 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("SDH54GDS45");
+            MonitorDataEntity monitorDataEntity7 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("QWA65D");
+            MonitorDataEntity monitorDataEntity8 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("DFG454963");
+            MonitorDataEntity monitorDataEntity9 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("DFD1234");
+            MonitorDataEntity monitorDataEntity10 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("DSF24564 ");
+            MonitorDataEntity monitorDataEntity11 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("ASH641 ");
+            MonitorDataEntity monitorDataEntity12 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("HJH562");
+            list.add(monitorDataEntity0);
+            list.add(monitorDataEntity1);
+            list.add(monitorDataEntity2);
+            list.add(monitorDataEntity3);
+            list.add(monitorDataEntity4);
+            list.add(monitorDataEntity5);
+            list.add(monitorDataEntity6 );
+            list.add(monitorDataEntity7 );
+            list.add(monitorDataEntity8 );
+            list.add(monitorDataEntity9 );
+            list.add(monitorDataEntity10);
+            list.add(monitorDataEntity11);
+            list.add(monitorDataEntity12);
+            for(MonitorDataEntity monitorDataEntity:list){
+            //
             //查询不到设备或者设备属性为空
             if(monitorDataEntity == null
                     || monitorDataEntity.getDataValues() == null
@@ -193,7 +222,7 @@ public class ReceiveData {
                 alarmDetailMapper.batchInsert(insert);
                }
            }
-
+            }
         }
 
     }

+ 22 - 0
sms_water/src/main/java/com/huaxu/service/TestDataService.java

@@ -0,0 +1,22 @@
+package com.huaxu.service;
+
+import com.huaxu.entity.DayReportEntity;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDate;
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020/12/14 14:36
+ */
+public interface TestDataService {
+
+    void createDataByYear(Long id , LocalDate beginDate, LocalDate endDate);
+    void createDataByMonth(Long id ,LocalDate beginDate, LocalDate endDate);
+    void createDataByDay(List<DayReportEntity> dayReportEntityList,LocalDate beginDate, LocalDate endDate);
+    void createAlarmByDay(Integer deviceId,LocalDate beginDate, LocalDate endDate,Integer times);
+    List<DayReportEntity> selectDeviceInfo(Long id);
+}

+ 168 - 0
sms_water/src/main/java/com/huaxu/service/impl/TestDataServiceImpl.java

@@ -0,0 +1,168 @@
+package com.huaxu.service.impl;
+
+import com.huaxu.dao.AlarmDetailMapper;
+import com.huaxu.dao.MonitorDataMapper;
+import com.huaxu.dao.TestDataMapper;
+import com.huaxu.dto.DeviceCheckAlarmDto;
+import com.huaxu.entity.AlarmDetailsEntity;
+import com.huaxu.entity.DayReportEntity;
+import com.huaxu.service.TestDataService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.time.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2020/12/14 14:36
+ */
+@Service
+public class TestDataServiceImpl implements TestDataService {
+
+    @Resource
+    private AlarmDetailMapper alarmDetailMapper;
+    @Resource
+    private TestDataMapper testDataMapper;
+
+    @Resource
+    private MonitorDataMapper monitorDataMapper;
+
+    public List<DayReportEntity> selectDeviceInfo(Long id){
+        return testDataMapper.selectDeviceInfo(id);
+    }
+
+    @Override
+    public void createDataByYear(Long id ,LocalDate beginDate, LocalDate endDate) {
+        while(beginDate.isBefore(endDate)){
+            testDataMapper.batchInsertYearReport(beginDate.getYear(),id);
+            beginDate=beginDate.plusYears(1);
+        }
+    }
+
+    @Override
+    public void createDataByMonth(Long id ,LocalDate beginDate, LocalDate endDate) {
+        while(beginDate.isBefore(endDate)){
+            testDataMapper.batchInsertMonthReport(beginDate.getYear(),beginDate.getMonthValue(),id);
+            beginDate=beginDate.plusMonths(1);
+        }
+    }
+    public void createDataByDay(List<DayReportEntity> dayReportEntityList,LocalDate beginDate, LocalDate endDate) {
+        LocalDateTime beginDateTime=beginDate.atStartOfDay();
+        LocalDateTime endDateTime=endDate.atStartOfDay();
+
+        List<DayReportEntity> dayReportEntities =new ArrayList<>();
+        for(int i=0,j=0; beginDateTime.isBefore(endDateTime);i++,j++){
+            if(i==24){
+                i=0;
+            }
+            beginDateTime = beginDateTime.plusHours(1);
+            for(DayReportEntity dayReportEntity : dayReportEntityList){
+
+                DayReportEntity dayReport = new DayReportEntity();
+                dayReport.setTenantId(dayReportEntity.getTenantId());
+                dayReport.setParentSceneId(dayReportEntity.getParentSceneId());
+                dayReport.setParentSceneName(dayReportEntity.getParentSceneName());
+                dayReport.setSceneId(dayReportEntity.getSceneId());
+                dayReport.setSceneName(dayReportEntity.getSceneName());
+                dayReport.setDeviceId(dayReportEntity.getDeviceId());
+                dayReport.setDeviceName(dayReportEntity.getDeviceName());
+                dayReport.setDeviceCode(dayReportEntity.getDeviceCode());
+                dayReport.setAttributeId(dayReportEntity.getAttributeId());
+                dayReport.setAttributeName(dayReportEntity.getAttributeName());
+
+
+                dayReport.setYear(beginDateTime.getYear());
+                dayReport.setMonth(beginDateTime.getMonthValue());
+                dayReport.setDay(beginDateTime.getDayOfMonth());
+                dayReport.setHour(i);
+                dayReport.setMinValue(new Double(j));
+                dayReport.setMaxValue(j+1.0);
+                dayReport.setAvgValue(j+0.5);
+                dayReport.setSumValue(1d);
+                dayReport.setLatestValue(j+1.0);
+                dayReport.setCollectDate(Date.from(beginDateTime.atZone(ZoneId.systemDefault()).toInstant()));
+                dayReportEntities.add(dayReport);
+            }
+
+        }
+        if(dayReportEntities.size()>0){
+            for(int i=0;500*i<dayReportEntities.size();i++){
+                if(500*i+500<dayReportEntities.size()){
+                    monitorDataMapper.batchInsertDayReport(dayReportEntities.subList(500*i,500*i+500));
+                }else{
+                    monitorDataMapper.batchInsertDayReport(dayReportEntities.subList(500*i,dayReportEntities.size()));
+                }
+            }
+        }
+    }
+
+    public void createAlarmByDay(Integer deviceId,LocalDate beginDate, LocalDate endDate,Integer times){
+
+        List<DeviceCheckAlarmDto> deviceCheckAlarmDtos = alarmDetailMapper.selectDeviceForCheckAlarm(deviceId,"状态报警");
+
+        ZoneOffset zoneOffset = ZoneOffset.ofHours(8);
+        Long beginTimestamp = beginDate.atStartOfDay().toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
+        Long endTimestamp = endDate.atStartOfDay().toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
+        int size =deviceCheckAlarmDtos.size();
+        List<DayReportEntity> dayReportEntities =new ArrayList<>();
+        if(size>0){
+            List<AlarmDetailsEntity>  deviceStateAlarmDtoNews = new ArrayList<>();
+            for(int i=0;i<times;i++){
+                //随机时间报警
+                Long timestamp = new Double(Math.random()*(endTimestamp-beginTimestamp+1)+beginTimestamp).longValue();
+                Integer m = (int)(Math.random()*size);
+                //随机报警参数
+//                DeviceCheckAlarmDto d=deviceCheckAlarmDtos.get(m);
+                DeviceCheckAlarmDto d=deviceCheckAlarmDtos.get(0);
+
+                AlarmDetailsEntity alarmDetailsEntity = new AlarmDetailsEntity();
+                alarmDetailsEntity.setDateUpdate(new Date(timestamp));
+                alarmDetailsEntity.setDateCreate(new Date(timestamp));
+                alarmDetailsEntity.setStatus(1);
+                alarmDetailsEntity.setOpState(1);
+                alarmDetailsEntity.setState(1);
+                alarmDetailsEntity.setAlarmStartTime(new Date(timestamp));
+                alarmDetailsEntity.setAlarmContent(d.getDeviceName()+"离线时间"+d.getAlarmCondition() +d.getAlarmValue()+"分钟");
+                alarmDetailsEntity.setAlarmValue(d.getDuration());
+                alarmDetailsEntity.setAttributeId(d.getAttributeId());
+                alarmDetailsEntity.setAlarmType("状态报警");
+                alarmDetailsEntity.setDeptOrgId(d.getDeptOrgId());
+                alarmDetailsEntity.setCompanyOrgId(d.getCompanyOrgId());
+                alarmDetailsEntity.setDeviceId(d.getDeviceId());
+                alarmDetailsEntity.setTenantId(d.getTenantId());
+                alarmDetailsEntity.setAlarmSettingId(d.getAlarmSettingId());
+                deviceStateAlarmDtoNews.add(alarmDetailsEntity);
+            }
+            if(deviceStateAlarmDtoNews.size()>0){
+                for(int i=0;500*i<dayReportEntities.size();i++){
+                    if(500*i+500<dayReportEntities.size()){
+                        alarmDetailMapper.batchInsert(deviceStateAlarmDtoNews.subList(500*i,500*i+500));
+                    }else{
+                        alarmDetailMapper.batchInsert(deviceStateAlarmDtoNews.subList(500*i,dayReportEntities.size()));
+                    }
+                }
+            }
+        }
+    }
+
+    public static void main(String[] args) {
+        int max=8,min=7;
+        int ran2 = (int) (Math.random()*(max-min+1)+min);
+        int a=(int) (Math.random()*10);
+        int b=(int)(Math.random()*10);
+        System.out.println(a+"..."+b+"......."+ran2);
+
+//        Long timestamp = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8));
+//        Long timestamp2 = LocalDateTime.now().toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
+//        LocalDate localDate = Instant.ofEpochSecond(timestamp).atZone(ZoneOffset.ofHours(8)).toLocalDate();
+//        LocalDateTime localDateTime = Instant.ofEpochSecond(timestamp).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
+//        System.out.println(timestamp);
+//        System.out.println(timestamp2);
+//        System.out.println(localDate.toString());
+//        System.out.println(localDateTime.toString());
+    }
+}

+ 1 - 1
sms_water/src/main/resources/mapper/DeviceMapper.xml

@@ -49,7 +49,7 @@
         from sms_device d
         <include refid="deviceJoins"/>
         where d.status = 1
-        and id  in
+        and d.id  in
         <foreach collection="ids" item="item" open="(" close=")" separator=",">
             #{item}
         </foreach>

+ 54 - 0
sms_water/src/main/resources/mapper/TestDataMapper.xml

@@ -0,0 +1,54 @@
+<?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.huaxu.dao.TestDataMapper">
+
+    <select id="selectDeviceInfo" resultType="com.huaxu.entity.DayReportEntity">
+        select
+            d.TENANT_ID as "tenantId"
+            ,ps.id as "parentSceneId"
+            ,ps.SCENE_NAME as "parentSceneName"
+            ,s.id as "sceneId"
+            ,s.SCENE_NAME as "sceneName"
+            ,d.id as "deviceId"
+            ,d.DEVICE_NAME as "deviceName"
+            ,d.DEVICE_CODE as "deviceCode"
+            ,da.id as "attributeId"
+            ,da.`NAME` as "attributeName"
+        from sms_device d
+        left join sms_device_type dt on dt.id=d.DEVICE_TYPE_ID
+        left join sms_device_attribute da on da.DEVICE_TYPE_ID =dt.id
+        left join sms_scene s on d.SCENE_ID=s.id
+        left join sms_scene ps on s.PARENT_SCENE_IDS like concat( '%,',ps.id,',%' )and ps.PARENT_SCENE_ID ='0'
+        where d.ID=#{id}
+    </select>
+
+    <insert id="batchInsertYearReport">
+        INSERT INTO `sms`.`sms_year_report`( `TENANT_ID`, `PARENT_SCENE_ID`, `PARENT_SCENE_NAME`, `SCENE_ID`, `SCENE_NAME`, `DEVICE_ID`, `DEVICE_NAME`, `DEVICE_CODE`, `ATTRIBUTE_ID`, `ATTRIBUTE_NAME`, `YEAR`, `MONTH`, `MIN_VALUE`, `MAX_VALUE`, `AVG_VALUE`, `SUM_VALUE`, `LATEST_VALUE`, `COLLECT_DATE`)
+        select TENANT_ID, PARENT_SCENE_ID, PARENT_SCENE_NAME, SCENE_ID, SCENE_NAME, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME,  YEAR, MONTH
+            ,min(MIN_VALUE) MIN_VALUE
+            ,max(MAX_VALUE) MAX_VALUE
+            ,avg(AVG_VALUE) AVG_VALUE
+            ,sum(SUM_VALUE) SUM_VALUE
+            ,(select LATEST_VALUE from sms_day_report where DEVICE_ID =a.DEVICE_ID and ATTRIBUTE_ID = a.ATTRIBUTE_ID and COLLECT_DATE = max(a.COLLECT_DATE)) LATEST_VALUE
+            ,max(COLLECT_DATE) COLLECT_DATE
+        from sms_month_report a
+        where year =#{year} and DEVICE_ID=#{id}
+        group by TENANT_ID, PARENT_SCENE_ID, PARENT_SCENE_NAME, SCENE_ID, SCENE_NAME, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME,  YEAR, MONTH
+    </insert>
+
+    <insert id="batchInsertMonthReport">
+        INSERT INTO `sms`.`sms_month_report`( `TENANT_ID`, `PARENT_SCENE_ID`, `PARENT_SCENE_NAME`, `SCENE_ID`, `SCENE_NAME`, `DEVICE_ID`, `DEVICE_NAME`, `DEVICE_CODE`, `ATTRIBUTE_ID`, `ATTRIBUTE_NAME`, `YEAR`, `MONTH`, `DAY`, `MIN_VALUE`, `MAX_VALUE`, `AVG_VALUE`, `SUM_VALUE`, `LATEST_VALUE`, `COLLECT_DATE`)
+
+        select TENANT_ID, PARENT_SCENE_ID, PARENT_SCENE_NAME, SCENE_ID, SCENE_NAME, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME,  YEAR, MONTH, DAY
+            ,min(MIN_VALUE) MIN_VALUE
+            ,max(MAX_VALUE) MAX_VALUE
+            ,avg(AVG_VALUE) AVG_VALUE
+            ,sum(SUM_VALUE) SUM_VALUE
+            ,(select LATEST_VALUE from sms_day_report where DEVICE_ID =a.DEVICE_ID and ATTRIBUTE_ID = a.ATTRIBUTE_ID and COLLECT_DATE = max(a.COLLECT_DATE)) LATEST_VALUE
+            ,max(COLLECT_DATE) COLLECT_DATE
+        from sms_day_report a
+        where year = #{year} and month =#{month} and DEVICE_ID=#{id}
+        group by TENANT_ID, PARENT_SCENE_ID, PARENT_SCENE_NAME, SCENE_ID, SCENE_NAME, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME,  YEAR, MONTH, DAY
+    </insert>
+
+</mapper>