Selaa lähdekoodia

uniapp模块与base模块合并device、filed、AlertRecord相关接口

jiuling 10 kuukautta sitten
vanhempi
sitoutus
25ad8b1ee2
41 muutettua tiedostoa jossa 826 lisäystä ja 1595 poistoa
  1. 62 0
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/controller/DeviceController.java
  2. 68 0
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/controller/FieldController.java
  3. 3 2
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/AlertRecord.java
  4. 29 0
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/Field.java
  5. 4 0
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/WeatherRealtimeData.java
  6. 2 1
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/dto/DeviceDto.java
  7. 1 1
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/enums/DeviceTypeEnum.java
  8. 1 1
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/enums/FieldStatusEnum.java
  9. 1 1
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/enums/FieldTypeEnum.java
  10. 2 1
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/vo/DeviceOverviewVO.java
  11. 3 2
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/vo/FieldVO.java
  12. 3 2
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/mapper/AlertRecordMapper.java
  13. 36 0
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/mapper/DeviceMapper.java
  14. 45 0
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/mapper/FieldMapper.java
  15. 8 0
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/mapper/WeatherRealtimeDataMapper.java
  16. 29 0
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/service/IDeviceService.java
  17. 45 0
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/service/IFieldService.java
  18. 123 0
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/service/impl/DeviceServiceImpl.java
  19. 177 4
      ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/service/impl/FieldServiceImpl.java
  20. 2 2
      ruoyi-modules/ruoyi-base/src/main/resources/mapper/base/AlertRecordMapper.xml
  21. 86 0
      ruoyi-modules/ruoyi-base/src/main/resources/mapper/base/DeviceMapper.xml
  22. 87 2
      ruoyi-modules/ruoyi-base/src/main/resources/mapper/base/FieldMapper.xml
  23. 9 0
      ruoyi-modules/ruoyi-base/src/main/resources/mapper/base/WeatherRealtimeDataMapper.xml
  24. 0 101
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/controller/DeviceController.java
  25. 0 90
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/controller/FieldController.java
  26. 0 80
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/Device.java
  27. 0 111
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/Field.java
  28. 0 83
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/WeatherRealtimeData.java
  29. 0 62
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/mapper/DeviceMapper.java
  30. 0 57
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/mapper/FieldMapper.java
  31. 0 18
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/mapper/WeatherRealtimeDataMapper.java
  32. 0 50
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/service/IDeviceService.java
  33. 0 57
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/service/IFieldService.java
  34. 0 155
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/service/impl/DeviceServiceImpl.java
  35. 0 198
      ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/service/impl/FieldServiceImpl.java
  36. 0 87
      ruoyi-modules/ruoyi-uniapp/src/main/resources/logback-spring.xml
  37. 0 121
      ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/DeviceMapper.xml
  38. 0 117
      ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/FieldMapper.xml
  39. 0 146
      ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/KnowledgeArticleMapper.xml
  40. 0 0
      ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/KnowledgeContentMapper.xml
  41. 0 43
      ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/WeatherRealtimeDataMapper.xml

+ 62 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/controller/DeviceController.java

@@ -1,7 +1,13 @@
 package com.ruoyi.base.controller;
 
 import com.ruoyi.base.domain.Device;
+import com.ruoyi.base.domain.WeatherRealtimeData;
+import com.ruoyi.base.domain.dto.DeviceDto;
+import com.ruoyi.base.domain.enums.DeviceTypeEnum;
+import com.ruoyi.base.domain.vo.DeviceOverviewVO;
 import com.ruoyi.base.service.IDeviceService;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.web.controller.BaseController;
 import com.ruoyi.common.core.web.domain.AjaxResult;
@@ -14,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -105,4 +112,59 @@ public class DeviceController extends BaseController
     }
 
 
+    /*
+    * uniapp 接口
+    * eg:getOverview、listByType、getDeviceCollectorDetail
+    * */
+
+    /**
+     * 获取设备概览
+     */
+    @PostMapping("/overview")
+    public AjaxResult getOverview(@RequestBody DeviceDto device) {
+        if (device.getFieldId() == null){
+            return error("请选择所属地块!");
+        }
+        DeviceOverviewVO overview = deviceService.getDeviceOverview(device.getUserId(), device.getFieldId());
+        return success(overview);
+    }
+
+    /**
+     *根据条件(地块、用户、设备类型)查询设备列表
+     */
+    @PostMapping("/typeList")
+    public TableDataInfo listByType(@RequestBody DeviceDto device) {
+
+        //若缺少必要条件时,返回空表格数据
+        if (device.getFieldId() == null &&
+                device.getUserId() == null &&
+                device.getDeviceType() == null) {
+            return getDataTable(Collections.emptyList());
+        }
+
+        //设备类型不为空,则进行转换为对应code
+        String frontendType = device.getDeviceType();
+        if (StringUtils.isNotEmpty(frontendType)) {
+            String code = DeviceTypeEnum.getCodeByFrontendType(frontendType);
+            if (code == null) {
+                //若无法根据前端type获取到code时,可适时抛出异常或者返回空
+                return getDataTable(Collections.emptyList());
+            }
+            device.setDeviceTypeId(code);
+        }
+
+        startPage();
+
+        List<Device> list = deviceService.selectUniappDeviceList(device);
+        return getDataTable(list);
+    }
+
+    /**
+     * 根据设备编号获取设备详情(包含气象/土壤数据和告警信息)
+     */
+    @GetMapping("/collector/detail/{deviceId}")
+    public R<WeatherRealtimeData> getDeviceCollectorDetail(@PathVariable("deviceId") String deviceId, String deviceTypeId) {
+        WeatherRealtimeData detail = deviceService.getDeviceDetail(deviceId,deviceTypeId);
+        return R.ok(detail);
+    }
 }

+ 68 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/controller/FieldController.java

@@ -1,7 +1,11 @@
 package com.ruoyi.base.controller;
 
+import com.github.pagehelper.PageInfo;
 import com.ruoyi.base.domain.Field;
+import com.ruoyi.base.domain.vo.FieldVO;
 import com.ruoyi.base.service.IFieldService;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.web.controller.BaseController;
 import com.ruoyi.common.core.web.domain.AjaxResult;
@@ -198,4 +202,68 @@ public class FieldController extends BaseController
     {
         return toAjax(fieldService.unbindFieldUser(ids));
     }
+
+
+    /*
+    * uniapp 接口:listFieldName、listByUserId、searchByUserId、countUserPlots
+    * */
+
+    /**
+     * 返回用户关联的地块信息(不分页)
+     */
+    @GetMapping("/name/{userId}")
+    public R<List<Field>> listFieldName(@PathVariable("userId") Long userId) {
+        List<Field> fields = fieldService.fieldNameByUserList(userId);
+        return R.ok(fields);
+    }
+
+    /**
+     * 根据用户ID查询关联地块列表
+     */
+    @PostMapping("/list/user")
+    public R<PageInfo<FieldVO>> listByUserId(@RequestBody Field field) {
+        if (field.getUserId() == null){
+            return R.fail("查询用户关联地块信息失败");
+        }
+
+        Object pageNum = field.getParams().get("pageNum");
+        Object pageSize = field.getParams().get("pageSize");
+        if (null != pageNum && null != pageSize){
+            PageInfo<FieldVO> fieldVOPageInfo = fieldService.selectFieldListByUserId(field.getUserId(), new Integer(pageNum.toString()), new Integer(pageSize.toString()));
+            return R.ok(fieldVOPageInfo);
+        }
+        return R.fail("分页查询参数缺失");
+
+    }
+
+
+    /**
+     * 根据用户ID搜索地块信息
+     */
+    @PostMapping("/search/user")
+    public R<PageInfo<FieldVO>> searchByUserId(@RequestBody Field field) {
+        if (field.getUserId() == null || field.getUserId() <= 0) {
+            return R.fail("用户ID不能为空或小于等于0");
+        }
+        Object pageNum = field.getParams().get("pageNum");
+        Object pageSize = field.getParams().get("pageSize");
+        Object keyword = field.getParams().get("keyword");
+        String keywordValue = keyword.toString();
+        if (null != pageNum && null != pageSize){
+            PageInfo<FieldVO> fieldVOPageInfo = fieldService.searchFieldsByUserIdAndKeyword(field.getUserId(), StringUtils.trimToNull(keywordValue), new Integer(pageNum.toString()), new Integer(pageSize.toString()));
+            return R.ok(fieldVOPageInfo);
+        }
+        // 构建带有分页信息的返回对象
+        return R.fail("搜索地块信息失败");
+    }
+
+
+    /**
+     * 根据用户ID查询关联地块列表
+     */
+    @GetMapping("/count/{userId}")
+    public R<FieldVO> countUserPlots(@PathVariable("userId") Long userId) {
+        FieldVO fieldCounts = fieldService.countFieldTotalByUser(userId);
+        return R.ok(fieldCounts);
+    }
 }

+ 3 - 2
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/AlertRecord.java → ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/AlertRecord.java

@@ -1,11 +1,12 @@
-package com.ruoyi.uniapp.domain;
+package com.ruoyi.base.domain;
 
-import java.util.Date;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.ruoyi.common.core.annotation.Excel;
 import com.ruoyi.common.core.web.domain.BaseEntity;
 import lombok.Data;
 
+import java.util.Date;
+
 /**
  * 告警记录对象 alert_record
  * 

+ 29 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/Field.java

@@ -30,6 +30,9 @@ public class Field extends BaseEntity
     /** 主键ID */
     private Long id;
 
+    /** 用户ID */
+    private Long userId;
+
     /** 地块编号 */
     @Excel(name = "地块编号")
     private String fieldCode;
@@ -42,6 +45,10 @@ public class Field extends BaseEntity
     @Excel(name = "所属农场ID")
     private Long farmId;
 
+    /** 所属农场名称(非数据库字段) */
+    @Excel(name = "所属农场名称")
+    private String farmName;
+
     /** 地块类型 */
     @Excel(name = "地块类型")
     private String fieldType;
@@ -124,7 +131,29 @@ public class Field extends BaseEntity
     /** 所属机构id集合-查询条件 */
     private List<String> deptIdList;
 
+    /** 设备数量(非数据库字段) */
+    private Integer deviceCount;
+
+    /** 在线设备数量(非数据库字段) */
+    private Integer onlineDevices;
+
+    /** 告警数量(非数据库字段) */
+    private Integer alerts;
+
+    /*
+     * 地块总数
+     * */
+    private Integer plotsTotal;
+
+    /*
+     * 使用中数量
+     * */
+    private Integer inUseCount;
 
+    /*
+     * 空闲数量
+     * */
+    private Integer leiSureCount;
 
 
 

+ 4 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/WeatherRealtimeData.java

@@ -12,6 +12,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 气象站实时数据对象 weather_realtime_data
@@ -94,4 +95,7 @@ public class WeatherRealtimeData extends BaseEntity
 
     private LocalDateTime endWeatherTime;
 
+    /*告警列表*/
+    private List<AlertRecord> alertRecordList;
+
 }

+ 2 - 1
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/dto/DeviceDto.java → ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/dto/DeviceDto.java

@@ -1,6 +1,7 @@
-package com.ruoyi.uniapp.domain.dto;
+package com.ruoyi.base.domain.dto;
 
 import lombok.Data;
