소스 검색

新增 停止灌溉时候 重置所有设备状态为关闭

zhaiyifei 8 달 전
부모
커밋
0ab7438913

+ 15 - 5
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/RunHaoSfDeviceImpl.java

@@ -380,7 +380,8 @@ public class RunHaoSfDeviceImpl extends DeviceAbstractImpl implements IRunHaoSfD
         for(IotRunHaoSfdata iotRunHaoSfdata: iotRunHaoSfdataList){
             iotRunHaoSfdataMap.put(iotRunHaoSfdata.getSfdataBid(), iotRunHaoSfdata);
         }
-        String endDate = DateUtils.dateTimeNow();
+        String endDateStr = DateUtils.dateTimeNow();
+        Date endDate = DateUtils.parseDate(endDateStr);
         for(IotSfIrrigationRecord record: recordList){
             IotRunHaoSfdata iotRunHaoSfdata = iotRunHaoSfdataMap.get(record.getSfdataBid());
             JSONObject sfdataContent = iotRunHaoSfdata.getSfdataContent();
@@ -404,20 +405,29 @@ public class RunHaoSfDeviceImpl extends DeviceAbstractImpl implements IRunHaoSfD
                 totalLL += diffLL;
             }
             StringBuilder rcdContent = new StringBuilder(record.getRcdContent());
-            rcdContent = new StringBuilder(rcdContent.toString().replace(EnumIrrigationRecord.STATUS_RUNNING.getName(), " 灌溉完成d. "));
-
+            rcdContent = new StringBuilder(rcdContent.toString().replace(EnumIrrigationRecord.STATUS_RUNNING.getName(), " 灌溉完成. "));
+            String rcdFertilizer = "";
             for(Map.Entry<IotSfElementfactor, Double> entry: llMap.entrySet()) {
                 IotSfElementfactor elementFactor = entry.getKey();
                 String sfDisplayname = elementFactor.getSfDisplayname();
                 Double diffLL = entry.getValue();
                 String msg = sfDisplayname + "用量:" + diffLL + "L  ";
-                rcdContent.append(msg);
+                rcdFertilizer += msg;
+            }
+
+            Date startDate = DateUtils.parseDate(record.getRcdStartdate());
+            long diff = endDate.getTime() - startDate.getTime();
+            int diffMinutes = (int) (diff / (60 * 1000));
+            if(diffMinutes < 0){
+                diffMinutes = 0;
             }
 
+            record.setRcdFertilizer(rcdFertilizer);
+            record.setRcdTime(diffMinutes);
             record.setRcdContent(rcdContent.toString());
             record.setRcdStatus(EnumIrrigationRecord.STATUS_FINISHED.getCode());
             record.setRcdFlow(totalLL);
-            record.setRcdEnddate(endDate);
+            record.setRcdEnddate(endDateStr);
         }
         iIotSfIrrigationRecordService.batchUpdateIrrigationRecord(recordList);
     }

+ 14 - 2
src/main/resources/mapper/IotSfIrrigationRecordMapper.xml

@@ -22,6 +22,8 @@
                 <if test="rcdCreatorName!= null">rcdCreatorName,</if>
                 <if test="rcdCreateddate!= null">rcdCreateddate,</if>
                 <if test="tid!= null">tid,</if>
+                <if test="rcdTime!= null">rcdTime,</if>
+                <if test="rcdUpdateddate!= null">rcdUpdateddate,</if>
             </trim>
             <trim prefix="values (" suffix=")" suffixOverrides=",">
                 <if test="rcdBid!= null">#{rcdBid},</if>
@@ -39,6 +41,8 @@
                 <if test="rcdCreatorName!= null">#{rcdCreatorName},</if>
                 <if test="rcdCreateddate!= null">#{rcdCreateddate},</if>
                 <if test="tid!= null">#{tid},</if>
+                <if test="rcdTime!= null">#{rcdTime},</if>
+                <if test="rcdFertilizer!= null">#{rcdFertilizer},</if>
             </trim>
     </insert>
     <insert id="batchInsertIotSfIrrigationRecord">
