Procházet zdrojové kódy

津南精细化服务平台

lin před 3 roky
rodič
revize
f4b7ce97c0

+ 61 - 0
src/main/java/com/zoniot/ccrc/commom/utils/Jdk8DateUtils.java

@@ -0,0 +1,61 @@
+package com.zoniot.ccrc.commom.utils;
+
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.Date;
+
+/**
+ * jdk1.8 LocalDateTime 时间操作工具类
+ */
+public class Jdk8DateUtils {
+
+    /**
+     * LocalDateTime 转 Date
+     *
+     * @param localDateTime
+     * @return
+     */
+    public static Date getLocalDateTimeToDate(LocalDateTime localDateTime) {
+        if (localDateTime != null) {
+            ZoneId zoneId = ZoneId.systemDefault();
+            return Date.from(localDateTime.atZone(zoneId).toInstant());
+        }else {
+            return null;
+        }
+    }
+
+    /**
+     * LocalDate 转 Date
+     *
+     * @param localDate
+     * @return
+     */
+    public static Date getLocalDateToDate(LocalDate localDate) {
+        if (localDate != null) {
+            ZoneId zoneId = ZoneId.systemDefault();
+            return Date.from(localDate.atStartOfDay(zoneId).toInstant());
+        }else {
+            return null;
+        }
+    }
+
+
+    /**
+     * Date 转 LocalDateTime
+     *
+     * @param date
+     * @return
+     */
+    public static LocalDateTime getDateToLocalDateTime(Date date) {
+        if (date != null) {
+            ZoneId zoneId = ZoneId.systemDefault();
+            Instant instant = date.toInstant();
+            return LocalDateTime.ofInstant(instant, zoneId);
+        }else {
+            return null;
+        }
+    }
+
+}

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

