Bladeren bron

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/zoniot/ccrc/dao/MeterReadRecordMapper.java
#	src/main/java/com/zoniot/ccrc/entity/MeterReadRecord.java
#	src/main/resources/mapper/MeterReadRecordMapper.xml
hym 3 jaren geleden
bovenliggende
commit
59aa3da693
21 gewijzigde bestanden met toevoegingen van 424 en 718 verwijderingen
  1. 61 0
      src/main/java/com/zoniot/ccrc/commom/utils/Jdk8DateUtils.java
  2. 1 1
      src/main/java/com/zoniot/ccrc/controller/RealTimeMonitorController.java
  3. 2 4
      src/main/java/com/zoniot/ccrc/controller/system/CommunityManagerController.java
  4. 41 1
      src/main/java/com/zoniot/ccrc/controller/system/DeviceController.java
  5. 16 0
      src/main/java/com/zoniot/ccrc/dao/CommunityMapper.java
  6. 1 41
      src/main/java/com/zoniot/ccrc/dao/MeterReadRecordMapper.java
  7. 4 0
      src/main/java/com/zoniot/ccrc/dto/WarningLogDto.java
  8. 2 2
      src/main/java/com/zoniot/ccrc/entity/Device.java
  9. 51 142
      src/main/java/com/zoniot/ccrc/entity/MeterReadRecord.java
  10. 1 1
      src/main/java/com/zoniot/ccrc/rabbit/SyncBuildingReceiver.java
  11. 1 1
      src/main/java/com/zoniot/ccrc/rabbit/SyncCommunityReceiver.java
  12. 1 1
      src/main/java/com/zoniot/ccrc/rabbit/SyncDeviceReceiver.java
  13. 14 0
      src/main/java/com/zoniot/ccrc/service/MeterReadRecordService.java
  14. 9 14
      src/main/java/com/zoniot/ccrc/service/impl/BuildingServiceImpl.java
  15. 7 11
      src/main/java/com/zoniot/ccrc/service/impl/DeviceServiceImpl.java
  16. 83 0
      src/main/java/com/zoniot/ccrc/service/impl/MeterReadRecordServiceImpl.java
  17. 6 51
      src/main/java/com/zoniot/ccrc/service/impl/StatAndAnalysisServiceImpl.java
  18. 49 0
      src/main/resources/mapper/CommunityMapper.xml
  19. 17 18
      src/main/resources/mapper/DeviceMapper.xml
  20. 43 417
      src/main/resources/mapper/MeterReadRecordMapper.xml
  21. 14 13
      src/main/resources/mapper/WarningLogMapper.xml

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

+ 2 - 4
src/main/java/com/zoniot/ccrc/controller/system/CommunityManagerController.java

