lin 4 years ago
parent
commit
6b253f2658
40 changed files with 1959 additions and 47 deletions
  1. 5 3
      build.gradle
  2. 42 0
      src/main/java/com/zoniot/ccrc/commom/config/RabbitConfig.java
  3. 38 0
      src/main/java/com/zoniot/ccrc/commom/model/BuildingData.java
  4. 40 0
      src/main/java/com/zoniot/ccrc/commom/model/CommunityData.java
  5. 31 0
      src/main/java/com/zoniot/ccrc/commom/model/DeviceData.java
  6. 334 0
      src/main/java/com/zoniot/ccrc/commom/utils/ExcelUtil.java
  7. 32 0
      src/main/java/com/zoniot/ccrc/controller/ExternalApiController.java
  8. 54 0
      src/main/java/com/zoniot/ccrc/controller/RealTimeMonitorController.java
  9. 1 1
      src/main/java/com/zoniot/ccrc/controller/system/BuildingController.java
  10. 52 0
      src/main/java/com/zoniot/ccrc/controller/system/DeviceController.java
  11. 2 0
      src/main/java/com/zoniot/ccrc/dao/BuildingMapper.java
  12. 2 0
      src/main/java/com/zoniot/ccrc/dao/CommunityMapper.java
  13. 60 0
      src/main/java/com/zoniot/ccrc/dao/DeviceMapper.java
  14. 2 0
      src/main/java/com/zoniot/ccrc/dao/SiteMapper.java
  15. 75 0
      src/main/java/com/zoniot/ccrc/dto/BuildingInfoListDto.java
  16. 37 0
      src/main/java/com/zoniot/ccrc/dto/DeviceDto.java
  17. 64 0
      src/main/java/com/zoniot/ccrc/dto/MapStatisticalDto.java
  18. 9 2
      src/main/java/com/zoniot/ccrc/entity/Building.java
  19. 3 2
      src/main/java/com/zoniot/ccrc/entity/Community.java
  20. 8 6
      src/main/java/com/zoniot/ccrc/entity/Device.java
  21. 41 0
      src/main/java/com/zoniot/ccrc/rabbit/SyncBuildingReceiver.java
  22. 40 0
      src/main/java/com/zoniot/ccrc/rabbit/SyncCommunityReceiver.java
  23. 39 0
      src/main/java/com/zoniot/ccrc/rabbit/SyncDeviceReceiver.java
  24. 2 1
      src/main/java/com/zoniot/ccrc/security/WebSecurityConfig.java
  25. 2 1
      src/main/java/com/zoniot/ccrc/security/mobile/MobileLoginAuthenticationProvider.java
  26. 2 0
      src/main/java/com/zoniot/ccrc/service/BuildingService.java
  27. 3 0
      src/main/java/com/zoniot/ccrc/service/CommunityService.java
  28. 11 0
      src/main/java/com/zoniot/ccrc/service/DeviceService.java
  29. 12 0
      src/main/java/com/zoniot/ccrc/service/StatAndAnalysisService.java
  30. 29 6
      src/main/java/com/zoniot/ccrc/service/impl/BuildingServiceImpl.java
  31. 35 5
      src/main/java/com/zoniot/ccrc/service/impl/CommunityServiceImpl.java
  32. 114 1
      src/main/java/com/zoniot/ccrc/service/impl/DeviceServiceImpl.java
  33. 312 0
      src/main/java/com/zoniot/ccrc/service/impl/StatAndAnalysisServiceImpl.java
  34. 22 0
      src/main/resources/application-dev.properties
  35. 39 0
      src/main/resources/mapper/BuildingMapper.xml
  36. 62 1
      src/main/resources/mapper/CommunityMapper.xml
  37. 283 2
      src/main/resources/mapper/DeviceMapper.xml
  38. 4 0
      src/main/resources/mapper/SiteMapper.xml
  39. 11 15
      src/main/resources/mapper/WarningLogMapper.xml
  40. 5 1
      src/test/java/com/zoniot/ccrc/OptionalTest.java

+ 5 - 3
build.gradle