@@ -37,7 +37,7 @@ public class RealTimeMonitorController {
     @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 = "类型  1:省  2:市 3:区 4:小区 ", 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,

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

@@ -7,6 +7,7 @@ import com.zoniot.ccrc.dto.BuildingSelectDto;
 import com.zoniot.ccrc.dto.DeviceDto;
 import com.zoniot.ccrc.dto.DeviceMeasuringDataDTO;
 import com.zoniot.ccrc.service.DeviceService;
+import com.zoniot.ccrc.service.MeterReadRecordService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -43,6 +44,8 @@ public class DeviceController {
 
     @Autowired
     private DeviceService deviceService;
+    @Autowired
+    private MeterReadRecordService meterReadRecordService;
 
     @Value("${iot.server}")
     private String server;
@@ -134,7 +137,7 @@ public class DeviceController {
         return new AjaxMessage<>(ResultStatus.OK, device);
     }
 
-    @ResponseBody
+    /*@ResponseBody
     @GetMapping("/getData")
     @ApiOperation(value = "获取设备数据")
     public void getData(
@@ -193,5 +196,42 @@ public class DeviceController {
         bais.close();
 
 
+    }*/
+
+
+
+    @ResponseBody
+    @GetMapping("/getData")
+    @ApiOperation(value = "获取设备数据")
+    public AjaxMessage<List<DeviceMeasuringDataDTO>> getData(
+            @ApiParam(value = "设备id", required = true) @RequestParam(required = true) Long deviceId,
+            @ApiParam(value = "查询日期,YYYYMMDD格式", required = true) @RequestParam Integer startDate,
+            @ApiParam(value = "查询日期,YYYYMMDD格式", required = true) @RequestParam Integer endDate,
+            HttpServletRequest httpServletRequest,
+            HttpServletResponse httpServletResponse
+    )  {
+        List<DeviceMeasuringDataDTO> list = meterReadRecordService.getData(deviceId,startDate,endDate);
+        return new AjaxMessage<>(ResultStatus.OK,list);
+    }
+
+
+
+
+
+
+
+
+    @GetMapping("/getDataExcel")
+    @ApiOperation(value = "导出设备数据excel")
+    public void getDataExcel(
+            @ApiParam(value = "设备id", required = true) @RequestParam(required = true) Long deviceId,
+            @ApiParam(value = "查询日期,YYYYMMDD格式", required = true) @RequestParam Integer startDate,
+            @ApiParam(value = "查询日期,YYYYMMDD格式", required = true) @RequestParam Integer endDate,
+            HttpServletRequest httpServletRequest,
+            HttpServletResponse httpServletResponse
+    )  {
+        meterReadRecordService.getDataExcel(deviceId,startDate,endDate, httpServletResponse);
+
+
     }
 }

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

@@ -1,5 +1,6 @@
 package com.zoniot.ccrc.dao;
 
+import com.zoniot.ccrc.dto.BuildingInfoListDto;
 import com.zoniot.ccrc.dto.CommunityDto;
 import com.zoniot.ccrc.entity.Community;
 import org.apache.ibatis.annotations.Mapper;
@@ -49,4 +50,19 @@ public interface CommunityMapper {
 
     List<Community> getOrgCommunity(@Param("orgId") Integer orgId, @Param("areaId") Integer areaId
             , @Param("siteId") Integer siteId);
+
+    List<BuildingInfoListDto> getStatistics(
+            @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);
 }

+ 13 - 0
src/main/java/com/zoniot/ccrc/dao/MeterReadRecordMapper.java

@@ -0,0 +1,13 @@
+package com.zoniot.ccrc.dao;
+
+import com.zoniot.ccrc.entity.MeterReadRecord;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface MeterReadRecordMapper {
+
+    List<MeterReadRecord> getList(@Param("deviceId") Long deviceId, @Param("startDate") Integer startDate, @Param("endDate") Integer endDate);
+}

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

@@ -50,10 +50,10 @@ public class Device {
     @ApiModelProperty(value="水表读数")
     private Double meterReading;
 
-    @ApiModelProperty(value="阀门状态 0:关阀 1:开阀 2:异常")
+    @ApiModelProperty(value="阀门状态 0:关,1:开,2:无阀")
     private Integer valveStatus;
 
-    @ApiModelProperty(value="设备状态  1:正常 2:故障 3:无 4: 预警 5:未启用")
+    @ApiModelProperty(value="设备状态  1:正常,0:告警")
     private Integer deviceStatus;
 
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")

+ 110 - 0
src/main/java/com/zoniot/ccrc/entity/MeterReadRecord.java

@@ -0,0 +1,110 @@
+package com.zoniot.ccrc.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import lombok.Data;
+
+@ApiModel(value="com-zoniot-ccrc-entity-MeterReadRecord")
+@Data
+public class MeterReadRecord {
+
+    @ApiModelProperty(value="主键")
+    private Long id;
+
+    @ApiModelProperty(value="读表日期")
+    private Integer readDate;
+
+
+    @ApiModelProperty(value="站点")
+    private Integer siteId;
+
+
+    @ApiModelProperty(value="场景")
+    private Integer sysId;
+
+
+    @ApiModelProperty(value="省")
+    private Integer province;
+
+
+    @ApiModelProperty(value="市")
+    private Integer city;
+
+    @ApiModelProperty(value="区")
+    private Integer region;
+
+    @ApiModelProperty(value="小区")
+    private Integer community;
+
+    @ApiModelProperty(value="客户")
+    private Integer customerId;
+
+    @ApiModelProperty(value="集中器")
+    private Integer concentratorId;
+
+
+    @ApiModelProperty(value="采集器")
+    private Integer collectorId;
+
+
+    @ApiModelProperty(value="建筑")
+    private Integer buildingId;
+
+
+    @ApiModelProperty(value="安装地址")
+    private String location;
+
+    @ApiModelProperty(value="设备类型")
+    private Integer deviceTypeId;
+
+    @ApiModelProperty(value="设备id")
+    private Long deviceId;
+
+    @ApiModelProperty(value="节点编号")
+    private String deviceNo;
+
+    @ApiModelProperty(value="电子号")
+    private String meterNo;
+
+    @ApiModelProperty(value="档案号")
+    private String meterFileNo;
+
+    @ApiModelProperty(value="读表时间")
+    private LocalDateTime readTime;
+
+    @ApiModelProperty(value="读表状态")
+    private String readStatus;
+
+
+    @ApiModelProperty(value="读表数据")
+    private String readData;
+
+    @ApiModelProperty(value="最近有效数据")
+    private String lastValid;
+
+    @ApiModelProperty(value="距离上次的消耗")
+    private BigDecimal lastCost;
+
+    @ApiModelProperty(value="状态")
+    private Integer status;
+
+    @ApiModelProperty(value="创建时间")
+    private LocalDateTime dateCreate;
+
+    @ApiModelProperty(value="更新时间")
+    private LocalDateTime dateUpdate;
+
+    @ApiModelProperty(value="创建人")
+    private String createBy;
+
+    @ApiModelProperty(value="更新人")
+    private String updateBy;
+
+    @ApiModelProperty(value="阀门状态")
+    private Integer valveStatus;
+
+    @ApiModelProperty(value="告警信息")
+    private String meterStatusInfo;
+}

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

@@ -21,7 +21,7 @@ public class SyncBuildingReceiver {
     private BuildingService buildingService;
 
 
-    @RabbitListener(queues = {"${spring.rabbitmq.building.queue}"},containerFactory = "customContainerFactory")
+    //@RabbitListener(queues = {"${spring.rabbitmq.building.queue}"},containerFactory = "customContainerFactory")
     public void receiver(Channel channel, Message message) throws IOException {
         //String str = new String(body);
         try {

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

@@ -21,7 +21,7 @@ public class SyncCommunityReceiver {
     private CommunityService communityService;
 
 
-    @RabbitListener(queues = {"${spring.rabbitmq.community.queue}"},containerFactory = "customContainerFactory")
+    //@RabbitListener(queues = {"${spring.rabbitmq.community.queue}"},containerFactory = "customContainerFactory")
     public void receiver(Channel channel, Message message) throws IOException {
         try {
             String msg = new String(message.getBody());

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

@@ -20,7 +20,7 @@ public class SyncDeviceReceiver {
     private DeviceService deviceService;
 
 
-    @RabbitListener(queues = {"${spring.rabbitmq.device.queue}"},containerFactory = "customContainerFactory")
+    //@RabbitListener(queues = {"${spring.rabbitmq.device.queue}"},containerFactory = "customContainerFactory")
     public void receiver(Channel channel, Message message) throws IOException {
         try {
             String msg = new String(message.getBody());

+ 14 - 0
src/main/java/com/zoniot/ccrc/service/MeterReadRecordService.java

@@ -0,0 +1,14 @@
+package com.zoniot.ccrc.service;
+
+import com.zoniot.ccrc.dto.DeviceMeasuringDataDTO;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+public interface MeterReadRecordService{
+
+
+    List<DeviceMeasuringDataDTO> getData(Long deviceId, Integer startDate, Integer endDate);
+
+    void getDataExcel(Long deviceId, Integer startDate, Integer endDate, HttpServletResponse httpServletResponse);
+}

+ 9 - 14
src/main/java/com/zoniot/ccrc/service/impl/BuildingServiceImpl.java

@@ -189,19 +189,14 @@ public class BuildingServiceImpl implements BuildingService {
                 buildingSelectDto.setNum(building.getDeviceCount());
                 buildingSelectDto.setLongitude(building.getLongitude());
                 buildingSelectDto.setLatitude(building.getLatitude());
-                buildingSelectDto.setDimensionCode("BUILDING");
-                if (building.getCommunity() != null) {
-                    //区关联建筑,把区id设置成建筑的父类id
-                    buildingSelectDto.setPid(building.getCommunity());
+                buildingSelectDto.setDimensionCode("COMMUNITY");
+                if (building.getRegion() != null) {
+                    //区关联建筑,把区id设置成建筑的父类id
+                    buildingSelectDto.setPid(building.getRegion());
                 } else {
-                    if (building.getRegion() != null) {
-                        //区关联建筑,把区id设置成建筑的父类id
-                        buildingSelectDto.setPid(building.getRegion());
-                    } else {
-                        if (building.getCity() != null) {
-                            //市关联建筑,把市id设置成建筑的父类id
-                            buildingSelectDto.setPid(building.getCity());
-                        }
+                    if (building.getCity() != null) {
+                        //市关联建筑,把市id设置成建筑的父类id
+                        buildingSelectDto.setPid(building.getCity());
                     }
                 }
                 buildingSelectDtoArrayList.add(buildingSelectDto);
@@ -209,7 +204,7 @@ public class BuildingServiceImpl implements BuildingService {
         }
 
         //查询所有的小区
-        if (communityIds.size() > 0) {
+        /*if (communityIds.size() > 0) {
             List<Community> communityList = communityMapper.findByIds(communityIds.stream().distinct().collect(Collectors.toList()));
             if (communityList != null && communityList.size() > 0) {
                 for (Community community : communityList) {
@@ -236,7 +231,7 @@ public class BuildingServiceImpl implements BuildingService {
                     buildingSelectDtoArrayList.add(buildingSelectDto);
                 }
             }
-        }
+        }*/
         //查询所有建筑的区域
         List<Area> areaList = newArrayList();
         if (ids.size() > 0) {

+ 83 - 0
src/main/java/com/zoniot/ccrc/service/impl/MeterReadRecordServiceImpl.java

@@ -0,0 +1,83 @@
+package com.zoniot.ccrc.service.impl;
+
+import com.zoniot.ccrc.commom.exception.ServiceException;
+import com.zoniot.ccrc.commom.utils.ExcelUtil;
+import com.zoniot.ccrc.commom.utils.Jdk8DateUtils;
+import com.zoniot.ccrc.dto.DeviceMeasuringDataDTO;
+import com.zoniot.ccrc.entity.MeterReadRecord;
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+
+import com.zoniot.ccrc.dao.MeterReadRecordMapper;
+import com.zoniot.ccrc.service.MeterReadRecordService;
+
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+@Service
+public class MeterReadRecordServiceImpl implements MeterReadRecordService{
+
+    @Resource
+    private MeterReadRecordMapper meterReadRecordMapper;
+
+    @Override
+    public List<DeviceMeasuringDataDTO> getData(Long deviceId, Integer startDate, Integer endDate) {
+
+        List<MeterReadRecord> list = meterReadRecordMapper.getList(deviceId,startDate,endDate);
+
+        List<DeviceMeasuringDataDTO> result = new ArrayList<>();
+        if (list != null && list.size() > 0) {
+            for (MeterReadRecord record : list) {
+                DeviceMeasuringDataDTO dto = new DeviceMeasuringDataDTO();
+                dto.setDateTime(Jdk8DateUtils.getLocalDateTimeToDate(record.getReadTime()));
+                Map<String,String> map = new HashMap<>();
+                map.put("meterReading",record.getReadData());
+                map.put("valveStatus",convert(record.getValveStatus()));
+                map.put("meterStatusInfo",record.getMeterStatusInfo());
+                dto.setMeasuringData(map);
+                result.add(dto);
+            }
+        }
+        return result;
+    }
+
+    @Override
+    public void getDataExcel(Long deviceId, Integer startDate, Integer endDate, HttpServletResponse httpServletResponse) {
+        List<MeterReadRecord> list = meterReadRecordMapper.getList(deviceId,startDate,endDate);
+        String title = "历史数据";
+        String[] rowsName = new String[]{"序号", "时间", "读数", "阀门状态", "告警信息"};
+        List<Object[]> dataList = newArrayList();
+        Object[] objs = null;
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        for (int i = 0; i < list.size(); i++) {
+            MeterReadRecord dto = list.get(i);
+            objs = new Object[rowsName.length];
+            objs[0] = i;
+            objs[1] = dto.getReadTime()!=null?dto.getReadTime().format(df):null;
+            objs[2] = dto.getReadData();
+            objs[3] = convert(dto.getValveStatus());
+            objs[4] = dto.getMeterStatusInfo();
+
+            dataList.add(objs);
+        }
+        ExcelUtil excelUtil = new ExcelUtil(title, rowsName, dataList);
+        try {
+            excelUtil.export(httpServletResponse);
+        } catch (Exception e) {
+            throw new ServiceException(-900, "导出异常");
+        }
+    }
+
+    private String convert(Integer valveStatus){
+        //0:关,1:开,2:无阀
+        if(valveStatus == 0) return "关";
+        if(valveStatus == 1) return "开";
+        return "无阀";
+    }
+}

+ 6 - 51
src/main/java/com/zoniot/ccrc/service/impl/StatAndAnalysisServiceImpl.java

@@ -3,6 +3,7 @@ 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.CommunityMapper;
 import com.zoniot.ccrc.dao.DeviceMapper;
 import com.zoniot.ccrc.dto.BuildingInfoListDto;
 import com.zoniot.ccrc.dto.LoginUser;
@@ -27,6 +28,8 @@ public class StatAndAnalysisServiceImpl implements StatAndAnalysisService {
     private AreaMapper areaMapper;
     @Resource
     private DeviceMapper deviceMapper;
+    @Resource
+    private CommunityMapper communityMapper;
 
     @Override
     public List<MapStatisticalDto> realTimeMapStatistical(Integer sysId, Integer type, String northEast, String southWest, Integer province, Integer city, Integer region, Integer community) {
@@ -49,7 +52,8 @@ public class StatAndAnalysisServiceImpl implements StatAndAnalysisService {
         Integer userId = null;
         if (loginUser.getRoleType() !=null && loginUser.getRoleType() == 4) userId = loginUser.getId();
 
-        List<BuildingInfoListDto> buildingInfoListDtoList = deviceMapper.getBuildingStatistics(loginUser.getSiteId(),sysId, userId, null, province, city, region,  community, type, longitudeMin, longitudeMax, latitudeMin, latitudeMax);
+        //List<BuildingInfoListDto> buildingInfoListDtoList = deviceMapper.getBuildingStatistics(loginUser.getSiteId(),sysId, userId, null, province, city, region,  community, type, longitudeMin, longitudeMax, latitudeMin, latitudeMax);
+        List<BuildingInfoListDto> buildingInfoListDtoList = communityMapper.getStatistics(loginUser.getSiteId(),sysId, userId, null, province, city, region,  community, type, longitudeMin, longitudeMax, latitudeMin, latitudeMax);
         return this.mapStatistical(type, buildingInfoListDtoList);
     }
 
@@ -133,32 +137,7 @@ public class StatAndAnalysisServiceImpl implements StatAndAnalysisService {
                     }
                 }
             }
-        } 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 {
+        } else  {
             if (provinceIds.size() > 1) {
                 //省
                 List<Area> areaList = areaMapper.findByIds(provinceIds);
@@ -185,30 +164,6 @@ public class StatAndAnalysisServiceImpl implements StatAndAnalysisService {
                             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);
-                                }
-                            }
                         }
                     }
                 }

+ 49 - 0
src/main/resources/mapper/CommunityMapper.xml

@@ -508,5 +508,54 @@
         </if>
     </select>
 
+    <select id="getStatistics" resultType="com.zoniot.ccrc.dto.BuildingInfoListDto">
+        select
+        sc.id as building_id,
+        sc.name as building_name,
+        sc.address ,
+        sc.province,
+        sc.city,
+        sc.region,
+        sc.id as community,
+        sa1.name as province_name,
+        sa2.name as city_name,
+        sa3.name as region_name,
+        sc.name as community_name,
+        sc.latitude,
+        sc.longitude,
+        temp.device_count,
+        temp.normal_count,
+        temp.alarm_count
+        from sc_community sc
+        LEFT JOIN(
+        SELECT
+        sd.community_id,
+        <if test="sysId != null">sd.sys_id,</if>
+        count(1) as device_count,
+        SUM(IF(sd.device_status = 0, 1, 0)) as alarm_count,
+        SUM(IF(sd.device_status = 1, 1, 0)) as normal_count
+        from sc_device sd
+        <if test="userId != null"> left join sc_grid_management scm on(scm.device_id = sd.id and scm.status = 1) </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.community_id <if test="sysId != null">,sd.sys_id</if>
+        ) temp on (sc.id = temp.community_id)
+        left join sc_area sa1 on sa1.id = sc.province
+        left join sc_area sa2 on sa2.id = sc.city
+        left join sc_area sa3 on sa3.id = sc.region
+        where sc.status = 1
+        <if test="siteId != null"> and sc.site_id = #{siteId} </if>
+        <if test="sysId != null"> and temp.sys_id = #{sysId} </if>
+        <if test="province != null"> AND sc.province = #{province}</if>
+        <if test="city != null"> AND sc.city = #{city}</if>
+        <if test="region != null"> AND sc.region = #{region}</if>
+        <if test="community != null"> AND sc.id = #{community}</if>
+        <if test="type != null and (type == 4 or type == 5) and longitudeMin != 0 and longitudeMax != 0"> and sc.longitude > #{longitudeMin} AND sc.longitude <![CDATA[  < ]]> #{longitudeMax} </if>
+        <if test="type != null and (type == 4 or type == 5) and latitudeMin != 0 and latitudeMax != 0"> and sc.latitude > #{latitudeMin} AND sc.latitude <![CDATA[  < ]]> #{latitudeMax} </if>
+        order by sc.date_create desc
+    </select>
 </mapper>
 

+ 17 - 18
src/main/resources/mapper/DeviceMapper.xml

@@ -537,21 +537,20 @@
 
   <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,
+    sc.id,
+    sc.name,
+    sc.province,
+    sc.city,
+    sc.region,
+    sc.id as community,
+    sc.longitude,
+    sc.latitude,
     t1.device_count
-    from sc_building b
+    from sc_community sc
     right join (
-    select sd.building_id,count(1) as device_count
+    select sd.community_id,count(1) as device_count
     from sc_device sd
     left join sc_grid_management sgm on(sgm.device_id = sd.id and sgm.status = 1)
-    <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>
@@ -559,9 +558,9 @@
     <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="province != null"> and sc.province = #{province}</if>
+    <if test="city != null"> and sc.city = #{city}</if>
+    <if test="region != null"> and sc.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>
@@ -572,10 +571,10 @@
     <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>
+    GROUP BY sd.community_id
+    ) t1 on (t1.community_id = sc.id)
+    where sc.status = 1
+    <if test="siteId != null"> and sc.site_id=#{siteId} </if>
   </select>
   <select id="getDeviceIdByUserNumber" resultType="java.lang.Long">
     select b.id

+ 59 - 0
src/main/resources/mapper/MeterReadRecordMapper.xml

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zoniot.ccrc.dao.MeterReadRecordMapper">
+  <resultMap id="BaseResultMap" type="com.zoniot.ccrc.entity.MeterReadRecord">
+    <!--@mbg.generated-->
+    <!--@Table sc_meter_read_record-->
+    <id column="id" property="id" />
+    <result column="read_date" property="readDate" />
+    <result column="site_id" property="siteId" />
+    <result column="sys_id" property="sysId" />
+    <result column="province" property="province" />
+    <result column="city" property="city" />
+    <result column="region" property="region" />
+    <result column="community" property="community" />
+    <result column="customer_id" property="customerId" />
+    <result column="concentrator_id" property="concentratorId" />
+    <result column="collector_id" property="collectorId" />
+    <result column="building_id" property="buildingId" />
+    <result column="location" property="location" />
+    <result column="device_type_id" property="deviceTypeId" />
+    <result column="device_id" property="deviceId" />
+    <result column="device_no" property="deviceNo" />
+    <result column="meter_no" property="meterNo" />
+    <result column="meter_file_no" property="meterFileNo" />
+    <result column="read_time" property="readTime" />
+    <result column="read_status" property="readStatus" />
+    <result column="read_data" property="readData" />
+    <result column="last_valid" property="lastValid" />
+    <result column="last_cost" property="lastCost" />
+    <result column="status" property="status" />
+    <result column="date_create" property="dateCreate" />
+    <result column="date_update" property="dateUpdate" />
+    <result column="create_by" property="createBy" />
+    <result column="update_by" property="updateBy" />
+    <result column="valve_status" property="valveStatus" />
+    <result column="meter_status_info" property="meterStatusInfo" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--@mbg.generated-->
+    id, read_date, site_id, sys_id, province, city, region, community, customer_id, concentrator_id, 
+    collector_id, building_id, `location`, device_type_id, device_id, device_no, meter_no, 
+    meter_file_no, read_time, read_status, read_data, last_valid, last_cost, `status`, 
+    date_create, date_update, create_by, update_by, valve_status, meter_status_info
+  </sql>
+
+  <select id="getList" resultMap="BaseResultMap">
+    select
+    id,
+    device_id,
+    read_data,
+    valve_status,
+    meter_status_info,
+    read_time
+    from sc_meter_read_record where status = 1 and device_id = #{deviceId} and read_status = '2'
+    <if test="startDate != null and startDate != 0"> and read_date <![CDATA[ >= ]]> #{startDate} </if>
+    <if test="endDate != null and endDate != 0"> and read_date <![CDATA[ <= ]]> #{endDate} </if>
+    order by date_create desc
+  </select>
+</mapper>