+
 @Data
 public class DeviceDto {
     /** 用户ID */

+ 1 - 1
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/enums/DeviceTypeEnum.java → ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/enums/DeviceTypeEnum.java

@@ -1,4 +1,4 @@
-package com.ruoyi.uniapp.domain.enums;
+package com.ruoyi.base.domain.enums;
 
 /**
  * 设备类型枚举

+ 1 - 1
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/enums/FieldStatusEnum.java → ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/enums/FieldStatusEnum.java

@@ -1,4 +1,4 @@
-package com.ruoyi.uniapp.domain.enums;
+package com.ruoyi.base.domain.enums;
 
 /**
  * 地块使用状态枚举

+ 1 - 1
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/enums/FieldTypeEnum.java → ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/enums/FieldTypeEnum.java

@@ -1,4 +1,4 @@
-package com.ruoyi.uniapp.domain.enums;
+package com.ruoyi.base.domain.enums;
 
 /**
  * 地块类型枚举

+ 2 - 1
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/vo/DeviceOverviewVO.java → ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/vo/DeviceOverviewVO.java

@@ -1,6 +1,7 @@
-package com.ruoyi.uniapp.domain.vo;
+package com.ruoyi.base.domain.vo;
 
 import lombok.Data;
+
 import java.io.Serializable;
 import java.util.List;
 

+ 3 - 2
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/vo/FieldVO.java → ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/domain/vo/FieldVO.java

@@ -1,8 +1,9 @@
-package com.ruoyi.uniapp.domain.vo;
+package com.ruoyi.base.domain.vo;
 
-import java.math.BigDecimal;
 import lombok.Data;
 
+import java.math.BigDecimal;
+
 /**
  * 地块信息视图对象
  * 

+ 3 - 2
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/mapper/AlertRecordMapper.java → ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/mapper/AlertRecordMapper.java

@@ -1,7 +1,8 @@
-package com.ruoyi.uniapp.mapper;
+package com.ruoyi.base.mapper;
+
+import com.ruoyi.base.domain.AlertRecord;
 
 import java.util.List;
-import com.ruoyi.uniapp.domain.AlertRecord;
 
 /**
  * 告警记录Mapper接口

+ 36 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/mapper/DeviceMapper.java

@@ -2,6 +2,9 @@ package com.ruoyi.base.mapper;
 
 import com.ruoyi.base.domain.Device;
 import com.ruoyi.base.domain.FieldPersonnel;
+import com.ruoyi.base.domain.dto.DeviceDto;
+import com.ruoyi.base.domain.vo.DeviceOverviewVO;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
@@ -91,6 +94,39 @@ public interface DeviceMapper
 
     List<FieldPersonnel> selectUserById(Long id);
 
+    /**
+     * 查询设备列表
+     *
+     * @param device 设备信息
+     * @return 设备集合
+     */
+    public List<Device> selectUniappDeviceList(DeviceDto device);
+
+    /**
+     * 按设备类型统计在线和离线设备数量
+     *
+     * @param fieldId 地块ID
+     * @param userId 用户ID
+     * @return 设备统计信息
+     */
+    public List<Map<String, Object>> countDevicesByType(@Param("fieldId") String fieldId , @Param("userId") String userId);
+
+    /**
+     * 按设备类型统计告警数量
+     *
+     * @param farmId 农场ID,可为空
+     * @param fieldId 地块ID,可为空
+     * @return 告警统计信息
+     */
+    public List<Map<String, Object>> countAlertsByType(@Param("farmId") String farmId, @Param("fieldId") String fieldId);
 
+    /**
+     * 获取设备统计信息
+     *
+     * @param fieldId 地块ID
+     * @param userId 用户ID
+     * @return 包含totalDevices、onlineDevices、offlineDevices、alertDevices的Map
+     */
+    public DeviceOverviewVO countDeviceStatistics(@Param("fieldId") String fieldId , @Param("userId") String userId);
 
 }

+ 45 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/mapper/FieldMapper.java

@@ -1,8 +1,10 @@
 package com.ruoyi.base.mapper;
 
 import com.ruoyi.base.domain.Field;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -64,4 +66,47 @@ public interface FieldMapper
     public int deleteFieldByIds(Long[] ids);
 
 
+    /**
+     * 根据用户ID查询用户关联的地块信息列表
+     *
+     * @param userId 用户ID
+     * @return 地块信息集合
+     */
+    public List<Field> selectFieldListByUserId(@Param("userId") Long userId);
+
+
+    /**
+     * 根据用户ID和关键词搜索地块
+     *
+     * @param userId 用户ID
+     * @param keyword 搜索关键字
+     * @return 地块信息集合
+     */
+    public List<Field> searchFieldsByUserIdAndKeyword(@Param("userId") Long userId, @Param("keyword") String keyword);
+
+
+    /**
+     * 获取用户的地块总数、状态数量;
+     *
+     * @param userId 用户ID
+     * @return 地块总数、状态数量
+     */
+    public Field countFieldTotalByUser(Long userId);
+
+    /**
+     * 批量获取地块设备数量
+     *
+     * @param fieldIds 地块ID列表
+     * @return 地块ID与设备数量的映射
+     */
+    public List<Map<String, Object>> batchCountDevicesByFieldIds(@Param("fieldIds") List<Long> fieldIds);
+
+    /**
+     * 批量获取地块在线设备数量
+     *
+     * @param fieldIds 地块ID列表
+     * @return 地块ID与在线设备数量的映射
+     */
+    public List<Map<String, Object>> batchCountOnlineDevicesByFieldIds(@Param("fieldIds") List<Long> fieldIds);
+
 }

+ 8 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/mapper/WeatherRealtimeDataMapper.java

@@ -70,4 +70,12 @@ public interface WeatherRealtimeDataMapper
      */
     public int deleteWeatherRealtimeDataByIds(Long[] ids);
 
+    /**
+     * 查询最新的气象站实时数据
+     *
+     * @param deviceId 设备编号
+     * @return 气象站实时数据
+     */
+    public WeatherRealtimeData selectLatestDataByDeviceId(String deviceId);
+
 }

+ 29 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/service/IDeviceService.java

@@ -1,6 +1,9 @@
 package com.ruoyi.base.service;
 
 import com.ruoyi.base.domain.Device;
+import com.ruoyi.base.domain.WeatherRealtimeData;
+import com.ruoyi.base.domain.dto.DeviceDto;
+import com.ruoyi.base.domain.vo.DeviceOverviewVO;
 
 import java.util.List;
 
@@ -61,4 +64,30 @@ public interface IDeviceService
      * @return 结果
      */
     public int deleteDeviceById(Long id);
+
+    /**
+     * Uniapp 查询设备列表
+     *
+     * @param device 设备信息
+     * @return 设备集合
+     */
+    public List<Device> selectUniappDeviceList(DeviceDto device);
+
+    /**
+     * 获取设备概览信息
+     *
+     * @param userId 用户ID
+     * @param fieldId 地块ID
+     * @return 设备概览信息
+     */
+    public DeviceOverviewVO getDeviceOverview(String userId, String fieldId);
+
+    /**
+     * 根据设备编号获取设备详情(包含气象/土壤数据和告警信息)
+     *
+     * @param deviceId 设备编号
+     * @param deviceTypeId 设备类型编号
+     * @return 设备详情数据
+     */
+    public WeatherRealtimeData getDeviceDetail(String deviceId, String deviceTypeId);
 }

+ 45 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/service/IFieldService.java

@@ -1,8 +1,10 @@
 package com.ruoyi.base.service;
 
+import com.github.pagehelper.PageInfo;
 import com.ruoyi.base.domain.Device;
 import com.ruoyi.base.domain.Field;
 import com.ruoyi.base.domain.FieldPersonnel;
+import com.ruoyi.base.domain.vo.FieldVO;
 
 import java.util.List;
 
@@ -132,4 +134,47 @@ public interface IFieldService
      * @return 地块信息
      */
     public  List<FieldPersonnel> selectUserUnById(Long id);
+
+
+    /**
+     * 获取用户的地块;
+     *
+     * @param userId 用户ID
+     * @return 地块总数、状态数量
+     */
+    public List<Field> fieldNameByUserList(Long userId);
+
+    /**
+     * 根据用户ID查询用户关联的地块列表
+     *
+     * @param userId 用户ID
+     * @return 地块信息集合
+     */
+    public PageInfo<FieldVO> selectFieldListByUserId(Long userId, Integer pageNum, Integer pageSize);
+
+
+    /**
+     * 根据用户ID和关键词搜索地块
+     *
+     * @param userId 用户ID
+     * @param keyword 搜索关键词
+     * @return 地块信息集合
+     */
+    public PageInfo<FieldVO> searchFieldsByUserIdAndKeyword(Long userId, String keyword,Integer pageNum, Integer pageSize);
+
+    /**
+     * 获取用户的地块总数、状态数量;
+     *
+     * @param userId 地块ID
+     * @return 地块总数、状态数量
+     */
+    public FieldVO countFieldTotalByUser(Long userId);
+
+    /**
+     * 转换地块实体为VO对象
+     *
+     * @param field 地块实体
+     * @return 地块VO对象
+     */
+    public FieldVO convertToVO(Field field);
 }

+ 123 - 0
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/service/impl/DeviceServiceImpl.java

@@ -1,13 +1,23 @@
 package com.ruoyi.base.service.impl;
 
+import com.ruoyi.base.domain.AlertRecord;
 import com.ruoyi.base.domain.Device;
+import com.ruoyi.base.domain.WeatherRealtimeData;
+import com.ruoyi.base.domain.dto.DeviceDto;
+import com.ruoyi.base.domain.enums.DeviceTypeEnum;
+import com.ruoyi.base.domain.vo.DeviceOverviewVO;
+import com.ruoyi.base.mapper.AlertRecordMapper;
 import com.ruoyi.base.mapper.DeviceMapper;
+import com.ruoyi.base.mapper.WeatherRealtimeDataMapper;
 import com.ruoyi.base.service.IDeviceService;
 import com.ruoyi.common.core.utils.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -22,6 +32,12 @@ public class DeviceServiceImpl implements IDeviceService
     @Autowired
     private DeviceMapper deviceMapper;
 
+    @Autowired
+    private WeatherRealtimeDataMapper weatherRealtimeDataMapper;
+
+    @Autowired
+    private AlertRecordMapper alertRecordMapper;
+
     /**
      * 查询设备
      * 
@@ -95,4 +111,111 @@ public class DeviceServiceImpl implements IDeviceService
     {
         return deviceMapper.deleteDeviceById(id);
     }
+
+    /**
+     * 查询设备列表
+     *
+     * @param device 设备信息
+     * @return 设备
+     */
+    @Override
+    public List<Device> selectUniappDeviceList(DeviceDto device) {
+        return deviceMapper.selectUniappDeviceList(device);
+    }
+
+    /**
+     * 获取设备概览信息
+     *
+     * @param userId 用户ID
+     * @param fieldId 地块ID
+     * @return 设备概览信息
+     */
+    @Override
+    public DeviceOverviewVO getDeviceOverview(String userId, String fieldId) {
+
+        DeviceOverviewVO overview = deviceMapper.countDeviceStatistics(fieldId,userId);
+
+        // 获取按设备类型分组的统计数据
+        List<Map<String, Object>> deviceStats = deviceMapper.countDevicesByType(fieldId,userId);
+        // TODO 等待告警模块完善
+        // List<Map<String, Object>> alertStats = deviceMapper.countAlertsByType(farmId, fieldId);
+
+        // 初始化设备类型统计列表
+        Map<String, DeviceOverviewVO> deviceTypeMap = initDeviceTypeMap();
+
+        // 填充设备数量数据
+        for (Map<String, Object> stat : deviceStats) {
+            String deviceTypeId = (String) stat.get("deviceTypeId");
+            DeviceTypeEnum deviceType = DeviceTypeEnum.getByCode(deviceTypeId);
+
+            if (deviceType != null) {
+                String frontendType = deviceType.getFrontendType();
+                DeviceOverviewVO typeStats = deviceTypeMap.get(frontendType);
+
+                if (typeStats != null) {
+                    typeStats.setOnline(((Number) stat.get("online")).intValue());
+                    typeStats.setOffline(((Number) stat.get("offline")).intValue());
+                }
+            }
+        }
+
+        // 填充告警数据
+        /*for (Map<String, Object> stat : alertStats) {
+            String deviceTypeId = (String) stat.get("deviceTypeId");
+            DeviceTypeEnum deviceType = DeviceTypeEnum.getByCode(deviceTypeId);
+
+            if (deviceType != null) {
+                String frontendType = deviceType.getFrontendType();
+                DeviceTypeStatsVO typeStats = deviceTypeMap.get(frontendType);
+
+                if (typeStats != null) {
+                    typeStats.setAlerts(((Number) stat.get("alerts")).intValue());
+                }
+            }
+        }*/
+
+        // 设置设备类型统计列表
+        overview.setDeviceList(new ArrayList<>(deviceTypeMap.values()));
+
+        return overview;
+    }
+
+    /**
+     * 获取设备详情(包含气象/土壤数据和告警信息)
+     *
+     * @param deviceId 设备编号
+     * @param deviceTypeId 设备类型编号
+     * @return 设备详情数据
+     */
+    @Override
+    public WeatherRealtimeData getDeviceDetail(String deviceId,String deviceTypeId) {
+        //获取最新的气象/土壤数据 /告警数据
+        WeatherRealtimeData weatherRealtimeData = weatherRealtimeDataMapper.selectLatestDataByDeviceId(deviceId);
+
+        if (weatherRealtimeData == null) {
+            weatherRealtimeData = new WeatherRealtimeData();
+        }
+        // 获取当前设备的告警信息(未处理且最近三条;后续考虑增加分页查询)
+        List<AlertRecord> alertRecords = alertRecordMapper.selectAlertRecordsByDeviceId(deviceId);
+        if (alertRecords != null && !alertRecords.isEmpty()) {
+            weatherRealtimeData.setAlertRecordList(alertRecords);
+        }
+
+        return weatherRealtimeData;
+    }
+
+    /**
+     * 初始化设备类型统计映射
+     */
+    private Map<String, DeviceOverviewVO> initDeviceTypeMap() {
+        Map<String, DeviceOverviewVO> deviceTypeMap = new LinkedHashMap<>();
+
+        deviceTypeMap.put("monitor", new DeviceOverviewVO("监控设备", "monitor", "/static/icons/camera.png"));
+        deviceTypeMap.put("sensor", new DeviceOverviewVO("采集设备", "sensor", "/static/icons/sensor.png"));
+        deviceTypeMap.put("control", new DeviceOverviewVO("控制设备", "control", "/static/icons/control.png"));
+        deviceTypeMap.put("irrigation", new DeviceOverviewVO("灌溉设备", "irrigation", "/static/icons/water.png"));
+        deviceTypeMap.put("tractor", new DeviceOverviewVO("农机设备", "tractor", "/static/icons/tractor.png"));
+
+        return deviceTypeMap;
+    }
 }

