fix (farm): 性能优化

1. 地块的颜色需要再透明一点 ✅
2. 点击大屏报错 ✅
3. 图片展示不出来 ✅
4. 基础管理 - 模型管理 - 缓存慢
5. 设备中心缓存慢 ✅
6. 首页 - 负责人展示不出来 ✅
7. 基础管理 - 基地规划 - 缓存慢  ✅
8. 网箱数量没接通 ✅
This commit is contained in:
达富斌
2025-11-26 19:22:25 +08:00
parent 91dcfd73c1
commit e6cb5601c6
19 changed files with 185 additions and 387 deletions

View File

@@ -138,6 +138,13 @@ public class DeviceInfoController {
@Operation(summary = "获得设备信息分页") @Operation(summary = "获得设备信息分页")
public CommonResult<PageResult<DeviceInfoPageV2RespVO>> getDeviceInfoPage(@Valid DeviceInfoPageV2ReqVO pageReqVO) { public CommonResult<PageResult<DeviceInfoPageV2RespVO>> getDeviceInfoPage(@Valid DeviceInfoPageV2ReqVO pageReqVO) {
Map<String, String> typeNameMap = deviceClassifyService.getTypeNameMap();
Map<String, String> typeCodeMap = deviceClassifyService.getTypeCodeMap();
Map<String, String> imageMap = deviceClassifyService.getImageMap();
// Map<String, String> basePointMap = baseInfoService.getBasePointMap();
Map<String, String> plotPointMap = plotInfoService.getPlotPointMap();
DeviceInfoPageReqVO targetObj = new DeviceInfoPageReqVO(); DeviceInfoPageReqVO targetObj = new DeviceInfoPageReqVO();
targetObj.setPageSize(100); targetObj.setPageSize(100);
targetObj.setBaseId(pageReqVO.getBaseId()); targetObj.setBaseId(pageReqVO.getBaseId());
@@ -151,14 +158,11 @@ public class DeviceInfoController {
for (DeviceInfoPageV2RespVO d : deviceInfoRespVOPageResult.getList()) { for (DeviceInfoPageV2RespVO d : deviceInfoRespVOPageResult.getList()) {
if (!StringUtils.isEmpty(d.getBaseId()) && !StringUtils.isEmpty(d.getBaseId())) { if (!StringUtils.isEmpty(d.getBaseId()) && !StringUtils.isEmpty(d.getBaseId())) {
BaseInfoDO b = baseInfoService.getBaseInfo(d.getBaseId()); // d.setBasePoint(basePointMap.get(d.getBaseId()));
PlotInfoDO p = plotInfoService.getPlotInfo(d.getPlotId()); d.setPlotPoint(plotPointMap.get(d.getPlotId()));
d.setBasePoint(b.getPoint());
d.setPlotPoint(p.getPoint());
} }
Map<String, String> typeNameMap = deviceClassifyService.getTypeNameMap(); d.setImage(imageMap.get(d.getDeviceType()));
Map<String, String> typeCodeMap = deviceClassifyService.getTypeCodeMap();
d.setDeviceTypeName(typeNameMap.get(d.getDeviceType())); d.setDeviceTypeName(typeNameMap.get(d.getDeviceType()));
d.setDeviceTypeCode(typeCodeMap.get(d.getDeviceType())); d.setDeviceTypeCode(typeCodeMap.get(d.getDeviceType()));
d.setDeviceStateName(DEVICE_STATE_MAP.get(d.getDeviceState())); d.setDeviceStateName(DEVICE_STATE_MAP.get(d.getDeviceState()));

View File

@@ -1,204 +0,0 @@
package cn.iocoder.yudao.module.farm.controller.admin.devicestatus;
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.devicestatus.vo.DeviceStatusRespVO;
import cn.iocoder.yudao.module.farm.controller.admin.devicestatus.vo.DeviceStatusStatisticsRespVO;
import cn.iocoder.yudao.module.farm.dal.dataobject.deviceinfo.DeviceInfoDO;
import cn.iocoder.yudao.module.farm.dal.mysql.deviceinfo.DeviceInfoMapper;
import cn.iocoder.yudao.module.farm.enums.DeviceStateEnum;
import cn.iocoder.yudao.module.farm.service.devicestatus.DeviceStatusService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
//@Tag(name = "管理后台 - 设备状态管理")
//@RestController
//@RequestMapping("/farm/device-status")
//@Validated
//@Slf4j
public class DeviceStatusController {
//
// @Resource
// private DeviceStatusService deviceStatusService;
//
// @Resource
// private DeviceInfoMapper deviceInfoMapper;
//
// @GetMapping("/check/{deviceUniqueId}")
// @Operation(summary = "检查设备是否在线")
// @Parameter(name = "deviceUniqueId", description = "设备唯一标识", required = true, example = "2409AA01")
// @PreAuthorize("@ss.hasPermission('farm:device-status:query')")
// public CommonResult<Boolean> checkDeviceOnline(@PathVariable("deviceUniqueId") String deviceUniqueId) {
// boolean online = deviceStatusService.isDeviceOnline(deviceUniqueId);
// return success(online);
// }
//
// @GetMapping("/state/{deviceUniqueId}")
// @Operation(summary = "获取设备状态")
// @Parameter(name = "deviceUniqueId", description = "设备唯一标识", required = true, example = "2409AA01")
// @PreAuthorize("@ss.hasPermission('farm:device-status:query')")
// public CommonResult<DeviceStatusRespVO> getDeviceStatus(@PathVariable("deviceUniqueId") String deviceUniqueId) {
// DeviceInfoDO device = deviceInfoMapper.selectOne(DeviceInfoDO::getDeviceUniqueId, deviceUniqueId);
// if (device == null) {
// return success(null);
// }
//
// DeviceStatusRespVO respVO = BeanUtils.toBean(device, DeviceStatusRespVO.class);
// if (device.getDeviceState() != null) {
// DeviceStateEnum stateEnum = DeviceStateEnum.valueOf(device.getDeviceState());
// if (stateEnum != null) {
// respVO.setStateName(stateEnum.getName());
// respVO.setOnline(DeviceStateEnum.isOnline(device.getDeviceState()));
// }
// }
// return success(respVO);
// }
//
// @GetMapping("/online-devices")
// @Operation(summary = "获取在线设备列表")
// @PreAuthorize("@ss.hasPermission('farm:device-status:query')")
// public CommonResult<List<DeviceStatusRespVO>> getOnlineDevices() {
// List<DeviceInfoDO> devices = deviceStatusService.getOnlineDevices();
// List<DeviceStatusRespVO> respList = BeanUtils.toBean(devices, DeviceStatusRespVO.class);
//
// // 填充状态信息
// respList.forEach(resp -> {
// if (resp.getState() != null) {
// DeviceStateEnum stateEnum = DeviceStateEnum.valueOf(resp.getState());
// if (stateEnum != null) {
// resp.setStateName(stateEnum.getName());
// resp.setOnline(DeviceStateEnum.isOnline(resp.getState()));
// }
// }
// });
//
// return success(respList);
// }
//
// @GetMapping("/offline-devices")
// @Operation(summary = "获取离线设备列表")
// @PreAuthorize("@ss.hasPermission('farm:device-status:query')")
// public CommonResult<List<DeviceStatusRespVO>> getOfflineDevices() {
// List<DeviceInfoDO> devices = deviceStatusService.getOfflineDevices();
// List<DeviceStatusRespVO> respList = BeanUtils.toBean(devices, DeviceStatusRespVO.class);
//
// // 填充状态信息
// respList.forEach(resp -> {
// if (resp.getState() != null) {
// DeviceStateEnum stateEnum = DeviceStateEnum.valueOf(resp.getState());
// if (stateEnum != null) {
// resp.setStateName(stateEnum.getName());
// resp.setOnline(DeviceStateEnum.isOnline(resp.getState()));
// }
// }
// });
//
// return success(respList);
// }
//
// @GetMapping("/timeout-devices")
// @Operation(summary = "获取超时未上报的设备列表")
// @Parameter(name = "timeoutMinutes", description = "超时分钟数", required = false, example = "10")
// @PreAuthorize("@ss.hasPermission('farm:device-status:query')")
// public CommonResult<List<DeviceStatusRespVO>> getTimeoutDevices(
// @RequestParam(value = "timeoutMinutes", defaultValue = "10") int timeoutMinutes) {
// List<DeviceInfoDO> devices = deviceStatusService.getTimeoutDevices(timeoutMinutes);
// List<DeviceStatusRespVO> respList = BeanUtils.toBean(devices, DeviceStatusRespVO.class);
//
// // 填充状态信息
// respList.forEach(resp -> {
// if (resp.getState() != null) {
// DeviceStateEnum stateEnum = DeviceStateEnum.valueOf(resp.getState());
// if (stateEnum != null) {
// resp.setStateName(stateEnum.getName());
// resp.setOnline(DeviceStateEnum.isOnline(resp.getState()));
// }
// }
// });
//
// return success(respList);
// }
//
// @GetMapping("/statistics")
// @Operation(summary = "获取设备状态统计")
// @PreAuthorize("@ss.hasPermission('farm:device-status:query')")
// public CommonResult<DeviceStatusStatisticsRespVO> getDeviceStatusStatistics() {
// DeviceStatusStatisticsRespVO statistics = new DeviceStatusStatisticsRespVO();
//
// // 统计各状态设备数量
// Long totalCount = deviceInfoMapper.selectCount();
// Long onlineCount = deviceInfoMapper.selectCountByState(DeviceStateEnum.ONLINE.getState());
// Long offlineCount = deviceInfoMapper.selectCountByState(DeviceStateEnum.OFFLINE.getState());
// Long inactiveCount = deviceInfoMapper.selectCountByState(DeviceStateEnum.INACTIVE.getState());
// Long maintenanceCount = deviceInfoMapper.selectCountByState(DeviceStateEnum.MAINTENANCE.getState());
// Long faultCount = deviceInfoMapper.selectCountByState(DeviceStateEnum.FAULT.getState());
//
// statistics.setTotalCount(totalCount);
// statistics.setOnlineCount(onlineCount != null ? onlineCount : 0L);
// statistics.setOfflineCount(offlineCount != null ? offlineCount : 0L);
// statistics.setInactiveCount(inactiveCount != null ? inactiveCount : 0L);
// statistics.setMaintenanceCount(maintenanceCount != null ? maintenanceCount : 0L);
// statistics.setFaultCount(faultCount != null ? faultCount : 0L);
//
// // 计算在线率和离线率
// if (totalCount > 0) {
// statistics.setOnlineRate((double) statistics.getOnlineCount() / totalCount * 100);
// statistics.setOfflineRate((double) statistics.getOfflineCount() / totalCount * 100);
// } else {
// statistics.setOnlineRate(0.0);
// statistics.setOfflineRate(0.0);
// }
//
// return success(statistics);
// }
//
// @PostMapping("/update-state/{deviceUniqueId}")
// @Operation(summary = "手动更新设备状态")
// @Parameter(name = "deviceUniqueId", description = "设备唯一标识", required = true, example = "2409AA01")
// @Parameter(name = "state", description = "设备状态", required = true, example = "1")
// @PreAuthorize("@ss.hasPermission('farm:device-status:update')")
// public CommonResult<Boolean> updateDeviceState(
// @PathVariable("deviceUniqueId") String deviceUniqueId,
// @RequestParam("state") Integer state) {
// deviceStatusService.updateDeviceState(deviceUniqueId, state);
// return success(true);
// }
//
// @PostMapping("/set-online/{deviceUniqueId}")
// @Operation(summary = "手动设置设备上线")
// @Parameter(name = "deviceUniqueId", description = "设备唯一标识", required = true, example = "2409AA01")
// @PreAuthorize("@ss.hasPermission('farm:device-status:update')")
// public CommonResult<Boolean> setDeviceOnline(@PathVariable("deviceUniqueId") String deviceUniqueId) {
// deviceStatusService.deviceOnline(deviceUniqueId);
// return success(true);
// }
//
// @PostMapping("/set-offline/{deviceUniqueId}")
// @Operation(summary = "手动设置设备离线")
// @Parameter(name = "deviceUniqueId", description = "设备唯一标识", required = true, example = "2409AA01")
// @PreAuthorize("@ss.hasPermission('farm:device-status:update')")
// public CommonResult<Boolean> setDeviceOffline(@PathVariable("deviceUniqueId") String deviceUniqueId) {
// deviceStatusService.deviceOffline(deviceUniqueId);
// return success(true);
// }
//
// @PostMapping("/check-offline")
// @Operation(summary = "手动检查离线设备")
// @Parameter(name = "timeoutMinutes", description = "超时分钟数", required = false, example = "10")
// @PreAuthorize("@ss.hasPermission('farm:device-status:update')")
// public CommonResult<Integer> checkOfflineDevices(
// @RequestParam(value = "timeoutMinutes", defaultValue = "10") int timeoutMinutes) {
// int count = deviceStatusService.checkAndUpdateOfflineDevices(timeoutMinutes);
// return success(count);
// }
}

View File

@@ -1,41 +0,0 @@
package cn.iocoder.yudao.module.farm.controller.admin.devicestatus.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 设备状态分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class DeviceStatusPageReqVO extends PageParam {
@Schema(description = "设备名称", example = "温湿度传感器")
private String deviceName;
@Schema(description = "设备状态", example = "1")
private Integer state;
@Schema(description = "设备分类名称", example = "传感器")
private String deviceCategoryName;
@Schema(description = "基地名称", example = "示范基地1")
private String baseName;
@Schema(description = "地块名称", example = "A1地块")
private String plotName;
@Schema(description = "是否在线", example = "true")
private Boolean online;
@Schema(description = "最后消息时间范围")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] lastMessageTime;
}

View File

@@ -1,47 +0,0 @@
package cn.iocoder.yudao.module.farm.controller.admin.devicestatus.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 设备状态 Response VO")
@Data
public class DeviceStatusRespVO {
@Schema(description = "设备唯一标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "2409AA01")
private String deviceUniqueId;
@Schema(description = "设备名称", example = "温湿度传感器1")
private String deviceName;
@Schema(description = "设备状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer state;
@Schema(description = "设备状态名称", example = "在线")
private String stateName;
@Schema(description = "是否在线", example = "true")
private Boolean online;
@Schema(description = "设备激活时间")
private LocalDateTime activeTime;
@Schema(description = "设备最后上线时间")
private LocalDateTime onlineTime;
@Schema(description = "设备最后离线时间")
private LocalDateTime offlineTime;
@Schema(description = "设备最后消息时间")
private LocalDateTime lastMessageTime;
@Schema(description = "设备分类名称", example = "传感器")
private String deviceCategoryName;
@Schema(description = "基地名称", example = "示范基地1")
private String baseName;
@Schema(description = "地块名称", example = "A1地块")
private String plotName;
}

View File

@@ -1,33 +0,0 @@
package cn.iocoder.yudao.module.farm.controller.admin.devicestatus.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 设备状态统计 Response VO")
@Data
public class DeviceStatusStatisticsRespVO {
@Schema(description = "设备总数", example = "100")
private Long totalCount;
@Schema(description = "在线设备数", example = "85")
private Long onlineCount;
@Schema(description = "离线设备数", example = "10")
private Long offlineCount;
@Schema(description = "未激活设备数", example = "3")
private Long inactiveCount;
@Schema(description = "维护中设备数", example = "1")
private Long maintenanceCount;
@Schema(description = "故障设备数", example = "1")
private Long faultCount;
@Schema(description = "在线率(百分比)", example = "85.0")
private Double onlineRate;
@Schema(description = "离线率(百分比)", example = "10.0")
private Double offlineRate;
}

View File

@@ -13,6 +13,7 @@ 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.companyinfo.CompanyInfoService;
import cn.iocoder.yudao.module.farm.service.deviceinfo.DeviceInfoService; 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.farmingrecord.FarmingRecordService;
import cn.iocoder.yudao.module.farm.service.messagecenter.MessageCenterService;
import cn.iocoder.yudao.module.farm.service.modelmanagement.ModelManagementService; 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.plotinfo.PlotInfoService;
import cn.iocoder.yudao.module.farm.service.productionplan.ProductionPlanService; import cn.iocoder.yudao.module.farm.service.productionplan.ProductionPlanService;
@@ -27,7 +28,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
@@ -49,8 +49,9 @@ public class DigitalCockpitController {
private final ProductionPlanService productionPlanService; private final ProductionPlanService productionPlanService;
private final FarmingRecordService farmingRecordService; private final FarmingRecordService farmingRecordService;
private final ModelManagementService modelManagementService; private final ModelManagementService modelManagementService;
private final MessageCenterService messageCenterService;
public DigitalCockpitController(BaseInfoService baseInfoService, PlotInfoService plotInfoService, CompanyInfoService companyInfoService, DeviceInfoService deviceInfoService, ProductionPlanService productionPlanService, FarmingRecordService farmingRecordService, ModelManagementService modelManagementService) { public DigitalCockpitController(BaseInfoService baseInfoService, PlotInfoService plotInfoService, CompanyInfoService companyInfoService, DeviceInfoService deviceInfoService, ProductionPlanService productionPlanService, FarmingRecordService farmingRecordService, ModelManagementService modelManagementService, MessageCenterService messageCenterService) {
this.baseInfoService = baseInfoService; this.baseInfoService = baseInfoService;
this.plotInfoService = plotInfoService; this.plotInfoService = plotInfoService;
this.companyInfoService = companyInfoService; this.companyInfoService = companyInfoService;
@@ -58,6 +59,7 @@ public class DigitalCockpitController {
this.productionPlanService = productionPlanService; this.productionPlanService = productionPlanService;
this.farmingRecordService = farmingRecordService; this.farmingRecordService = farmingRecordService;
this.modelManagementService = modelManagementService; this.modelManagementService = modelManagementService;
this.messageCenterService = messageCenterService;
} }
@GetMapping("/company-info") @GetMapping("/company-info")
@@ -112,13 +114,8 @@ public class DigitalCockpitController {
@Operation(summary = "各项数据统计") @Operation(summary = "各项数据统计")
@Parameter(name = "baseId", description = "基地ID", required = true) @Parameter(name = "baseId", description = "基地ID", required = true)
public CommonResult<VariousIndexesRespVO> getVariousIndexes(@RequestParam("baseId") String baseId) { public CommonResult<VariousIndexesRespVO> getVariousIndexes(@RequestParam("baseId") String baseId) {
// TODO: 2025/9/24 待实现 VariousIndexesRespVO res = messageCenterService.getVariousIndexes(baseId);
int weatherAlertCount = 10; return success(res);
int pestAlertCount = 11;
int environmentalAlertCount = 12;
int deviceAlertCount = 13;
int farmingReminderCount = 14;
return success(new VariousIndexesRespVO(weatherAlertCount, pestAlertCount, environmentalAlertCount, deviceAlertCount, farmingReminderCount));
} }
@GetMapping("/crop-statistics/type/1") @GetMapping("/crop-statistics/type/1")
@@ -196,7 +193,7 @@ public class DigitalCockpitController {
ModelManagementDO mObj = modelManagementService.getTopQuoteCount(); ModelManagementDO mObj = modelManagementService.getTopQuoteCount();
if (ObjectUtils.isEmpty(mObj)) { if (ObjectUtils.isEmpty(mObj)) {
return error(500,"还未创建模型"); return success(new PlanSpeciesRespVO());
} }
PlanSpeciesRespVO res = new PlanSpeciesRespVO(); PlanSpeciesRespVO res = new PlanSpeciesRespVO();
res.setImage(mObj.getSpeciesImage()); res.setImage(mObj.getSpeciesImage());

View File

@@ -14,14 +14,14 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class VariousIndexesRespVO { public class VariousIndexesRespVO {
@Schema(description = "气象预警数量") @Schema(description = "气象告警数量")
private Integer weatherAlertCount; private Integer weatherAlertCount;
@Schema(description = "病虫害告警数量") @Schema(description = "虫害告警数量")
private Integer pestAlertCount; private Integer pestAlertCount;
@Schema(description = "环境告警数量") @Schema(description = "环境告警数量")
private Integer environmentalAlertCount; private Integer environmentalAlertCount;
@Schema(description = "设备告警数量") @Schema(description = "预警数量")
private Integer deviceAlertCount; private Integer deviceAlertCount;
@Schema(description = "农事提醒刷领") @Schema(description = "消息数量")
private Integer farmingReminderCount; private Integer farmingReminderCount;
} }

View File

@@ -101,6 +101,24 @@ public class BaseInfoController {
return success(res); return success(res);
} }
@GetMapping("/base-overview/base")
@Operation(summary = "基地详情")
@Parameter(name = "baseId", description = "基地编号", required = true, example = "1024")
public CommonResult<BaseInfoRespVO.BaseInfo> getBaseOverviewDetails(@RequestParam("baseId") String baseId) {
BaseInfoRespVO.BaseInfo res = baseInfoService.getBaseOverviewDetails(baseId);
return success(res);
}
@GetMapping("/base-overview/plot")
@Operation(summary = "地块详情")
@Parameter(name = "plotId", description = "地块编号", required = true, example = "1024")
public CommonResult<BaseInfoRespVO.PlotInfo> getPlotDetails(@RequestParam("plotId") String plotId) {
BaseInfoRespVO.PlotInfo res = baseInfoService.getPlotDetails(plotId);
return success(res);
}
@GetMapping("/export-excel") @GetMapping("/export-excel")
@Operation(summary = "导出基地 Excel") @Operation(summary = "导出基地 Excel")
@ApiAccessLog(operateType = EXPORT) @ApiAccessLog(operateType = EXPORT)

View File

@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.farm.dal.mysql.messagecenter;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.farm.controller.admin.digitalcockpit.vo.VariousIndexesRespVO;
import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageCenterPageReqVO; import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageCenterPageReqVO;
import cn.iocoder.yudao.module.farm.dal.dataobject.messagecenter.MessageCenterDO; import cn.iocoder.yudao.module.farm.dal.dataobject.messagecenter.MessageCenterDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@@ -83,4 +84,5 @@ public interface MessageCenterMapper extends BaseMapperX<MessageCenterDO> {
@Param("startTime") String startTime, @Param("startTime") String startTime,
@Param("endTime") String endTime); @Param("endTime") String endTime);
VariousIndexesRespVO getVariousIndexes(String baseId);
} }

View File

@@ -86,6 +86,20 @@ public interface BaseInfoService {
*/ */
TenantInfoRespVO getBaseOverviewInfo(); TenantInfoRespVO getBaseOverviewInfo();
/**
* 基地概述详情
* @param baseId
* @return
*/
BaseInfoRespVO.BaseInfo getBaseOverviewDetails(String baseId);
/**
* 地块详情
* @param plotId
* @return
*/
BaseInfoRespVO.PlotInfo getPlotDetails(String plotId);
/** /**
* 获取网箱信息 * 获取网箱信息
* @param plotId * @param plotId
@@ -132,4 +146,5 @@ public interface BaseInfoService {
* @return * @return
*/ */
BaseCountInfoRespVO countBaseInfo(String tenantId); BaseCountInfoRespVO countBaseInfo(String tenantId);
} }

View File

@@ -120,11 +120,6 @@ public class BaseInfoServiceImpl implements BaseInfoService {
if (flag2) { if (flag2) {
throw exception(PLOT_AREA_EXISTS_ERRORS); throw exception(PLOT_AREA_EXISTS_ERRORS);
} }
// 校验: 存在在种地块时 不允许删除
// boolean flag = productionPlanService.validateIncompletePlansBId("base_id", id);
// if (!flag) {
// throw exception(BEING_PLOT_AREA_EXISTS_ERRORS);
// }
// 删除 // 删除
baseInfoMapper.deleteById(id); baseInfoMapper.deleteById(id);
plotInfoService.deleteByBaseId(id); plotInfoService.deleteByBaseId(id);
@@ -234,12 +229,46 @@ public class BaseInfoServiceImpl implements BaseInfoService {
List<BaseInfoRespVO> baseList = BeanUtils.toBean(pageResult, BaseInfoRespVO.class); List<BaseInfoRespVO> baseList = BeanUtils.toBean(pageResult, BaseInfoRespVO.class);
this.packageBaseInfo(tenantId, baseList, employeeMap); this.packageBaseInfo(tenantId, baseList, employeeMap);
// 基地面积 取整
baseList.forEach(e -> e.setArea(BigDecimalUtil.roundedViaMath(e.getArea())));
return new TenantInfoRespVO(tenantInfo, baseList); return new TenantInfoRespVO(tenantInfo, baseList);
} }
@Override
public BaseInfoRespVO.BaseInfo getBaseOverviewDetails(String baseId) {
BaseInfoDO bObj = baseInfoMapper.selectOne("id", baseId);
List<PlotInfoDO> plotList = plotInfoService.getPlotInfos(baseId);
return this.packageBaseOverview(
getLoginUser().getTenantId(),
baseId, bObj.getName(),
bObj.getArea(),
plotList.size());
}
@Override
public BaseInfoRespVO.PlotInfo getPlotDetails(String plotId) {
Map<String, String> employeeMap = adminUserService.getIdAndNickNameMap();
PlotInfoDO aDo = plotInfoService.getPlotInfo(plotId);
// 户主
List<PlotLesseeDetailsRespVO> lesseeList = plotLesseeService.getPlotLesseeList(aDo.getId());
String plotManager = employeeMap.getOrDefault(aDo.getEmployeeId(), "系统");
BaseInfoRespVO.PlotInfo target = new BaseInfoRespVO.PlotInfo(
aDo.getId(),
aDo.getPlotName(),
aDo.getPlotColor(),
BigDecimalUtil.roundedViaMath( aDo.getPlotArea()),
plotManager,
aDo.getPoint(),
aDo.getPlotLeaseStatus(),
LEASE_STATUS_MAP.get(aDo.getPlotLeaseStatus()),
aDo.getGridNumber(),
Collections.EMPTY_LIST,
lesseeList);
return target;
}
@Override @Override
public List<ProductionPlanGridRespVO> getGridInfo(String plotId) { public List<ProductionPlanGridRespVO> getGridInfo(String plotId) {
String plotCode = plotId; String plotCode = plotId;
@@ -434,29 +463,28 @@ public class BaseInfoServiceImpl implements BaseInfoService {
private void packageBaseInfo(long tenantId, List<BaseInfoRespVO> respVOS, Map<String, String> employeeMap) { private void packageBaseInfo(long tenantId, List<BaseInfoRespVO> respVOS, Map<String, String> employeeMap) {
for (BaseInfoRespVO obj : respVOS) { for (BaseInfoRespVO obj : respVOS) {
obj.setArea(BigDecimalUtil.roundedViaMath(obj.getArea()));
String baseId = obj.getId(); String baseId = obj.getId();
String baseName = obj.getName(); String baseName = obj.getName();
BigDecimal baseArea = BigDecimalUtil.roundedViaMath(obj.getArea());
List<PlotInfoDO> plotList = plotInfoService.getPlotInfos(baseId); List<PlotInfoDO> plotList = plotInfoService.getPlotInfos(baseId);
// 基地概述 // 基地概述
BaseInfoRespVO.BaseInfo baseOverview = this.packageBaseOverview(tenantId, baseId, baseName, baseArea, plotList); // BaseInfoRespVO.BaseInfo baseOverview = this.packageBaseOverview(tenantId, baseId, baseName, baseArea, plotList.size());
obj.setBaseOverview(baseOverview); // obj.setBaseOverview(baseOverview);
// 地块集合 // 地块集合
List<BaseInfoRespVO.PlotInfo> targetList = this.packagePlotInfo(employeeMap, plotList); List<BaseInfoRespVO.PlotInfo> targetList = this.packagePlotInfo(employeeMap, plotList);
obj.setPlotOverviewList(targetList); obj.setPlotOverviewList(targetList);
} }
} }
private BaseInfoRespVO.BaseInfo packageBaseOverview(long tenantId, String baseId, String baseName, BigDecimal baseArea, List<PlotInfoDO> plotList) { private BaseInfoRespVO.BaseInfo packageBaseOverview(long tenantId, String baseId, String baseName, BigDecimal baseArea, int plotTotalCount) {
// 在种作物数量 // 在种作物数量
Integer cropCount = speciesLibraryMapper.getSpeciesCount(tenantId, baseId); Integer cropCount = speciesLibraryMapper.getSpeciesCount(tenantId, baseId);
// 在种地块占比 // 在种地块占比
double plotRatio = 0.00; double plotRatio = 0.00;
// 在种地块数量 // 在种地块数量
int plotCount = productionPlanService.getGrowingPlotCount(baseId); int plotCount = productionPlanService.getGrowingPlotCount(baseId);
// 地块总数
int plotTotalCount = plotList.size();
if (plotTotalCount > 0) { if (plotTotalCount > 0) {
plotRatio = Math.round((plotCount * 10000.0) / plotTotalCount) / 100.0; plotRatio = Math.round((plotCount * 10000.0) / plotTotalCount) / 100.0;
} }
@@ -464,29 +492,21 @@ public class BaseInfoServiceImpl implements BaseInfoService {
} }
private List<BaseInfoRespVO.PlotInfo> packagePlotInfo(Map<String, String> employeeMap, List<PlotInfoDO> plotList) { private List<BaseInfoRespVO.PlotInfo> packagePlotInfo(Map<String, String> employeeMap, List<PlotInfoDO> plotList) {
List<BaseInfoRespVO.PlotInfo> targetList = new ArrayList<>(); return plotList.stream().map(aDo ->
for (PlotInfoDO aDo : plotList) { new BaseInfoRespVO.PlotInfo(
// 网箱
// List<ProductionPlanGridRespVO> gridInfos = this.packageGridInfo(aDo.getPlotId());
List<ProductionPlanGridRespVO> gridInfos = Collections.EMPTY_LIST;
// 户主
List<PlotLesseeDetailsRespVO> lesseeList = plotLesseeService.getPlotLesseeList(aDo.getId());
String plotManager = employeeMap.getOrDefault(aDo.getEmployeeId(), "系统");
BaseInfoRespVO.PlotInfo target = new BaseInfoRespVO.PlotInfo(
aDo.getId(), aDo.getId(),
aDo.getPlotName(), aDo.getPlotName(),
aDo.getPlotColor(), aDo.getPlotColor(),
BigDecimalUtil.roundedViaMath(aDo.getPlotArea()), BigDecimalUtil.roundedViaMath(aDo.getPlotArea()),
plotManager, "",
aDo.getPoint(), aDo.getPoint(),
aDo.getPlotLeaseStatus(), aDo.getPlotLeaseStatus(),
LEASE_STATUS_MAP.get(aDo.getPlotLeaseStatus()), "",
// LEASE_STATUS_MAP.get(aDo.getPlotLeaseStatus()),
aDo.getGridNumber(), aDo.getGridNumber(),
gridInfos, Collections.EMPTY_LIST,
lesseeList); Collections.EMPTY_LIST)
targetList.add(target); ).toList();
}
return targetList;
} }
private List<ProductionPlanGridRespVO> packageGridInfo(String plotId) { private List<ProductionPlanGridRespVO> packageGridInfo(String plotId) {

View File

@@ -70,7 +70,10 @@ public interface DeviceClassifyService {
Map<String, String> getTypeNameMap(); Map<String, String> getTypeNameMap();
Map<String, String> getTypeCodeMap(); Map<String, String> getTypeCodeMap();
Map<String, String> getImageMap();
Map<String, String> getTypeNameMap(String tenantId); Map<String, String> getTypeNameMap(String tenantId);
Map<String, String> getTypeCodeMap(String tenantId); Map<String, String> getTypeCodeMap(String tenantId);
} }

View File

@@ -234,6 +234,18 @@ public class DeviceClassifyServiceImpl implements DeviceClassifyService {
return typeCodeMap; return typeCodeMap;
} }
@Override
public Map<String, String> getImageMap() {
LambdaQueryWrapperX<DeviceClassifyDO> x = new LambdaQueryWrapperX<>();
x.eq(DeviceClassifyDO::getTenantId, getLoginUser().getTenantId());
List<DeviceClassifyDO> deviceClassifyDOS = deviceClassifyMapper.selectList(x);
Map<String, String> imageMap = deviceClassifyDOS.stream().filter(device -> device.getParentId() != null && device.getParentId() != 0)
.collect(Collectors.toMap(e -> e.getParentId().toString(), DeviceClassifyDO::getImage));
return imageMap;
}
public Map<String, String> getTypeNameMap(String tenantId) { public Map<String, String> getTypeNameMap(String tenantId) {
LambdaQueryWrapperX<DeviceClassifyDO> x = new LambdaQueryWrapperX<>(); LambdaQueryWrapperX<DeviceClassifyDO> x = new LambdaQueryWrapperX<>();
x.eq(DeviceClassifyDO::getTenantId, tenantId); x.eq(DeviceClassifyDO::getTenantId, tenantId);
@@ -254,4 +266,5 @@ public class DeviceClassifyServiceImpl implements DeviceClassifyService {
return typeCodeMap; return typeCodeMap;
} }
} }

View File

@@ -275,17 +275,17 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
@Override @Override
public PageResult<DeviceInfoDO> getDeviceInfoPage(DeviceInfoPageReqVO pageReqVO) { public PageResult<DeviceInfoDO> getDeviceInfoPage(DeviceInfoPageReqVO pageReqVO) {
PageResult<DeviceInfoDO> pageResult = deviceInfoMapper.selectPage(pageReqVO); PageResult<DeviceInfoDO> pageResult = deviceInfoMapper.selectPage(pageReqVO);
if (pageResult.getList() != null) { // if (pageResult.getList() != null) {
// 触发图片集合转换,确保分页结果中的每个DO对象都包含转换后的图片集合 // // 触发图片集合转换,确保分页结果中的每个DO对象都包含转换后的图片集合
for (DeviceInfoDO d : pageResult.getList()) { // for (DeviceInfoDO d : pageResult.getList()) {
if (d == null) { // if (d == null) {
continue; // continue;
} // }
DeviceClassifyDO dc = deviceClassifyMapper.selectOne(DeviceClassifyDO::getId, d.getDeviceType()); // DeviceClassifyDO dc = deviceClassifyMapper.selectOne(DeviceClassifyDO::getId, d.getDeviceType());
d.setImage(dc.getImage()); // d.setImage(dc.getImage());
d.setImageList(dc.getImageList()); //// d.setImageList(dc.getImageList());
} // }
} // }
return pageResult; return pageResult;
} }

View File

@@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.farm.service.messagecenter; package cn.iocoder.yudao.module.farm.service.messagecenter;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.farm.controller.admin.digitalcockpit.vo.VariousIndexesRespVO;
import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageCenterPageReqVO; import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageCenterPageReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageCenterSaveReqVO; import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageCenterSaveReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageStatisticsRespVO; import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageStatisticsRespVO;
@@ -77,4 +78,11 @@ public interface MessageCenterService {
* @param messageType * @param messageType
*/ */
void pushMessage(String title, String content, Integer messageType); void pushMessage(String title, String content, Integer messageType);
/**
* 预警统计
* @param baseId
* @return
*/
VariousIndexesRespVO getVariousIndexes(String baseId);
} }

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.util.IdUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.module.farm.controller.admin.digitalcockpit.vo.VariousIndexesRespVO;
import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageCenterPageReqVO; import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageCenterPageReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageCenterSaveReqVO; import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageCenterSaveReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageStatisticsRespVO; import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.messagecenter.vo.MessageStatisticsRespVO;
@@ -146,4 +147,10 @@ public class MessageCenterServiceImpl implements MessageCenterService {
this.createMessageCenter(m); this.createMessageCenter(m);
} }
@Override
public VariousIndexesRespVO getVariousIndexes(String baseId) {
VariousIndexesRespVO res = messageCenterMapper.getVariousIndexes(baseId);
return res;
}
} }

View File

@@ -9,6 +9,7 @@ import jakarta.validation.Valid;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 地块 Service 接口 * 地块 Service 接口
@@ -117,4 +118,11 @@ public interface PlotInfoService {
* @return * @return
*/ */
List<PlotListRespVO> listPlotInfo(String baseId); List<PlotListRespVO> listPlotInfo(String baseId);
/**
* id
* point
* @return
*/
Map<String, String> getPlotPointMap();
} }

View File

@@ -26,6 +26,7 @@ import org.springframework.validation.annotation.Validated;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
@@ -311,6 +312,17 @@ public class PlotInfoServiceImpl implements PlotInfoService {
return pList; return pList;
} }
@Override
public Map<String, String> getPlotPointMap() {
LambdaQueryWrapperX<PlotInfoDO> wrapperX = new LambdaQueryWrapperX<>();
wrapperX.eq(PlotInfoDO::getDeleted, CommonConstants.NO_CODE);
List<PlotInfoDO> plotInfoDOS = plotInfoMapper.selectList(wrapperX);
Map<String, String> pointMap = plotInfoDOS.stream().collect(Collectors.toMap(PlotInfoDO::getId, PlotInfoDO::getPoint, (v1, v2) -> v1));
return pointMap;
}
// ==================== 私有方法 ==================== // ==================== 私有方法 ====================
/** /**

View File

@@ -9,4 +9,20 @@
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
--> -->
<select id="getVariousIndexes"
resultType="cn.iocoder.yudao.module.farm.controller.admin.digitalcockpit.vo.VariousIndexesRespVO">
SELECT
COALESCE(SUM(CASE WHEN message_type = 1 THEN 1 ELSE 0 END), 0) as weatherAlertCount,
COALESCE(SUM(CASE WHEN message_type = 100 THEN 1 ELSE 0 END), 0) as pestAlertCount,
COALESCE(SUM(CASE WHEN message_type = 10 THEN 1 ELSE 0 END), 0) as environmentalAlertCount,
COALESCE(SUM(CASE WHEN message_type = 2 THEN 1 ELSE 0 END), 0) as deviceAlertCount,
COALESCE(SUM(CASE WHEN message_type = 3 THEN 1 ELSE 0 END), 0) as farmingReminderCount
FROM farm_message_center
<where>
deleted = 0
<if test="baseId != null and baseId != ''">
AND base_id = #{baseId}
</if>
</where>
</select>
</mapper> </mapper>