|
@@ -13,6 +13,8 @@ import com.yunfeiyun.agmp.iot.common.constant.devicetype.ServiceNameConst;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotRunHaoSfdata;
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotRunHaoSfdata;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotSfIrrigationRecord;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.enums.EnumIrrigationRecord;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.EnumSfElementType;
|
|
import com.yunfeiyun.agmp.iot.common.enums.EnumSfElementType;
|
|
|
import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
@@ -22,6 +24,7 @@ import com.yunfeiyun.agmp.iotm.device.sf.domain.*;
|
|
|
import com.yunfeiyun.agmp.iotm.device.sf.service.IIotSfCommService;
|
|
import com.yunfeiyun.agmp.iotm.device.sf.service.IIotSfCommService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotSfElementfactorService;
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotSfElementfactorService;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.web.service.IIotSfIrrigationRecordService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -45,6 +48,15 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private MongoService mongoService;
|
|
private MongoService mongoService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IIotSfIrrigationRecordService iotSfIrrigationRecordService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取设备状态
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param reqVo 请求参数,包含设备标识(devBid)等信息
|
|
|
|
|
+ **/
|
|
|
|
|
+
|
|
|
private String getDataValue(JSONObject dataJson, String key){
|
|
private String getDataValue(JSONObject dataJson, String key){
|
|
|
String v = dataJson.getString(key);
|
|
String v = dataJson.getString(key);
|
|
|
if("true".equals(v)){
|
|
if("true".equals(v)){
|
|
@@ -363,6 +375,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
}catch (Exception e){}
|
|
}catch (Exception e){}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ runStatus.put("sfdataBid", iotRunHaoSfdata.getSfdataBid());
|
|
|
return runStatus;
|
|
return runStatus;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -738,12 +751,12 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
if(childType == null || !typeSet.contains(childType)){
|
|
if(childType == null || !typeSet.contains(childType)){
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- sfTypeValueMap.put(childType, Math.max(sfTypeValueMap.getOrDefault(childType, 0), Integer.parseInt(child.getValue())));
|
|
|
|
|
|
|
+ sfTypeValueMap.put(childType, sfTypeValueMap.getOrDefault(childType, 0) + Integer.parseInt(child.getValue()));
|
|
|
sfTypeMap.put(child.getSfCode(), childType);
|
|
sfTypeMap.put(child.getSfCode(), childType);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if(typeSet.contains(elementType)){
|
|
if(typeSet.contains(elementType)){
|
|
|
- sfTypeValueMap.put(elementType, Math.max(sfTypeValueMap.getOrDefault(elementType, 0), Integer.parseInt(element.getValue())));
|
|
|
|
|
|
|
+ sfTypeValueMap.put(elementType, sfTypeValueMap.getOrDefault(elementType, 0) + Integer.parseInt(element.getValue()));
|
|
|
sfTypeMap.put(element.getSfCode(), elementType);
|
|
sfTypeMap.put(element.getSfCode(), elementType);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -772,13 +785,13 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
if(elementType == EnumSfElementType.WATER_SOURCE && Objects.equals(v, "1")){
|
|
if(elementType == EnumSfElementType.WATER_SOURCE && Objects.equals(v, "1")){
|
|
|
// 请先打开阀
|
|
// 请先打开阀
|
|
|
Integer va = sfTypeValueMap.get(EnumSfElementType.SOLENOID_VALVE);
|
|
Integer va = sfTypeValueMap.get(EnumSfElementType.SOLENOID_VALVE);
|
|
|
- if(va != 1){
|
|
|
|
|
|
|
+ if(va == 0){
|
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先打开阀门");
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先打开阀门");
|
|
|
}
|
|
}
|
|
|
}else if(elementType == EnumSfElementType.FERTILIZER){
|
|
}else if(elementType == EnumSfElementType.FERTILIZER){
|
|
|
Integer va = sfTypeValueMap.get(EnumSfElementType.SUCTION);
|
|
Integer va = sfTypeValueMap.get(EnumSfElementType.SUCTION);
|
|
|
if(Objects.equals(v, "1")){
|
|
if(Objects.equals(v, "1")){
|
|
|
- if(va != 1){
|
|
|
|
|
|
|
+ if(va == 0){
|
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先打开肥阀");
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先打开肥阀");
|
|
|
}
|
|
}
|
|
|
}else {
|
|
}else {
|
|
@@ -787,10 +800,14 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}else if(elementType == EnumSfElementType.SOLENOID_VALVE && Objects.equals(v, "0")){
|
|
}else if(elementType == EnumSfElementType.SOLENOID_VALVE && Objects.equals(v, "0")){
|
|
|
- Integer va = sfTypeValueMap.get(EnumSfElementType.WATER_SOURCE);
|
|
|
|
|
- if(va != 0){
|
|
|
|
|
- throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先关闭水源泵");
|
|
|
|
|
|
|
+ Integer sova = sfTypeValueMap.get(EnumSfElementType.SOLENOID_VALVE);
|
|
|
|
|
+ if(sova - 1 <= 0){
|
|
|
|
|
+ Integer va = sfTypeValueMap.get(EnumSfElementType.WATER_SOURCE);
|
|
|
|
|
+ if(va != 0){
|
|
|
|
|
+ throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先关闭水源泵");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -962,6 +979,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "未配置灌溉设备");
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "未配置灌溉设备");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ List<IotSfElementfactorAlreadyListResVo> groupList = new ArrayList<>();
|
|
|
JSONObject sendJson = new JSONObject();
|
|
JSONObject sendJson = new JSONObject();
|
|
|
for(IotSfElementfactorAlreadyListResVo elementfactor : elementfactorList){
|
|
for(IotSfElementfactorAlreadyListResVo elementfactor : elementfactorList){
|
|
|
String sfCode = elementfactor.getSfCode();
|
|
String sfCode = elementfactor.getSfCode();
|
|
@@ -972,6 +990,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "灌区未配置阀,无法开始灌溉");
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "灌区未配置阀,无法开始灌溉");
|
|
|
}
|
|
}
|
|
|
sendJson.put(sfCode, "1");
|
|
sendJson.put(sfCode, "1");
|
|
|
|
|
+ groupList.add(elementfactor);
|
|
|
}
|
|
}
|
|
|
if(sendJson.isEmpty()){
|
|
if(sendJson.isEmpty()){
|
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "请先选择灌区");
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "请先选择灌区");
|
|
@@ -998,6 +1017,44 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ String tid = SecurityUtils.getTid();
|
|
|
|
|
+ String userId = SecurityUtils.getUserId();
|
|
|
|
|
+ String userLoginName = SecurityUtils.getLoginLogName();
|
|
|
|
|
+ String rcdStartdate = DateUtils.dateTimeNow();
|
|
|
|
|
+ List<IotSfIrrigationRecord> irrigationRecordList = new ArrayList<>();
|
|
|
|
|
+ for(IotSfElementfactorAlreadyListResVo group : groupList){
|
|
|
|
|
+ StringBuilder rcdContent = new StringBuilder();
|
|
|
|
|
+ List<IotSfElementfactorAlreadyListResVo> childrenList = group.getChildrenList();
|
|
|
|
|
+ for(IotSfElementfactorAlreadyListResVo child : childrenList){
|
|
|
|
|
+ rcdContent.append(child.getSfDisplayname()).append(",");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(rcdContent.length() > 0){
|
|
|
|
|
+ rcdContent.deleteCharAt(rcdContent.length() - 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ rcdContent.append(EnumIrrigationRecord.STATUS_RUNNING.getName());
|
|
|
|
|
+
|
|
|
|
|
+ IotSfIrrigationRecord record = new IotSfIrrigationRecord();
|
|
|
|
|
+ record.setRcdBid(record.getUUId());
|
|
|
|
|
+ record.setDevBid(devBid);
|
|
|
|
|
+ record.setRcdGroupbid(group.getSfBid());
|
|
|
|
|
+ record.setRcdGroupName(group.getSfDisplayname());
|
|
|
|
|
+ record.setRcdStatus(EnumIrrigationRecord.STATUS_RUNNING.getCode());
|
|
|
|
|
+ record.setRcdMode(EnumIrrigationRecord.MODE_AUTO.getCode());
|
|
|
|
|
+ record.setRcdContent(rcdContent.toString());
|
|
|
|
|
+ record.setSfdataBid(runStatusData.getString("sfdataBid"));
|
|
|
|
|
+ record.setRcdCreator(userId);
|
|
|
|
|
+ record.setRcdCreatorName(userLoginName);
|
|
|
|
|
+ record.setRcdStartdate(rcdStartdate);
|
|
|
|
|
+ record.setRcdCreateddate(rcdStartdate);
|
|
|
|
|
+ record.setTid(tid);
|
|
|
|
|
+
|
|
|
|
|
+ irrigationRecordList.add(record);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!irrigationRecordList.isEmpty()){
|
|
|
|
|
+ iotSfIrrigationRecordService.batchInsertIotSfIrrigationRecord(irrigationRecordList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
IotSfConfigCmdReqVo cmdReqVo = new IotSfConfigCmdReqVo();
|
|
IotSfConfigCmdReqVo cmdReqVo = new IotSfConfigCmdReqVo();
|
|
|
cmdReqVo.setDevBid(devBid);
|
|
cmdReqVo.setDevBid(devBid);
|
|
|
cmdReqVo.setCmd(CmdDef.RunHaoSfCmdDef.CMD_CONFIG);
|
|
cmdReqVo.setCmd(CmdDef.RunHaoSfCmdDef.CMD_CONFIG);
|