feat (farm): 首页扫码
- 加入户主流转信息
This commit is contained in:
@@ -60,8 +60,10 @@ public class HomeController {
|
||||
@Operation(summary = "农场首页-扫描二维码")
|
||||
@GetMapping("/scan-qr")
|
||||
@Parameter(name = "baseId", description = "基地ID")
|
||||
public CommonResult<QrDetailsRespVO> scanQrCodes(@RequestParam("baseId") String baseId) {
|
||||
QrDetailsRespVO res = homeService.scanQrCodes(baseId);
|
||||
@Parameter(name = "tenantId", description = "租户ID")
|
||||
public CommonResult<QrDetailsRespVO> scanQrCodes(@RequestParam("baseId") String baseId,
|
||||
@RequestParam("tenantId") String tenantId) {
|
||||
QrDetailsRespVO res = homeService.scanQrCodes(baseId,tenantId);
|
||||
return success(res);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,4 +70,7 @@ public interface DeviceClassifyService {
|
||||
|
||||
Map<String, String> getTypeNameMap();
|
||||
Map<String, String> getTypeCodeMap();
|
||||
|
||||
Map<String, String> getTypeNameMap(String tenantId);
|
||||
Map<String, String> getTypeCodeMap(String tenantId);
|
||||
}
|
||||
@@ -232,4 +232,24 @@ public class DeviceClassifyServiceImpl implements DeviceClassifyService {
|
||||
return typeCodeMap;
|
||||
}
|
||||
|
||||
public Map<String, String> getTypeNameMap(String tenantId) {
|
||||
LambdaQueryWrapperX<DeviceClassifyDO> x = new LambdaQueryWrapperX<>();
|
||||
x.eq(DeviceClassifyDO::getTenantId, tenantId);
|
||||
List<DeviceClassifyDO> deviceClassifyDOS = deviceClassifyMapper.selectList(x);
|
||||
|
||||
Map<String, String> typeNameMap = deviceClassifyDOS.stream().filter(device -> device.getParentId() != null && device.getParentId() == 0)
|
||||
.collect(Collectors.toMap(e -> e.getId().toString(), DeviceClassifyDO::getName));
|
||||
return typeNameMap;
|
||||
}
|
||||
|
||||
public Map<String, String> getTypeCodeMap(String tenantId) {
|
||||
LambdaQueryWrapperX<DeviceClassifyDO> x = new LambdaQueryWrapperX<>();
|
||||
x.eq(DeviceClassifyDO::getTenantId, tenantId);
|
||||
List<DeviceClassifyDO> deviceClassifyDOS = deviceClassifyMapper.selectList(x);
|
||||
|
||||
Map<String, String> typeCodeMap = deviceClassifyDOS.stream().filter(device -> device.getParentId() != null && device.getParentId() == 0)
|
||||
.collect(Collectors.toMap(e -> e.getId().toString(), DeviceClassifyDO::getTypeCode));
|
||||
return typeCodeMap;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public interface DeviceInfoService {
|
||||
DeviceInfoRespVO getDeviceInfoByDp(String baseId);
|
||||
|
||||
List<DeviceMonitorDataRespVO> deviceList();
|
||||
List<DeviceMonitorDataRespVO> deviceList(String plotId);
|
||||
List<DeviceMonitorDataRespVO> deviceList(String plotId,String tenantId);
|
||||
|
||||
/**
|
||||
* 设备统计信息
|
||||
|
||||
@@ -177,7 +177,22 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
}
|
||||
return target;
|
||||
}
|
||||
private DeviceInfoDetailV2RespVO.SoilInfo getSoilInfo(String deviceUniqueId,String plotId, Integer dateType,Long tenantId) {
|
||||
// Long tenantId = getLoginUser().getTenantId();
|
||||
|
||||
UnifiedLoginResponse login = equipmentProducerManager.login(DEVICE_TYPE_SOIL, tenantId, plotId);
|
||||
String token = login.getData().getToken();
|
||||
|
||||
// 实时数据
|
||||
RealTimeDataReqVO soilRequest = new RealTimeDataReqVO(deviceUniqueId,tenantId);
|
||||
RealTimeDataResponse realTimeData = equipmentProducerManager.getRealTimeData(DEVICE_TYPE_SOIL, tenantId, token, soilRequest);
|
||||
|
||||
// 历史数据
|
||||
HistoryDataListPageReqVO req = HistoryDataListPageReqVO.buildHistoryData(deviceUniqueId, dateType);
|
||||
HistoryDataResponse historyData = equipmentProducerManager.getHistoryData(DEVICE_TYPE_SOIL, tenantId, token, req);
|
||||
|
||||
return new DeviceInfoDetailV2RespVO.SoilInfo(deviceUniqueId, realTimeData, historyData);
|
||||
}
|
||||
/**
|
||||
* 土壤墒情传感器
|
||||
* @param deviceUniqueId 设备地址(唯一编号)
|
||||
@@ -201,6 +216,22 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
return new DeviceInfoDetailV2RespVO.SoilInfo(deviceUniqueId, realTimeData, historyData);
|
||||
}
|
||||
|
||||
private DeviceInfoDetailV2RespVO.WfInfo getWfInfo(String deviceUniqueId,String plotId,Long tenantId ) {
|
||||
// 登录
|
||||
UnifiedLoginResponse login = equipmentProducerManager.login(DEVICE_TYPE_WF, tenantId, plotId);
|
||||
String token = login.getData().getToken();
|
||||
|
||||
// 获取设备列表
|
||||
// DeviceListResponse response = equipmentProducerManager.getDeviceList(DEVICE_TYPE_WF, tenantId, token, null);
|
||||
// System.out.println("获取设备列表:"+response);
|
||||
|
||||
// 实时数据
|
||||
RealTimeDeviceDataReqVO wfRequest = new RealTimeDeviceDataReqVO(deviceUniqueId,tenantId);
|
||||
RealTimeDataResponse realTimeData = equipmentProducerManager.getRealTimeData(DEVICE_TYPE_WF, tenantId, token, wfRequest);
|
||||
|
||||
return new DeviceInfoDetailV2RespVO.WfInfo(deviceUniqueId,realTimeData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 水肥机
|
||||
* @param deviceUniqueId 设备地址(唯一编号)
|
||||
@@ -361,13 +392,13 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceMonitorDataRespVO> deviceList(String plotId) {
|
||||
public List<DeviceMonitorDataRespVO> deviceList(String plotId,String tenantId) {
|
||||
LambdaQueryWrapperX<DeviceInfoDO> wrapperX = new LambdaQueryWrapperX<>();
|
||||
wrapperX.eq(DeviceInfoDO::getPlotId, plotId);
|
||||
wrapperX.eq(DeviceInfoDO::getDeleted, CommonConstants.NO_CODE);
|
||||
|
||||
List<DeviceInfoDO> doList = deviceInfoMapper.selectList(wrapperX);
|
||||
return execute(doList);
|
||||
return execute(doList,tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -409,11 +440,11 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
return res;
|
||||
}
|
||||
|
||||
private List<DeviceMonitorDataRespVO> execute(List<DeviceInfoDO> doList) {
|
||||
private List<DeviceMonitorDataRespVO> execute(List<DeviceInfoDO> doList,String tenantId) {
|
||||
Map<String, List<DeviceInfoDO>> groupedByDeviceType = doList.stream().collect(Collectors.groupingBy(DeviceInfoDO::getDeviceType));
|
||||
|
||||
Map<String, String> typeCodeMap = deviceClassifyService.getTypeCodeMap();
|
||||
Map<String, String> typeNameMap = deviceClassifyService.getTypeNameMap();
|
||||
Map<String, String> typeCodeMap = deviceClassifyService.getTypeCodeMap(tenantId);
|
||||
Map<String, String> typeNameMap = deviceClassifyService.getTypeNameMap(tenantId);
|
||||
|
||||
|
||||
List<DeviceMonitorDataRespVO> res = new ArrayList<>();
|
||||
@@ -422,7 +453,7 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
List<DeviceInfoDO> list = d.getValue();
|
||||
|
||||
String typeCode = typeCodeMap.getOrDefault(deviceType, "其他");
|
||||
List<DeviceMonitorDataRespVO.Row> rows = this.getRealTimeList(typeCode, list);
|
||||
List<DeviceMonitorDataRespVO.Row> rows = this.getRealTimeList(typeCode, list,tenantId);
|
||||
res.add(new DeviceMonitorDataRespVO(typeNameMap.get(deviceType), rows));
|
||||
}
|
||||
|
||||
@@ -438,7 +469,32 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
|
||||
List<DeviceInfoDO> doList = deviceInfoMapper.selectList(wrapperX);
|
||||
|
||||
return execute(doList);
|
||||
return execute(doList,tenantId.toString());
|
||||
}
|
||||
|
||||
private List<DeviceMonitorDataRespVO.Row> getRealTimeList(String typeCode, List<DeviceInfoDO> doList,String tenantId) {
|
||||
List<DeviceMonitorDataRespVO.Row> rows = new ArrayList<>();
|
||||
|
||||
for (DeviceInfoDO d : doList) {
|
||||
// 获取设备商数据
|
||||
switch (typeCode) {
|
||||
case DEVICE_TYPE_SOIL:
|
||||
DeviceInfoDetailV2RespVO.SoilInfo soilInfo = getSoilInfo(d.getDeviceUniqueId(), d.getPlotId(), 12,Long.valueOf(d.getTenantId()));
|
||||
List<DeviceMonitorDataRespVO.Row> rows1 = this.getSoilData(d.getDeviceName(), soilInfo);
|
||||
rows.addAll(rows1);
|
||||
break;
|
||||
case DEVICE_TYPE_WF:
|
||||
DeviceInfoDetailV2RespVO.WfInfo wfInfo = getWfInfo(d.getDeviceUniqueId(), d.getPlotId(),Long.valueOf(d.getTenantId()));
|
||||
List<DeviceMonitorDataRespVO.Row> rows2 = this.getWfData( wfInfo);
|
||||
rows.addAll(rows2);
|
||||
break;
|
||||
case DEVICE_TYPE_VIDEO_MONITOR:
|
||||
rows.add(new DeviceMonitorDataRespVO.Row(d.getDeviceName(),DEVICE_STATE_MAP.get(d.getDeviceState()),d.getDeviceUrl()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
private List<DeviceMonitorDataRespVO.Row> getRealTimeList(String typeCode, List<DeviceInfoDO> doList) {
|
||||
|
||||
@@ -30,5 +30,5 @@ public interface HomeService {
|
||||
* @param baseId
|
||||
* @return
|
||||
*/
|
||||
QrDetailsRespVO scanQrCodes(String baseId);
|
||||
QrDetailsRespVO scanQrCodes(String baseId,String tenantId);
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ public class HomeServiceImpl implements HomeService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public QrDetailsRespVO scanQrCodes(String baseId) {
|
||||
public QrDetailsRespVO scanQrCodes(String baseId,String tenantId) {
|
||||
BaseInfoDO bObj = baseInfoService.getBaseInfo(baseId);
|
||||
if (ObjectUtils.isEmpty(bObj)) {
|
||||
return null;
|
||||
@@ -277,7 +277,7 @@ public class HomeServiceImpl implements HomeService {
|
||||
List<PlotInfoDO> plotInfos = plotInfoService.getPlotInfos(baseId);
|
||||
for (PlotInfoDO p : plotInfos) {
|
||||
List<PlotLesseeDetailsRespVO> ls = this.getLs(p.getId());
|
||||
List<DeviceMonitorDataRespVO> ds = this.getDs(p.getId());
|
||||
List<DeviceMonitorDataRespVO> ds = this.getDs(p.getId(),tenantId);
|
||||
|
||||
QrDetailsRespVO.PlotInfo targetP = new QrDetailsRespVO.PlotInfo();
|
||||
targetP.setPlotName(p.getPlotName());
|
||||
@@ -304,8 +304,8 @@ public class HomeServiceImpl implements HomeService {
|
||||
|
||||
}
|
||||
|
||||
private List<DeviceMonitorDataRespVO> getDs(String plotId) {
|
||||
List<DeviceMonitorDataRespVO> res = deviceService.deviceList(plotId);
|
||||
private List<DeviceMonitorDataRespVO> getDs(String plotId,String tenantId) {
|
||||
List<DeviceMonitorDataRespVO> res = deviceService.deviceList(plotId,tenantId);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user