Browse Source

更改判断条件

hym 3 years ago
parent
commit
549ea702d8

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

@@ -1,6 +1,8 @@
 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;
 
@@ -10,4 +12,23 @@ import java.util.List;
 public interface MeterReadRecordMapper {
 
     List<MeterReadRecord> getList(@Param("deviceId") Long deviceId, @Param("startDate") Integer startDate, @Param("endDate") Integer endDate);
-}
+
+    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);
+    int batchInsert(@Param("list") List<MeterReadRecord> list);
+
+    MeterReadRecord findRecordByReadDayAndDeviceId(Long deviceId, Integer readDate);
+}

+ 5 - 5
src/main/java/com/zoniot/ccrc/scheduled/SyncData.java

@@ -213,12 +213,12 @@ public class SyncData {
         meterReadRecord.setCommunity(waterMeter.getCommunity());
         meterReadRecord.setMeterFileNo(waterMeter.getMeterFileNo());
         meterReadRecord.setMeterNo(waterMeter.getMeterNo());
-        meterReadRecord.setDateCreate(new Date());
+        meterReadRecord.setDateCreate(LocalDateTime.now());
         meterReadRecord.setDeviceId(waterMeter.getDeviceId());
         meterReadRecord.setDeviceNo(waterMeter.getDeviceNo());
         meterReadRecord.setDeviceTypeId(waterMeter.getDeviceTypeId());
         meterReadRecord.setId(snowflakeIdWorker.nextId());
-        meterReadRecord.setLastCost(new Double(0));
+        meterReadRecord.setLastCost(new BigDecimal(0));
         meterReadRecord.setLocation(waterMeter.getLocation());
         meterReadRecord.setCreateBy(Constants.SYS_FLAG);
         meterReadRecord.setStatus(1);
@@ -240,13 +240,13 @@ public class SyncData {
         if(meterRecord!=null){
             String reading=meterRecord.getMeterReading()+"";
             meterReadRecord.setLastValid(reading);
-            meterReadRecord.setReadTime(meterRecord.getReadingTime());
+            //meterReadRecord.setReadTime(meterRecord.getReadingTime());
             meterReadRecord.setReadData(reading);
             Double todayCost = new BigDecimal(calculateTodayCost(reading,
                     new Double(meterReadRecord.getLastValid()),
                     meterReadRecord)).setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue();
-            meterReadRecord.setLastCost(todayCost);
-            meterReadRecord.setValveState(meterRecord.getValveStatus());
+           // meterReadRecord.setLastCost(todayCost);
+           // meterReadRecord.setValveState(meterRecord.getValveStatus());
             meterReadRecord.setMeterStatusInfo(meterRecord.getMeterStatusInfo());
             meterReadRecord.setReadStatus(meterRecord.getMeterStatus()+"");
             setMeterLastDataToCache(meterReadRecord.getDeviceId(),reading);

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

@@ -56,4 +56,57 @@
     <if test="endDate != null and endDate != 0"> and read_date <![CDATA[ <= ]]> #{endDate} </if>
     order by date_create desc
   </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}
+  </select>
+  <select id="findRecordByReadDayAndDeviceId" 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>
+  <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>
 </mapper>