瀏覽代碼

Merge remote-tracking branch 'origin/master'

wangyangyang 4 年之前
父節點
當前提交
96d5bb5395

+ 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;
+	}
+}

+ 13 - 3
sms_water/src/main/java/com/huaxu/controller/MonitorDataReportController.java

@@ -27,8 +27,6 @@ import java.util.List;
 @RequestMapping("/MonitorDataReport")
 @Api(tags = "统计分析")
 public class MonitorDataReportController {
-    @Autowired
-    private MonitorDataService monitorDataService;
 
     @Autowired
     private MonitorDataReportService monitorDataReportService;
@@ -37,10 +35,16 @@ public class MonitorDataReportController {
     @ApiOperation(value = "二供——图表")
     public AjaxMessage<List<MonitorDataChartReportDeviceDto>> MonitorDataChartReport(
             @ApiParam(value = "场景id", required = true) @RequestParam Long sceneId,
-            @ApiParam(value = "日期,格式:2020-12-12", required = true) @RequestParam String reportDate,
+            @ApiParam(value = "时间", required = true) @RequestParam String reportDate,
             @ApiParam(value = "类型,1年2月3日", required = true) @RequestParam Integer reportType
     ){
         LocalDate localDate =LocalDate.now();
+        if(reportType !=null && reportType ==1){
+            reportDate = reportDate+"-01-01";
+        }else
+        if(reportType !=null && reportType ==2){
+            reportDate = reportDate+"-01";
+        }
         if(null != reportDate){
             localDate = LocalDate.parse(reportDate,DateTimeFormatter.ofPattern("yyyy-MM-dd"));
         }
@@ -66,6 +70,12 @@ public class MonitorDataReportController {
             @ApiParam(value = "类型,1年2月3日", required = true) @RequestParam Integer reportType
     ){
         LocalDate localDate =LocalDate.now();
+        if(reportType !=null && reportType ==1){
+            reportDate = reportDate+"-01-01";
+        }else
+        if(reportType !=null && reportType ==2){
+            reportDate = reportDate+"-01";
+        }
         if(null != reportDate){
             localDate = LocalDate.parse(reportDate,DateTimeFormatter.ofPattern("yyyy-MM-dd"));
         }

+ 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);
+}

+ 2 - 0
sms_water/src/main/java/com/huaxu/dto/MonitorDataChartReportAttributeDto.java

@@ -22,6 +22,8 @@ public class MonitorDataChartReportAttributeDto implements Serializable {
     private String attributeType;
     @ApiModelProperty("属性名称")
     private String attributeName;
+    @ApiModelProperty("属性单位")
+    private String unit;
     @ApiModelProperty("数据")
     private List<MonitorDataChartReportValueDto> monitorDataChartReportValue;
 }

+ 3 - 1
sms_water/src/main/java/com/huaxu/dto/MonitorDataChartReportValueDto.java

@@ -20,8 +20,10 @@ import java.util.Date;
 public class MonitorDataChartReportValueDto implements Serializable {
 
     private static final long serialVersionUID = 6248751275101485917L;
-    @ApiModelProperty("X轴时间数字")
+    @ApiModelProperty("X轴数字")
     private Integer dateLabel;
+    @ApiModelProperty("X轴时间")
+    private String dateStringLabel;
     @ApiModelProperty("数据带单位")
     private String monitorData;
     @ApiModelProperty("数据值")

+ 3 - 0
sms_water/src/main/java/com/huaxu/rabbitmq/ReceiveData.java

@@ -100,7 +100,10 @@ public class ReceiveData {
             if(StringUtils.isBlank(devcieCode)){
                 return ;
             }
+            List<MonitorDataEntity> list = new ArrayList<>();
+            //暂时测试共用一个设备数据
             MonitorDataEntity monitorDataEntity =  monitorDataService.getDeviceMonitorInfoByDeviceCode(devcieCode);
+            //
             //查询不到设备或者设备属性为空
             if(monitorDataEntity == null
                     || monitorDataEntity.getDataValues() == null

+ 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);
+}

+ 36 - 6
sms_water/src/main/java/com/huaxu/service/impl/MonitorDataReportServiceImpl.java

@@ -81,13 +81,28 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
                                 MonitorDataChartReportValueDto monitorDataChartReportValueDto = new MonitorDataChartReportValueDto();
                                 monitorDataChartReportValueDto.setData(0.0);
                                 if(type != null && type ==3){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusHours(i));
+                                    LocalDateTime dateTime= localDateTime.plusHours(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                                        dateTime.getYear()+"-"+
+                                                        dateTime.getMonthValue()+"-"+
+                                                        dateTime.getDayOfMonth()+" "+
+                                                        dateTime.getHour()+":00");
                                 }
                                 if(type != null && type ==2){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusDays(i));
+                                    LocalDateTime dateTime= localDateTime.plusDays(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                                    dateTime.getYear()+"-"+
+                                                    dateTime.getMonthValue()+"-"+
+                                                    dateTime.getDayOfMonth());
                                 }
                                 if(type != null && type ==1){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusMonths(i));
+                                    LocalDateTime dateTime= localDateTime.plusMonths(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                            dateTime.getYear()+"-"+
+                                                    dateTime.getMonthValue());
                                 }
                                 monitorDataChartReportValueDto.setDateLabel(i+growingBase);
                                 monitorDataChartReportValueDto.setMonitorData("");
