lipenghui hai 3 meses
pai
achega
8788355a5b

+ 1 - 0
yudao-module-pms/yudao-module-pms-api/src/main/java/cn/iocoder/yudao/module/pms/enums/ErrorCodeConstant.java

@@ -49,4 +49,5 @@ public interface ErrorCodeConstant{
     ErrorCode IOT_MAINTENANCE_PLAN_NO_EXISTS = new ErrorCode(140,"维修计划不存在");
     ErrorCode IOT_MAIN_WORK_ORDER_NOT_EXISTS = new ErrorCode(141,"保养工单不存在");
     ErrorCode IOT_DEVICE_RUN_LOG_NOT_EXISTS = new ErrorCode(142, "设备运行数据记录 中间表不存在");
+    ErrorCode DEVICE_NOT_EXISTS = new ErrorCode(143, "延凡设备不存在");
 }

+ 19 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/IotDeviceController.java

@@ -125,6 +125,25 @@ public class IotDeviceController {
                 pageResult.getTotal()));
     }
 
+    @GetMapping("/td/page")
+    @Operation(summary = "获得设备台账包含数采信息")
+    @PreAuthorize("@ss.hasPermission('rq:iot-device:query')")
+    public CommonResult<PageResult<IotDeviceRespVO>> getIotDeviceTdPage(@Valid IotDevicePageReqVO pageReqVO) {
+        PageResult<IotDeviceDO> pageResult = iotDeviceService.getIotDevicePage(pageReqVO);
+        if (CollUtil.isEmpty(pageResult.getList())) {
+            return success(new PageResult<>(pageResult.getTotal()));
+        }
+        Map<Long, DeptDO> deptMap = deptService.getDeptMap(
+                convertList(pageResult.getList(), IotDeviceDO::getDeptId));
+        PageResult<IotDeviceRespVO> result = new PageResult<>(IotDeviceConvert.INSTANCE.convertList(pageResult.getList(), deptMap),
+                pageResult.getTotal());
+        for (IotDeviceRespVO iotDeviceRespVO : result.getList()) {
+            String deviceCode = iotDeviceRespVO.getDeviceCode();
+
+        }
+        return success(result);
+    }
+
     @GetMapping("/deviceAssociateBomPage")
     @Operation(summary = "获得设备台账分页")
     @PreAuthorize("@ss.hasPermission('rq:iot-device:query')")

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDeviceRespVO.java

@@ -162,4 +162,10 @@ public class IotDeviceRespVO {
     private BigDecimal totalMileage;
     @Schema(description = "设备累计运行时间")
     private BigDecimal totalRunTime;
+    @Schema(description = "是否在线")
+    private Boolean ifInline;
+
+    @Schema(description = "最后在线时间")
+    private String lastInlineTime;
+
 }

+ 148 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/yanfan/DeviceDO.java

@@ -0,0 +1,148 @@
+package cn.iocoder.yudao.module.iot.dal.dataobject.device;
+
+import lombok.*;
+import java.util.*;
+import java.time.LocalDateTime;
+import java.time.LocalDateTime;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.*;
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+
+/**
+ * 设备 DO
+ *
+ * @author 李鹏辉
+ */
+@TableName("iot_device")
+@KeySequence("iot_device_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class DeviceDO extends BaseDO {
+
+    /**
+     * 设备ID
+     */
+    @TableId
+    private Long deviceId;
+    /**
+     * 设备名称
+     */
+    private String deviceName;
+    /**
+     * 产品ID
+     */
+    private Long productId;
+    /**
+     * 产品名称
+     */
+    private String productName;
+    /**
+     * 租户名称
+     */
+    private String tenantName;
+    /**
+     * 设备编号
+     */
+    private String serialNumber;
+    /**
+     * 子设备网关编号
+     */
+    private String gwDevCode;
+    /**
+     * 固件版本
+     */
+    private Double firmwareVersion;
+    /**
+     * 设备状态(1-未激活,2-禁用,3-在线,4-离线)
+     */
+    private Boolean status;
+    /**
+     * 信号强度(	信号极好4格[-55— 0],	信号好3格[-70— -55],	信号一般2格[-85— -70],	信号差1格[-100— -85])
+     */
+    private Integer rssi;
+    /**
+     * 是否启用设备影子(0=禁用,1=启用)
+     */
+    private Boolean isShadow;
+    /**
+     * 定位方式(1=ip自动定位,2=设备定位,3=自定义)
+     */
+    private Boolean locationWay;
+    /**
+     * 物模型值
+     */
+    private String thingsModelValue;
+    /**
+     * 设备所在地址
+     */
+    private String networkAddress;
+    /**
+     * 设备入网IP
+     */
+    private String networkIp;
+    /**
+     * 设备经度
+     */
+    private Double longitude;
+    /**
+     * 设备纬度
+     */
+    private Double latitude;
+    /**
+     * 激活时间
+     */
+    private LocalDateTime activeTime;
+    /**
+     * 设备摘要,格式[{"name":"device"},{"chip":"esp8266"}]
+     */
+    private String summary;
+    /**
+     * 图片地址
+     */
+    private String imgUrl;
+    /**
+     * 删除标志(0代表存在 2代表删除)
+     */
+    private String delFlag;
+    /**
+     * 创建者
+     */
+    private String createBy;
+    /**
+     * 更新者
+     */
+    private String updateBy;
+    /**
+     * 备注
+     */
+    private String remark;
+    /**
+     * 是否是模拟设备
+     */
+    private Integer isSimulate;
+    /**
+     * 从机id
+     */
+    private Integer slaveId;
+    /**
+     * clientId编号
+     */
+    private String clientId;
+    /**
+     * 发布
+     */
+    private String postDev;
+    /**
+     * 订阅
+     */
+    private String getDev;
+    /**
+     * mqtt是否自定义状态(1为初始化,0为自定义)
+     */
+    private Integer mqttstats;
+
+}

