|
@@ -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");
|
|
|
}
|
|
|
}
|