fix (farm): 大屏
- 统计图bug
This commit is contained in:
@@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.farm.controller.admin.digitalcockpit;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.api.vo.FarmingDistributionReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.api.vo.FarmingDistributionRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.digitalcockpit.vo.*;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.baseinfo.BaseInfoDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.companyinfo.CompanyInfoDO;
|
||||
@@ -11,7 +13,6 @@ import cn.iocoder.yudao.module.farm.service.baseinfo.BaseInfoService;
|
||||
import cn.iocoder.yudao.module.farm.service.companyinfo.CompanyInfoService;
|
||||
import cn.iocoder.yudao.module.farm.service.deviceinfo.DeviceInfoService;
|
||||
import cn.iocoder.yudao.module.farm.service.farmingrecord.FarmingRecordService;
|
||||
import cn.iocoder.yudao.module.farm.service.modelcycle.ModelCycleService;
|
||||
import cn.iocoder.yudao.module.farm.service.modelmanagement.ModelManagementService;
|
||||
import cn.iocoder.yudao.module.farm.service.plotinfo.PlotInfoService;
|
||||
import cn.iocoder.yudao.module.farm.service.productionplan.ProductionPlanService;
|
||||
@@ -23,7 +24,6 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
|
||||
@@ -160,21 +160,16 @@ public class DigitalCockpitController {
|
||||
@GetMapping("/farm-records/type/1")
|
||||
@Operation(summary = "农事分布")
|
||||
@Parameter(name = "baseId", description = "基地ID", required = true)
|
||||
public CommonResult<FarmRecordsRespVO> getFarmRecords(@RequestParam("baseId") String baseId) {
|
||||
// TODO: 2025/9/24 待实现
|
||||
FarmRecordsRespVO res = new FarmRecordsRespVO();
|
||||
res.setTotalCount(0);
|
||||
res.setOverdueStatusCount(0);
|
||||
res.setCompletedStatusCount(0);
|
||||
res.setPendingStatusCount(0);
|
||||
res.setExecutingStatusCount(0);
|
||||
return success(res);
|
||||
public CommonResult<FarmingDistributionRespVO> getFarmRecords(@RequestParam("baseId") String baseId) {
|
||||
FarmingDistributionReqVO req = new FarmingDistributionReqVO(baseId,"");
|
||||
return farmingRecordService.getFarmingDistributionChart(req);
|
||||
}
|
||||
|
||||
@GetMapping("/farm-records/type/2")
|
||||
@Operation(summary = "农事活动趋势")
|
||||
@Parameter(name = "baseId", description = "基地ID", required = true)
|
||||
public CommonResult<String> getFarmRecordsDirection(@RequestParam("baseId") String baseId) {
|
||||
// 移除
|
||||
return success("暂时不做");
|
||||
}
|
||||
|
||||
@@ -182,15 +177,7 @@ public class DigitalCockpitController {
|
||||
@Operation(summary = "设备统计")
|
||||
@Parameter(name = "baseId", description = "基地ID", required = true)
|
||||
public CommonResult<DeviceInfoRespVO> getDeviceInfo(@RequestParam("baseId") String baseId) {
|
||||
// TODO: 2025/9/24 待实现
|
||||
DeviceInfoRespVO res = new DeviceInfoRespVO();
|
||||
res.setTotal(17);
|
||||
res.setDeviceInfos(
|
||||
Arrays.asList(
|
||||
new DeviceInfoRespVO.DeviceInfo("水肥机", 1),
|
||||
new DeviceInfoRespVO.DeviceInfo("土壤墒情", 16)
|
||||
)
|
||||
);
|
||||
DeviceInfoRespVO res = deviceInfoService.getDeviceInfoByDp(baseId);
|
||||
return success(res);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.api.vo.DeviceStateRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.deviceinfo.vo.DeviceInfoPageReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.deviceinfo.vo.v2.DeviceStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.digitalcockpit.vo.DeviceInfoRespVO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.deviceinfo.DeviceInfoDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -99,8 +100,12 @@ public interface DeviceInfoMapper extends BaseMapperX<DeviceInfoDO> {
|
||||
|
||||
/**
|
||||
* 设备在线状态统计
|
||||
*
|
||||
* @param tenantId
|
||||
* @return
|
||||
*/
|
||||
DeviceStateRespVO countDeviceState(@Param("baseId") String baseId,@Param("tenantId") String tenantId);
|
||||
DeviceStateRespVO countDeviceState(@Param("baseId") String baseId, @Param("tenantId") String tenantId);
|
||||
|
||||
List<DeviceInfoRespVO.DeviceInfo> selectDeviceTypeCount(@Param("baseId") String baseId);
|
||||
|
||||
}
|
||||
@@ -68,6 +68,7 @@ public class HistoryDataListPageReqVO {
|
||||
case 24 -> target = HistoryDataTimeRangeUtil.getLast24Hours();
|
||||
case 3 -> target = HistoryDataTimeRangeUtil.getLast3Days();
|
||||
case 7 -> target = HistoryDataTimeRangeUtil.getLast7Days();
|
||||
default -> target = HistoryDataTimeRangeUtil.getLast7Days();
|
||||
}
|
||||
target.setDeviceAddr(deviceAddr);
|
||||
return target;
|
||||
|
||||
@@ -384,7 +384,7 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService {
|
||||
// 任务进度 - 分子 (添加到: 种植中心-农事记录里的记录数)
|
||||
int progressNumerator = farmingRecordService.getFarmRecordCount(planObj.getId());
|
||||
// 任务进度 - 分母 (引用模型中的所有模型周期的农事记录总和)
|
||||
int progressDenominator = modelManagementService.getFarmRecordCount(planObj.getSpeciesModelId());
|
||||
int progressDenominator = this.setProgressBar(planObj);
|
||||
String progressBar = progressNumerator + "/" + progressDenominator; // 进度条
|
||||
String progressRatio = (int) Math.round((double) progressNumerator / progressDenominator * 100) + "%";
|
||||
|
||||
@@ -411,6 +411,20 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 农事记录总数 = 模型中的农事记录 + 自定义农事记录
|
||||
* @return
|
||||
*/
|
||||
private int setProgressBar(ProductionPlanDO planObj) {
|
||||
String speciesModelId = planObj.getSpeciesModelId();
|
||||
String planNumber = planObj.getPlanNumber();
|
||||
|
||||
int num1 = modelManagementService.getFarmRecordCount(speciesModelId);
|
||||
int num2 = farmingRecordService.getFarmRecordCountByTaskScope(planNumber);
|
||||
|
||||
return num1 + num2;
|
||||
}
|
||||
|
||||
private int countIntervalDays(ProductionPlanDO aDo) {
|
||||
LocalDate productionStartDate = aDo.getProductionStartDate();
|
||||
LocalDate productionEndDate = aDo.getProductionEndDate();
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.farm.controller.admin.deviceinfo.vo.DeviceInfoPag
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.deviceinfo.vo.DeviceInfoSaveReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.deviceinfo.vo.v2.DeviceInfoDetailV2RespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.deviceinfo.vo.v2.DeviceStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.digitalcockpit.vo.DeviceInfoRespVO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.deviceinfo.DeviceInfoDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.farm.manager.equipmentproducer.dto.RealTimeDataResponse;
|
||||
@@ -119,4 +120,11 @@ public interface DeviceInfoService {
|
||||
*/
|
||||
int countDevice(String baseId, String tenantId);
|
||||
|
||||
/**
|
||||
* 设备统计 (大屏)
|
||||
* @param baseId
|
||||
* @return
|
||||
*/
|
||||
DeviceInfoRespVO getDeviceInfoByDp(String baseId);
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.farm.controller.admin.deviceinfo.vo.DeviceInfoPag
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.deviceinfo.vo.DeviceInfoSaveReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.deviceinfo.vo.v2.DeviceInfoDetailV2RespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.deviceinfo.vo.v2.DeviceStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.digitalcockpit.vo.DeviceInfoRespVO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.baseinfo.BaseInfoDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.deviceclassify.DeviceClassifyDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.plotinfo.PlotInfoDO;
|
||||
@@ -24,6 +25,7 @@ import cn.iocoder.yudao.module.farm.manager.equipmentproducer.dto.UnifiedLoginRe
|
||||
import cn.iocoder.yudao.module.farm.manager.equipmentproducer.dto.soil.history.HistoryDataListPageReqVO;
|
||||
import cn.iocoder.yudao.module.farm.manager.equipmentproducer.dto.soil.realtime.RealTimeDataReqVO;
|
||||
import cn.iocoder.yudao.module.farm.manager.equipmentproducer.dto.wf.realtime.RealTimeDeviceDataReqVO;
|
||||
import cn.iocoder.yudao.module.farm.service.deviceclassify.DeviceClassifyService;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -63,6 +65,8 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
@Resource
|
||||
private DeviceClassifyMapper deviceClassifyMapper;
|
||||
@Resource
|
||||
private DeviceClassifyService deviceClassifyService;
|
||||
@Resource
|
||||
private BaseInfoMapper baseInfoMapper;
|
||||
@Resource
|
||||
private PlotInfoMapper plotInfoMapper;
|
||||
@@ -183,8 +187,7 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
String token = login.getData().getToken();
|
||||
|
||||
// 实时数据
|
||||
RealTimeDataReqVO soilRequest = new RealTimeDataReqVO();
|
||||
soilRequest.setDeviceAddrs(deviceUniqueId);
|
||||
RealTimeDataReqVO soilRequest = new RealTimeDataReqVO(deviceUniqueId,tenantId);
|
||||
RealTimeDataResponse realTimeData = equipmentProducerManager.getRealTimeData(DEVICE_TYPE_SOIL, tenantId, token, soilRequest);
|
||||
|
||||
// 历史数据
|
||||
@@ -270,7 +273,7 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
UnifiedLoginResponse login = equipmentProducerManager.login(DEVICE_TYPE_SOIL, Long.valueOf(req.getTenantId()), req.getTenantId());
|
||||
String token = login.getData().getToken();
|
||||
|
||||
RealTimeDataReqVO soilRequest = new RealTimeDataReqVO("");
|
||||
RealTimeDataReqVO soilRequest = new RealTimeDataReqVO("",Long.valueOf(req.getTenantId()));
|
||||
RealTimeDataResponse realTimeData = equipmentProducerManager.getRealTimeData(DEVICE_TYPE_SOIL, Long.valueOf(req.getTenantId()), token, soilRequest);
|
||||
|
||||
return success(realTimeData);
|
||||
@@ -324,4 +327,17 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
return deviceInfoMapper.selectCount(wrapperX).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceInfoRespVO getDeviceInfoByDp(String baseId) {
|
||||
Map<String, String> typeNameMap = deviceClassifyService.getTypeNameMap();
|
||||
|
||||
List<DeviceInfoRespVO.DeviceInfo> deviceInfos = deviceInfoMapper.selectDeviceTypeCount(baseId);
|
||||
deviceInfos.forEach(e -> e.setDeviceTypeName(typeNameMap.getOrDefault(e.getDeviceTypeName(), "")));
|
||||
// deviceCount 总和
|
||||
Integer totalCount = deviceInfos.stream().mapToInt(DeviceInfoRespVO.DeviceInfo::getDeviceCount).sum();
|
||||
|
||||
return new DeviceInfoRespVO(totalCount, deviceInfos);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -85,6 +85,8 @@ public interface FarmingRecordService {
|
||||
*/
|
||||
int getFarmRecordCount(String planId);
|
||||
|
||||
int getFarmRecordCountByTaskScope(String taskScope);
|
||||
|
||||
/**
|
||||
* api 接口
|
||||
* 灾害统计-农事分布
|
||||
|
||||
@@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.farm.dal.mysql.farmingnamemaintenance.FarmingName
|
||||
import cn.iocoder.yudao.module.farm.dal.mysql.farmingrecord.FarmingRecordMapper;
|
||||
import cn.iocoder.yudao.module.farm.dal.mysql.farmingrecordinput.FarmingRecordInputMapper;
|
||||
import cn.iocoder.yudao.module.farm.dal.mysql.farmingtypemaintenance.FarmingTypeMaintenanceMapper;
|
||||
import cn.iocoder.yudao.module.farm.enums.CommonConstants;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -268,6 +269,15 @@ public class FarmingRecordServiceImpl implements FarmingRecordService {
|
||||
return count.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFarmRecordCountByTaskScope(String taskScope) {
|
||||
LambdaQueryWrapperX<FarmingRecordDO> x = new LambdaQueryWrapperX<>();
|
||||
x.eq(FarmingRecordDO::getTaskScope, taskScope);
|
||||
x.eq(FarmingRecordDO::getDeleted, CommonConstants.NO_CODE);
|
||||
Long count = farmingRecordMapper.selectCount(x);
|
||||
return count.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<FarmingDistributionRespVO> getFarmingDistributionChart(FarmingDistributionReqVO req) {
|
||||
FarmingDistributionRespVO res = farmingRecordMapper.getFarmingDistributionChart(req);
|
||||
|
||||
@@ -46,5 +46,24 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectDeviceTypeCount"
|
||||
resultType="cn.iocoder.yudao.module.farm.controller.admin.digitalcockpit.vo.DeviceInfoRespVO$DeviceInfo">
|
||||
|
||||
SELECT
|
||||
device_type as deviceTypeName,
|
||||
COUNT(*) as deviceCount
|
||||
FROM farm_device_info
|
||||
<where>
|
||||
deleted = b'0'
|
||||
<if test="baseId != null and baseId != ''">
|
||||
AND base_id = #{baseId}
|
||||
</if>
|
||||
</where>
|
||||
GROUP BY device_type
|
||||
ORDER BY deviceCount DESC
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user