@@ -60,6 +64,8 @@
                 <if test="item.rcdCreatorName!= null">rcdCreatorName,</if>
                 <if test="item.rcdCreateddate!= null">rcdCreateddate,</if>
                 <if test="item.tid!= null">tid,</if>
+                <if test="item.rcdTime!= null">rcdTime,</if>
+                <if test="item.rcdFertilizer!= null">rcdFertilizer,</if>
             </trim>
             <trim prefix="values (" suffix=")" suffixOverrides=",">
                 <if test="item.rcdBid!= null">#{item.rcdBid},</if>
@@ -77,6 +83,8 @@
                 <if test="item.rcdCreatorName!= null">#{item.rcdCreatorName},</if>
                 <if test="item.rcdCreateddate!= null">#{item.rcdCreateddate},</if>
                 <if test="item.tid!= null">#{item.tid},</if>
+                <if test="item.rcdTime!= null">#{item.rcdTime},</if>
+                <if test="item.rcdFertilizer!= null">#{item.rcdFertilizer},</if>
             </trim>
         </foreach>
     </insert>
@@ -88,6 +96,8 @@
             <if test="rcdStatus!= null">rcdStatus = #{rcdStatus},</if>
             <if test="rcdFlow!= null">rcdFlow = #{rcdFlow},</if>
             <if test="rcdEnddate!= null">rcdEnddate = #{rcdEnddate},</if>
+            <if test="rcdTime!= null">rcdTime = #{rcdTime},</if>
+            <if test="rcdFertilizer!= null">rcdFertilizer = #{rcdFertilizer},</if>
         </trim>
         where rcdBid = #{rcdBid} and tid = #{tid}
     </update>
@@ -100,6 +110,8 @@
                 <if test="item.rcdStatus!= null">rcdStatus = #{item.rcdStatus},</if>
                 <if test="item.rcdFlow!= null">rcdFlow = #{item.rcdFlow},</if>
                 <if test="item.rcdEnddate!= null">rcdEnddate = #{item.rcdEnddate},</if>
+                <if test="item.rcdTime!= null">rcdTime = #{item.rcdTime},</if>
+                <if test="item.rcdFertilizer!= null">rcdFertilizer = #{item.rcdFertilizer},</if>
             </trim>
             where rcdBid = #{item.rcdBid} and tid = #{item.tid}
         </foreach>
@@ -108,7 +120,7 @@
     <select id="selectIrrigationRecordByBid" parameterType="com.yunfeiyun.agmp.iot.common.domain.IotSfIrrigationRecord"
             resultType="com.yunfeiyun.agmp.iot.common.domain.IotSfIrrigationRecord">
         SELECT rcdBid, devBid, rcdContent, rcdGroupbid, rcdGroupName, rcdStatus, rcdMode, sfdataBid, rcdFlow, rcdCreator,
-            rcdStartdate, rcdEnddate, rcdCreatorName, rcdCreateddate, tid
+            rcdStartdate, rcdEnddate, rcdCreatorName, rcdCreateddate, tid, rcdTime, rcdFertilizer
         FROM IotSfIrrigationRecord
         where rcdBid = #{rcdBid}
     </select>
@@ -116,7 +128,7 @@
     <select id="selectIrrigationRecordList" parameterType="IotSfIrrigationRecordListReqVo"
             resultType="com.yunfeiyun.agmp.iot.common.domain.IotSfIrrigationRecord">
         SELECT rcdBid, devBid, rcdContent, rcdGroupbid, rcdGroupName, rcdStatus, rcdMode, sfdataBid, rcdFlow, rcdCreator,
-            rcdStartdate, rcdEnddate, rcdCreatorName, rcdCreateddate, tid
+            rcdStartdate, rcdEnddate, rcdCreatorName, rcdCreateddate, tid, rcdTime, rcdFertilizer
         FROM IotSfIrrigationRecord
         <where>
             tid = #{tid}