@@ -97,13 +112,28 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
                                 MonitorDataChartReportValueDto monitorDataChartReportValueDto = new MonitorDataChartReportValueDto();
                                 monitorDataChartReportValueDto.setData(0.0);
                                 if(type != null && type ==3){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusHours(i));
+                                    LocalDateTime dateTime= localDateTime.plusHours(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                            dateTime.getYear()+"-"+
+                                                    dateTime.getMonthValue()+"-"+
+                                                    dateTime.getDayOfMonth()+" "+
+                                                    dateTime.getHour()+":00");
                                 }
                                 if(type != null && type ==2){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusDays(i));
+                                    LocalDateTime dateTime= localDateTime.plusDays(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                            dateTime.getYear()+"-"+
+                                                    dateTime.getMonthValue()+"-"+
+                                                    dateTime.getDayOfMonth());
                                 }
                                 if(type != null && type ==1){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusMonths(i));
+                                    LocalDateTime dateTime= localDateTime.plusMonths(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                            dateTime.getYear()+"-"+
+                                                    dateTime.getMonthValue());
                                 }
                                 monitorDataChartReportValueDto.setDateLabel(i+growingBase);
                                 monitorDataChartReportValueDto.setMonitorData("");

+ 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>

+ 36 - 11
sms_water/src/main/resources/mapper/MonitorDataReportMapper.xml

@@ -11,11 +11,13 @@
     <resultMap id="AttributeData" type="com.huaxu.dto.MonitorDataChartReportAttributeDto">
         <result property="attributeType" column="attributeType"/>
         <result property="attributeName" column="attributeName"/>
+        <result property="unit" column="unit"/>
         <collection property="monitorDataChartReportValue" resultMap="MonitorDataChartReportValue"/>
     </resultMap>
 
     <resultMap id="MonitorDataChartReportValue" type="com.huaxu.dto.MonitorDataChartReportValueDto">
         <result property="dateLabel" column="dateLabel" />
+        <result property="dateStringLabel" column="dateStringLabel" />
         <result property="monitorData" column="monitorData" />
         <result property="data" column="data"/>
         <result property="date" column="date"/>
@@ -30,12 +32,15 @@
         select
         <if test="type != null and type ==1">
             r.`MONTH` as "dateLabel",
+            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`)) as "dateStringLabel",
         </if>
         <if test="type != null and type ==2">
             r.`DAY` as "dateLabel",
+            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`)) as "dateStringLabel",
         </if>
         <if test="type != null and type ==3">
             r.`HOUR` as "dateLabel",
