Explorar el Código

完成查询洗消烘干设备烘干详情。

zhuoning hace 2 años
padre
commit
cd5b7ac904

+ 2 - 4
huimv-farm-environ/src/main/java/com/huimv/environ/eco/schedule/ScheduleTask.java

@@ -53,7 +53,7 @@ public class ScheduleTask {
     private String URL_ENVIRON_DEVICE_SERVICE;
 //    private static String URL = "http://www.0531yun.com/app/GetDeviceData";
 
-//    @Scheduled(cron = "0 0/5 * * * ?")  //每5分钟执行一次
+    @Scheduled(cron = "0 0/5 * * * ?")  //每5分钟执行一次
 //    @Scheduled(cron = "*/10 * * * * ?")  //每10秒钟执行一次
     public void getDeviceFlow() throws ParseException {
         DateUtil dateUtil = new DateUtil();
@@ -92,8 +92,6 @@ public class ScheduleTask {
                 } else {
                     JSONArray dataJa = resultJo.getJSONArray("data");
                     System.out.println("dataJa.size=" + dataJa.size());
-//                    for (int b = 0; b < dataJa.size(); b++) {
-//                        JSONObject dataJo = dataJa.getJSONObject(b);
                     JSONObject dataJo = dataJa.getJSONObject(0);
                     Date todayTime = dateUtil.getTodayDateTime();
                     //保存温度流水记录
@@ -103,8 +101,8 @@ public class ScheduleTask {
                     //新建烘干记录
                     ecoDryListService.saveDryList(deviceMap, dataJo, thresholdJo, todayTime);
                     //新建洗消烘干温度时长不足报警记录
+                    //dryMin = thresholdJo.getString("dryMin");
 //                    newShortDryingtime();
-//                    }
                 }
             }
         }

+ 1 - 1
huimv-farm-environ/src/main/java/com/huimv/environ/eco/service/EcoDeviceFlowService.java

@@ -26,5 +26,5 @@ public interface EcoDeviceFlowService extends IService<EcoDeviceFlow> {
 
     Result listByRoom(HttpServletRequest request, Map<String, String> paramsMap) throws ParseException;
 
-    Result listDayDetails(HttpServletRequest request, Map<String, String> paramsMap);
+    Result listDayDetails(HttpServletRequest request, Map<String, String> paramsMap) throws ParseException;
 }

+ 79 - 13
huimv-farm-environ/src/main/java/com/huimv/environ/eco/service/impl/EcoDeviceFlowServiceImpl.java

@@ -15,18 +15,22 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.huimv.environ.env.utils.DateUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
 
 import javax.servlet.http.HttpServletRequest;
 import java.text.ParseException;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author zn
@@ -34,14 +38,21 @@ import java.util.Map;
  */
 @Service
 public class EcoDeviceFlowServiceImpl extends ServiceImpl<EcoDeviceFlowMapper, EcoDeviceFlow> implements EcoDeviceFlowService {
-
     @Autowired
     private EcoDeviceFlowMapper ecoDeviceFlowMapper;
+    @Value("${dry.search.before.minute}")
+    private String BEFORE_MINUTE;
+    @Value("${dry.search.after.minute}")
+    private String AFTER_MINUTE;
+    @Value("${url.threshold.service}")
+    private String URL_THRESHOLD_SERVICE;
+    @Autowired
+    private RestTemplate restTemplate;
 
     @Override
     public Result getLastFlow(Map<String, String> paramsMap) {
         String farmId = paramsMap.get("farmId");
-        return new Result(ResultCode.SUCCESS,ecoDeviceFlowMapper.getLastFlow(farmId));
+        return new Result(ResultCode.SUCCESS, ecoDeviceFlowMapper.getLastFlow(farmId));
     }
 
     @Override
@@ -58,7 +69,7 @@ public class EcoDeviceFlowServiceImpl extends ServiceImpl<EcoDeviceFlowMapper, E
         ecoDeviceFlow.setId1Name(id1Jo.getString("dataName"));
         //
         String id1Value = id1Jo.getString("dataValue");
-        if(StringUtils.isBlank(id1Value)){
+        if (StringUtils.isBlank(id1Value)) {
             id1Value = "0";
         }
         ecoDeviceFlow.setId1Value(id1Value);
@@ -68,7 +79,7 @@ public class EcoDeviceFlowServiceImpl extends ServiceImpl<EcoDeviceFlowMapper, E
         ecoDeviceFlow.setId2Name(id2Jo.getString("dataName"));
         String id2Value = id2Jo.getString("dataValue");
         //
-        if(StringUtils.isBlank(id2Value)){
+        if (StringUtils.isBlank(id2Value)) {
             id2Value = "0";
         }
         ecoDeviceFlow.setId2Value(id2Value);
@@ -89,7 +100,7 @@ public class EcoDeviceFlowServiceImpl extends ServiceImpl<EcoDeviceFlowMapper, E
 
         List<EcoDeviceDto> ecoDeviceDtos = null;
         //默认显示
-        if (type==null) {
+        if (type == null) {
             unitId = "77";
             DateUtil dateUtil = new DateUtil();
             startDate = dateUtil.getTodayDate().toString();
@@ -113,15 +124,70 @@ public class EcoDeviceFlowServiceImpl extends ServiceImpl<EcoDeviceFlowMapper, E
             else if ("1".equals(type)) {
                 ecoDeviceDtos = ecoDeviceFlowMapper.listMonthDevice(farmId, unitId);
             }
-
         }
-
         return new Result(ResultCode.SUCCESS, ecoDeviceDtos);
     }
 
     @Override
-    public Result listDayDetails(HttpServletRequest request, Map<String, String> paramsMap) {
+    public Result listDayDetails(HttpServletRequest request, Map<String, String> paramsMap) throws ParseException {
+        String farmId = paramsMap.get("farmId");
+        String deviceCode = paramsMap.get("deviceCode");
+        String addTime = paramsMap.get("addTime");
+
+        //读取高温阈值数据
+        JSONObject thresholdJo = getThresholdURL(Integer.parseInt(farmId));
+        System.out.println("调取牧场[" + farmId + "]服务获取阈值接口:" + thresholdJo);
+        String dryDuration = "0";
+        if(thresholdJo.getString("dryDuration") != null){
+            //一次烘干持续时间(分钟)
+            dryDuration = thresholdJo.getString("dryDuration");
+        }
+        System.out.println("dryDuration="+dryDuration);
+        System.out.println("BEFORE_MINUTE="+BEFORE_MINUTE);
+        System.out.println("AFTER_MINUTE="+AFTER_MINUTE);
 
-        return null;
+        DateUtil dateUtil = new DateUtil();
+        Date startDateTime = dateUtil.getDateBeforeMinute(addTime, Integer.parseInt(BEFORE_MINUTE));
+        Date endDateTime = dateUtil.getDateAfterMinute(addTime, Integer.parseInt(dryDuration) + Integer.parseInt(AFTER_MINUTE));
+        System.out.println("farmId=" + farmId);
+        System.out.println("deviceCode=" + deviceCode);
+        System.out.println("addTime=" + addTime);
+        System.out.println("startDateTime = " + dateUtil.formatDateTime(startDateTime));
+        System.out.println("endDateTime = " + dateUtil.formatDateTime(endDateTime));
+        //查询时间范围:开始时间(startTime = beforeMinute + addTime)
+        //查询时间范围:结束时间(endTime = addTime + duration + afterMinute)
+        QueryWrapper<EcoDeviceFlow> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("device_code", deviceCode);
+        queryWrapper.between("add_time", startDateTime, endDateTime);
+        queryWrapper.orderByAsc("add_time");
+        List<EcoDeviceFlow> ecoDeviceFlowList = ecoDeviceFlowMapper.selectList(queryWrapper);
+        List resultList = new ArrayList();
+        for(EcoDeviceFlow ecoDeviceFlow:ecoDeviceFlowList){
+            JSONObject ecoDeviceFlowJo = new JSONObject();
+            ecoDeviceFlowJo.put("value",ecoDeviceFlow.getId1Value());
+            ecoDeviceFlowJo.put("time",dateUtil.formatDateTime(ecoDeviceFlow.getAddTime()));
+            resultList.add(ecoDeviceFlowJo);
+        }
+        return new Result(ResultCode.SUCCESS,resultList);
+    }
+
+    //获取阈值
+    private JSONObject getThresholdURL(Integer farmId) {
+        HttpHeaders httpHeaders = new HttpHeaders();
+        MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
+        httpHeaders.setContentType(type);
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("farmId", farmId);
+        HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(map, httpHeaders);
+        //读取真实数据
+//        String remoteUrl = "http://192.168.1.67:8010/produce/threshold/getThresholdByFarmId";
+        System.out.println("URL_THRESHOLD_SERVICE=" + URL_THRESHOLD_SERVICE);
+        ResponseEntity<String> entity = restTemplate.postForEntity(URL_THRESHOLD_SERVICE, objectHttpEntity, String.class);
+        JSONObject thresholdJo = JSONObject.parseObject(entity.getBody());
+        System.out.println("thresholdJo>>>>>>>>>>>>>>>"+thresholdJo);
+        if (thresholdJo.getInteger("code") != 10000) {
+            return null;
+        }
+        return thresholdJo.getJSONObject("data");
     }
 }

+ 11 - 5
huimv-farm-environ/src/main/java/com/huimv/environ/eco/service/impl/EcoDryListServiceImpl.java

@@ -55,18 +55,24 @@ public class EcoDryListServiceImpl extends ServiceImpl<EcoDryListMapper, EcoDryL
         if (StringUtils.isBlank(temp)) {
             temp = "0";
         }
-        //Debug var
+        //Debug:temp
         temp = "40";
         System.out.println(">> temp=" + temp);
         //烘干温度(分钟)
-        String dryTem = thresholdJo.getString("dryTem");
+        String dryTem = "0";
         System.out.println(">> dryTem=" + dryTem);
         //烘干时间过短报警时长(分钟)
-        String dryMin = thresholdJo.getString("dryMin");
+        String dryMin = "0";
         //一次烘干持续时间(分钟)
-        String dryDuration = thresholdJo.getString("dryDuration");
+        String dryDuration = "0";
         //常温阈值
-        String dryNormalTemp = thresholdJo.getString("dryNormalTemp");
+        String dryNormalTemp = "0";
+        if(thresholdJo == null){
+             dryTem = thresholdJo.getString("dryTem");
+             dryMin = thresholdJo.getString("dryMin");
+             dryDuration = thresholdJo.getString("dryDuration");
+             dryNormalTemp = thresholdJo.getString("dryNormalTemp");
+        }
         String farmId = thresholdJo.getString("farmId");
         DateUtil dateUtil = new DateUtil();
         int deviceType = (int) deviceMap.get("device_type");

+ 31 - 0
huimv-farm-environ/src/main/java/com/huimv/environ/env/utils/DateUtil.java

@@ -22,6 +22,34 @@ import java.util.Date;
 @Slf4j
 public class DateUtil {
 
+    public Date getDateBeforeMinute(String addTime, int beforeMinute) throws ParseException {
+        Calendar calendar=Calendar.getInstance();
+        calendar.setTime(parseDateTime(addTime));
+        calendar.set(Calendar.MINUTE,calendar.get(Calendar.MINUTE)-beforeMinute);
+        return calendar.getTime();
+    }
+
+    public Date getDateBeforeMinute(int beforeMinute){
+        Calendar calendar=Calendar.getInstance();
+        calendar.setTime(new Date());
+        calendar.set(Calendar.MINUTE,calendar.get(Calendar.MINUTE)-beforeMinute);
+        return calendar.getTime();
+    }
+
+    public Date getDateAfterMinute(String addTime, int afterMinute) throws ParseException {
+        Calendar calendar=Calendar.getInstance();
+        calendar.setTime(parseDateTime(addTime));
+        calendar.set(Calendar.MINUTE,calendar.get(Calendar.MINUTE)+afterMinute);
+        return calendar.getTime();
+    }
+
+    public Date getDateAfterMinute(int afterMinute){
+        Calendar calendar=Calendar.getInstance();
+        calendar.setTime(new Date());
+        calendar.set(Calendar.MINUTE,calendar.get(Calendar.MINUTE)+afterMinute);
+        return calendar.getTime();
+    }
+
     //Long转换为Date格式
     public String fromLongToDate(Long time ,String format) {
         SimpleDateFormat sdf = new SimpleDateFormat(format);
@@ -210,4 +238,7 @@ public class DateUtil {
         String date = text.substring(0,4)+"-"+text.substring(4,6)+"-"+text.substring(6,8)+" "+text.substring(8,10)+":"+text.substring(10,12)+":"+text.substring(12,14);
         System.out.println("date="+date);
     }
+
+
+
 }

+ 8 - 0
huimv-farm-environ/src/main/resources/application-lishui.yml

@@ -37,3 +37,11 @@ spring:
         max-idle: 3
         max-wait: 1
       shutdown-timeout: 100
+
+mybatis-plus:
+  configuration:
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    map-underscore-to-camel-case: true   # 关闭驼峰式编码
+  # mapper.xml文件所存放的位置
+#  mapper-locations: classpath*:com/huimv/saas/breed/mapper/xml/*.xml  # 不加这一行出错:“org.apache.ibatis.binding.BindingException:  Invalid bound statement (not found)”
+#  mapper-locations: classpath:com/huimv/center/mappers/**/*Mapper.xml

+ 11 - 4
huimv-farm-environ/src/main/resources/application.properties

@@ -9,13 +9,20 @@ spring.profiles.active=lishui
 url.environ.device.service=http://www.0531yun.com/app/GetDeviceData
 
 #
-url.threshold.service=http://192.168.1.67:8010/produce/threshold/getThresholdByFarmId
-#url.threshold.service=http://localhost:8010/produce/threshold/getThresholdByFarmId
+#url.threshold.service=http://192.168.1.67:8010/produce/threshold/getThresholdByFarmId
+url.threshold.service=http://localhost:8010/produce/threshold/getThresholdByFarmId
 
 #
-url.warning.service=http://192.168.1.67:8010/produce/warningInfo/newAlarm
-#url.warning.service=http://localhost:8010/produce/warningInfo/newAlarm
+#url.warning.service=http://192.168.1.67:8010/produce/warningInfo/newAlarm
+url.warning.service=http://localhost:8010/produce/warningInfo/newAlarm
 
 #第一次烘干结束,第二次烘干开始之间的间隔持续时间
 dry.twice.duration.minute=0
 
+#查询起始时间(beforeMinute + addTime)
+dry.search.before.minute=10
+
+#查询截至时间(addTime + duration + afterMinute)
+dry.search.after.minute=10
+
+

+ 16 - 0
huimv-farm-environ/src/test/java/com/huimv/environ/eco/TaskTest.java

@@ -2,11 +2,15 @@ package com.huimv.environ.eco;
 
 import com.huimv.environ.eco.schedule.ScheduleTask;
 import com.huimv.environ.eco.service.EcoDryListService;
+import com.huimv.environ.env.utils.DateUtil;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import sun.dc.pr.PRError;
 
 import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
 
 /**
  * @Project : huimv-farm-datacenter
@@ -22,6 +26,8 @@ public class TaskTest {
     private ScheduleTask test;
     @Autowired
     private EcoDryListService ecoDryListService;
+    @Autowired
+    private DateUtil dateUtil;
 
     @Test
     public void testDevice() throws ParseException {
@@ -51,4 +57,14 @@ public class TaskTest {
         String todayTime = "2022-11-12 19:35:52";
         ecoDryListService.sendLowDryTempAlarm(alarmInfo,farmId,todayTime,todayTime);
     }
+
+    @Test
+    public void testAdd() throws ParseException {
+        DateUtil dateUtil = new DateUtil();
+        String addTime = "2022-11-13 11:36:08";
+        System.out.println("newDate -10 ="+dateUtil.formatDateTime(dateUtil.getDateBeforeMinute(addTime,10)));
+        System.out.println("newDate +10 ="+dateUtil.formatDateTime(dateUtil.getDateAfterMinute(addTime,10)));
+    }
+
+
 }

+ 1 - 1
huimv-farm-produce/pom.xml

@@ -15,7 +15,7 @@
         <dependency>
             <groupId>com.huimv</groupId>
             <artifactId>huimv-common</artifactId>
-            <version>0.0.6-SNAPSHOT</version>
+            <version>0.0.9-SNAPSHOT</version>
         </dependency>
 <!--        <dependency>-->
 <!--            <groupId>org.springframework.boot</groupId>-->

+ 1 - 1
huimv-farm-produce/src/main/java/com/huimv/produce/task/MyScheduledTask.java

@@ -20,7 +20,7 @@ public class MyScheduledTask {
     @Autowired
     private IWeight iWeight;
 
-    @Scheduled(cron = "0 0/10 * * * ?")
+//    @Scheduled(cron = "0 0/10 * * * ?")
 //    @Scheduled(cron = "0/10 * * * * ?")
     public void scheduledTask1() throws ParseException {
         iWeight.autoGenerateDayWeight();

+ 10 - 4
huimv-farm-produce/src/main/java/com/huimv/produce/warning/controller/SysThresholdController.java

@@ -7,6 +7,7 @@ import com.huimv.common.utils.Result;
 import com.huimv.common.utils.ResultCode;
 import com.huimv.produce.warning.entity.SysThreshold;
 import com.huimv.produce.warning.service.ISysThresholdService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -23,9 +24,8 @@ import java.util.Map;
  */
 @RestController
 @RequestMapping("/threshold")
+@Slf4j
 public class SysThresholdController {
-
-
     @Autowired
     private ISysThresholdService thresholdService;
 
@@ -34,13 +34,19 @@ public class SysThresholdController {
         return thresholdService.addThreshold(request,paramsMap);
     }
 
-    @PostMapping("/getThreshold")
     //阈值
+    @PostMapping("/getThreshold")
     public Result getThreshold(@RequestBody  Map<String,String> paramsMap, HttpServletRequest request){
-
         return thresholdService.getThreshold(request,paramsMap);
     }
 
+    @PostMapping("/getThresholdByFarmId")
+    public Result getThresholdByFarmId(@RequestBody  Map<String,String> paramsMap){
+        String farmId = paramsMap.get("farmId");
+        log.info("farmId="+farmId);
+        return new Result(ResultCode.SUCCESS,thresholdService.getById(farmId));
+    }
+
     @PostMapping("/listWarningInfoWeater")
     public Result listWarningInfoWeater(@RequestBody Map<String, String> map ) {
         return thresholdService.listWarningInfoWeater(map);

+ 3 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/warning/entity/SysThreshold.java

@@ -55,5 +55,8 @@ public class SysThreshold extends Model {
      */
     private String dryMin;
 
+    private String dryDuration;
+
+    private String dryNormalTemp;
 
 }

+ 0 - 2
huimv-farm-produce/src/main/java/com/huimv/produce/warning/service/impl/SysThresholdServiceImpl.java

@@ -55,8 +55,6 @@ public class SysThresholdServiceImpl extends ServiceImpl<SysThresholdMapper, Sys
 //            endMap.put("minTem",false);
 //            endMap.put("minTemStr",null);
 //        }
-
-
         return new Result(ResultCode.SUCCESS,map);
     }