+ 177 - 4
ruoyi-modules/ruoyi-base/src/main/java/com/ruoyi/base/service/impl/FieldServiceImpl.java

@@ -1,22 +1,28 @@
 package com.ruoyi.base.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.nacos.client.naming.utils.CollectionUtils;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import com.ruoyi.base.domain.Device;
 import com.ruoyi.base.domain.Field;
 import com.ruoyi.base.domain.FieldDevice;
 import com.ruoyi.base.domain.FieldPersonnel;
+import com.ruoyi.base.domain.enums.FieldStatusEnum;
+import com.ruoyi.base.domain.enums.FieldTypeEnum;
+import com.ruoyi.base.domain.vo.FieldVO;
 import com.ruoyi.base.mapper.DeviceMapper;
 import com.ruoyi.base.mapper.FieldDeviceMapper;
 import com.ruoyi.base.mapper.FieldMapper;
 import com.ruoyi.base.mapper.FieldPersonnelMapper;
 import com.ruoyi.base.service.IFieldService;
 import com.ruoyi.common.security.utils.SecurityUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 地块信息Service业务层处理
@@ -194,5 +200,172 @@ public class FieldServiceImpl implements IFieldService
     }
 
 
+    @Override
+    public List<Field> fieldNameByUserList(Long userId) {
+        return fieldMapper.selectFieldListByUserId(userId);
+    }
+
+    /**
+     * 根据用户ID查询用户关联的地块列表
+     *
+     * @param userId    用户ID
+     * @param pageNum   页码
+     * @param pageSize  每页数量
+     * @return 分页信息
+     */
+    public PageInfo<FieldVO> selectFieldListByUserId(Long userId, Integer pageNum, Integer pageSize) {
+        if (userId == null) {
+            return new PageInfo<>(Collections.emptyList());
+        }
+
+        try {
+            PageHelper.startPage(ObjectUtil.defaultIfNull(pageNum, 1), ObjectUtil.defaultIfNull(pageSize, 10));
+            List<Field> fields = fieldMapper.selectFieldListByUserId(userId);
+            PageInfo<Field> sourcePageInfo = new PageInfo<>(fields);
+            return processFields(fields, sourcePageInfo);
+        } catch (Exception e) {
+            return new PageInfo<>(Collections.emptyList());
+        }
+    }
+
+
+    /**
+     * 根据用户ID和关键词搜索地块
+     *
+     * @param userId 用户ID
+     * @param keyword 搜索关键词
+     * @return 地块信息集合
+     */
+    @Override
+    public PageInfo<FieldVO> searchFieldsByUserIdAndKeyword(Long userId, String keyword, Integer pageNum, Integer pageSize) {
+        if (userId == null) {
+            return new PageInfo<>(Collections.emptyList());
+        }
+
+        try {
+            PageHelper.startPage(ObjectUtil.defaultIfNull(pageNum, 1), ObjectUtil.defaultIfNull(pageSize, 10));
+            List<Field> fields = fieldMapper.searchFieldsByUserIdAndKeyword(userId, keyword);
+            PageInfo<Field> sourcePageInfo = new PageInfo<>(fields);
+            return processFields(fields, sourcePageInfo);
+        } catch (Exception e) {
+            return new PageInfo<>(Collections.emptyList());
+        }
+    }
+
+
+    @Override
+    public FieldVO countFieldTotalByUser(Long userId) {
+        Field field = fieldMapper.countFieldTotalByUser(userId);
+
+        FieldVO fieldVO = new FieldVO();
+        fieldVO.setPlotsTotal(field.getPlotsTotal() != null ? field.getPlotsTotal() : 0);
+        fieldVO.setInUseCount(field.getInUseCount() != null ? field.getInUseCount() : 0);
+        fieldVO.setLeiSureCount(field.getLeiSureCount() != null ? field.getLeiSureCount() : 0);
+        return fieldVO;
+    }
+
+    /**
+     * 转换地块实体为VO对象
+     *
+     * @param field 地块实体
+     * @return 地块VO对象
+     */
+    @Override
+    public FieldVO convertToVO(Field field) {
+        if (field == null) {
+            return null;
+        }
+
+        FieldVO vo = new FieldVO();
+        vo.setId(field.getId());
+        vo.setCode(field.getFieldCode());
+        vo.setName(field.getFieldName());
+        vo.setFarmName(field.getFarmName());
+        vo.setManager(field.getManagerName());
+        vo.setArea(field.getSize());
+
+        // 使用枚举处理地块类型
+        vo.setType(FieldTypeEnum.getInfoByCode(field.getFieldType()));
+
+        vo.setCrop(field.getGrowCrops());
+
+        // 使用枚举处理地块状态
+        vo.setStatus(FieldStatusEnum.getStatusByCode(field.getStatus()));
+
+        // 设备信息
+        vo.setDeviceCount(field.getDeviceCount());
+        vo.setOnlineDevices(field.getOnlineDevices());
+        vo.setAlerts(field.getAlerts());
+
+        return vo;
+    }
+
+    private PageInfo<FieldVO> processFields(List<Field> fields, PageInfo<Field> sourcePageInfo) {
+        if (CollectionUtils.isEmpty(fields)) {
+            return new PageInfo<>(Collections.emptyList());
+        }
+
+        // 批量查询设备数量和告警信息
+        batchEnrichFieldsWithDeviceInfo(fields);
+
+        // 转换为VO列表
+        List<FieldVO> voList = fields.stream()
+                .map(this::convertToVO)
+                .collect(Collectors.toList());
+
+        // 创建新的分页信息对象并复制属性
+        PageInfo<FieldVO> resultPage = new PageInfo<>(voList);
+        BeanUtils.copyProperties(sourcePageInfo, resultPage, "list");
+
+        return resultPage;
+    }
+
+    /**
+     * 批量为地块实体填充设备和告警信息
+     *
+     * @param fields 地块实体列表
+     */
+    private void batchEnrichFieldsWithDeviceInfo(List<Field> fields) {
+        if (fields == null || fields.isEmpty()) {
+            return;
+        }
+
+        // 提取所有地块ID
+        List<Long> fieldIds = fields.stream()
+                .map(Field::getId)
+                .collect(Collectors.toList());
+
+        // 批量查询设备数量
+        List<Map<String, Object>> deviceCountResults = fieldMapper.batchCountDevicesByFieldIds(fieldIds);
+        Map<Long, Integer> deviceCountMap = new HashMap<>();
+        for (Map<String, Object> result : deviceCountResults) {
+            Long fieldId = ((Number) result.get("fieldId")).longValue();
+            Integer count = ((Number) result.get("deviceCount")).intValue();
+            deviceCountMap.put(fieldId, count);
+        }
+
+        // 批量查询在线设备数量
+        List<Map<String, Object>> onlineDeviceCountResults = fieldMapper.batchCountOnlineDevicesByFieldIds(fieldIds);
+        Map<Long, Integer> onlineDeviceCountMap = new HashMap<>();
+        for (Map<String, Object> result : onlineDeviceCountResults) {
+            Long fieldId = ((Number) result.get("fieldId")).longValue();
+            Integer count = ((Number) result.get("onlineDevices")).intValue();
+            onlineDeviceCountMap.put(fieldId, count);
+        }
+
+        // 将结果应用到地块对象上
+        for (Field field : fields) {
+            // 设置设备数量
+            Integer deviceCount = deviceCountMap.get(field.getId());
+            field.setDeviceCount(deviceCount != null ? deviceCount : 0);
+
+            // 设置在线设备数量
+            Integer onlineDevices = onlineDeviceCountMap.get(field.getId());
+            field.setOnlineDevices(onlineDevices != null ? onlineDevices : 0);
+
+            // 设置告警数量 TODO 等告警列表完善之后再查询
+            field.setAlerts(0);
+        }
+    }
 
 }

+ 2 - 2
ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/AlertRecordMapper.xml → ruoyi-modules/ruoyi-base/src/main/resources/mapper/base/AlertRecordMapper.xml

@@ -2,9 +2,9 @@
 <!DOCTYPE mapper
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.ruoyi.uniapp.mapper.AlertRecordMapper">
+<mapper namespace="com.ruoyi.base.mapper.AlertRecordMapper">
     
-    <resultMap type="com.ruoyi.uniapp.domain.AlertRecord" id="AlertRecordResult">
+    <resultMap type="com.ruoyi.base.domain.AlertRecord" id="AlertRecordResult">
         <id property="alertId" column="alert_id"/>
         <result property="deviceId" column="device_id"/>
         <result property="deviceName" column="device_name"/>

+ 86 - 0
ruoyi-modules/ruoyi-base/src/main/resources/mapper/base/DeviceMapper.xml