+            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`),' ',if(r.`HOUR`&lt;10,CONCAT(0,r.`HOUR`),r.`HOUR`),':00') as "dateStringLabel",
         </if>
         cast(ifnull(r.AVG_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
         ,r.AVG_VALUE as "data"
@@ -43,6 +48,7 @@
 
         ,d.DEVICE_CODE as "devoceCode"
         ,d.DEVICE_NAME as "deviceName"
+        ,da.unit as "unit"
         ,r.ATTRIBUTE_NAME as "attributeName"
 
         from ${tableName} r
@@ -104,23 +110,28 @@
 
     <select id="MonitorDataEnergyReport" resultMap="MonitorDataChartReportMap">
         select
-            <if test="type != null and type ==1">
-                r.`MONTH` as "dateLabel",
-            </if>
-            <if test="type != null and type ==2">
-                r.`DAY` as "dateLabel",
-            </if>
-            <if test="type != null and type ==3">
-                r.`HOUR` as "dateLabel",
-            </if>
-            cast(ifnull(r.SUM_VALUE,0) as char)+ifnull(da.UNIT,'') as "monitorData"
+        <if test="type != null and type ==1">
+            r.`MONTH` as "dateLabel",
+            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`)) as "dateStringLabel",
+        </if>
+        <if test="type != null and type ==2">
+            r.`DAY` as "dateLabel",
+            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`)) as "dateStringLabel",
+        </if>
+        <if test="type != null and type ==3">
+            r.`HOUR` as "dateLabel",
+            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`),' ',if(r.`HOUR`&lt;10,CONCAT(0,r.`HOUR`),r.`HOUR`),':00') as "dateStringLabel",
+        </if>
+        cast(ifnull(r.SUM_VALUE,0) as char)+ifnull(da.UNIT,'') as "monitorData"
             ,ifnull(r.SUM_VALUE ,0)  as "data"
             ,r.COLLECT_DATE as "date"
 
             ,d.DEVICE_CODE as "devoceCode"
             ,d.DEVICE_NAME as "deviceName"
             ,da.ATTRIBUTE_TYPE as "attributeType"
+            ,da.unit as "unit"
             ,if(da.ATTRIBUTE_TYPE=3,'用水量','耗电量') as  "attributeName"
+
         <if test="type != null and type ==1">
             from sms_year_report r
         </if>
@@ -188,12 +199,15 @@
         select
         <if test="type != null and type ==1">
             r.`MONTH` as "dateLabel",
+            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`)) as "dateStringLabel",
         </if>
         <if test="type != null and type ==2">
             r.`DAY` as "dateLabel",
+            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`)) as "dateStringLabel",
         </if>
         <if test="type != null and type ==3">
             r.`HOUR` as "dateLabel",