@@ -66,7 +66,6 @@ public class CommunityManagerController {
 
 	@GetMapping("getCommunityPage")
 	@ApiOperation(value = "获取小区列表分页", notes = "权限:sys:community:query")
-
 	public AjaxMessage<Pagination<CommunityDto>> getCommunityPage(
 			@ApiParam(value = "小区名称", required = false) @RequestParam(required = false) String communityName,
 			@ApiParam(value = "省", required = false) @RequestParam(required = false) Integer province,
@@ -82,7 +81,7 @@ public class CommunityManagerController {
 
 	@PostMapping("add")
 	@ApiOperation(value = "添加小区", notes = "权限:sys:community:add")
-	@PreAuthorize("hasAuthority('sys:community:add')")
+	//@PreAuthorize("hasAuthority('sys:community:add')")
 	public AjaxMessage addCommunity(
 			@ApiParam(value = "小区", required = true) @RequestBody(required = true) @Validated CommunityDto communityDto
 	) {
@@ -92,7 +91,7 @@ public class CommunityManagerController {
 
 	@PutMapping("edit")
 	@ApiOperation(value = "编辑小区", notes = "权限:sys:community:edit")
-	@PreAuthorize("hasAuthority('sys:community:edit')")
+	//@PreAuthorize("hasAuthority('sys:community:edit')")
 	public AjaxMessage editCommunity(
 			@ApiParam(value = "小区", required = true) @RequestBody(required = true) @Validated Community community
 	) {
@@ -111,7 +110,6 @@ public class CommunityManagerController {
 	}
 	@GetMapping("getOrgCommunity")
 	@ApiOperation(value = "获取机构小区")
-
 	public AjaxMessage getOrgCommunity(
 			@ApiParam(value = "小区Id") @RequestParam(required = false) Integer orgId,
 			@ApiParam(value = "区域Id") @RequestParam(required = false) Integer areaId

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

+ 1 - 41
src/main/java/com/zoniot/ccrc/dao/MeterReadRecordMapper.java

@@ -1,53 +1,13 @@
 package com.zoniot.ccrc.dao;
 
-
-import com.zoniot.ccrc.dto.UseWaterDto;
 import com.zoniot.ccrc.entity.MeterReadRecord;
-import com.zoniot.ccrc.repository.MongoMeterReadRecord;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
-/**
- * <p></p>
- * @Author wilian.peng
- * @Date 2020/12/22 16:59
- * @Version 1.0
- */
 @Mapper
 public interface MeterReadRecordMapper {
-    int deleteByPrimaryKey(Long id);
-
-    int insert(MeterReadRecord record);
-
-    int insertSelective(MeterReadRecord record);
-
-    MeterReadRecord selectByPrimaryKey(Long id);
-
-    MeterReadRecord findRecordByReadDayAndDeviceId(@Param("deviceId") Long deviceId, @Param("readDate") Integer readDate);
-
-    int deleteRecordByReadDayAndDeviceId(@Param("deviceId") Long deviceId, @Param("readDate") Integer readDate);
-
-    int updateByPrimaryKeySelective(MeterReadRecord record);
-
-    int updateByPrimaryKey(MeterReadRecord record);
-
-    int batchInsert(@Param("list") List<MeterReadRecord> list);
-
-    List<UseWaterDto> getRealTimeUseWater(@Param("deviceId")Long deviceId,
-                                          @Param("startDate")Integer startDate,
-                                          @Param("endDate") Integer endDate);
-
-    List<UseWaterDto> getUseWaterByMonth(@Param("deviceId")Long deviceId,
-                                         @Param("startDate")Integer startDate,
-                                         @Param("endDate")Integer endDate);
-
-    Double getDeviceVolume(@Param("deviceId")Long deviceId,
-                           @Param("startDate")Integer startDate,
-                           @Param("endDate")Integer endDate);
 
-    List<MongoMeterReadRecord> getYesterReadData(
-            @Param("deviceId")Long deviceId,
-            @Param("date")Integer date);
+    List<MeterReadRecord> getList(@Param("deviceId") Long deviceId, @Param("startDate") Integer startDate, @Param("endDate") Integer endDate);
 }

+ 4 - 0
src/main/java/com/zoniot/ccrc/dto/WarningLogDto.java

@@ -24,6 +24,9 @@ public class WarningLogDto extends WarningLog {
     @ApiModelProperty(value = "水表电子号", position = 105)
     private String waterMeterNo;
 
+    @ApiModelProperty(value = "档案号", position = 105)
+    private String fileNo;
+
     @ApiModelProperty(value = "系列", position = 106)
     private String equipmentType;
 
@@ -35,5 +38,6 @@ public class WarningLogDto extends WarningLog {
 
     @ApiModelProperty(value = "位置描述", position = 109)
     private String locDesc;
+
     private String meterCode;
 }

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

+ 51 - 142
src/main/java/com/zoniot/ccrc/entity/MeterReadRecord.java

@@ -1,201 +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;
-import org.springframework.data.mongodb.core.mapping.Document;
-
-import java.io.Serializable;
-import java.util.Date;
-import java.util.Map;
-
-/**
- * <p>抄表记录</p>
- * sh.enableSharding("meter-reading-database");
- * sh.shardCollection("meter-reading-database.sc_meter_read_record",{"readDate":1,"deviceId":1});
- * db.sc_meter_read_record.createIndex({readDate:1,customerId:1,buildingId:1,siteId:1,sysId:1,readStatus:1,concentratorId:1},{background: true,name:'idx_1'})
- * @Author wilian.peng
- * @Date 2020/12/22 16:59
- * @Version 1.0
- */
+
+@ApiModel(value="com-zoniot-ccrc-entity-MeterReadRecord")
 @Data
-@Document(collection = "sc_meter_read_record")
-public class MeterReadRecord implements Serializable {
-    /**
-    * 主键
-    */
+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;
 
-    /**
-    * 设备id
-    */
+    @ApiModelProperty(value="设备id")
     private Long deviceId;
 
-    /**
-    * 节点编号
-    */
+    @ApiModelProperty(value="节点编号")
     private String deviceNo;
 
-    /**
-    * 电子号
-    */
+    @ApiModelProperty(value="电子号")
     private String meterNo;
 
-    /**
-    * 档案号
-    */
+    @ApiModelProperty(value="档案号")
     private String meterFileNo;
 
-    /**
-    * 读表时间
-    */
-    private Date readTime;
+    @ApiModelProperty(value="读表时间")
+    private LocalDateTime readTime;
 
-    /**
-    * 读表状态
-    */
+    @ApiModelProperty(value="读表状态")
     private String readStatus;
 
-    /**
-    * 读表数据
-    */
-    private String readData;
 
-    /**
-     * 阀门状态
-     * 0:关 1:开 2:无阀 3:异常
-     */
-    private Integer valveState ;
+    @ApiModelProperty(value="读表数据")
+    private String readData;
 
-    /**
-    * 最近有效数据
-    */
+    @ApiModelProperty(value="最近有效数据")
     private String lastValid;
 
-    /**
-    * 距离上次的消耗
-    */
-    private Double lastCost;
+    @ApiModelProperty(value="距离上次的消耗")
+    private BigDecimal lastCost;
 
-    /**
-    * 状态
-    */
+    @ApiModelProperty(value="状态")
     private Integer status;
 
-    /**
-    * 创建时间
-    */
-    private Date dateCreate;
+    @ApiModelProperty(value="创建时间")
+    private LocalDateTime dateCreate;
 
-    /**
-    * 更新时间
-    */
-    private Date dateUpdate;
+    @ApiModelProperty(value="更新时间")
+    private LocalDateTime dateUpdate;
 
-    /**
-    * 创建人
-    */
+    @ApiModelProperty(value="创建人")
     private String createBy;
 
-    /**
-    * 更新人
-    */
+    @ApiModelProperty(value="更新人")
     private String updateBy;
 
-    /***********************************以下字段将存入MongoDB中**************************************/
-    private String communityName;
-
-    private String buildingName ;
+    @ApiModelProperty(value="阀门状态")
+    private Integer valveStatus;
 
-    private String customerName ;
-
-    private String provinceName ;
-
-    private String cityName ;
-
-    private String regionName ;
-
-    private String deviceTypeName ;
-
-    private String concentratorNo ;
-
-    private String collectorNo ;
-
-    private Integer manufacturerId ;
-
-    private String manufacturerName ;
-
-    private Integer channelNumberId;
-
-    private String channelName ;
+    @ApiModelProperty(value="告警信息")
     private String meterStatusInfo;
-
-    /**
-     * 最后上送数据,格式如下:
-     * {"数据ID":11111,data:{"WSV":"1","VOL":"2.5"}}
-     */
-    private Map<String, String> lastSendData ;
 }

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

+ 7 - 11
src/main/java/com/zoniot/ccrc/service/impl/DeviceServiceImpl.java

@@ -84,10 +84,8 @@ public class DeviceServiceImpl implements DeviceService{
         if (orgId != null) communityIds = organizationMapper.findCommunityIds(orgId);
         List<DeviceDto> list = deviceMapper.getList(loginUser.getSiteId(),userId,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,communityIds,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[]{"序号", "水表档案号", "水表电子号", "设备状态", "当前读数", "机构", "客户编号", "客户名称", "手机号", "标签","建筑","安装地址","网格员"};
+        //设备编号、水表档案号、设备状态、当前读数、机构、客户编号、客户名称、手机号、标签、小区、安装地址、网格员
+        String[] rowsName = new String[]{"序号", "设备编号", "水表档案号", "设备状态", "当前读数", "机构", "客户编号", "客户名称", "手机号", "标签","小区","安装地址","网格员"};
 
         List<Object[]> dataList = newArrayList();
         Object[] objs = null;
@@ -95,8 +93,8 @@ public class DeviceServiceImpl implements DeviceService{
             DeviceDto data = list.get(i);
             objs = new Object[rowsName.length];
             objs[0] = i;
-            objs[1] = data.getFileNo();
-            objs[2] = data.getMeterNo();
+            objs[1] = data.getDeviceNo();
+            objs[2] = data.getFileNo();
             objs[3] = getDeviceStatusName(data.getDeviceStatus());
             objs[4] = data.getMeterReading();
             objs[5] = data.getOrgName();
@@ -104,7 +102,7 @@ public class DeviceServiceImpl implements DeviceService{
             objs[7] = data.getCustomerName();
             objs[8] = data.getCustomerPhone();
             objs[9] = data.getLabel();
-            objs[10] = data.getBuildingName();
+            objs[10] = data.getCommunityName();
             objs[11] = data.getLocDesc();
             objs[12] = data.getUsername();
 
@@ -120,11 +118,9 @@ public class DeviceServiceImpl implements DeviceService{
     }
 
     private String getDeviceStatusName(Integer deviceStatus){
-        //1:正常 2:故障 3:无 4: 预警 5:未启用
+        //1:正常 0:告警
         if (deviceStatus == 1) return  "正常";
-        if (deviceStatus == 2) return  "故障";
-        if (deviceStatus == 4) return  "预警";
-        if (deviceStatus == 5) return  "未启用";
+        if (deviceStatus == 0) return  "告警";
         return "";
     }
 

+ 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

@@ -509,5 +509,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

+ 43 - 417
src/main/resources/mapper/MeterReadRecordMapper.xml

@@ -4,430 +4,56 @@
   <resultMap id="BaseResultMap" type="com.zoniot.ccrc.entity.MeterReadRecord">
     <!--@mbg.generated-->
     <!--@Table sc_meter_read_record-->
-    <id column="id" jdbcType="BIGINT" property="id" />
-    <result column="read_date" jdbcType="INTEGER" property="readDate" />
-    <result column="site_id" jdbcType="INTEGER" property="siteId" />
-    <result column="sys_id" jdbcType="INTEGER" property="sysId" />
-    <result column="province" jdbcType="INTEGER" property="province" />
-    <result column="city" jdbcType="INTEGER" property="city" />
-    <result column="region" jdbcType="INTEGER" property="region" />
-    <result column="community" jdbcType="INTEGER" property="community" />
-    <result column="customer_id" jdbcType="INTEGER" property="customerId" />
-    <result column="concentrator_id" jdbcType="INTEGER" property="concentratorId" />
-    <result column="collector_id" jdbcType="INTEGER" property="collectorId" />
-    <result column="building_id" jdbcType="INTEGER" property="buildingId" />
-    <result column="location" jdbcType="VARCHAR" property="location" />
-    <result column="device_type_id" jdbcType="INTEGER" property="deviceTypeId" />
-    <result column="device_id" jdbcType="BIGINT" property="deviceId" />
-    <result column="device_no" jdbcType="VARCHAR" property="deviceNo" />
-    <result column="meter_no" jdbcType="VARCHAR" property="meterNo" />
-    <result column="meter_file_no" jdbcType="VARCHAR" property="meterFileNo" />
-    <result column="read_time" jdbcType="TIMESTAMP" property="readTime" />
-    <result column="read_status" jdbcType="VARCHAR" property="readStatus" />
-    <result column="read_data" jdbcType="VARCHAR" property="readData" />
-    <result column="last_valid" jdbcType="VARCHAR" property="lastValid" />
-    <result column="last_cost" jdbcType="DECIMAL" property="lastCost" />
-    <result column="status" jdbcType="INTEGER" property="status" />
-    <result column="date_create" jdbcType="TIMESTAMP" property="dateCreate" />
-    <result column="date_update" jdbcType="TIMESTAMP" property="dateUpdate" />
-    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
-    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
+    <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
+    date_create, date_update, create_by, update_by, valve_status, meter_status_info
   </sql>
-  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
-    <!--@mbg.generated-->
-    select 
-    <include refid="Base_Column_List" />
-    from sc_meter_read_record
-    where id = #{id,jdbcType=BIGINT}
-  </select>
-  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
-    <!--@mbg.generated-->
-    delete from sc_meter_read_record
-    where id = #{id,jdbcType=BIGINT}
-  </delete>
-  <insert id="insert" parameterType="com.zoniot.ccrc.entity.MeterReadRecord">
-    <!--@mbg.generated-->
-    insert into sc_meter_read_record (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)
-    values (#{id,jdbcType=BIGINT}, #{readDate,jdbcType=INTEGER}, #{siteId,jdbcType=INTEGER}, 
-      #{sysId,jdbcType=INTEGER}, #{province,jdbcType=INTEGER}, #{city,jdbcType=INTEGER}, 
-      #{region,jdbcType=INTEGER}, #{community,jdbcType=INTEGER}, #{customerId,jdbcType=INTEGER}, 
-      #{concentratorId,jdbcType=INTEGER}, #{collectorId,jdbcType=INTEGER}, #{buildingId,jdbcType=INTEGER}, 
-      #{location,jdbcType=VARCHAR}, #{deviceTypeId,jdbcType=INTEGER}, #{deviceId,jdbcType=BIGINT}, 
-      #{deviceNo,jdbcType=VARCHAR}, #{meterNo,jdbcType=VARCHAR}, #{meterFileNo,jdbcType=VARCHAR}, 
-      #{readTime,jdbcType=TIMESTAMP}, #{readStatus,jdbcType=VARCHAR}, #{readData,jdbcType=VARCHAR}, 
-      #{lastValid,jdbcType=VARCHAR}, #{lastCost,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER}, 
-      #{dateCreate,jdbcType=TIMESTAMP}, #{dateUpdate,jdbcType=TIMESTAMP}, #{createBy,jdbcType=VARCHAR}, 
-      #{updateBy,jdbcType=VARCHAR})
-  </insert>
-  <insert id="insertSelective" parameterType="com.zoniot.ccrc.entity.MeterReadRecord">
-    <!--@mbg.generated-->
-    insert into sc_meter_read_record
-    <trim prefix="(" suffix=")" suffixOverrides=",">
-      <if test="id != null">
-        id,
-      </if>
-      <if test="readDate != null">
-        read_date,
-      </if>
-      <if test="siteId != null">
-        site_id,
-      </if>
-      <if test="sysId != null">
-        sys_id,
-      </if>
-      <if test="province != null">
-        province,
-      </if>
-      <if test="city != null">
-        city,
-      </if>
-      <if test="region != null">
-        region,
-      </if>
-      <if test="community != null">
-        community,
-      </if>
-      <if test="customerId != null">
-        customer_id,
-      </if>
-      <if test="concentratorId != null">
-        concentrator_id,
-      </if>
-      <if test="collectorId != null">
-        collector_id,
-      </if>
-      <if test="buildingId != null">
-        building_id,
-      </if>
-      <if test="location != null">
-        `location`,
-      </if>
-      <if test="deviceTypeId != null">
-        device_type_id,
-      </if>
-      <if test="deviceId != null">
-        device_id,
-      </if>
-      <if test="deviceNo != null">
-        device_no,
-      </if>
-      <if test="meterNo != null">
-        meter_no,
-      </if>
-      <if test="meterFileNo != null">
-        meter_file_no,
-      </if>
-      <if test="readTime != null">
-        read_time,
-      </if>
-      <if test="readStatus != null">
-        read_status,
-      </if>
-      <if test="readData != null">
-        read_data,
-      </if>
-      <if test="lastValid != null">
-        last_valid,
-      </if>
-      <if test="lastCost != null">
-        last_cost,
-      </if>
-      <if test="status != null">
-        `status`,
-      </if>
-      <if test="dateCreate != null">
-        date_create,
-      </if>
-      <if test="dateUpdate != null">
-        date_update,
-      </if>
-      <if test="createBy != null">
-        create_by,
-      </if>
-      <if test="updateBy != null">
-        update_by,
-      </if>
-    </trim>
-    <trim prefix="values (" suffix=")" suffixOverrides=",">
-      <if test="id != null">
-        #{id,jdbcType=BIGINT},
-      </if>
-      <if test="readDate != null">
-        #{readDate,jdbcType=INTEGER},
-      </if>
-      <if test="siteId != null">
-        #{siteId,jdbcType=INTEGER},
-      </if>
-      <if test="sysId != null">
-        #{sysId,jdbcType=INTEGER},
-      </if>
-      <if test="province != null">
-        #{province,jdbcType=INTEGER},
-      </if>
-      <if test="city != null">
-        #{city,jdbcType=INTEGER},
-      </if>
-      <if test="region != null">
-        #{region,jdbcType=INTEGER},
-      </if>
-      <if test="community != null">
-        #{community,jdbcType=INTEGER},
-      </if>
-      <if test="customerId != null">
-        #{customerId,jdbcType=INTEGER},
-      </if>
-      <if test="concentratorId != null">
-        #{concentratorId,jdbcType=INTEGER},
-      </if>
-      <if test="collectorId != null">
-        #{collectorId,jdbcType=INTEGER},
-      </if>
-      <if test="buildingId != null">
-        #{buildingId,jdbcType=INTEGER},
-      </if>
-      <if test="location != null">
-        #{location,jdbcType=VARCHAR},
-      </if>
-      <if test="deviceTypeId != null">
-        #{deviceTypeId,jdbcType=INTEGER},
-      </if>
-      <if test="deviceId != null">
-        #{deviceId,jdbcType=BIGINT},
-      </if>
-      <if test="deviceNo != null">
-        #{deviceNo,jdbcType=VARCHAR},
-      </if>
-      <if test="meterNo != null">
-        #{meterNo,jdbcType=VARCHAR},
-      </if>
-      <if test="meterFileNo != null">
-        #{meterFileNo,jdbcType=VARCHAR},
-      </if>
-      <if test="readTime != null">
-        #{readTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="readStatus != null">
-        #{readStatus,jdbcType=VARCHAR},
-      </if>
-      <if test="readData != null">
-        #{readData,jdbcType=VARCHAR},
-      </if>
-      <if test="lastValid != null">
-        #{lastValid,jdbcType=VARCHAR},
-      </if>
-      <if test="lastCost != null">
-        #{lastCost,jdbcType=DECIMAL},
-      </if>
-      <if test="status != null">
-        #{status,jdbcType=INTEGER},
-      </if>
-      <if test="dateCreate != null">
-        #{dateCreate,jdbcType=TIMESTAMP},
-      </if>
-      <if test="dateUpdate != null">
-        #{dateUpdate,jdbcType=TIMESTAMP},
-      </if>
-      <if test="createBy != null">
-        #{createBy,jdbcType=VARCHAR},
-      </if>
-      <if test="updateBy != null">
-        #{updateBy,jdbcType=VARCHAR},
-      </if>
-    </trim>
-  </insert>
-  <update id="updateByPrimaryKeySelective" parameterType="com.zoniot.ccrc.entity.MeterReadRecord">
-    <!--@mbg.generated-->
-    update sc_meter_read_record
-    <set>
-      <if test="readDate != null">
-        read_date = #{readDate,jdbcType=INTEGER},
-      </if>
-      <if test="siteId != null">
-        site_id = #{siteId,jdbcType=INTEGER},
-      </if>
-      <if test="sysId != null">
-        sys_id = #{sysId,jdbcType=INTEGER},
-      </if>
-      <if test="province != null">
-        province = #{province,jdbcType=INTEGER},
-      </if>
-      <if test="city != null">
-        city = #{city,jdbcType=INTEGER},
-      </if>
-      <if test="region != null">
-        region = #{region,jdbcType=INTEGER},
-      </if>
-      <if test="community != null">
-        community = #{community,jdbcType=INTEGER},
-      </if>
-      <if test="customerId != null">
-        customer_id = #{customerId,jdbcType=INTEGER},
-      </if>
-      <if test="concentratorId != null">
-        concentrator_id = #{concentratorId,jdbcType=INTEGER},
-      </if>
-      <if test="collectorId != null">
-        collector_id = #{collectorId,jdbcType=INTEGER},
-      </if>
-      <if test="buildingId != null">
-        building_id = #{buildingId,jdbcType=INTEGER},
-      </if>
-      <if test="location != null">
-        `location` = #{location,jdbcType=VARCHAR},
-      </if>
-      <if test="deviceTypeId != null">
-        device_type_id = #{deviceTypeId,jdbcType=INTEGER},
-      </if>
-      <if test="deviceId != null">
-        device_id = #{deviceId,jdbcType=BIGINT},
-      </if>
-      <if test="deviceNo != null">
-        device_no = #{deviceNo,jdbcType=VARCHAR},
-      </if>
-      <if test="meterNo != null">
-        meter_no = #{meterNo,jdbcType=VARCHAR},
-      </if>
-      <if test="meterFileNo != null">
-        meter_file_no = #{meterFileNo,jdbcType=VARCHAR},
-      </if>
-      <if test="readTime != null">
-        read_time = #{readTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="readStatus != null">
-        read_status = #{readStatus,jdbcType=VARCHAR},
-      </if>
-      <if test="readData != null">
-        read_data = #{readData,jdbcType=VARCHAR},
-      </if>
-      <if test="lastValid != null">
-        last_valid = #{lastValid,jdbcType=VARCHAR},
-      </if>
-      <if test="lastCost != null">
-        last_cost = #{lastCost,jdbcType=DECIMAL},
-      </if>
-      <if test="status != null">
-        `status` = #{status,jdbcType=INTEGER},
-      </if>
-      <if test="dateCreate != null">
-        date_create = #{dateCreate,jdbcType=TIMESTAMP},
-      </if>
-      <if test="dateUpdate != null">
-        date_update = #{dateUpdate,jdbcType=TIMESTAMP},
-      </if>
-      <if test="createBy != null">
-        create_by = #{createBy,jdbcType=VARCHAR},
-      </if>
-      <if test="updateBy != null">
-        update_by = #{updateBy,jdbcType=VARCHAR},
-      </if>
-    </set>
-    where id = #{id,jdbcType=BIGINT}
-  </update>
-  <update id="updateByPrimaryKey" parameterType="com.zoniot.ccrc.entity.MeterReadRecord">
-    <!--@mbg.generated-->
-    update sc_meter_read_record
-    set read_date = #{readDate,jdbcType=INTEGER},
-      site_id = #{siteId,jdbcType=INTEGER},
-      sys_id = #{sysId,jdbcType=INTEGER},
-      province = #{province,jdbcType=INTEGER},
-      city = #{city,jdbcType=INTEGER},
-      region = #{region,jdbcType=INTEGER},
-      community = #{community,jdbcType=INTEGER},
-      customer_id = #{customerId,jdbcType=INTEGER},
-      concentrator_id = #{concentratorId,jdbcType=INTEGER},
-      collector_id = #{collectorId,jdbcType=INTEGER},
-      building_id = #{buildingId,jdbcType=INTEGER},
-      `location` = #{location,jdbcType=VARCHAR},
-      device_type_id = #{deviceTypeId,jdbcType=INTEGER},
-      device_id = #{deviceId,jdbcType=BIGINT},
-      device_no = #{deviceNo,jdbcType=VARCHAR},
-      meter_no = #{meterNo,jdbcType=VARCHAR},
-      meter_file_no = #{meterFileNo,jdbcType=VARCHAR},
-      read_time = #{readTime,jdbcType=TIMESTAMP},
-      read_status = #{readStatus,jdbcType=VARCHAR},
-      read_data = #{readData,jdbcType=VARCHAR},
-      last_valid = #{lastValid,jdbcType=VARCHAR},
-      last_cost = #{lastCost,jdbcType=DECIMAL},
-      `status` = #{status,jdbcType=INTEGER},
-      date_create = #{dateCreate,jdbcType=TIMESTAMP},
-      date_update = #{dateUpdate,jdbcType=TIMESTAMP},
-      create_by = #{createBy,jdbcType=VARCHAR},
-      update_by = #{updateBy,jdbcType=VARCHAR}
-    where id = #{id,jdbcType=BIGINT}
-  </update>
-  <insert id="batchInsert" parameterType="map">
-    <!--@mbg.generated-->
-    replace into sc_meter_read_record
-    (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)
-    values
-    <foreach collection="list" item="item" separator=",">
-      (#{item.id,jdbcType=BIGINT}, #{item.readDate,jdbcType=INTEGER}, #{item.siteId,jdbcType=INTEGER}, 
-        #{item.sysId,jdbcType=INTEGER}, #{item.province,jdbcType=INTEGER}, #{item.city,jdbcType=INTEGER}, 
-        #{item.region,jdbcType=INTEGER}, #{item.community,jdbcType=INTEGER}, #{item.customerId,jdbcType=INTEGER}, 
-        #{item.concentratorId,jdbcType=INTEGER}, #{item.collectorId,jdbcType=INTEGER}, 
-        #{item.buildingId,jdbcType=INTEGER}, #{item.location,jdbcType=VARCHAR}, #{item.deviceTypeId,jdbcType=INTEGER}, 
-        #{item.deviceId,jdbcType=BIGINT}, #{item.deviceNo,jdbcType=VARCHAR}, #{item.meterNo,jdbcType=VARCHAR}, 
-        #{item.meterFileNo,jdbcType=VARCHAR}, #{item.readTime,jdbcType=TIMESTAMP}, #{item.readStatus,jdbcType=VARCHAR}, 
-        #{item.readData,jdbcType=VARCHAR}, #{item.lastValid,jdbcType=VARCHAR}, #{item.lastCost,jdbcType=DECIMAL}, 
-        #{item.status,jdbcType=INTEGER}, #{item.dateCreate,jdbcType=TIMESTAMP}, #{item.dateUpdate,jdbcType=TIMESTAMP}, 
-        #{item.createBy,jdbcType=VARCHAR}, #{item.updateBy,jdbcType=VARCHAR},
-       #{item.valveState,jdbcType=INTEGER}, #{item.meterStatusInfo,jdbcType=VARCHAR})
-    </foreach>
-  </insert>
-  <select id="findRecordByReadDayAndDeviceId" resultMap="BaseResultMap">
+
+  <select id="getList" resultMap="BaseResultMap">
     select
-        <include refid="Base_Column_List" />
-    from
-      sc_meter_read_record
-    where
-        status = 1
-    and read_date = #{readDate,jdbcType=INTEGER}
-    and device_id = #{deviceId,jdbcType=BIGINT}
-  </select>
-  <select id="getDeviceVolume" resultType="java.lang.Double">
-    select ifnull(sum(last_cost),0) from sc_meter_read_record
-    where status = 1 and device_id = #{deviceId} and
-      read_date <![CDATA[ >= ]]> #{startDate} and read_date <![CDATA[ <= ]]> #{endDate}
-  </select>
-  <select id="getRealTimeUseWater" resultType="com.zoniot.ccrc.dto.UseWaterDto">
-    select read_date as date,last_cost as use_volume from sc_meter_read_record
-    where status = 1 and device_id = #{deviceId} and
-      read_date <![CDATA[ >= ]]> #{startDate} and read_date <![CDATA[ <= ]]> #{endDate}
-    order by read_data asc
-  </select>
-  <select id="getUseWaterByMonth" resultType="com.zoniot.ccrc.dto.UseWaterDto">
-    SELECT DATE_FORMAT(read_date,'%Y%m') as date,sum(last_cost) as useVolume FROM sc_meter_read_record
-    where status = 1 and device_id = #{deviceId}
-      and read_date <![CDATA[ >= ]]> #{startDate} and read_date <![CDATA[ <= ]]> #{endDate}
-    GROUP BY  date
-  </select>
-  <select id="getYesterReadData" resultType="com.zoniot.ccrc.repository.MongoMeterReadRecord">
-    select last_cost from sc_meter_read_record where status = 1 and device_id = #{deviceId}
-    and read_date=#{date}
+    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>
-  <update id="deleteRecordByReadDayAndDeviceId">
-    update sc_meter_read_record set status = 0
-    where
-     read_date = #{readDate,jdbcType=INTEGER}
-    and device_id = #{deviceId,jdbcType=BIGINT}
-  </update>
 </mapper>

+ 14 - 13
src/main/resources/mapper/WarningLogMapper.xml

@@ -132,6 +132,7 @@
     swl.*,
     sd.device_no,
     sd.meter_no as water_meter_no,
+    sd.file_no,
     sd.loc_desc,
     sdt1.equipment_type as equipment_type,
     sdt1.model as model,
@@ -170,18 +171,18 @@
 
   <select id="getAreaList" 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_warning_log swl
     left join sc_device sd on(sd.id = swl.device_id)
     left join sc_grid_management sgm on(sgm.device_id = sd.id and sgm.status = 1)
@@ -199,9 +200,9 @@
     <if test="feedbackStatus != null"> and swl.feedback_status = #{feedbackStatus}</if>
     <if test="startDate != null"> and swl.date_create <![CDATA[ >= ]]> #{startDate}</if>
     <if test="endDate != null"> and swl.date_create <![CDATA[ <= ]]> #{endDate}</if>
-    GROUP BY sd.building_id
-    ) t1 on (t1.building_id = b.id)
-    where b.status = 1
+    GROUP BY sd.community_id
+    ) t1 on (t1.community_id = sc.id)
+    where sc.status = 1
   </select>
 
 </mapper>