@@ -204,4 +204,90 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+    <select id="selectUniappDeviceList" parameterType="com.ruoyi.base.domain.dto.DeviceDto" resultMap="DeviceResult">
+        select d.id, d.device_id, d.device_name, d.device_type_id, d.farm_id, d.model, d.longitude,
+        d.latitude, d.manufacturer, d.install_date, d.status, d.last_active_time, d.create_time,
+        d.update_time, d.remark, f.field_name
+        from device d
+        INNER JOIN field_device fd ON fd.device_id = d.id AND fd.status = 0
+        INNER JOIN field f ON f.id = fd.field_id
+        INNER JOIN field_personnel fp ON fp.field_id = f.id AND fp.status = 0
+        <where>
+            <if test="deviceId != null  and deviceId != ''"> and d.device_id = #{deviceId}</if>
+            <if test="fieldId != null  and fieldId != ''"> and fd.field_id = #{fieldId}</if>
+            <if test="userId != null  and userId != ''"> and fp.user_id = #{userId}</if>
+            <if test="deviceName != null  and deviceName != ''"> and d.device_name like concat('%', #{deviceName}, '%')</if>
+            <if test="deviceTypeId != null  and deviceTypeId != ''"> and d.device_type_id = #{deviceTypeId}</if>
+            <if test="status != null "> and d.status = #{status}</if>
+            <if test="deviceQueryParams != null and deviceQueryParams != ''">
+                and (
+                d.device_name like concat('%', #{deviceQueryParams}, '%') OR
+                d.device_id like concat('%', #{deviceQueryParams}, '%')
+                )
+            </if>
+        </where>
+        order by create_time desc
+    </select>
+
+    <select id="countDeviceStatistics" resultType="com.ruoyi.base.domain.vo.DeviceOverviewVO">
+        SELECT
+        COUNT(DISTINCT d.id) AS totalDevices,
+        SUM(CASE WHEN d.status = 1 THEN 1 ELSE 0 END) AS onlineDevices,
+        SUM(CASE WHEN d.status = 0 THEN 1 ELSE 0 END) AS offlineDevices
+        FROM device d
+        INNER JOIN field_device fd ON fd.device_id = d.id AND fd.status = 0
+        INNER JOIN field f ON f.id = fd.field_id
+        INNER JOIN field_personnel fp ON fp.field_id = f.id AND fp.status = 0
+        <where>
+            <if test="fieldId != null and fieldId != ''">
+                AND fd.field_id = #{fieldId}
+            </if>
+            <if test="userId != null and userId != ''">
+                AND fp.user_id = #{userId}
+            </if>
+        </where>
+    </select>
+
+
+    <select id="countDevicesByType" resultType="java.util.Map">
+        SELECT
+        d.device_type_id AS deviceTypeId,
+        SUM( CASE WHEN d.STATUS = 1 THEN 1 ELSE 0 END ) AS online,
+        SUM( CASE WHEN d.STATUS = 0 THEN 1 ELSE 0 END ) AS offline
+        FROM
+        device d
+        LEFT JOIN field_device fd ON fd.device_id = d.id
+        LEFT JOIN field_personnel fp ON fd.field_id = fp.field_id
+        <where>
+            <if test="fieldId != null and fieldId != ''">
+                AND fd.field_id = #{fieldId}
+            </if>
+            <if test="userId != null and userId != ''">
+                AND fp.user_id = #{userId}
+            </if>
+            AND fd.`status` = 0
+            AND fp.`status` = 0
+        </where>
+        GROUP BY device_type_id
+    </select>
+
+    <select id="countAlertsByType" resultType="java.util.Map">
+        SELECT
+        d.device_type_id as deviceTypeId,
+        COUNT(a.id) as alerts
+        FROM
+        device d
+        LEFT JOIN
+        device_alert a ON d.device_id = a.device_id AND a.status = 0
+        <where>
+            <if test="farmId != null and farmId != ''">
+                AND d.farm_id = #{farmId}
+            </if>
+            <if test="fieldId != null and fieldId != ''">
+                AND d.field_id = #{fieldId}
+            </if>
+        </where>
+        GROUP BY d.device_type_id
+    </select>
 </mapper>

+ 87 - 2
ruoyi-modules/ruoyi-base/src/main/resources/mapper/base/FieldMapper.xml

@@ -9,6 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="fieldCode"    column="field_code"    />
         <result property="fieldName"    column="field_name"    />
         <result property="farmId"    column="farm_id"    />
+        <result property="farmName" column="farmName"/>
         <result property="fieldType"    column="field_type"    />
         <result property="growCrops"    column="grow_crops"    />
         <result property="size"    column="size"    />
@@ -26,6 +27,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="isDeleted"    column="is_deleted"    />
         <result property="bindDeviceCount"    column="bindDeviceCount"    />
         <result property="bindUserCount"    column="bindUserCount"    />
+        <result column="plotsTotal" property="plotsTotal"/>
+        <result column="inUseCount" property="inUseCount"/>
+        <result column="leiSureCount" property="leiSureCount"/>
         <association property="dept"    javaType="com.ruoyi.system.api.domain.SysDept"         resultMap="deptResult" />
         <collection  property="roles"   javaType="java.util.List"  resultMap="RoleResult" />
     </resultMap>
@@ -49,8 +53,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="status"       column="role_status"    />
     </resultMap>
 
-    <sql id="selectFieldVo">
-        select id, field_code, field_name, farm_id, field_type, grow_crops, size, soil_type, irrigation_type, status, manager_id, description, location_data, created_time, updated_time, created_by, updated_by, is_deleted from field
+    <sql id="selectFieldWithFarm">
+        select
+            f.id, f.field_code, f.field_name, f.farm_id,
+            f.field_type, f.grow_crops, f.size, f.soil_type, f.irrigation_type,
+            f.status, f.manager_id, f.manager_name, f.description, f.location_data,
+            f.created_time, f.updated_time, f.created_by, f.updated_by, f.is_deleted,s.dept_name as farmName
+        from field f
+                 left join sys_dept s on f.farm_id = s.dept_id
     </sql>
 
     <select id="selectFieldList" parameterType="Field" resultMap="FieldResult">
@@ -169,4 +179,79 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+
+    <!-- 根据用户ID查询关联的地块列表 -->
+    <select id="selectFieldListByUserId" parameterType="Long" resultMap="FieldResult">
+        <include refid="selectFieldWithFarm"/>
+        inner join field_personnel fp on f.id = fp.field_id
+        <where>
+            f.is_deleted = 0
+            and fp.is_deleted = 0
+            and fp.status = '0'
+            and fp.user_id = #{userId}
+        </where>
+    </select>
+
+
+    <!-- 根据用户ID和关键词搜索地块 -->
+    <select id="searchFieldsByUserIdAndKeyword" resultMap="FieldResult">
+        <include refid="selectFieldWithFarm"/>
+        inner join field_personnel fp on f.id = fp.field_id
+        <where>
+            f.is_deleted = 0
+            and fp.is_deleted = 0
+            and fp.status = '0'
+            and fp.user_id = #{userId}
+            <if test="keyword != null and keyword != ''">
+                and (
+                f.field_code like concat('%', #{keyword}, '%') OR
+                f.field_name like concat('%', #{keyword}, '%') OR
+                f.manager_name like concat('%', #{keyword}, '%')
+                )
+            </if>
+        </where>
+    </select>
+
+    <select id="countFieldTotalByUser" parameterType="Long" resultMap="FieldResult">
+        SELECT
+            COUNT(*) AS plotsTotal,
+            COUNT(CASE WHEN f.status = '0' THEN 1 END) AS inUseCount,
+            COUNT(CASE WHEN f.status = '1' THEN 1 END) AS leiSureCount
+        FROM field f
+                 LEFT JOIN field_personnel fp on f.id = fp.field_id
+        where fp.user_id = #{userId}
+    </select>
+
+    <!-- 批量查询地块的设备数量 -->
+    <select id="batchCountDevicesByFieldIds" resultType="java.util.Map">
+        SELECT
+        field_id as fieldId,
+        COUNT(1) as deviceCount
+        FROM field_device
+        WHERE field_id IN
+        <foreach collection="fieldIds" item="fieldId" open="(" separator="," close=")">
+            #{fieldId}
+        </foreach>
+        AND status = '0'
+        AND is_deleted = 0
+        GROUP BY field_id
+    </select>
+
+    <!-- 批量查询地块的在线设备数量 -->
+    <select id="batchCountOnlineDevicesByFieldIds" resultType="java.util.Map">
+        SELECT
+        fd.field_id as fieldId,
+        COUNT(1) as onlineDevices
+        FROM field_device fd
+        LEFT JOIN device d ON fd.device_id = d.id
+        WHERE fd.field_id IN
+        <foreach collection="fieldIds" item="fieldId" open="(" separator="," close=")">
+            #{fieldId}
+        </foreach>
+        AND fd.status = '0'
+        AND fd.is_deleted = 0
+        AND d.status = '1'
+        GROUP BY fd.field_id
+    </select>
 </mapper>

+ 9 - 0
ruoyi-modules/ruoyi-base/src/main/resources/mapper/base/WeatherRealtimeDataMapper.xml

@@ -175,4 +175,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+
+
+    <select id="selectLatestDataByDeviceId" parameterType="String" resultMap="WeatherRealtimeDataResult">
+        <include refid="selectWeatherRealtimeDataVo"/>
+        WHERE device_id = #{deviceId}
+        order by collect_time desc
+        LIMIT 1
+    </select>
 </mapper>

+ 0 - 101
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/controller/DeviceController.java

@@ -1,101 +0,0 @@
-package com.ruoyi.uniapp.controller;
-
-import java.util.Collections;
-import java.util.List;
-
-import com.ruoyi.common.core.domain.R;
-import com.ruoyi.common.core.utils.StringUtils;
-import com.ruoyi.uniapp.domain.WeatherRealtimeData;
-import com.ruoyi.uniapp.domain.dto.DeviceDto;
-import com.ruoyi.uniapp.domain.enums.DeviceTypeEnum;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-import com.ruoyi.common.core.web.controller.BaseController;
-import com.ruoyi.common.core.web.domain.AjaxResult;
-import com.ruoyi.common.core.web.page.TableDataInfo;
-import com.ruoyi.uniapp.domain.Device;
-import com.ruoyi.uniapp.domain.vo.DeviceOverviewVO;
-import com.ruoyi.uniapp.service.IDeviceService;
-
-/**
- * 设备管理Controller
- * 
- * @author ruoyi
- */
-@RestController
-@RequestMapping("/device")
-public class DeviceController extends BaseController {
-
-    @Autowired
-    private IDeviceService deviceService;
-    
-    /**
-     * 查询设备列表
-     *//*
-    @GetMapping("/list")
-    public TableDataInfo list(Device device) {
-        startPage();
-        List<Device> list = deviceService.selectDeviceList(device);
-        return getDataTable(list);
-    }*/
-
-    /**
-     * 获取设备详细信息
-     */
-    @GetMapping("/{id}")
-    public AjaxResult getInfo(@PathVariable("id") Integer id) {
-        return success(deviceService.selectDeviceById(id));
-    }
-
-    
-    /**
-     * 获取设备概览
-     */
-    @PostMapping("/overview")
-    public AjaxResult getOverview(@RequestBody DeviceDto device) {
-        if (device.getFieldId() == null){
-            return error("请选择所属地块!");
-        }
-        DeviceOverviewVO overview = deviceService.getDeviceOverview(device.getUserId(), device.getFieldId());
-        return success(overview);
-    }
-
-    /**
-     *根据条件(地块、用户、设备类型)查询设备列表
-     */
-    @PostMapping("/typeList")
-    public TableDataInfo listByType(@RequestBody DeviceDto device) {
-
-        //若缺少必要条件时,返回空表格数据
-        if (device.getFieldId() == null &&
-                device.getUserId() == null &&
-                device.getDeviceType() == null) {
-            return getDataTable(Collections.emptyList());
-        }
-
-        //设备类型不为空,则进行转换为对应code
-        String frontendType = device.getDeviceType();
-        if (StringUtils.isNotEmpty(frontendType)) {
-            String code = DeviceTypeEnum.getCodeByFrontendType(frontendType);
-            if (code == null) {
-                //若无法根据前端type获取到code时,可适时抛出异常或者返回空
-                return getDataTable(Collections.emptyList());
-            }
-            device.setDeviceTypeId(code);
-        }
-
-        startPage();
-
-        List<Device> list = deviceService.selectDeviceList(device);
-        return getDataTable(list);
-    }
-    
-    /**
-     * 根据设备编号获取设备详情(包含气象/土壤数据和告警信息)
-     */
-    @GetMapping("/collector/detail/{deviceId}")
-    public R<WeatherRealtimeData> getDeviceCollectorDetail(@PathVariable("deviceId") String deviceId,String deviceTypeId) {
-        WeatherRealtimeData detail = deviceService.getDeviceDetail(deviceId,deviceTypeId);
-        return R.ok(detail);
-    }
-} 

+ 0 - 90
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/controller/FieldController.java

@@ -1,90 +0,0 @@
-package com.ruoyi.uniapp.controller;
-
-
-import java.util.List;
-import java.util.Map;
-
-import cn.hutool.core.util.ObjectUtil;
-import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
-import com.ruoyi.common.core.utils.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-import com.ruoyi.common.core.domain.R;
-import com.ruoyi.common.core.web.controller.BaseController;
-import com.ruoyi.common.core.web.page.TableDataInfo;
-import com.ruoyi.uniapp.domain.Field;
-import com.ruoyi.uniapp.domain.vo.FieldVO;
-import com.ruoyi.uniapp.service.IFieldService;
-
-/**
- * 地块信息 控制层
- * 
- * @author ruoyi
- */
-@RestController
-@RequestMapping("/field")
-public class FieldController extends BaseController {
-    @Autowired
-    private IFieldService fieldService;
-
-
-    /**
-     * 返回用户关联的地块信息(不分页)
-     */
-    @GetMapping("/name/{userId}")
-    public R<List<Field>> listFieldName(@PathVariable("userId") Long userId) {
-        List<Field> fields = fieldService.fieldNameByUserList(userId);
-        return R.ok(fields);
-    }
-
-    /**
-     * 根据用户ID查询关联地块列表
-     */
-    @PostMapping("/list/user")
-    public R<PageInfo<FieldVO>> listByUserId(@RequestBody Field field) {
-        if (field.getUserId() == null){
-            return R.fail("查询用户关联地块信息失败");
-        }
-
-        Object pageNum = field.getParams().get("pageNum");
-        Object pageSize = field.getParams().get("pageSize");
-        if (null != pageNum && null != pageSize){
-            PageInfo<FieldVO> fieldVOPageInfo = fieldService.selectFieldListByUserId(field.getUserId(), new Integer(pageNum.toString()), new Integer(pageSize.toString()));
-            return R.ok(fieldVOPageInfo);
-        }
-        return R.fail("分页查询参数缺失");
-
-    }
-
-    
-    /**
-     * 根据用户ID搜索地块信息
-     */
-    @PostMapping("/search/user")
-    public R<PageInfo<FieldVO>> searchByUserId(@RequestBody Field field) {
-        if (field.getUserId() == null || field.getUserId() <= 0) {
-            return R.fail("用户ID不能为空或小于等于0");
-        }
-        Object pageNum = field.getParams().get("pageNum");
-        Object pageSize = field.getParams().get("pageSize");
-        Object keyword = field.getParams().get("keyword");
-        String keywordValue = keyword.toString();
-        if (null != pageNum && null != pageSize){
-            PageInfo<FieldVO> fieldVOPageInfo = fieldService.searchFieldsByUserIdAndKeyword(field.getUserId(), StringUtils.trimToNull(keywordValue), new Integer(pageNum.toString()), new Integer(pageSize.toString()));
-            return R.ok(fieldVOPageInfo);
-        }
-        // 构建带有分页信息的返回对象
-        return R.fail("搜索地块信息失败");
-    }
-
-
-    /**
-     * 根据用户ID查询关联地块列表
-     */
-    @GetMapping("/count/{userId}")
-    public R<FieldVO> countUserPlots(@PathVariable("userId") Long userId) {
-        FieldVO fieldCounts = fieldService.countFieldTotalByUser(userId);
-        return R.ok(fieldCounts);
-    }
-} 

+ 0 - 80
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/Device.java

@@ -1,80 +0,0 @@
-package com.ruoyi.uniapp.domain;
-
-import java.math.BigDecimal;
-import java.util.Date;
-import java.io.Serializable;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.ruoyi.common.core.annotation.Excel;
-import com.ruoyi.common.core.annotation.Excel.ColumnType;
-import com.ruoyi.common.core.web.domain.BaseEntity;
-import lombok.Data;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
-/**
- * 设备信息对象 device
- * 
- * @author ruoyi
- */
-@Data
-public class Device extends BaseEntity implements Serializable {
-    private static final long serialVersionUID = 1L;
-
-    /** 主键ID */
-    private Integer id;
-
-    /** 设备编号 */
-    @Excel(name = "设备编号")
-    private String deviceId;
-
-    /** 设备名称 */
-    @Excel(name = "设备名称")
-    private String deviceName;
-
-    /** 设备类型(1-传感器,2-摄像头,3-控制器,4-气象设备,5-农机设备) */
-    @Excel(name = "设备类型")
-    private String deviceTypeId;
-    
-    /** 所属农场ID */
-    @Excel(name = "所属农场ID")
-    private String farmId;
-
-    /** 设备型号 */
-    @Excel(name = "设备型号")
-    private String model;
-
-    /** GPS经度 */
-    @Excel(name = "GPS经度")
-    private BigDecimal longitude;
-
-    /** GPS纬度 */
-    @Excel(name = "GPS纬度")
-    private BigDecimal latitude;
-
-    /** 厂家 */
-    @Excel(name = "厂家")
-    private String manufacturer;
-
-    /** 安装日期 */
-    @JsonFormat(pattern = "yyyy-MM-dd")
-    @Excel(name = "安装日期", width = 30, dateFormat = "yyyy-MM-dd")
-    private Date installDate;
-
-    /** 状态: 0-离线, 1-在线, 2-故障, 3-维护中 */
-    @Excel(name = "状态", readConverterExp = "0=离线,1=在线,2=故障,3=维护中")
-    private Integer status;
-
-    /** 最后活动时间 */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    @Excel(name = "最后活动时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
-    private Date lastActiveTime;
-
-    /** 备注信息 */
-    @Excel(name = "备注信息")
-    private String remark;
-
-    /** 地块名称 */
-    private String fieldName;
-
-} 

+ 0 - 111
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/Field.java

@@ -1,111 +0,0 @@
-package com.ruoyi.uniapp.domain;
-
-import java.math.BigDecimal;
-import java.util.Date;
-import java.io.Serializable;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.ruoyi.common.core.annotation.Excel;
-import com.ruoyi.common.core.annotation.Excel.ColumnType;
-import com.ruoyi.common.core.web.domain.BaseEntity;
-import lombok.Data;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
-/**
- * 地块信息对象 field
- * 
- * @author ruoyi
- */
-@Data
-public class Field extends BaseEntity implements Serializable {
-    private static final long serialVersionUID = 1L;
-
-    /** 主键ID */
-    private Long id;
-
-    /** 用户ID */
-    private Long userId;
-
-    /** 地块编号 */
-    @Excel(name = "地块编号")
-    private String fieldCode;
-
-    /** 地块名称 */
-    @Excel(name = "地块名称")
-    private String fieldName;
-
-    /** 所属农场ID */
-    @Excel(name = "所属农场ID")
-    private Long farmId;
-    
-    /** 所属农场名称(非数据库字段) */
-    @Excel(name = "所属农场名称")
-    private String farmName;
-
-    /** 地块类型(水田、旱地、果园、菜地、其他) */
-    @Excel(name = "地块类型")
-    private String fieldType;
-
-    /** 种植作物(字典) */
-    @Excel(name = "种植作物")
-    private String growCrops;
-
-    /** 面积(亩) */
-    @Excel(name = "面积(亩)")
-    private BigDecimal size;
-
-    /** 土壤类型(粘土、沙质土、壤土、沙壤土、其他) */
-    @Excel(name = "土壤类型")
-    private String soilType;
-
-    /** 灌溉方式(喷灌、滴灌、微喷灌、漫灌、其他) */
-    @Excel(name = "灌溉方式")
-    private String irrigationType;
-
-    /** 使用状态(0-使用中,1-未使用,2-维护中) */
-    @Excel(name = "使用状态", readConverterExp = "0=使用中,1=未使用,2=维护中")
-    private String status;
-
-    /** 负责人ID */
-    private Long managerId;
-
-    /** 负责人名字 */
-    @Excel(name = "负责人")
-    private String managerName;
-
-    /** 地块描述 */
-    @Excel(name = "地块描述")
-    private String description;
-
-    /** 地理位置数据(GeoJSON格式) */
-    private String locationData;
-
-    /** 是否删除 */
-    private Integer isDeleted;
-    
-    /** 设备数量(非数据库字段) */
-    private Integer deviceCount;
-    
-    /** 在线设备数量(非数据库字段) */
-    private Integer onlineDevices;
-    
-    /** 告警数量(非数据库字段) */
-    private Integer alerts;
-
-    /*
-     * 地块总数
-     * */
-    private Integer plotsTotal;
-
-    /*
-     * 使用中数量
-     * */
-    private Integer inUseCount;
-
-    /*
-     * 空闲数量
-     * */
-    private Integer leiSureCount;
-
-} 

+ 0 - 83
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/domain/WeatherRealtimeData.java

@@ -1,83 +0,0 @@
-package com.ruoyi.uniapp.domain;
-
-import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.ruoyi.common.core.annotation.Excel;
-import com.ruoyi.common.core.web.domain.BaseEntity;
-import lombok.Data;
-
-/**
- * 气象站实时数据对象 weather_realtime_data
- * 
- * @author ruoyi
- */
-@Data
-public class WeatherRealtimeData extends BaseEntity {
-    private static final long serialVersionUID = 1L;
-
-    /** 主键ID */
-    private Long id;
-
-    /** 设备编号 */
-    @Excel(name = "设备编号")
-    private String deviceId;
-
-    /** 气温(°C) */
-    @Excel(name = "气温(°C)")
-    private BigDecimal temperature;
-
-    /** 湿度(%) */
-    @Excel(name = "湿度(%)")
-    private BigDecimal humidity;
-
-    /** 降雨量(mm) */
-    @Excel(name = "降雨量(mm)")
-    private BigDecimal rainfall;
-
-    /** 风向 */
-    @Excel(name = "风向")
-    private String windDirection;
-
-    /** 风速(m/s) */
-    @Excel(name = "风速(m/s)")
-    private BigDecimal windSpeed;
-
-    /** 气压(hPa) */
-    @Excel(name = "气压(hPa)")
-    private BigDecimal airPressure;
-
-    /** 光照强度(lux) */
-    @Excel(name = "光照强度(lux)")
-    private BigDecimal lightIntensity;
-
-    /** 土壤温度 */
-    @Excel(name = "土壤温度")
-    private BigDecimal soilTemperature;
-
-    /** 土壤水分 */
-    @Excel(name = "土壤水分")
-    private BigDecimal soilHumidity;
-
-    /** 土壤氮 */
-    @Excel(name = "土壤氮")
-    private BigDecimal soilN;
-
-    /** 土壤磷 */
-    @Excel(name = "土壤磷")
-    private BigDecimal soilP;
-
-    /** 土壤钾 */
-    @Excel(name = "土壤钾")
-    private BigDecimal soilK;
-
-    /** 采集时间 */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    @Excel(name = "采集时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
-    private Date collectTime;
-
-    /*告警列表*/
-    private List<AlertRecord> alertRecordList;
-} 

+ 0 - 62
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/mapper/DeviceMapper.java

@@ -1,62 +0,0 @@
-package com.ruoyi.uniapp.mapper;
-
-import com.ruoyi.uniapp.domain.Device;
-import com.ruoyi.uniapp.domain.dto.DeviceDto;
-import com.ruoyi.uniapp.domain.vo.DeviceOverviewVO;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * 设备Mapper接口
- * 
- * @author ruoyi
- */
-@Mapper
-public interface DeviceMapper {
-    /**
-     * 查询设备信息
-     * 
-     * @param id 设备ID
-     * @return 设备信息
-     */
-    public Device selectDeviceById(Integer id);
-
-    /**
-     * 查询设备列表
-     * 
-     * @param device 设备信息
-     * @return 设备集合
-     */
-    public List<Device> selectDeviceList(DeviceDto device);
-
-    
-    /**
-     * 按设备类型统计在线和离线设备数量
-     *
-     * @param fieldId 地块ID
-     * @param userId 用户ID
-     * @return 设备统计信息
-     */
-    public List<Map<String, Object>> countDevicesByType(@Param("fieldId") String fieldId , @Param("userId") String userId);
-    
-    /**
-     * 按设备类型统计告警数量
-     *
-     * @param farmId 农场ID,可为空
-     * @param fieldId 地块ID,可为空
-     * @return 告警统计信息
-     */
-    public List<Map<String, Object>> countAlertsByType(@Param("farmId") String farmId, @Param("fieldId") String fieldId);
-
-    /**
-     * 获取设备统计信息
-     *
-     * @param fieldId 地块ID
-     * @param userId 用户ID
-     * @return 包含totalDevices、onlineDevices、offlineDevices、alertDevices的Map
-     */
-    public DeviceOverviewVO countDeviceStatistics(@Param("fieldId") String fieldId , @Param("userId") String userId);
-} 

+ 0 - 57
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/mapper/FieldMapper.java

@@ -1,57 +0,0 @@
-package com.ruoyi.uniapp.mapper;
-
-import java.util.List;
-import java.util.Map;
-import com.ruoyi.uniapp.domain.Field;
-import org.apache.ibatis.annotations.Param;
-
-/**
- * 地块信息 数据层
- * 
- * @author ruoyi
- */
-public interface FieldMapper {
-    
-    /**
-     * 根据用户ID查询用户关联的地块信息列表
-     * 
-     * @param userId 用户ID
-     * @return 地块信息集合
-     */
-    public List<Field> selectFieldListByUserId(@Param("userId") Long userId);
-
-    
-    /**
-     * 根据用户ID和关键词搜索地块
-     * 
-     * @param userId 用户ID
-     * @param keyword 搜索关键字
-     * @return 地块信息集合
-     */
-    public List<Field> searchFieldsByUserIdAndKeyword(@Param("userId") Long userId, @Param("keyword") String keyword);
-
-
-    /**
-     * 获取用户的地块总数、状态数量;
-     *
-     * @param userId 用户ID
-     * @return 地块总数、状态数量
-     */
-    public Field countFieldTotalByUser(Long userId);
-    
-    /**
-     * 批量获取地块设备数量
-     *
-     * @param fieldIds 地块ID列表
-     * @return 地块ID与设备数量的映射
-     */
-    public List<Map<String, Object>> batchCountDevicesByFieldIds(@Param("fieldIds") List<Long> fieldIds);
-    
-    /**
-     * 批量获取地块在线设备数量
-     *
-     * @param fieldIds 地块ID列表
-     * @return 地块ID与在线设备数量的映射
-     */
-    public List<Map<String, Object>> batchCountOnlineDevicesByFieldIds(@Param("fieldIds") List<Long> fieldIds);
-} 

+ 0 - 18
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/mapper/WeatherRealtimeDataMapper.java

@@ -1,18 +0,0 @@
-package com.ruoyi.uniapp.mapper;
-
-import com.ruoyi.uniapp.domain.WeatherRealtimeData;
-
-/**
- * 气象站实时数据Mapper接口
- * 
- * @author ruoyi
- */
-public interface WeatherRealtimeDataMapper {
-    /**
-     * 查询最新的气象站实时数据
-     * 
-     * @param deviceId 设备编号
-     * @return 气象站实时数据
-     */
-    public WeatherRealtimeData selectLatestDataByDeviceId(String deviceId);
-} 

+ 0 - 50
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/service/IDeviceService.java

@@ -1,50 +0,0 @@
-package com.ruoyi.uniapp.service;
-
-import com.ruoyi.uniapp.domain.Device;
-import com.ruoyi.uniapp.domain.WeatherRealtimeData;
-import com.ruoyi.uniapp.domain.dto.DeviceDto;
-import com.ruoyi.uniapp.domain.vo.DeviceOverviewVO;
-
-import java.util.List;
-
-/**
- * 设备管理Service接口
- * 
- * @author ruoyi
- */
-public interface IDeviceService {
-    /**
-     * 查询设备信息
-     * 
-     * @param id 设备ID
-     * @return 设备信息
-     */
-    public Device selectDeviceById(Integer id);
-
-    /**
-     * 查询设备列表
-     * 
-     * @param device 设备信息
-     * @return 设备集合
-     */
-    public List<Device> selectDeviceList(DeviceDto device);
-
-    
-    /**
-     * 获取设备概览信息
-     *
-     * @param userId 用户ID
-     * @param fieldId 地块ID
-     * @return 设备概览信息
-     */
-    public DeviceOverviewVO getDeviceOverview(String userId, String fieldId);
-
-    /**
-     * 根据设备编号获取设备详情(包含气象/土壤数据和告警信息)
-     *
-     * @param deviceId 设备编号
-     * @param deviceTypeId 设备类型编号
-     * @return 设备详情数据
-     */
-    public WeatherRealtimeData getDeviceDetail(String deviceId,String deviceTypeId);
-} 

+ 0 - 57
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/service/IFieldService.java

@@ -1,57 +0,0 @@
-package com.ruoyi.uniapp.service;
-
-import java.util.List;
-
-import com.github.pagehelper.PageInfo;
-import com.ruoyi.uniapp.domain.Field;
-import com.ruoyi.uniapp.domain.vo.FieldVO;
-
-/**
- * 地块信息 服务层
- * 
- * @author ruoyi
- */
-public interface IFieldService {
-
-    /**
-     * 获取用户的地块;
-     *
-     * @param userId 用户ID
-     * @return 地块总数、状态数量
-     */
-    public List<Field> fieldNameByUserList(Long userId);
-    
-    /**
-     * 根据用户ID查询用户关联的地块列表
-     * 
-     * @param userId 用户ID
-     * @return 地块信息集合
-     */
-    public PageInfo<FieldVO> selectFieldListByUserId(Long userId, Integer pageNum, Integer pageSize);
-
-    
-    /**
-     * 根据用户ID和关键词搜索地块
-     * 
-     * @param userId 用户ID
-     * @param keyword 搜索关键词
-     * @return 地块信息集合
-     */
-    public PageInfo<FieldVO> searchFieldsByUserIdAndKeyword(Long userId, String keyword,Integer pageNum, Integer pageSize);
-
-    /**
-     * 获取用户的地块总数、状态数量;
-     *
-     * @param userId 地块ID
-     * @return 地块总数、状态数量
-     */
-    public FieldVO countFieldTotalByUser(Long userId);
-    
-    /**
-     * 转换地块实体为VO对象
-     * 
-     * @param field 地块实体
-     * @return 地块VO对象
-     */
-    public FieldVO convertToVO(Field field);
-} 

+ 0 - 155
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/service/impl/DeviceServiceImpl.java

@@ -1,155 +0,0 @@
-package com.ruoyi.uniapp.service.impl;
-
-import java.math.BigDecimal;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-import com.ruoyi.common.core.utils.StringUtils;
-import com.ruoyi.uniapp.domain.AlertRecord;
-import com.ruoyi.uniapp.domain.WeatherRealtimeData;
-import com.ruoyi.uniapp.domain.dto.DeviceDto;
-import com.ruoyi.uniapp.mapper.AlertRecordMapper;
-import com.ruoyi.uniapp.mapper.WeatherRealtimeDataMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import com.ruoyi.uniapp.mapper.DeviceMapper;
-import com.ruoyi.uniapp.domain.Device;
-import com.ruoyi.uniapp.domain.enums.DeviceTypeEnum;
-import com.ruoyi.uniapp.domain.vo.DeviceOverviewVO;
-import com.ruoyi.uniapp.service.IDeviceService;
-
-/**
- * 设备Service业务层处理
- * 
- * @author ruoyi
- */
-@Service
-public class DeviceServiceImpl implements IDeviceService {
-    @Autowired
-    private DeviceMapper deviceMapper;
-
-    @Autowired
-    private WeatherRealtimeDataMapper weatherRealtimeDataMapper;
-
-    @Autowired
-    private AlertRecordMapper alertRecordMapper;
-
-    /**
-     * 查询设备信息
-     * 
-     * @param id 设备ID
-     * @return 设备信息
-     */
-    @Override
-    public Device selectDeviceById(Integer id) {
-        return deviceMapper.selectDeviceById(id);
-    }
-
-    /**
-     * 查询设备列表
-     * 
-     * @param device 设备信息
-     * @return 设备
-     */
-    @Override
-    public List<Device> selectDeviceList(DeviceDto device) {
-        return deviceMapper.selectDeviceList(device);
-    }
-    
-    /**
-     * 获取设备概览信息
-     *
-     * @param userId 用户ID
-     * @param fieldId 地块ID
-     * @return 设备概览信息
-     */
-    @Override
-    public DeviceOverviewVO getDeviceOverview(String userId, String fieldId) {
-
-        DeviceOverviewVO overview = deviceMapper.countDeviceStatistics(fieldId,userId);
-        
-        // 获取按设备类型分组的统计数据
-        List<Map<String, Object>> deviceStats = deviceMapper.countDevicesByType(fieldId,userId);
-        // TODO 等待告警模块完善
-        // List<Map<String, Object>> alertStats = deviceMapper.countAlertsByType(farmId, fieldId);
-        
-        // 初始化设备类型统计列表
-        Map<String, DeviceOverviewVO> deviceTypeMap = initDeviceTypeMap();
-        
-        // 填充设备数量数据
-        for (Map<String, Object> stat : deviceStats) {
-            String deviceTypeId = (String) stat.get("deviceTypeId");
-            DeviceTypeEnum deviceType = DeviceTypeEnum.getByCode(deviceTypeId);
-            
-            if (deviceType != null) {
-                String frontendType = deviceType.getFrontendType();
-                DeviceOverviewVO typeStats = deviceTypeMap.get(frontendType);
-                
-                if (typeStats != null) {
-                    typeStats.setOnline(((Number) stat.get("online")).intValue());
-                    typeStats.setOffline(((Number) stat.get("offline")).intValue());
-                }
-            }
-        }
-        
-        // 填充告警数据
-        /*for (Map<String, Object> stat : alertStats) {
-            String deviceTypeId = (String) stat.get("deviceTypeId");
-            DeviceTypeEnum deviceType = DeviceTypeEnum.getByCode(deviceTypeId);
-            
-            if (deviceType != null) {
-                String frontendType = deviceType.getFrontendType();
-                DeviceTypeStatsVO typeStats = deviceTypeMap.get(frontendType);
-                
-                if (typeStats != null) {
-                    typeStats.setAlerts(((Number) stat.get("alerts")).intValue());
-                }
-            }
-        }*/
-        
-        // 设置设备类型统计列表
-        overview.setDeviceList(new ArrayList<>(deviceTypeMap.values()));
-        
-        return overview;
-    }
-
-    /**
-     * 获取设备详情(包含气象/土壤数据和告警信息)
-     *
-     * @param deviceId 设备编号
-     * @param deviceTypeId 设备类型编号
-     * @return 设备详情数据
-     */
-    @Override
-    public WeatherRealtimeData getDeviceDetail(String deviceId,String deviceTypeId) {
-        //获取最新的气象/土壤数据 /告警数据
-        WeatherRealtimeData weatherRealtimeData = weatherRealtimeDataMapper.selectLatestDataByDeviceId(deviceId);
-
-        if (weatherRealtimeData == null) {
-            weatherRealtimeData = new WeatherRealtimeData();
-        }
-        // 获取当前设备的告警信息(未处理且最近三条;后续考虑增加分页查询)
-        List<AlertRecord> alertRecords = alertRecordMapper.selectAlertRecordsByDeviceId(deviceId);
-        if (alertRecords != null && !alertRecords.isEmpty()) {
-            weatherRealtimeData.setAlertRecordList(alertRecords);
-        }
-
-        return weatherRealtimeData;
-    }
-    
-    /**
-     * 初始化设备类型统计映射
-     */
-    private Map<String, DeviceOverviewVO> initDeviceTypeMap() {
-        Map<String, DeviceOverviewVO> deviceTypeMap = new LinkedHashMap<>();
-
-        deviceTypeMap.put("monitor", new DeviceOverviewVO("监控设备", "monitor", "/static/icons/camera.png"));
-        deviceTypeMap.put("sensor", new DeviceOverviewVO("采集设备", "sensor", "/static/icons/sensor.png"));
-        deviceTypeMap.put("control", new DeviceOverviewVO("控制设备", "control", "/static/icons/control.png"));
-        deviceTypeMap.put("irrigation", new DeviceOverviewVO("灌溉设备", "irrigation", "/static/icons/water.png"));
-        deviceTypeMap.put("tractor", new DeviceOverviewVO("农机设备", "tractor", "/static/icons/tractor.png"));
-
-        return deviceTypeMap;
-    }
-
-} 

+ 0 - 198
ruoyi-modules/ruoyi-uniapp/src/main/java/com/ruoyi/uniapp/service/impl/FieldServiceImpl.java

@@ -1,198 +0,0 @@
-package com.ruoyi.uniapp.service.impl;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-import cn.hutool.core.util.ObjectUtil;
-import com.alibaba.nacos.client.naming.utils.CollectionUtils;
-import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import com.ruoyi.uniapp.mapper.FieldMapper;
-import com.ruoyi.uniapp.domain.Field;
-import com.ruoyi.uniapp.domain.enums.FieldStatusEnum;
-import com.ruoyi.uniapp.domain.enums.FieldTypeEnum;
-import com.ruoyi.uniapp.domain.vo.FieldVO;
-import com.ruoyi.uniapp.service.IFieldService;
-
-/**
- * 地块信息 服务层实现
- * 
- * @author ruoyi
- */
-@Service
-public class FieldServiceImpl implements IFieldService {
-    @Autowired
-    private FieldMapper fieldMapper;
-
-    @Override
-    public List<Field> fieldNameByUserList(Long userId) {
-        return fieldMapper.selectFieldListByUserId(userId);
-    }
-
-    /**
-     * 根据用户ID查询用户关联的地块列表
-     *
-     * @param userId    用户ID
-     * @param pageNum   页码
-     * @param pageSize  每页数量
-     * @return 分页信息
-     */
-    public PageInfo<FieldVO> selectFieldListByUserId(Long userId, Integer pageNum, Integer pageSize) {
-        if (userId == null) {
-            return new PageInfo<>(Collections.emptyList());
-        }
-
-        try {
-            PageHelper.startPage(ObjectUtil.defaultIfNull(pageNum, 1), ObjectUtil.defaultIfNull(pageSize, 10));
-            List<Field> fields = fieldMapper.selectFieldListByUserId(userId);
-            PageInfo<Field> sourcePageInfo = new PageInfo<>(fields);
-            return processFields(fields, sourcePageInfo);
-        } catch (Exception e) {
-            return new PageInfo<>(Collections.emptyList());
-        }
-    }
-
-
-    /**
-     * 根据用户ID和关键词搜索地块
-     * 
-     * @param userId 用户ID
-     * @param keyword 搜索关键词
-     * @return 地块信息集合
-     */
-    @Override
-    public PageInfo<FieldVO> searchFieldsByUserIdAndKeyword(Long userId, String keyword, Integer pageNum, Integer pageSize) {
-        if (userId == null) {
-            return new PageInfo<>(Collections.emptyList());
-        }
-
-        try {
-            PageHelper.startPage(ObjectUtil.defaultIfNull(pageNum, 1), ObjectUtil.defaultIfNull(pageSize, 10));
-            List<Field> fields = fieldMapper.searchFieldsByUserIdAndKeyword(userId, keyword);
-            PageInfo<Field> sourcePageInfo = new PageInfo<>(fields);
-            return processFields(fields, sourcePageInfo);
-        } catch (Exception e) {
-            return new PageInfo<>(Collections.emptyList());
-        }
-    }
-
-
-    @Override
-    public FieldVO countFieldTotalByUser(Long userId) {
-        Field field = fieldMapper.countFieldTotalByUser(userId);
-
-        FieldVO fieldVO = new FieldVO();
-        fieldVO.setPlotsTotal(field.getPlotsTotal() != null ? field.getPlotsTotal() : 0);
-        fieldVO.setInUseCount(field.getInUseCount() != null ? field.getInUseCount() : 0);
-        fieldVO.setLeiSureCount(field.getLeiSureCount() != null ? field.getLeiSureCount() : 0);
-        return fieldVO;
-    }
-
-    /**
-     * 转换地块实体为VO对象
-     * 
-     * @param field 地块实体
-     * @return 地块VO对象
-     */
-    @Override
-    public FieldVO convertToVO(Field field) {
-        if (field == null) {
-            return null;
-        }
-        
-        FieldVO vo = new FieldVO();
-        vo.setId(field.getId());
-        vo.setCode(field.getFieldCode());
-        vo.setName(field.getFieldName());
-        vo.setFarmName(field.getFarmName());
-        vo.setManager(field.getManagerName());
-        vo.setArea(field.getSize());
-        
-        // 使用枚举处理地块类型
-        vo.setType(FieldTypeEnum.getInfoByCode(field.getFieldType()));
-        
-        vo.setCrop(field.getGrowCrops());
-        
-        // 使用枚举处理地块状态
-        vo.setStatus(FieldStatusEnum.getStatusByCode(field.getStatus()));
-        
-        // 设备信息
-        vo.setDeviceCount(field.getDeviceCount());
-        vo.setOnlineDevices(field.getOnlineDevices());
-        vo.setAlerts(field.getAlerts());
-        
-        return vo;
-    }
-
-    private PageInfo<FieldVO> processFields(List<Field> fields, PageInfo<Field> sourcePageInfo) {
-        if (CollectionUtils.isEmpty(fields)) {
-            return new PageInfo<>(Collections.emptyList());
-        }
-
-        // 批量查询设备数量和告警信息
-        batchEnrichFieldsWithDeviceInfo(fields);
-
-        // 转换为VO列表
-        List<FieldVO> voList = fields.stream()
-                .map(this::convertToVO)
-                .collect(Collectors.toList());
-
-        // 创建新的分页信息对象并复制属性
-        PageInfo<FieldVO> resultPage = new PageInfo<>(voList);
-        BeanUtils.copyProperties(sourcePageInfo, resultPage, "list");
-
-        return resultPage;
-    }
-    
-    /**
-     * 批量为地块实体填充设备和告警信息
-     * 
-     * @param fields 地块实体列表
-     */
-    private void batchEnrichFieldsWithDeviceInfo(List<Field> fields) {
-        if (fields == null || fields.isEmpty()) {
-            return;
-        }
-        
-        // 提取所有地块ID
-        List<Long> fieldIds = fields.stream()
-                                   .map(Field::getId)
-                                   .collect(Collectors.toList());
-        
-        // 批量查询设备数量
-        List<Map<String, Object>> deviceCountResults = fieldMapper.batchCountDevicesByFieldIds(fieldIds);
-        Map<Long, Integer> deviceCountMap = new HashMap<>();
-        for (Map<String, Object> result : deviceCountResults) {
-            Long fieldId = ((Number) result.get("fieldId")).longValue();
-            Integer count = ((Number) result.get("deviceCount")).intValue();
-            deviceCountMap.put(fieldId, count);
-        }
-        
-        // 批量查询在线设备数量
-        List<Map<String, Object>> onlineDeviceCountResults = fieldMapper.batchCountOnlineDevicesByFieldIds(fieldIds);
-        Map<Long, Integer> onlineDeviceCountMap = new HashMap<>();
-        for (Map<String, Object> result : onlineDeviceCountResults) {
-            Long fieldId = ((Number) result.get("fieldId")).longValue();
-            Integer count = ((Number) result.get("onlineDevices")).intValue();
-            onlineDeviceCountMap.put(fieldId, count);
-        }
-        
-        // 将结果应用到地块对象上
-        for (Field field : fields) {
-            // 设置设备数量
-            Integer deviceCount = deviceCountMap.get(field.getId());
-            field.setDeviceCount(deviceCount != null ? deviceCount : 0);
-            
-            // 设置在线设备数量
-            Integer onlineDevices = onlineDeviceCountMap.get(field.getId());
-            field.setOnlineDevices(onlineDevices != null ? onlineDevices : 0);
-            
-            // 设置告警数量 TODO 等告警列表完善之后再查询
-            field.setAlerts(0);
-        }
-    }
-} 

+ 0 - 87
ruoyi-modules/ruoyi-uniapp/src/main/resources/logback-spring.xml

@@ -57,20 +57,6 @@
         </filter>
     </appender>
 
-
-	<!-- E充网访问日志输出  -->
-	<appender name="sys-pilelog" class="ch.qos.logback.core.rolling.RollingFileAppender">
-		<file>${log.path}/sys-pilelog/sys-pilelog.log</file>
-		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-			<!-- 按天回滚 daily -->
-			<fileNamePattern>${log.path}/sys-pilelog/sys-pilelog.%d{yyyy-MM-dd}.log</fileNamePattern>
-			<!-- 日志最大的历史 60天 -->
-			<maxHistory>14</maxHistory>
-		</rollingPolicy>
-		<encoder>
-			<pattern>${log.pattern}</pattern>
-		</encoder>
-	</appender>
 	<!--uniapp小程序日志访问日志输出  -->
 	<appender name="sys-uniapp" class="ch.qos.logback.core.rolling.RollingFileAppender">
 		<file>${log.path}/sys-uniapp/sys-uniapp.log</file>
@@ -84,59 +70,6 @@
 			<pattern>${log.pattern}</pattern>
 		</encoder>
 	</appender>
-	<!--支付充电访问日志输出  -->
-	<appender name="sys-pay" class="ch.qos.logback.core.rolling.RollingFileAppender">
-		<file>${log.path}/sys-pay/sys-pay.log</file>
-		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-			<!-- 按天回滚 daily -->
-			<fileNamePattern>${log.path}/sys-pay/sys-pay.%d{yyyy-MM-dd}.log</fileNamePattern>
-			<!-- 日志最大的历史 60天 -->
-			<maxHistory>14</maxHistory>
-		</rollingPolicy>
-		<encoder>
-			<pattern>${log.pattern}</pattern>
-		</encoder>
-	</appender>
-	<!--结算访问日志输出  -->
-	<appender name="sys-settlement" class="ch.qos.logback.core.rolling.RollingFileAppender">
-		<file>${log.path}/sys-settlement/settlement.log</file>
-		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-			<!-- 按天回滚 daily -->
-			<fileNamePattern>${log.path}/sys-settlement/sys-settlement.%d{yyyy-MM-dd}.log</fileNamePattern>
-			<!-- 日志最大的历史 60天 -->
-			<maxHistory>14</maxHistory>
-		</rollingPolicy>
-		<encoder>
-			<pattern>${log.pattern}</pattern>
-		</encoder>
-	</appender>
-	<!--数据共享日志输出  -->
-	<appender name="datashare" class="ch.qos.logback.core.rolling.RollingFileAppender">
-		<file>${log.path}/datashare/datashare.log</file>
-		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-			<!-- 按天回滚 daily -->
-			<fileNamePattern>${log.path}/sys-datashare/datashare.%d{yyyy-MM-dd}.log</fileNamePattern>
-			<!-- 日志最大的历史 60天 -->
-			<maxHistory>14</maxHistory>
-		</rollingPolicy>
-		<encoder>
-			<pattern>${log.pattern}</pattern>
-		</encoder>
-	</appender>
-
-	<!--二代电池包日志输出  -->
-	<appender name="sys-secondBattery" class="ch.qos.logback.core.rolling.RollingFileAppender">
-		<file>${log.path}/sys-secondBattery/secondBattery.log</file>
-		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-			<!-- 按天回滚 daily -->
-			<fileNamePattern>${log.path}/sys-secondBattery/sys-secondBattery.%d{yyyy-MM-dd}.log</fileNamePattern>
-			<!-- 日志最大的历史 60天 -->
-			<maxHistory>14</maxHistory>
-		</rollingPolicy>
-		<encoder>
-			<pattern>${log.pattern}</pattern>
-		</encoder>
-	</appender>
 
     <logger name="org.activiti.engine.impl.db" level="info">
         <appender-ref ref="info"/>
@@ -151,24 +84,4 @@
         <appender-ref ref="console"/>
         <appender-ref ref="info"/>
     </root>
-	<!--充电操作日志-->
-	<logger name="sys-pilelog" level="INFO">
-		<appender-ref ref="sys-pilelog"/>
-	</logger>
-	<!--小程序操作日志-->
-	<logger name="sys-uniapp" level="INFO">
-		<appender-ref ref="sys-uniapp"/>
-	</logger>
-	<!--支付充值操作日志-->
-	<logger name="sys-pay" level="INFO">
-		<appender-ref ref="sys-pay"/>
-	</logger>
-	<!--结算操作日志-->
-	<logger name="sys-settlement" level="INFO">
-		<appender-ref ref="sys-settlement"/>
-	</logger>
-	<!--二代电池包操作日志-->
-	<logger name="sys-secondBattery" level="INFO">
-		<appender-ref ref="sys-secondBattery"/>
-	</logger>
 </configuration>

+ 0 - 121
ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/DeviceMapper.xml

@@ -1,121 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.ruoyi.uniapp.mapper.DeviceMapper">
-    
-    <resultMap type="com.ruoyi.uniapp.domain.Device" id="DeviceResult">
-        <id property="id" column="id"/>
-        <result property="deviceId" column="device_id"/>
-        <result property="deviceName" column="device_name"/>
-        <result property="deviceTypeId" column="device_type_id"/>
-        <result property="farmId" column="farm_id"/>
-        <result property="model" column="model"/>
-        <result property="longitude" column="longitude"/>
-        <result property="latitude" column="latitude"/>
-        <result property="manufacturer" column="manufacturer"/>
-        <result property="installDate" column="install_date"/>
-        <result property="status" column="status"/>
-        <result property="lastActiveTime" column="last_active_time"/>
-        <result property="createTime" column="create_time"/>
-        <result property="updateTime" column="update_time"/>
-        <result property="remark" column="remark"/>
-        <result property="fieldName" column="field_name"/>
-    </resultMap>
-
-    <sql id="selectDeviceVo">
-        select d.id, d.device_id, d.device_name, d.device_type_id, d.farm_id, d.model, d.longitude,
-        d.latitude, d.manufacturer, d.install_date, d.status, d.last_active_time, d.create_time,
-        d.update_time, d.remark, f.field_name
-        from device d
-    </sql>
-
-    <select id="selectDeviceList" parameterType="com.ruoyi.uniapp.domain.dto.DeviceDto" resultMap="DeviceResult">
-        <include refid="selectDeviceVo"/>
-        INNER JOIN field_device fd ON fd.device_id = d.id AND fd.status = 0
-        INNER JOIN field f ON f.id = fd.field_id
-        INNER JOIN field_personnel fp ON fp.field_id = f.id AND fp.status = 0
-        <where>  
-            <if test="deviceId != null  and deviceId != ''"> and d.device_id = #{deviceId}</if>
-            <if test="fieldId != null  and fieldId != ''"> and fd.field_id = #{fieldId}</if>
-            <if test="userId != null  and userId != ''"> and fp.user_id = #{userId}</if>
-            <if test="deviceName != null  and deviceName != ''"> and d.device_name like concat('%', #{deviceName}, '%')</if>
-            <if test="deviceTypeId != null  and deviceTypeId != ''"> and d.device_type_id = #{deviceTypeId}</if>
-            <if test="status != null "> and d.status = #{status}</if>
-            <if test="deviceQueryParams != null and deviceQueryParams != ''">
-                and (
-                d.device_name like concat('%', #{deviceQueryParams}, '%') OR
-                d.device_id like concat('%', #{deviceQueryParams}, '%')
-                )
-            </if>
-        </where>
-        order by create_time desc
-    </select>
-    
-    <select id="selectDeviceById" parameterType="Integer" resultMap="DeviceResult">
-        <include refid="selectDeviceVo"/>
-        where id = #{id}
-    </select>
-
-    <select id="countDeviceStatistics" resultType="com.ruoyi.uniapp.domain.vo.DeviceOverviewVO">
-        SELECT
-        COUNT(DISTINCT d.id) AS totalDevices,
-        SUM(CASE WHEN d.status = 1 THEN 1 ELSE 0 END) AS onlineDevices,
-        SUM(CASE WHEN d.status = 0 THEN 1 ELSE 0 END) AS offlineDevices
-        FROM device d
-        INNER JOIN field_device fd ON fd.device_id = d.id AND fd.status = 0
-        INNER JOIN field f ON f.id = fd.field_id
-        INNER JOIN field_personnel fp ON fp.field_id = f.id AND fp.status = 0
-        <where>
-            <if test="fieldId != null and fieldId != ''">
-                AND fd.field_id = #{fieldId}
-            </if>
-            <if test="userId != null and userId != ''">
-                AND fp.user_id = #{userId}
-            </if>
-        </where>
-    </select>
-
-
-    <select id="countDevicesByType" resultType="java.util.Map">
-        SELECT
-        d.device_type_id AS deviceTypeId,
-        SUM( CASE WHEN d.STATUS = 1 THEN 1 ELSE 0 END ) AS online,
-        SUM( CASE WHEN d.STATUS = 0 THEN 1 ELSE 0 END ) AS offline
-        FROM
-        device d
-        LEFT JOIN field_device fd ON fd.device_id = d.id
-        LEFT JOIN field_personnel fp ON fd.field_id = fp.field_id
-        <where>
-            <if test="fieldId != null and fieldId != ''">
-                AND fd.field_id = #{fieldId}
-            </if>
-            <if test="userId != null and userId != ''">
-                AND fp.user_id = #{userId}
-            </if>
-            AND fd.`status` = 0
-            AND fp.`status` = 0
-        </where>
-        GROUP BY device_type_id
-    </select>
-    
-    <select id="countAlertsByType" resultType="java.util.Map">
-        SELECT 
-            d.device_type_id as deviceTypeId,
-            COUNT(a.id) as alerts
-        FROM 
-            device d
-        LEFT JOIN 
-            device_alert a ON d.device_id = a.device_id AND a.status = 0
-        <where>
-            <if test="farmId != null and farmId != ''">
-                AND d.farm_id = #{farmId}
-            </if>
-            <if test="fieldId != null and fieldId != ''">
-                AND d.field_id = #{fieldId}
-            </if>
-        </where>
-        GROUP BY d.device_type_id
-    </select>
-    
-</mapper> 

+ 0 - 117
ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/FieldMapper.xml

@@ -1,117 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.ruoyi.uniapp.mapper.FieldMapper">
-    
-    <resultMap type="com.ruoyi.uniapp.domain.Field" id="FieldResult">
-        <id property="id" column="id"/>
-        <result property="fieldCode" column="field_code"/>
-        <result property="fieldName" column="field_name"/>
-        <result property="farmId" column="farm_id"/>
-        <result property="farmName" column="farmName"/>
-        <result property="fieldType" column="field_type"/>
-        <result property="growCrops" column="grow_crops"/>
-        <result property="size" column="size"/>
-        <result property="soilType" column="soil_type"/>
-        <result property="irrigationType" column="irrigation_type"/>
-        <result property="status" column="status"/>
-        <result property="managerId" column="manager_id"/>
-        <result property="managerName" column="manager_name"/>
-        <result property="description" column="description"/>
-        <result property="locationData" column="location_data"/>
-        <result property="createTime" column="created_time"/>
-        <result property="updateTime" column="updated_time"/>
-        <result property="createBy" column="created_by"/>
-        <result property="updateBy" column="updated_by"/>
-        <result property="isDeleted" column="is_deleted"/>
-        <result column="plotsTotal" property="plotsTotal"/>
-        <result column="inUseCount" property="inUseCount"/>
-        <result column="leiSureCount" property="leiSureCount"/>
-    </resultMap>
-    
-    <sql id="selectFieldWithFarm">
-        select
-            f.id, f.field_code, f.field_name, f.farm_id,
-            f.field_type, f.grow_crops, f.size, f.soil_type, f.irrigation_type, 
-            f.status, f.manager_id, f.manager_name, f.description, f.location_data, 
-            f.created_time, f.updated_time, f.created_by, f.updated_by, f.is_deleted,s.dept_name as farmName
-        from field f
-        left join sys_dept s on f.farm_id = s.dept_id
-    </sql>
-    
-    <!-- 根据用户ID查询关联的地块列表 -->
-    <select id="selectFieldListByUserId" parameterType="Long" resultMap="FieldResult">
-        <include refid="selectFieldWithFarm"/>
-        inner join field_personnel fp on f.id = fp.field_id
-        <where>
-            f.is_deleted = 0
-            and fp.is_deleted = 0
-            and fp.status = '0'
-            and fp.user_id = #{userId}
-        </where>
-    </select>
-
-    
-    <!-- 根据用户ID和关键词搜索地块 -->
-    <select id="searchFieldsByUserIdAndKeyword" resultMap="FieldResult">
-        <include refid="selectFieldWithFarm"/>
-        inner join field_personnel fp on f.id = fp.field_id
-        <where>
-            f.is_deleted = 0
-            and fp.is_deleted = 0
-            and fp.status = '0'
-            and fp.user_id = #{userId}
-            <if test="keyword != null and keyword != ''">
-                and (
-                    f.field_code like concat('%', #{keyword}, '%') OR
-                    f.field_name like concat('%', #{keyword}, '%') OR
-                    f.manager_name like concat('%', #{keyword}, '%')
-                )
-            </if>
-        </where>
-    </select>
-
-    <select id="countFieldTotalByUser" parameterType="Long" resultMap="FieldResult">
-        SELECT
-            COUNT(*) AS plotsTotal,
-            COUNT(CASE WHEN f.status = '0' THEN 1 END) AS inUseCount,
-            COUNT(CASE WHEN f.status = '1' THEN 1 END) AS leiSureCount
-        FROM field f
-                 LEFT JOIN field_personnel fp on f.id = fp.field_id
-        where fp.user_id = #{userId}
-    </select>
-
-    <!-- 批量查询地块的设备数量 -->
-    <select id="batchCountDevicesByFieldIds" resultType="java.util.Map">
-        SELECT 
-            field_id as fieldId,
-            COUNT(1) as deviceCount
-        FROM field_device
-        WHERE field_id IN
-        <foreach collection="fieldIds" item="fieldId" open="(" separator="," close=")">
-            #{fieldId}
-        </foreach>
-        AND status = '0'
-        AND is_deleted = 0
-        GROUP BY field_id
-    </select>
-    
-    <!-- 批量查询地块的在线设备数量 -->
-    <select id="batchCountOnlineDevicesByFieldIds" resultType="java.util.Map">
-        SELECT 
-            fd.field_id as fieldId,
-            COUNT(1) as onlineDevices
-        FROM field_device fd
-        LEFT JOIN device d ON fd.device_id = d.id
-        WHERE fd.field_id IN
-        <foreach collection="fieldIds" item="fieldId" open="(" separator="," close=")">
-            #{fieldId}
-        </foreach>
-        AND fd.status = '0'
-        AND fd.is_deleted = 0
-        AND d.status = '1'
-        GROUP BY fd.field_id
-    </select>
-    
-</mapper> 

+ 0 - 146
ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/KnowledgeArticleMapper.xml

@@ -1,146 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.ruoyi.uniapp.mapper.KnowledgeArticleMapper">
-    
-    <resultMap type="com.ruoyi.uniapp.domain.KnowledgeArticle" id="KnowledgeArticleResult">
-        <id property="id" column="id"/>
-        <result property="title" column="title"/>
-        <result property="description" column="description"/>
-        <result property="content" column="content"/>
-        <result property="category" column="category"/>
-        <result property="thumbnail" column="thumbnail"/>
-        <result property="contentType" column="content_type"/>
-        <result property="videoUrl" column="video_url"/>
-        <result property="videoDuration" column="video_duration"/>
-        <result property="source" column="source"/>
-        <result property="tags" column="tags"/>
-        <result property="publishDate" column="publish_date"/>
-        <result property="viewCount" column="view_count"/>
-        <result property="likeCount" column="like_count"/>
-        <result property="isRecommend" column="is_recommend"/>
-        <result property="status" column="status"/>
-        <result property="createTime" column="create_time"/>
-        <result property="updateTime" column="update_time"/>
-    </resultMap>
-
-    <sql id="selectKnowledgeArticleVo">
-        select id, title, description, content, category, thumbnail, content_type, video_url, video_duration, 
-        source, tags, publish_date, view_count, like_count, is_recommend, status, create_time, update_time 
-        from knowledge_article
-    </sql>
-
-    <select id="selectKnowledgeArticleById" parameterType="Integer" resultMap="KnowledgeArticleResult">
-        <include refid="selectKnowledgeArticleVo"/>
-        where id = #{id}
-    </select>
-    
-    <select id="selectKnowledgeArticleList" parameterType="com.ruoyi.uniapp.domain.KnowledgeArticle" resultMap="KnowledgeArticleResult">
-        <include refid="selectKnowledgeArticleVo"/>
-        <where>
-            <if test="title != null and title != ''">
-                AND title like concat('%', #{title}, '%')
-            </if>
-            <if test="category != null and category != ''">
-                AND category = #{category}
-            </if>
-            <if test="contentType != null and contentType != ''">
-                AND content_type = #{contentType}
-            </if>
-            <if test="isRecommend != null">
-                AND is_recommend = #{isRecommend}
-            </if>
-            <if test="status != null">
-                AND status = #{status}
-            </if>
-        </where>
-        order by publish_date desc
-    </select>
-    
-    <select id="selectKnowledgeArticlesByCategory" resultMap="KnowledgeArticleResult">
-        <include refid="selectKnowledgeArticleVo"/>
-        where category = #{category} and status = 1
-        order by publish_date desc
-    </select>
-    
-    <insert id="insertKnowledgeArticle" parameterType="com.ruoyi.uniapp.domain.KnowledgeArticle" useGeneratedKeys="true" keyProperty="id">
-        insert into knowledge_article (
-            <if test="title != null">title,</if>
-            <if test="description != null">description,</if>
-            <if test="content != null">content,</if>
-            <if test="category != null">category,</if>
-            <if test="thumbnail != null">thumbnail,</if>
-            <if test="contentType != null">content_type,</if>
-            <if test="videoUrl != null">video_url,</if>
-            <if test="videoDuration != null">video_duration,</if>
-            <if test="source != null">source,</if>
-            <if test="tags != null">tags,</if>
-            <if test="publishDate != null">publish_date,</if>
-            <if test="viewCount != null">view_count,</if>
-            <if test="likeCount != null">like_count,</if>
-            <if test="isRecommend != null">is_recommend,</if>
-            <if test="status != null">status,</if>
-            create_time,
-            update_time
-        ) values (
-            <if test="title != null">#{title},</if>
-            <if test="description != null">#{description},</if>
-            <if test="content != null">#{content},</if>
-            <if test="category != null">#{category},</if>
-            <if test="thumbnail != null">#{thumbnail},</if>
-            <if test="contentType != null">#{contentType},</if>
-            <if test="videoUrl != null">#{videoUrl},</if>
-            <if test="videoDuration != null">#{videoDuration},</if>
-            <if test="source != null">#{source},</if>
-            <if test="tags != null">#{tags},</if>
-            <if test="publishDate != null">#{publishDate},</if>
-            <if test="viewCount != null">#{viewCount},</if>
-            <if test="likeCount != null">#{likeCount},</if>
-            <if test="isRecommend != null">#{isRecommend},</if>
-            <if test="status != null">#{status},</if>
-            sysdate(),
-            sysdate()
-        )
-    </insert>
-    
-    <update id="updateKnowledgeArticle" parameterType="com.ruoyi.uniapp.domain.KnowledgeArticle">
-        update knowledge_article
-        <set>
-            <if test="title != null">title = #{title},</if>
-            <if test="description != null">description = #{description},</if>
-            <if test="content != null">content = #{content},</if>
-            <if test="category != null">category = #{category},</if>
-            <if test="thumbnail != null">thumbnail = #{thumbnail},</if>
-            <if test="contentType != null">content_type = #{contentType},</if>
-            <if test="videoUrl != null">video_url = #{videoUrl},</if>
-            <if test="videoDuration != null">video_duration = #{videoDuration},</if>
-            <if test="source != null">source = #{source},</if>
-            <if test="tags != null">tags = #{tags},</if>
-            <if test="publishDate != null">publish_date = #{publishDate},</if>
-            <if test="viewCount != null">view_count = #{viewCount},</if>
-            <if test="likeCount != null">like_count = #{likeCount},</if>
-            <if test="isRecommend != null">is_recommend = #{isRecommend},</if>
-            <if test="status != null">status = #{status},</if>
-            update_time = sysdate()
-        </set>
-        where id = #{id}
-    </update>
-    
-    <delete id="deleteKnowledgeArticleById" parameterType="Integer">
-        delete from knowledge_article where id = #{id}
-    </delete>
-    
-    <update id="updateViewCount" parameterType="Integer">
-        update knowledge_article
-        set view_count = view_count + 1
-        where id = #{id}
-    </update>
-    
-    <update id="updateLikeCount">
-        update knowledge_article
-        set like_count = like_count + #{count}
-        where id = #{id}
-    </update>
-    
-</mapper> 

+ 0 - 0
ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/uniapp/KnowledgeContentMapper.xml → ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/KnowledgeContentMapper.xml


+ 0 - 43
ruoyi-modules/ruoyi-uniapp/src/main/resources/mapper/WeatherRealtimeDataMapper.xml

@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.ruoyi.uniapp.mapper.WeatherRealtimeDataMapper">
-    
-    <resultMap type="com.ruoyi.uniapp.domain.WeatherRealtimeData" id="WeatherRealtimeDataResult">
-        <id property="id" column="id"/>
-        <result property="deviceId" column="device_id"/>
-        <result property="temperature" column="temperature"/>
-        <result property="humidity" column="humidity"/>
-        <result property="rainfall" column="rainfall"/>
-        <result property="windDirection" column="wind_direction"/>
-        <result property="windSpeed" column="wind_speed"/>
-        <result property="airPressure" column="air_pressure"/>
-        <result property="lightIntensity" column="light_intensity"/>
-        <result property="soilTemperature" column="soil_temperature"/>
-        <result property="soilHumidity" column="soil_humidity"/>
-        <result property="soilN" column="soil_n"/>
-        <result property="soilP" column="soil_p"/>
-        <result property="soilK" column="soil_k"/>
-        <result property="collectTime" column="collect_time"/>
-        <result property="createTime" column="create_time"/>
-        <result property="updateTime" column="update_time"/>
-        <result property="createBy" column="create_by"/>
-        <result property="updateBy" column="update_by"/>
-    </resultMap>
-    
-    <sql id="selectWeatherRealtimeDataVo">
-        select wrd.id, wrd.device_id, wrd.temperature, wrd.humidity, wrd.rainfall, wrd.wind_direction, wrd.wind_speed,
-               wrd.air_pressure, wrd.light_intensity, wrd.soil_temperature, wrd.soil_humidity, wrd.soil_n, wrd.soil_p, wrd.soil_k,
-               wrd.collect_time, wrd.create_time, wrd.update_time, wrd.create_by, wrd.update_by
-        from weather_realtime_data wrd
-    </sql>
-    
-    <select id="selectLatestDataByDeviceId" parameterType="String" resultMap="WeatherRealtimeDataResult">
-        <include refid="selectWeatherRealtimeDataVo"/>
-        WHERE wrd.device_id = #{deviceId}
-        order by collect_time desc
-        LIMIT 1
-    </select>
-    
-</mapper>