+            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`),' ',if(r.`HOUR`&lt;10,CONCAT(0,r.`HOUR`),r.`HOUR`),':00') as "dateStringLabel",
         </if>
             cast(ifnull(r.AVG_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
             ,r.AVG_VALUE as "data"
@@ -202,6 +216,7 @@
             ,d.DEVICE_CODE as "devoceCode"
             ,d.DEVICE_NAME as "deviceName"
             ,da.ATTRIBUTE_TYPE as "attributeType"
+            ,da.unit as "unit"
             ,if(da.ATTRIBUTE_TYPE=8,'PH',if(da.ATTRIBUTE_TYPE=11,'余氯','浊度')) as  "attributeName"
         <if test="type != null and type ==1">
             from sms_year_report r
@@ -271,10 +286,20 @@
 
     <select id="DeviceAlarmReport" resultMap="MonitorDataChartReportMap">
         select
-        a.*,DATE_ADD(#{beginDate},INTERVAL a.dateLabel ${dateType}) as "date"
+        a.*,DATE_ADD(#{beginDate},INTERVAL a.dateLabel-1 ${dateType}) as "date"
         from (
             select
         ${dateType}(ad.ALARM_START_TIME) as  "dateLabel"
+
+        <if test="dateType != null and dateType == 'month'">
+            ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m') as "dateStringLabel"
+        </if>
+        <if test="dateType != null and dateType == 'day'">
+            ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m-%d') as "dateStringLabel"
+        </if>
+        <if test="dateType != null and dateType == 'hour'">
+            ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m-%d %H:00') as "dateStringLabel"
+        </if>
             ,count(1) as "monitorData"
             ,count(1) as "data"
 

+ 19 - 7
sms_water/src/main/resources/mapper/OnlineMonitorMapper.xml

@@ -41,7 +41,7 @@
     <sql id="sceneDeviceJoins">
         inner join sms_scene t2 on find_in_set(t1.id, t2.parent_scene_ids) and t2. status = 1
         inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
-        left join sms_device t4 on t4.scene_id=t2.id
+        left join sms_device t4 on t4.scene_id=t2.id and t4. status = 1 and  t4.enable_state=1
     </sql>
     <sql id="attributeJoins">
         select a1.device_id,a1.attribute_id,a1.remark,a1.seq,a2.name,a2.unit,a2.attribute_type
@@ -58,7 +58,7 @@
             from sms_device a1
             inner join sms_alarm_details a2 on a1.id=a2.device_id and a2.`status` = 1 and  a2.state = 1
             inner join sms_scene a3 on a3.id=a1.scene_id and a3.`status` = 1
-            where a1.`status` = 1 group by one_scene_id
+            where a1.`status` = 1 and a1.enable_state=1 group by one_scene_id
         )t7 on t7.one_scene_id=t1.id
     </sql>
 
@@ -71,13 +71,16 @@
         from sms_scene t1
         <include refid="sceneDeviceJoins"/>
         <include refid="alarmDetailsJoins"/>
-        where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{sceneTypeName} and t6.state=1
+        where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{sceneTypeName} and t6.state=1
         <if test="sceneIds != null and sceneIds.size() > 0">
             and t1.id  in
             <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
                 #{item}
             </foreach>
         </if>
+        <if test="sceneIds == null or sceneIds.size() == 0">
+            and t1.id is null
+        </if>
         <if test="sceneName != null and sceneName != ''">
             and t1.scene_name  like concat('%',#{sceneName},'%')
         </if>
@@ -94,13 +97,16 @@
         from sms_scene t1
         <include refid="sceneDeviceJoins"/>
         <include refid="alarmDetailsJoins"/>
-        where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{sceneTypeName} and t6.state=1
+        where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{sceneTypeName} and t6.state=1
         <if test="sceneIds != null and sceneIds.size() > 0">
             and t1.id  in
             <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
                 #{item}
             </foreach>
         </if>
+        <if test="sceneIds == null or sceneIds.size() == 0">
+            and t1.id is null
+        </if>
         <if test="sceneName != null and sceneName != ''">
             and t1.scene_name  like concat('%',#{sceneName},'%')
         </if>
@@ -121,13 +127,16 @@
             <include refid="attributeJoins"/> and a1.is_suspension = 1
         )t5 on t5.device_id=t4.id
         left join sms_alarm_details t6 on t6.device_id=t4.id and t6. status = 1 and t6.attribute_id = t5.attribute_id and t6.state = 1
-        where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{sceneTypeName}
+        where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{sceneTypeName}
         <if test="sceneIds != null and sceneIds.size() > 0">
             and t1.id  in
             <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
                 #{item}
             </foreach>
         </if>
+        <if test="sceneIds == null or sceneIds.size() == 0">
+            and t1.id is null
+        </if>
         <if test="tenantId != null and tenantId != ''">
             and t1.tenant_id = #{tenantId}
         </if>
@@ -158,13 +167,16 @@
         select t1.id scene_id,t1.scene_name,t1.address
         from sms_scene t1
         inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
-        where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{onlineDataDto.sceneTypeName}
+        where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{onlineDataDto.sceneTypeName}
         <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
             and t1.id  in
             <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
                 #{item}
             </foreach>
         </if>
+        <if test="onlineDataDto.sceneIds == null or onlineDataDto.sceneIds.size() == 0">
+            and t1.id is null
+        </if>
         <if test="onlineDataDto.sceneName != null and onlineDataDto.sceneName != ''">
             and t1.scene_name  like concat('%',#{onlineDataDto.sceneName},'%')
         </if>
@@ -183,7 +195,7 @@
         from sms_scene t1
         <include refid="sceneDeviceJoins"/>
         <include refid="alarmDetailsJoins"/>
-        where t1.parent_scene_id = 0 and t1. status = 1 and t1.id = #{id}
+        where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t1.id = #{id}
         <if test="sceneIds != null and sceneIds.size() > 0">
             and t1.id  in
             <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">

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

@@ -228,7 +228,7 @@
         FROM sms_scene a
         <include refid="deviceJoins"/>
         <where>
-            a.parent_scene_id=0 and a.status=1 and s.scene_type_name=#{scene.sceneTypeName}
+            a.parent_scene_id=0 and a.status=1 and a.enable_state=1 and s.scene_type_name=#{scene.sceneTypeName}
             <if test="scene.tenantId != null  and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
             <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and  scene.programItems != null and scene.programItems.size() > 0">
                 <if test="scene.permissonType == 5 or scene.permissonType == 2">

+ 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>