+ 55 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/yanfan/DeviceMapper.java

@@ -0,0 +1,55 @@
+package cn.iocoder.yudao.module.iot.dal.mysql.device;
+
+import java.util.*;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
+import org.apache.ibatis.annotations.Mapper;
+import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
+
+/**
+ * 设备 Mapper
+ *
+ * @author 李鹏辉
+ */
+@Mapper
+public interface DeviceMapper extends BaseMapperX<DeviceDO> {
+
+    default PageResult<DeviceDO> selectPage(DevicePageReqVO reqVO) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceDO>()
+                .likeIfPresent(DeviceDO::getDeviceName, reqVO.getDeviceName())
+                .eqIfPresent(DeviceDO::getProductId, reqVO.getProductId())
+                .likeIfPresent(DeviceDO::getProductName, reqVO.getProductName())
+                .likeIfPresent(DeviceDO::getTenantName, reqVO.getTenantName())
+                .eqIfPresent(DeviceDO::getSerialNumber, reqVO.getSerialNumber())
+                .eqIfPresent(DeviceDO::getGwDevCode, reqVO.getGwDevCode())
+                .eqIfPresent(DeviceDO::getFirmwareVersion, reqVO.getFirmwareVersion())
+                .eqIfPresent(DeviceDO::getStatus, reqVO.getStatus())
+                .eqIfPresent(DeviceDO::getRssi, reqVO.getRssi())
+                .eqIfPresent(DeviceDO::getIsShadow, reqVO.getIsShadow())
+                .eqIfPresent(DeviceDO::getLocationWay, reqVO.getLocationWay())
+                .eqIfPresent(DeviceDO::getThingsModelValue, reqVO.getThingsModelValue())
+                .eqIfPresent(DeviceDO::getNetworkAddress, reqVO.getNetworkAddress())
+                .eqIfPresent(DeviceDO::getNetworkIp, reqVO.getNetworkIp())
+                .eqIfPresent(DeviceDO::getLongitude, reqVO.getLongitude())
+                .eqIfPresent(DeviceDO::getLatitude, reqVO.getLatitude())
+                .betweenIfPresent(DeviceDO::getActiveTime, reqVO.getActiveTime())
+                .eqIfPresent(DeviceDO::getSummary, reqVO.getSummary())
+                .eqIfPresent(DeviceDO::getImgUrl, reqVO.getImgUrl())
+                .eqIfPresent(DeviceDO::getDelFlag, reqVO.getDelFlag())
+                .eqIfPresent(DeviceDO::getCreateBy, reqVO.getCreateBy())
+                .betweenIfPresent(DeviceDO::getCreateTime, reqVO.getCreateTime())
+                .eqIfPresent(DeviceDO::getUpdateBy, reqVO.getUpdateBy())
+                .eqIfPresent(DeviceDO::getRemark, reqVO.getRemark())
+                .eqIfPresent(DeviceDO::getIsSimulate, reqVO.getIsSimulate())
+                .eqIfPresent(DeviceDO::getSlaveId, reqVO.getSlaveId())
+                .eqIfPresent(DeviceDO::getClientId, reqVO.getClientId())
+                .eqIfPresent(DeviceDO::getPostDev, reqVO.getPostDev())
+                .eqIfPresent(DeviceDO::getGetDev, reqVO.getGetDev())
+                .eqIfPresent(DeviceDO::getMqttstats, reqVO.getMqttstats())
+                .orderByDesc(DeviceDO::getId));
+    }
+
+}