@@ -66,9 +66,9 @@ dependencies {
     compile('commons-collections:commons-collections:3.2.2')
 
     //poi
-    //compile 'org.apache.poi:poi:3.17'
-    //compile 'org.apache.poi:poi-ooxml:3.17'
-    //compile 'org.apache.poi:poi-ooxml-schemas:3.17'
+    compile 'org.apache.poi:poi:3.17'
+    compile 'org.apache.poi:poi-ooxml:3.17'
+    compile 'org.apache.poi:poi-ooxml-schemas:3.17'
     //jxls
     //compile 'org.jxls.jxls:2.4.6'
     //compile 'org.jxls:jxls-poi:1.0.16'
@@ -87,6 +87,8 @@ dependencies {
     compile('com.aliyun:aliyun-java-sdk-core:4.1.0')
     //jdom
     compile('org.jdom:jdom:1.1')
+
+    compile('org.springframework.boot:spring-boot-starter-amqp')
 }
 
 test {

+ 42 - 0
src/main/java/com/zoniot/ccrc/commom/config/RabbitConfig.java

@@ -0,0 +1,42 @@
+package com.zoniot.ccrc.commom.config;
+
+
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.FanoutExchange;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+
+/**
+ * <p>RabbitMQ配置</p>
+ *
+ * @Author wilian.peng
+ * @Date 2020/4/7 11:50
+ * @Version 1.0
+ */
+@Configuration
+public class RabbitConfig {
+
+
+
+    @Bean("customContainerFactory")
+    public SimpleRabbitListenerContainerFactory containerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
+        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
+        //设置线程数
+        factory.setConcurrentConsumers(2);
+        //最大线程数
+        factory.setMaxConcurrentConsumers(4);
+        configurer.configure(factory, connectionFactory);
+        return factory;
+    }
+
+
+
+
+}

+ 38 - 0
src/main/java/com/zoniot/ccrc/commom/model/BuildingData.java

@@ -0,0 +1,38 @@
+package com.zoniot.ccrc.commom.model;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class BuildingData {
+
+    private Integer id;
+
+    private Integer communityId;
+
+    private Integer customerId;
+
+    private String name;
+
+    private String address;
+
+    private Integer province;
+
+    private Integer city;
+
+    private Integer region;
+
+    private Double longitude;
+
+    private Double latitude;
+
+    private Integer status;
+    @JSONField(format="yyyy-MM-dd HH:mm:ss")
+    private Date createDate;
+    @JSONField(format="yyyy-MM-dd HH:mm:ss")
+    private Date updateDate;
+
+
+}

+ 40 - 0
src/main/java/com/zoniot/ccrc/commom/model/CommunityData.java

@@ -0,0 +1,40 @@
+package com.zoniot.ccrc.commom.model;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class CommunityData {
+    private Integer id;
+
+    private String name;
+
+    private String code;
+
+    private Integer customerId;
+
+    private Integer province;
+
+    private Integer city;
+
+    private Integer region;
+
+    private Double longitude;
+
+    private Double latitude;
+
+    private Integer districtId;
+
+    private String address;
+
+    private String remark;
+
+    private Integer status;
+    @JSONField(format="yyyy-MM-dd HH:mm:ss")
+    private Date dateCreate;
+    @JSONField(format="yyyy-MM-dd HH:mm:ss")
+    private Date dateUpdate;
+
+}

+ 31 - 0
src/main/java/com/zoniot/ccrc/commom/model/DeviceData.java

@@ -0,0 +1,31 @@
+package com.zoniot.ccrc.commom.model;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class DeviceData {
+    private Long id;
+    private String deviceNo;
+    private String meterNo;
+    private String fileNo;
+    private String sealNo;
+    private Integer sysId;
+    private Integer customerId;
+    private Integer deviceTypeId;
+    private Integer manufacturerId;
+    private Integer buildingId;
+    private Integer communityId;
+    private String locDesc;
+    private Double meterReading;
+    private Integer valveStatus;
+    private Integer status;
+    @JSONField(format="yyyy-MM-dd HH:mm:ss")
+    private Date lastReceiveTime;
+    @JSONField(format="yyyy-MM-dd HH:mm:ss")
+    private Date dateCreate;
+    @JSONField(format="yyyy-MM-dd HH:mm:ss")
+    private Date dateUpdate;
+}

+ 334 - 0
src/main/java/com/zoniot/ccrc/commom/utils/ExcelUtil.java

@@ -0,0 +1,334 @@
+package com.zoniot.ccrc.commom.utils;
+
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 导出Excel公共方法
+ */
+public class ExcelUtil {
+
+    //显示的导出表的标题
+    private String title;
+    //导出表的列名
+    private String[] rowName;
+
+    private List<Object[]> dataList = new ArrayList<Object[]>();
+
+    private List<String> eList = new ArrayList<String>();
+
+    HttpServletResponse response;
+
+    //构造方法,传入要导出的数据
+    public ExcelUtil(String title, String[] rowName, List<Object[]> dataList) {
+        this.dataList = dataList;
+        this.rowName = rowName;
+        this.title = title;
+    }
+    public ExcelUtil(String title, String[] rowName, List<Object[]> dataList, List<String>list) {
+        this.dataList = dataList;
+        this.rowName = rowName;
+        this.title = title;
+        this.eList = list;
+    }
+
+    /*
+     * 导出数据
+     * */
+    public void export(HttpServletResponse response) throws Exception {
+        try {
+            HSSFWorkbook workbook = new HSSFWorkbook();                        // 创建工作簿对象
+            int pointsDataLimit = 60000;
+            int part = dataList.size() / pointsDataLimit;//分批数
+            for (int p = 0; p <= part; p++) {
+                if(dataList.size() <  pointsDataLimit){
+                    pointsDataLimit = dataList.size();
+                }
+                List<Object[]> listPage = dataList.subList(0, pointsDataLimit);
+                HSSFSheet sheet = workbook.createSheet("Sheet"+(p+1));                     // 创建工作表
+
+                // 产生表格标题行
+                HSSFRow rowm = sheet.createRow(0);
+                HSSFCell cellTiltle = rowm.createCell(0);
+
+                //sheet样式定义【getColumnTopStyle()/getStyle()均为自定义方法 - 在下面  - 可扩展】
+                HSSFCellStyle columnTopStyle = this.getColumnTopStyle(workbook);//获取列头样式对象
+                HSSFCellStyle style = this.getStyle(workbook);                    //单元格样式对象
+
+                sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, (rowName.length - 1)));
+                cellTiltle.setCellStyle(columnTopStyle);
+                cellTiltle.setCellValue(title);
+
+
+                HSSFRow rowRowName = null;
+                if(eList != null && eList.size() > 0){
+                    for(int i=0; i<eList.size(); i++){
+                        Row searchFormRow = sheet.createRow(2+i);
+                        Cell searchFormCell = searchFormRow.createCell(0);
+                        searchFormCell.setCellValue(eList.get(i));
+                        sheet.addMergedRegion(new CellRangeAddress(searchFormRow.getRowNum(),
+                                searchFormRow.getRowNum(), 0, (rowName.length - 1)));
+                    }
+                    rowRowName = sheet.createRow(4);                // 在索引4的位置创建行(最顶端的行开始的第二行)
+                }else{
+                    rowRowName = sheet.createRow(2);                // 在索引2的位置创建行(最顶端的行开始的第二行)
+                }
+
+                // 定义所需列数
+                int columnNum = rowName.length;
+
+                // 将列头设置到sheet的单元格中
+                for (int n = 0; n < columnNum; n++) {
+                    HSSFCell cellRowName = rowRowName.createCell(n);                //创建列头对应个数的单元格
+                    cellRowName.setCellType(CellType.STRING);                //设置列头单元格的数据类型
+                    HSSFRichTextString text = new HSSFRichTextString(rowName[n]);
+                    cellRowName.setCellValue(text);                                    //设置列头单元格的值
+                    cellRowName.setCellStyle(columnTopStyle);                        //设置列头单元格样式
+                }
+
+                //将查询出的数据设置到sheet对应的单元格中
+                for (int i = 0; i < listPage.size(); i++) {
+                    Object[] obj = listPage.get(i);//遍历每个对象
+                    HSSFRow row = null;
+                    if(eList != null && eList.size() > 0){
+                        row = sheet.createRow(i + 5);//创建所需的行数
+                    }else{
+                        row = sheet.createRow(i + 3);//创建所需的行数
+                    }
+
+
+                    for (int j = 0; j < obj.length; j++) {
+                        HSSFCell cell = null;   //设置单元格的数据类型
+                        if (j == 0) {
+                            cell = row.createCell(j, CellType.NUMERIC);
+                            cell.setCellValue(i + 1);
+                        } else {
+                            cell = row.createCell(j, CellType.STRING);
+                            if (obj[j] != null && !"".equals(obj[j])) {
+                                cell.setCellValue(obj[j].toString());                        //设置单元格的值
+                            }else {
+                                cell.setCellValue("-");
+                            }
+                        }
+                        cell.setCellStyle(style);                                    //设置单元格样式
+                    }
+                }
+                //让列宽随着导出的列长自动适应
+                for (int colNum = 0; colNum < columnNum; colNum++) {
+                    int columnWidth = sheet.getColumnWidth(colNum) / 256;
+                    for (int rowNum = 0; rowNum <= sheet.getLastRowNum(); rowNum++) {
+                        HSSFRow currentRow;
+                        //当前行未被使用过
+                        if (sheet.getRow(rowNum) == null) {
+                            currentRow = sheet.createRow(rowNum);
+                        } else {
+                            currentRow = sheet.getRow(rowNum);
+                        }
+                        if (currentRow.getCell(colNum) != null) {
+                            HSSFCell currentCell = currentRow.getCell(colNum);
+                            String numbers = "";
+
+                            if (currentCell.getCellTypeEnum() == CellType.STRING) {
+                                int length = calculateLength(currentCell.getStringCellValue());
+                                if (columnWidth < length) {
+                                    columnWidth = length;
+                                }
+                                if(eList != null && eList.size() > 0){
+                                    if(rowNum == 4){
+                                        numbers = currentCell != null ? currentCell.getStringCellValue() : "";
+                                    }
+                                    if(numbers.equals("序号")){
+                                        columnWidth = 18;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    if(columnWidth > 60){
+                        sheet.setColumnWidth(colNum, 60 * 256);
+                    }else {
+                        sheet.setColumnWidth(colNum, columnWidth * 256);
+                    }
+                }
+                //剔除
+                dataList.subList(0, pointsDataLimit).clear();
+            }
+
+            OutputStream out = null;
+            try {
+                //输出数据流
+                DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
+                LocalDateTime date = LocalDateTime.now();
+                String fileName = title + "-" + date.format(f) + ".xls";
+
+                String headStr = "attachment;filename*=UTF-8''" + URLEncoder.encode(fileName, "UTF-8");
+
+                response.setContentType("APPLICATION/OCTET-STREAM");
+                response.setHeader("Content-Disposition", headStr);
+                out = response.getOutputStream();
+                workbook.write(out);
+
+                //输出Excel文件
+                /*FileOutputStream output = new FileOutputStream("D:\\test.xls");
+                workbook.write(output);
+                output.flush();
+                workbook.close();*/
+            } catch (IOException e) {
+                e.printStackTrace();
+            }finally {
+                workbook.close();
+                if (out != null) {
+                    out.close();
+                }
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    /*
+     * 列头单元格样式
+     */
+    public HSSFCellStyle getColumnTopStyle(HSSFWorkbook workbook) {
+
+        // 设置字体
+        HSSFFont font = workbook.createFont();
+        //设置字体大小
+        font.setFontHeightInPoints((short) 11);
+        //字体加粗
+        font.setBold(true);
+        //设置字体名字
+        font.setFontName("Courier New");
+        //设置样式;
+        HSSFCellStyle style = workbook.createCellStyle();
+        //设置底边框;
+        style.setBorderBottom(BorderStyle.THIN);
+        //设置底边框颜色;
+        style.setBottomBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
+        //设置左边框;
+        style.setBorderLeft(BorderStyle.THIN);
+        //设置左边框颜色;
+        style.setLeftBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
+        //设置右边框;
+        style.setBorderRight(BorderStyle.THIN);
+        //设置右边框颜色;
+        style.setRightBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
+        //设置顶边框;
+        style.setBorderTop(BorderStyle.THIN);
+        //设置顶边框颜色;
+        style.setTopBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
+        //在样式用应用设置的字体;
+        style.setFont(font);
+        //设置自动换行;
+        style.setWrapText(false);
+        //设置水平对齐的样式为居中对齐;
+        style.setAlignment(HorizontalAlignment.CENTER);
+        //设置垂直对齐的样式为居中对齐;
+        style.setVerticalAlignment(VerticalAlignment.CENTER);
+
+        return style;
+
+    }
+
+    /*
+   * 列数据信息单元格样式
+   */
+    public HSSFCellStyle getStyle(HSSFWorkbook workbook) {
+        // 设置字体
+        HSSFFont font = workbook.createFont();
+        //设置字体大小
+        //font.setFontHeightInPoints((short)10);
+        //字体加粗
+        //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+        //设置字体名字
+        font.setFontName("Courier New");
+        //设置样式;
+        HSSFCellStyle style = workbook.createCellStyle();
+        //设置底边框;
+        style.setBorderBottom(BorderStyle.THIN);
+        //设置底边框颜色;
+        style.setBottomBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
+        //设置左边框;
+        style.setBorderLeft(BorderStyle.THIN);
+        //设置左边框颜色;
+        style.setLeftBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
+        //设置右边框;
+        style.setBorderRight(BorderStyle.THIN);
+        //设置右边框颜色;
+        style.setRightBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
+        //设置顶边框;
+        style.setBorderTop(BorderStyle.THIN);
+        //设置顶边框颜色;
+        style.setTopBorderColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
+        //在样式用应用设置的字体;
+        style.setFont(font);
+        //设置自动换行;
+        style.setWrapText(false);
+        //设置水平对齐的样式为居中对齐;
+        style.setAlignment(HorizontalAlignment.CENTER);
+        //设置垂直对齐的样式为居中对齐;
+        style.setVerticalAlignment(VerticalAlignment.CENTER);
+
+        style.setLocked(false);
+
+        return style;
+
+    }
+
+    public static int calculateLength(String str){
+        int m = 0;
+        char arr[] = str.toCharArray();
+        for (int i = 0; i < arr.length; i++) {
+            char c = arr[i];
+            // 中文字符(根据Unicode范围判断),中文字符长度为3
+            if ((c >= 0x0391 && c <= 0xFFE5)) {
+                m = m + 3;
+            } else
+            {
+                m = m + 2;
+            }
+        }
+        return m;
+    }
+
+    public static void main(String[] args) throws Exception {
+        String title = "测试一览表";
+        String[] rowsName = new String[]{"序号", "名称"};
+        List<Object[]> dataList = new ArrayList<Object[]>();
+        List<String> list = new ArrayList<>();
+        list.add("004a770124007922");
+        list.add("004a770124007922");
+        list.add("004a770124007922");
+        /*list.add("大厅");
+        list.add(null);
+        list.add("1");
+        list.add("大厅");
+        list.add("B2");
+        list.add("B2");
+        list.add("微型消防站消防栓门");*/
+        Object[] objs = null;
+        for (int i = 0; i < list.size(); i++) {
+            String str = list.get(i);
+            objs = new Object[rowsName.length];
+            objs[0] = i;
+            objs[1] = str;
+            dataList.add(objs);
+        }
+        ExcelUtil ex = new ExcelUtil(title, rowsName, dataList);
+        ex.export(null);
+    }
+
+}

+ 32 - 0
src/main/java/com/zoniot/ccrc/controller/ExternalApiController.java

@@ -0,0 +1,32 @@
+package com.zoniot.ccrc.controller;
+
+import com.zoniot.ccrc.commom.model.AjaxMessage;
+import com.zoniot.ccrc.commom.model.ResultStatus;
+import com.zoniot.ccrc.dao.SiteMapper;
+import com.zoniot.ccrc.dto.GridInfo;
+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.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/external")
+@Api(tags = "对外接口")
+public class ExternalApiController {
+
+    @Autowired
+    private SiteMapper siteMapper;
+
+    @PostMapping("getSiteCustomerIds")
+    @ApiOperation(value = "获取站点客户id")
+    public AjaxMessage<List<Integer>> getSiteCustomerIds() {
+        List<Integer> list = siteMapper.getSiteCustomerIds();
+
+        return new AjaxMessage<>(ResultStatus.OK, list);
+    }
+}
+
+

+ 54 - 0
src/main/java/com/zoniot/ccrc/controller/RealTimeMonitorController.java

@@ -0,0 +1,54 @@
+package com.zoniot.ccrc.controller;
+
+import com.alibaba.fastjson.JSON;
+import com.zoniot.ccrc.commom.model.AjaxMessage;
+import com.zoniot.ccrc.commom.model.ResultStatus;
+import com.zoniot.ccrc.dto.MapStatisticalDto;
+import com.zoniot.ccrc.service.StatAndAnalysisService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author wilian.peng
+ */
+@Api(tags = "物联云实时监测")
+@RestController
+@RequestMapping("/monitor/")
+public class RealTimeMonitorController {
+
+    @Autowired
+    StatAndAnalysisService statAndAnalysisService;
+
+    /**
+     * 地图统计查询
+     *
+     * @throws ParseException
+     */
+    @GetMapping("/mapStatistical/")
+    @ApiOperation(value = "实时监控地图统计查询")
+    public AjaxMessage<List<MapStatisticalDto>> mapStatistical(
+            @ApiParam(value = "系统id", required = false) @RequestParam(required = false) Integer sysId,
+            @ApiParam(value = "类型  1:省  2:市 3:区 4:小区 5:建筑", required = false, defaultValue = "0") @RequestParam(required = false, defaultValue = "0") Integer type,
+            @ApiParam(value = "northEast坐标", required = false) @RequestParam(required = false) String northEast,
+            @ApiParam(value = "southWest坐标", required = false) @RequestParam(required = false) String southWest,
+            @ApiParam(value = "省", required = false) @RequestParam(required = false) Integer province,
+            @ApiParam(value = "市", required = false) @RequestParam(required = false) Integer city,
+            @ApiParam(value = "区", required = false) @RequestParam(required = false) Integer region,
+            @ApiParam(value = "小区", required = false) @RequestParam(required = false) Integer community
+    ) {
+        AjaxMessage<List<MapStatisticalDto>> returnMsg = new AjaxMessage<List<MapStatisticalDto>>();
+        List<MapStatisticalDto> list = statAndAnalysisService.realTimeMapStatistical(sysId, type, northEast, southWest, province, city, region, community);
+        returnMsg.setMsg(ResultStatus.OK, list);
+        return returnMsg;
+    }
+
+}

+ 1 - 1
src/main/java/com/zoniot/ccrc/controller/system/BuildingController.java

@@ -67,7 +67,7 @@ public class BuildingController {
     @ResponseBody
     @GetMapping("/getBuildingPage")
     @ApiOperation(value = "查询建筑分页")
-    public AjaxMessage<Pagination<BuildingDto>> getBuildingPageV2(
+    public AjaxMessage<Pagination<BuildingDto>> getBuildingPage(
             @ApiParam(value = "系统id", required = false) @RequestParam(required = false) Integer sysId,
             @ApiParam(value = "建筑名称", required = false) @RequestParam(required = false) String buildingName,
             @ApiParam(value = "省", required = false) @RequestParam(required = false) Integer province,

+ 52 - 0
src/main/java/com/zoniot/ccrc/controller/system/DeviceController.java

@@ -3,6 +3,7 @@ package com.zoniot.ccrc.controller.system;
 import com.zoniot.ccrc.commom.model.AjaxMessage;
 import com.zoniot.ccrc.commom.model.Pagination;
 import com.zoniot.ccrc.commom.model.ResultStatus;
+import com.zoniot.ccrc.dto.BuildingSelectDto;
 import com.zoniot.ccrc.dto.DeviceDto;
 import com.zoniot.ccrc.service.DeviceService;
 import io.swagger.annotations.Api;
@@ -16,6 +17,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
 @Controller
 @RequestMapping("device")
 @Api(tags = "设备管理")
@@ -48,4 +52,52 @@ public class DeviceController {
         Pagination<DeviceDto> pageInfo = deviceService.pageList(sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus, sortColumn, sortOrder, pageNum, pageSize);
         return new AjaxMessage<>(ResultStatus.OK, pageInfo);
     }
+
+
+    @GetMapping("/getDeviceListExcel")
+    @ApiOperation(value = "导出设备列表excel")
+    public void getDeviceListExcel(
+            @ApiParam(value = "系统id", required = false) @RequestParam(required = false) Integer sysId,
+            @ApiParam(value = "设备类型id", required = false) @RequestParam(required = false) Integer deviceTypeId,
+            @ApiParam(value = "机构id", required = false) @RequestParam(required = false) Integer orgId,
+            @ApiParam(value = "省", required = false) @RequestParam(required = false) Integer province,
+            @ApiParam(value = "市", required = false) @RequestParam(required = false) Integer city,
+            @ApiParam(value = "区", required = false) @RequestParam(required = false) Integer region,
+            @ApiParam(value = "小区id", required = false) @RequestParam(required = false) Integer communityId,
+            @ApiParam(value = "建筑id", required = false) @RequestParam(required = false) Integer buildingId,
+            @ApiParam(value = "设备编号", required = false) @RequestParam(required = false) String deviceNo,
+            @ApiParam(value = "客户名称", required = false) @RequestParam(required = false) String clientName,
+            @ApiParam(value = "位置描述", required = false) @RequestParam(required = false) String locDesc,
+            @ApiParam(value = "设备状态  1:正常 2:故障 3:无 4: 预警 5:未启用", required = false) @RequestParam(required = false) Integer status,
+            @ApiParam(value = "阀门状态 0:关阀 1:开阀  2:无阀", required = false) @RequestParam(required = false) Integer valveStatus,
+            @ApiParam(value = "排序参数,对应列表字段", required = false) @RequestParam(required = false,defaultValue = "sd.date_create") String sortColumn,
+            @ApiParam(value = "排序方式,顺序:ASC  倒序:DESC", required = false) @RequestParam(required = false,defaultValue = "DESC") String sortOrder,
+            HttpServletResponse httpServletResponse
+    ) {
+        deviceService.getDeviceListExcel(sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus, sortColumn, sortOrder, httpServletResponse);
+
+    }
+
+
+    @ResponseBody
+    @GetMapping("/deviceAreaList")
+    @ApiOperation(value = "获取设备数量区域列表")
+    public AjaxMessage<List<BuildingSelectDto>> deviceAreaList(
+            @ApiParam(value = "系统id", required = false) @RequestParam(required = false) Integer sysId,
+            @ApiParam(value = "设备类型id", required = false) @RequestParam(required = false) Integer deviceTypeId,
+            @ApiParam(value = "机构id", required = false) @RequestParam(required = false) Integer orgId,
+            @ApiParam(value = "省", required = false) @RequestParam(required = false) Integer province,
+            @ApiParam(value = "市", required = false) @RequestParam(required = false) Integer city,
+            @ApiParam(value = "区", required = false) @RequestParam(required = false) Integer region,
+            @ApiParam(value = "小区id", required = false) @RequestParam(required = false) Integer communityId,
+            @ApiParam(value = "建筑id", required = false) @RequestParam(required = false) Integer buildingId,
+            @ApiParam(value = "设备编号", required = false) @RequestParam(required = false) String deviceNo,
+            @ApiParam(value = "客户名称", required = false) @RequestParam(required = false) String clientName,
+            @ApiParam(value = "位置描述", required = false) @RequestParam(required = false) String locDesc,
+            @ApiParam(value = "设备状态  1:正常 2:故障 3:无 4: 预警 5:未启用", required = false) @RequestParam(required = false) Integer status,
+            @ApiParam(value = "阀门状态 0:关阀 1:开阀  2:无阀", required = false) @RequestParam(required = false) Integer valveStatus
+    ) {
+        List<BuildingSelectDto> list = deviceService.deviceAreaList(sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus);
+        return new AjaxMessage<>(ResultStatus.OK, list);
+    }
 }

+ 2 - 0
src/main/java/com/zoniot/ccrc/dao/BuildingMapper.java

@@ -15,6 +15,8 @@ public interface BuildingMapper {
 
     int insertSelective(@Param("building") Building building);
 
+    int replaceSelective(@Param("building") Building building);
+
     int insertList(@Param("buildings") List<Building> buildings);
 
     int updateByPrimaryKeySelective(@Param("building") Building building);

+ 2 - 0
src/main/java/com/zoniot/ccrc/dao/CommunityMapper.java

@@ -13,6 +13,8 @@ public interface CommunityMapper {
 
     int insertSelective(@Param("community") Community community);
 
+    int replaceSelective(@Param("community") Community community);
+
     int insertList(@Param("communitys") List<Community> communitys);
 
     int updateByPrimaryKeySelective(@Param("community") Community community);

+ 60 - 0
src/main/java/com/zoniot/ccrc/dao/DeviceMapper.java

@@ -1,7 +1,12 @@
 package com.zoniot.ccrc.dao;
 
+import com.zoniot.ccrc.dto.BuildingInfoListDto;
+import com.zoniot.ccrc.dto.BuildingSelectInfoDto;
+import com.zoniot.ccrc.dto.DeviceDto;
 import com.zoniot.ccrc.entity.Device;
+
 import java.util.List;
+
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -9,11 +14,66 @@ import org.apache.ibatis.annotations.Param;
 public interface DeviceMapper {
     int insertSelective(Device record);
 
+    int replaceSelective(Device record);
+
     int updateByPrimaryKeySelective(Device record);
 
     int updateBatch(List<Device> list);
 
     int batchInsert(@Param("list") List<Device> list);
 
+    List<DeviceDto> getList(
+            @Param("siteId") Integer siteId,
+            @Param("userId") Integer userId,
+            @Param("sysId") Integer sysId,
+            @Param("deviceTypeId") Integer deviceTypeId,
+            @Param("orgId") Integer orgId,
+            @Param("province") Integer province,
+            @Param("city") Integer city,
+            @Param("region") Integer region,
+            @Param("communityId") Integer communityId,
+            @Param("buildingId") Integer buildingId,
+            @Param("deviceNo") String deviceNo,
+            @Param("clientName") String clientName,
+            @Param("locDesc") String locDesc,
+            @Param("status") Integer status,
+            @Param("valveStatus") Integer valveStatus,
+            @Param("communityIds") List<Integer> communityIds,
+            @Param("sortColumn") String sortColumn,
+            @Param("sortOrder") String sortOrder);
+
+    List<BuildingSelectInfoDto> deviceAreaList(
+            @Param("siteId") Integer siteId,
+            @Param("userId") Integer userId,
+            @Param("sysId") Integer sysId,
+            @Param("deviceTypeId") Integer deviceTypeId,
+            @Param("orgId") Integer orgId,
+            @Param("province") Integer province,
+            @Param("city") Integer city,
+            @Param("region") Integer region,
+            @Param("communityId") Integer communityId,
+            @Param("buildingId") Integer buildingId,
+            @Param("deviceNo") String deviceNo,
+            @Param("clientName") String clientName,
+            @Param("locDesc") String locDesc,
+            @Param("status") Integer status,
+            @Param("valveStatus") Integer valveStatus,
+            @Param("communityIds") List<Integer> communityIds);
+
     Long getDeviceIdByUserNumber(Integer id);
+
+    List<BuildingInfoListDto> getBuildingStatistics(
+            @Param("siteId") Integer siteId,
+            @Param("sysId") Integer sysId,
+            @Param("userId") Integer userId,
+            @Param("communityIds") List<Integer> communityIds,
+            @Param("province") Integer province,
+            @Param("city") Integer city,
+            @Param("region") Integer region,
+            @Param("community") Integer community,
+            @Param("type") Integer type,
+            @Param("longitudeMin") Double longitudeMin,
+            @Param("longitudeMax") Double longitudeMax,
+            @Param("latitudeMin") Double latitudeMin,
+            @Param("latitudeMax") Double latitudeMax);
 }

+ 2 - 0
src/main/java/com/zoniot/ccrc/dao/SiteMapper.java

@@ -26,4 +26,6 @@ public interface SiteMapper {
     Site findById(@Param("siteId") Integer siteId);
 
     int findByCustomerIdUnique(@Param("id") Integer id, @Param("customerId") Integer customerId);
+
+    List<Integer> getSiteCustomerIds();
 }

+ 75 - 0
src/main/java/com/zoniot/ccrc/dto/BuildingInfoListDto.java

@@ -0,0 +1,75 @@
+package com.zoniot.ccrc.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class BuildingInfoListDto implements Serializable {
+
+    private static final long serialVersionUID = -7349239278001071116L;
+
+    @ApiModelProperty(value = "建筑id", position = 1)
+    private Integer buildingId;
+
+    @ApiModelProperty(value = "建筑名称", position = 2)
+    private String buildingName;
+
+    @ApiModelProperty(value = "建筑地址", position = 3)
+    private String address;
+
+    @ApiModelProperty(value = "消防安全责任人", position = 4)
+    private String fireRespName;
+
+    @ApiModelProperty(value = "消防安全责任人电话", position = 5)
+    private String fireRespPhone;
+
+    @ApiModelProperty(value = "正常数", position = 8)
+    private Integer normalCount = 0;
+
+    @ApiModelProperty(value = "告警数", position = 6)
+    private Integer alarmCount = 0;
+
+    @ApiModelProperty(value = "故障数", position = 7)
+    private Integer faultCount = 0;
+
+    @ApiModelProperty(value = "预警设备数", position = 8)
+    private Integer offlineCount = 0;
+
+    @ApiModelProperty(value = "未启用设备数", position = 8)
+    private Integer deviceUnusedCount = 0;
+
+    @ApiModelProperty(value = "设备数", position = 8)
+    private Integer deviceCount = 0;
+
+    @ApiModelProperty(value = "省", position = 9)
+    private String provinceName;
+
+    @ApiModelProperty(value = "市", position = 10)
+    private String cityName;
+
+    @ApiModelProperty(value = "区", position = 11)
+    private String regionName;
+
+    @ApiModelProperty(value = "小区", position = 12)
+    private String communityName;
+
+    @ApiModelProperty(value = "经度", position = 18)
+    private String longitude;
+
+    @ApiModelProperty(value = "纬度", position = 19)
+    private String latitude;
+
+    @ApiModelProperty(value = "省", position = 20)
+    private Integer province;
+
+    @ApiModelProperty(value = "市", position = 21)
+    private Integer city;
+
+    @ApiModelProperty(value = "区", position = 22)
+    private Integer region;
+
+    @ApiModelProperty(value = "小区", position = 23)
+    private Integer community;
+}

+ 37 - 0
src/main/java/com/zoniot/ccrc/dto/DeviceDto.java

@@ -1,8 +1,45 @@
 package com.zoniot.ccrc.dto;
 
 import com.zoniot.ccrc.entity.Device;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 @Data
 public class DeviceDto extends Device {
+    @ApiModelProperty(value = "系列", position = 100)
+    private String equipmentType;
+
+    @ApiModelProperty(value = "型号", position = 101)
+    private String model;
+
+    @ApiModelProperty(value = "厂商名称", position = 102)
+    private String manufacturerName;
+
+    @ApiModelProperty(value = "建筑名称", position = 103)
+    private String buildingName;
+
+    @ApiModelProperty(value = "小区名称", position = 110)
+    private String communityName;
+
+    @ApiModelProperty(value = "机构名称", position = 110)
+    private String orgName;
+
+    @ApiModelProperty(value="是否有无阀门 0:无 1:有",position = 125)
+    private Integer isValve;
+
+    @ApiModelProperty(value = "客户编号", position = 110)
+    private String customerNo;
+
+    @ApiModelProperty(value = "客户手机", position = 110)
+    private String customerPhone;
+
+    @ApiModelProperty(value = "客户名称", position = 110)
+    private String customerName;
+
+    @ApiModelProperty(value = "标签", position = 110)
+    private String label;
+
+    @ApiModelProperty(value = "用户名称", position = 110)
+    private String username;
+
 }

+ 64 - 0
src/main/java/com/zoniot/ccrc/dto/MapStatisticalDto.java

@@ -0,0 +1,64 @@
+package com.zoniot.ccrc.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel("地图统计")
+public class MapStatisticalDto {
+
+    @ApiModelProperty(value = "id", position = 0)
+    private Integer id;
+
+    @ApiModelProperty(value = "名称", position = 1)
+    private String name;
+
+    @ApiModelProperty(value = "建筑id", position = 2)
+    private Integer buildingId;
+
+    @ApiModelProperty(value = "正常数", position = 5)
+    private Integer normalCount;
+
+    @ApiModelProperty(value = "告警数", position = 3)
+    private Integer alarmCount;
+
+    @ApiModelProperty(value = "故障数", position = 4)
+    private Integer faultCount;
+
+    @ApiModelProperty(value = "预警设备数", position = 8)
+    private Integer offlineCount;
+
+    @ApiModelProperty(value = "未启用设备数", position = 8)
+    private Integer unusedCount;
+
+    @ApiModelProperty(value = "设备数", position = 8)
+    private Integer deviceCount;
+
+    @ApiModelProperty(value = "经度", position = 7)
+    private String longitude;
+
+    @ApiModelProperty(value = "纬度", position = 8)
+    private String latitude;
+
+    @ApiModelProperty(value = "code", position = 9)
+    private String code;
+
+    @ApiModelProperty(value = "建筑数", position = 10)
+    private Integer buildingCount;
+
+    @ApiModelProperty(value = "建筑地址", position = 11)
+    private String address;
+
+    @ApiModelProperty(value = "省", position = 101)
+    private Integer province;
+
+    @ApiModelProperty(value = "市", position = 102)
+    private Integer city;
+
+    @ApiModelProperty(value = "区", position = 103)
+    private Integer region;
+
+    @ApiModelProperty(value = "小区", position = 104)
+    private Integer community;
+}

+ 9 - 2
src/main/java/com/zoniot/ccrc/entity/Building.java

@@ -10,6 +10,7 @@ import org.springframework.format.annotation.DateTimeFormat;
 import java.io.Serializable;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.util.Date;
 
 @Data
 @ToString
@@ -39,19 +40,25 @@ public class Building implements Serializable {
     @ApiModelProperty(value = "区", position = 11)
     private Integer region;
 
+    @ApiModelProperty(value = "经度", position = 18)
+    private Double longitude;
+
+    @ApiModelProperty(value = "纬度", position = 19)
+    private Double latitude;
+
     @ApiModelProperty(value = "状态", hidden = true, position = 49)
     private Integer status;
 
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty(value = "创建时间", position = 50, hidden = true)
-    private LocalDateTime createDate = LocalDateTime.now();
+    private Date createDate;
 
     @ApiModelProperty(value = "创建人", position = 51, hidden = true)
     private String createBy = "system";
 
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty(value = "更新时间", position = 52, hidden = true)
-    private LocalDateTime updateDate = LocalDateTime.now();
+    private Date updateDate;
 
     @ApiModelProperty(value = "更新用户", position = 53, hidden = true)
     private String updateBy = "system";

+ 3 - 2
src/main/java/com/zoniot/ccrc/entity/Community.java

@@ -6,6 +6,7 @@ import lombok.Data;
 
 import java.io.Serializable;
 import java.time.LocalDateTime;
+import java.util.Date;
 
 @ApiModel(value="小区")
 @Data
@@ -53,10 +54,10 @@ public class Community implements Serializable {
     private Integer status;
 
     @ApiModelProperty(value="创建时间", hidden = true)
-    private LocalDateTime dateCreate;
+    private Date dateCreate;
 
     @ApiModelProperty(value="更新时间", hidden = true)
-    private LocalDateTime dateUpdate;
+    private Date dateUpdate;
 
     @ApiModelProperty(value="创建人", hidden = true)
     private String createBy;

+ 8 - 6
src/main/java/com/zoniot/ccrc/entity/Device.java

@@ -3,6 +3,8 @@ package com.zoniot.ccrc.entity;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import java.time.LocalDateTime;
+import java.util.Date;
+
 import lombok.Data;
 
 @ApiModel(value="设备")
@@ -45,29 +47,29 @@ public class Device {
     private String locDesc;
 
     @ApiModelProperty(value="水表读数")
-    private Long meterReading;
+    private Double meterReading;
 
     @ApiModelProperty(value="阀门状态 0:关阀 1:开阀 2:异常")
     private Integer valveStatus;
 
     @ApiModelProperty(value="设备状态  1:正常 2:故障 3:无 4: 预警 5:未启用")
-    private String deviceStatus;
+    private Integer deviceStatus;
 
     @ApiModelProperty(value="最后上报时间")
-    private LocalDateTime lastReceiveTime;
+    private Date lastReceiveTime;
 
     @ApiModelProperty(value="状态")
-    private Boolean status;
+    private Integer status;
 
     @ApiModelProperty(value="创建人")
     private String createBy;
 
     @ApiModelProperty(value="创建时间")
-    private LocalDateTime dateCreate;
+    private Date dateCreate;
 
     @ApiModelProperty(value="更新人")
     private String updateBy;
 
     @ApiModelProperty(value="更新时间")
-    private LocalDateTime dateUpdate;
+    private Date dateUpdate;
 }

+ 41 - 0
src/main/java/com/zoniot/ccrc/rabbit/SyncBuildingReceiver.java

@@ -0,0 +1,41 @@
+package com.zoniot.ccrc.rabbit;
+
+import com.alibaba.fastjson.JSON;
+import com.rabbitmq.client.Channel;
+import com.zoniot.ccrc.commom.model.BuildingData;
+import com.zoniot.ccrc.service.BuildingService;
+import com.zoniot.ccrc.service.DeviceService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+
+@Component
+@Slf4j
+public class SyncBuildingReceiver {
+
+    @Autowired
+    private BuildingService buildingService;
+
+
+    @RabbitListener(queues = {"${spring.rabbitmq.building.queue}"},containerFactory = "customContainerFactory")
+    public void receiver(Channel channel, Message message) throws IOException {
+        //String str = new String(body);
+        try {
+            String msg = new String(message.getBody());
+            log.info("-----SyncBuildingReceiver msg-----,"  +msg);
+            BuildingData buildingData = JSON.parseObject(msg, BuildingData.class);
+            // 1,处理消息
+            buildingService.syncBuilding(buildingData);
+
+            // 2,确认消息消费成功 
+            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+        } catch (Exception e) {
+            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
+            log.error("consumer message error !",e);
+        }
+    }
+}

+ 40 - 0
src/main/java/com/zoniot/ccrc/rabbit/SyncCommunityReceiver.java

@@ -0,0 +1,40 @@
+package com.zoniot.ccrc.rabbit;
+
+import com.alibaba.fastjson.JSON;
+import com.rabbitmq.client.Channel;
+import com.zoniot.ccrc.commom.model.CommunityData;
+import com.zoniot.ccrc.service.CommunityService;
+import com.zoniot.ccrc.service.DeviceService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+
+@Component
+@Slf4j
+public class SyncCommunityReceiver {
+
+    @Autowired
+    private CommunityService communityService;
+
+
+    @RabbitListener(queues = {"${spring.rabbitmq.community.queue}"},containerFactory = "customContainerFactory")
+    public void receiver(Channel channel, Message message) throws IOException {
+        try {
+            String msg = new String(message.getBody());
+            log.info("-----SyncCommunityReceiver msg-----,"  +msg);
+            CommunityData communityData = JSON.parseObject(msg, CommunityData.class);
+            // 1,处理消息
+            communityService.syncCommunity(communityData);
+
+            // 2,确认消息消费成功 
+            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+        } catch (Exception e) {
+            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
+            log.error("consumer message error !",e);
+        }
+    }
+}

+ 39 - 0
src/main/java/com/zoniot/ccrc/rabbit/SyncDeviceReceiver.java

@@ -0,0 +1,39 @@
+package com.zoniot.ccrc.rabbit;
+
+import com.alibaba.fastjson.JSON;
+import com.rabbitmq.client.Channel;
+import com.zoniot.ccrc.commom.model.DeviceData;
+import com.zoniot.ccrc.service.DeviceService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+
+@Component
+@Slf4j
+public class SyncDeviceReceiver {
+
+    @Autowired
+    private DeviceService deviceService;
+
+
+    @RabbitListener(queues = {"${spring.rabbitmq.device.queue}"},containerFactory = "customContainerFactory")
+    public void receiver(Channel channel, Message message) throws IOException {
+        try {
+            String msg = new String(message.getBody());
+            log.info("-----SyncDeviceReceiver msg-----,"  +msg);
+            DeviceData deviceData = JSON.parseObject(msg, DeviceData.class);
+            // 1,处理消息
+            deviceService.syncDevice(deviceData);
+
+            // 2,确认消息消费成功 
+            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+        } catch (Exception e) {
+            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
+            log.error("consumer message error !",e);
+        }
+    }
+}

+ 2 - 1
src/main/java/com/zoniot/ccrc/security/WebSecurityConfig.java

@@ -82,7 +82,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers( "/validateCode/image", "/validateCode/test")
                 .antMatchers("/statics/**", "/sms/send/**","/sms/v2/send/**","/file/**")
                 .antMatchers("/druid/**")
-                .antMatchers("/integration/user/save","/integration/user/del");
+                .antMatchers("/integration/user/save","/integration/user/del")
+                .antMatchers("/external/getSiteCustomerIds");
 
     }
 

+ 2 - 1
src/main/java/com/zoniot/ccrc/security/mobile/MobileLoginAuthenticationProvider.java

@@ -42,7 +42,8 @@ public class MobileLoginAuthenticationProvider implements AuthenticationProvider
 
     @Override
     public boolean supports(Class<?> authentication) {
-        return MobileLoginAuthenticationToken.class.isAssignableFrom(authentication);
+        //return MobileLoginAuthenticationToken.class.isAssignableFrom(authentication);
+        return false;
     }
 
     public void setPasswordEncoder(PasswordEncoder passwordEncoder) {

+ 2 - 0
src/main/java/com/zoniot/ccrc/service/BuildingService.java

@@ -1,5 +1,6 @@
 package com.zoniot.ccrc.service;
 
+import com.zoniot.ccrc.commom.model.BuildingData;
 import com.zoniot.ccrc.commom.model.Pagination;
 import com.zoniot.ccrc.dto.BuildingDto;
 import com.zoniot.ccrc.dto.BuildingSelectDto;
@@ -39,4 +40,5 @@ public interface BuildingService{
     List<BuildingSelectDto> areaList(List<BuildingSelectInfoDto> buildingList);
 
 
+    void syncBuilding(BuildingData buildingData);
 }

+ 3 - 0
src/main/java/com/zoniot/ccrc/service/CommunityService.java

@@ -1,5 +1,6 @@
 package com.zoniot.ccrc.service;
 
+import com.zoniot.ccrc.commom.model.CommunityData;
 import com.zoniot.ccrc.commom.model.Pagination;
 import com.zoniot.ccrc.dto.BuildingSelectDto;
 import com.zoniot.ccrc.dto.CommunityDto;
@@ -56,4 +57,6 @@ public interface CommunityService {
 
 
     List<Community> getOrgCommunity(Integer orgId);
+
+    void syncCommunity(CommunityData communityData);
 }

+ 11 - 0
src/main/java/com/zoniot/ccrc/service/DeviceService.java

@@ -2,9 +2,14 @@ package com.zoniot.ccrc.service;
 
 import java.util.List;
 
+import com.zoniot.ccrc.commom.model.DeviceData;
 import com.zoniot.ccrc.commom.model.Pagination;
+import com.zoniot.ccrc.dto.BuildingSelectDto;
 import com.zoniot.ccrc.dto.DeviceDto;
 import com.zoniot.ccrc.entity.Device;
+
+import javax.servlet.http.HttpServletResponse;
+
 public interface DeviceService{
 
 
@@ -17,4 +22,10 @@ public interface DeviceService{
     int batchInsert(List<Device> list);
 
     Pagination<DeviceDto> pageList(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus, String sortColumn, String sortOrder, int pageNum, int pageSize);
+
+    void getDeviceListExcel(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus, String sortColumn, String sortOrder, HttpServletResponse httpServletResponse);
+
+    List<BuildingSelectDto> deviceAreaList(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus);
+
+    void syncDevice(DeviceData deviceData);
 }

+ 12 - 0
src/main/java/com/zoniot/ccrc/service/StatAndAnalysisService.java

@@ -0,0 +1,12 @@
+package com.zoniot.ccrc.service;
+
+import com.zoniot.ccrc.dto.BuildingInfoListDto;
+import com.zoniot.ccrc.dto.MapStatisticalDto;
+
+import java.util.List;
+
+public interface StatAndAnalysisService {
+    List<MapStatisticalDto> realTimeMapStatistical(Integer sysId, Integer type, String northEast, String southWest, Integer province, Integer city, Integer region, Integer community);
+
+    List<MapStatisticalDto> mapStatistical(Integer type, List<BuildingInfoListDto> buildingInfoListDtoList);
+}

+ 29 - 6
src/main/java/com/zoniot/ccrc/service/impl/BuildingServiceImpl.java

@@ -3,6 +3,7 @@ package com.zoniot.ccrc.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.github.pagehelper.PageHelper;
 import com.zoniot.ccrc.commom.exception.ServiceException;
+import com.zoniot.ccrc.commom.model.BuildingData;
 import com.zoniot.ccrc.commom.model.Pagination;
 import com.zoniot.ccrc.commom.utils.TreeUtil;
 import com.zoniot.ccrc.commom.utils.UserUtil;
@@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
+import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -55,18 +57,18 @@ public class BuildingServiceImpl implements BuildingService {
     @Override
     public int insert(Building building) {
         building.setCreateBy("system");
-        building.setCreateDate(LocalDateTime.now());
+        building.setCreateDate(new Date());
         building.setUpdateBy("system");
-        building.setUpdateDate(LocalDateTime.now());
+        building.setUpdateDate(new Date());
         return buildingMapper.insert(building);
     }
 
     @Override
     public int insertSelective(Building building) {
         building.setCreateBy(UserUtil.getCurrentUser().getUsername());
-        building.setCreateDate(LocalDateTime.now());
+        building.setCreateDate(new Date());
         building.setUpdateBy(UserUtil.getCurrentUser().getUsername());
-        building.setUpdateDate(LocalDateTime.now());
+        building.setUpdateDate(new Date());
         return buildingMapper.insertSelective(building);
     }
 
@@ -78,7 +80,7 @@ public class BuildingServiceImpl implements BuildingService {
     @Override
     public int updateByPrimaryKeySelective(Building building) {
         building.setUpdateBy(UserUtil.getCurrentUser().getUsername());
-        building.setUpdateDate(LocalDateTime.now());
+        building.setUpdateDate(new Date());
         return buildingMapper.updateByPrimaryKeySelective(building);
     }
 
@@ -318,7 +320,28 @@ public class BuildingServiceImpl implements BuildingService {
     }
 
 
+    @Override
+    public void syncBuilding(BuildingData buildingData) {
 
+        Integer siteId = 1;
 
-
+        Building building = new Building();
+        building.setId(buildingData.getId());
+        building.setSiteId(siteId);
+        building.setCommunityId(buildingData.getCommunityId());
+        building.setName(buildingData.getName());
+        building.setAddress(buildingData.getAddress());
+        building.setProvince(buildingData.getProvince());
+        building.setCity(buildingData.getCity());
+        building.setRegion(buildingData.getRegion());
+        building.setLongitude(buildingData.getLongitude());
+        building.setLatitude(buildingData.getLatitude());
+        building.setStatus(buildingData.getStatus());
+        building.setCreateDate(buildingData.getCreateDate());
+        building.setCreateBy("system");
+        building.setUpdateDate(buildingData.getUpdateDate());
+        building.setUpdateBy("system");
+        log.info("building {}", JSON.toJSONString(building));
+        buildingMapper.replaceSelective(building);
+    }
 }

+ 35 - 5
src/main/java/com/zoniot/ccrc/service/impl/CommunityServiceImpl.java

@@ -1,7 +1,9 @@
 package com.zoniot.ccrc.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.github.pagehelper.PageHelper;
 import com.zoniot.ccrc.commom.exception.ServiceException;
+import com.zoniot.ccrc.commom.model.CommunityData;
 import com.zoniot.ccrc.commom.model.Pagination;
 import com.zoniot.ccrc.commom.utils.TreeUtil;
 import com.zoniot.ccrc.commom.utils.UserUtil;
@@ -22,6 +24,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
@@ -77,18 +80,18 @@ public class CommunityServiceImpl implements CommunityService {
     @Override
     public int insert(Community community){
         community.setCreateBy("system");
-        community.setDateCreate(LocalDateTime.now());
+        community.setDateCreate(new Date());
         community.setUpdateBy("system");
-        community.setDateUpdate(LocalDateTime.now());
+        community.setDateUpdate(new Date());
         return communityMapper.insert(community);
     }
 
     @Override
     public int insertSelective(Community community){
         community.setCreateBy(UserUtil.getCurrentUser().getUsername());
-        community.setDateCreate(LocalDateTime.now());
+        community.setDateCreate(new Date());
         community.setUpdateBy(UserUtil.getCurrentUser().getUsername());
-        community.setDateUpdate(LocalDateTime.now());
+        community.setDateUpdate(new Date());
         return communityMapper.insertSelective(community);
     }
 
@@ -100,7 +103,7 @@ public class CommunityServiceImpl implements CommunityService {
     @Override
     public int updateByPrimaryKeySelective(Community community){
         community.setUpdateBy("system");
-        community.setDateUpdate(LocalDateTime.now());
+        community.setDateUpdate(new Date());
         return communityMapper.updateByPrimaryKeySelective(community);
     }
 
@@ -282,4 +285,31 @@ public class CommunityServiceImpl implements CommunityService {
 
         return communityMapper.getOrgCommunity(orgId);
     }
+
+    @Override
+    public void syncCommunity(CommunityData communityData) {
+        Integer siteId = 1;
+        Community community = new Community();
+        community.setId(communityData.getId());
+        community.setSiteId(siteId);
+        community.setName(communityData.getName());
+        community.setCode(communityData.getCode());
+        community.setCustomerId(communityData.getCustomerId());
+        community.setProvince(communityData.getProvince());
+        community.setCity(communityData.getCity());
+        community.setRegion(communityData.getRegion());
+        community.setLongitude(communityData.getLongitude());
+        community.setLatitude(communityData.getLatitude());
+        community.setDistrictId(communityData.getDistrictId());
+        community.setAddress(communityData.getAddress());
+        community.setRemark(communityData.getRemark());
+        community.setStatus(communityData.getStatus());
+        community.setDateCreate(communityData.getDateCreate());
+        community.setDateUpdate(communityData.getDateUpdate());
+        community.setCreateBy("system");
+        community.setUpdateBy("system");
+        log.info("community {}", JSON.toJSONString(community));
+        communityMapper.replaceSelective(community);
+
+    }
 }

+ 114 - 1
src/main/java/com/zoniot/ccrc/service/impl/DeviceServiceImpl.java

@@ -1,18 +1,38 @@
 package com.zoniot.ccrc.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.github.pagehelper.PageHelper;
+import com.zoniot.ccrc.commom.exception.ServiceException;
+import com.zoniot.ccrc.commom.model.DeviceData;
 import com.zoniot.ccrc.commom.model.Pagination;
+import com.zoniot.ccrc.commom.utils.ExcelUtil;
+import com.zoniot.ccrc.commom.utils.UserUtil;
+import com.zoniot.ccrc.dto.BuildingSelectDto;
+import com.zoniot.ccrc.dto.BuildingSelectInfoDto;
 import com.zoniot.ccrc.dto.DeviceDto;
+import com.zoniot.ccrc.dto.LoginUser;
+import com.zoniot.ccrc.service.BuildingService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.text.SimpleDateFormat;
 import java.util.List;
 import com.zoniot.ccrc.entity.Device;
 import com.zoniot.ccrc.dao.DeviceMapper;
 import com.zoniot.ccrc.service.DeviceService;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+@Slf4j
 @Service
 public class DeviceServiceImpl implements DeviceService{
 
     @Resource
     private DeviceMapper deviceMapper;
+    @Autowired
+    private BuildingService buildingService;
 
     @Override
     public int insertSelective(Device record) {
@@ -36,6 +56,99 @@ public class DeviceServiceImpl implements DeviceService{
 
     @Override
     public Pagination<DeviceDto> pageList(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus, String sortColumn, String sortOrder, int pageNum, int pageSize) {
-        return null;
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        PageHelper.startPage(pageNum,pageSize);
+        List<DeviceDto> list = deviceMapper.getList(loginUser.getSiteId(),null,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,null,sortColumn,sortOrder);
+        return new Pagination<>(list);
+    }
+
+    @Override
+    public void getDeviceListExcel(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus, String sortColumn, String sortOrder, HttpServletResponse httpServletResponse) {
+        String title = "历史数据";
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        List<DeviceDto> list = deviceMapper.getList(loginUser.getSiteId(),null,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,null,sortColumn,sortOrder);
+
+        //水表档案号、水表电子号、设备状态、当前读数、机构、客户编号、客户名称、手机号、标签、建筑、安装地址、网格员
+        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        //DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        String[] rowsName = new String[]{"序号", "水表档案号", "水表电子号", "设备状态", "当前读数", "机构", "客户编号", "客户名称", "手机号", "标签","建筑","安装地址","网格员"};
+
+        List<Object[]> dataList = newArrayList();
+        Object[] objs = null;
+        for (int i = 0; i < list.size(); i++) {
+            DeviceDto data = list.get(i);
+            objs = new Object[rowsName.length];
+            objs[0] = i;
+            objs[1] = data.getFileNo();
+            objs[2] = data.getMeterNo();
+            objs[3] = getDeviceStatusName(data.getDeviceStatus());
+            objs[4] = data.getMeterReading();
+            objs[5] = data.getOrgName();
+            objs[6] = data.getCustomerNo();
+            objs[7] = data.getCustomerName();
+            objs[8] = data.getCustomerPhone();
+            objs[9] = data.getLabel();
+            objs[10] = data.getBuildingName();
+            objs[11] = data.getLocDesc();
+            objs[12] = data.getUsername();
+
+
+            dataList.add(objs);
+        }
+        ExcelUtil excelUtil = new ExcelUtil(title, rowsName, dataList);
+        try {
+            excelUtil.export(httpServletResponse);
+        } catch (Exception e) {
+            throw new ServiceException(-900, "导出异常");
+        }
+    }
+
+    private String getDeviceStatusName(Integer deviceStatus){
+        //1:正常 2:故障 3:无 4: 预警 5:未启用
+        if (deviceStatus == 1) return  "正常";
+        if (deviceStatus == 2) return  "故障";
+        if (deviceStatus == 4) return  "预警";
+        if (deviceStatus == 5) return  "未启用";
+        return "";
+    }
+
+
+    @Override
+    public List<BuildingSelectDto> deviceAreaList(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus) {
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        //查询用户数据项下的建筑列表
+        List<BuildingSelectInfoDto> list = deviceMapper.deviceAreaList(loginUser.getSiteId(),null,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,null);
+        return buildingService.areaList(list);
+    }
+
+    @Override
+    public void syncDevice(DeviceData deviceData) {
+        // TODO: 2021/3/18  查询站点
+        Integer siteId = 1;
+
+        Device device = new Device();
+        device.setId(deviceData.getId());
+        device.setDeviceNo(deviceData.getDeviceNo());
+        device.setMeterNo(deviceData.getMeterNo());
+        device.setFileNo(deviceData.getFileNo());
+        device.setSealNo(deviceData.getSealNo());
+        device.setSiteId(siteId);
+        device.setSysId(deviceData.getSysId());
+        device.setDeviceTypeId(deviceData.getDeviceTypeId());
+        device.setManufacturerId(deviceData.getManufacturerId());
+        device.setBuildingId(deviceData.getBuildingId());
+        device.setCommunityId(deviceData.getCommunityId());
+        device.setLocDesc(deviceData.getLocDesc());
+        device.setMeterReading(deviceData.getMeterReading());
+        device.setValveStatus(deviceData.getValveStatus());
+        device.setDeviceStatus(deviceData.getValveStatus());
+        device.setLastReceiveTime(deviceData.getLastReceiveTime());
+        device.setStatus(deviceData.getStatus());
+        device.setCreateBy("system");
+        device.setDateCreate(deviceData.getDateCreate());
+        device.setUpdateBy("system");
+        device.setDateUpdate(deviceData.getDateUpdate());
+        log.info("device {}", JSON.toJSONString(device));
+        deviceMapper.replaceSelective(device);
     }
 }

+ 312 - 0
src/main/java/com/zoniot/ccrc/service/impl/StatAndAnalysisServiceImpl.java

@@ -0,0 +1,312 @@
+package com.zoniot.ccrc.service.impl;
+
+import com.zoniot.ccrc.commom.utils.UserUtil;
+import com.zoniot.ccrc.commom.utils.Util;
+import com.zoniot.ccrc.dao.AreaMapper;
+import com.zoniot.ccrc.dao.DeviceMapper;
+import com.zoniot.ccrc.dto.BuildingInfoListDto;
+import com.zoniot.ccrc.dto.LoginUser;
+import com.zoniot.ccrc.dto.MapStatisticalDto;
+import com.zoniot.ccrc.entity.Area;
+import com.zoniot.ccrc.service.StatAndAnalysisService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+@Slf4j
+@Service
+public class StatAndAnalysisServiceImpl implements StatAndAnalysisService {
+
+    @Resource
+    private AreaMapper areaMapper;
+    @Resource
+    private DeviceMapper deviceMapper;
+
+    @Override
+    public List<MapStatisticalDto> realTimeMapStatistical(Integer sysId, Integer type, String northEast, String southWest, Integer province, Integer city, Integer region, Integer community) {
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        Double longitudeMin = 0d;
+        Double longitudeMax = 0d;
+
+        Double latitudeMin = 0d;
+        Double latitudeMax = 0d;
+        if (northEast != null && southWest != null) {
+            String[] northEastStr = StringUtils.split(northEast, ",");
+            String[] southWestStr = StringUtils.split(southWest, ",");
+
+            longitudeMin = Double.valueOf(southWestStr[0]);
+            longitudeMax = Double.valueOf(northEastStr[0]);
+
+            latitudeMin = Double.valueOf(southWestStr[1]);
+            latitudeMax = Double.valueOf(northEastStr[1]);
+        }
+        //设置当前站点
+        List<Integer> siteList = UserUtil.getUserCurrentSiteIds();
+
+        List<BuildingInfoListDto> buildingInfoListDtoList = deviceMapper.getBuildingStatistics(loginUser.getSiteId(),sysId, null, null, province, city, region,  community, type, longitudeMin, longitudeMax, latitudeMin, latitudeMax);
+        return this.mapStatistical(type, buildingInfoListDtoList);
+    }
+
+    @Override
+    @Transactional
+    public List<MapStatisticalDto> mapStatistical(Integer type, List<BuildingInfoListDto> buildingInfoListDtoList) {
+
+        List<MapStatisticalDto> list = newArrayList();
+        List<Integer> provinceIds = newArrayList();
+        List<Integer> cityIds = newArrayList();
+        List<Integer> regionIds = newArrayList();
+        List<Integer> communityIds = newArrayList();
+        if (buildingInfoListDtoList != null && buildingInfoListDtoList.size() > 0) {
+            for (BuildingInfoListDto buildingInfoListDto : buildingInfoListDtoList) {
+                if (buildingInfoListDto.getProvince() != null) provinceIds.add(buildingInfoListDto.getProvince());
+                if (buildingInfoListDto.getCity() != null) cityIds.add(buildingInfoListDto.getCity());
+                if (buildingInfoListDto.getRegion() != null) regionIds.add(buildingInfoListDto.getRegion());
+                if (buildingInfoListDto.getCommunity() != null) communityIds.add(buildingInfoListDto.getCommunity());
+            }
+        }else {
+            return list;
+        }
+
+        //去重
+        provinceIds = Util.removeDuplicate(provinceIds);
+        cityIds = Util.removeDuplicate(cityIds);
+        regionIds = Util.removeDuplicate(regionIds);
+        communityIds = Util.removeDuplicate(communityIds);
+
+        if (type == 1) {
+            //省
+            if (provinceIds.size() > 0) {
+                List<Area> areaList = areaMapper.findByIds(provinceIds);
+                for (Area area : areaList) {
+                    list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 1));
+                }
+            }
+        } else if (type == 2) {
+            //市
+            List<Area> areaList = areaMapper.findByIds(cityIds);
+            for (Area area : areaList) {
+                list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 2));
+            }
+        } else if (type == 3) {
+            //区
+            if (regionIds.size() > 0) {
+                List<Area> areaList = areaMapper.findByIds(regionIds);
+                for (Area area : areaList) {
+                    list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 3));
+                }
+            }
+
+        } else if (type == 4) {
+            //小区
+            if(communityIds.size() > 0){
+                for (Integer id : communityIds) {
+                    list.add(this.countAreaDeviceNum(buildingInfoListDtoList, id, null, null, 4));
+                }
+            }else {
+                if (buildingInfoListDtoList != null && buildingInfoListDtoList.size() > 0) {
+                    for (BuildingInfoListDto buildingInfoListDto : buildingInfoListDtoList) {
+                        MapStatisticalDto mapStatisticalDto = new MapStatisticalDto();
+                        mapStatisticalDto.setId(buildingInfoListDto.getBuildingId());
+                        mapStatisticalDto.setName(buildingInfoListDto.getBuildingName());
+                        mapStatisticalDto.setBuildingId(buildingInfoListDto.getBuildingId());
+                        mapStatisticalDto.setLongitude(buildingInfoListDto.getLongitude());
+                        mapStatisticalDto.setLatitude(buildingInfoListDto.getLatitude());
+                        mapStatisticalDto.setNormalCount(buildingInfoListDto.getNormalCount());
+                        mapStatisticalDto.setAlarmCount(buildingInfoListDto.getAlarmCount());
+                        mapStatisticalDto.setFaultCount(buildingInfoListDto.getFaultCount());
+                        mapStatisticalDto.setOfflineCount(buildingInfoListDto.getOfflineCount());
+                        mapStatisticalDto.setUnusedCount(buildingInfoListDto.getDeviceUnusedCount());
+                        mapStatisticalDto.setDeviceCount(buildingInfoListDto.getDeviceCount());
+                        mapStatisticalDto.setAddress(buildingInfoListDto.getAddress());
+                        mapStatisticalDto.setProvince(buildingInfoListDto.getProvince());
+                        mapStatisticalDto.setCity(buildingInfoListDto.getCity());
+                        mapStatisticalDto.setRegion(buildingInfoListDto.getRegion());
+                        mapStatisticalDto.setCommunity(buildingInfoListDto.getCommunity());
+                        mapStatisticalDto.setCode("BUILDING");
+                        list.add(mapStatisticalDto);
+                    }
+                }
+            }
+        } else if(type == 5){
+            //建筑
+            if (buildingInfoListDtoList != null && buildingInfoListDtoList.size() > 0) {
+                for (BuildingInfoListDto buildingInfoListDto : buildingInfoListDtoList) {
+                    MapStatisticalDto mapStatisticalDto = new MapStatisticalDto();
+                    mapStatisticalDto.setId(buildingInfoListDto.getBuildingId());
+                    mapStatisticalDto.setName(buildingInfoListDto.getBuildingName());
+                    mapStatisticalDto.setBuildingId(buildingInfoListDto.getBuildingId());
+                    mapStatisticalDto.setLongitude(buildingInfoListDto.getLongitude());
+                    mapStatisticalDto.setLatitude(buildingInfoListDto.getLatitude());
+                    mapStatisticalDto.setNormalCount(buildingInfoListDto.getNormalCount());
+                    mapStatisticalDto.setAlarmCount(buildingInfoListDto.getAlarmCount());
+                    mapStatisticalDto.setFaultCount(buildingInfoListDto.getFaultCount());
+                    mapStatisticalDto.setOfflineCount(buildingInfoListDto.getOfflineCount());
+                    mapStatisticalDto.setUnusedCount(buildingInfoListDto.getDeviceUnusedCount());
+                    mapStatisticalDto.setDeviceCount(buildingInfoListDto.getDeviceCount());
+                    mapStatisticalDto.setAddress(buildingInfoListDto.getAddress());
+                    mapStatisticalDto.setProvince(buildingInfoListDto.getProvince());
+                    mapStatisticalDto.setCity(buildingInfoListDto.getCity());
+                    mapStatisticalDto.setRegion(buildingInfoListDto.getRegion());
+                    mapStatisticalDto.setCommunity(buildingInfoListDto.getCommunity());
+                    mapStatisticalDto.setCode("BUILDING");
+                    list.add(mapStatisticalDto);
+                }
+            }
+        }else {
+            if (provinceIds.size() > 1) {
+                //省
+                List<Area> areaList = areaMapper.findByIds(provinceIds);
+                for (Area area : areaList) {
+                    list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 1));
+                }
+            } else {
+                if (cityIds.size() > 1) {
+                    //市
+                    List<Area> areaList = areaMapper.findByIds(cityIds);
+                    for (Area area : areaList) {
+                        list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 2));
+                    }
+                } else {
+                    if (regionIds.size() > 1) {
+                        //区
+                        List<Area> areaList = areaMapper.findByIds(regionIds);
+                        for (Area area : areaList) {
+                            list.add(this.countAreaDeviceNum(buildingInfoListDtoList, area.getId(), area.getLng(), area.getLat(), 3));
+                        }
+                    } else {
+                        if (communityIds.size() > 1) {
+                            //小区
+                            for (Integer id : communityIds) {
+                                list.add(this.countAreaDeviceNum(buildingInfoListDtoList, id, null, null, 4));
+                            }
+                        } else {
+                            //建筑
+                            if (buildingInfoListDtoList.size() > 0) {
+                                for (BuildingInfoListDto buildingInfoListDto : buildingInfoListDtoList) {
+                                    MapStatisticalDto mapStatisticalDto = new MapStatisticalDto();
+                                    mapStatisticalDto.setCode("BUILDING");
+                                    mapStatisticalDto.setName(buildingInfoListDto.getBuildingName());
+                                    mapStatisticalDto.setBuildingId(buildingInfoListDto.getBuildingId());
+                                    mapStatisticalDto.setLongitude(buildingInfoListDto.getLongitude());
+                                    mapStatisticalDto.setLatitude(buildingInfoListDto.getLatitude());
+                                    mapStatisticalDto.setNormalCount(buildingInfoListDto.getNormalCount());
+                                    mapStatisticalDto.setAlarmCount(buildingInfoListDto.getAlarmCount());
+                                    mapStatisticalDto.setFaultCount(buildingInfoListDto.getFaultCount());
+                                    mapStatisticalDto.setOfflineCount(buildingInfoListDto.getOfflineCount());
+                                    mapStatisticalDto.setUnusedCount(buildingInfoListDto.getDeviceUnusedCount());
+                                    mapStatisticalDto.setDeviceCount(buildingInfoListDto.getDeviceCount());
+                                    mapStatisticalDto.setAddress(buildingInfoListDto.getAddress());
+                                    mapStatisticalDto.setProvince(buildingInfoListDto.getProvince());
+                                    mapStatisticalDto.setCity(buildingInfoListDto.getCity());
+                                    mapStatisticalDto.setRegion(buildingInfoListDto.getRegion());
+                                    mapStatisticalDto.setCommunity(buildingInfoListDto.getCommunity());
+                                    list.add(mapStatisticalDto);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return list;
+    }
+
+    /**
+     * 统计地区数量
+     */
+    private MapStatisticalDto countAreaDeviceNum(List<BuildingInfoListDto> buildingInfoListDtoList, Integer areaId, String longitude, String latitude, Integer levelType) {
+        List<MapStatisticalDto> list = newArrayList();
+        Integer normalCount = 0;
+        Integer alarmCount = 0;
+        Integer faultCount = 0;
+        Integer offlineCount = 0;
+        Integer unusedCount = 0;
+        Integer deviceCount = 0;
+        MapStatisticalDto mapStatisticalDto = new MapStatisticalDto();
+
+        Integer buildingCount = 0;//建筑数
+        if (buildingInfoListDtoList != null && buildingInfoListDtoList.size() > 0) {
+            for (BuildingInfoListDto buildingInfoListDto : buildingInfoListDtoList) {
+
+                if (levelType == 1) {
+                    if (areaId.equals(buildingInfoListDto.getProvince())) {
+                        normalCount += buildingInfoListDto.getNormalCount();
+                        alarmCount += buildingInfoListDto.getAlarmCount();
+                        faultCount += buildingInfoListDto.getFaultCount();
+                        offlineCount += buildingInfoListDto.getOfflineCount();
+                        unusedCount += buildingInfoListDto.getDeviceUnusedCount();
+                        deviceCount += buildingInfoListDto.getDeviceCount();
+                        mapStatisticalDto.setCode("PROVINCE");
+                        mapStatisticalDto.setName(buildingInfoListDto.getProvinceName());
+                        mapStatisticalDto.setLongitude(longitude);
+                        mapStatisticalDto.setLatitude(latitude);
+                        buildingCount++;
+                    }
+                }
+                if (levelType == 2) {
+                    if (areaId.equals(buildingInfoListDto.getCity())) {
+                        normalCount += buildingInfoListDto.getNormalCount();
+                        alarmCount += buildingInfoListDto.getAlarmCount();
+                        faultCount += buildingInfoListDto.getFaultCount();
+                        offlineCount += buildingInfoListDto.getOfflineCount();
+                        unusedCount += buildingInfoListDto.getDeviceUnusedCount();
+                        deviceCount += buildingInfoListDto.getDeviceCount();
+                        mapStatisticalDto.setCode("CITY");
+                        mapStatisticalDto.setName(buildingInfoListDto.getCityName());
+                        mapStatisticalDto.setLongitude(longitude);
+                        mapStatisticalDto.setLatitude(latitude);
+                        buildingCount++;
+                    }
+
+                }
+                if (levelType == 3) {
+                    if (areaId.equals(buildingInfoListDto.getRegion())) {
+                        normalCount += buildingInfoListDto.getNormalCount();
+                        alarmCount += buildingInfoListDto.getAlarmCount();
+                        faultCount += buildingInfoListDto.getFaultCount();
+                        offlineCount += buildingInfoListDto.getOfflineCount();
+                        unusedCount += buildingInfoListDto.getDeviceUnusedCount();
+                        deviceCount += buildingInfoListDto.getDeviceCount();
+                        mapStatisticalDto.setCode("REGION");
+                        mapStatisticalDto.setName(buildingInfoListDto.getRegionName());
+                        mapStatisticalDto.setLongitude(longitude);
+                        mapStatisticalDto.setLatitude(latitude);
+                        buildingCount++;
+                    }
+                }
+                if (levelType == 4) {
+                    if (areaId.equals(buildingInfoListDto.getCommunity())) {
+                        normalCount += buildingInfoListDto.getNormalCount();
+                        alarmCount += buildingInfoListDto.getAlarmCount();
+                        faultCount += buildingInfoListDto.getFaultCount();
+                        offlineCount += buildingInfoListDto.getOfflineCount();
+                        unusedCount += buildingInfoListDto.getDeviceUnusedCount();
+                        deviceCount += buildingInfoListDto.getDeviceCount();
+                        mapStatisticalDto.setCode("COMMUNITY");
+                        mapStatisticalDto.setName(buildingInfoListDto.getCommunityName());
+                        if (buildingInfoListDto.getLongitude() != null && buildingInfoListDto.getLatitude() != null) {
+                            mapStatisticalDto.setLongitude(buildingInfoListDto.getLongitude());
+                            mapStatisticalDto.setLatitude(buildingInfoListDto.getLatitude());
+                        }
+                        buildingCount++;
+                    }
+                }
+            }
+        }
+        mapStatisticalDto.setId(areaId);
+        mapStatisticalDto.setNormalCount(normalCount);
+        mapStatisticalDto.setAlarmCount(alarmCount);
+        mapStatisticalDto.setFaultCount(faultCount);
+        mapStatisticalDto.setOfflineCount(offlineCount);
+        mapStatisticalDto.setUnusedCount(unusedCount);
+        mapStatisticalDto.setDeviceCount(deviceCount);
+        mapStatisticalDto.setBuildingCount(buildingCount);
+        return mapStatisticalDto;
+    }
+}

+ 22 - 0
src/main/resources/application-dev.properties

@@ -71,3 +71,25 @@ files.path=${project.path}/data
 iot.url=http://114.135.61.188:58080
 
 
+#########################################Rabbit MQ ����#############################################
+spring.rabbitmq.host=114.135.61.188
+spring.rabbitmq.port=55672
+spring.rabbitmq.username=zoniot
+spring.rabbitmq.password=zcxk100
+spring.rabbitmq.virtual-host=/
+spring.rabbitmq.connection-timeout=1000ms
+# ��������ȷ��
+spring.rabbitmq.publisher-confirm-type=correlated
+# ��������ʧ���˻�
+spring.rabbitmq.publisher-returns=true
+spring.rabbitmq.template.mandatory=true
+# ����ACK
+spring.rabbitmq.listener.direct.acknowledge-mode=manual
+spring.rabbitmq.listener.simple.acknowledge-mode=manual
+# �������
+spring.rabbitmq.exchange=sync-handler-exchange
+spring.rabbitmq.device.queue=sync-device-handler-queue
+spring.rabbitmq.community.queue=sync-community-handler-queue
+spring.rabbitmq.building.queue=sync-building-handler-queue
+
+

+ 39 - 0
src/main/resources/mapper/BuildingMapper.xml

@@ -104,6 +104,45 @@
         </trim>
 </insert>
 
+    <insert id="replaceSelective" useGeneratedKeys="true" keyProperty="building.id">
+        REPLACE INTO sc_building
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="building.id!=null"> id,</if>
+            <if test="building.siteId!=null"> site_id,</if>
+            <if test="building.communityId!=null"> community_id,</if>
+            <if test="building.name!=null"> name,</if>
+            <if test="building.address!=null"> address,</if>
+            <if test="building.province!=null"> province,</if>
+            <if test="building.city!=null"> city,</if>
+            <if test="building.region!=null"> region,</if>
+            <if test="building.longitude!=null"> longitude,</if>
+            <if test="building.latitude!=null"> latitude,</if>
+            <if test="building.status!=null"> status,</if>
+            <if test="building.createDate!=null"> create_date,</if>
+            <if test="building.createBy!=null"> create_by,</if>
+            <if test="building.updateDate!=null"> update_date,</if>
+            <if test="building.updateBy!=null"> update_by</if>
+        </trim>
+        VALUES
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="building.id!=null"> #{building.id,jdbcType=INTEGER},</if>
+            <if test="building.siteId!=null"> #{building.siteId,jdbcType=INTEGER},</if>
+            <if test="building.communityId!=null"> #{building.communityId,jdbcType=INTEGER},</if>
+            <if test="building.name!=null"> #{building.name,jdbcType=VARCHAR},</if>
+            <if test="building.address!=null"> #{building.address,jdbcType=VARCHAR},</if>
+            <if test="building.province!=null"> #{building.province,jdbcType=INTEGER},</if>
+            <if test="building.city!=null"> #{building.city,jdbcType=INTEGER},</if>
+            <if test="building.region!=null"> #{building.region,jdbcType=INTEGER},</if>
+            <if test="building.longitude!=null"> #{building.longitude,jdbcType=INTEGER},</if>
+            <if test="building.latitude!=null"> #{building.latitude,jdbcType=INTEGER},</if>
+            <if test="building.status!=null"> #{building.status,jdbcType=INTEGER},</if>
+            <if test="building.createDate!=null"> #{building.createDate,jdbcType=TIMESTAMP},</if>
+            <if test="building.createBy!=null"> #{building.createBy,jdbcType=VARCHAR},</if>
+            <if test="building.updateDate!=null"> #{building.updateDate,jdbcType=TIMESTAMP},</if>
+            <if test="building.updateBy!=null"> #{building.updateBy,jdbcType=VARCHAR}</if>
+        </trim>
+    </insert>
+
     <!--auto generated Code-->
     <insert id="insertList">
         INSERT INTO sc_building(

+ 62 - 1
src/main/resources/mapper/CommunityMapper.xml

@@ -111,7 +111,68 @@
 
     <!--auto generated Code-->
     <insert id="insertSelective" useGeneratedKeys="true" keyProperty="community.id">
-        INSERT INTO sc_community
+    INSERT INTO sc_community
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+        <if test="community.id!=null"> id,</if>
+        <if test="community.siteId!=null"> site_id,</if>
+        <if test="community.name!=null"> `name`,</if>
+        <if test="community.code!=null"> code,</if>
+        <if test="community.customerId!=null"> customer_id,</if>
+        <if test="community.province!=null"> province,</if>
+        <if test="community.city!=null"> city,</if>
+        <if test="community.region!=null"> region,</if>
+        <if test="community.longitude!=null"> longitude,</if>
+        <if test="community.latitude!=null"> latitude,</if>
+        <if test="community.districtId!=null"> district_id,</if>
+        <if test="community.address!=null"> address,</if>
+        <if test="community.remark!=null"> remark,</if>
+        <if test="community.status!=null"> `status`,</if>
+        <if test="community.dateCreate!=null"> date_create,</if>
+        <if test="community.dateUpdate!=null"> date_update,</if>
+        <if test="community.createBy!=null"> create_by,</if>
+        <if test="community.updateBy!=null"> update_by,</if>
+    </trim>
+    VALUES
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+        <if test="community.id!=null">#{community.id,jdbcType=INTEGER},
+        </if>
+        <if test="community.siteId!=null">#{community.siteId,jdbcType=INTEGER},
+        </if>
+        <if test="community.name!=null">#{community.name,jdbcType=VARCHAR},
+        </if>
+        <if test="community.code!=null">#{community.code,jdbcType=VARCHAR},
+        </if>
+        <if test="community.customerId!=null">#{community.customerId,jdbcType=INTEGER},
+        </if>
+        <if test="community.province!=null">#{community.province,jdbcType=INTEGER},
+        </if>
+        <if test="community.city!=null">#{community.city,jdbcType=INTEGER},
+        </if>
+        <if test="community.region!=null">#{community.region,jdbcType=INTEGER},
+        </if>
+        <if test="community.longitude!=null"> #{community.longitude,jdbcType=VARCHAR},</if>
+        <if test="community.latitude!=null"> #{community.latitude,jdbcType=VARCHAR},</if>
+        <if test="community.districtId!=null">#{community.districtId,jdbcType=INTEGER},
+        </if>
+        <if test="community.address!=null">#{community.address,jdbcType=VARCHAR},
+        </if>
+        <if test="community.remark!=null">#{community.remark,jdbcType=VARCHAR},
+        </if>
+        <if test="community.status!=null">#{community.status,jdbcType=INTEGER},
+        </if>
+        <if test="community.dateCreate!=null">#{community.dateCreate,jdbcType=TIMESTAMP},
+        </if>
+        <if test="community.dateUpdate!=null">#{community.dateUpdate,jdbcType=TIMESTAMP},
+        </if>
+        <if test="community.createBy!=null">#{community.createBy,jdbcType=VARCHAR},
+        </if>
+        <if test="community.updateBy!=null">#{community.updateBy,jdbcType=VARCHAR},
+        </if>
+    </trim>
+</insert>
+
+    <insert id="replaceSelective" useGeneratedKeys="true" keyProperty="community.id">
+        REPLACE INTO sc_community
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="community.id!=null"> id,</if>
             <if test="community.siteId!=null"> site_id,</if>

+ 283 - 2
src/main/resources/mapper/DeviceMapper.xml

@@ -160,6 +160,139 @@
       </if>
     </trim>
   </insert>
+  <insert id="replaceSelective" keyColumn="id" keyProperty="id" parameterType="com.zoniot.ccrc.entity.Device" useGeneratedKeys="true">
+    replace into sc_device
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        id,
+      </if>
+      <if test="deviceNo != null">
+        device_no,
+      </if>
+      <if test="meterNo != null">
+        meter_no,
+      </if>
+      <if test="fileNo != null">
+        file_no,
+      </if>
+      <if test="sealNo != null">
+        seal_no,
+      </if>
+      <if test="siteId != null">
+        site_id,
+      </if>
+      <if test="sysId != null">
+        sys_id,
+      </if>
+      <if test="deviceTypeId != null">
+        device_type_id,
+      </if>
+      <if test="manufacturerId != null">
+        manufacturer_id,
+      </if>
+      <if test="buildingId != null">
+        building_id,
+      </if>
+      <if test="communityId != null">
+        community_id,
+      </if>
+      <if test="locDesc != null">
+        loc_desc,
+      </if>
+      <if test="meterReading != null">
+        meter_reading,
+      </if>
+      <if test="valveStatus != null">
+        valve_status,
+      </if>
+      <if test="deviceStatus != null">
+        device_status,
+      </if>
+      <if test="lastReceiveTime != null">
+        last_receive_time,
+      </if>
+      <if test="status != null">
+        `status`,
+      </if>
+      <if test="createBy != null">
+        create_by,
+      </if>
+      <if test="dateCreate != null">
+        date_create,
+      </if>
+      <if test="updateBy != null">
+        update_by,
+      </if>
+      <if test="dateUpdate != null">
+        date_update,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        #{id},
+      </if>
+      <if test="deviceNo != null">
+        #{deviceNo},
+      </if>
+      <if test="meterNo != null">
+        #{meterNo},
+      </if>
+      <if test="fileNo != null">
+        #{fileNo},
+      </if>
+      <if test="sealNo != null">
+        #{sealNo},
+      </if>
+      <if test="siteId != null">
+        #{siteId},
+      </if>
+      <if test="sysId != null">
+        #{sysId},
+      </if>
+      <if test="deviceTypeId != null">
+        #{deviceTypeId},
+      </if>
+      <if test="manufacturerId != null">
+        #{manufacturerId},
+      </if>
+      <if test="buildingId != null">
+        #{buildingId},
+      </if>
+      <if test="communityId != null">
+        #{communityId},
+      </if>
+      <if test="locDesc != null">
+        #{locDesc},
+      </if>
+      <if test="meterReading != null">
+        #{meterReading},
+      </if>
+      <if test="valveStatus != null">
+        #{valveStatus},
+      </if>
+      <if test="deviceStatus != null">
+        #{deviceStatus},
+      </if>
+      <if test="lastReceiveTime != null">
+        #{lastReceiveTime},
+      </if>
+      <if test="status != null">
+        #{status},
+      </if>
+      <if test="createBy != null">
+        #{createBy},
+      </if>
+      <if test="dateCreate != null">
+        #{dateCreate},
+      </if>
+      <if test="updateBy != null">
+        #{updateBy},
+      </if>
+      <if test="dateUpdate != null">
+        #{dateUpdate},
+      </if>
+    </trim>
+  </insert>
   <update id="updateByPrimaryKeySelective" parameterType="com.zoniot.ccrc.entity.Device">
     <!--@mbg.generated-->
     update sc_device
@@ -337,8 +470,7 @@
       #{item.id}
     </foreach>
   </update>
-
-    <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
+  <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
     <!--@mbg.generated-->
     insert into sc_device
     (device_no, meter_no, file_no, seal_no, site_id, sys_id, device_type_id, manufacturer_id, 
@@ -353,10 +485,159 @@
         #{item.dateCreate}, #{item.updateBy}, #{item.dateUpdate})
     </foreach>
   </insert>
+
+  <select id="getList" resultType="com.zoniot.ccrc.dto.DeviceDto">
+    select
+        sd.*,
+        sb.name as building_name,
+        sc.name as community_name,
+        so.name as org_name,
+        sdt.equipment_type,
+        sdt.model,
+        sdt.is_valve,
+        sdm.name manufacturer_name,
+        sgm.customer_no,
+        sgm.customer_phone,
+        sgm.customer_name,
+        sgm.label,
+        su.username
+    from sc_device sd
+    left join sc_building sb on(sb.id = sd.building_id)
+    left join sc_community sc on(sc.id = sd.community_id)
+    left join sc_organization so on(so.id = sc.org_id)
+    left join sc_device_type sdt on(sdt.id = sd.device_type_id)
+    left join sc_device_manufacturer sdm on(sdm.id = sd.manufacturer_id)
+    left join sc_grid_management sgm on(sgm.device_id = sd.id)
+    left join sc_user su on(su.id = sgm.user_id)
+    where sd.status = 1
+    <if test="siteId != null"> and sd.site_id = #{siteId}</if>
+    <if test="userId != null"> and sgm.user_id = #{userId}</if>
+    <if test="sysId != null"> and sd.sys_id = #{sysId}</if>
+    <if test="deviceTypeId != null"> and sd.device_type_id = #{deviceTypeId}</if>
+    <if test="orgId != null"> and sc.org_id = #{orgId}</if>
+    <if test="province != null"> and sb.province = #{province}</if>
+    <if test="city != null"> and sb.city = #{city}</if>
+    <if test="region != null"> and sb.region = #{region}</if>
+    <if test="communityId != null"> and sd.community_id = #{communityId}</if>
+    <if test="buildingId != null"> and sd.building_id = #{buildingId}</if>
+    <if test="deviceNo != null and deviceNo != ''"> AND (sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.meter_no LIKE concat('%',#{deviceNo},'%') or sd.file_no LIKE concat('%',#{deviceNo},'%'))</if>
+    <if test="clientName != null and clientName != ''"> AND sgm.customer_name LIKE concat('%',#{clientName},'%')</if>
+    <if test="locDesc != null and locDesc != ''"> AND sd.loc_desc LIKE concat('%',#{locDesc},'%')</if>
+    <if test="status != null and status != ''"> and sd.device_status = #{status}</if>
+    <if test="valveStatus != null"> and sd.valve_status = #{valveStatus}</if>
+    <if test="communityIds != null and communityIds.size() != 0">
+      and sd.community_id in <foreach collection="communityIds" item="item" open="(" separator="," close=")">#{item}</foreach>
+    </if>
+    <if test="sortColumn != null and sortColumn != ''">
+      <if test="sortOrder != null and sortOrder != ''">
+        order by ${sortColumn} ${sortOrder}
+      </if>
+    </if>
+  </select>
+
+  <select id="deviceAreaList" resultType="com.zoniot.ccrc.dto.BuildingSelectInfoDto">
+    select
+    b.id,
+    b.name,
+    b.province,
+    b.city,
+    b.region,
+    b.community_id as community,
+    b.longitude,
+    b.latitude,
+    t1.device_count
+    from sc_building b
+    right join (
+    select sd.building_id,count(1) as device_count
+    from sc_device sd
+    left join sc_grid_management sgm on(sgm.device_id = sd.id)
+    <if test="province != null or city != null or region != null or communityId != null">left join sc_building sb on (sb.id = sd.building_id and sb.status = 1)</if>
+    <if test="orgId != null">left join sc_community sc on(sc.id = sd.community_id)</if>
+    where sd.status = 1
+    <if test="siteId != null"> and sd.site_id = #{siteId}</if>
+    <if test="userId != null"> and sgm.user_id = #{userId}</if>
+    <if test="sysId != null"> and sd.sys_id = #{sysId}</if>
+    <if test="deviceTypeId != null"> and sd.device_type_id = #{deviceTypeId}</if>
+    <if test="orgId != null"> and sc.org_id = #{orgId}</if>
+    <if test="province != null"> and sb.province = #{province}</if>
+    <if test="city != null"> and sb.city = #{city}</if>
+    <if test="region != null"> and sb.region = #{region}</if>
+    <if test="communityId != null"> and sd.community_id = #{communityId}</if>
+    <if test="buildingId != null"> and sd.building_id = #{buildingId}</if>
+    <if test="deviceNo != null and deviceNo != ''"> AND (sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.meter_no LIKE concat('%',#{deviceNo},'%') or sd.file_no LIKE concat('%',#{deviceNo},'%'))</if>
+    <if test="clientName != null and clientName != ''"> AND sgm.customer_name LIKE concat('%',#{clientName},'%')</if>
+    <if test="locDesc != null and locDesc != ''"> AND sd.loc_desc LIKE concat('%',#{locDesc},'%')</if>
+    <if test="status != null and status != ''"> and sd.device_status = #{status}</if>
+    <if test="valveStatus != null"> and sd.valve_status = #{valveStatus}</if>
+    <if test="communityIds != null and communityIds.size() != 0">
+      and sd.community_id in <foreach collection="communityIds" item="item" open="(" separator="," close=")">#{item}</foreach>
+    </if>
+    GROUP BY sd.building_id
+    ) t1 on (t1.building_id = b.id)
+    where b.status = 1
+    <if test="siteId != null"> and b.site_id=#{siteId} </if>
+  </select>
   <select id="getDeviceIdByUserNumber" resultType="java.lang.Long">
     select b.id
     from sc_grid_management a
            inner join  sc_device b on b.id=a.device_id where a.id=#{id}
 
   </select>
+
+  <select id="getBuildingStatistics" resultType="com.zoniot.ccrc.dto.BuildingInfoListDto">
+    select
+    sb.id as building_id,
+    sb.name as building_name,
+    sb.address ,
+    sb.province,
+    sb.city,
+    sb.region,
+    sb.community_id as community,
+    sa1.name as province_name,
+    sa2.name as city_name,
+    sa3.name as region_name,
+    sc.name as community_name,
+    sb.latitude,
+    sb.longitude,
+    temp.device_count,
+    temp.normal_count,
+    temp.alarm_count,
+    temp.fault_count,
+    temp.offline_count,
+    temp.device_unused_count
+    from sc_building sb
+    LEFT JOIN(
+    SELECT
+    sd.building_id,
+    <if test="sysId != null">sd.sys_id,</if>
+    count(1) as device_count,
+    SUM(IF(sd.device_status = 1, 1, 0)) as normal_count,
+    SUM(IF(sd.device_status = 2, 1, 0)) as alarm_count,
+    SUM(IF(sd.device_status = 3, 1, 0)) as fault_count,
+    SUM(IF(sd.device_status = 4, 1, 0)) as offline_count,
+    SUM(IF(sd.device_status = 5, 1, 0)) as device_unused_count
+    from sc_device sd
+    <if test="userId != null"> left join sc_grid_management scm on(scm.device_id = sd.id) </if>
+    WHERE sd.status = 1
+    <if test="siteId != null"> and sd.site_id = #{siteId} </if>
+    <if test="sysId != null"> and sd.sys_id = #{sysId} </if>
+    <if test="userId != null"> and scm.user_id = #{userId} </if>
+    <if test="communityIds != null and communityIds.size() != 0"> and sd.community_id in <foreach collection="communityIds" item="item" open="(" separator="," close=")">#{item}</foreach></if>
+    GROUP BY sd.building_id <if test="sysId != null">,sd.sys_id</if>
+    ) temp on (sb.id = temp.building_id)
+    left join sc_area sa1 on sa1.id = sb.province
+    left join sc_area sa2 on sa2.id = sb.city
+    left join sc_area sa3 on sa3.id = sb.region
+    left join sc_community sc on sc.id = sb.community_id
+    where sb.status = 1
+    <if test="siteId != null"> and sb.site_id = #{siteId} </if>
+    <if test="sysId != null"> and temp.sys_id = #{sysId} </if>
+    <if test="province != null"> AND sb.province = #{province}</if>
+    <if test="city != null"> AND sb.city = #{city}</if>
+    <if test="region != null"> AND sb.region = #{region}</if>
+    <if test="community != null"> AND sb.community_id = #{community}</if>
+    <if test="type != null and (type == 4 or type == 5) and longitudeMin != 0 and longitudeMax != 0"> and sb.longitude > #{longitudeMin} AND sb.longitude <![CDATA[  < ]]> #{longitudeMax} </if>
+    <if test="type != null and (type == 4 or type == 5) and latitudeMin != 0 and latitudeMax != 0"> and sb.latitude > #{latitudeMin} AND sb.latitude <![CDATA[  < ]]> #{latitudeMax} </if>
+    order by sb.update_date desc
+    </select>
 </mapper>

+ 4 - 0
src/main/resources/mapper/SiteMapper.xml

@@ -195,5 +195,9 @@
         select count(1) from sc_site where status = 1 and customer_id = #{customerId}
         <if test="id != null"> and id != #{id}</if>
     </select>
+
+    <select id="getSiteCustomerIds" resultType="java.lang.Integer">
+        select customer_id from sc_site where status = 1
+    </select>
 </mapper>
 

+ 11 - 15
src/main/resources/mapper/WarningLogMapper.xml

@@ -131,34 +131,32 @@
     select
     swl.*,
     sd.device_no,
-    sd.water_meter_no,
+    sd.meter_no as water_meter_no,
     sd.loc_desc,
     sdt1.equipment_type as equipment_type,
     sdt1.model as model,
-    sdm1.name as manufacturer_name,
-    sil.metercode meterCode
+    sdm1.name as manufacturer_name
     from sc_warning_log swl
     left join sc_device sd on(sd.id = swl.device_id)
-    left join sc_install_list sil on sd.id=sil.device_id
     left join sc_building sb on(sb.id = sd.building_id)
-    left join sc_device_type sdt1 on(sdt1.id = sd.device_type)
+    left join sc_device_type sdt1 on(sdt1.id = sd.device_type_id)
     left join sc_device_manufacturer sdm1 on(sdm1.id = sdt1.manufacturer_id)
-    <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = sd.id and sdd.status = 1)</if>
+    left join sc_grid_management sgm on(sgm.device_id = sd.id)
     where swl.status = 1 and sd.status = 1
     <if test="siteId != null"> and sd.site_id = #{siteId}</if>
     <if test="channelId != null"> and sd.sys_id = #{channelId}</if>
     <if test="deviceNo != null and deviceNo != ''"> and (
-      sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.water_meter_no LIKE concat('%',#{deviceNo},'%')
+      sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.meter_no LIKE concat('%',#{deviceNo},'%')
     )</if>
     <if test="warningType != null"> and swl.warning_type = #{warningType}</if>
     <if test="clientName != null and clientName != ''"> and (
-      pba.name LIKE concat('%',#{clientName},'%') or pba.mobilephone LIKE concat('%',#{clientName},'%') or pba.accountnumber LIKE concat('%',#{clientName},'%')
+      sgm.customer_name LIKE concat('%',#{clientName},'%') or sgm.customer_phone LIKE concat('%',#{clientName},'%') or sgm.customer_no LIKE concat('%',#{clientName},'%')
     )</if>
     <if test="feedbackStatus != null"> and swl.feedback_status = #{feedbackStatus}</if>
     <if test="provinceId != null"> and sb.province = #{provinceId}</if>
     <if test="cityId != null"> and sb.city = #{cityId}</if>
     <if test="regionId != null"> and sb.region = #{regionId}</if>
-    <if test="communityId != null"> and sb.community = #{communityId}</if>
+    <if test="communityId != null"> and sb.community_id = #{communityId}</if>
     <if test="buildingId != null"> and sd.building_id = #{buildingId}</if>
     <if test="startDate != null"> and swl.date_create <![CDATA[ >= ]]> #{startDate}</if>
     <if test="endDate != null"> and swl.date_create <![CDATA[ <= ]]> #{endDate}</if>
@@ -172,7 +170,7 @@
     b.province,
     b.city,
     b.region,
-    b.community,
+    b.community_id as community,
     b.longitude,
     b.latitude,
     t1.device_count
@@ -181,18 +179,16 @@
     select sd.building_id,count(1) as device_count
     from sc_warning_log swl
     left join sc_device sd on(sd.id = swl.device_id)
-    left join pay_base_customerandmeterrela pbc on(pbc.watermeter_id = swl.device_id)
-    left join pay_base_account pba on(pba.id = pbc.account_id)
-    <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = sd.id and sdd.status = 1)</if>
+    left join sc_grid_management sgm on(sgm.device_id = sd.id)
     where swl.status = 1 and sd.status = 1
     <if test="siteId != null"> and sd.site_id = #{siteId}</if>
     <if test="channelId != null"> and sd.sys_id = #{channelId}</if>
     <if test="deviceNo != null and deviceNo != ''"> and (
-      sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.water_meter_no LIKE concat('%',#{deviceNo},'%')
+      sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.meter_no LIKE concat('%',#{deviceNo},'%')
       )</if>
     <if test="warningType != null"> and swl.warning_type = #{warningType}</if>
     <if test="clientName != null and clientName != ''"> and (
-      pba.name LIKE concat('%',#{clientName},'%') or pba.mobilephone LIKE concat('%',#{clientName},'%') or pba.accountnumber LIKE concat('%',#{clientName},'%')
+      sgm.customer_name LIKE concat('%',#{clientName},'%') or sgm.customer_phone LIKE concat('%',#{clientName},'%') or sgm.customer_no LIKE concat('%',#{clientName},'%')
       )</if>
     <if test="feedbackStatus != null"> and swl.feedback_status = #{feedbackStatus}</if>
     <if test="startDate != null"> and swl.date_create <![CDATA[ >= ]]> #{startDate}</if>

+ 5 - 1
src/test/java/com/zoniot/ccrc/OptionalTest.java

@@ -1,5 +1,7 @@
 package com.zoniot.ccrc;
 
+import com.alibaba.fastjson.JSON;
+import com.zoniot.ccrc.commom.model.DeviceData;
 import org.junit.Test;
 import org.springframework.util.Assert;
 
@@ -11,7 +13,9 @@ public class OptionalTest {
     @Test
     public void test(){
 
-        Optional<String> s = Optional.ofNullable("test");
+        String json = "{\"buildingId\":7427,\"communityId\":260,\"customerId\":5,\"dateCreate\":\"2021-03-09 19:14:13\",\"dateUpdate\":\"2021-03-12 13:49:46\",\"deviceNo\":\"004A7701240145AE\",\"deviceTypeId\":15,\"fileNo\":\"1030657515\",\"id\":818924656340893696,\"lastReceiveTime\":\"2021-03-09 20:27:11\",\"locDesc\":\"8-1-301\",\"manufacturerId\":8,\"meterNo\":\"100271109803\",\"meterReading\":134.7,\"sysId\":40,\"valveStatus\":1}";
+        DeviceData deviceData = JSON.parseObject(json, DeviceData.class);
+        System.out.println(deviceData);
 
 
     }