+ 8 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java

@@ -22,6 +22,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
 import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
 import cn.iocoder.yudao.module.system.service.dict.DictDataService;
+import com.baomidou.dynamic.datasource.annotation.Slave;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.ImmutableMap;
@@ -57,6 +58,13 @@ public class IotDeviceServiceImpl implements IotDeviceService {
     @Resource
     private DictDataService dictDataService;
 
+    @Slave
+    public List<Map<String,Object>> getTdDevice() {
+        List<Map<String, Object>> devices = new ArrayList<>();
+
+        return devices;
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Long createIotDevice(IotDeviceSaveReqVO createReqVO) {

+ 55 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/yanfan/DeviceService.java

@@ -0,0 +1,55 @@
+package cn.iocoder.yudao.module.iot.service.device;
+
+import java.util.*;
+import javax.validation.*;
+import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
+import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+
+/**
+ * 设备 Service 接口
+ *
+ * @author 李鹏辉
+ */
+public interface DeviceService {
+
+    /**
+     * 创建设备
+     *
+     * @param createReqVO 创建信息
+     * @return 编号
+     */
+    Long createDevice(@Valid DeviceSaveReqVO createReqVO);
+
+    /**
+     * 更新设备
+     *
+     * @param updateReqVO 更新信息
+     */
+    void updateDevice(@Valid DeviceSaveReqVO updateReqVO);
+
+    /**
+     * 删除设备
+     *
+     * @param id 编号
+     */
+    void deleteDevice(Long id);
+
+    /**
+     * 获得设备
+     *
+     * @param id 编号
+     * @return 设备
+     */
+    DeviceDO getDevice(Long id);
+
+    /**
+     * 获得设备分页
+     *
+     * @param pageReqVO 分页查询
+     * @return 设备分页
+     */
+    PageResult<DeviceDO> getDevicePage(DevicePageReqVO pageReqVO);
+
+}

+ 74 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/yanfan/DeviceServiceImpl.java

@@ -0,0 +1,74 @@
+package cn.iocoder.yudao.module.iot.service.device;
+
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.*;
+import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
+import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+
+import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper;
+
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
+
+/**
+ * 设备 Service 实现类
+ *
+ * @author 李鹏辉
+ */
+@Service
+@Validated
+public class DeviceServiceImpl implements DeviceService {
+
+    @Resource
+    private DeviceMapper deviceMapper;
+
+    @Override
+    public Long createDevice(DeviceSaveReqVO createReqVO) {
+        // 插入
+        DeviceDO device = BeanUtils.toBean(createReqVO, DeviceDO.class);
+        deviceMapper.insert(device);
+        // 返回
+        return device.getId();
+    }
+
+    @Override
+    public void updateDevice(DeviceSaveReqVO updateReqVO) {
+        // 校验存在
+        validateDeviceExists(updateReqVO.getId());
+        // 更新
+        DeviceDO updateObj = BeanUtils.toBean(updateReqVO, DeviceDO.class);
+        deviceMapper.updateById(updateObj);
+    }
+
+    @Override
+    public void deleteDevice(Long id) {
+        // 校验存在
+        validateDeviceExists(id);
+        // 删除
+        deviceMapper.deleteById(id);
+    }
+
+    private void validateDeviceExists(Long id) {
+        if (deviceMapper.selectById(id) == null) {
+            throw exception(DEVICE_NOT_EXISTS);
+        }
+    }
+
+    @Override
+    public DeviceDO getDevice(Long id) {
+        return deviceMapper.selectById(id);
+    }
+
+    @Override
+    public PageResult<DeviceDO> getDevicePage(DevicePageReqVO pageReqVO) {
+        return deviceMapper.selectPage(pageReqVO);
+    }
+
+}

+ 2 - 1
yudao-server/src/main/resources/application-dev.yaml

@@ -52,7 +52,8 @@ spring:
           password: .N_Mdq!BR1W4
         slave: # 模拟从库,可根据自己需要修改 # 模拟从库,可根据自己需要修改
           lazy: true # 开启懒加载,保证启动速度
-          url: jdbc:mysql://1.94.244.160:3306/rqiot?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
+#          url: jdbc:mysql://1.94.244.160:3306/rqiot?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
+          url: jdbc:mysql://1.94.244.160:3306/yanfan?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
           username: root
           password: .N_Mdq!BR1W4
         # TDengine数据库